tor-browser

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

test-write-and-notify-wrapper.https.sub.html (2696B)


      1 <!--
      2  Any copyright is dedicated to the Public Domain.
      3  http://creativecommons.org/publicdomain/zero/1.0/
      4 -->
      5 <html>
      6  <head>
      7    <meta charset="utf-8" />
      8    <meta name="timeout" content="long" />
      9    <iframe id="write-frame"></iframe>
     10    <script src="/resources/testharness.js"></script>
     11    <script src="/resources/testharnessreport.js"></script>
     12  </head>
     13  <body>
     14    <script>
     15      const params = new URL(window.location.href).searchParams;
     16      const id = params.get("id");
     17      var testId;
     18      var testAPI;
     19      async_test(t => {
     20        const writeFrame = document.getElementById("write-frame");
     21 
     22        window.addEventListener("message", e => {
     23          console.log(
     24            "Write wrapper window received " + JSON.stringify(e.data)
     25          );
     26          try {
     27            if (!testId) {
     28              assert_true(!!e.data.message); // First message contain the database name.
     29              assert_equals(id, e.data.message);
     30              testId = e.data.message;
     31              assert_true(!!e.data.type); // First message also contain the tested API name.
     32              testAPI = e.data.type;
     33              writeFrame.src =
     34                "https://{{hosts[alt][www1]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-write-and-notify.https.html?id=" +
     35                id;
     36              return;
     37            }
     38 
     39            assert_true(!!e.data.id, e.data.message);
     40            if (e.data.id !== id) {
     41              console.log(
     42                "id " +
     43                  id +
     44                  " ignoring message for id " +
     45                  e.data.id +
     46                  " origin " +
     47                  e.origin
     48              );
     49              return;
     50            }
     51 
     52            if (e.data.message === "write loaded") {
     53              writeFrame.contentWindow.postMessage(
     54                { id, message: id, type: testAPI },
     55                "*"
     56              );
     57            } else {
     58              assert_equals(e.data.message, "write done");
     59              assert_true(!!e.data.expected); // We should get a nonzero number.
     60              console.log(
     61                "Write wrapper window sends up " + JSON.stringify(e.data)
     62              );
     63              parent.opener.postMessage(e.data, document.referrer);
     64              t.done();
     65            }
     66          } catch (err) {
     67            parent.opener.postMessage(
     68              { id, message: err.message },
     69              document.referrer
     70            );
     71            t.unreached_func(err.message);
     72            t.done();
     73          }
     74        });
     75 
     76        parent.opener.postMessage(
     77          { id, message: "write loaded" },
     78          document.referrer
     79        );
     80      }, "Write wrapper");
     81    </script>
     82  </body>
     83 </html>