Truly independent web browser
Tests/LibWeb: Import WPT tests for history API rate limits
Andreas Klinga09469573b1c
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 2ef9c4e4632..1e7478344d2 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -140,6 +140,13 @@ Text/input/wpt-import/wasm/serialization/module/window-simple-success.htmlText/input/wpt-import/html/syntax/xmldecl/xmldecl-1.htmlText/input/wpt-import/html/syntax/xmldecl/xmldecl-2.html+; Loads iframes by root-relative URLs, which need an HTTP origin.+Text/input/wpt-import/html/browsers/history/the-history-interface/history_go_too_many_calls.optional.html+Text/input/wpt-import/html/browsers/history/the-history-interface/history_pushstate_too_many_calls.optional.html+Text/input/wpt-import/html/browsers/history/the-history-interface/history_pushstate_too_many_calls_ordering.optional.html+Text/input/wpt-import/html/browsers/history/the-history-interface/history_replacestate_too_many_calls.optional.html+Text/input/wpt-import/html/browsers/history/the-history-interface/history_replacestate_too_many_calls_ordering.optional.html+; Calls reload() on a child window's Location, which requires a shared tuple origin.Text/input/wpt-import/html/browsers/history/the-location-interface/reload_document_write.htmldiff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-history-interface/history_go_too_many_calls.optional.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-history-interface/history_go_too_many_calls.optional.txtnew file mode 100644index 00000000000..a57f47b6a4d--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-history-interface/history_go_too_many_calls.optional.txt@@ -0,0 +1,8 @@+Harness status: OK++Found 2 tests++1 Pass+1 Fail+Fail history go too many calls+Pass fully active check should be before rate limit check\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-history-interface/history_pushstate_too_many_calls.optional.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-history-interface/history_pushstate_too_many_calls.optional.txtnew file mode 100644index 00000000000..fcaa46b3095--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-history-interface/history_pushstate_too_many_calls.optional.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail history pushState too many calls\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-history-interface/history_pushstate_too_many_calls_ordering.optional.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-history-interface/history_pushstate_too_many_calls_ordering.optional.txtnew file mode 100644index 00000000000..432c5f21e65--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-history-interface/history_pushstate_too_many_calls_ordering.optional.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 4 tests++1 Pass+3 Fail+Fail pushState serializes state before checking the rate limit+Fail pushState parses the URL before checking the rate limit+Fail pushState checks whether the URL can be rewritten before checking the rate limit+Pass pushState checks fully active before checking the rate limit\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-history-interface/history_replacestate_too_many_calls.optional.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-history-interface/history_replacestate_too_many_calls.optional.txtnew file mode 100644index 00000000000..aacb77f7387--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-history-interface/history_replacestate_too_many_calls.optional.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail history replaceState too many calls\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-history-interface/history_replacestate_too_many_calls_ordering.optional.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-history-interface/history_replacestate_too_many_calls_ordering.optional.txtnew file mode 100644index 00000000000..ea89640ac3d--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-history-interface/history_replacestate_too_many_calls_ordering.optional.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 4 tests++1 Pass+3 Fail+Fail replaceState serializes state before checking the rate limit+Fail replaceState parses the URL before checking the rate limit+Fail replaceState checks whether the URL can be rewritten before checking the rate limit+Pass replaceState checks fully active before checking the rate limit\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-history-interface/history_go_too_many_calls.optional.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-history-interface/history_go_too_many_calls.optional.htmlnew file mode 100644index 00000000000..c78ec319284--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-history-interface/history_go_too_many_calls.optional.html@@ -0,0 +1,48 @@+<!DOCTYPE HTML>+<html>+ <head>+ <title>history go too many calls</title>+ <script src="../../../../resources/testharness.js"></script>+ <script src="../../../../resources/testharnessreport.js"></script>+ </head>+ <body>+ <div id="log"></div>+ <script>+ async function createIframe() {+ const iframe = document.createElement('iframe');+ iframe.src = '../../../../common/blank.html';+ const iframeLoaded = new Promise(resolve => iframe.addEventListener('load', resolve, { once: true }));+ document.body.append(iframe);+ await iframeLoaded;+ return iframe;+ }++ promise_test(async t => {+ const iframe = await createIframe();+ let navigateEvents = 0;+ iframe.contentWindow.navigation.onnavigate = e => { navigateEvents++; return false; };+ for (let i = 0; i < 500; i++) {+ iframe.contentWindow.history.go(0);+ await new Promise(resolve => t.step_timeout(resolve, 0));+ if (i > navigateEvents) {+ return;+ }+ }+ assert_unreached("No rate limit reached.");+ }, 'history go too many calls');++ promise_test(async t => {+ const iframe = await createIframe();+ const iframeWindow = iframe.contentWindow;+ const iframeDOMException = iframeWindow.DOMException;+ const iframeHistory = iframeWindow.history;+ iframe.remove();+ for (let i = 0; i < 500; i++) {+ assert_throws_dom("SecurityError", iframeDOMException, () => {+ iframeHistory.go(0);+ });+ }+ }, 'fully active check should be before rate limit check');+ </script>+ </body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-history-interface/history_pushstate_too_many_calls.optional.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-history-interface/history_pushstate_too_many_calls.optional.htmlnew file mode 100644index 00000000000..4c831af0a01--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-history-interface/history_pushstate_too_many_calls.optional.html@@ -0,0 +1,23 @@+<!DOCTYPE HTML>+<html>+ <head>+ <title>history pushState too many calls</title>+ <script src="../../../../resources/testharness.js"></script>+ <script src="../../../../resources/testharnessreport.js"></script>+ </head>+ <body>+ <div id="log"></div>+ <script>+ test(function () {+ for (let i = 0; i < 500; i++) {+ let prev = location.href;+ window.history.pushState(null, null, i);+ if (location.href === prev) {+ return;+ }+ }+ assert_unreached("No rate limit reached.");+ });+ </script>+ </body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-history-interface/history_pushstate_too_many_calls_ordering.optional.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-history-interface/history_pushstate_too_many_calls_ordering.optional.htmlnew file mode 100644index 00000000000..8ff5a2ac456--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-history-interface/history_pushstate_too_many_calls_ordering.optional.html@@ -0,0 +1,83 @@+<!DOCTYPE html>+<html>+<head>+<title>pushState too many calls ordering</title>+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+</head>+<body>+<div id="log"></div>+<script>+const maxCalls = 500;++async function createIframe(t) {+ const iframe = document.createElement("iframe");+ iframe.src = "../../../../common/blank.html";+ t.add_cleanup(() => iframe.remove());++ const iframeLoaded = new Promise(resolve => {+ iframe.addEventListener("load", resolve, { once: true });+ });+ document.body.append(iframe);+ await iframeLoaded;+ return iframe;+}++function reachPushStateRateLimit(iframeWindow) {+ for (let i = 0; i < maxCalls; ++i) {+ const previousURL = iframeWindow.location.href;+ iframeWindow.history.pushState(null, "", `#rate-limit-${i}`);+ if (iframeWindow.location.href === previousURL) {+ return;+ }+ }++ assert_unreached("No rate limit reached.");+}++promise_test(async t => {+ const iframe = await createIframe(t);+ const iframeWindow = iframe.contentWindow;+ reachPushStateRateLimit(iframeWindow);++ assert_throws_dom("DataCloneError", iframeWindow.DOMException, () => {+ iframeWindow.history.pushState(() => {}, "", "#after-rate-limit");+ });+}, "pushState serializes state before checking the rate limit");++promise_test(async t => {+ const iframe = await createIframe(t);+ const iframeWindow = iframe.contentWindow;+ reachPushStateRateLimit(iframeWindow);++ assert_throws_dom("SecurityError", iframeWindow.DOMException, () => {+ iframeWindow.history.pushState(null, "", "http://[");+ });+}, "pushState parses the URL before checking the rate limit");++promise_test(async t => {+ const iframe = await createIframe(t);+ const iframeWindow = iframe.contentWindow;+ reachPushStateRateLimit(iframeWindow);++ assert_throws_dom("SecurityError", iframeWindow.DOMException, () => {+ iframeWindow.history.pushState(null, "", "https://example.com/");+ });+}, "pushState checks whether the URL can be rewritten before checking the rate limit");++promise_test(async t => {+ const iframe = await createIframe(t);+ const iframeWindow = iframe.contentWindow;+ const iframeHistory = iframeWindow.history;+ const iframeDOMException = iframeWindow.DOMException;+ iframe.remove();++ for (let i = 0; i < maxCalls; ++i) {+ assert_throws_dom("SecurityError", iframeDOMException, () => {+ iframeHistory.pushState(null, "", `#inactive-${i}`);+ });+ }+}, "pushState checks fully active before checking the rate limit");+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-history-interface/history_replacestate_too_many_calls.optional.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-history-interface/history_replacestate_too_many_calls.optional.htmlnew file mode 100644index 00000000000..bf901d8d805--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-history-interface/history_replacestate_too_many_calls.optional.html@@ -0,0 +1,23 @@+<!DOCTYPE HTML>+<html>+ <head>+ <title>history replaceState too many calls</title>+ <script src="../../../../resources/testharness.js"></script>+ <script src="../../../../resources/testharnessreport.js"></script>+ </head>+ <body>+ <div id="log"></div>+ <script>+ test(function () {+ for (let i = 0; i < 500; i++) {+ let prev = location.href;+ window.history.replaceState(null, null, i);+ if (location.href === prev) {+ return;+ }+ }+ assert_unreached("No rate limit reached.");+ });+ </script>+ </body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-history-interface/history_replacestate_too_many_calls_ordering.optional.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-history-interface/history_replacestate_too_many_calls_ordering.optional.htmlnew file mode 100644index 00000000000..0bd593b5936--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-history-interface/history_replacestate_too_many_calls_ordering.optional.html@@ -0,0 +1,83 @@+<!DOCTYPE html>+<html>+<head>+<title>replaceState too many calls ordering</title>+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+</head>+<body>+<div id="log"></div>+<script>+const maxCalls = 500;++async function createIframe(t) {+ const iframe = document.createElement("iframe");+ iframe.src = "../../../../common/blank.html";+ t.add_cleanup(() => iframe.remove());++ const iframeLoaded = new Promise(resolve => {+ iframe.addEventListener("load", resolve, { once: true });+ });+ document.body.append(iframe);+ await iframeLoaded;+ return iframe;+}++function reachReplaceStateRateLimit(iframeWindow) {+ for (let i = 0; i < maxCalls; ++i) {+ const previousURL = iframeWindow.location.href;+ iframeWindow.history.replaceState(null, "", `#rate-limit-${i}`);+ if (iframeWindow.location.href === previousURL) {+ return;+ }+ }++ assert_unreached("No rate limit reached.");+}++promise_test(async t => {+ const iframe = await createIframe(t);+ const iframeWindow = iframe.contentWindow;+ reachReplaceStateRateLimit(iframeWindow);++ assert_throws_dom("DataCloneError", iframeWindow.DOMException, () => {+ iframeWindow.history.replaceState(() => {}, "", "#after-rate-limit");+ });+}, "replaceState serializes state before checking the rate limit");++promise_test(async t => {+ const iframe = await createIframe(t);+ const iframeWindow = iframe.contentWindow;+ reachReplaceStateRateLimit(iframeWindow);++ assert_throws_dom("SecurityError", iframeWindow.DOMException, () => {+ iframeWindow.history.replaceState(null, "", "http://[");+ });+}, "replaceState parses the URL before checking the rate limit");++promise_test(async t => {+ const iframe = await createIframe(t);+ const iframeWindow = iframe.contentWindow;+ reachReplaceStateRateLimit(iframeWindow);++ assert_throws_dom("SecurityError", iframeWindow.DOMException, () => {+ iframeWindow.history.replaceState(null, "", "https://example.com/");+ });+}, "replaceState checks whether the URL can be rewritten before checking the rate limit");++promise_test(async t => {+ const iframe = await createIframe(t);+ const iframeWindow = iframe.contentWindow;+ const iframeHistory = iframeWindow.history;+ const iframeDOMException = iframeWindow.DOMException;+ iframe.remove();++ for (let i = 0; i < maxCalls; ++i) {+ assert_throws_dom("SecurityError", iframeDOMException, () => {+ iframeHistory.replaceState(null, "", `#inactive-${i}`);+ });+ }+}, "replaceState checks fully active before checking the rate limit");+</script>+</body>+</html>