tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_permission_hasValidTransientUserActivation.xhtml (3602B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
      3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
      4 <!--
      5  Tests that the hasValidTransientUserGestureActivation attribute on permission requests is set correctly.
      6 -->
      7 <window title="hasValidTransientUserGestureActivation test" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
      8  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      9  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
     10 
     11  <body xmlns="http://www.w3.org/1999/xhtml">
     12    <iframe id="frame" src="https://example.com/chrome/dom/base/test/chrome/dummy.html" />
     13  </body>
     14 
     15  <script type="application/javascript">
     16  <![CDATA[
     17  const {Integration} = ChromeUtils.importESModule(
     18    "resource://gre/modules/Integration.sys.mjs"
     19  );
     20 
     21  SimpleTest.waitForExplicitFinish();
     22 
     23  let frame = document.getElementById("frame");
     24 
     25  function checkPermissionRequest(permission, hasValidTransientUserGestureActivation) {
     26    return new Promise(function(resolve) {
     27      let TestIntegration = (base) => ({
     28        __proto__: base,
     29        createPermissionPrompt(type, request) {
     30          is(type, permission, `Has correct permission type ${permission}.`);
     31          is(request.hasValidTransientUserGestureActivation, hasValidTransientUserGestureActivation,
     32             "The hasValidTransientUserGestureActivation attribute is set correctly.");
     33          Integration.contentPermission.unregister(TestIntegration);
     34          resolve();
     35          return { prompt() {} };
     36        },
     37      });
     38      Integration.contentPermission.register(TestIntegration);
     39    });
     40  }
     41 
     42  async function runTest() {
     43    await SpecialPowers.setBoolPref("dom.webnotifications.allowcrossoriginiframe", true);
     44 
     45    // Test programmatic request for persistent storage.
     46    let request = checkPermissionRequest("persistent-storage", false);
     47    navigator.storage.persist();
     48    await request;
     49 
     50    // Test user-initiated request for persistent storage.
     51    request = checkPermissionRequest("persistent-storage", true);
     52    document.notifyUserGestureActivation();
     53    navigator.storage.persist();
     54    await request;
     55    content.document.clearUserGestureActivation();
     56 
     57    // Test programmatic request for geolocation.
     58    request = checkPermissionRequest("geolocation", false);
     59    navigator.geolocation.getCurrentPosition(() => {});
     60    await request;
     61 
     62    // Test user-initiated request for geolocation.
     63    request = checkPermissionRequest("geolocation", true);
     64    document.notifyUserGestureActivation();
     65    navigator.geolocation.getCurrentPosition(() => {});
     66    await request;
     67    document.clearUserGestureActivation();
     68 
     69    // Notifications need to be tested in an HTTPS frame, because
     70    // chrome:// URLs are whitelisted.
     71    let frameWin = frame.contentWindow;
     72 
     73    // Test programmatic request for notifications.
     74    request = checkPermissionRequest("desktop-notification", false);
     75    frameWin.Notification.requestPermission();
     76    await request;
     77 
     78    // Test user-initiated request for notifications.
     79    request = checkPermissionRequest("desktop-notification", true);
     80    frameWin.document.notifyUserGestureActivation();
     81    frameWin.Notification.requestPermission();
     82    await request;
     83    frameWin.document.clearUserGestureActivation();
     84 
     85    await SpecialPowers.clearUserPref("dom.webnotifications.allowcrossoriginiframe");
     86  }
     87 
     88  frame.addEventListener("load", function() {
     89    runTest().then(() => SimpleTest.finish());
     90  });
     91  ]]>
     92  </script>
     93 </window>