diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/navigation-api/currententrychange-event | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/navigation-api/currententrychange-event')
23 files changed, 430 insertions, 0 deletions
diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/anchor-click.html b/testing/web-platform/tests/navigation-api/currententrychange-event/anchor-click.html new file mode 100644 index 0000000000..e0bf91166a --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/anchor-click.html @@ -0,0 +1,18 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<a id="a" href="#foo"></a> +<script> +test(t => { + let oncurrententrychange_called = false; + navigation.oncurrententrychange = t.step_func(e => { + oncurrententrychange_called = true; + assert_equals(e.from, navigation.entries()[0]); + assert_equals(e.from.index, 0); + assert_equals(e.navigationType, "push"); + assert_equals(navigation.currentEntry.index, 1); + }); + a.click(); + assert_true(oncurrententrychange_called); +}, "currententrychange fires for link click"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/constructor.html b/testing/web-platform/tests/navigation-api/currententrychange-event/constructor.html new file mode 100644 index 0000000000..b09e68e1c7 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/constructor.html @@ -0,0 +1,32 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +test(() => { + assert_throws_js(TypeError, () => { + new NavigationCurrentEntryChangeEvent("currententrychange"); + }); +}, "can't bypass required members by omitting the dictionary entirely"); + +test(() => { + assert_throws_js(TypeError, () => { + new NavigationCurrentEntryChangeEvent("currententrychange", { + navigationType: "push" + }); + }); +}, "from is required"); + +test(() => { + const event = new NavigationCurrentEntryChangeEvent("currententrychange", { + navigationType: "replace", + from: navigation.currentEntry + }); + assert_equals(event.navigationType, "replace"); + assert_equals(event.from, navigation.currentEntry); +}, "all properties are reflected back"); + +test(t => { + const event = new NavigationCurrentEntryChangeEvent("currententrychange", { from: navigation.currentEntry }); + assert_equals(event.navigationType, null); +}, "defaults are as expected"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/history-back-same-doc.html b/testing/web-platform/tests/navigation-api/currententrychange-event/history-back-same-doc.html new file mode 100644 index 0000000000..768805b752 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/history-back-same-doc.html @@ -0,0 +1,24 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<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("#foo"); + assert_equals(navigation.entries().length, 2); + + let oncurrententrychange_called = false; + navigation.oncurrententrychange = t.step_func(e => { + oncurrententrychange_called = true; + assert_equals(e.from, navigation.entries()[1]); + assert_equals(e.navigationType, "traverse"); + assert_equals(navigation.currentEntry.index, 0); + }); + history.back(); + assert_false(oncurrententrychange_called); + await new Promise(resolve => window.onpopstate = resolve); + assert_true(oncurrententrychange_called); +}, "currententrychange fires for history.back()"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/history-pushState.html b/testing/web-platform/tests/navigation-api/currententrychange-event/history-pushState.html new file mode 100644 index 0000000000..1a17a7cec0 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/history-pushState.html @@ -0,0 +1,16 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +test(t => { + let oncurrententrychange_called = false; + navigation.oncurrententrychange = t.step_func(e => { + oncurrententrychange_called = true; + assert_equals(e.from, navigation.entries()[0]); + assert_equals(e.navigationType, "push"); + assert_equals(navigation.currentEntry.index, 1); + }); + history.pushState(1, "", "#1"); + assert_true(oncurrententrychange_called); +}, "currententrychange fires for history.pushState()"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/history-replaceState.html b/testing/web-platform/tests/navigation-api/currententrychange-event/history-replaceState.html new file mode 100644 index 0000000000..e8ae8ee57a --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/history-replaceState.html @@ -0,0 +1,18 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +test(t => { + let oncurrententrychange_called = false; + let original_currentEntry = navigation.currentEntry; + navigation.oncurrententrychange = t.step_func(e => { + oncurrententrychange_called = true; + assert_equals(e.from, original_currentEntry); + assert_equals(e.from.index, -1); + assert_equals(e.navigationType, "replace"); + assert_equals(navigation.currentEntry.index, 0); + }); + history.replaceState(1, "", "#1"); + assert_true(oncurrententrychange_called); +}, "currententrychange fires for history.replaceState()"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/location-api.html b/testing/web-platform/tests/navigation-api/currententrychange-event/location-api.html new file mode 100644 index 0000000000..88ebd985a1 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/location-api.html @@ -0,0 +1,18 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +test(t => { + 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, 0); + }); + location.hash = "#foo"; + assert_true(oncurrententrychange_called); +}, "currententrychange fires for location API navigations"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/navigate-from-initial-about-blank-same-doc-popup.html b/testing/web-platform/tests/navigation-api/currententrychange-event/navigate-from-initial-about-blank-same-doc-popup.html new file mode 100644 index 0000000000..2399fb2ef9 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/navigate-from-initial-about-blank-same-doc-popup.html @@ -0,0 +1,15 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +promise_test(async t => { + const w = window.open("about:blank#1"); + w.navigation.oncurrententrychange = t.unreached_func("currententrychange should not fire"); + + assert_equals(w.location.href, "about:blank#1"); + w.location.href = "about:blank#2"; + assert_equals(w.location.href, "about:blank#2"); + + await new Promise(resolve => t.step_timeout(resolve, 10)); +}, "currententrychange does not fire when navigating away from the initial about:blank (popup window)"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/navigate-from-initial-about-blank-same-doc.html b/testing/web-platform/tests/navigation-api/currententrychange-event/navigate-from-initial-about-blank-same-doc.html new file mode 100644 index 0000000000..f0fa9cdf57 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/navigate-from-initial-about-blank-same-doc.html @@ -0,0 +1,12 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<iframe id="i"></iframe> +<script> +promise_test(async t => { + i.contentWindow.navigation.oncurrententrychange = t.unreached_func("currententrychange should not fire"); + i.contentWindow.location.href = "about:blank#1"; + i.contentWindow.location.href = "about:blank#2"; + await new Promise(resolve => t.step_timeout(resolve, 10)); +}, "currententrychange does not fire when navigating away from the initial about:blank"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/navigate-from-initial-about-blank.html b/testing/web-platform/tests/navigation-api/currententrychange-event/navigate-from-initial-about-blank.html new file mode 100644 index 0000000000..56eaa1af26 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/navigate-from-initial-about-blank.html @@ -0,0 +1,11 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<iframe id="i"></iframe> +<script> +promise_test(async t => { + i.contentWindow.navigation.oncurrententrychange = t.unreached_func("currententrychange should not fire"); + i.contentWindow.navigation.navigate("/common/blank.html"); + await new Promise(resolve => t.step_timeout(resolve, 10)); +}, "currententrychange does not fire when navigating away from the initial about:blank"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-back-forward-cross-doc.html b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-back-forward-cross-doc.html new file mode 100644 index 0000000000..7416caa94b --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-back-forward-cross-doc.html @@ -0,0 +1,20 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<iframe id="i" src="/common/blank.html"></iframe> +<script> +promise_test(async t => { + await new Promise(resolve => window.onload = resolve); + i.contentWindow.navigation.navigate("/common/blank.html?1"); + await new Promise(resolve => i.onload = resolve); + assert_equals(i.contentWindow.navigation.entries().length, 2); + + i.contentWindow.navigation.oncurrententrychange = t.unreached_func("currententrychange should not fire for cross-document navigations"); + i.contentWindow.navigation.back(); + await new Promise(resolve => i.onload = resolve); + + i.contentWindow.navigation.oncurrententrychange = t.unreached_func("currententrychange should not fire for cross-document navigations"); + i.contentWindow.navigation.forward(); + await new Promise(resolve => i.onload = resolve); +}, "currententrychange does not fire for cross-document navigation.back() and navigation.forward()"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-back-forward-same-doc.html b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-back-forward-same-doc.html new file mode 100644 index 0000000000..8182673aa5 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-back-forward-same-doc.html @@ -0,0 +1,40 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<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("#foo").committed; + assert_equals(navigation.entries().length, 2); + + let oncurrententrychange_back_called = false; + let back_committed = false; + navigation.oncurrententrychange = t.step_func(e => { + oncurrententrychange_back_called = true; + assert_equals(e.from, navigation.entries()[1]); + assert_equals(e.navigationType, "traverse"); + assert_equals(navigation.currentEntry.index, 0); + assert_false(back_committed); + }); + let back_result = navigation.back(); + assert_false(oncurrententrychange_back_called); + await back_result.committed.then(() => back_committed = true); + assert_true(oncurrententrychange_back_called); + + let oncurrententrychange_forward_called = false; + let forward_committed = false; + navigation.oncurrententrychange = t.step_func(e => { + oncurrententrychange_forward_called = true; + assert_equals(e.from, navigation.entries()[0]); + assert_equals(e.navigationType, "traverse"); + assert_equals(navigation.currentEntry.index, 1); + assert_false(forward_committed); + }); + let forward_result = navigation.forward(); + assert_false(oncurrententrychange_forward_called); + await forward_result.committed.then(() => forward_committed = true); + assert_true(oncurrententrychange_forward_called); +}, "currententrychange fires for same-document navigation.back() and navigation.forward()"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-cross-doc.html b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-cross-doc.html new file mode 100644 index 0000000000..81a4e239ba --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-cross-doc.html @@ -0,0 +1,12 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<iframe id="i" src="/common/blank.html"></iframe> +<script> +promise_test(async t => { + await new Promise(resolve => window.onload = resolve); + i.contentWindow.navigation.oncurrententrychange = t.unreached_func("currententrychange should not fire for cross-document navigations"); + i.contentWindow.navigation.navigate("/common/blank.html?1"); + await new Promise(resolve => i.onload = resolve); +}, "currententrychange does not fire for cross-document navigation.navigate()"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-intercept.html b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-intercept.html new file mode 100644 index 0000000000..af0fe104f9 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-intercept.html @@ -0,0 +1,21 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<iframe id="i" src="/common/blank.html"></iframe> +<script> +promise_test(async t => { + await new Promise(resolve => window.onload = resolve); + + let oncurrententrychange_called = false; + i.contentWindow.navigation.oncurrententrychange = t.step_func(e => { + oncurrententrychange_called = true; + assert_equals(e.from, i.contentWindow.navigation.entries()[0]); + assert_equals(e.navigationType, "push"); + assert_equals(i.contentWindow.navigation.currentEntry.index, 1); + }); + i.contentWindow.navigation.onnavigate = e => e.intercept(); + let result = i.contentWindow.navigation.navigate("/common/blank.html?1"); + assert_true(oncurrententrychange_called); + await result.committed; +}, "currententrychange fires for navigation.navigate() intercepted by intercept()"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-preventDefault.html b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-preventDefault.html new file mode 100644 index 0000000000..34b98353ba --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-preventDefault.html @@ -0,0 +1,10 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +promise_test(async t => { + navigation.oncurrententrychange = t.unreached_func("currententrychange should not fire"); + navigation.onnavigate = e => e.preventDefault(); + await promise_rejects_dom(t, "AbortError", navigation.navigate("#foo").committed); +}, "currententrychange does not fire when onnavigate preventDefault() is called"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-replace-cross-doc.html b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-replace-cross-doc.html new file mode 100644 index 0000000000..ab762c04bc --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-replace-cross-doc.html @@ -0,0 +1,12 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<iframe id="i" src="/common/blank.html"></iframe> +<script> +promise_test(async t => { + await new Promise(resolve => window.onload = resolve); + i.contentWindow.navigation.oncurrententrychange = t.unreached_func("currententrychange should not fire for cross-document navigations"); + i.contentWindow.navigation.navigate("/common/blank.html?1", { history: "replace" }); + await new Promise(resolve => i.onload = resolve); +}, "currententrychange does not fire for cross-document navigation.navigate() with replace"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-replace-intercept.html b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-replace-intercept.html new file mode 100644 index 0000000000..33209202d8 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-replace-intercept.html @@ -0,0 +1,23 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<iframe id="i" src="/common/blank.html"></iframe> +<script> +promise_test(async t => { + await new Promise(resolve => window.onload = resolve); + + let oncurrententrychange_called = false; + let original_entry = i.contentWindow.navigation.currentEntry; + i.contentWindow.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(i.contentWindow.navigation.currentEntry.index, 0); + }); + i.contentWindow.navigation.onnavigate = e => e.intercept(); + let result = i.contentWindow.navigation.navigate("/common/blank.html?1", { history: "replace" }); + assert_true(oncurrententrychange_called); + await result.committed; +}, "currententrychange fires for navigation.navigate() with replace intercepted by intercept()"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-replace-same-doc.html b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-replace-same-doc.html new file mode 100644 index 0000000000..f993597305 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-replace-same-doc.html @@ -0,0 +1,23 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<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 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, 0); + }); + let result = navigation.navigate("#foo", { history: "replace" }); + assert_true(oncurrententrychange_called); + await result.committed; +}, "currententrychange fires for navigation.navigate() with replace"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-same-doc.html b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-same-doc.html new file mode 100644 index 0000000000..87fc28d174 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-navigate-same-doc.html @@ -0,0 +1,21 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<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 oncurrententrychange_called = false; + navigation.oncurrententrychange = t.step_func(e => { + oncurrententrychange_called = true; + assert_equals(e.from, navigation.entries()[0]); + assert_equals(e.navigationType, "push"); + assert_equals(navigation.currentEntry.index, 1); + }); + let result = navigation.navigate("#foo"); + assert_true(oncurrententrychange_called); + await result.committed; +}, "currententrychange fires for navigation.navigate()"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-reload-cross-doc.html b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-reload-cross-doc.html new file mode 100644 index 0000000000..e590cab382 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-reload-cross-doc.html @@ -0,0 +1,12 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<iframe id="i" src="/common/blank.html"></iframe> +<script> +promise_test(async t => { + await new Promise(resolve => window.onload = resolve); + i.contentWindow.navigation.oncurrententrychange = t.unreached_func("currententrychange should not fire for cross-document navigations"); + i.contentWindow.navigation.reload(); + await new Promise(resolve => i.onload = resolve); +}, "currententrychange does not fire for cross-document navigation.reload()"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-reload-intercept.html b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-reload-intercept.html new file mode 100644 index 0000000000..275e23363c --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-reload-intercept.html @@ -0,0 +1,21 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<iframe id="i" src="/common/blank.html"></iframe> +<script> +promise_test(async t => { + await new Promise(resolve => window.onload = resolve); + + let oncurrententrychange_called = false; + i.contentWindow.navigation.oncurrententrychange = t.step_func(e => { + oncurrententrychange_called = true; + assert_equals(e.from, i.contentWindow.navigation.currentEntry); + assert_equals(e.navigationType, "reload"); + assert_equals(i.contentWindow.navigation.currentEntry.index, 0); + }); + i.contentWindow.navigation.onnavigate = e => e.intercept(); + let result = i.contentWindow.navigation.reload(); + assert_true(oncurrententrychange_called); + await result.committed; +}, "currententrychange fires for navigation.reload() intercepted by intercept()"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-updateCurrentEntry.html b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-updateCurrentEntry.html new file mode 100644 index 0000000000..4423b2bc90 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/navigation-updateCurrentEntry.html @@ -0,0 +1,20 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +test(t => { + let oncurrententrychange_count = 0; + navigation.oncurrententrychange = t.step_func(e => { + oncurrententrychange_count++; + assert_equals(e.from, navigation.currentEntry); + assert_equals(e.navigationType, null); + assert_equals(navigation.currentEntry.getState(), "newState"); + }); + navigation.updateCurrentEntry({ state: "newState" }); + assert_equals(oncurrententrychange_count, 1); + + // "Updating" the state to the current state should still fire currententrychange. + navigation.updateCurrentEntry({ state: navigation.currentEntry.getState() }); + assert_equals(oncurrententrychange_count, 2); +}, "currententrychange fires for navigation.updateCurrentEntry()"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/not-on-load.html b/testing/web-platform/tests/navigation-api/currententrychange-event/not-on-load.html new file mode 100644 index 0000000000..8cc1688913 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/not-on-load.html @@ -0,0 +1,17 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<!-- Per https://github.com/WICG/navigation-api/issues/31, make sure nothing happens on page loads --> + +<script> +async_test(t => { + navigation.onnavigate = t.unreached_func("navigate must not fire"); + navigation.oncurrententrychange = t.unreached_func("currententrychange must not fire"); + + // pageshow is the latest event in the normal document loading cycle. + // Ensure nothing happens even 10 ms afterward. + window.addEventListener("pageshow", () => t.step_timeout(() => { + t.done(); + }, 10)); +}, "No navigation API events happen on initial page load"); +</script> diff --git a/testing/web-platform/tests/navigation-api/currententrychange-event/properties.html b/testing/web-platform/tests/navigation-api/currententrychange-event/properties.html new file mode 100644 index 0000000000..e862543bcc --- /dev/null +++ b/testing/web-platform/tests/navigation-api/currententrychange-event/properties.html @@ -0,0 +1,14 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +async_test(t => { + navigation.oncurrententrychange = t.step_func_done(e => { + assert_equals(e.constructor, NavigationCurrentEntryChangeEvent); + assert_false(e.bubbles); + assert_false(e.cancelable); + assert_true(e.isTrusted); + }); + location.href = "#1"; +}, "NavigationCurrentEntryChangeEvent's properties"); +</script> |