File: test_data.html

package info (click to toggle)
firefox 147.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,324 kB
  • sloc: cpp: 7,607,156; javascript: 6,532,492; ansic: 3,775,158; python: 1,415,368; xml: 634,556; asm: 438,949; java: 186,241; sh: 62,751; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (103 lines) | stat: -rw-r--r-- 3,001 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE HTML>
<html>
<!--
Bug 1185544: Add data delivery to the WebSocket backend.

Any copyright is dedicated to the Public Domain.
http://creativecommons.org/licenses/publicdomain/

-->
<head>
  <title>Test for Bug 1185544</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/dom/push/test/test_utils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
</head>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1185544">Mozilla Bug 1185544</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
</pre>

<script class="testbody" type="text/javascript">
  var userAgentID = "ac44402c-85fc-41e4-a0d0-483316d15351";
  var channelID = null;

  var mockSocket = new MockWebSocket();
  mockSocket.onRegister = function(request) {
    channelID = request.channelID;
    this.serverSendMsg(JSON.stringify({
      messageType: "register",
      uaid: userAgentID,
      channelID,
      status: 200,
      pushEndpoint: "https://example.com/endpoint/1",
    }));
  };

  var registration;
  add_task(async function start() {
    await setupPrefsAndMockSocket(mockSocket);
    await setPushPermission(true);

    var url = "worker.js?caller=test_data.html";
    registration = await navigator.serviceWorker.register(url, {scope: "."});
    await waitForActive(registration);
  });

  var controlledFrame;
  add_task(async function createControlledIFrame() {
    controlledFrame = await injectControlledFrame();
  });

  var pushSubscription;
  add_task(async function subscribe() {
    pushSubscription = await registration.pushManager.subscribe();
  });

  add_task(async function compareJSONSubscription() {
    var json = pushSubscription.toJSON();
    is(json.endpoint, pushSubscription.endpoint, "Wrong endpoint");

    ["p256dh", "auth"].forEach(keyName => {
      isDeeply(
        base64UrlDecode(json.keys[keyName]),
        new Uint8Array(pushSubscription.getKey(keyName)),
        "Mismatched Base64-encoded key: " + keyName
      );
    });
  });

  add_task(async function comparePublicKey() {
    var data = await sendRequestToWorker({ type: "publicKey" });
    var p256dhKey = new Uint8Array(pushSubscription.getKey("p256dh"));
    is(p256dhKey.length, 65, "Key share should be 65 octets");
    isDeeply(
      p256dhKey,
      new Uint8Array(data.p256dh),
      "Mismatched key share"
    );
    var authSecret = new Uint8Array(pushSubscription.getKey("auth"));
    is(authSecret.length, 16, "Auth secret should be 16 octets");
    isDeeply(
      authSecret,
      new Uint8Array(data.auth),
      "Mismatched auth secret"
    );
  });

  add_task(async function unsubscribe() {
    controlledFrame.remove();
    await pushSubscription.unsubscribe();
  });

  add_task(async function unregister() {
    await registration.unregister();
  });

</script>
</body>
</html>