tor-browser

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

basic-shared-worker.https.html (2614B)


      1 <!doctype html>
      2 <html>
      3  <head>
      4    <meta charset=utf-8>
      5    <title>Test SharedWorkerGlobalScope.isSecureContext for HTTP creator</title>
      6    <meta name="help" href="https://w3c.github.io/webappsec-secure-contexts/#monkey-patching-global-object">
      7    <script src=/resources/testharness.js></script>
      8    <script src=/resources/testharnessreport.js></script>
      9    <script src="server-locations.sub.js"></script>
     10  </head>
     11  <body>
     12    <script>
     13      var t1 = async_test("Shared worker");
     14      var t2 = async_test("Nested worker in shared worker");
     15      var t3 = async_test("Shared worker from https subframe");
     16      var t4 = async_test("Nested worker from shared worker from https subframe");
     17      var t5 = async_test("Shared worker from data URL");
     18 
     19      t1.step(function() {
     20        var w = new SharedWorker("support/shared-worker-script.js");
     21        w.port.onmessage = t1.step_func_done(function(e) {
     22          assert_true(e.data);
     23        });
     24        w.port.start();
     25      });
     26 
     27      t2.step(function() {
     28        var w = new SharedWorker("support/parent-shared-worker-script.js");
     29        w.port.onmessage = t2.step_func_done(function(e) {
     30          assert_true(e.data);
     31        });
     32        w.port.start();
     33      });
     34 
     35      onmessage = function(e) {
     36        var data = e.data;
     37        if (data.type == "shared") {
     38          t3.step(function() {
     39            assert_false(data.exception);
     40            assert_false(data.error);
     41            assert_true(data.isSecureContext);
     42          });
     43          t3.done();
     44        } else if (data.type == "nested") {
     45          t4.step(function() {
     46            assert_false(data.exception);
     47            assert_false(data.error);
     48            assert_true(data.isSecureContext);
     49          });
     50          t4.done();
     51        } else {
     52          t3.step(function() {
     53            assert_unreached("Unknown message");
     54          });
     55          t3.done();
     56          t4.step(function() {
     57            assert_unreached("Unknown message");
     58          });
     59          t4.done();
     60        }
     61      }
     62 
     63      var ifr = document.createElement("iframe");
     64      ifr.src = https_dir3 + "support/https-subframe-shared.html";
     65      document.body.appendChild(ifr);
     66 
     67      t5.step(function() {
     68        var w = new SharedWorker(
     69          `data:text/javascript,addEventListener("connect", function (e) {
     70             var port = e.ports[0];
     71             port.start();
     72             port.postMessage(isSecureContext);
     73          });`
     74        );
     75        w.port.onmessage = t5.step_func_done(function(e) {
     76          assert_true(e.data);
     77        });
     78        w.port.start();
     79      });
     80    </script>
     81  </body>
     82 </html>