diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/base/test/chrome/test_permission_hasValidTransientUserActivation.xhtml | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/test/chrome/test_permission_hasValidTransientUserActivation.xhtml')
-rw-r--r-- | dom/base/test/chrome/test_permission_hasValidTransientUserActivation.xhtml | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/dom/base/test/chrome/test_permission_hasValidTransientUserActivation.xhtml b/dom/base/test/chrome/test_permission_hasValidTransientUserActivation.xhtml new file mode 100644 index 0000000000..06675a90ad --- /dev/null +++ b/dom/base/test/chrome/test_permission_hasValidTransientUserActivation.xhtml @@ -0,0 +1,91 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> +<!-- + Tests that the hasValidTransientUserGestureActivation attribute on permission requests is set correctly. +--> +<window title="hasValidTransientUserGestureActivation test" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> + + <body xmlns="http://www.w3.org/1999/xhtml"> + <iframe id="frame" src="https://example.com/chrome/dom/base/test/chrome/dummy.html" /> + </body> + + <script type="application/javascript"> + <![CDATA[ + const {Integration} = ChromeUtils.import("resource://gre/modules/Integration.jsm"); + + SimpleTest.waitForExplicitFinish(); + + let frame = document.getElementById("frame"); + + function checkPermissionRequest(permission, hasValidTransientUserGestureActivation) { + return new Promise(function(resolve) { + let TestIntegration = (base) => ({ + __proto__: base, + createPermissionPrompt(type, request) { + is(type, permission, `Has correct permission type ${permission}.`); + is(request.hasValidTransientUserGestureActivation, hasValidTransientUserGestureActivation, + "The hasValidTransientUserGestureActivation attribute is set correctly."); + Integration.contentPermission.unregister(TestIntegration); + resolve(); + return { prompt() {} }; + }, + }); + Integration.contentPermission.register(TestIntegration); + }); + } + + async function runTest() { + await SpecialPowers.setBoolPref("dom.webnotifications.allowcrossoriginiframe", true); + + // Test programmatic request for persistent storage. + let request = checkPermissionRequest("persistent-storage", false); + navigator.storage.persist(); + await request; + + // Test user-initiated request for persistent storage. + request = checkPermissionRequest("persistent-storage", true); + document.notifyUserGestureActivation(); + navigator.storage.persist(); + await request; + content.document.clearUserGestureActivation(); + + // Test programmatic request for geolocation. + request = checkPermissionRequest("geolocation", false); + navigator.geolocation.getCurrentPosition(() => {}); + await request; + + // Test user-initiated request for geolocation. + request = checkPermissionRequest("geolocation", true); + document.notifyUserGestureActivation(); + navigator.geolocation.getCurrentPosition(() => {}); + await request; + document.clearUserGestureActivation(); + + // Notifications need to be tested in an HTTPS frame, because + // chrome:// URLs are whitelisted. + let frameWin = frame.contentWindow; + + // Test programmatic request for notifications. + request = checkPermissionRequest("desktop-notification", false); + frameWin.Notification.requestPermission(); + await request; + + // Test user-initiated request for notifications. + request = checkPermissionRequest("desktop-notification", true); + frameWin.document.notifyUserGestureActivation(); + frameWin.Notification.requestPermission(); + await request; + frameWin.document.clearUserGestureActivation(); + + await SpecialPowers.clearUserPref("dom.webnotifications.allowcrossoriginiframe"); + } + + frame.addEventListener("load", function() { + runTest().then(() => SimpleTest.finish()); + }); + ]]> + </script> +</window> |