diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/permissions/non-fully-active.https.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/permissions/non-fully-active.https.html')
-rw-r--r-- | testing/web-platform/tests/permissions/non-fully-active.https.html | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/testing/web-platform/tests/permissions/non-fully-active.https.html b/testing/web-platform/tests/permissions/non-fully-active.https.html new file mode 100644 index 0000000000..1c11afa3d9 --- /dev/null +++ b/testing/web-platform/tests/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> |