tor-browser

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

test_data.html (3001B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 Bug 1185544: Add data delivery to the WebSocket backend.
      5 
      6 Any copyright is dedicated to the Public Domain.
      7 http://creativecommons.org/licenses/publicdomain/
      8 
      9 -->
     10 <head>
     11  <title>Test for Bug 1185544</title>
     12  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     13  <script type="text/javascript" src="/tests/dom/push/test/test_utils.js"></script>
     14  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     15  <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
     16 </head>
     17 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1185544">Mozilla Bug 1185544</a>
     18 <p id="display"></p>
     19 <div id="content" style="display: none">
     20 
     21 </div>
     22 <pre id="test">
     23 </pre>
     24 
     25 <script class="testbody" type="text/javascript">
     26  var userAgentID = "ac44402c-85fc-41e4-a0d0-483316d15351";
     27  var channelID = null;
     28 
     29  var mockSocket = new MockWebSocket();
     30  mockSocket.onRegister = function(request) {
     31    channelID = request.channelID;
     32    this.serverSendMsg(JSON.stringify({
     33      messageType: "register",
     34      uaid: userAgentID,
     35      channelID,
     36      status: 200,
     37      pushEndpoint: "https://example.com/endpoint/1",
     38    }));
     39  };
     40 
     41  var registration;
     42  add_task(async function start() {
     43    await setupPrefsAndMockSocket(mockSocket);
     44    await setPushPermission(true);
     45 
     46    var url = "worker.js?caller=test_data.html";
     47    registration = await navigator.serviceWorker.register(url, {scope: "."});
     48    await waitForActive(registration);
     49  });
     50 
     51  var controlledFrame;
     52  add_task(async function createControlledIFrame() {
     53    controlledFrame = await injectControlledFrame();
     54  });
     55 
     56  var pushSubscription;
     57  add_task(async function subscribe() {
     58    pushSubscription = await registration.pushManager.subscribe();
     59  });
     60 
     61  add_task(async function compareJSONSubscription() {
     62    var json = pushSubscription.toJSON();
     63    is(json.endpoint, pushSubscription.endpoint, "Wrong endpoint");
     64 
     65    ["p256dh", "auth"].forEach(keyName => {
     66      isDeeply(
     67        base64UrlDecode(json.keys[keyName]),
     68        new Uint8Array(pushSubscription.getKey(keyName)),
     69        "Mismatched Base64-encoded key: " + keyName
     70      );
     71    });
     72  });
     73 
     74  add_task(async function comparePublicKey() {
     75    var data = await sendRequestToWorker({ type: "publicKey" });
     76    var p256dhKey = new Uint8Array(pushSubscription.getKey("p256dh"));
     77    is(p256dhKey.length, 65, "Key share should be 65 octets");
     78    isDeeply(
     79      p256dhKey,
     80      new Uint8Array(data.p256dh),
     81      "Mismatched key share"
     82    );
     83    var authSecret = new Uint8Array(pushSubscription.getKey("auth"));
     84    is(authSecret.length, 16, "Auth secret should be 16 octets");
     85    isDeeply(
     86      authSecret,
     87      new Uint8Array(data.auth),
     88      "Mismatched auth secret"
     89    );
     90  });
     91 
     92  add_task(async function unsubscribe() {
     93    controlledFrame.remove();
     94    await pushSubscription.unsubscribe();
     95  });
     96 
     97  add_task(async function unregister() {
     98    await registration.unregister();
     99  });
    100 
    101 </script>
    102 </body>
    103 </html>