Truly independent web browser
Tests: Import the WPT permissions and geolocation tests that can run
sideshowbarkerb18a43ab1ded
diff --git a/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query-worker.window.html b/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query-worker.window.htmlnew file mode 100644index 00000000000..73a11f7a73a--- /dev/null+++ b/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query-worker.window.html@@ -0,0 +1,7 @@+<!doctype html>+<meta charset=utf-8>++<script src="/resources/testharness.js"></script>+<script src="/resources/testharnessreport.js"></script>+<div id=log></div>+<script src="permissions-query-worker.window.js"></script>diff --git a/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query-worker.window.js b/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query-worker.window.jsnew file mode 100644index 00000000000..915e62e9f16--- /dev/null+++ b/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query-worker.window.js@@ -0,0 +1,16 @@+promise_test(async () => {+ const worker = new Worker(URL.createObjectURL(new Blob([`+ postMessage("load");+ while (true) {+ navigator.permissions.query({ name: "geolocation" });+ }+ `])));+ await new Promise(resolve => {+ worker.onmessage = (e) => {+ if (e.data === "load") {+ worker.terminate();+ resolve();+ }+ };+ });+}, "Terminating worker after permission query should not crash");diff --git a/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query.any.html b/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query.any.htmlnew file mode 100644index 00000000000..84fd9f6010d--- /dev/null+++ b/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query.any.html@@ -0,0 +1,14 @@+<!doctype html>+<meta charset=utf-8>++<script>+self.GLOBAL = {+ isWindow: function() { return true; },+ isWorker: function() { return false; },+ isShadowRealm: function() { return false; },+};+</script>+<script src="/resources/testharness.js"></script>+<script src="/resources/testharnessreport.js"></script>+<div id=log></div>+<script src="permissions-query.any.js"></script>diff --git a/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query.any.js b/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query.any.jsnew file mode 100644index 00000000000..2e207fa2f22--- /dev/null+++ b/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query.any.js@@ -0,0 +1,35 @@+// META: global=window,worker++const permissionNames = [+ // Powerful features in https://w3c.github.io/permissions/#registry-table-of-standardized-permissions+ "geolocation",+ "notifications",+ "push",++ // extra permissions not in there: https://github.com/w3c/permissions/issues/475+ "accelerometer",+ "background-fetch",+ "camera",+ "display-capture",+ "gyroscope",+ "local-network",+ "loopback-network",+ "magnetometer",+ "microphone",+ "midi",+ "nfc",+ "persistent-storage",+ "screen-wake-lock",+ "speaker-selection",+ "storage-access",+];++for (const permissionName of permissionNames) {+ promise_test(async () => {+ try {+ await navigator.permissions.query({ name: permissionName });+ } catch (e) {+ assert_equals(e.name, "TypeError", `${permissionName} can throw a TypeError if unsupported`);+ }+ }, `${permissionName} should be queried without crash`);+}diff --git a/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query.any.worker.html b/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query.any.worker.htmlnew file mode 100644index 00000000000..a1460d46150--- /dev/null+++ b/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query.any.worker.html@@ -0,0 +1,9 @@+<!doctype html>+<meta charset=utf-8>++<script src="/resources/testharness.js"></script>+<script src="/resources/testharnessreport.js"></script>+<div id=log></div>+<script>+fetch_tests_from_worker(new Worker("permissions-query.any.worker.js"));+</script>diff --git a/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query.any.worker.js b/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query.any.worker.jsnew file mode 100644index 00000000000..563b9719e3d--- /dev/null+++ b/Tests/LibWeb/Crash/wpt-import/permissions/crashtests/permissions-query.any.worker.js@@ -0,0 +1,9 @@++self.GLOBAL = {+ isWindow: function() { return false; },+ isWorker: function() { return true; },+ isShadowRealm: function() { return false; },+};+importScripts("/resources/testharness.js");+importScripts("permissions-query.any.js");+done();diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex d78c212f95b..9582fc94d6d 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -10,6 +10,8 @@ Text/input/wpt-import/html/rendering/replaced-elements/attributes-for-embedded-cText/input/PermissionsAPI/Text/input/wpt-import/geolocation/Text/input/wpt-import/permissions/+; Their harness scripts are served from the WPT root, which a file: page cannot reach.+Crash/wpt-import/permissions/Text/input/HTML/xml-document-encoding.htmlText/input/HTML/createImageBitmap-video.htmlText/input/HTML/HTMLVideoElement-capture-before-seek-keeps-frame.html@@ -1179,6 +1181,8 @@ Text/input/visual-viewport-scrollend-after-pan.html[LoadFromInsecureOrigin]Text/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.+Text/input/wpt-import/geolocation/non-secure-contexts.http.html; A frame nested in its localhost iframe prohibits mixed security contexts while this page does not.Text/input/SiteIsolation/iframe/mixed-content-of-an-isolated-iframes-navigation-is-decided-by-the-iframe.html; Upstream serves it from a page that is not potentially trustworthy, where its data: frame's blob: worker is not mixed content.diff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/clearWatch_TypeError.https.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/clearWatch_TypeError.https.txtnew file mode 100644index 00000000000..cf6f98aff0c--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/clearWatch_TypeError.https.txt@@ -0,0 +1,12 @@+Harness status: OK++Found 7 tests++7 Pass+Pass Test that calling clearWatch with invalid watch ID (NaN) does not cause an exception+Pass Test that calling clearWatch with invalid watch ID (-1) does not cause an exception+Pass Test that calling clearWatch with invalid watch ID (0) does not cause an exception+Pass Test that calling clearWatch with invalid watch ID (1) does not cause an exception+Pass Test that calling clearWatch with invalid watch ID (2147483648) does not cause an exception+Pass Test that calling clearWatch with invalid watch ID (Infinity) does not cause an exception+Pass Test that calling clearWatch with invalid watch ID (-Infinity) does not cause an exception\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/disabled-by-permissions-policy.https.sub.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/disabled-by-permissions-policy.https.sub.txtnew file mode 100644index 00000000000..7da88206f4d--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/disabled-by-permissions-policy.https.sub.txt@@ -0,0 +1,8 @@+Harness status: OK++Found 3 tests++3 Pass+Pass Permissions-Policy header geolocation=() disallows the top-level document.+Pass Permissions-Policy header geolocation=() disallows same-origin iframes.+Pass Permissions-Policy header geolocation=() disallows cross-origin iframes.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/enabled-by-permission-policy-attribute-redirect-on-load.https.sub.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/enabled-by-permission-policy-attribute-redirect-on-load.https.sub.txtnew file mode 100644index 00000000000..ae314571396--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/enabled-by-permission-policy-attribute-redirect-on-load.https.sub.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass Permissions-Policy allow="geolocation" allows same-origin redirection+Pass Permissions-Policy allow="geolocation" disallows cross-origin redirection\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/enabled-by-permission-policy-attribute.https.sub.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/enabled-by-permission-policy-attribute.https.sub.txtnew file mode 100644index 00000000000..b08c593749b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/enabled-by-permission-policy-attribute.https.sub.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass Permissions policy "geolocation" can be enabled in same-origin iframe using allow="geolocation" attribute+Pass Permissions policy "geolocation" can be enabled in cross-origin iframe using allow="geolocation" attribute\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/enabled-by-permissions-policy.https.sub.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/enabled-by-permissions-policy.https.sub.txtnew file mode 100644index 00000000000..65448e9ab38--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/enabled-by-permissions-policy.https.sub.txt@@ -0,0 +1,8 @@+Harness status: OK++Found 3 tests++3 Pass+Pass Permissions-Policy header geolocation=* allows the top-level document.+Pass Permissions-Policy header geolocation=* allows same-origin iframes.+Pass Permissions-Policy header geolocation=* allows cross-origin iframes.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/enabled-on-self-origin-by-permissions-policy.https.sub.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/enabled-on-self-origin-by-permissions-policy.https.sub.txtnew file mode 100644index 00000000000..817ed5310bf--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/enabled-on-self-origin-by-permissions-policy.https.sub.txt@@ -0,0 +1,8 @@+Harness status: OK++Found 3 tests++3 Pass+Pass Permissions-Policy header geolocation=(self) allows the top-level document.+Pass Permissions-Policy header geolocation=(self) allows same-origin iframes.+Pass Permissions-Policy header geolocation=(self) disallows cross-origin iframes.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-accuracyMode-cache.https.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-accuracyMode-cache.https.txtnew file mode 100644index 00000000000..8a9c4facd9e--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-accuracyMode-cache.https.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass A cached approximate position is not reused for a precise request+Pass A cached precise position is not reused for an approximate request\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-accuracyMode.https.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-accuracyMode.https.txtnew file mode 100644index 00000000000..0333c5e5a82--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-accuracyMode.https.txt@@ -0,0 +1,8 @@+Harness status: OK++Found 2 tests++1 Pass+1 Fail+Fail getCurrentPosition with accuracyMode: "approximate"+Pass getCurrentPosition with accuracyMode: "precise"\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition_TypeError.https.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition_TypeError.https.txtnew file mode 100644index 00000000000..3027a3bca63--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition_TypeError.https.txt@@ -0,0 +1,12 @@+Harness status: OK++Found 7 tests++7 Pass+Pass Call getCurrentPosition without arguments, check that exception is thrown+Pass Call getCurrentPosition with null success callback, check that exception is thrown+Pass Call getCurrentPosition with null success and error callbacks, check that exception is thrown+Pass Call getCurrentPosition() with wrong type for first argument. Exception expected.+Pass Call getCurrentPosition() with wrong type for second argument. Exception expected.+Pass Call getCurrentPosition() with wrong type for third argument. Exception expected.+Pass Calling getCurrentPosition() with a legacy event handler objects.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/heading-stationary.https.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/heading-stationary.https.txtnew file mode 100644index 00000000000..d9b1af0d3b8--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/heading-stationary.https.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass heading is null when stationary (speed is 0)+Pass heading has a value when moving (speed > 0)\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/non-fully-active.https.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/non-fully-active.https.txtnew file mode 100644index 00000000000..8aff5ea5fcd--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/non-fully-active.https.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 4 tests++2 Pass+2 Fail+Pass watchPosition returns 0 for non-fully-active document+Fail watchPosition calls errorCallback with POSITION_UNAVAILABLE for non-fully-active document+Fail getCurrentPosition calls errorCallback with POSITION_UNAVAILABLE for non-fully-active document+Pass re-attached document restores geolocation functionality\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/non-secure-contexts.http.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/non-secure-contexts.http.txtnew file mode 100644index 00000000000..cda2621fd7f--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/non-secure-contexts.http.txt@@ -0,0 +1,9 @@+Harness status: OK++Found 4 tests++4 Pass+Pass When in a non-secure context, getCurrentPosition()'s errorCallback is asynchronously called.+Pass When in a non-secure context, watchPosition()'s errorCallback is asynchronously called.+Pass When in a non-secure context, the getCurrentPosition() errorCallBack gets a GeolocationPositionError with the correct error code.+Pass When in a non-secure context, the watchPosition() errorCallBack gets a GeolocationPositionError with the correct error code.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/tojson.https.window.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/tojson.https.window.txtnew file mode 100644index 00000000000..c32d71bf4e2--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/tojson.https.window.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Test toJSON() in GeolocationPosition and GeolocationCoordinates.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/watchPosition_TypeError.https.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/watchPosition_TypeError.https.txtnew file mode 100644index 00000000000..fb4bde69614--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/watchPosition_TypeError.https.txt@@ -0,0 +1,12 @@+Harness status: OK++Found 7 tests++7 Pass+Pass Call watchPosition without arguments, check that exception is thrown+Pass Call watchPosition with null success callback, check that exception is thrown+Pass Call watchPosition with null success and error callbacks, check that exception is thrown+Pass Call watchPosition() with wrong type for first argument. Exception expected.+Pass Call watchPosition() with wrong type for second argument. Exception expected.+Pass Call watchPosition() with wrong type for third argument. Exception expected.+Pass Calling watchPosition() with a legacy event handler object.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/watchposition-timeout.https.window.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/watchposition-timeout.https.window.txtnew file mode 100644index 00000000000..90ce45ac2b0--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/watchposition-timeout.https.window.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Passing timeout=1 should not cause multiple timeout errors\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/permissions/permissions-cg.https.txt b/Tests/LibWeb/Text/expected/wpt-import/permissions/permissions-cg.https.txtnew file mode 100644index 00000000000..27a81f55eda--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/permissions/permissions-cg.https.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass status is not garbage collected when it goes out of scope\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/clearWatch_TypeError.https.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/clearWatch_TypeError.https.htmlnew file mode 100644index 00000000000..ce92109f30b--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/clearWatch_TypeError.https.html@@ -0,0 +1,13 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>Geolocation Test: clearWatch TypeError tests</title>+<link rel="help" href="http://www.w3.org/TR/geolocation-API/#clear-watch" />+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script>+ for (const invalidId of [NaN, -1, 0, 1, 2147483648, Infinity, -Infinity]) {+ test(() => {+ navigator.geolocation.clearWatch(invalidId);+ }, `Test that calling clearWatch with invalid watch ID (${invalidId}) does not cause an exception`);+ }+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/disabled-by-permissions-policy.https.sub.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/disabled-by-permissions-policy.https.sub.htmlnew file mode 100644index 00000000000..a97dc583c7d--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/disabled-by-permissions-policy.https.sub.html@@ -0,0 +1,75 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<body>+ <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 src="../permissions-policy/resources/permissions-policy.js"></script>+ <script>+ "use strict";++ const same_origin_src =+ "/permissions-policy/resources/permissions-policy-geolocation.html";+ const cross_origin_src =+ "https://{{hosts[alt][]}}:{{ports[https][0]}}" + same_origin_src;++ promise_setup(async () => {+ await test_driver.set_permission({ name: "geolocation" }, "granted");+ });++ promise_test(async (test) => {+ // These operations are slow, so let's do them in parallel.+ const getCurrentPositionPromise = new Promise((resolve, reject) => {+ navigator.geolocation.getCurrentPosition(reject, resolve);+ });+ const watchPositionPromise = new Promise((resolve, reject) => {+ navigator.geolocation.watchPosition(reject, resolve);+ });+ const posError = await getCurrentPositionPromise;++ assert_true(+ posError instanceof GeolocationPositionError,+ "Expected instance of GeolocationPositionError"+ );++ assert_equals(+ posError.code,+ GeolocationPositionError.prototype.PERMISSION_DENIED,+ "Expected PERMISSION_DENIED"+ );++ const watchError = await watchPositionPromise;+ assert_true(+ watchError instanceof GeolocationPositionError,+ "Expected instance of GeolocationPositionError"+ );+ assert_equals(+ watchError.code,+ GeolocationPositionError.prototype.PERMISSION_DENIED,+ "Expected PERMISSION_DENIED"+ );+ }, "Permissions-Policy header geolocation=() disallows the top-level document.");++ promise_test(async (test) => {+ await test_feature_availability({+ feature_description: "Geolocation API",+ test,+ src: same_origin_src,+ expect_feature_available: expect_feature_unavailable_default,+ is_promise_test: true,+ });+ }, "Permissions-Policy header geolocation=() disallows same-origin iframes.");++ promise_test(async (test) => {+ await test_feature_availability({+ feature_description: "Geolocation API",+ test,+ src: cross_origin_src,+ expect_feature_available: expect_feature_unavailable_default,+ feature_name: "geolocation",+ is_promise_test: true,+ });+ }, "Permissions-Policy header geolocation=() disallows cross-origin iframes.");+ </script>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/disabled-by-permissions-policy.https.sub.html.headers b/Tests/LibWeb/Text/input/wpt-import/geolocation/disabled-by-permissions-policy.https.sub.html.headersnew file mode 100644index 00000000000..26bfbc24964--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/disabled-by-permissions-policy.https.sub.html.headers@@ -0,0 +1 @@+Permissions-Policy: geolocation=()diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-by-permission-policy-attribute-redirect-on-load.https.sub.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-by-permission-policy-attribute-redirect-on-load.https.sub.htmlnew file mode 100644index 00000000000..e054c11887b--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-by-permission-policy-attribute-redirect-on-load.https.sub.html@@ -0,0 +1,58 @@+<!DOCTYPE html>+<meta name="timeout" content="long">+<body>+ <script src="../resources/testharness.js"></script>+ <script src="../resources/testharnessreport.js"></script>+ <script src="../resources/testdriver.js?feature=bidi"></script>+ <script src="../resources/testdriver-vendor.js"></script>+ <script src="../permissions-policy/resources/permissions-policy.js"></script>+ <script>+ "use strict";++ const relative_path =+ "/permissions-policy/resources/permissions-policy-geolocation.html";+ const base_src = "/permissions-policy/resources/redirect-on-load.html#";+ const same_origin_src = base_src + relative_path;+ const cross_origin_src = `${base_src}https://{{hosts[alt][]}}:{{ports[https][0]}}${relative_path}`;++ // Grant permission to outer frame+ promise_setup(async () => {+ await test_driver.bidi.permissions.set_permission({+ descriptor: { name: "geolocation" }, state: "granted"+ });+ await test_driver.bidi.emulation.set_geolocation_override({+ coordinates: {+ latitude: 52.51,+ longitude: 13.39,+ accuracy: 0.5,+ altitude: 34,+ altitudeAccuracy: 0.75,+ heading: 180,+ speed: 2.77+ }+ });+ });++ promise_test(async (test) => {+ await test_feature_availability({+ feature_description: "Geolocation",+ test,+ src: same_origin_src,+ expect_feature_available: expect_feature_available_default,+ is_promise_test: true,+ feature_name: "geolocation",+ });+ }, 'Permissions-Policy allow="geolocation" allows same-origin redirection');++ promise_test(async (test) => {+ await test_feature_availability({+ feature_description: "Geolocation",+ test,+ src: cross_origin_src,+ expect_feature_available: expect_feature_unavailable_default,+ is_promise_test: true,+ feature_name: "geolocation",+ });+ }, 'Permissions-Policy allow="geolocation" disallows cross-origin redirection');+ </script>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-by-permission-policy-attribute.https.sub.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-by-permission-policy-attribute.https.sub.htmlnew file mode 100644index 00000000000..e1931e872a4--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-by-permission-policy-attribute.https.sub.html@@ -0,0 +1,41 @@+<!DOCTYPE html>+<body>+ <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 src="../permissions-policy/resources/permissions-policy.js"></script>+ <script>+ "use strict";++ const same_origin_src =+ "/permissions-policy/resources/permissions-policy-geolocation.html";+ const cross_origin_src =+ "https://{{hosts[alt][]}}:{{ports[https][0]}}" + same_origin_src;++ // Grant permission to outer frame+ promise_setup(async () => {+ await test_driver.set_permission({ name: "geolocation" }, "granted");+ });++ promise_test(async (test) => {+ await test_feature_availability(+ "Geolocation",+ test,+ same_origin_src,+ expect_feature_available_default,+ "geolocation"+ );+ }, 'Permissions policy "geolocation" can be enabled in same-origin iframe using allow="geolocation" attribute');++ promise_test(async (test) => {+ await test_feature_availability(+ "Geolocation",+ test,+ cross_origin_src,+ expect_feature_available_default,+ "geolocation"+ );+ }, 'Permissions policy "geolocation" can be enabled in cross-origin iframe using allow="geolocation" attribute');+ </script>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-by-permissions-policy.https.sub.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-by-permissions-policy.https.sub.htmlnew file mode 100644index 00000000000..386ea021b85--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-by-permissions-policy.https.sub.html@@ -0,0 +1,74 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<body>+ <script src="../resources/testharness.js"></script>+ <script src="../resources/testharnessreport.js"></script>+ <script src="../resources/testdriver.js?feature=bidi"></script>+ <script src="../resources/testdriver-vendor.js"></script>+ <script src="../permissions-policy/resources/permissions-policy.js"></script>+ <script>+ const same_origin_src =+ "/permissions-policy/resources/permissions-policy-geolocation.html";+ const cross_origin_src =+ "https://{{hosts[alt][]}}:{{ports[https][0]}}" + same_origin_src;++ promise_setup(async () => {+ // Grant permission for the top-level document's origin.+ await test_driver.bidi.permissions.set_permission({+ descriptor: {+ name: "geolocation"+ },+ state: "granted"+ });++ // Set a default position.+ await test_driver.bidi.emulation.set_geolocation_override({+ coordinates: {+ latitude: 0,+ longitude: 0,+ accuracy: 0+ }+ });+ });++ promise_test(async (test) => {+ const position = await new Promise((resolve, reject) => {+ navigator.geolocation.getCurrentPosition(resolve, reject);+ });++ assert_true(+ position instanceof GeolocationPosition,+ "Expected a GeolocationPosition"+ );+ }, "Permissions-Policy header geolocation=* allows the top-level document.");++ promise_test(async (test) => {+ await test_feature_availability({+ feature_description: "Geolocation API",+ test,+ src: same_origin_src,+ expect_feature_available: expect_feature_available_default,+ is_promise_test: true,+ });+ }, "Permissions-Policy header geolocation=* allows same-origin iframes.");++ promise_test(async (test) => {+ // Grant site-level permission for the cross-origin iframe's origin.+ await test_driver.bidi.permissions.set_permission({+ descriptor: {+ name: "geolocation"+ },+ state: "granted",+ origin: cross_origin_src+ });+ await test_feature_availability({+ feature_description: "Geolocation API",+ test,+ src: cross_origin_src,+ expect_feature_available: expect_feature_available_default,+ feature_name: "geolocation",+ is_promise_test: true,+ });+ }, "Permissions-Policy header geolocation=* allows cross-origin iframes.");+ </script>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-by-permissions-policy.https.sub.html.headers b/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-by-permissions-policy.https.sub.html.headersnew file mode 100644index 00000000000..774f4819e9b--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-by-permissions-policy.https.sub.html.headers@@ -0,0 +1 @@+Permissions-Policy: geolocation=*diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-on-self-origin-by-permissions-policy.https.sub.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-on-self-origin-by-permissions-policy.https.sub.htmlnew file mode 100644index 00000000000..98db1a0967c--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-on-self-origin-by-permissions-policy.https.sub.html@@ -0,0 +1,78 @@+<!DOCTYPE html>+<body>+ <script src="../resources/testharness.js"></script>+ <script src="../resources/testharnessreport.js"></script>+ <script src="../resources/testdriver.js?feature=bidi"></script>+ <script src="../resources/testdriver-vendor.js"></script>+ <script src="../permissions-policy/resources/permissions-policy.js"></script>++ <script>+ "use strict";++ const same_origin_src =+ "/permissions-policy/resources/permissions-policy-geolocation.html";+ const cross_origin_src =+ "https://{{hosts[alt][]}}:{{ports[https][0]}}" + same_origin_src;+++ promise_setup(async () => {+ // Grant site-level permission for the top-level document's origin.+ await test_driver.bidi.permissions.set_permission({+ descriptor: {+ name: "geolocation"+ },+ state: "granted"+ });++ // Set a default position.+ await test_driver.bidi.emulation.set_geolocation_override({+ coordinates: {+ latitude: 0,+ longitude: 0,+ accuracy: 0+ }+ });+ });++ promise_test(async (t) => {+ const position = await new Promise((resolve, reject) => {+ navigator.geolocation.getCurrentPosition(resolve, reject);+ });+ assert_true(+ position instanceof GeolocationPosition,+ "Expected a GeolocationPosition"+ );+ }, "Permissions-Policy header geolocation=(self) allows the top-level document.");++ promise_test(async (test) => {+ await test_feature_availability({+ feature_description: "Geolocation API",+ test,+ src: same_origin_src,+ expect_feature_available: expect_feature_available_default,+ is_promise_test: true,+ });+ }, "Permissions-Policy header geolocation=(self) allows same-origin iframes.");++ promise_test(async (test) => {+ // This is to ensure that the rejection is due to permission policy+ // instead of site-level permission.+ await test_driver.bidi.permissions.set_permission({+ descriptor: {+ name: "geolocation"+ },+ state: "granted",+ origin: cross_origin_src+ });++ await test_feature_availability({+ feature_description: "Geolocation API",+ test,+ src: cross_origin_src,+ expect_feature_available: expect_feature_unavailable_default,+ feature_name: "geolocation",+ is_promise_test: true,+ });+ }, "Permissions-Policy header geolocation=(self) disallows cross-origin iframes.");+ </script>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-on-self-origin-by-permissions-policy.https.sub.html.headers b/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-on-self-origin-by-permissions-policy.https.sub.html.headersnew file mode 100644index 00000000000..9fa0a4ac9a8--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/enabled-on-self-origin-by-permissions-policy.https.sub.html.headers@@ -0,0 +1 @@+Permissions-Policy: geolocation=(self)diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition-accuracyMode-cache.https.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition-accuracyMode-cache.https.htmlnew file mode 100644index 00000000000..0a1f9919f75--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition-accuracyMode-cache.https.html@@ -0,0 +1,97 @@+<!DOCTYPE html>+<meta charset="utf-8"/>+<title>Cached positions are only reused for a matching accuracyMode</title>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script src="../resources/testdriver.js?feature=bidi"></script>+<script src="../resources/testdriver-vendor.js"></script>++<script>+ const firstLatitude = 51.478;+ const firstLongitude = -0.166;+ const firstAccuracy = 100;++ // Deliberately far from the first position, so that a reused cached+ // position and a freshly acquired one are distinguishable even after+ // coarsening: no coarsening of one yields the other.+ const secondLatitude = -33.865;+ const secondLongitude = 151.209;+ const secondAccuracy = 120;++ async function setPosition(t, latitude, longitude, accuracy) {+ t.add_cleanup(async () => {+ await test_driver.bidi.emulation.set_geolocation_override(+ {coordinates: null});+ });+ await test_driver.bidi.emulation.set_geolocation_override({+ coordinates: {latitude, longitude, accuracy}+ });+ }++ function getPosition(options) {+ return new Promise((resolve, reject) => {+ navigator.geolocation.getCurrentPosition(resolve, reject, options);+ });+ }++ promise_setup(async () => {+ await test_driver.bidi.permissions.set_permission({+ descriptor: {name: "geolocation"},+ state: "granted",+ });+ });++ // A cached position records the accuracyMode it was acquired with, and may+ // only be reused by a request asking for that same mode.+ //+ // Both tests move the underlying position between the two requests and+ // compare timestamps. A reused cached position keeps the timestamp it was+ // acquired with, so a newer timestamp means a fresh acquisition. That+ // holds regardless of how much an implementation coarsens, which+ // comparing coordinates would not: a wrongly reused precise position that+ // is then coarsened on delivery also differs from the one that was cached.++ promise_test(async (t) => {+ await setPosition(t, firstLatitude, firstLongitude, firstAccuracy);+ const cached = await getPosition({accuracyMode: "approximate"});++ // Ensure any newly acquired position has a distinguishable timestamp,+ // even where timestamp resolution is coarse.+ await new Promise(resolve => t.step_timeout(resolve, 100));++ await setPosition(t, secondLatitude, secondLongitude, secondAccuracy);+ const position = await getPosition({+ accuracyMode: "precise",+ maximumAge: 600000,+ });++ assert_greater_than(position.timestamp, cached.timestamp,+ "the approximate position in the cache must not satisfy a precise request");+ assert_equals(position.coords.latitude, secondLatitude);+ assert_equals(position.coords.longitude, secondLongitude);+ assert_equals(position.coords.accuracy, secondAccuracy);+ }, "A cached approximate position is not reused for a precise request");++ promise_test(async (t) => {+ await setPosition(t, firstLatitude, firstLongitude, firstAccuracy);+ const cached = await getPosition({accuracyMode: "precise"});++ await new Promise(resolve => t.step_timeout(resolve, 100));++ await setPosition(t, secondLatitude, secondLongitude, secondAccuracy);+ const position = await getPosition({+ accuracyMode: "approximate",+ maximumAge: 600000,+ });++ // The coordinates are not compared to the emulated values here: an+ // approximate position is coarsened by an amount left to the+ // implementation. The timestamp is what shows the cache was not used.+ assert_greater_than(position.timestamp, cached.timestamp,+ "the precise position in the cache must not satisfy an approximate request");+ assert_equals(position.coords.altitude, null);+ assert_equals(position.coords.altitudeAccuracy, null);+ assert_equals(position.coords.heading, null);+ assert_equals(position.coords.speed, null);+ }, "A cached precise position is not reused for an approximate request");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition-accuracyMode.https.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition-accuracyMode.https.htmlnew file mode 100644index 00000000000..53797a172c7--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition-accuracyMode.https.html@@ -0,0 +1,80 @@+<!DOCTYPE html>+<meta charset="utf-8"/>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script src="../resources/testdriver.js?feature=bidi"></script>+<script src="../resources/testdriver-vendor.js"></script>++<script>+ const latitude = 51.478;+ const longitude = -0.166;+ const accuracy = 100;+ const altitude = 53;+ const altitudeAccuracy = 30;+ const heading = 10.4;+ const speed = 20.7;++ async function override_geolocation(t) {+ t.add_cleanup(async () => {+ await test_driver.bidi.emulation.set_geolocation_override(+ {coordinates: null});+ });++ await test_driver.bidi.emulation.set_geolocation_override({+ coordinates: {latitude, longitude, accuracy, altitude,+ altitudeAccuracy, heading, speed}+ });+ }++ promise_setup(async () => {+ // Ensure permission is granted before proceeding.+ await test_driver.bidi.permissions.set_permission({+ descriptor: {name: "geolocation"},+ state: "granted",+ });+ });++ promise_test(async (t) => {+ await override_geolocation(t);++ const position = await new Promise((resolve, reject) => {+ window.navigator.geolocation.getCurrentPosition(+ position => resolve(position.coords.toJSON()),+ reject,+ {accuracyMode: "approximate"}+ );+ });++ // The coordinates are not compared to the emulated values: an approximate position is "coarsened+ // to a larger area", and "What constitutes a coarsened area is left to the underlying system,+ // which in turn can vary per jurisdiction", so an implementation that coarsens cannot be+ // required to return them unchanged. They must still be present.+ assert_equals(typeof position.latitude, "number", "latitude must be a number");+ assert_equals(typeof position.longitude, "number", "longitude must be a number");+ assert_equals(typeof position.accuracy, "number", "accuracy must be a number");+ assert_equals(position.altitude, null);+ assert_equals(position.altitudeAccuracy, null);+ assert_equals(position.heading, null);+ assert_equals(position.speed, null);+ }, 'getCurrentPosition with accuracyMode: "approximate"');++ promise_test(async (t) => {+ await override_geolocation(t);++ const position = await new Promise((resolve, reject) => {+ window.navigator.geolocation.getCurrentPosition(+ position => resolve(position.coords.toJSON()),+ reject,+ {accuracyMode: "precise", enableHighAccuracy: true}+ );+ });++ assert_equals(position.latitude, latitude);+ assert_equals(position.longitude, longitude);+ assert_equals(position.accuracy, accuracy);+ assert_equals(position.altitude, altitude);+ assert_equals(position.altitudeAccuracy, altitudeAccuracy);+ assert_equals(position.heading, heading);+ assert_equals(position.speed, speed);+ }, 'getCurrentPosition with accuracyMode: "precise"');+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition_TypeError.https.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition_TypeError.https.htmlnew file mode 100644index 00000000000..621243a429f--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition_TypeError.https.html@@ -0,0 +1,61 @@+<!DOCTYPE HTML>+<meta charset='utf-8'>+<title>Geolocation Test: getCurrentPosition TypeError tests</title>+<link rel='help' href='http://www.w3.org/TR/geolocation-API/'>+<script src='../resources/testharness.js'></script>+<script src='../resources/testharnessreport.js'></script>++<script>+// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00027+test(function() {+ assert_throws_js(TypeError, function() {+ navigator.geolocation.getCurrentPosition();+ });+}, 'Call getCurrentPosition without arguments, check that exception is thrown');++// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00011+test(function() {+ assert_throws_js(TypeError, function() {+ navigator.geolocation.getCurrentPosition(null);+ });+}, 'Call getCurrentPosition with null success callback, check that exception is thrown');++// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00013+test(function() {+ assert_throws_js(TypeError, function() {+ navigator.geolocation.getCurrentPosition(null, null);+ });+}, 'Call getCurrentPosition with null success and error callbacks, check that exception is thrown');++// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00028+test(function() {+ assert_throws_js(TypeError, function() {+ navigator.geolocation.getCurrentPosition(3);+ });+}, 'Call getCurrentPosition() with wrong type for first argument. Exception expected.');++// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00029+test(function() {+ assert_throws_js(TypeError, function() {+ navigator.geolocation.getCurrentPosition(()=>{}, 4);+ });+}, 'Call getCurrentPosition() with wrong type for second argument. Exception expected.');++// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00030+test(function() {+ assert_throws_js(TypeError, function() {+ navigator.geolocation.getCurrentPosition(()=>{}, ()=>{}, 4);+ });+}, 'Call getCurrentPosition() with wrong type for third argument. Exception expected.');++test(function () {+ const handleEvent = ()=>{};+ assert_throws_js(TypeError, function () {+ navigator.geolocation.getCurrentPosition({ handleEvent });+ });++ assert_throws_js(TypeError, function () {+ navigator.geolocation.getCurrentPosition(()=>{}, { handleEvent });+ });+}, "Calling getCurrentPosition() with a legacy event handler objects.");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/heading-stationary.https.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/heading-stationary.https.htmlnew file mode 100644index 00000000000..ac09243fdb9--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/heading-stationary.https.html@@ -0,0 +1,79 @@+<!doctype html>+<meta charset="utf-8" />+<title>Geolocation Test: heading is null when stationary</title>+<link rel="help" href="https://www.w3.org/TR/geolocation/#c9" />+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script src="../resources/testdriver.js?feature=bidi"></script>+<script src="../resources/testdriver-vendor.js"></script>++<script>+ const latitude = 51.478;+ const longitude = -0.166;+ const accuracy = 100;++ promise_setup(async () => {+ await test_driver.set_permission({ name: "geolocation" }, "granted");+ });++ promise_test(async (t) => {+ t.add_cleanup(async () => {+ await test_driver.bidi.emulation.set_geolocation_override({+ coordinates: null,+ });+ });++ // Set geolocation with speed = 0 (stationary)+ await test_driver.bidi.emulation.set_geolocation_override({+ coordinates: {+ latitude,+ longitude,+ accuracy,+ speed: 0,+ },+ });++ const position = await new Promise((resolve, reject) => {+ navigator.geolocation.getCurrentPosition(resolve, reject);+ });++ // When stationary (speed is 0), heading must be null, not NaN+ assert_equals(+ position.coords.heading,+ null,+ "heading must be null when device is stationary (speed is 0)",+ );+ assert_equals(position.coords.speed, 0, "speed should be 0");+ }, "heading is null when stationary (speed is 0)");++ promise_test(async (t) => {+ t.add_cleanup(async () => {+ await test_driver.bidi.emulation.set_geolocation_override({+ coordinates: null,+ });+ });++ // Set geolocation with speed > 0 (moving) and a heading+ await test_driver.bidi.emulation.set_geolocation_override({+ coordinates: {+ latitude,+ longitude,+ accuracy,+ speed: 10,+ heading: 90,+ },+ });++ const position = await new Promise((resolve, reject) => {+ navigator.geolocation.getCurrentPosition(resolve, reject);+ });++ // When moving (speed > 0), heading should be the specified value+ assert_equals(+ position.coords.heading,+ 90,+ "heading should be 90 when moving",+ );+ assert_equals(position.coords.speed, 10, "speed should be 10");+ }, "heading has a value when moving (speed > 0)");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/non-fully-active.https.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/non-fully-active.https.htmlnew file mode 100644index 00000000000..f19d6b1bf69--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/non-fully-active.https.html@@ -0,0 +1,161 @@+<!doctype html>+<meta charset="utf-8" />+<title>Geolocation Test: non-fully active document</title>+<link rel="help" href="https://github.com/w3c/geolocation-api/pull/97" />+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script src="../resources/testdriver.js?feature=bidi"></script>+<script src="../resources/testdriver-vendor.js"></script>+<script src="support.js"></script>+<body></body>+<script>+ promise_setup(async () => {+ await test_driver.bidi.permissions.set_permission({+ descriptor: { name: "geolocation" },+ state: "granted",+ });+ await test_driver.bidi.emulation.set_geolocation_override({+ coordinates: { latitude: 51.478, longitude: -0.166, accuracy: 100 },+ });+ });++ promise_test(async (t) => {+ const iframe = document.createElement("iframe");+ await new Promise((resolve) => {+ iframe.src = "resources/iframe.html";+ iframe.allow = "geolocation";+ iframe.addEventListener("load", resolve, { once: true });+ document.body.appendChild(iframe);+ });++ const geo = iframe.contentWindow.navigator.geolocation;+ iframe.remove();++ const watchId = geo.watchPosition(+ () => {},+ () => {},+ );+ assert_equals(watchId, 0, "watchId is 0 when document is not fully-active");++ const watchId2 = geo.watchPosition(+ () => {},+ () => {},+ );+ assert_equals(+ watchId2,+ 0,+ "watchId remains 0 when document is not fully-active",+ );+ }, "watchPosition returns 0 for non-fully-active document");++ promise_test(async (t) => {+ const iframe = document.createElement("iframe");+ await new Promise((resolve) => {+ iframe.src = "resources/iframe.html";+ iframe.allow = "geolocation";+ iframe.addEventListener("load", resolve, { once: true });+ document.body.appendChild(iframe);+ });++ const geo = iframe.contentWindow.navigator.geolocation;+ iframe.remove();++ const result = await new Promise((resolve) => {+ const timeoutId = t.step_timeout(() => {+ resolve({ timedOut: true });+ }, 100);++ geo.watchPosition(+ () => resolve({ success: true }),+ (error) => {+ clearTimeout(timeoutId);+ resolve({ error });+ },+ );+ });++ assert_false(result.timedOut, "errorCallback should be called");+ assert_false(result.success, "successCallback should not be called");+ assert_equals(+ result.error.code,+ GeolocationPositionError.POSITION_UNAVAILABLE,+ "errorCallback receives POSITION_UNAVAILABLE",+ );+ }, "watchPosition calls errorCallback with POSITION_UNAVAILABLE for non-fully-active document");++ promise_test(async (t) => {+ const iframe = document.createElement("iframe");+ await new Promise((resolve) => {+ iframe.src = "resources/iframe.html";+ iframe.allow = "geolocation";+ iframe.addEventListener("load", resolve, { once: true });+ document.body.appendChild(iframe);+ });++ const geo = iframe.contentWindow.navigator.geolocation;+ iframe.remove();++ const result = await new Promise((resolve) => {+ const timeoutId = t.step_timeout(() => {+ resolve({ timedOut: true });+ }, 100);++ geo.getCurrentPosition(+ () => resolve({ success: true }),+ (error) => {+ clearTimeout(timeoutId);+ resolve({ error });+ },+ );+ });++ assert_false(result.timedOut, "errorCallback should be called");+ assert_false(result.success, "successCallback should not be called");+ assert_equals(+ result.error.code,+ GeolocationPositionError.POSITION_UNAVAILABLE,+ "errorCallback receives POSITION_UNAVAILABLE",+ );+ }, "getCurrentPosition calls errorCallback with POSITION_UNAVAILABLE for non-fully-active document");++ promise_test(async (t) => {+ t.add_cleanup(async () => {+ await test_driver.bidi.emulation.set_geolocation_override({+ coordinates: null,+ });+ });++ const iframe = document.createElement("iframe");+ await new Promise((resolve) => {+ iframe.src = "resources/iframe.html";+ iframe.allow = "geolocation";+ iframe.addEventListener("load", resolve, { once: true });+ document.body.appendChild(iframe);+ });++ iframe.remove();+ document.body.appendChild(iframe);+ await new Promise((resolve) =>+ iframe.addEventListener("load", resolve, { once: true }),+ );++ let watchId;+ let position = await new Promise((resolve, reject) => {+ watchId = iframe.contentWindow.navigator.geolocation.watchPosition(+ resolve,+ reject,+ );+ });+ assert_true(Number.isInteger(watchId), "Expected integer watchId");+ assert_true(Boolean(position), "Expected a position");++ position = await new Promise((resolve, reject) => {+ iframe.contentWindow.navigator.geolocation.getCurrentPosition(+ resolve,+ reject,+ );+ });+ assert_true(Boolean(position), "Expected a position");+ iframe.contentWindow.navigator.geolocation.clearWatch(watchId);+ }, "re-attached document restores geolocation functionality");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/non-secure-contexts.http.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/non-secure-contexts.http.htmlnew file mode 100644index 00000000000..ca5250ea400--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/non-secure-contexts.http.html@@ -0,0 +1,82 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>Geolocation Test: non-secure contexts</title>+<link rel="help" href="https://github.com/w3c/geolocation-api/pull/34" />+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script>+ promise_test(() => {+ return new Promise(resolve => {+ let isAsync = true;+ const successCallback = () => {+ assert_unreached(+ "successCallback must never be invoked in non-secure contexts."+ );+ };+ const errorCallBack = () => {+ isAsync = false;+ resolve();+ };+ navigator.geolocation.getCurrentPosition(successCallback, errorCallBack);+ assert_true(+ isAsync,+ "Expected the errorCallback to be called asynchronously."+ );+ });+ }, "When in a non-secure context, getCurrentPosition()'s errorCallback is asynchronously called.");++ promise_test(async () => {+ return new Promise(resolve => {+ let isAsync = true;+ const successCallback = () => {+ assert_unreached(+ "successCallback must never be invoked in non-secure contexts."+ );+ };+ const errorCallBack = () => {+ isAsync = false;+ resolve();+ };+ navigator.geolocation.watchPosition(successCallback, errorCallBack);+ assert_true(isAsync, "errorCallback must be called asynchronously.");+ });+ }, "When in a non-secure context, watchPosition()'s errorCallback is asynchronously called.");++ promise_test(async () => {+ const positionErrorPromise = new Promise(errorCallBack => {+ const successCallback = () => {+ assert_unreached(+ "successCallback must never be invoked in non-secure contexts."+ );+ };+ navigator.geolocation.getCurrentPosition(successCallback, errorCallBack);+ });+ const positionError = await positionErrorPromise;+ assert_equals(+ positionError.code,+ 1,+ "Expected the value for PERMISSION_DENIED, which is 1."+ );+ }, "When in a non-secure context, the getCurrentPosition() errorCallBack gets a GeolocationPositionError with the correct error code.");++ promise_test(async () => {+ const positionErrorPromise = new Promise(errorCallBack => {+ const successCallback = () => {+ assert_unreached(+ "successCallback must never be invoked in non-secure contexts."+ );+ };+ const id = navigator.geolocation.watchPosition(+ successCallback,+ errorCallBack+ );+ assert_true(Number.isInteger(id), "Must return an identifier.");+ });+ const positionError = await positionErrorPromise;+ assert_equals(+ positionError.code,+ 1,+ "Expected the value for PERMISSION_DENIED, which is 1."+ );+ }, "When in a non-secure context, the watchPosition() errorCallBack gets a GeolocationPositionError with the correct error code.");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/resources/iframe.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/resources/iframe.htmlnew file mode 100644index 00000000000..25cf3d92f39--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/resources/iframe.html@@ -0,0 +1,3 @@+<!DOCTYPE html>+<meta charset="utf-8">+<h1>Just a support file</h1>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/support.js b/Tests/LibWeb/Text/input/wpt-import/geolocation/support.jsnew file mode 100644index 00000000000..0f0e7f65b2c--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/support.js@@ -0,0 +1,30 @@+var geo;++setup(function() {+ geo = navigator.geolocation;+});++// The spec states that an implementation SHOULD acquire user permission before+// beginning the position acquisition steps. If an implementation follows this+// advice, set the following flag to aid debugging.+var isUsingPreemptivePermission = false;+++var dummyFunction = function() {};++var positionToString = function(pos) {+ var c = pos.coords;+ return '[lat: ' + c.latitude + ', lon: ' + c.longitude + ', acc: ' + c.accuracy + ']';+};++var errorToString = function(err) {+ var codeString;+ switch(err.code) {+ case err.UNKNOWN_ERROR: codeString = 'UNKNOWN_ERROR'; break;+ case err.PERMISSION_DENIED: codeString = 'PERMISSION_DENIED'; break;+ case err.POSITION_UNAVAILABLE: codeString = 'POSITION_UNAVAILABLE'; break;+ case err.TIMEOUT: codeString = 'TIMEOUT'; break;+ default: codeString = 'undefined error code'; break;+ }+ return '[code: ' + codeString + ' (' + err.code + '), message: ' + (err.message ? err.message : '(empty)') + ']';+};diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/tojson.https.window.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/tojson.https.window.htmlnew file mode 100644index 00000000000..6822a593c83--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/tojson.https.window.html@@ -0,0 +1,9 @@+<!doctype html>+<meta charset=utf-8>++<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script src="../resources/testdriver.js?feature=bidi"></script>+<script src="../resources/testdriver-vendor.js"></script>+<div id=log></div>+<script src="../geolocation/tojson.https.window.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/tojson.https.window.js b/Tests/LibWeb/Text/input/wpt-import/geolocation/tojson.https.window.jsnew file mode 100644index 00000000000..0f8f4f7628b--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/tojson.https.window.js@@ -0,0 +1,53 @@+// META: script=/resources/testdriver.js?feature=bidi+// META: script=/resources/testdriver-vendor.js+"use strict";++function check_equals(original, json) {+ const proto = Object.getPrototypeOf(original);+ const keys = Object.keys(proto).filter(+ (k) => typeof original[k] !== "function",+ );+ for (const key of keys) {+ assert_equals(+ original[key],+ json[key],+ `${original.constructor.name} ${key} entry does not match its toJSON value`,+ );+ }+}++promise_setup(async () => {+ // Ensure permission is granted before proceeding.+ await test_driver.bidi.permissions.set_permission({+ descriptor: {name: "geolocation"},+ state: "granted",+ });+});++promise_test(async (t) => {+ t.add_cleanup(async () => {+ await test_driver.bidi.emulation.set_geolocation_override(+ {coordinates: null});+ });++ const latitude = 51.478;+ const longitude = -0.166;+ const accuracy = 100;+ await test_driver.bidi.emulation.set_geolocation_override({+ coordinates: {latitude, longitude, accuracy}+ });++ const position = await new Promise((resolve, reject) => {+ navigator.geolocation.getCurrentPosition(resolve, reject);+ });++ const json = position.toJSON();+ assert_equals(+ position.timestamp,+ json.timestamp,+ "GeolocationPosition timestamp entry does not match its toJSON value",+ );++ check_equals(position.coords, json.coords);+ check_equals(position.coords, position.coords.toJSON());+}, "Test toJSON() in GeolocationPosition and GeolocationCoordinates.");diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/watchPosition_TypeError.https.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/watchPosition_TypeError.https.htmlnew file mode 100644index 00000000000..d896516681c--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/watchPosition_TypeError.https.html@@ -0,0 +1,65 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>Geolocation Test: watchPosition TypeError tests</title>+<link rel="help" href="http://www.w3.org/TR/geolocation-API/" />+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>++<script>+ // Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00058+ test(() => {+ assert_throws_js(TypeError, () => {+ navigator.geolocation.watchPosition();+ });+ }, "Call watchPosition without arguments, check that exception is thrown");++ // Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00015+ test(() => {+ assert_throws_js(TypeError, () => {+ navigator.geolocation.watchPosition(null);+ });+ }, "Call watchPosition with null success callback, check that exception is thrown");++ // Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00017+ test(() => {+ assert_throws_js(TypeError, () => {+ navigator.geolocation.watchPosition(null, null);+ });+ }, "Call watchPosition with null success and error callbacks, check that exception is thrown");++ // Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00059+ test(() => {+ assert_throws_js(TypeError, () => {+ navigator.geolocation.watchPosition(3);+ });+ }, "Call watchPosition() with wrong type for first argument. Exception expected.");++ // Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00060+ test(() => {+ assert_throws_js(TypeError, () => {+ navigator.geolocation.watchPosition(() => {}, 4);+ });+ }, "Call watchPosition() with wrong type for second argument. Exception expected.");++ // Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00061+ test(() => {+ assert_throws_js(TypeError, () => {+ navigator.geolocation.watchPosition(+ () => {},+ () => {},+ 4+ );+ });+ }, "Call watchPosition() with wrong type for third argument. Exception expected.");++ test(function () {+ const handleEvent = function(){};+ assert_throws_js(TypeError, function () {+ navigator.geolocation.watchPosition({ handleEvent });+ });++ assert_throws_js(TypeError, function () {+ navigator.geolocation.watchPosition(()=>{}, { handleEvent });+ });+ }, "Calling watchPosition() with a legacy event handler object.");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/watchposition-timeout.https.window.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/watchposition-timeout.https.window.htmlnew file mode 100644index 00000000000..7b5c6df7caf--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/watchposition-timeout.https.window.html@@ -0,0 +1,9 @@+<!doctype html>+<meta charset=utf-8>++<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>+<div id=log></div>+<script src="../geolocation/watchposition-timeout.https.window.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/watchposition-timeout.https.window.js b/Tests/LibWeb/Text/input/wpt-import/geolocation/watchposition-timeout.https.window.jsnew file mode 100644index 00000000000..fc1edd6ea95--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/watchposition-timeout.https.window.js@@ -0,0 +1,22 @@+// META: script=/resources/testdriver.js+// META: script=/resources/testdriver-vendor.js++promise_setup(async () => {+ await test_driver.set_permission({ name: "geolocation" }, "granted");+});++promise_test(async (t) => {+ let timeoutCount = 0;++ // This may still succeed without timeout in case there's a cache.+ const watchId = navigator.geolocation.watchPosition(() => {}, (error) => {+ if (error.code === GeolocationPositionError.TIMEOUT) {+ ++timeoutCount;+ }+ }, { timeout: 1 });+ t.add_cleanup(() => navigator.geolocation.clearWatch(watchId));++ await new Promise(r => setTimeout(r, 100));++ assert_true(timeoutCount < 2, "At most one timeout should have been seen");+}, "Passing timeout=1 should not cause multiple timeout errors");diff --git a/Tests/LibWeb/Text/input/wpt-import/permissions-policy/resources/permissions-policy-geolocation.html b/Tests/LibWeb/Text/input/wpt-import/permissions-policy/resources/permissions-policy-geolocation.htmlnew file mode 100644index 00000000000..e32dde3845b--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/permissions-policy/resources/permissions-policy-geolocation.html@@ -0,0 +1,11 @@+<script>+ const type = "availability-result";+ navigator.geolocation.getCurrentPosition(+ () => {+ window.parent.postMessage({ type, enabled: true }, "*");+ },+ () => {+ window.parent.postMessage({ type, enabled: false }, "*");+ }+ );+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/permissions-policy/resources/permissions-policy.js b/Tests/LibWeb/Text/input/wpt-import/permissions-policy/resources/permissions-policy.jsnew file mode 100644index 00000000000..cfc6d3caab1--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/permissions-policy/resources/permissions-policy.js@@ -0,0 +1,500 @@+// Feature test to avoid timeouts+function assert_permissions_policy_supported() {+ assert_true("allow" in HTMLIFrameElement.prototype, 'permissions policy is supported');+}+// Tests whether a feature that is enabled/disabled by permissions policy works+// as expected.+// Arguments:+// feature_descriptionOrObject: either and object, containing the following+// properties, or a string describing what feature is being tested.+// Examples: "usb.GetDevices()", "PaymentRequest()".+// test: test created by testharness. Examples: async_test, promise_test.+// src: URL where a feature's availability is checked. Examples:+// "/permissions-policy/resources/permissions-policy-payment.html",+// "/permissions-policy/resources/permissions-policy-usb.html".+// expect_feature_available: a callback(data, feature_description) to+// verify if a feature is available or unavailable as expected.+// The file under the path "src" defines what "data" is sent back via+// postMessage with type: 'availability-result'.+// Inside the callback, some tests (e.g., EXPECT_EQ, EXPECT_TRUE, etc)+// are run accordingly to test a feature's availability.+// Example: expect_feature_available_default(data, feature_description).+// feature_name: Optional argument, only provided when testing iframe allow+// attribute. "feature_name" is the feature name of a policy controlled+// feature (https://w3c.github.io/webappsec-permissions-policy/#features).+// See examples at:+// https://github.com/w3c/webappsec-permissions-policy/blob/main/features.md+// allowfullscreen: Optional argument, only used for testing fullscreen+// by passing "allowfullscreen".+// is_promise_test: Optional argument, true if this call should return a+// promise. Used by test_feature_availability_with_post_message_result()+function test_feature_availability(+ feature_descriptionOrObject, test, src, expect_feature_available, feature_name,+ allowfullscreen, is_promise_test = false, needs_focus = false) {++ if (feature_descriptionOrObject && feature_descriptionOrObject instanceof Object) {+ const {+ feature_description,+ test,+ src,+ expect_feature_available,+ feature_name,+ allowfullscreen,+ is_promise_test,+ needs_focus,+ } = feature_descriptionOrObject;+ return test_feature_availability(+ feature_description,+ test,+ src,+ expect_feature_available,+ feature_name,+ allowfullscreen,+ is_promise_test,+ needs_focus,+ );+ }++ const feature_description = feature_descriptionOrObject;+ let frame = document.createElement('iframe');+ frame.src = src;++ if (typeof feature_name !== 'undefined') {+ frame.allow = frame.allow.concat(";" + feature_name);+ }++ if (typeof allowfullscreen !== 'undefined') {+ frame.setAttribute(allowfullscreen, true);+ }++ function expectFeatureAvailable(evt) {+ if (evt.source === frame.contentWindow &&+ evt.data.type === 'availability-result') {+ expect_feature_available(evt.data, feature_description);+ document.body.removeChild(frame);+ test.done();+ }+ }++ if (!is_promise_test) {+ window.addEventListener('message', test.step_func(expectFeatureAvailable));+ document.body.appendChild(frame);+ return;+ }++ const promise = new Promise((resolve) => {+ window.addEventListener('message', resolve);+ }).then(expectFeatureAvailable);+ document.body.appendChild(frame);+ if (needs_focus) {+ frame.focus();+ }+ return promise;+}++// Default helper functions to test a feature's availability:+function expect_feature_available_default(data, feature_description) {+ assert_true(data.enabled, feature_description);+}++function expect_feature_unavailable_default(data, feature_description) {+ assert_false(data.enabled, feature_description);+}++// This is the same as test_feature_availability() but instead of passing in a+// function to check the result of the message sent back from an iframe, instead+// just compares the result to an expected result passed in.+// Arguments:+// test: test created by testharness. Examples: async_test, promise_test.+// src: the URL to load in an iframe in which to test the feature.+// expected_result: the expected value to compare to the data passed back+// from the src page by postMessage.+// allow_attribute: Optional argument, only provided when an allow+// attribute should be specified on the iframe.+function test_feature_availability_with_post_message_result(+ test, src, expected_result, allow_attribute) {+ const test_result = ({ name, message }, feature_description) => {+ assert_equals(name, expected_result, message + '.');+ };+ return test_feature_availability(+ null, test, src, test_result, allow_attribute, undefined, true);+}++// If this page is intended to test the named feature (according to the URL),+// tests the feature availability and posts the result back to the parent.+// Otherwise, does nothing.+async function test_feature_in_iframe(feature_name, feature_promise_factory) {+ if (location.hash.endsWith(`#${feature_name}`)) {+ let message = 'Available';+ let name = '#OK';+ try {+ await feature_promise_factory();+ } catch (e) {+ ({ name, message } = e);+ }+ window.parent.postMessage(+ { type: 'availability-result', name, message }, '*');+ }+}++// Returns true if the URL for this page indicates that it is embedded in an+// iframe.+function page_loaded_in_iframe() {+ return new URLSearchParams(location.search).get('in-iframe');+}++// Returns a same-origin (relative) URL suitable for embedding in an iframe for+// testing the availability of the feature.+function same_origin_url(feature_name) {+ // Add an "in-iframe" query parameter so that we can detect the iframe'd+ // version of the page and testharness script loading can be disabled in+ // that version, as required for use of testdriver in non-toplevel browsing+ // contexts.+ return location.pathname + '?in-iframe=yes#' + feature_name;+}++// Returns a cross-origin (absolute) URL suitable for embedding in an iframe for+// testing the availability of the feature.+function cross_origin_url(base_url, feature_name) {+ return base_url + same_origin_url(feature_name);+}++// This function runs all permissions policy tests for a particular feature that+// has a default policy of "self". This includes testing:+// 1. Feature usage succeeds by default in the top level frame.+// 2. Feature usage succeeds by default in a same-origin iframe.+// 3. Feature usage fails by default in a cross-origin iframe.+// 4. Feature usage succeeds when an allow attribute is specified on a+// cross-origin iframe.+// 5. Feature usage fails when an allow attribute is specified on a+// same-origin iframe with a value of "feature-name 'none'".+//+// The same page which called this function will be loaded in the iframe in+// order to test feature usage there. When this function is called in that+// context it will simply run the feature and return a result back via+// postMessage.+//+// Arguments:+// cross_origin: A cross-origin URL base to be used to load the page which+// called into this function.+// feature_name: The name of the feature as it should be specified in an+// allow attribute.+// error_name: If feature usage does not succeed, this is the string+// representation of the error that will be passed in the rejected+// promise.+// feature_promise_factory: A function which returns a promise which tests+// feature usage. If usage succeeds, the promise should resolve. If it+// fails, the promise should reject with an error that can be+// represented as a string.+function run_all_fp_tests_allow_self(+ cross_origin, feature_name, error_name, feature_promise_factory) {+ // This may be the version of the page loaded up in an iframe. If so, just+ // post the result of running the feature promise back to the parent.+ if (page_loaded_in_iframe()) {+ test_feature_in_iframe(feature_name, feature_promise_factory);+ return;+ }++ // Run the various tests.+ // 1. Allowed in top-level frame.+ promise_test(+ () => feature_promise_factory(),+ 'Default "' + feature_name ++ '" permissions policy ["self"] allows the top-level document.');++ // 2. Allowed in same-origin iframe.+ const same_origin_frame_pathname = same_origin_url(feature_name);+ promise_test(+ t => {+ return test_feature_availability_with_post_message_result(+ t, same_origin_frame_pathname, '#OK');+ },+ 'Default "' + feature_name ++ '" permissions policy ["self"] allows same-origin iframes.');++ // 3. Blocked in cross-origin iframe.+ const cross_origin_frame_url = cross_origin_url(cross_origin, feature_name);+ promise_test(+ t => {+ return test_feature_availability_with_post_message_result(+ t, cross_origin_frame_url, error_name);+ },+ 'Default "' + feature_name ++ '" permissions policy ["self"] disallows cross-origin iframes.');++ // 4. Allowed in cross-origin iframe with "allow" attribute.+ promise_test(+ t => {+ return test_feature_availability_with_post_message_result(+ t, cross_origin_frame_url, '#OK', feature_name);+ },+ 'permissions policy "' + feature_name ++ '" can be enabled in cross-origin iframes using "allow" attribute.');++ // 5. Blocked in same-origin iframe with "allow" attribute set to 'none'.+ promise_test(+ t => {+ return test_feature_availability_with_post_message_result(+ t, same_origin_frame_pathname, error_name,+ feature_name + ' \'none\'');+ },+ 'permissions policy "' + feature_name ++ '" can be disabled in same-origin iframes using "allow" attribute.');+}++// This function runs all permissions policy tests for a particular feature that+// has a default policy of "*". This includes testing:+// 1. Feature usage succeeds by default in the top level frame.+// 2. Feature usage succeeds by default in a same-origin iframe.+// 3. Feature usage succeeds by default in a cross-origin iframe.+// 4. Feature usage fails when an allow attribute is specified on a+// cross-origin iframe with a value of "feature-name 'none'".+// 5. Feature usage fails when an allow attribute is specified on a+// same-origin iframe with a value of "feature-name 'none'".+//+// The same page which called this function will be loaded in the iframe in+// order to test feature usage there. When this function is called in that+// context it will simply run the feature and return a result back via+// postMessage.+//+// Arguments:+// cross_origin: A cross-origin URL base to be used to load the page which+// called into this function.+// feature_name: The name of the feature as it should be specified in an+// allow attribute.+// error_name: If feature usage does not succeed, this is the string+// representation of the error that will be passed in the rejected+// promise.+// feature_promise_factory: A function which returns a promise which tests+// feature usage. If usage succeeds, the promise should resolve. If it+// fails, the promise should reject with an error that can be+// represented as a string.+function run_all_fp_tests_allow_all(+ cross_origin, feature_name, error_name, feature_promise_factory) {+ // This may be the version of the page loaded up in an iframe. If so, just+ // post the result of running the feature promise back to the parent.+ if (page_loaded_in_iframe()) {+ test_feature_in_iframe(feature_name, feature_promise_factory);+ return;+ }++ // Run the various tests.+ // 1. Allowed in top-level frame.+ promise_test(+ () => feature_promise_factory(),+ 'Default "' + feature_name ++ '" permissions policy ["*"] allows the top-level document.');++ // 2. Allowed in same-origin iframe.+ const same_origin_frame_pathname = same_origin_url(feature_name);+ promise_test(+ t => {+ return test_feature_availability_with_post_message_result(+ t, same_origin_frame_pathname, '#OK');+ },+ 'Default "' + feature_name ++ '" permissions policy ["*"] allows same-origin iframes.');++ // 3. Allowed in cross-origin iframe.+ const cross_origin_frame_url = cross_origin_url(cross_origin, feature_name);+ promise_test(+ t => {+ return test_feature_availability_with_post_message_result(+ t, cross_origin_frame_url, '#OK');+ },+ 'Default "' + feature_name ++ '" permissions policy ["*"] allows cross-origin iframes.');++ // 4. Blocked in cross-origin iframe with "allow" attribute set to 'none'.+ promise_test(+ t => {+ return test_feature_availability_with_post_message_result(+ t, cross_origin_frame_url, error_name, feature_name + ' \'none\'');+ },+ 'permissions policy "' + feature_name ++ '" can be disabled in cross-origin iframes using "allow" attribute.');++ // 5. Blocked in same-origin iframe with "allow" attribute set to 'none'.+ promise_test(+ t => {+ return test_feature_availability_with_post_message_result(+ t, same_origin_frame_pathname, error_name,+ feature_name + ' \'none\'');+ },+ 'permissions policy "' + feature_name ++ '" can be disabled in same-origin iframes using "allow" attribute.');+}++// This function tests that a subframe's document policy allows a given feature.+// A feature is allowed in a frame either through inherited policy or specified+// by iframe allow attribute.+// Arguments:+// test: test created by testharness. Examples: async_test, promise_test.+// feature: feature name that should be allowed in the frame.+// src: the URL to load in the frame.+// allow: the allow attribute (container policy) of the iframe+function test_allowed_feature_for_subframe(message, feature, src, allow) {+ let frame = document.createElement('iframe');+ if (typeof allow !== 'undefined') {+ frame.allow = allow;+ }+ promise_test(function() {+ assert_permissions_policy_supported();+ frame.src = src;+ return new Promise(function(resolve, reject) {+ window.addEventListener('message', function handler(evt) {+ resolve(evt.data);+ }, { once: true });+ document.body.appendChild(frame);+ }).then(function(data) {+ assert_true(data.includes(feature), feature);+ });+ }, message);+}++// This function tests that a subframe's document policy disallows a given+// feature. A feature is allowed in a frame either through inherited policy or+// specified by iframe allow attribute.+// Arguments:+// test: test created by testharness. Examples: async_test, promise_test.+// feature: feature name that should not be allowed in the frame.+// src: the URL to load in the frame.+// allow: the allow attribute (container policy) of the iframe+function test_disallowed_feature_for_subframe(message, feature, src, allow) {+ let frame = document.createElement('iframe');+ if (typeof allow !== 'undefined') {+ frame.allow = allow;+ }+ promise_test(function() {+ assert_permissions_policy_supported();+ frame.src = src;+ return new Promise(function(resolve, reject) {+ window.addEventListener('message', function handler(evt) {+ resolve(evt.data);+ }, { once: true });+ document.body.appendChild(frame);+ }).then(function(data) {+ assert_false(data.includes(feature), feature);+ });+ }, message);+}++// This function tests that a subframe with header policy defined on a given+// feature allows and disallows the feature as expected.+// Arguments:+// feature: feature name.+// frame_header_policy: either *, self or \\(\\), defines the frame+// document's header policy on |feature|.+// '(' and ')' need to be escaped because of server end+// header parameter syntax limitation.+// src: the URL to load in the frame.+// test_expects: contains 6 expected results of either |feature| is allowed+// or not inside of a local or remote iframe nested inside+// the subframe given the header policy to be either *,+// self, or ().+// test_name: name of the test.+function test_subframe_header_policy(+ feature, frame_header_policy, src, test_expects, test_name) {+ let frame = document.createElement('iframe');+ promise_test(function() {+ assert_permissions_policy_supported()+ frame.src = src + '?pipe=sub|header(Permissions-Policy,' + feature + '='+ + frame_header_policy + ')';+ return new Promise(function(resolve) {+ window.addEventListener('message', function handler(evt) {+ resolve(evt.data);+ });+ document.body.appendChild(frame);+ }).then(function(results) {+ for (var j = 0; j < results.length; j++) {+ var data = results[j];++ function test_result(message, test_expect) {+ if (test_expect) {+ assert_true(data.allowedfeatures.includes(feature), message);+ } else {+ assert_false(data.allowedfeatures.includes(feature), message);+ }+ }++ if (data.frame === 'local') {+ if (data.policy === '*') {+ test_result('local_all:', test_expects.local_all);+ }+ if (data.policy === 'self') {+ test_result('local_self:', test_expects.local_self);+ }+ if (data.policy === '\\(\\)') {+ test_result('local_none:', test_expects.local_none);+ }+ }++ if (data.frame === 'remote') {+ if (data.policy === '*') {+ test_result('remote_all:', test_expects.remote_all);+ }+ if (data.policy === 'self') {+ test_result('remote_self:', test_expects.remote_self);+ }+ if (data.policy === '\\(\\)') {+ test_result('remote_none:', test_expects.remote_none);+ }+ }+ }+ });+ }, test_name);+}++// This function tests that frame policy allows a given feature correctly. A+// feature is allowed in a frame either through inherited policy or specified+// by iframe allow attribute.+// Arguments:+// feature: feature name.+// src: the URL to load in the frame. If undefined, the iframe will have a+// srcdoc="" attribute+// test_expect: boolean value of whether the feature should be allowed.+// allow: optional, the allow attribute (container policy) of the iframe.+// allowfullscreen: optional, boolean value of allowfullscreen attribute.+// sandbox: optional boolean. If true, the frame will be sandboxed (with+// allow-scripts, so that tests can run in it.)+function test_frame_policy(+ feature, src, srcdoc, test_expect, allow, allowfullscreen, sandbox) {+ let frame = document.createElement('iframe');+ document.body.appendChild(frame);+ // frame_policy should be dynamically updated as allow and allowfullscreen is+ // updated.+ var frame_policy = frame.permissionsPolicy;+ if (typeof allow !== 'undefined') {+ frame.setAttribute('allow', allow);+ }+ if (!!allowfullscreen) {+ frame.setAttribute('allowfullscreen', true);+ }+ if (!!sandbox) {+ frame.setAttribute('sandbox', 'allow-scripts');+ }+ if (!!src) {+ frame.src = src;+ }+ if (!!srcdoc) {+ frame.srcdoc = "<h1>Hello world!</h1>";+ }+ if (test_expect) {+ assert_true(frame_policy.allowedFeatures().includes(feature));+ } else {+ assert_false(frame_policy.allowedFeatures().includes(feature));+ }+}++function expect_reports(report_count, policy_name, description) {+ async_test(t => {+ var num_received_reports = 0;+ new ReportingObserver(t.step_func((reports, observer) => {+ const relevant_reports = reports.filter(r => (r.body.featureId === policy_name));+ num_received_reports += relevant_reports.length;+ if (num_received_reports >= report_count) {+ t.done();+ }+ }), {types: ['permissions-policy-violation'], buffered: true}).observe();+ }, description);+}diff --git a/Tests/LibWeb/Text/input/wpt-import/permissions-policy/resources/redirect-on-load.html b/Tests/LibWeb/Text/input/wpt-import/permissions-policy/resources/redirect-on-load.htmlnew file mode 100644index 00000000000..54d3cf55b1d--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/permissions-policy/resources/redirect-on-load.html@@ -0,0 +1,11 @@+<!DOCTYPE html>+<body>+<script>+// Automatically redirects the page to a new URL on load.+// Load this document with a URL like:+// "permissions-policy/resources/redirect-on-load.html#https://www.example.com/"+window.onload = function () {+ document.location = document.location.hash.substring(1);+}+</script>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/permissions/permissions-cg.https.html b/Tests/LibWeb/Text/input/wpt-import/permissions/permissions-cg.https.htmlnew file mode 100644index 00000000000..3432e2c4f94--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/permissions/permissions-cg.https.html@@ -0,0 +1,36 @@+<!doctype html>+<meta charset=utf-8>+<title>Test PermissionStatus's name attribute.</title>+<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 src="../common/gc.js"></script>++<script>+promise_test(async () => {+ const { state: initialState } = await navigator.permissions.query({+ name: "geolocation",+ });++ const pass = new Promise(async (resolve) => {+ let status = await navigator.permissions.query({+ name: "geolocation",+ });+ status.addEventListener("change", resolve, { once: true });++ status = null;+ await garbageCollect();++ // Will cause change event to be dispatched.+ await test_driver.set_permission({ name: "geolocation" }, "granted");+ });++ // Wait for the change event to be dispatched.+ await pass;++ // Reset the permission to its default value.+ await test_driver.set_permission({ name: "geolocation" }, initialState);+}, "status is not garbage collected when it goes out of scope");++</script>