fune/testing/web-platform/tests/navigation-api/currententrychange-event/location-api.html
Blink WPT Bot b4b7fb96a8 Bug 1857339 [wpt PR 42232] - Make navigation-api/ tests resilient to starting with extra NavigationHistoryEntries, a=testonly
Automatic update from web-platform-tests
Make navigation-api/ tests resilient to starting with extra NavigationHistoryEntries (#42232)

When WPT are run in-browser or via wptrunner, there may be additional
session history entries when the test starts, so the tests shouldn't
assume that they start with navigation.entries().length == 1 or
navigation.currentEntry.index == 0.

This fixes all directories except navigate-event/ and
navigation-methods/, which had enough tests to deserve separate
treatment.

This is a workaround for https://github.com/web-platform-tests/wpt/issues/33590.

Change-Id: Ic60de8ffe247b374ef3a0e0939fc4c1a3427c7e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4903245
Auto-Submit: Nate Chapin <japhet@chromium.org>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Weizhong Xia <weizhong@google.com>
Cr-Commit-Position: refs/heads/main@{#1204873}

Co-authored-by: Nate Chapin <japhet@chromium.org>
--

wpt-commits: 0a5ef44bf2e1c9be8f50beee9936771d5adcd35b
wpt-pr: 42232
2023-10-26 08:56:00 +00:00

20 lines
719 B
HTML

<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(t => {
let start_index = navigation.currentEntry.index;
let oncurrententrychange_called = false;
let original_entry = navigation.currentEntry;
navigation.oncurrententrychange = t.step_func(e => {
oncurrententrychange_called = true;
assert_equals(e.from, original_entry);
assert_equals(e.from.index, -1);
assert_equals(e.navigationType, "replace");
assert_equals(navigation.currentEntry.index, start_index);
});
location.hash = "#foo";
assert_true(oncurrententrychange_called);
}, "currententrychange fires for location API navigations");
</script>