tor-browser

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

test_serviceworkermanager.xhtml (2752B)


      1 <?xml version="1.0"?>
      2 <!--
      3  Any copyright is dedicated to the Public Domain.
      4  http://creativecommons.org/publicdomain/zero/1.0/
      5 -->
      6 <window title="Test for ServiceWorkerManager"
      7        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      8        onload="test();">
      9  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
     10  <script type="application/javascript" src="chrome_helpers.js"/>
     11  <script type="application/javascript">
     12  <![CDATA[
     13 
     14    let IFRAME_URL = EXAMPLE_URL + "serviceworkermanager_iframe.html";
     15 
     16    function test() {
     17      SimpleTest.waitForExplicitFinish();
     18 
     19      SpecialPowers.pushPrefEnv({'set': [
     20        ["dom.serviceWorkers.enabled", true],
     21        ["dom.serviceWorkers.testing.enabled", true],
     22      ]}, function () {
     23        (async function() {
     24          let registrations = swm.getAllRegistrations();
     25          is(registrations.length, 0);
     26 
     27          let iframe = $("iframe");
     28          let promise = waitForIframeLoad(iframe);
     29          iframe.src = IFRAME_URL;
     30          await promise;
     31 
     32          info("Check that the service worker manager notifies its listeners " +
     33               "when a service worker is registered.");
     34          promise = waitForRegister(EXAMPLE_URL);
     35          iframe.contentWindow.postMessage("register", "*");
     36          let registration = await promise;
     37 
     38          registrations = swm.getAllRegistrations();
     39          is(registrations.length, 1);
     40          is(registrations.queryElementAt(0, Ci.nsIServiceWorkerRegistrationInfo),
     41             registration);
     42 
     43          info("Check that the service worker manager does not notify its " +
     44               "listeners when a service worker is registered with the same " +
     45               "scope as an existing registration.");
     46          let listener = {
     47            onRegister () {
     48              ok(false, "Listener should not have been notified.");
     49            }
     50          };
     51          swm.addListener(listener);
     52          iframe.contentWindow.postMessage("register", "*");
     53 
     54          info("Check that the service worker manager notifies its listeners " +
     55               "when a service worker is unregistered.");
     56          promise = waitForUnregister(EXAMPLE_URL);
     57          iframe.contentWindow.postMessage("unregister", "*");
     58          registration = await promise;
     59          swm.removeListener(listener);
     60 
     61          registrations = swm.getAllRegistrations();
     62          is(registrations.length, 0);
     63 
     64          SimpleTest.finish();
     65        })();
     66      });
     67    }
     68 
     69  ]]>
     70  </script>
     71 
     72  <body xmlns="http://www.w3.org/1999/xhtml">
     73    <p id="display"></p>
     74    <div id="content" style="display:none;"></div>
     75    <pre id="test"></pre>
     76    <iframe id="iframe"></iframe>
     77  </body>
     78  <label id="test-result"/>
     79 </window>