tor-browser

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

test_shadowRealm_worker.html (1473B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test for ShadowRealms</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8  <iframe id="ifr"></iframe>
      9 </head>
     10 
     11 <body>
     12  <p id="display"></p>
     13  <script type="application/javascript">
     14    SimpleTest.waitForExplicitFinish();
     15 
     16    var promise = (async ()=> {
     17      var module = await import("./shadow_realm_module.js");
     18      is(module.x, 1, "import works outside worker");
     19 
     20      var sr = new ShadowRealm();
     21      await sr.importValue("./shadow_realm_module.js", 'x').then((x) => is(x,1, "imported x and got 1"));
     22    })();
     23 
     24    promise.then(() => {
     25      var worker = new Worker("shadow_realm_worker.js");
     26 
     27      var expected = 0;
     28      var recieved = 0;
     29 
     30      function test(str) {
     31        worker.postMessage(str);
     32        expected++;
     33      }
     34 
     35      worker.onmessage = function(e) {
     36            console.log("Received Message: "+e.data);
     37            recieved++;
     38 
     39            if (e.data == "finish") {
     40              is(expected, recieved, "Got the appropriate Number of messages");
     41              SimpleTest.finish();
     42              return;
     43            }
     44 
     45            if (e.data.startsWith("PASS")) {
     46              ok(true, e.data);
     47              return;
     48            }
     49 
     50            ok(false, e.data);
     51          };
     52 
     53 
     54      test("evaluate");
     55      test("import");
     56 
     57 
     58      test("finish");
     59  });
     60  </script>
     61 </body>
     62 
     63 </html>