summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/fetch/sw_reroute.js
blob: 11ad7b76e4dc003a890e9ccd64dc72c84ef5936a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var gRegistration;

function testScript(script) {
  function setupSW(registration) {
    gRegistration = registration;

    var iframe = document.createElement("iframe");
    iframe.src = "reroute.html?" + script.replace(".js", "");
    document.body.appendChild(iframe);
  }

  SpecialPowers.pushPrefEnv({
    "set": [["dom.serviceWorkers.enabled", true],
            ["dom.serviceWorkers.testing.enabled", true],
            ["dom.serviceWorkers.exemptFromPerDomainMax", true]]
  }, function() {
    navigator.serviceWorker.ready.then(setupSW);
    var scriptURL = location.href.includes("sw_empty_reroute.html")
                  ? "empty.js" : "reroute.js";
    navigator.serviceWorker.register(scriptURL, {scope: "/"});
  });
}

function finishTest() {
  gRegistration.unregister().then(SimpleTest.finish, function(e) {
    dump("unregistration failed: " + e + "\n");
    SimpleTest.finish();
  });
}

SimpleTest.waitForExplicitFinish();