diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/navigation-api/scroll-behavior | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/navigation-api/scroll-behavior')
24 files changed, 707 insertions, 0 deletions
diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-basic.html b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-basic.html new file mode 100644 index 0000000000..8ee4cc395b --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-basic.html @@ -0,0 +1,20 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + await navigation.navigate("#frag").finished; + assert_not_equals(window.scrollY, 0); + navigation.onnavigate = e => e.intercept({ scroll: "after-transition" }); + await navigation.back().finished; + assert_equals(window.scrollY, 0); +}, "scroll: after-transition should scroll when back completes"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-change-history-scroll-restoration-during-promise.html b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-change-history-scroll-restoration-during-promise.html new file mode 100644 index 0000000000..6ededdeebf --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-change-history-scroll-restoration-during-promise.html @@ -0,0 +1,32 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + + history.scrollRestoration = "manual"; + await navigation.navigate("#frag").finished; + assert_not_equals(window.scrollY, 0); + + let intercept_resolve; + navigation.onnavigate = e => { + e.intercept({ handler: () => new Promise(r => intercept_resolve = r), + scroll: "after-transition" }); + }; + + let back_promises = navigation.back(); + await back_promises.committed; + history.scrollRestoration = "auto"; + intercept_resolve(); + await back_promises.finished; + assert_equals(window.scrollY, 0); +}, "scroll: after-transition should ignore history.scrollRestoration even if it changes in the middle of the navigation"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-explicit-scroll.html b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-explicit-scroll.html new file mode 100644 index 0000000000..4b7d075474 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-explicit-scroll.html @@ -0,0 +1,29 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + await navigation.navigate("#frag").finished; + assert_not_equals(window.scrollY, 0); + navigation.onnavigate = t.step_func(e => { + e.intercept({ + scroll: "after-transition", + handler: t.step_func(() => { + assert_not_equals(window.scrollY, 0); + e.scroll(); + assert_equals(window.scrollY, 0); + }) + }); + }); + await navigation.back().finished; + assert_equals(window.scrollY, 0); +}, "scroll: scroll() should preempt after-transition"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-intercept-handler-modifies.html b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-intercept-handler-modifies.html new file mode 100644 index 0000000000..baff6fe542 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-intercept-handler-modifies.html @@ -0,0 +1,37 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div id="main" style="height: 1000px; width: 1000px;"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + window.scrollTo(0, 100); + assert_equals(window.scrollY, 100); + navigation.onnavigate = e => e.intercept( + { scroll: "after-transition", + handler: async () => { + if (e.navigationType == "push") { + // Inserting this <div> should scroll *after* the scroll position + // is saved, so that it doesn't break scroll restoration when going + // back. + let div = document.createElement("div"); + div.style = "height: 1000px; width: 1000px;"; + document.body.insertBefore(div, main); + } + } + } + ); + await navigation.navigate("?go").finished; + // Ensure the layout changes and scroll position update from the first + // navigation are processed before navigating back, otherwise the restored + // scroll postion can be overwritten. + await new Promise(resolve => requestAnimationFrame(resolve)); + await navigation.back().finished; + assert_equals(window.scrollY, 100); +}, "scroll: state should be saved before intercept handlers run"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-push.html b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-push.html new file mode 100644 index 0000000000..f3ee1827bc --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-push.html @@ -0,0 +1,29 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + + let intercept_resolve; + let navigate_event; + navigation.onnavigate = e => { + navigate_event = e; + e.intercept({ handler: () => new Promise(r => intercept_resolve = r), + scroll: "after-transition" }); + }; + let promises = navigation.navigate("#frag"); + await promises.committed; + assert_equals(window.scrollY, 0); + intercept_resolve(); + await promises.finished; + assert_not_equals(window.scrollY, 0); +}, "scroll: after-transition should work on a push navigation"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-reject.html b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-reject.html new file mode 100644 index 0000000000..5880dbb331 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-reject.html @@ -0,0 +1,23 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + await navigation.navigate("#frag").finished; + assert_not_equals(window.scrollY, 0); + navigation.onnavigate = + e => e.intercept({ handler: () => Promise.reject(), + scroll: "after-transition" }); + + await promise_rejects_exactly(t, undefined, navigation.back().finished); + assert_not_equals(window.scrollY, 0); +}, "scroll: after-transition should not scroll when the intercept() handler rejects"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-reload.html b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-reload.html new file mode 100644 index 0000000000..badb7e7f41 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-reload.html @@ -0,0 +1,41 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div id="buffer" style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<div style="height: 1000px; width: 1000px;"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + await navigation.navigate("#frag").finished; + // Scroll down 10px from #frag + window.scrollBy(0, 10); + let scrollY_frag_plus_10 = window.scrollY; + + let intercept_resolve; + let navigate_event; + navigation.onnavigate = e => { + navigate_event = e; + e.intercept({ handler: () => new Promise(r => intercept_resolve = r), + scroll: "after-transition" }); + }; + let reload_promises = navigation.reload(); + await reload_promises.committed; + + // removing the <div id="buffer"> should scroll up 1000px. + assert_equals(window.scrollY, scrollY_frag_plus_10); + buffer.remove(); + let scrollY_after_buffer_remove = window.scrollY; + assert_equals(scrollY_after_buffer_remove, scrollY_frag_plus_10 - 1000); + + // Finishing should scroll to #frag, which is 10px up from the current location + intercept_resolve(); + await reload_promises.finished; + assert_equals(window.scrollY, scrollY_after_buffer_remove - 10); +}, "scroll: after-transition should work on a reload navigation"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-replace.html b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-replace.html new file mode 100644 index 0000000000..48f153b99e --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-replace.html @@ -0,0 +1,29 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + + let intercept_resolve; + let navigate_event; + navigation.onnavigate = e => { + navigate_event = e; + e.intercept({ handler: () => new Promise(r => intercept_resolve = r), + scroll: "after-transition" }); + }; + let promises = navigation.navigate("#frag", { history: "replace" }); + await promises.committed; + assert_equals(window.scrollY, 0); + intercept_resolve(); + await promises.finished; + assert_not_equals(window.scrollY, 0); +}, "scroll: after-transition should work on a replace navigation"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-timing.html b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-timing.html new file mode 100644 index 0000000000..88ba82102a --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-timing.html @@ -0,0 +1,48 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + await navigation.navigate("#frag").finished; + assert_not_equals(window.scrollY, 0); + + window.onpopstate = t.step_func(() => assert_not_equals(window.scrollY, 0)); + window.onhashchange = t.step_func(() => assert_not_equals(window.scrollY, 0)); + + // The scroll restore should take place before navigatesuccess fires. + let navigatesuccess_called = false; + navigation.onnavigatesuccess = t.step_func(() => { + navigatesuccess_called = true; + assert_equals(window.scrollY, 0); + }); + + let back_promises = navigation.back(); + navigation.onnavigate = t.step_func(e => { + e.intercept({ scroll: "after-transition", + handler: async () => { + // The ordering here should be: + // * intercept() is called + // * back_promises.committed is resolved + // * this handler runs. + // If this handler incorrectly blocks back_promises.committed, + // this test will hang. + await back_promises.committed; + assert_not_equals(window.scrollY, 0); + } + }); + assert_not_equals(window.scrollY, 0); + }); + + await back_promises.finished; + assert_equals(window.scrollY, 0); + assert_true(navigatesuccess_called); +}, "scroll: after-transition should scroll when back completes, just before navigatesuccess"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-with-history-scroll-restoration-manual.html b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-with-history-scroll-restoration-manual.html new file mode 100644 index 0000000000..bc2ce230ce --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-with-history-scroll-restoration-manual.html @@ -0,0 +1,23 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + + history.scrollRestoration = "manual"; + await navigation.navigate("#frag").finished; + assert_not_equals(window.scrollY, 0); + + navigation.onnavigate = e => e.intercept({ scroll: "after-transition" }); + await navigation.back().finished; + assert_equals(window.scrollY, 0); +}, "scroll: after-transition should ignore history.scrollRestoration"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/manual-basic.html b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-basic.html new file mode 100644 index 0000000000..e6ae29ad86 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-basic.html @@ -0,0 +1,20 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + await navigation.navigate("#frag").finished; + assert_not_equals(window.scrollY, 0); + navigation.onnavigate = e => e.intercept({ scroll: "manual" }); + await navigation.back().finished; + assert_not_equals(window.scrollY, 0); +}, "scroll: manual should prevent auto scroll on back."); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/manual-immediate-scroll.html b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-immediate-scroll.html new file mode 100644 index 0000000000..bafcf6b256 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-immediate-scroll.html @@ -0,0 +1,24 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + await navigation.navigate("#frag").finished; + assert_not_equals(window.scrollY, 0); + navigation.onnavigate = e => { + e.intercept({ scroll: "manual" }); + assert_throws_dom("InvalidStateError", () => e.scroll()); + assert_not_equals(window.scrollY, 0); + } + await navigation.back().finished; + assert_not_equals(window.scrollY, 0); +}, "scroll: scroll() should not work inside a navigate event handler"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-after-dispatch.html b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-after-dispatch.html new file mode 100644 index 0000000000..8b4a58c7a2 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-after-dispatch.html @@ -0,0 +1,33 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + await navigation.navigate("#frag").finished; + assert_not_equals(window.scrollY, 0); + + let intercept_resolve; + let navigate_event; + navigation.onnavigate = e => { + navigate_event = e; + e.intercept({ handler: () => new Promise(r => intercept_resolve = r), + scroll: "manual" }); + }; + let back_promises = navigation.back(); + await back_promises.committed; + assert_not_equals(window.scrollY, 0); + navigate_event.scroll(); + assert_equals(window.scrollY, 0); + intercept_resolve(); + await back_promises.finished; + assert_equals(window.scrollY, 0); +}, "scroll: scroll() should work after a navigate event dispatch"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-after-resolve.html b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-after-resolve.html new file mode 100644 index 0000000000..244c93af90 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-after-resolve.html @@ -0,0 +1,27 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + await navigation.navigate("#frag").finished; + assert_not_equals(window.scrollY, 0); + + let navigate_event; + navigation.onnavigate = e => { + navigate_event = e; + e.intercept({ scroll: "manual" }); + }; + await navigation.back().finished; + assert_not_equals(window.scrollY, 0); + assert_throws_dom("InvalidStateError", () => navigate_event.scroll()); + assert_not_equals(window.scrollY, 0); +}, "scroll: scroll() should throw after a navigation finished promise fulfills"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-before-after-transition-commit.html b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-before-after-transition-commit.html new file mode 100644 index 0000000000..3b32e72bb1 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-before-after-transition-commit.html @@ -0,0 +1,32 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + await navigation.navigate("#frag").finished; + assert_not_equals(window.scrollY, 0); + navigation.onnavigate = e => { + e.intercept({ + scroll: "manual", + commit: "after-transition", + handler: t.step_func(() => { + assert_throws_dom("InvalidStateError", () => e.scroll()); + assert_not_equals(window.scrollY, 0); + e.commit(); + e.scroll(); + assert_equals(window.scrollY, 0); + }) + }); + } + await navigation.back().finished; + assert_equals(window.scrollY, 0); +}, "scroll: scroll() before commit()"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-fragment-does-not-exist.html b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-fragment-does-not-exist.html new file mode 100644 index 0000000000..1ca582787e --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-fragment-does-not-exist.html @@ -0,0 +1,32 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + await navigation.navigate("#frag").finished; + assert_not_equals(window.scrollY, 0); + + let intercept_resolve; + let navigate_event; + navigation.onnavigate = e => { + navigate_event = e; + e.intercept({ handler: () => new Promise(r => intercept_resolve = r), + scroll: "manual" }); + }; + let promises = navigation.navigate("#does-not-exist"); + await promises.committed; + assert_not_equals(window.scrollY, 0); + navigate_event.scroll(); + assert_not_equals(window.scrollY, 0); + intercept_resolve(); + await promises.finished; + assert_not_equals(window.scrollY, 0); +}, "scroll: scroll() should do nothing when the fragment does not exist"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-push.html b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-push.html new file mode 100644 index 0000000000..3c29365178 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-push.html @@ -0,0 +1,31 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + + let intercept_resolve; + let navigate_event; + navigation.onnavigate = e => { + navigate_event = e; + e.intercept({ handler: () => new Promise(r => intercept_resolve = r), + scroll: "manual" }); + }; + let promises = navigation.navigate("#frag"); + await promises.committed; + assert_equals(window.scrollY, 0); + navigate_event.scroll(); + assert_not_equals(window.scrollY, 0); + intercept_resolve(); + await promises.finished; + assert_not_equals(window.scrollY, 0); +}, "scroll: scroll() should work on a push navigation"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-reload.html b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-reload.html new file mode 100644 index 0000000000..6dd3fd8a38 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-reload.html @@ -0,0 +1,45 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div id="buffer" style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<div style="height: 1000px; width: 1000px;"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + await navigation.navigate("#frag").finished; + // Scroll down 10px from #frag + window.scrollBy(0, 10); + let scrollY_frag_plus_10 = window.scrollY; + + let intercept_resolve; + let navigate_event; + navigation.onnavigate = e => { + navigate_event = e; + e.intercept({ handler: () => new Promise(r => intercept_resolve = r), + scroll: "manual" }); + }; + let reload_promises = navigation.reload(); + await reload_promises.committed; + + // removing the <div id="buffer"> should scroll up 1000px. + assert_equals(window.scrollY, scrollY_frag_plus_10); + buffer.remove(); + let scrollY_after_buffer_remove = window.scrollY; + assert_equals(scrollY_after_buffer_remove, scrollY_frag_plus_10 - 1000); + + // scroll() should scroll to #frag, which is 10px up from the current location + navigate_event.scroll(); + assert_equals(window.scrollY, scrollY_after_buffer_remove - 10); + + // Finishing should not scroll. + intercept_resolve(); + await reload_promises.finished; + assert_equals(window.scrollY, scrollY_after_buffer_remove - 10); +}, "scroll: scroll() should work on a reload navigation"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-repeated.html b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-repeated.html new file mode 100644 index 0000000000..1239146088 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-repeated.html @@ -0,0 +1,29 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + await navigation.navigate("#frag").finished; + assert_not_equals(window.scrollY, 0); + navigation.onnavigate = e => { + e.intercept({ + scroll: "manual", + handler: t.step_func(() => { + e.scroll(); + assert_equals(window.scrollY, 0); + assert_throws_dom("InvalidStateError", () => e.scroll()); + }) + }); + }; + await navigation.back().finished; + assert_equals(window.scrollY, 0); +}, "scroll: scroll() should throw if called a second time"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-replace.html b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-replace.html new file mode 100644 index 0000000000..db580229a8 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-replace.html @@ -0,0 +1,31 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + assert_equals(window.scrollY, 0); + + let intercept_resolve; + let navigate_event; + navigation.onnavigate = e => { + navigate_event = e; + e.intercept({ handler: () => new Promise(r => intercept_resolve = r), + scroll: "manual" }); + }; + let promises = navigation.navigate("#frag", { history: "replace" }); + await promises.committed; + assert_equals(window.scrollY, 0); + navigate_event.scroll(); + assert_not_equals(window.scrollY, 0); + intercept_resolve(); + await promises.finished; + assert_not_equals(window.scrollY, 0); +}, "scroll: scroll() should work on a replace navigation"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-resets-when-no-fragment.html b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-resets-when-no-fragment.html new file mode 100644 index 0000000000..5401976f64 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-resets-when-no-fragment.html @@ -0,0 +1,33 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + let start_url = location.href; + await navigation.navigate("#frag").finished; + assert_not_equals(window.scrollY, 0); + + let intercept_resolve; + let navigate_event; + navigation.onnavigate = e => { + navigate_event = e; + e.intercept({ handler: () => new Promise(r => intercept_resolve = r), + scroll: "manual" }); + }; + let promises = navigation.navigate(start_url); + await promises.committed; + assert_not_equals(window.scrollY, 0); + navigate_event.scroll(); + assert_equals(window.scrollY, 0); + intercept_resolve(); + await promises.finished; + assert_equals(window.scrollY, 0); +}, "scroll: scroll() should reset scroll position when the destination url contains no fragment"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/scroll-after-preventDefault.html b/testing/web-platform/tests/navigation-api/scroll-behavior/scroll-after-preventDefault.html new file mode 100644 index 0000000000..d83d341feb --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/scroll-after-preventDefault.html @@ -0,0 +1,21 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + + navigation.addEventListener("navigate", t.step_func(e => { + e.intercept(); + e.preventDefault(); + assert_throws_dom("InvalidStateError", () => e.scroll()); + }), { once : true }); + await promise_rejects_dom(t, "AbortError", navigation.navigate("#frag").finished); +}, "scroll: scroll() should throw after preventDefault"); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/scroll-on-synthetic-event.html b/testing/web-platform/tests/navigation-api/scroll-behavior/scroll-on-synthetic-event.html new file mode 100644 index 0000000000..7efc2d1d98 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/scroll-on-synthetic-event.html @@ -0,0 +1,19 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<script> +promise_test(async t => { + // We need to grab an NavigationDestination to construct the event. + navigation.onnavigate = t.step_func_done(e => { + const event = new NavigateEvent("navigate", { + destination: e.destination, + signal: (new AbortController()).signal + }); + + assert_throws_dom("SecurityError", () => event.scroll()); + }); + history.pushState(1, null, "#1"); +}, "scroll: scroll() should throw if invoked on a synthetic event."); +</script> +</body> diff --git a/testing/web-platform/tests/navigation-api/scroll-behavior/scroll-without-intercept.html b/testing/web-platform/tests/navigation-api/scroll-behavior/scroll-without-intercept.html new file mode 100644 index 0000000000..b3958352c7 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/scroll-behavior/scroll-without-intercept.html @@ -0,0 +1,19 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<div style="height: 1000px; width: 1000px;"></div> +<div id="frag"></div> +<script> +promise_test(async t => { + // Wait for after the load event so that the navigation doesn't get converted + // into a replace navigation. + await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); + + navigation.addEventListener("navigate", t.step_func(e => { + assert_throws_dom("InvalidStateError", () => e.scroll()); + }), { once : true }); + await navigation.navigate("#frag").finished; +}, "scroll: scroll() should throw for non-intercept"); +</script> +</body> |