Truly independent web browser
LibWeb: Pass pushState() data as the classic history API state
Andreas Kling3aa1ae231a0a
diff --git a/Libraries/LibWeb/HTML/History.cpp b/Libraries/LibWeb/HTML/History.cppindex 92268549f77..3a31952428a 100644--- a/Libraries/LibWeb/HTML/History.cpp+++ b/Libraries/LibWeb/HTML/History.cpp@@ -211,7 +211,7 @@ WebIDL::ExceptionOr<void> History::shared_history_push_replace_state(JS::Realm&// with navigationType set to historyHandling, isSameDocument set to true, destinationURL set to newURL,// and classicHistoryAPIState set to serializedData.auto navigation_type = history_handling == HistoryHandlingBehavior::Push ? NavigationType::Push : NavigationType::Replace;- auto continue_ = navigation->fire_a_push_replace_reload_navigate_event(navigation_type, new_url, true, UserNavigationInvolvement::None, {}, {}, serialized_data);+ auto continue_ = navigation->fire_a_push_replace_reload_navigate_event(navigation_type, new_url, true, UserNavigationInvolvement::None, {}, {}, {}, serialized_data);// 9. If continue is false, then return.if (!continue_)return {};diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex feaf7b0eabe..43d05ac73da 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -837,6 +837,10 @@ Text/input/wpt-import/navigation-api/scroll-behavior/scroll-on-synthetic-event.hText/input/wpt-import/navigation-api/navigate-event/intercept-handler-throws.htmlText/input/wpt-import/navigation-api/navigate-event/intercept-reject.htmlText/input/wpt-import/navigation-api/navigate-event/intercept-multiple-times-reject.html+Text/input/wpt-import/navigation-api/navigate-event/navigate-history-pushState.html+Text/input/wpt-import/navigation-api/navigate-event/navigate-history-replaceState.html+Text/input/wpt-import/navigation-api/navigate-event/intercept-history-pushState.html+Text/input/wpt-import/navigation-api/navigate-event/intercept-history-replaceState.html; Runs ten iframes in turn: served from the test's origin, they stay in its process instead of each launching one.Text/input/HTML/parser-created-style-script-blocking.htmldiff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-history-pushState.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-history-pushState.txtnew file mode 100644index 00000000000..ea75744ce60--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-history-pushState.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass event.intercept() should proceed if the given promise resolves\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-history-replaceState.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-history-replaceState.txtnew file mode 100644index 00000000000..ea75744ce60--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-history-replaceState.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass event.intercept() should proceed if the given promise resolves\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-history-pushState.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-history-pushState.txtnew file mode 100644index 00000000000..04f82b499a5--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-history-pushState.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass history.pushState() fires the navigate event\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-history-replaceState.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-history-replaceState.txtnew file mode 100644index 00000000000..cf89c1dcb1a--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/navigate-history-replaceState.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass history.replaceState() fires the navigate event\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/intercept-history-pushState.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/intercept-history-pushState.htmlnew file mode 100644index 00000000000..964856e9fc4--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/intercept-history-pushState.html@@ -0,0 +1,28 @@+<!doctype html>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script>+async_test(t => {+ let start_length = history.length;++ let onpopstate_fired = false;+ window.onpopstate = e => onpopstate_fired = true;++ navigation.onnavigate = t.step_func(e => {+ e.intercept({ handler: async () => {+ await new Promise(r => t.step_timeout(r, 0));+ t.step_timeout(t.step_func_done(() => {+ assert_equals(location.hash, "#1");+ assert_equals(history.state, "update");+ assert_equals(history.length, start_length + 1);+ assert_false(onpopstate_fired);+ }, 0));+ }});+ });++ history.pushState("update", "", "#1");+ assert_equals(location.hash, "#1");+ assert_equals(history.state, "update");+ assert_equals(history.length, start_length + 1);+}, "event.intercept() should proceed if the given promise resolves");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/intercept-history-replaceState.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/intercept-history-replaceState.htmlnew file mode 100644index 00000000000..43cb4be2fd9--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/intercept-history-replaceState.html@@ -0,0 +1,23 @@+<!doctype html>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script>+async_test(t => {+ let start_length = history.length;+ navigation.onnavigate = t.step_func(e => {+ e.intercept({ handler: async () => {+ await new Promise(r => t.step_timeout(r, 0));+ t.step_timeout(t.step_func_done(() => {+ assert_equals(location.hash, "#1");+ assert_equals(history.state, "update");+ assert_equals(history.length, start_length);+ }, 0));+ }});+ });++ history.replaceState("update", "", "#1");+ assert_equals(location.hash, "#1");+ assert_equals(history.state, "update");+ assert_equals(history.length, start_length);+}, "event.intercept() should proceed if the given promise resolves");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-history-pushState.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-history-pushState.htmlnew file mode 100644index 00000000000..87db1cd80a6--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-history-pushState.html@@ -0,0 +1,30 @@+<!doctype html>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script>+async_test(t => {+ let start_length = history.length;+ navigation.onnavigate = t.step_func(e => {+ assert_equals(e.navigationType, "push");+ assert_true(e.cancelable);+ assert_true(e.canIntercept);+ assert_false(e.userInitiated);+ assert_false(e.hashChange);+ assert_equals(e.downloadRequest, null);+ assert_equals(new URL(e.destination.url).hash, "#1");+ assert_true(e.destination.sameDocument);+ assert_equals(e.destination.key, "");+ assert_equals(e.destination.id, "");+ assert_equals(e.destination.index, -1);+ assert_equals(e.formData, null);+ assert_equals(e.sourceElement, null);+ e.preventDefault();+ t.step_timeout(t.step_func_done(() => {+ assert_equals(location.hash, "");+ assert_equals(history.state, null);+ assert_equals(history.length, start_length);+ }), 0);+ });+ history.pushState(1, null, "#1");+}, "history.pushState() fires the navigate event");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-history-replaceState.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-history-replaceState.htmlnew file mode 100644index 00000000000..2b0e814e23c--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/navigate-history-replaceState.html@@ -0,0 +1,30 @@+<!doctype html>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script>+async_test(t => {+ let start_length = history.length;+ navigation.onnavigate = t.step_func(e => {+ assert_equals(e.navigationType, "replace");+ assert_true(e.cancelable);+ assert_true(e.canIntercept);+ assert_false(e.userInitiated);+ assert_false(e.hashChange);+ assert_equals(e.downloadRequest, null);+ assert_equals(new URL(e.destination.url).hash, "#1");+ assert_true(e.destination.sameDocument);+ assert_equals(e.destination.key, "");+ assert_equals(e.destination.id, "");+ assert_equals(e.destination.index, -1);+ assert_equals(e.formData, null);+ assert_equals(e.sourceElement, null);+ e.preventDefault();+ t.step_timeout(t.step_func_done(() => {+ assert_equals(location.hash, "");+ assert_equals(history.state, null);+ assert_equals(history.length, start_length);+ }), 0);+ });+ history.replaceState(1, null, "#1");+}, "history.replaceState() fires the navigate event");+</script>