Truly independent web browser
Tests: Import WPT permissions and geolocation tests
sideshowbarkerb8771cc28477
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 6a3770c3c9a..d78c212f95b 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -8,6 +8,8 @@ Text/input/wpt-import/custom-elements/connected-callbacks.htmlText/input/wpt-import/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio.html; Permissions are kept for a site's origin, and a file: page has none.Text/input/PermissionsAPI/+Text/input/wpt-import/geolocation/+Text/input/wpt-import/permissions/Text/input/HTML/xml-document-encoding.htmlText/input/HTML/createImageBitmap-video.htmlText/input/HTML/HTMLVideoElement-capture-before-seek-keeps-frame.htmldiff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/PositionOptions.https.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/PositionOptions.https.txtnew file mode 100644index 00000000000..b8c176d277b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/PositionOptions.https.txt@@ -0,0 +1,12 @@+Harness status: OK++Found 6 tests++2 Pass+4 Fail+Fail Set timeout and maximumAge to 0, check that timeout error raised (getCurrentPosition)+Fail Set timeout and maximumAge to 0, check that timeout error raised (watchPosition)+Fail Check that a negative timeout and maxAge values are clamped to 0 (getCurrentPosition)+Fail Check that a negative timeout and maxAge values are clamped to 0 (watchPosition)+Pass Call getCurrentPosition with wrong type for enableHighAccuracy. No exception expected.+Pass Call watchPosition with wrong type for enableHighAccuracy. No exception expected.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-error.https.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-error.https.txtnew file mode 100644index 00000000000..1402c747b01--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-error.https.txt@@ -0,0 +1,6 @@+Harness status: Error++Found 1 tests++1 Not Run+Not Run Tests Geolocation error callback\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-success.https.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-success.https.txtnew file mode 100644index 00000000000..fd2b5fd445f--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-success.https.txt@@ -0,0 +1,7 @@+Harness status: Error++Found 2 tests++2 Not Run+Not Run getCurrentPosition called with success and error callbacks+Not Run Error callback is nullable for getCurrentPosition().\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition_permission_deny.https.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition_permission_deny.https.txtnew file mode 100644index 00000000000..c4bfac91bbc--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition_permission_deny.https.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass User denies access, check that error callback is called with correct code\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/permission.https.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/permission.https.txtnew file mode 100644index 00000000000..73687c25ba1--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/permission.https.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Query "geolocation" powerful feature\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/watchPosition_permission_deny.https.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/watchPosition_permission_deny.https.txtnew file mode 100644index 00000000000..7c30ca072c4--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/watchPosition_permission_deny.https.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass Check that watchPosition returns synchronously before any callbacks are invoked.+Pass User denies access, check that error callback is called.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/permissions/event-model.https.txt b/Tests/LibWeb/Text/expected/wpt-import/permissions/event-model.https.txtnew file mode 100644index 00000000000..87ffc35cf97--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/permissions/event-model.https.txt@@ -0,0 +1,9 @@+Harness status: OK++Found 4 tests++4 Pass+Pass Multiple listeners on a single PermissionStatus should all fire on change+Pass Multiple transitions generate multiple "change" events+Pass Multiple PermissionStatus objects observe the same transition+Pass PermissionStatus out of scope should still fire "change" event\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/permissions/non-fully-active.https.txt b/Tests/LibWeb/Text/expected/wpt-import/permissions/non-fully-active.https.txtnew file mode 100644index 00000000000..d65053dff5d--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/permissions/non-fully-active.https.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass Trying to query() a non-fully active document rejects with a InvalidStateError+Pass Permission change events shouldn't fire on non-fully active document\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/permissions/permissions-garbage-collect.https.txt b/Tests/LibWeb/Text/expected/wpt-import/permissions/permissions-garbage-collect.https.txtnew file mode 100644index 00000000000..817cf00eb9b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/permissions/permissions-garbage-collect.https.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Events fire even if the status object is garbage collected\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/permissions/revocation.https.txt b/Tests/LibWeb/Text/expected/wpt-import/permissions/revocation.https.txtnew file mode 100644index 00000000000..5c5d18ac387--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/permissions/revocation.https.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass Transition "granted" -> "prompt" fires a "change" event+Pass Transition "granted" -> "denied" fires a "change" event\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/permissions/worker.https.txt b/Tests/LibWeb/Text/expected/wpt-import/permissions/worker.https.txtnew file mode 100644index 00000000000..3253c93e2e1--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/permissions/worker.https.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail Worker can query the 'geolocation' permission and detect a transition to 'granted'\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/PositionOptions.https.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/PositionOptions.https.htmlnew file mode 100644index 00000000000..cb3a56e4540--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/PositionOptions.https.html@@ -0,0 +1,83 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>Geolocation Test: PositionOptions tests</title>+<link+ rel="help"+ href="http://www.w3.org/TR/geolocation-API/#position_options_interface"+/>+<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(async ()=>{+ await test_driver.set_permission({ name: "geolocation" }, "granted");+ });++ const invalidValues = ["boom", 321, -Infinity, { foo: 5 }];++ promise_test(async (t) => {+ const error = await new Promise((resolve, reject) => {+ navigator.geolocation.getCurrentPosition(reject, resolve, {+ timeout: 0,+ maxAge: 0,+ });+ });+ assert_equals(error.code, GeolocationPositionError.TIMEOUT);+ }, "Set timeout and maximumAge to 0, check that timeout error raised (getCurrentPosition)");++ promise_test(async (t) => {+ let watchId;+ const error = await new Promise((resolve, reject) => {+ watchId = navigator.geolocation.watchPosition(reject, resolve, {+ timeout: 0,+ maxAge: 0,+ });+ });+ assert_equals(error.code, GeolocationPositionError.TIMEOUT);+ navigator.geolocation.clearWatch(watchId);+ }, "Set timeout and maximumAge to 0, check that timeout error raised (watchPosition)");++ promise_test(async (t) => {+ let watchId;+ const error = await new Promise((resolve, reject) => {+ watchId = navigator.geolocation.getCurrentPosition(reject, resolve, {+ timeout: -100,+ maxAge: -100,+ });+ });+ assert_equals(error.code, GeolocationPositionError.TIMEOUT);+ navigator.geolocation.clearWatch(watchId);+ }, "Check that a negative timeout and maxAge values are clamped to 0 (getCurrentPosition)");++ promise_test(async (t) => {+ let watchId;+ const error = await new Promise((resolve, reject) => {+ watchId = navigator.geolocation.watchPosition(reject, resolve, {+ timeout: -100,+ maxAge: -100,+ });+ });+ assert_equals(error.code, GeolocationPositionError.TIMEOUT);+ navigator.geolocation.clearWatch(watchId);+ }, "Check that a negative timeout and maxAge values are clamped to 0 (watchPosition)");++ promise_test(async (t) => {+ for (const enableHighAccuracy of invalidValues) {+ navigator.geolocation.getCurrentPosition(() => {}, null, {+ enableHighAccuracy,+ });+ }+ }, "Call getCurrentPosition with wrong type for enableHighAccuracy. No exception expected.");++ promise_test(async (t) => {+ for (const enableHighAccuracy of invalidValues) {+ const id = navigator.geolocation.watchPosition(() => {}, null, {+ enableHighAccuracy,+ });+ navigator.geolocation.clearWatch(id);+ }+ }, "Call watchPosition with wrong type for enableHighAccuracy. No exception expected.");++</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition-error.https.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition-error.https.htmlnew file mode 100644index 00000000000..952fc1fd041--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition-error.https.html@@ -0,0 +1,48 @@+<!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>+ 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});+ });++ await test_driver.bidi.emulation.set_geolocation_override({+ error: {type: "positionUnavailable"}+ });++ const error = await new Promise(+ (resolve, reject) =>+ window.navigator.geolocation.getCurrentPosition(+ () => reject("Unexpected success callback"),+ error => resolve({+ code: error.code,+ message: error.message,+ PERMISSION_DENIED: error.PERMISSION_DENIED,+ POSITION_UNAVAILABLE: error.POSITION_UNAVAILABLE,+ TIMEOUT: error.TIMEOUT+ }),+ {timeout: 1000}+ ));++ assert_equals(error.code, 2);+ // The message value is not specified.+ assert_not_equals(error.message, undefined);+ assert_equals(error.PERMISSION_DENIED, 1);+ assert_equals(error.POSITION_UNAVAILABLE, 2);+ assert_equals(error.TIMEOUT, 3);+ }, "Tests Geolocation error callback");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition-success.https.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition-success.https.htmlnew file mode 100644index 00000000000..0dd4dc2d598--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition-success.https.html@@ -0,0 +1,88 @@+<!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;++ 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});+ });++ await test_driver.bidi.emulation.set_geolocation_override({+ coordinates: {latitude, longitude, accuracy}+ });++ const position = await new Promise((resolve, reject) => {+ let calledAsync = false;+ window.navigator.geolocation.getCurrentPosition(+ t.step_func((position) => {+ assert_true(+ calledAsync,+ "Expected callback to be called asynchronously"+ );+ resolve(position.coords.toJSON());+ }),+ reject,+ {timeout: 200}+ );+ calledAsync = true;+ });++ assert_equals(position.latitude, latitude);+ assert_equals(position.longitude, longitude);+ assert_equals(position.accuracy, accuracy);+ }, "getCurrentPosition called with success and error callbacks");++ promise_test(async (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}+ });++ const position = await new Promise((resolve, reject) => {+ let calledAsync = false;+ try {+ navigator.geolocation.getCurrentPosition(+ t.step_func((position) => {+ assert_true(+ calledAsync,+ "Expected callback to be called asynchronously"+ );+ resolve(position);+ }),+ null+ );+ calledAsync = true;+ } catch (err) {+ reject(err);+ }+ });+ assert_true(+ position instanceof GeolocationPosition,+ "Expected GeolocationPosition"+ );+ assert_equals(position.coords.latitude, latitude);+ assert_equals(position.coords.longitude, longitude);+ assert_equals(position.coords.accuracy, accuracy);+ }, "Error callback is nullable for getCurrentPosition().");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition_permission_deny.https.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition_permission_deny.https.htmlnew file mode 100644index 00000000000..87429d051ad--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/getCurrentPosition_permission_deny.https.html@@ -0,0 +1,29 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>Geolocation Test: getCurrentPosition location access denied</title>+<link rel="help" href="http://www.w3.org/TR/geolocation-API/#privacy_for_uas" />+<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_test(async (t) => {+ t.add_cleanup(() => {+ return test_driver.set_permission({ name: "geolocation" }, "prompt");+ });+ await test_driver.set_permission({ name: "geolocation" }, "denied");+ const error = await new Promise((resolve, reject) => {+ let calledAsync = false;+ navigator.geolocation.getCurrentPosition(reject, t.step_func((error) => {+ assert_true(calledAsync, "Expected callback to be called asynchronously");+ resolve(error);+ }));+ calledAsync = true;+ });+ assert_true(+ error instanceof GeolocationPositionError,+ "should be a GeolocationPositionError"+ );+ assert_equals(error.code, error.PERMISSION_DENIED);+ }, "User denies access, check that error callback is called with correct code");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/permission.https.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/permission.https.htmlnew file mode 100644index 00000000000..7e7ef5302dc--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/permission.https.html@@ -0,0 +1,22 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>Test geolocation is a powerful feature via Permissions API</title>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>++<script>+ promise_test(async (test) => {+ const status = await navigator.permissions.query({ name: "geolocation" });+ assert_true(status instanceof PermissionStatus);+ assert_equals(+ status.name,+ "geolocation",+ `permission's name must be "geolocation"`+ );+ const states = ["prompt", "granted", "denied"];+ assert_true(+ states.includes(status.state),+ `permission's state must be one of ${states.join(", ")}`+ );+ }, `Query "geolocation" powerful feature`);+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/geolocation/watchPosition_permission_deny.https.html b/Tests/LibWeb/Text/input/wpt-import/geolocation/watchPosition_permission_deny.https.htmlnew file mode 100644index 00000000000..791c4838475--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/geolocation/watchPosition_permission_deny.https.html@@ -0,0 +1,45 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>Geolocation Test: watchPosition location access denied</title>+<link rel="help" href="http://www.w3.org/TR/geolocation-API/#privacy_for_uas" />+<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>+ const resetPermission = () => {+ return test_driver.set_permission({ name: "geolocation" }, "prompt");+ };++ promise_test(async (t) => {+ t.add_cleanup(resetPermission);+ await test_driver.set_permission({ name: "geolocation" }, "denied");+ let errorCBCalled = false;+ let id;+ const errorPromise = new Promise((resolve, reject) => {+ id = navigator.geolocation.watchPosition(reject, () => {+ errorCBCalled = true;+ resolve();+ });+ });+ assert_false(+ errorCBCalled,+ "error callback must not be called synchronously"+ );+ await errorPromise;+ navigator.geolocation.clearWatch(id);+ }, "Check that watchPosition returns synchronously before any callbacks are invoked.");++ promise_test(async (t) => {+ t.add_cleanup(resetPermission);+ await test_driver.set_permission({ name: "geolocation" }, "denied");+ const promise = new Promise((resolve, reject) => {+ navigator.geolocation.watchPosition(reject, resolve);+ });+ const result = await promise;+ assert_true(+ result instanceof GeolocationPositionError,+ "expected GeolocationPositionError"+ );+ }, "User denies access, check that error callback is called.");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/permissions/event-model.https.html b/Tests/LibWeb/Text/input/wpt-import/permissions/event-model.https.htmlnew file mode 100644index 00000000000..219f8bf70db--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/permissions/event-model.https.html@@ -0,0 +1,115 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>Permissions API - Event Model Tests</title>+<link rel="help" href="https://www.w3.org/TR/permissions/" />+<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>++<body>+ <script>+ promise_test(async (t) => {+ await test_driver.set_permission({ name: "geolocation" }, "prompt");+ const status = await navigator.permissions.query({+ name: "geolocation",+ });+ assert_equals(status.state, "prompt", 'Initial state is "prompt"');++ let count = 0;+ const promise1 = new Promise((resolve) => {+ status.addEventListener("change", () => resolve(count++), {+ once: true,+ });+ });++ const promise2 = new Promise((resolve) => {+ status.onchange = () => resolve(count++);+ });++ await test_driver.set_permission(+ { name: "geolocation" },+ "granted"+ );++ const results = await Promise.all([promise1, promise2]);++ assert_equals(+ status.state,+ "granted",+ 'State should now be "granted"'+ );+ assert_array_equals(results, [0, 1], "Both listeners fired once");++ status.onchange = null;+ }, "Multiple listeners on a single PermissionStatus should all fire on change");++ promise_test(async (t) => {+ await test_driver.set_permission({ name: "geolocation" }, "prompt");+ const status = await navigator.permissions.query({+ name: "geolocation",+ });+ assert_equals(status.state, "prompt", 'Initial state is "prompt"');++ const grantedPromise = new Promise((resolve) => {+ status.addEventListener("change", resolve, { once: true });+ });+ await test_driver.set_permission(+ { name: "geolocation" },+ "granted"+ );+ await grantedPromise;+ assert_equals(status.state, "granted", 'Now in "granted" state');++ const deniedPromise = new Promise((resolve) => {+ status.addEventListener("change", resolve, { once: true });+ });+ await test_driver.set_permission({ name: "geolocation" }, "denied");+ await deniedPromise;+ assert_equals(status.state, "denied", 'Now in "denied" state');+ }, 'Multiple transitions generate multiple "change" events');++ promise_test(async (t) => {+ await test_driver.set_permission({ name: "geolocation" }, "prompt");++ const statusA = await navigator.permissions.query({+ name: "geolocation",+ });+ const statusB = await navigator.permissions.query({+ name: "geolocation",+ });++ const watchA = new Promise((resolve) => {+ statusA.addEventListener("change", resolve, { once: true });+ });+ const watchB = new Promise((resolve) => {+ statusB.addEventListener("change", resolve, { once: true });+ });++ await test_driver.set_permission(+ { name: "geolocation" },+ "granted"+ );+ const results = await Promise.all([watchA, watchB]);+ }, "Multiple PermissionStatus objects observe the same transition");++ promise_test(async (t) => {+ await test_driver.set_permission({ name: "geolocation" }, "prompt");++ const ephemeralPromise = new Promise((resolve) => {+ (async () => {+ const status = await navigator.permissions.query({+ name: "geolocation",+ });+ status.addEventListener("change", resolve, { once: true });+ })();+ });++ await test_driver.set_permission(+ { name: "geolocation" },+ "granted"+ );+ await ephemeralPromise;+ }, 'PermissionStatus out of scope should still fire "change" event');+ </script>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/permissions/non-fully-active.https.html b/Tests/LibWeb/Text/input/wpt-import/permissions/non-fully-active.https.htmlnew file mode 100644index 00000000000..8b6c1928ce7--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/permissions/non-fully-active.https.html@@ -0,0 +1,108 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>Geolocation Test: non-fully active document</title>+<link rel="help" href="https://github.com/w3c/permissions/pull/365" />+<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>+<body></body>+<script>+ // Creates the iframe, wait for it to load...+ async function attachIframe() {+ const iframe = document.createElement("iframe");+ await new Promise((resolve) => {+ iframe.src = "resources/empty.html";+ iframe.addEventListener("load", resolve, { once: true });+ document.body.appendChild(iframe);+ });+ return iframe;+ }++ promise_test(async (t) => {+ const iframe = await attachIframe();++ // Steal the needed references+ const { permissions } = iframe.contentWindow.navigator;+ const TypeErrorCtor = iframe.contentWindow.TypeError;+ const DOMExceptionCtor = iframe.contentWindow.DOMException;++ // Let's check that ordering is correct.+ await promise_rejects_js(+ t,+ TypeErrorCtor,+ permissions.query({ name: "xxxxx-not-supported" }),+ "query() should reject if the feature is not supported"+ );++ // no longer fully active, let's try that again...+ iframe.remove();++ // Now, let's try with Geolocation as it's supported by all browsers.+ await promise_rejects_dom(+ t,+ "InvalidStateError",+ DOMExceptionCtor,+ permissions.query({ name: "whatever" }),+ "must reject in the right global when the document is not fully active"+ );++ // Re-attach, and go back to fully active.+ document.body.appendChild(iframe);+ await new Promise((resolve) =>+ iframe.addEventListener("load", resolve, { once: true })+ );++ // And we are back to fully active, so this should not reject.+ const status = await iframe.contentWindow.navigator.permissions.query({+ name: "geolocation",+ });+ assert_equals(status.name, "geolocation");+ iframe.remove();+ }, "Trying to query() a non-fully active document rejects with a InvalidStateError");++ promise_test(async (t) => {+ // Create the iframe, wait for it to load...+ const iframe = await attachIframe();++ // Get the status+ const initialStatus =+ await iframe.contentWindow.navigator.permissions.query({+ name: "geolocation",+ });++ assert_true("onchange" in initialStatus, "onchange is supported");++ // Let's check events are firing...+ await new Promise(async (resolve) => {+ const newState = initialStatus.state === "prompt" ? "denied" : "granted";+ initialStatus.addEventListener("change", resolve, { once: true });+ await test_driver.set_permission({ name: "geolocation" }, newState);+ });++ // No longer fully active...+ iframe.remove();++ await new Promise(async (resolve, reject) => {+ // Gets dropped on the floor.+ initialStatus.addEventListener("change", reject, { once: true });+ await test_driver.set_permission({ name: "geolocation" }, "prompt");+ // Try to force it synthetically. This would trigger the event synchronously.+ initialStatus.dispatchEvent(new Event("change"));+ resolve();+ });++ // Re-attach, and go back to fully active.+ document.body.appendChild(iframe);+ await new Promise((resolve) =>+ iframe.addEventListener("load", resolve, { once: true })+ );++ // Finally, let's recheck that permission state.+ const finalStatus = await iframe.contentWindow.navigator.permissions.query({+ name: "geolocation",+ });+ assert_equals(finalStatus.state, "prompt", "expected prompt state");+ iframe.remove();+ }, "Permission change events shouldn't fire on non-fully active document");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/permissions/permissions-garbage-collect.https.html b/Tests/LibWeb/Text/input/wpt-import/permissions/permissions-garbage-collect.https.htmlnew file mode 100644index 00000000000..42180928f8d--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/permissions/permissions-garbage-collect.https.html@@ -0,0 +1,52 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>Test Permission garbage collection persistance.</title>+<link rel="help" href="https://github.com/w3c/permissions/pull/256" />+<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>+<body>+ <script>+ async function createABunchOfGarbage() {+ const promises = [];+ for (let i = 0; i < 25; i++) {+ const promise = new Promise((r) => {+ const iframe = document.createElement("iframe");+ iframe.onload = () => r(iframe);+ iframe.src = "about:blank";+ document.body.appendChild(iframe);+ });+ promises.push(promise);+ }+ const iframes = await Promise.all(promises);+ iframes.forEach((iframe) => iframe.remove());+ }++ promise_test(async (t) => {+ t.add_cleanup(() => {+ return test_driver.set_permission({ name: "geolocation" }, "prompt");+ });++ const eventPromise = new Promise(+ async (r) => {+ // we create the status here, but it goes out of scope+ // at the end of the function. Thus, we assume it will be+ // garbage collected.+ const status = await navigator.permissions.query({+ name: "geolocation",+ });+ status.addEventListener("change", r);+ },+ { once: true }+ );++ // Maybe got garbage collected.+ await createABunchOfGarbage();++ // Causes event to fire.+ await test_driver.set_permission({ name: "geolocation" }, "granted");+ await eventPromise;+ }, "Events fire even if the status object is garbage collected");+ </script>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/permissions/resources/empty.html b/Tests/LibWeb/Text/input/wpt-import/permissions/resources/empty.htmlnew file mode 100644index 00000000000..b0653f8c0cd--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/permissions/resources/empty.html@@ -0,0 +1,3 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Just a support file</title>diff --git a/Tests/LibWeb/Text/input/wpt-import/permissions/revocation.https.html b/Tests/LibWeb/Text/input/wpt-import/permissions/revocation.https.htmlnew file mode 100644index 00000000000..badbefbc49a--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/permissions/revocation.https.html@@ -0,0 +1,59 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>Permissions API - Revocation Tests</title>+<link rel="help" href="https://www.w3.org/TR/permissions/" />+<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>++<body>+ <script>+ promise_test(async (t) => {+ await test_driver.set_permission(+ { name: "geolocation" },+ "granted"+ );+ const status = await navigator.permissions.query({+ name: "geolocation",+ });+ assert_equals(+ status.state,+ "granted",+ 'Initial state is "granted"'+ );++ const p = new Promise((resolve) => {+ status.addEventListener("change", resolve, { once: true });+ });++ await test_driver.set_permission({ name: "geolocation" }, "prompt");+ await p;++ assert_equals(status.state, "prompt", 'Now in "prompt" state');+ }, 'Transition "granted" -> "prompt" fires a "change" event');++ promise_test(async (t) => {+ await test_driver.set_permission(+ { name: "geolocation" },+ "granted"+ );+ const status = await navigator.permissions.query({+ name: "geolocation",+ });+ assert_equals(+ status.state,+ "granted",+ 'Initial state is "granted"'+ );++ const p = new Promise((resolve) => {+ status.addEventListener("change", resolve, { once: true });+ });++ await test_driver.set_permission({ name: "geolocation" }, "denied");+ await p;+ assert_equals(status.state, "denied", 'Now in "denied" state');+ }, 'Transition "granted" -> "denied" fires a "change" event');+ </script>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/permissions/worker.https.html b/Tests/LibWeb/Text/input/wpt-import/permissions/worker.https.htmlnew file mode 100644index 00000000000..b5605c64209--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/permissions/worker.https.html@@ -0,0 +1,59 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>Permissions API in Worker</title>+<link rel="help" href="https://www.w3.org/TR/permissions/" />+<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>+ const workerScript = `+ async function setup() {+ const status = await self.navigator.permissions.query({+ name: "geolocation",+ });+ status.addEventListener("change", () => {+ postMessage({ event: "change", state: status.state });+ });+ self.postMessage({ event: "ready", state: status.state });+ }++ setup();+ `;++ function messageFrom(worker, message) {+ const abortController = new AbortController();+ return new Promise((resolve) => {+ worker.addEventListener(+ "message",+ (event) => {+ if (event.data.event == message) {+ abortController.abort();+ resolve(event.data);+ }+ },+ { signal: abortController.signal }+ );+ });+ }++ promise_test(async (t) => {+ await test_driver.set_permission({ name: "geolocation" }, "prompt");+ const blobUrl = URL.createObjectURL(+ new Blob([workerScript], { type: "text/javascript" })+ );+ const worker = new Worker(blobUrl);+ const { state:initialState } = await messageFrom(worker, "ready");+ assert_equals(initialState, "prompt", "Worker sees the initial permission state as 'prompt'");++ const setPermissionPromise = test_driver.set_permission({ name: "geolocation" }, "granted");+ const changePromise = messageFrom(worker, "change");+ const [{state:changedState}] = await Promise.all([messagePromise, setPermissionPromise]);+ assert_equals(+ changedState,+ "granted",+ "Worker detects the permission state change to 'granted'"+ );+ }, "Worker can query the 'geolocation' permission and detect a transition to 'granted'");+</script>