-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1749027 [wpt PR 32291] - Test using location API to navigate to t…
…he current hash, a=testonly Automatic update from web-platform-tests Test using location API to navigate to the current hash See whatwg/html#7386. -- wpt-commits: 1e5972db2fb855ac1a1685b95b11a5f7159e4c4c wpt-pr: 32291
- Loading branch information
1 parent
d6dbe99
commit 9d08569
Showing
1 changed file
with
101 additions
and
0 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
testing/web-platform/tests/html/browsers/history/the-location-interface/same-hash.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Using the location interface to navigate to the same hash as the current one</title> | ||
<link rel="help" href="https://github.com/whatwg/html/issues/7386"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<iframe id="i" srcdoc="<div style='height: 200vh'></div><div id='te<st'></div>"></iframe> | ||
|
||
<script type="module"> | ||
setup({ explicit_done: true }); | ||
await new Promise(r => window.onload = r); | ||
|
||
for (const value of ["#te<st", "te<st", "#te%3Cst", "te%3Cst"]) { | ||
promise_test(async t => { | ||
t.add_cleanup(() => { i.contentWindow.location.hash = ""; }); | ||
assert_equals(i.contentWindow.scrollY, 0, "Setup: iframe starts at top"); | ||
|
||
i.contentWindow.location.hash = "te<st"; | ||
await delayForFragmentNavigationScrolling(t); | ||
|
||
assert_greater_than(i.contentWindow.scrollY, i.contentWindow.innerHeight, "First hash assignment scrolls the iframe"); | ||
|
||
i.contentWindow.scroll({ top: 0, behavior: "instant" }); | ||
assert_equals(i.contentWindow.scrollY, 0, "Resetting the scroll position must work"); | ||
|
||
i.contentWindow.location.hash = value; | ||
await delayForFragmentNavigationScrolling(t); | ||
|
||
assert_equals(i.contentWindow.scrollY, 0, "Reassigning the same hash must not change the scroll position"); | ||
}, `Using location.hash = "${value}" must not reset scroll position`); | ||
} | ||
|
||
// These don't canonicalize to the current value of location.hash; the post-parsing version of | ||
// "te<st" is "te%3Cst", uppercase. | ||
for (const value of ["#te%3cst", "te%3cst"]) { | ||
promise_test(async t => { | ||
t.add_cleanup(() => { i.contentWindow.location.hash = ""; }); | ||
assert_equals(i.contentWindow.scrollY, 0, "Setup: iframe starts at top"); | ||
|
||
i.contentWindow.location.hash = "te<st"; | ||
await delayForFragmentNavigationScrolling(t); | ||
|
||
assert_greater_than(i.contentWindow.scrollY, i.contentWindow.innerHeight, "First hash assignment scrolls the iframe"); | ||
|
||
i.contentWindow.scroll({ top: 0, behavior: "instant" }); | ||
assert_equals(i.contentWindow.scrollY, 0, "Resetting the scroll position must work"); | ||
|
||
i.contentWindow.location.hash = value; | ||
await delayForFragmentNavigationScrolling(t); | ||
|
||
assert_greater_than(i.contentWindow.scrollY, i.contentWindow.innerHeight, "Reassigning the same-ish hash scrolls the iframe"); | ||
}, `Using location.hash = "${value}" must reset scroll position`); | ||
} | ||
|
||
for (const value of ["about:srcdoc#te<st", "about:srcdoc#te%3cst", "about:srcdoc#te%3Cst"]) { | ||
promise_test(async t => { | ||
t.add_cleanup(() => { i.contentWindow.location.hash = ""; }); | ||
assert_equals(i.contentWindow.scrollY, 0, "Setup: iframe starts at top"); | ||
|
||
i.contentWindow.location.hash = "te<st"; | ||
await delayForFragmentNavigationScrolling(t); | ||
|
||
assert_greater_than(i.contentWindow.scrollY, i.contentWindow.innerHeight, "First hash assignment scrolls the iframe"); | ||
|
||
i.contentWindow.scroll({ top: 0, behavior: "instant" }); | ||
assert_equals(i.contentWindow.scrollY, 0, "Resetting the scroll position must work"); | ||
|
||
i.contentWindow.location.href = value; | ||
await delayForFragmentNavigationScrolling(t); | ||
|
||
assert_greater_than(i.contentWindow.scrollY, i.contentWindow.innerHeight, "Setting href must scroll the iframe"); | ||
}, `Using location.href = "${value}" must reset scroll position`); | ||
|
||
promise_test(async t => { | ||
t.add_cleanup(() => { i.contentWindow.location.hash = ""; }); | ||
assert_equals(i.contentWindow.scrollY, 0, "Setup: iframe starts at top"); | ||
|
||
i.contentWindow.location.hash = "te<st"; | ||
await delayForFragmentNavigationScrolling(t); | ||
|
||
assert_greater_than(i.contentWindow.scrollY, i.contentWindow.innerHeight, "First hash assignment scrolls the iframe"); | ||
|
||
i.contentWindow.scroll({ top: 0, behavior: "instant" }); | ||
assert_equals(i.contentWindow.scrollY, 0, "Resetting the scroll position must work"); | ||
|
||
i.contentWindow.location.assign(value); | ||
await delayForFragmentNavigationScrolling(t); | ||
|
||
assert_greater_than(i.contentWindow.scrollY, i.contentWindow.innerHeight, "Setting href must scroll the iframe"); | ||
}, `Using location.assign("${value}") must reset scroll position`); | ||
} | ||
|
||
function delayForFragmentNavigationScrolling(t) { | ||
// Scroll behavior for fragment navigation is set to "auto" in the spec, so we can't guarantee it's instant. | ||
// In practice 10 milliseconds seems to be enough. | ||
return new Promise(r => t.step_timeout(r, 10)); | ||
} | ||
|
||
done(); | ||
</script> |