103 lines
2.9 KiB
HTML
103 lines
2.9 KiB
HTML
<!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>
|