Truly independent web browser
Tests: Import the WPT notification permission and non-secure tests
sideshowbarkere9c19e42a03b
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 025854dfb19..ad737a8a9a4 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -1233,6 +1233,8 @@ Text/input/visual-viewport-scrollend-after-pan.html[LoadFromInsecureOrigin]Text/input/notifications/permission-insecure-context.htmlText/input/notifications/request-permission-insecure.html+Text/input/wpt-import/notifications/constructor-non-secure.html+Text/input/wpt-import/notifications/permissions-non-secure.htmlText/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/insecure-http.sub.htmlText/input/HTML/page-from-an-insecure-origin-is-not-a-secure-context.html; Geolocation refuses a page that is not a secure context, which localhost would be.diff --git a/Tests/LibWeb/Text/expected/wpt-import/notifications/constructor-non-secure.txt b/Tests/LibWeb/Text/expected/wpt-import/notifications/constructor-non-secure.txtnew file mode 100644index 00000000000..53d941b426b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/notifications/constructor-non-secure.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass new Notification calls onerror in non-secure contexts\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/notifications/event-onshow.https.txt b/Tests/LibWeb/Text/expected/wpt-import/notifications/event-onshow.https.txtnew file mode 100644index 00000000000..61038192665--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/notifications/event-onshow.https.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Invoked the onshow event handler.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/notifications/icon-url-encoding-euc-kr.https.txt b/Tests/LibWeb/Text/expected/wpt-import/notifications/icon-url-encoding-euc-kr.https.txtnew file mode 100644index 00000000000..41a12721186--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/notifications/icon-url-encoding-euc-kr.https.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass icon-url-encoding-euc-kr\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/notifications/permission.txt b/Tests/LibWeb/Text/expected/wpt-import/notifications/permission.txtnew file mode 100644index 00000000000..8565268c350--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/notifications/permission.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Checked the Notification.permission property.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/notifications/permissions-non-secure.txt b/Tests/LibWeb/Text/expected/wpt-import/notifications/permissions-non-secure.txtnew file mode 100644index 00000000000..02e5ef5505f--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/notifications/permissions-non-secure.txt@@ -0,0 +1,8 @@+Harness status: OK++Found 3 tests++3 Pass+Pass Notification.requestPermission must be called from a secure context+Pass Notification.permission must be called from a secure context+Pass Notification.permission must be called from a secure worker\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/notifications/constructor-non-secure.html b/Tests/LibWeb/Text/input/wpt-import/notifications/constructor-non-secure.htmlnew file mode 100644index 00000000000..bd1a609db56--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/notifications/constructor-non-secure.html@@ -0,0 +1,13 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Notification constructor (basic) on a non-secure connection</title>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script>+async_test(function (t) {+ const notification = new Notification("Sup.");+ notification.onerror = t.step_func_done(e => {+ assert_equals(e.type, "error");+ });+}, "new Notification calls onerror in non-secure contexts")+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/notifications/event-onshow.https.html b/Tests/LibWeb/Text/input/wpt-import/notifications/event-onshow.https.htmlnew file mode 100644index 00000000000..811aba82273--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/notifications/event-onshow.https.html@@ -0,0 +1,24 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Notification.onshow (basic)</title>+<link rel="author" title="Intel" href="http://www.intel.com/">+<link rel="author" title="Xin Liu" href="mailto:[email protected]">+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script src="../resources/testdriver.js"></script>+<script src="../resources/testdriver-vendor.js"></script>+<script>+promise_setup(() => {+ return test_driver.set_permission({ name: "notifications" }, "granted")+})++promise_test(async t => {+ const notification = new Notification("New Email Received")+ const event = await new Promise(resolve => {+ notification.onshow = resolve;+ })+ notification.close()+ assert_equals(Object.prototype.toString.call(event), "[object Event]")+ assert_equals(event.type, "show", "Checked the event type.")+}, "Invoked the onshow event handler.")+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/notifications/icon-url-encoding-euc-kr.https.html b/Tests/LibWeb/Text/input/wpt-import/notifications/icon-url-encoding-euc-kr.https.htmlnew file mode 100644index 00000000000..26ac6bd3b3d--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/notifications/icon-url-encoding-euc-kr.https.html@@ -0,0 +1,16 @@+<!DOCTYPE html>+<meta charset="euc-kr">+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script>+ // This file is actually ascii, because otherwise text editors would have hard time.++ promise_test(async (t) => {+ // "icon" in Korean language+ const iconKorean = "\uc544\uc774\ucf58";+ const n = new Notification("title", { icon: `?icon=${iconKorean}` })+ t.add_cleanup(() => n.close());++ assert_equals(new URL(n.icon).search, "?icon=%EC%95%84%EC%9D%B4%EC%BD%98", "icon encoded with utf-8");+ })+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/notifications/permission.html b/Tests/LibWeb/Text/input/wpt-import/notifications/permission.htmlnew file mode 100644index 00000000000..12e1f96bf00--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/notifications/permission.html@@ -0,0 +1,14 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Notification.permission (basic)</title>+<link rel="author" title="Intel" href="http://www.intel.com/">+<link rel="author" title="Xin Liu" href="mailto:[email protected]">+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script>+test(function() {+ assert_in_array(Notification.permission,+ ["default", "denied", "granted"],+ "Notification.permission")+}, "Checked the Notification.permission property.")+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/notifications/permissions-non-secure.html b/Tests/LibWeb/Text/input/wpt-import/notifications/permissions-non-secure.htmlnew file mode 100644index 00000000000..dba11c80c9c--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/notifications/permissions-non-secure.html@@ -0,0 +1,22 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Notification permissions should be denied in non-secure contexts</title>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script>+promise_test(t => {+ return Notification.requestPermission().then(result => {+ assert_equals(result, "denied");+ });+}, "Notification.requestPermission must be called from a secure context");++test(t => {+ assert_equals(Notification.permission, "denied");+}, "Notification.permission must be called from a secure context");++promise_test(async t => {+ const worker = new Worker("resources/permission-worker.js", { type: "module" });+ const data = await new Promise(r => worker.onmessage = ev => r(ev.data));+ assert_equals(data.permission, "denied");+}, "Notification.permission must be called from a secure worker");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/notifications/resources/custom-data.js b/Tests/LibWeb/Text/input/wpt-import/notifications/resources/custom-data.jsnew file mode 100644index 00000000000..49a5c60d811--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/notifications/resources/custom-data.js@@ -0,0 +1,65 @@+var fakeCustomData = (function() {+ var buffer = new ArrayBuffer(2);+ new DataView(buffer).setInt16(0, 42, true);+ var canvas = new OffscreenCanvas(100, 100);+ var context = canvas.getContext("2d");++ var map = new Map();+ var set = new Set();+ map.set("test", 42);+ set.add(4);+ set.add(2);++ return {+ primitives: {+ a: 123,+ b: "test",+ c: true,+ d: [1, 2, 3],+ },+ date: new Date(2013, 2, 1, 1, 10),+ regexp: new RegExp("[^.]+"),+ arrayBuffer: buffer,+ imageData: context.createImageData(100, 100),+ map,+ set,+ };+})();++function assert_custom_data(dataObj) {+ assert_equals(typeof dataObj, "object", "data should be a JS object");+ assert_equals(+ JSON.stringify(dataObj.primitives),+ JSON.stringify(fakeCustomData.primitives),+ "data.primitives should be preserved"+ );+ assert_equals(+ dataObj.date.toDateString(),+ fakeCustomData.date.toDateString(),+ "data.date should be preserved"+ );+ assert_equals(+ dataObj.regexp.exec("http://www.domain.com")[0].substr(7),+ "www",+ "data.regexp should be preserved"+ );+ assert_equals(+ new Int16Array(dataObj.arrayBuffer)[0],+ 42,+ "data.arrayBuffer should be preserved"+ );+ assert_equals(+ JSON.stringify(dataObj.imageData.data),+ JSON.stringify(fakeCustomData.imageData.data),+ "data.imageData should be preserved"+ )+ assert_equals(+ dataObj.map.get("test"),+ 42,+ "data.map should be preserved"+ );+ assert_true(+ dataObj.set.has(4) && dataObj.set.has(2),+ "data.set should be preserved"+ );+}diff --git a/Tests/LibWeb/Text/input/wpt-import/notifications/resources/permission-helper.js b/Tests/LibWeb/Text/input/wpt-import/notifications/resources/permission-helper.jsnew file mode 100644index 00000000000..22b11abae52--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/notifications/resources/permission-helper.js@@ -0,0 +1,24 @@+export function permissionTest(origin, sender) {+ function ping(message) {+ if (!globalThis.WorkerGlobalScope) {+ window.top.postMessage(message, origin);+ } else {+ globalThis.postMessage(message);+ }+ n.close();+ }++ const n = new Notification(sender);+ const permission = Notification.permission;+ n.onshow = () => ping({ sender, permission, shown: true });+ n.onerror = () => ping({ sender, permission, shown: false });++ if (!globalThis.WorkerGlobalScope) {+ Notification.requestPermission().then(permission => ping({ sender: `${sender}Request`, permission }));++ const workerUrl = new URL(`./permission-worker.js`, import.meta.url);+ workerUrl.searchParams.set("sender", `${sender}Worker`);+ const worker = new Worker(workerUrl, { type: "module" });+ worker.onmessage = ev => ping(ev.data, origin);+ }+}diff --git a/Tests/LibWeb/Text/input/wpt-import/notifications/resources/permission-worker.js b/Tests/LibWeb/Text/input/wpt-import/notifications/resources/permission-worker.jsnew file mode 100644index 00000000000..17314bd5e1e--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/notifications/resources/permission-worker.js@@ -0,0 +1,4 @@+import { permissionTest } from "./permission-helper.js"++const params = new URL(import.meta.url).searchParams;+permissionTest(null, params.get("sender"));