tor-browser

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

test_fetch_event_with_thirdpartypref.html (2586B)


      1 <!--
      2  Any copyright is dedicated to the Public Domain.
      3  http://creativecommons.org/publicdomain/zero/1.0/
      4 -->
      5 <!DOCTYPE HTML>
      6 <html>
      7 <head>
      8  <title>Bug 94048 - test install event.</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <body>
     13 <p id="display"></p>
     14 <div id="content" style="display: none"></div>
     15 <pre id="test"></pre>
     16 <script src="utils.js"></script>
     17 <script class="testbody" type="text/javascript">
     18 
     19  // NOTE: This is just test_fetch_event.html but with an alternate cookie
     20  //       mode preference set to make sure that setting the preference does
     21  //       not break interception as observed in bug 1336364.
     22  // TODO: Refactor this test so it doesn't duplicate so much code logic.
     23 
     24  SimpleTest.requestCompleteLog();
     25 
     26  var registration;
     27  function simpleRegister() {
     28    return navigator.serviceWorker.register("fetch_event_worker.js", { scope: "./fetch" })
     29      .then(swr => {
     30        registration = swr;
     31        return waitForState(swr.installing, 'activated');
     32      });
     33  }
     34 
     35  function unregister() {
     36    return registration.unregister().then(function(success) {
     37      ok(success, "Service worker should be unregistered successfully");
     38    }, function(e) {
     39      dump("SW unregistration error: " + e + "\n");
     40    });
     41  }
     42 
     43  function testController() {
     44    var p = new Promise(function(resolve, reject) {
     45      var reloaded = false;
     46      window.onmessage = function(e) {
     47        if (e.data.status == "ok") {
     48          ok(e.data.result, e.data.message);
     49        } else if (e.data.status == "done") {
     50          if (reloaded) {
     51            window.onmessage = null;
     52            w.close();
     53            resolve();
     54          } else {
     55            w.location.reload();
     56            reloaded = true;
     57          }
     58        }
     59      }
     60    });
     61 
     62    var w = window.open("fetch/index.html");
     63    return p;
     64  }
     65 
     66  function runTest() {
     67    simpleRegister()
     68      .then(testController)
     69      .then(unregister)
     70      .then(function() {
     71        SimpleTest.finish();
     72      }).catch(function(e) {
     73        ok(false, "Some test failed with error " + e);
     74        SimpleTest.finish();
     75      });
     76  }
     77 
     78  const COOKIE_BEHAVIOR_REJECTFOREIGN = 1;
     79 
     80  SimpleTest.waitForExplicitFinish();
     81  SpecialPowers.pushPrefEnv({"set": [
     82    ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     83    ["dom.serviceWorkers.enabled", true],
     84    ["dom.serviceWorkers.testing.enabled", true],
     85    ["network.cookie.cookieBehavior", COOKIE_BEHAVIOR_REJECTFOREIGN],
     86  ]}, runTest);
     87 </script>
     88 </pre>
     89 </body>
     90 </html>