Skip to content

Truly independent web browser

Tests/LibWeb: Import navigation API tests

Andreas Kling2f8fdaedbd8a
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index 1f10b4d8784..feaf7b0eabe 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -800,6 +800,43 @@ Text/input/wpt-import/navigation-api/navigate-event/navigation-traverseTo-in-ifr
Text/input/wpt-import/navigation-api/navigate-event/navigation-traverseTo-navigates-top-and-same-doc-child-and-cross-doc-child.html
Text/input/wpt-import/navigation-api/navigate-event/navigation-traverseTo-top-cancels-cross-document-child.html
Text/input/wpt-import/navigation-api/navigation-methods/back-forward-multiple-frames.html
+Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-back.html
+Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-forward.html
+Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-traverseTo-back-multiple.html
+Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-traverseTo-forward-multiple.html
+Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-addHandler.html
+Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-back-and-forth.html
+Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-new-navigation-before-commit.html
+Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-push.html
+Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-non-api-navigation.html
+Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-options.html
+Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-push-changed-to-replace.html
+Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-push.html
+Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-replace-changed-to-push.html
+Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-replace.html
+Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-reload.html
+Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-replace.html
+Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-traverse.html
+Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-uncancelable.html
+Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-basic.html
+Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-change-history-scroll-restoration-during-promise.html
+Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-explicit-scroll.html
+Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-intercept-handler-modifies.html
+Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-reload-after-traverse.html
+Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-fragment.html
+Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-scroll-anchoring.html
+Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-timing.html
+Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-no-fragment.html
+Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-to-fragment.html
+Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-after-dispatch.html
+Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-clears-target-when-fragment-does-not-exist.html
+Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-in-precommit-handler.html
+Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-reload-no-scroll-anchoring.html
+Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-repeated.html
+Text/input/wpt-import/navigation-api/scroll-behavior/scroll-on-synthetic-event.html
+Text/input/wpt-import/navigation-api/navigate-event/intercept-handler-throws.html
+Text/input/wpt-import/navigation-api/navigate-event/intercept-reject.html
+Text/input/wpt-import/navigation-api/navigate-event/intercept-multiple-times-reject.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.html
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-handler-throws.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-handler-throws.txt
new file mode 100644
index 00000000000..9a10c0ce139
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-handler-throws.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail event.intercept() should abort if the handler throws
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-multiple-times-reject.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-multiple-times-reject.txt
new file mode 100644
index 00000000000..863fb10fcdb
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-multiple-times-reject.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail event.intercept() is called multiple times and one of the promises rejects
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-reject.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-reject.txt
new file mode 100644
index 00000000000..34b53d5bb7e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-reject.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail event.intercept() should abort if the given promise rejects
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigation-methods/disambigaute-back.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigation-methods/disambigaute-back.txt
new file mode 100644
index 00000000000..b1d71a67f57
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigation-methods/disambigaute-back.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail navigation.back() goes to the nearest back entry
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigation-methods/disambigaute-forward.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigation-methods/disambigaute-forward.txt
new file mode 100644
index 00000000000..52cd680ff0a
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigation-methods/disambigaute-forward.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail navigation.forward() goes to the nearest forward entry
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigation-methods/disambigaute-traverseTo-back-multiple.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigation-methods/disambigaute-traverseTo-back-multiple.txt
new file mode 100644
index 00000000000..858f53b7239
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigation-methods/disambigaute-traverseTo-back-multiple.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail navigation.traverseTo() goes to the nearest entry when going back
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigation-methods/disambigaute-traverseTo-forward-multiple.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigation-methods/disambigaute-traverseTo-forward-multiple.txt
new file mode 100644
index 00000000000..65cbe41f499
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigation-methods/disambigaute-traverseTo-forward-multiple.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail navigation.traverseTo() goes to the nearest entry when going forward
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-addHandler.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-addHandler.txt
new file mode 100644
index 00000000000..76fdcdb203a
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-addHandler.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Fail
+Fail handler added in addHandler() delays navigation finish
+Fail handler added in addHandler() is executed in the correct order
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-back-and-forth.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-back-and-forth.txt
new file mode 100644
index 00000000000..5a8f1a83306
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-back-and-forth.txt
@@ -0,0 +1,8 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail
+ Test that going back and forward during a precommitHandler ends up in the
+ correct entry
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-new-navigation-before-commit.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-new-navigation-before-commit.txt
new file mode 100644
index 00000000000..d19e5739da9
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-new-navigation-before-commit.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail Cancel a navigation with a precommitHandler before commit by starting a new navigation
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-push.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-push.txt
new file mode 100644
index 00000000000..7703f6bf7d0
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-push.txt
@@ -0,0 +1,9 @@
+Harness status: OK
+
+Found 3 tests
+
+2 Pass
+1 Fail
+Fail precommitHandler for a push navigation, reject before commit
+Pass precommitHandler for a push navigation, reject after commit
+Pass precommitHandler for a push navigation, success
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-non-api-navigation.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-non-api-navigation.txt
new file mode 100644
index 00000000000..338e668491c
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-non-api-navigation.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Fail
+Fail precommitHandler redirect() on non-API navigation does not serialize state
+Fail precommitHandler redirect() with state on non-API navigation (link click)
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-options.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-options.txt
new file mode 100644
index 00000000000..8efe20865a4
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-options.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail precommitHandler redirect() with options dictionary
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-push-changed-to-replace.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-push-changed-to-replace.txt
new file mode 100644
index 00000000000..c572d1c885c
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-push-changed-to-replace.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail precommitHandler redirect() push changed to replace
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-push.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-push.txt
new file mode 100644
index 00000000000..77f08196901
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-push.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail precommitHandler redirect() push
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-replace-changed-to-push.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-replace-changed-to-push.txt
new file mode 100644
index 00000000000..52bbbd35674
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-replace-changed-to-push.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail precommitHandler redirect() replace changed to push
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-replace.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-replace.txt
new file mode 100644
index 00000000000..18dc304ba63
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-replace.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail precommitHandler redirect() replace
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-reload.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-reload.txt
new file mode 100644
index 00000000000..e923b62f3aa
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-reload.txt
@@ -0,0 +1,9 @@
+Harness status: OK
+
+Found 3 tests
+
+2 Pass
+1 Fail
+Fail precommitHandler for a reload navigation, reject before commit
+Pass precommitHandler for a reload navigation, reject after commit
+Pass precommitHandler for a reload navigation, success
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-replace.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-replace.txt
new file mode 100644
index 00000000000..a58310393b7
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-replace.txt
@@ -0,0 +1,9 @@
+Harness status: OK
+
+Found 3 tests
+
+2 Pass
+1 Fail
+Fail precommitHandler for a replace navigation, reject before commit
+Pass precommitHandler for a replace navigation, reject after commit
+Pass precommitHandler for a replace navigation, success
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-traverse.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-traverse.txt
new file mode 100644
index 00000000000..68cbd883159
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-traverse.txt
@@ -0,0 +1,8 @@
+Harness status: OK
+
+Found 3 tests
+
+3 Fail
+Fail precommitHandler for a traverse navigation, reject before commit
+Fail precommitHandler for a traverse navigation, reject after commit
+Fail precommitHandler for a traverse navigation, success
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-uncancelable.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-uncancelable.txt
new file mode 100644
index 00000000000..6c0b2631535
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/precommit-handler/precommitHandler-uncancelable.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail precommitHandler for an uncancelable traverse navigation
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-basic.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-basic.txt
new file mode 100644
index 00000000000..90ab27e696d
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-basic.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: after-transition should scroll when back completes
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-change-history-scroll-restoration-during-promise.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-change-history-scroll-restoration-during-promise.txt
new file mode 100644
index 00000000000..0f16b28db0e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-change-history-scroll-restoration-during-promise.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: after-transition should ignore history.scrollRestoration even if it changes in the middle of the navigation
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-explicit-scroll.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-explicit-scroll.txt
new file mode 100644
index 00000000000..cf86bfb5f8e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-explicit-scroll.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: scroll() should preempt after-transition
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-intercept-handler-modifies.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-intercept-handler-modifies.txt
new file mode 100644
index 00000000000..83dd010b762
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-intercept-handler-modifies.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: state should be saved before intercept handlers run
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-after-traverse.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-after-traverse.txt
new file mode 100644
index 00000000000..a4a6057f688
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-after-traverse.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: after-transition on a reload of a traversed-to fragment entry scrolls to the fragment
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-fragment.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-fragment.txt
new file mode 100644
index 00000000000..de7fb6a207a
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-fragment.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: after-transition on a reload without a fragment scrolls to the beginning of the document
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-scroll-anchoring.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-scroll-anchoring.txt
new file mode 100644
index 00000000000..7b28123096d
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-scroll-anchoring.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: after-transition should work on a reload navigation
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-timing.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-timing.txt
new file mode 100644
index 00000000000..e47a3715cc5
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-timing.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: after-transition should scroll when back completes, just before navigatesuccess
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-no-fragment.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-no-fragment.txt
new file mode 100644
index 00000000000..d76a9df4d5f
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-no-fragment.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: after-transition on a traverse to an entry without a fragment restores the scroll position
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-to-fragment.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-to-fragment.txt
new file mode 100644
index 00000000000..3b3ba53dff9
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-to-fragment.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: after-transition on a traverse to an entry with a fragment restores the scroll position
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-after-dispatch.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-after-dispatch.txt
new file mode 100644
index 00000000000..b037c22e2b5
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-after-dispatch.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: scroll() should work after a navigate event dispatch
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-clears-target-when-fragment-does-not-exist.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-clears-target-when-fragment-does-not-exist.txt
new file mode 100644
index 00000000000..fdc76cdc083
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-clears-target-when-fragment-does-not-exist.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: scroll() should clear the CSS :target element when the fragment does not exist
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-in-precommit-handler.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-in-precommit-handler.txt
new file mode 100644
index 00000000000..48a0ad11fa1
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-in-precommit-handler.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: scroll() in precommitHandler throws
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-reload-no-scroll-anchoring.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-reload-no-scroll-anchoring.txt
new file mode 100644
index 00000000000..e67bf158ad8
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-reload-no-scroll-anchoring.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: scroll() should work on a reload navigation
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-repeated.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-repeated.txt
new file mode 100644
index 00000000000..a30450775d4
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-repeated.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: scroll() should throw if called a second time
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/scroll-on-synthetic-event.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/scroll-on-synthetic-event.txt
new file mode 100644
index 00000000000..b34264d7c40
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/scroll-on-synthetic-event.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail scroll: scroll() should throw if invoked on a synthetic event.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/intercept-handler-throws.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/intercept-handler-throws.html
new file mode 100644
index 00000000000..accb9b70019
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/intercept-handler-throws.html
@@ -0,0 +1,26 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script>
+async_test(t => {
+ const err = new TypeError("a message");
+ let start_href = location.href;
+
+ navigation.onnavigatesuccess = t.step_func_done(assert_unreached);
+ navigation.onnavigateerror = t.step_func_done(e => {
+ assert_equals(location.hash, "#1");
+ assert_equals(e.constructor, ErrorEvent);
+ assert_true(e.error === err);
+ assert_true(e.message.includes("TypeError: a message"));
+ assert_equals(e.filename, start_href);
+ assert_greater_than(e.colno, 0);
+ assert_greater_than(e.lineno, 0);
+ });
+ navigation.onnavigate = e => {
+ e.intercept({ handler() { throw err; }});
+ };
+
+ location.href = "#1";
+ assert_equals(location.hash, "#1");
+}, "event.intercept() should abort if the handler throws");
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/intercept-multiple-times-reject.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/intercept-multiple-times-reject.html
new file mode 100644
index 00000000000..8bb90add6b4
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/intercept-multiple-times-reject.html
@@ -0,0 +1,38 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script>
+promise_test(async t => {
+ const err = new TypeError("a message");
+ let start_href = location.href;
+
+ let onnavigateerror_called = false;
+ let caught_rejection = false;
+ navigation.onnavigatesuccess = t.step_func(assert_unreached);
+ navigation.onnavigateerror = t.step_func(e => {
+ onnavigateerror_called = true;
+ assert_equals(location.hash, "#1");
+ assert_equals(e.constructor, ErrorEvent);
+ assert_equals(e.error, err);
+ assert_true(e.message.includes("TypeError: a message"));
+ assert_equals(e.filename, start_href);
+ assert_greater_than(e.colno, 0);
+ assert_greater_than(e.lineno, 0);
+ });
+ navigation.onnavigate = t.step_func(e => {
+ e.intercept();
+ e.intercept({ handler: async () => {
+ await new Promise(r => t.step_timeout(r, 1));
+ return Promise.reject(err);
+ }});
+ e.intercept({ handler: () => new Promise(resolve => t.step_timeout(resolve, 1)) });
+ });
+
+ await navigation.navigate("#1").finished.catch(t.step_func(e => {
+ caught_rejection = true;
+ assert_equals(e, err);
+ }));
+ assert_true(onnavigateerror_called);
+ assert_true(caught_rejection);
+}, "event.intercept() is called multiple times and one of the promises rejects");
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/intercept-reject.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/intercept-reject.html
new file mode 100644
index 00000000000..3204eb93c4d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigate-event/intercept-reject.html
@@ -0,0 +1,29 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script>
+async_test(t => {
+ const err = new TypeError("a message");
+ let start_href = location.href;
+
+ navigation.onnavigatesuccess = t.step_func_done(assert_unreached);
+ navigation.onnavigateerror = t.step_func_done(e => {
+ assert_equals(location.hash, "#1");
+ assert_equals(e.constructor, ErrorEvent);
+ assert_true(e.error === err);
+ assert_true(e.message.includes("TypeError: a message"));
+ assert_equals(e.filename, start_href);
+ assert_greater_than(e.colno, 0);
+ assert_greater_than(e.lineno, 0);
+ });
+ navigation.onnavigate = e => {
+ e.intercept({ handler: async () => {
+ await new Promise(r => t.step_timeout(r, 0));
+ return Promise.reject(err);
+ }});
+ };
+
+ location.href = "#1";
+ assert_equals(location.hash, "#1");
+}, "event.intercept() should abort if the given promise rejects");
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-back.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-back.html
new file mode 100644
index 00000000000..f678fb8182d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-back.html
@@ -0,0 +1,34 @@
+<!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 => {
+ let start_length = navigation.entries().length;
+ let start_index = navigation.currentEntry.index;
+ // Wait for after the load event so that the navigation doesn't get converted
+ // into a replace navigation.
+ window.onload = () => t.step_timeout(() => {
+ assert_equals(navigation.entries().length, start_length);
+ assert_equals(i.contentWindow.navigation.entries().length, 1);
+ navigation.navigate("#top");
+ assert_equals(navigation.entries().length, start_length+1);
+ assert_equals(i.contentWindow.navigation.entries().length, 1);
+ i.contentWindow.navigation.navigate("#1");
+ assert_equals(navigation.entries().length, start_length+1);
+ assert_equals(i.contentWindow.navigation.entries().length, 2);
+ assert_equals(navigation.currentEntry.index, start_index+1);
+ assert_equals(i.contentWindow.navigation.currentEntry.index, 1);
+ assert_true(navigation.canGoBack);
+ assert_true(i.contentWindow.navigation.canGoBack);
+
+ // There are 2 joint session history entries containing the iframe's
+ // previous key. Navigate to the nearest one (which navigates the iframe
+ // but not the top window).
+ i.contentWindow.navigation.back().committed.then(t.step_func_done(() => {
+ assert_equals(navigation.currentEntry.index, start_index+1);
+ assert_equals(i.contentWindow.navigation.currentEntry.index, 0);
+ }));
+ }, 0);
+}, "navigation.back() goes to the nearest back entry");
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-forward.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-forward.html
new file mode 100644
index 00000000000..329b65536a5
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-forward.html
@@ -0,0 +1,42 @@
+<!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 => {
+ let start_length = navigation.entries().length;
+ let start_index = navigation.currentEntry.index;
+ // Wait for after the load event so that the navigation doesn't get converted
+ // into a replace navigation.
+ window.onload = () => t.step_timeout(() => {
+ assert_equals(navigation.entries().length, start_length);
+ assert_equals(i.contentWindow.navigation.entries().length, 1);
+ navigation.navigate("#top");
+ assert_equals(navigation.entries().length, start_length+1);
+ assert_equals(i.contentWindow.navigation.entries().length, 1);
+ i.contentWindow.navigation.navigate("#1");
+ assert_equals(navigation.entries().length, start_length+1);
+ assert_equals(i.contentWindow.navigation.entries().length, 2);
+ assert_equals(navigation.currentEntry.index, start_index+1);
+ assert_equals(i.contentWindow.navigation.currentEntry.index, 1);
+ assert_true(navigation.canGoBack);
+ assert_true(i.contentWindow.navigation.canGoBack);
+
+ i.contentWindow.navigation.back().committed.then(t.step_func(() => {
+ assert_equals(navigation.currentEntry.index, start_index+1);
+ assert_equals(i.contentWindow.navigation.currentEntry.index, 0);
+ navigation.back().committed.then(t.step_func(() => {
+ assert_equals(navigation.currentEntry.index, start_index);
+ assert_equals(i.contentWindow.navigation.currentEntry.index, 0);
+ // There are 2 joint session history entries containing the top window's
+ // final key. Navigate to the nearest one (which navigates only the
+ // top window).
+ navigation.forward().committed.then(t.step_func_done(() => {
+ assert_equals(navigation.currentEntry.index, start_index+1);
+ assert_equals(i.contentWindow.navigation.currentEntry.index, 0);
+ }));
+ }));
+ }));
+ }, 0);
+}, "navigation.forward() goes to the nearest forward entry");
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-traverseTo-back-multiple.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-traverseTo-back-multiple.html
new file mode 100644
index 00000000000..fe94504b6e4
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-traverseTo-back-multiple.html
@@ -0,0 +1,37 @@
+<!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 => {
+ let start_length = navigation.entries().length;
+ let start_index = navigation.currentEntry.index;
+ // Wait for after the load event so that the navigation doesn't get converted
+ // into a replace navigation.
+ window.onload = () => t.step_timeout(() => {
+ assert_equals(navigation.entries().length, start_length);
+ assert_equals(i.contentWindow.navigation.entries().length, 1);
+ navigation.navigate("#top");
+ assert_equals(navigation.entries().length, start_length+1);
+ assert_equals(i.contentWindow.navigation.entries().length, 1);
+
+ let iframe_initial_key = i.contentWindow.navigation.currentEntry.key;
+ i.contentWindow.navigation.navigate("#1");
+ i.contentWindow.navigation.navigate("#2");
+ assert_equals(navigation.entries().length, start_length+1);
+ assert_equals(i.contentWindow.navigation.entries().length, 3);
+ assert_equals(navigation.currentEntry.index, start_index+1);
+ assert_equals(i.contentWindow.navigation.currentEntry.index, 2);
+ assert_true(navigation.canGoBack);
+ assert_true(i.contentWindow.navigation.canGoBack);
+
+ // There are 2 joint session history entries containing the iframe's
+ // initial key. Navigate to the nearest one (which navigates the iframe
+ // but not the top window).
+ i.contentWindow.navigation.traverseTo(iframe_initial_key).committed.then(t.step_func_done(() => {
+ assert_equals(navigation.currentEntry.index, start_index+1);
+ assert_equals(i.contentWindow.navigation.currentEntry.index, 0);
+ }));
+ }, 0);
+}, "navigation.traverseTo() goes to the nearest entry when going back");
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-traverseTo-forward-multiple.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-traverseTo-forward-multiple.html
new file mode 100644
index 00000000000..84fbbbe99b9
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/navigation-methods/disambigaute-traverseTo-forward-multiple.html
@@ -0,0 +1,41 @@
+<!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 => {
+ let start_length = navigation.entries().length;
+ let start_index = navigation.currentEntry.index;
+ // 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(navigation.entries().length, start_length);
+ assert_equals(i.contentWindow.navigation.entries().length, 1);
+ let initial_key = navigation.currentEntry.key;
+ await navigation.navigate("#top1").committed;
+ await navigation.navigate("#top2").committed;
+ assert_equals(navigation.entries().length, start_length+2);
+ assert_equals(i.contentWindow.navigation.entries().length, 1);
+ await i.contentWindow.navigation.navigate("#1").committed;
+ assert_equals(navigation.entries().length, start_length+2);
+ assert_equals(i.contentWindow.navigation.entries().length, 2);
+ assert_equals(navigation.currentEntry.index, start_index+2);
+ assert_equals(i.contentWindow.navigation.currentEntry.index, 1);
+ assert_true(navigation.canGoBack);
+ assert_true(i.contentWindow.navigation.canGoBack);
+ let final_key = navigation.currentEntry.key;
+
+ await i.contentWindow.navigation.back().committed;
+ assert_equals(navigation.currentEntry.index, start_index+2);
+ assert_equals(i.contentWindow.navigation.currentEntry.index, 0);
+ await navigation.traverseTo(initial_key).committed;
+ assert_equals(navigation.currentEntry.index, start_index);
+ assert_equals(i.contentWindow.navigation.currentEntry.index, 0);
+ // There are 2 joint session history entries containing the top window's
+ // final key. Navigate to the nearest one (which navigates only the
+ // top window).
+ await navigation.traverseTo(final_key).committed;
+ assert_equals(navigation.currentEntry.index, start_index+2);
+ assert_equals(i.contentWindow.navigation.currentEntry.index, 0);
+}, "navigation.traverseTo() goes to the nearest entry when going forward");
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-addHandler.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-addHandler.html
new file mode 100644
index 00000000000..013d9d043ad
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-addHandler.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+ <script>
+ promise_test(async (t) => {
+ let did_delay = false;
+ navigation.onnavigate = t.step_func((e) => {
+ e.intercept({
+ precommitHandler: (controller) =>
+ controller.addHandler(
+ t.step_func(
+ () =>
+ new Promise((resolve) =>
+ t.step_timeout(() => {
+ did_delay = true;
+ resolve();
+ }, 1)
+ )
+ )
+ ),
+ });
+ });
+ await navigation.navigate("#").finished;
+ assert_true(did_delay);
+ }, "handler added in addHandler() delays navigation finish");
+
+ promise_test(async (t) => {
+ const events = [];
+ navigation.onnavigate = t.step_func((e) => {
+ e.intercept({
+ precommitHandler: async (controller) => {
+ controller.addHandler(
+ t.step_func(() => {
+ events.push("added");
+ })
+ );
+ },
+ handler: t.step_func(() => {
+ events.push("handler1");
+ }),
+ });
+ e.intercept({
+ handler: t.step_func(() => {
+ events.push("handler2");
+ }),
+ });
+ });
+ await navigation.navigate("#").finished;
+ assert_array_equals(events, ["handler1", "handler2", "added"]);
+ }, "handler added in addHandler() is executed in the correct order");
+ </script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-back-and-forth.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-back-and-forth.html
new file mode 100644
index 00000000000..f610578fc60
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-back-and-forth.html
@@ -0,0 +1,35 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<title>
+ Test that going back and forward during a precommitHandler ends up in the
+ correct entry
+</title>
+<body>
+ <script>
+ promise_test(async (t) => {
+ await new Promise((resolve) => window.addEventListener("load", resolve));
+ const initial_entry = navigation.currentEntry;
+ await navigation.navigate("#a", { history: "push" }).finished;
+
+ navigation.addEventListener(
+ "navigate",
+ (event) => {
+ event.intercept({
+ precommitHandler: () =>
+ new Promise((resolve, reject) => {
+ event.signal.addEventListener("abort", () =>
+ reject(event.signal.reason),
+ );
+ }),
+ });
+ },
+ { once: true },
+ );
+
+ history.pushState(null, null, "#b");
+ await navigation.back().finished;
+ assert_equals(navigation.currentEntry, initial_entry);
+ });
+ </script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-new-navigation-before-commit.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-new-navigation-before-commit.html
new file mode 100644
index 00000000000..94c5e3e266d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-new-navigation-before-commit.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../navigation-methods/return-value/resources/helpers.js"></script>
+<body>
+<script>
+promise_test(async t => {
+ navigation.addEventListener("navigate", e => e.intercept({ precommitHandler: async () => {} }), { once: "true" });
+
+ let navigateerror_called = false;
+ navigation.onnavigateerror = t.step_func(() => {
+ navigateerror_called = true;
+ assert_equals(location.hash, "");
+ });
+
+ let promises_should_not_commit = navigation.navigate("#ShouldNotCommit");
+ let promises_fulfilled = navigation.navigate("#1");
+ await assertBothRejectDOM(t, promises_should_not_commit, "AbortError");
+ await assertBothFulfill(t, promises_fulfilled, navigation.currentEntry);
+
+ assert_equals(location.hash, "#1");
+ assert_true(navigateerror_called);
+}, "Cancel a navigation with a precommitHandler before commit by starting a new navigation");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-push.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-push.html
new file mode 100644
index 00000000000..e7e023c1aab
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-push.html
@@ -0,0 +1,22 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../navigation-methods/return-value/resources/helpers.js"></script>
+<script src="resources/precommitHandler-helpers.js"></script>
+<body>
+<script>
+let tests = [
+ { mode: "rejectBeforeCommit", description: "precommitHandler for a push navigation, reject before commit" },
+ { mode: "rejectAfterCommit", description: "precommitHandler for a push navigation, reject after commit" },
+ { mode: "success", description: "precommitHandler for a push navigation, success" },
+];
+
+let onload_promise = new Promise(resolve => window.onload = resolve);
+for (let test of tests) {
+ promise_test(async t => {
+ await onload_promise;
+ await testDeferredCommit(t, "push", test.mode);
+ }, test.description);
+}
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-non-api-navigation.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-non-api-navigation.html
new file mode 100644
index 00000000000..3167b499f36
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-non-api-navigation.html
@@ -0,0 +1,51 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<a id="link" href="#link-target"></a>
+<body>
+<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_length = navigation.entries().length;
+ let navState = { baz: "qux" };
+
+ navigation.onnavigate = t.step_func(e => {
+ e.intercept({
+ precommitHandler: t.step_func(controller => {
+ controller.redirect("#redirected", { state: navState });
+ }),
+ });
+ });
+
+ location.hash = "#hash-target";
+ await navigation.transition.finished;
+
+ assert_equals(location.hash, "#redirected");
+ // State serialization is a no-op for non-API navigations because there is
+ // no ongoing API method tracker.
+ assert_equals(navigation.currentEntry.getState(), undefined);
+}, "precommitHandler redirect() on non-API navigation does not serialize state");
+
+promise_test(async t => {
+ let start_length = navigation.entries().length;
+ let navState = { foo: "bar" };
+
+ navigation.onnavigate = t.step_func(e => {
+ e.intercept({
+ precommitHandler: t.step_func(controller => {
+ controller.redirect("#link-redirected", { state: navState });
+ }),
+ });
+ });
+
+ document.getElementById("link").click();
+ await navigation.transition.finished;
+
+ assert_equals(location.hash, "#link-redirected");
+ assert_equals(navigation.currentEntry.getState(), undefined);
+}, "precommitHandler redirect() with state on non-API navigation (link click)");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-options.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-options.html
new file mode 100644
index 00000000000..3972ba1b5c3
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-options.html
@@ -0,0 +1,81 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<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_length = navigation.entries().length;
+ let start_hash = location.hash;
+
+ let navInfo0 = { nav : "info0" };
+ let navState0 = { statevar: "state0" };
+
+ let navInfo1 = { nav : "info1" };
+ let navState1 = { statevar: "state1" };
+
+ let navInfo2 = { nav : "info2" };
+ let navState2 = { statevar: "state2" };
+
+ navigation.onnavigate = t.step_func(e => {
+ e.intercept({
+ precommitHandler: t.step_func(controller => {
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#push");
+ assert_equals(e.info, navInfo0);
+ assert_not_equals(e.destination.getState(), navState0);
+ assert_equals(e.destination.getState().statevar, navState0.statevar);
+
+ // Redirect without options should not overwrite the original options.
+ controller.redirect("#redirect0");
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#redirect0");
+ assert_equals(e.info, navInfo0);
+ assert_not_equals(e.destination.getState(), navState0);
+ assert_equals(e.destination.getState().statevar, navState0.statevar);
+
+ // Update both info and state.
+ controller.redirect("#redirect1", { info: navInfo1, state: navState1});
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#redirect1");
+ assert_equals(e.info, navInfo1);
+ assert_not_equals(e.destination.getState(), navState1);
+ assert_equals(e.destination.getState().statevar, navState1.statevar);
+
+ // Update just info
+ controller.redirect("#redirect2", { info: navInfo2 });
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#redirect2");
+ assert_equals(e.info, navInfo2);
+ assert_not_equals(e.destination.getState(), navState1);
+ assert_equals(e.destination.getState().statevar, navState1.statevar);
+
+ // Update just state - this also tests the case where the url does
+ // not change.
+ controller.redirect("#redirect2", { state: navState2 });
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#redirect2");
+ assert_equals(e.info, navInfo2);
+ assert_not_equals(e.destination.getState(), navState2);
+ assert_equals(e.destination.getState().statevar, navState2.statevar);
+
+ // Explicit undefined is treated as absent.
+ controller.redirect("#redirect2", { info: undefined, state: undefined });
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#redirect2");
+ assert_equals(e.info, navInfo2);
+ assert_not_equals(e.destination.getState(), navState2);
+ assert_equals(e.destination.getState().statevar, navState2.statevar);
+ }),
+ });
+ });
+ await navigation.navigate("#push", { info: navInfo0, state: navState0 }).committed;
+ assert_equals(location.hash, "#redirect2");
+ assert_equals(navigation.entries().length, start_length + 1);
+ assert_equals(navigation.currentEntry.getState().statevar, navState2.statevar);
+}, "precommitHandler redirect() with options dictionary");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-push-changed-to-replace.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-push-changed-to-replace.html
new file mode 100644
index 00000000000..774ecbc6bdc
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-push-changed-to-replace.html
@@ -0,0 +1,30 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<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_length = navigation.entries().length;
+ let start_hash = location.hash;
+ navigation.onnavigate = t.step_func(e => {
+ e.intercept({
+ precommitHandler: t.step_func(controller => {
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#push");
+
+ controller.redirect("#redirect1", { history: "replace" });
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#redirect1");
+ }),
+ });
+ });
+ await navigation.navigate("#push").committed;
+ assert_equals(location.hash, "#redirect1");
+ assert_equals(navigation.entries().length, start_length);
+}, "precommitHandler redirect() push changed to replace");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-push.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-push.html
new file mode 100644
index 00000000000..d7e35cc8e61
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-push.html
@@ -0,0 +1,34 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<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_length = navigation.entries().length;
+ let start_hash = location.hash;
+ navigation.onnavigate = t.step_func(e => {
+ e.intercept({
+ precommitHandler: t.step_func(controller => {
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#push");
+
+ controller.redirect("#redirect1");
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#redirect1");
+
+ controller.redirect("#redirect2");
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#redirect2");
+ }),
+ });
+ });
+ await navigation.navigate("#push").committed;
+ assert_equals(location.hash, "#redirect2");
+ assert_equals(navigation.entries().length, start_length + 1);
+}, "precommitHandler redirect() push");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-replace-changed-to-push.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-replace-changed-to-push.html
new file mode 100644
index 00000000000..27ba08b2499
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-replace-changed-to-push.html
@@ -0,0 +1,30 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<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_length = navigation.entries().length;
+ let start_hash = location.hash;
+ navigation.onnavigate = t.step_func(e => {
+ e.intercept({
+ precommitHandler: t.step_func(controller => {
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#replace");
+
+ controller.redirect("#redirect1", { history: "push" });
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#redirect1");
+ }),
+ });
+ });
+ await navigation.navigate("#replace", { history: "replace" }).committed;
+ assert_equals(location.hash, "#redirect1");
+ assert_equals(navigation.entries().length, start_length + 1);
+}, "precommitHandler redirect() replace changed to push");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-replace.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-replace.html
new file mode 100644
index 00000000000..a10bf23b4b1
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-redirect-replace.html
@@ -0,0 +1,34 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<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_length = navigation.entries().length;
+ let start_hash = location.hash;
+ navigation.onnavigate = t.step_func(e => {
+ e.intercept({
+ precommitHandler: t.step_func(controller => {
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#replace");
+
+ controller.redirect("#redirect1");
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#redirect1");
+
+ controller.redirect("#redirect2");
+ assert_equals(location.hash, start_hash);
+ assert_equals(new URL(e.destination.url).hash, "#redirect2");
+ }),
+ });
+ });
+ await navigation.navigate("#replace", { history: "replace" }).committed;
+ assert_equals(location.hash, "#redirect2");
+ assert_equals(navigation.entries().length, start_length);
+}, "precommitHandler redirect() replace");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-reload.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-reload.html
new file mode 100644
index 00000000000..dbb25fb157c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-reload.html
@@ -0,0 +1,18 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../navigation-methods/return-value/resources/helpers.js"></script>
+<script src="resources/precommitHandler-helpers.js"></script>
+<body>
+<script>
+let tests = [
+ { mode: "rejectBeforeCommit", description: "precommitHandler for a reload navigation, reject before commit" },
+ { mode: "rejectAfterCommit", description: "precommitHandler for a reload navigation, reject after commit" },
+ { mode: "success", description: "precommitHandler for a reload navigation, success" },
+];
+
+for (let test of tests) {
+ promise_test(t => testDeferredCommit(t, "reload", test.mode), test.description);
+}
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-replace.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-replace.html
new file mode 100644
index 00000000000..d558c5bfc07
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-replace.html
@@ -0,0 +1,18 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../navigation-methods/return-value/resources/helpers.js"></script>
+<script src="resources/precommitHandler-helpers.js"></script>
+<body>
+<script>
+let tests = [
+ { mode: "rejectBeforeCommit", description: "precommitHandler for a replace navigation, reject before commit" },
+ { mode: "rejectAfterCommit", description: "precommitHandler for a replace navigation, reject after commit" },
+ { mode: "success", description: "precommitHandler for a replace navigation, success" },
+];
+
+for (let test of tests) {
+ promise_test(t => testDeferredCommit(t, "replace", test.mode), test.description);
+}
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-traverse.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-traverse.html
new file mode 100644
index 00000000000..0a2e6c561e3
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-traverse.html
@@ -0,0 +1,35 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../navigation-methods/return-value/resources/helpers.js"></script>
+<script src="resources/precommitHandler-helpers.js"></script>
+<body>
+<script>
+let start_index = navigation.currentEntry.index;
+
+// Note that `destinationIndex` is chosen relative to `start_index`, and the
+// tests begin at `start_index` + 4. So:
+// * "rejectBeforeCommit" will try to go back 4 steps and fail.
+// * "rejectAfterCommit" will go back 3 steps, then reject after commit.
+// * "success" will go forward 2 steps
+let tests = [
+ { mode: "rejectBeforeCommit", destinationIndex: start_index, description: "precommitHandler for a traverse navigation, reject before commit" },
+ { mode: "rejectAfterCommit", destinationIndex: start_index + 1, description: "precommitHandler for a traverse navigation, reject after commit" },
+ { mode: "success", destinationIndex: start_index + 3, description: "precommitHandler for a traverse navigation, success" }
+];
+
+// Push a bunch of history entries so each test case can target a unique entry.
+history.pushState("", "", "#1");
+history.pushState("", "", "#2");
+history.pushState("", "", "#3");
+history.pushState("", "", "#4");
+
+let onload_promise = new Promise(resolve => window.onload = resolve);
+for (let test of tests) {
+ promise_test(async t => {
+ await onload_promise;
+ await testDeferredCommit(t, "traverse", test.mode, test.destinationIndex);
+ }, test.description);
+}
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-uncancelable.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-uncancelable.html
new file mode 100644
index 00000000000..5aa4c000e2b
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/precommitHandler-uncancelable.html
@@ -0,0 +1,24 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<iframe id="i" src="../../common/blank.html"></iframe>
+<body>
+<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 i.contentWindow.navigation.navigate("#1").finished;
+
+ i.contentWindow.navigation.onnavigate = t.step_func(e => {
+ assert_false(e.cancelable);
+ // intercept() with a precommitHandler is forbidden because e.cancelable is false.
+ let iframe_constructor = i.contentWindow.DOMException;
+ assert_throws_dom("InvalidStateError", iframe_constructor,
+ () => e.intercept({ precommitHandler: async () => {} }));
+ });
+ await i.contentWindow.navigation.back().finished;
+}, "precommitHandler for an uncancelable traverse navigation");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/resources/precommitHandler-helpers.js b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/resources/precommitHandler-helpers.js
new file mode 100644
index 00000000000..1338617681f
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/precommit-handler/resources/precommitHandler-helpers.js
@@ -0,0 +1,93 @@
+window.testDeferredCommit = async (t, navigationType, mode, destinationIndex = 0) => {
+ let startHash = location.hash;
+ let destinationHash;
+ const err = new Error("boo!");
+
+ let popstate_fired = false;
+ window.addEventListener("popstate", () => popstate_fired = true, { once : true });
+ let navigatesuccess_fired = false;
+ navigation.addEventListener("navigatesuccess", () => navigatesuccess_fired = true, { once : true });
+ let navigateerror_fired = false;
+ navigation.addEventListener("navigateerror", () => navigateerror_fired = true, { once : true });
+
+ // mode-specific logic for the navigate event handler
+ let navigate_helpers = {
+ rejectBeforeCommit : async (e) => { return Promise.reject("Should never run") },
+ rejectAfterCommit : async (e) => {
+ assert_equals(location.hash, destinationHash, "hash after commit");
+ assert_equals(false, popstate_fired, "popstate before handler starts");
+ await new Promise(resolve => t.step_timeout(resolve, 0));
+ assert_equals(navigationType == "traverse", popstate_fired, "popstate fired after handler async step");
+ return Promise.reject(err);
+ },
+ success : async (e) => {
+ assert_equals(location.hash, destinationHash, "hash after commit");
+ assert_equals(false, popstate_fired, "popstate before handler starts");
+ await new Promise(resolve => t.step_timeout(resolve, 0));
+ assert_equals(navigationType == "traverse", popstate_fired, "popstate fired after handler async step");
+ return new Promise(resolve => t.step_timeout(resolve, 0));
+ },
+ }
+
+ navigation.addEventListener("navigate", e => {
+ e.intercept({ precommitHandler: t.step_func(async () => {
+ assert_equals(e.navigationType, navigationType);
+ assert_equals(location.hash, startHash, "start hash");
+ assert_false(popstate_fired, "popstate fired at handler start");
+
+ await new Promise(resolve => t.step_timeout(resolve, 0));
+ assert_equals(location.hash, startHash, "hash after first async step");
+ assert_false(popstate_fired, "popstate fired after first async step");
+
+ if (mode == "rejectBeforeCommit")
+ return Promise.reject(err);
+ }),
+ handler: t.step_func(navigate_helpers[mode])
+ });
+ }, { once: true });
+
+ let startingIndex = navigation.currentEntry.index;
+ let expectedIndexOnCommit;
+
+ let promises;
+ if (navigationType === "push" || navigationType === "replace") {
+ destinationHash = (startHash === "" ? "#" : startHash) + "a";
+ promises = navigation.navigate(destinationHash, { history: navigationType });
+ expectedIndexOnCommit = (navigationType === "push") ? startingIndex + 1
+ : startingIndex;
+ } else if (navigationType === "reload") {
+ destinationHash = startHash;
+ promises = navigation.reload();
+ expectedIndexOnCommit = startingIndex;
+ } else if (navigationType === "traverse") {
+ let destinationEntry = navigation.entries()[destinationIndex];
+ destinationHash = new URL(destinationEntry.url).hash;
+ promises = navigation.traverseTo(destinationEntry.key);
+ expectedIndexOnCommit = destinationIndex;
+ }
+
+ if (mode === "rejectBeforeCommit") {
+ await assertBothRejectExactly(t, promises, err);
+ assert_equals(location.hash, startHash, "hash after promise resolution");
+ assert_false(popstate_fired, "popstate fired after promise resolution");
+ assert_false(navigatesuccess_fired, "navigatesuccess fired");
+ assert_true(navigateerror_fired, "navigateerror fired");
+ assert_equals(navigation.currentEntry.index, startingIndex);
+ } else if (mode === "rejectAfterCommit") {
+ await promises.committed;
+ await assertCommittedFulfillsFinishedRejectsExactly(t, promises, navigation.currentEntry, err);
+ assert_equals(location.hash, destinationHash, "hash after promise resolution");
+ assert_equals(navigationType == "traverse", popstate_fired, "popstate fired after promise resolution");
+ assert_false(navigatesuccess_fired, "navigatesuccess fired");
+ assert_true(navigateerror_fired, "navigateerror fired");
+ assert_equals(navigation.currentEntry.index, expectedIndexOnCommit);
+ } else {
+ await promises.committed;
+ await assertBothFulfill(t, promises, navigation.currentEntry);
+ assert_equals(location.hash, destinationHash, "hash after promise resolution");
+ assert_equals(navigationType == "traverse", popstate_fired, "popstate fired after promise resolution");
+ assert_true(navigatesuccess_fired, "navigatesuccess fired");
+ assert_false(navigateerror_fired, "navigateerror fired");
+ assert_equals(navigation.currentEntry.index, expectedIndexOnCommit);
+ }
+}
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-basic.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-basic.html
new file mode 100644
index 00000000000..240b05e72eb
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-basic.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<div style="height: 200vh; width: 200vw;"></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/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-change-history-scroll-restoration-during-promise.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-change-history-scroll-restoration-during-promise.html
new file mode 100644
index 00000000000..d75bb71f37f
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-change-history-scroll-restoration-during-promise.html
@@ -0,0 +1,33 @@
+<!doctype html>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<div style="height: 200vh; width: 200vw;"></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/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-explicit-scroll.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-explicit-scroll.html
new file mode 100644
index 00000000000..d66e0473230
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-explicit-scroll.html
@@ -0,0 +1,30 @@
+<!doctype html>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<div style="height: 200vh; width: 200vw;"></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/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-intercept-handler-modifies.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-intercept-handler-modifies.html
new file mode 100644
index 00000000000..c9df7d06fdc
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-intercept-handler-modifies.html
@@ -0,0 +1,38 @@
+<!doctype html>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<div id="main" style="height: 200vh; width: 200vw;"></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/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-reload-after-traverse.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-reload-after-traverse.html
new file mode 100644
index 00000000000..123ffd64a09
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-reload-after-traverse.html
@@ -0,0 +1,31 @@
+<!doctype html>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<link rel="help" href="https://html.spec.whatwg.org/#process-scroll-behavior">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<div style="height: 1000px; width: 200vw;"></div>
+<div id="frag"></div>
+<div style="height: 1000px; width: 200vw;"></div>
+<div id="other"></div>
+<div style="height: 2000px; width: 200vw;"></div>
+<script>
+promise_test(async t => {
+ await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
+ await navigation.navigate("#frag").finished;
+ const frag_key = navigation.currentEntry.key;
+ const scrollY_frag = window.scrollY;
+ window.scrollBy(0, 10);
+
+ await navigation.navigate("#other").finished;
+ await navigation.traverseTo(frag_key).finished;
+ window.scrollTo(0, scrollY_frag + 30);
+ assert_equals(window.scrollY, scrollY_frag + 30);
+
+ navigation.onnavigate = e => e.intercept({ scroll: "after-transition" });
+ await navigation.reload().finished;
+ assert_equals(window.scrollY, scrollY_frag,
+ "should scroll to the fragment, ignoring any saved scroll position");
+}, "scroll: after-transition on a reload of a traversed-to fragment entry scrolls to the fragment");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-fragment.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-fragment.html
new file mode 100644
index 00000000000..26acd287b71
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-fragment.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<link rel="help" href="https://html.spec.whatwg.org/#process-scroll-behavior">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<div style="height: 300vh; width: 200vw;"></div>
+<script>
+promise_test(async t => {
+ await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
+ window.scrollTo(0, 500);
+ assert_equals(window.scrollY, 500);
+
+ navigation.onnavigate = e => e.intercept({ scroll: "after-transition" });
+ await navigation.reload().finished;
+ assert_equals(window.scrollY, 0, "should scroll to the beginning of the document");
+}, "scroll: after-transition on a reload without a fragment scrolls to the beginning of the document");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-scroll-anchoring.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-scroll-anchoring.html
new file mode 100644
index 00000000000..db1f1fe1e9f
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-scroll-anchoring.html
@@ -0,0 +1,47 @@
+<!doctype html>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<div id="buffer" style="height: 1000px; width: 200vw;"></div>
+<div id="frag"></div>
+<div style="height: 2000px; width: 200vw;"></div>
+<style>
+ * {
+ overflow-anchor: none;
+ }
+</style>
+<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 stay in same position.
+ 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);
+
+ // 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 - 1000 - 10);
+}, "scroll: after-transition should work on a reload navigation");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-timing.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-timing.html
new file mode 100644
index 00000000000..1525d04ab77
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-timing.html
@@ -0,0 +1,49 @@
+<!doctype html>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<div style="height: 200vh; width: 200vw;"></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/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-no-fragment.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-no-fragment.html
new file mode 100644
index 00000000000..a7df7029d93
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-no-fragment.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<link rel="help" href="https://html.spec.whatwg.org/#process-scroll-behavior">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<div style="height: 200vh; width: 200vw;"></div>
+<div id="frag"></div>
+<div style="height: 200vh; width: 200vw;"></div>
+<script>
+promise_test(async t => {
+ await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
+ const initial_key = navigation.currentEntry.key;
+ window.scrollTo(0, 500);
+ assert_equals(window.scrollY, 500);
+
+ await navigation.navigate("#frag").finished;
+ assert_not_equals(window.scrollY, 500);
+
+ navigation.onnavigate = e => e.intercept({ scroll: "after-transition" });
+ await navigation.traverseTo(initial_key).finished;
+ assert_equals(window.scrollY, 500, "scroll position should be restored");
+}, "scroll: after-transition on a traverse to an entry without a fragment restores the scroll position");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-to-fragment.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-to-fragment.html
new file mode 100644
index 00000000000..123eab7403a
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-to-fragment.html
@@ -0,0 +1,31 @@
+<!doctype html>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<link rel="help" href="https://html.spec.whatwg.org/#process-scroll-behavior">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<div style="height: 1000px; width: 200vw;"></div>
+<div id="frag"></div>
+<div style="height: 1000px; width: 200vw;"></div>
+<div id="other"></div>
+<div style="height: 2000px; width: 200vw;"></div>
+<script>
+promise_test(async t => {
+ await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
+ await navigation.navigate("#frag").finished;
+ const frag_key = navigation.currentEntry.key;
+ const scrollY_frag = window.scrollY;
+ window.scrollBy(0, 10);
+ const scrollY_frag_plus_10 = window.scrollY;
+ assert_equals(scrollY_frag_plus_10, scrollY_frag + 10);
+
+ await navigation.navigate("#other").finished;
+ assert_not_equals(window.scrollY, scrollY_frag_plus_10);
+
+ navigation.onnavigate = e => e.intercept({ scroll: "after-transition" });
+ await navigation.traverseTo(frag_key).finished;
+ assert_equals(window.scrollY, scrollY_frag_plus_10,
+ `scroll position should be restored rather than scrolling to the fragment at ${scrollY_frag}`);
+}, "scroll: after-transition on a traverse to an entry with a fragment restores the scroll position");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-after-dispatch.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-after-dispatch.html
new file mode 100644
index 00000000000..3cc0edac243
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-after-dispatch.html
@@ -0,0 +1,34 @@
+<!doctype html>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<div style="height: 200vh; width: 200vw;"></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/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-clears-target-when-fragment-does-not-exist.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-clears-target-when-fragment-does-not-exist.html
new file mode 100644
index 00000000000..273dee0ce5b
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-clears-target-when-fragment-does-not-exist.html
@@ -0,0 +1,34 @@
+<!doctype html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<div style="height: 200vh; width: 200vw;"></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_equals(document.querySelector(":target"), document.getElementById("frag"),
+ "target element after navigating to #frag");
+
+ 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_equals(document.querySelector(":target"), document.getElementById("frag"),
+ "target element before scroll()");
+ navigate_event.scroll();
+ assert_equals(document.querySelector(":target"), null, "target element after scroll()");
+ intercept_resolve();
+ await promises.finished;
+ assert_equals(document.querySelector(":target"), null, "target element after finished");
+}, "scroll: scroll() should clear the CSS :target element when the fragment does not exist");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-in-precommit-handler.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-in-precommit-handler.html
new file mode 100644
index 00000000000..dbbc6a5b2b5
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-in-precommit-handler.html
@@ -0,0 +1,33 @@
+<!doctype html>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<div style="height: 200vh; width: 200vw;"></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",
+ precommitHandler: t.step_func(() => {
+ assert_throws_dom("InvalidStateError", () => e.scroll());
+ assert_not_equals(window.scrollY, 0);
+ }),
+ handler: t.step_func(() => {
+ e.scroll();
+ assert_equals(window.scrollY, 0);
+ })
+ });
+ }
+ await navigation.back().finished;
+ assert_equals(window.scrollY, 0);
+}, "scroll: scroll() in precommitHandler throws");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-reload-no-scroll-anchoring.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-reload-no-scroll-anchoring.html
new file mode 100644
index 00000000000..a15951a8a0d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-reload-no-scroll-anchoring.html
@@ -0,0 +1,51 @@
+<!doctype html>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<div id="buffer" style="height: 1000px; width: 200vw;"></div>
+<div id="frag"></div>
+<div style="height: 2000px; width: 200vw;"></div>
+<style>
+ * {
+ overflow-anchor: none;
+ }
+</style>
+<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 stay in same position.
+ 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);
+
+ // scroll() should scroll to #frag, which is 10px up from the current location
+ navigate_event.scroll();
+ assert_equals(window.scrollY, scrollY_after_buffer_remove - 1000 - 10);
+
+ // Finishing should not scroll.
+ intercept_resolve();
+ await reload_promises.finished;
+ assert_equals(window.scrollY, scrollY_after_buffer_remove - 1000 - 10);
+}, "scroll: scroll() should work on a reload navigation");
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-repeated.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-repeated.html
new file mode 100644
index 00000000000..e599eab8871
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/manual-scroll-repeated.html
@@ -0,0 +1,30 @@
+<!doctype html>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+<div style="height: 200vh; width: 200vw;"></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/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/scroll-on-synthetic-event.html b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/scroll-on-synthetic-event.html
new file mode 100644
index 00000000000..d19d00d1bf0
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/navigation-api/scroll-behavior/scroll-on-synthetic-event.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<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>