summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/navigation-api/updateCurrentEntry-method
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/navigation-api/updateCurrentEntry-method')
-rw-r--r--testing/web-platform/tests/navigation-api/updateCurrentEntry-method/basic.html25
-rw-r--r--testing/web-platform/tests/navigation-api/updateCurrentEntry-method/cross-document-away-and-back.html31
-rw-r--r--testing/web-platform/tests/navigation-api/updateCurrentEntry-method/cross-document-location-api.html20
-rw-r--r--testing/web-platform/tests/navigation-api/updateCurrentEntry-method/exception-order-initial-about-blank-unserializablestate.html13
-rw-r--r--testing/web-platform/tests/navigation-api/updateCurrentEntry-method/exception-order-not-fully-active-unserializablestate.html20
-rw-r--r--testing/web-platform/tests/navigation-api/updateCurrentEntry-method/history-pushState.html11
-rw-r--r--testing/web-platform/tests/navigation-api/updateCurrentEntry-method/history-replaceState.html11
-rw-r--r--testing/web-platform/tests/navigation-api/updateCurrentEntry-method/initial-about-blank.html13
-rw-r--r--testing/web-platform/tests/navigation-api/updateCurrentEntry-method/location-reload.html19
-rw-r--r--testing/web-platform/tests/navigation-api/updateCurrentEntry-method/no-args.html15
-rw-r--r--testing/web-platform/tests/navigation-api/updateCurrentEntry-method/not-fully-active.html20
-rw-r--r--testing/web-platform/tests/navigation-api/updateCurrentEntry-method/opaque-origin.html9
-rw-r--r--testing/web-platform/tests/navigation-api/updateCurrentEntry-method/resources/opaque-origin-page.html11
-rw-r--r--testing/web-platform/tests/navigation-api/updateCurrentEntry-method/same-document-away-and-back-location-api.html40
-rw-r--r--testing/web-platform/tests/navigation-api/updateCurrentEntry-method/unserializable.html29
15 files changed, 287 insertions, 0 deletions
diff --git a/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/basic.html b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/basic.html
new file mode 100644
index 0000000000..b4a49e5bf9
--- /dev/null
+++ b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/basic.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+async_test(t => {
+ navigation.onnavigate = t.unreached_func("navigate must not fire");
+ navigation.onnavigatesuccess = t.unreached_func("navigatesuccess must not fire");
+ navigation.onnavigateerror = t.unreached_func("navigateerror must not fire");
+
+ assert_equals(navigation.currentEntry.getState(), undefined, "Navigation API state starts out as undefined");
+ assert_equals(history.state, null, "history.state starts out as null");
+
+ const newState = { key: "value" };
+
+ navigation.updateCurrentEntry({ state: newState });
+
+ assert_equals(navigation.currentEntry.getState().key, "value");
+ assert_not_equals(navigation.currentEntry.getState(), newState);
+ assert_equals(history.state, null);
+
+ // Wait a tick to make sure no events fire asynchronously.
+ t.step_timeout(() => t.done(), 0);
+}, "updateCurrentEntry() works as expected");
+</script>
diff --git a/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/cross-document-away-and-back.html b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/cross-document-away-and-back.html
new file mode 100644
index 0000000000..c37d5e979a
--- /dev/null
+++ b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/cross-document-away-and-back.html
@@ -0,0 +1,31 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<iframe id="i" src="/common/blank.html"></iframe>
+<script>
+async_test(t => {
+ window.onload = t.step_func(() => {
+ i.contentWindow.navigation.updateCurrentEntry({ state: { data: "value" } });
+ assert_equals(i.contentWindow.navigation.entries().length, 1);
+ assert_equals(i.contentWindow.navigation.currentEntry.getState().data, "value");
+
+ let navigated_back = false;
+ i.contentWindow.navigation.navigate("?1");
+ i.onload = t.step_func(() => {
+ if (navigated_back) {
+ let back_entry = i.contentWindow.navigation.currentEntry;
+ assert_equals(i.contentWindow.navigation.entries().length, 2);
+ assert_equals(back_entry.index, 0);
+ assert_equals(back_entry.getState().data, "value");
+ t.done();
+ } else {
+ assert_equals(i.contentWindow.navigation.entries().length, 2);
+ assert_equals(i.contentWindow.navigation.currentEntry, i.contentWindow.navigation.entries()[1]);
+ assert_equals(i.contentWindow.navigation.currentEntry.getState(), undefined);
+ history.back();
+ navigated_back = true;
+ }
+ });
+ });
+}, "entry.getState() behavior after navigating away and back");
+</script>
diff --git a/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/cross-document-location-api.html b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/cross-document-location-api.html
new file mode 100644
index 0000000000..26191fb876
--- /dev/null
+++ b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/cross-document-location-api.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>
+async_test(t => {
+ window.onload = t.step_func(() => {
+ i.contentWindow.navigation.updateCurrentEntry({ state: { data: "value" } });
+ assert_equals(i.contentWindow.navigation.entries().length, 1);
+ assert_equals(i.contentWindow.navigation.currentEntry.getState().data, "value");
+
+ i.contentWindow.location.href = "?1";
+ i.onload = t.step_func_done(() => {
+ assert_equals(i.contentWindow.navigation.entries().length, 2);
+ assert_equals(i.contentWindow.navigation.currentEntry.index, 1);
+ assert_equals(i.contentWindow.navigation.currentEntry.getState(), undefined);
+ });
+ });
+}, "entry.getState() behavior after cross-document location API navigation");
+</script>
diff --git a/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/exception-order-initial-about-blank-unserializablestate.html b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/exception-order-initial-about-blank-unserializablestate.html
new file mode 100644
index 0000000000..010632a40f
--- /dev/null
+++ b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/exception-order-initial-about-blank-unserializablestate.html
@@ -0,0 +1,13 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<iframe id="iframe"></iframe>
+
+<script>
+test(() => {
+ assert_throws_dom("InvalidStateError", iframe.contentWindow.DOMException, () => {
+ iframe.contentWindow.navigation.updateCurrentEntry({ state: document.body });
+ });
+ assert_equals(navigation.currentEntry.getState(), undefined);
+}, `updateCurrentEntry() with unserializable state on the initial about:blank must throw an "InvalidStateError", not a "DataCloneError"`);
+</script>
diff --git a/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/exception-order-not-fully-active-unserializablestate.html b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/exception-order-not-fully-active-unserializablestate.html
new file mode 100644
index 0000000000..1e1c1e2bae
--- /dev/null
+++ b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/exception-order-not-fully-active-unserializablestate.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<iframe id="iframe" src="/common/blank.html"></iframe>
+
+<script>
+async_test(t => {
+ window.onload = t.step_func_done(() => {
+ const wNavigation = iframe.contentWindow.navigation;
+ const wDOMException = iframe.contentWindow.DOMException;
+
+ iframe.remove();
+
+ assert_throws_dom("InvalidStateError", wDOMException, () => {
+ wNavigation.updateCurrentEntry({ state: document.body });
+ });
+ assert_equals(navigation.currentEntry.getState(), undefined);
+ });
+}, `updateCurrentEntry() with unserializable state while not fully active must throw an "InvalidStateError", not a "DataCloneError"`);
+</script>
diff --git a/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/history-pushState.html b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/history-pushState.html
new file mode 100644
index 0000000000..852294c64f
--- /dev/null
+++ b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/history-pushState.html
@@ -0,0 +1,11 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+test(() => {
+ navigation.updateCurrentEntry({ state : { data : "value" } });
+ assert_equals(navigation.currentEntry.getState().data, "value");
+ history.pushState(1, "", "#push");
+ assert_equals(navigation.currentEntry.getState(), undefined);
+}, "entry.getState() after history.pushState()");
+</script>
diff --git a/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/history-replaceState.html b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/history-replaceState.html
new file mode 100644
index 0000000000..3eb91a9a80
--- /dev/null
+++ b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/history-replaceState.html
@@ -0,0 +1,11 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+test(() => {
+ navigation.updateCurrentEntry({ state : { data : "value" } });
+ assert_equals(navigation.currentEntry.getState().data, "value");
+ history.replaceState(1, "", "#replace");
+ assert_equals(navigation.currentEntry.getState(), undefined);
+}, "entry.getState() after history.replaceState()");
+</script>
diff --git a/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/initial-about-blank.html b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/initial-about-blank.html
new file mode 100644
index 0000000000..c28137c082
--- /dev/null
+++ b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/initial-about-blank.html
@@ -0,0 +1,13 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<iframe id="iframe"></iframe>
+
+<script>
+test(() => {
+ assert_throws_dom("InvalidStateError", iframe.contentWindow.DOMException, () => {
+ iframe.contentWindow.navigation.updateCurrentEntry({ state: 1 });
+ });
+ assert_equals(navigation.currentEntry.getState(), undefined);
+}, "updateCurrentEntry() must throw if the document is still on the initial about:blank");
+</script>
diff --git a/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/location-reload.html b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/location-reload.html
new file mode 100644
index 0000000000..8589eeb694
--- /dev/null
+++ b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/location-reload.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<iframe id="i" src="/common/blank.html"></iframe>
+<script>
+async_test(t => {
+ window.onload = t.step_func(() => {
+ i.contentWindow.navigation.updateCurrentEntry({ state: { data: "value" } });
+ assert_equals(i.contentWindow.navigation.entries().length, 1);
+ assert_equals(i.contentWindow.navigation.currentEntry.getState().data, "value");
+
+ i.contentWindow.location.reload();
+ i.onload = t.step_func_done(() => {
+ assert_equals(i.contentWindow.navigation.entries().length, 1);
+ assert_equals(i.contentWindow.navigation.currentEntry.getState().data, "value");
+ });
+ });
+}, "entry.getState() after location.reload()");
+</script>
diff --git a/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/no-args.html b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/no-args.html
new file mode 100644
index 0000000000..3fd011e3d3
--- /dev/null
+++ b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/no-args.html
@@ -0,0 +1,15 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+test(() => {
+ assert_throws_js(TypeError, () => {
+ navigation.updateCurrentEntry();
+ }, "no args");
+
+ assert_throws_js(TypeError, () => {
+ navigation.updateCurrentEntry({});
+ }, "empty dictionary");
+}, "updateCurrentEntry() must throw if state is not given");
+</script>
diff --git a/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/not-fully-active.html b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/not-fully-active.html
new file mode 100644
index 0000000000..fce5e72c8d
--- /dev/null
+++ b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/not-fully-active.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<iframe id="iframe" src="/common/blank.html"></iframe>
+
+<script>
+async_test(t => {
+ window.onload = t.step_func_done(() => {
+ const wNavigation = iframe.contentWindow.navigation;
+ const wDOMException = iframe.contentWindow.DOMException;
+
+ iframe.remove();
+
+ assert_throws_dom("InvalidStateError", wDOMException, () => {
+ wNavigation.updateCurrentEntry({ state: 1 });
+ });
+ assert_equals(navigation.currentEntry.getState(), undefined);
+ });
+}, "updateCurrentEntry() must throw if the document is not fully active");
+</script>
diff --git a/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/opaque-origin.html b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/opaque-origin.html
new file mode 100644
index 0000000000..898ca27e4f
--- /dev/null
+++ b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/opaque-origin.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<iframe id="i" sandbox="allow-scripts" src="resources/opaque-origin-page.html"></iframe>
+
+<script>
+fetch_tests_from_window(i.contentWindow);
+</script>
diff --git a/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/resources/opaque-origin-page.html b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/resources/opaque-origin-page.html
new file mode 100644
index 0000000000..59931458a6
--- /dev/null
+++ b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/resources/opaque-origin-page.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<!-- Put this page in a sandbox to give it an opaque origin -->
+
+<script>
+test(t => {
+ assert_throws_dom("InvalidStateError", () => {
+ navigation.updateCurrentEntry({ state: 1 });
+ });
+}, "navigation.updateCurrentEntry() in an opaque origin iframe");
+</script>
diff --git a/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/same-document-away-and-back-location-api.html b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/same-document-away-and-back-location-api.html
new file mode 100644
index 0000000000..47b1904f4f
--- /dev/null
+++ b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/same-document-away-and-back-location-api.html
@@ -0,0 +1,40 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+async_test(t => {
+ // Wait for after the load event so that the navigation doesn't get converted
+ // into a replace navigation.
+ window.onload = () => t.step_timeout(async () => {
+ let entry0 = navigation.currentEntry;
+
+ let navState = { statevar: "state" };
+ navigation.updateCurrentEntry({ state: navState });
+ assert_equals(navigation.currentEntry, entry0);
+
+ location.href = "#2";
+ let entry1 = navigation.currentEntry;
+
+ assert_equals(navigation.entries().length, 2);
+ assert_equals(entry0, navigation.entries()[0]);
+ assert_equals(entry1, navigation.entries()[1]);
+
+ assert_equals(entry0.getState().statevar, "state");
+ assert_not_equals(entry0.getState(), navState);
+
+ assert_equals(entry1.getState().statevar, "state");
+ assert_not_equals(entry1.getState(), navState);
+ assert_not_equals(entry1.getState(), entry0.getState());
+
+ history.back();
+ window.onpopstate = t.step_func_done(() => {
+ assert_equals(navigation.entries().length, 2);
+ let back_entry = navigation.currentEntry;
+ assert_equals(back_entry, entry0);
+ let back_state = back_entry.getState();
+ assert_not_equals(back_state, navState);
+ assert_equals(back_state.statevar, "state");
+ });
+ }, 0);
+}, "entry.getState() behavior after navigating away using the location API, then back");
+</script>
diff --git a/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/unserializable.html b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/unserializable.html
new file mode 100644
index 0000000000..596ab16d62
--- /dev/null
+++ b/testing/web-platform/tests/navigation-api/updateCurrentEntry-method/unserializable.html
@@ -0,0 +1,29 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<iframe id="iframe" src="/common/blank.html"></iframe>
+
+<script>
+setup({ explicit_done: true });
+
+window.onload = () => {
+ test(() => {
+ assert_throws_dom("DataCloneError", iframe.contentWindow.DOMException, () => {
+ iframe.contentWindow.navigation.updateCurrentEntry({ state: new WritableStream() });
+ });
+ assert_equals(navigation.currentEntry.getState(), undefined);
+ }, "updateCurrentEntry() must throw if state is unserializable (WritableStream)");
+
+ test(() => {
+ // See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
+ const buffer = new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer;
+
+ assert_throws_dom("DataCloneError", iframe.contentWindow.DOMException, () => {
+ iframe.contentWindow.navigation.updateCurrentEntry({ state: buffer });
+ });
+ assert_equals(navigation.currentEntry.getState(), undefined);
+ }, "updateCurrentEntry() must throw if state is unserializable (SharedArrayBuffer)");
+
+ done();
+};
+</script>