Truly independent web browser
Tests/LibWeb: Import WPT tests for window.print()
Andreas Kling11dc08cbfa05
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex d6c5e3c865c..635e209e859 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -154,6 +154,10 @@ Text/input/wpt-import/html/browsers/browsing-the-web/history-traversal/popstate_; Compares the URLs of HTTP documents, which need an HTTP origin.Text/input/wpt-import/html/browsers/history/the-location-interface/location-encoding-parse.html+; Opens a .sub.html page, which needs the HTTP server to substitute it.+Text/input/wpt-import/html/webappapis/user-prompts/print-during-beforeunload.html+Text/input/wpt-import/html/webappapis/user-prompts/print-during-unload.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/webappapis/user-prompts/print-during-beforeunload.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/user-prompts/print-during-beforeunload.txtnew file mode 100644index 00000000000..e58fa648ead--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/user-prompts/print-during-beforeunload.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail print() during beforeunload\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/user-prompts/print-during-unload.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/user-prompts/print-during-unload.txtnew file mode 100644index 00000000000..d30fdb5e526--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/user-prompts/print-during-unload.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail print() during unload\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/user-prompts/print-in-detached-frame.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/user-prompts/print-in-detached-frame.txtnew file mode 100644index 00000000000..08cb24081ec--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/user-prompts/print-in-detached-frame.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail print() in a detached iframe\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/html/webappapis/user-prompts/print-during-beforeunload.html b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/user-prompts/print-during-beforeunload.htmlnew file mode 100644index 00000000000..4f2e605d6b4--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/user-prompts/print-during-beforeunload.html@@ -0,0 +1,29 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>print() during beforeunload</title>+<script src="../../../resources/testharness.js"></script>+<script src="../../../resources/testharnessreport.js"></script>++<body>+<script>+"use strict";++async_test(t => {+ const w = window.open("resources/print-during-event.sub.html?event=beforeunload");+ t.add_cleanup(() => w.close());++ const messages = [];+ window.addEventListener("message", t.step_func(({ data }) => {+ messages.push(data);++ if (messages.length === 1) {+ assert_array_equals(messages, ["start"]);+ w.location.href = "resources/destination.html";+ } else if (messages.length === 2) {+ // The test passes if we've reached this point because the print() dialog did not block the navigation.+ assert_array_equals(messages, ["start", "destination"]);+ t.done();+ }+ }));+});+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/webappapis/user-prompts/print-during-unload.html b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/user-prompts/print-during-unload.htmlnew file mode 100644index 00000000000..77519e5d40e--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/user-prompts/print-during-unload.html@@ -0,0 +1,29 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>print() during unload</title>+<script src="../../../resources/testharness.js"></script>+<script src="../../../resources/testharnessreport.js"></script>++<body>+<script>+"use strict";++async_test(t => {+ const w = window.open("resources/print-during-event.sub.html?event=unload");+ t.add_cleanup(() => w.close());++ const messages = [];+ window.addEventListener("message", t.step_func(({ data }) => {+ messages.push(data);++ if (messages.length === 1) {+ assert_array_equals(messages, ["start"]);+ w.location.href = "resources/destination.html";+ } else if (messages.length === 2) {+ // The test passes if we've reached this point because the print() dialog did not block the navigation.+ assert_array_equals(messages, ["start", "destination"]);+ t.done();+ }+ }));+});+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/webappapis/user-prompts/print-in-detached-frame.html b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/user-prompts/print-in-detached-frame.htmlnew file mode 100644index 00000000000..6351056b9f9--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/user-prompts/print-in-detached-frame.html@@ -0,0 +1,19 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>print() in a detached iframe</title>+<script src="../../../resources/testharness.js"></script>+<script src="../../../resources/testharnessreport.js"></script>++<body>+<script>+"use strict";++test(() => {+ const iframe = document.createElement("iframe");+ document.body.append(iframe);+ const print = iframe.contentWindow.print;+ iframe.remove();++ print();+});+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/webappapis/user-prompts/resources/destination.html b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/user-prompts/resources/destination.htmlnew file mode 100644index 00000000000..87fb35cea33--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/user-prompts/resources/destination.html@@ -0,0 +1,8 @@+<!DOCTYPE html>+<meta charset="utf-8">++<script>+"use strict";++opener.postMessage("destination", "*");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/webappapis/user-prompts/resources/print-during-event.sub.html b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/user-prompts/resources/print-during-event.sub.htmlnew file mode 100644index 00000000000..6f6a78b03c7--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/user-prompts/resources/print-during-event.sub.html@@ -0,0 +1,17 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Page that tries to print during an event</title>++<script>+"use strict";++window.on{{GET[event]}} = () => {+ try {+ window.print();+ } catch (e) {+ window.opener.postMessage(`error: ${e.message}`);+ }+};++window.opener.postMessage("start", "*");+</script>