tor-browser

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

test_post_message_source.html (1866B)


      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 1142015 - Test service worker post message source </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 class="testbody" type="text/javascript">
     17  var magic_value = "MAGIC_VALUE_RANDOM";
     18  var registration;
     19  function start() {
     20    return navigator.serviceWorker.register("source_message_posting_worker.js",
     21                                            { scope: "./nonexistent_scope/" })
     22      .then((swr) => registration = swr);
     23  }
     24 
     25  function unregister() {
     26    return registration.unregister().then(function(result) {
     27      ok(result, "Unregister should return true.");
     28    }, function(e) {
     29      dump("Unregistering the SW failed with " + e + "\n");
     30    });
     31  }
     32 
     33 
     34  function testPostMessage(swr) {
     35    var p = new Promise(function(res, rej) {
     36      navigator.serviceWorker.onmessage = function(e) {
     37        ok(e.data === magic_value, "Worker posted the correct value.");
     38        res();
     39      }
     40    });
     41 
     42    ok(swr.installing, "Installing worker exists.");
     43    swr.installing.postMessage(magic_value);
     44    return p;
     45  }
     46 
     47 
     48  function runTest() {
     49    start()
     50      .then(testPostMessage)
     51      .then(unregister)
     52      .catch(function(e) {
     53        ok(false, "Some test failed with error " + e);
     54      }).then(SimpleTest.finish);
     55  }
     56 
     57  SimpleTest.waitForExplicitFinish();
     58  SpecialPowers.pushPrefEnv({"set": [
     59    ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     60    ["dom.serviceWorkers.enabled", true],
     61    ["dom.serviceWorkers.testing.enabled", true]
     62  ]}, runTest);
     63 </script>
     64 </pre>
     65 </body>
     66 </html>