diff options
Diffstat (limited to 'testing/web-platform/tests/navigation-api/state')
9 files changed, 228 insertions, 0 deletions
diff --git a/testing/web-platform/tests/navigation-api/state/cross-document-away-and-back.html b/testing/web-platform/tests/navigation-api/state/cross-document-away-and-back.html new file mode 100644 index 0000000000..cccaebdf7b --- /dev/null +++ b/testing/web-platform/tests/navigation-api/state/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.navigate("#", { history: "replace", 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/state/cross-document-getState-undefined.html b/testing/web-platform/tests/navigation-api/state/cross-document-getState-undefined.html new file mode 100644 index 0000000000..cbd5cdd52e --- /dev/null +++ b/testing/web-platform/tests/navigation-api/state/cross-document-getState-undefined.html @@ -0,0 +1,17 @@ +<!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(() => { + assert_equals(i.contentWindow.navigation.entries().length, 1); + 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.entries()[0].getState(), undefined); + }); + }); +}, "Default behavior for entry.getState() for a non-current cross-document entry"); +</script> diff --git a/testing/web-platform/tests/navigation-api/state/cross-document-getState.html b/testing/web-platform/tests/navigation-api/state/cross-document-getState.html new file mode 100644 index 0000000000..aedbc471e0 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/state/cross-document-getState.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); + 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_not_equals(i.contentWindow.navigation.entries()[0].getState(), undefined); + assert_equals(i.contentWindow.navigation.entries()[0].getState().data, "value"); + }); + }); +}, "entry.getState() still works for a non-current cross-document entry"); +</script> diff --git a/testing/web-platform/tests/navigation-api/state/cross-document-location-api.html b/testing/web-platform/tests/navigation-api/state/cross-document-location-api.html new file mode 100644 index 0000000000..395d95c6fb --- /dev/null +++ b/testing/web-platform/tests/navigation-api/state/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.navigate("#", { history: "replace", 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/state/history-pushState.html b/testing/web-platform/tests/navigation-api/state/history-pushState.html new file mode 100644 index 0000000000..7d3c79ba6c --- /dev/null +++ b/testing/web-platform/tests/navigation-api/state/history-pushState.html @@ -0,0 +1,11 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +test(() => { + navigation.navigate("#", { history: "replace", 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/state/history-replaceState.html b/testing/web-platform/tests/navigation-api/state/history-replaceState.html new file mode 100644 index 0000000000..bdf3561639 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/state/history-replaceState.html @@ -0,0 +1,11 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +test(() => { + navigation.navigate("#", { history: "replace", 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/state/location-reload.html b/testing/web-platform/tests/navigation-api/state/location-reload.html new file mode 100644 index 0000000000..bf1bc105fb --- /dev/null +++ b/testing/web-platform/tests/navigation-api/state/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.navigate("#", { history: "replace", 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/state/same-document-away-and-back-location-api.html b/testing/web-platform/tests/navigation-api/state/same-document-away-and-back-location-api.html new file mode 100644 index 0000000000..d161df8b52 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/state/same-document-away-and-back-location-api.html @@ -0,0 +1,47 @@ +<!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" }; + await navigation.navigate("#1", { state: navState }); + let entry1 = navigation.currentEntry; + + location.href = "#2"; + let entry2 = navigation.currentEntry; + + assert_equals(navigation.entries().length, 3); + assert_equals(entry0, navigation.entries()[0]); + assert_equals(entry1, navigation.entries()[1]); + assert_equals(entry2, navigation.entries()[2]); + + assert_equals(entry0.getState(), undefined); + + let state1 = entry1.getState(); + assert_not_equals(state1, undefined); + assert_not_equals(state1, navState); + assert_equals(state1.statevar, "state"); + + let state2 = entry2.getState(); + assert_not_equals(state2, undefined); + assert_not_equals(state2, navState); + assert_equals(state2.statevar, "state"); + + history.back(); + window.onpopstate = t.step_func_done(() => { + assert_equals(navigation.entries().length, 3); + let back_entry = navigation.currentEntry; + assert_equals(back_entry, navigation.entries()[1]); + let back_state = back_entry.getState(); + assert_not_equals(back_state, state1); + assert_not_equals(back_state, state2); + assert_equals(back_state.statevar, "state"); + }); + }, 0); +}, "entry.getState() behavior after navigating away using a fragment change, then back"); +</script> diff --git a/testing/web-platform/tests/navigation-api/state/same-document-away-and-back-navigation-api.html b/testing/web-platform/tests/navigation-api/state/same-document-away-and-back-navigation-api.html new file mode 100644 index 0000000000..220908e4c4 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/state/same-document-away-and-back-navigation-api.html @@ -0,0 +1,53 @@ +<!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" }; + await navigation.navigate("#1", { state: navState }).committed; + let entry1 = navigation.currentEntry; + + navState.startvar2 = "otherstate"; + await navigation.navigate("#2", { state: navState }).committed; + let entry2 = navigation.currentEntry; + + t.step_func(() => { + assert_equals(navigation.entries().length, 3); + assert_equals(entry0, navigation.entries()[0]); + assert_equals(entry1, navigation.entries()[1]); + assert_equals(entry2, navigation.entries()[2]); + + assert_equals(entry0.getState(), undefined); + + let state1 = entry1.getState(); + assert_not_equals(state1, undefined); + assert_not_equals(state1, navState); + assert_equals(state1.statevar, "state"); + assert_equals(state1.startvar2, undefined); + + let state2 = entry2.getState(); + assert_not_equals(state2, undefined); + assert_not_equals(state2, navState); + assert_equals(state2.statevar, "state"); + assert_equals(state2.startvar2, "otherstate"); + + navigation.back(); + window.onpopstate = t.step_func_done(() => { + assert_equals(navigation.entries().length, 3); + let back_entry = navigation.currentEntry; + assert_equals(back_entry, navigation.entries()[1]); + let back_state = back_entry.getState(); + assert_not_equals(back_state, state1); + assert_not_equals(back_state, state2); + assert_equals(back_state.statevar, "state"); + assert_equals(back_state.startvar2, undefined); + }); + })(); + }, 0); +}, "entry.getState() behavior after navigating away using the navigation API, then back"); +</script> |