Bug 1281874 P2 Verify that terminating a worker running web crypto works correctly. r=khuey
--- a/dom/crypto/test/test_WebCrypto_Workers.html
+++ b/dom/crypto/test/test_WebCrypto_Workers.html
@@ -74,16 +74,59 @@ TestArray.addTest(
crypto.subtle.encrypt(alg, key, data).then(ciphertext => {
// Verify and decrypt.
crypto.subtle.decrypt(alg, key, ciphertext)
.then(memcmp_complete(that, data), error(that));
});
});
}
);
+
+// -----------------------------------------------------------------------------
+TestArray.addTest(
+ "Web crypto in terminating Worker",
+ function () {
+ var worker = new Worker(`data:text/plain,
+ function infiniteEncrypt(key, data, nonce) {
+ var alg = { name: "AES-GCM", iv: nonce };
+ return crypto.subtle.encrypt(alg, key, data).then(_ => {
+ infiniteEncrypt(key, data, nonce);
+ });
+ }
+ onmessage = ({data: {key, data, nonce}}) => {
+ infiniteEncrypt(key, data, nonce);
+ postMessage("started");
+ };
+ `);
+
+ var data = crypto.getRandomValues(new Uint8Array(128));
+ var nonce = crypto.getRandomValues(new Uint8Array(16));
+ var alg = { name: "AES-GCM", length: 128 };
+ var that = this;
+
+ // Generate a new AES key.
+ crypto.subtle.generateKey(alg, false, ["encrypt", "decrypt"]).then(key => {
+ worker.addEventListener("message", ({data: msg}) => {
+ if (msg === "started") {
+ // Terminate the worker while its busy doing crypto work
+ worker.terminate();
+ worker = null;
+
+ // Just end the test immediate since we can't receive any
+ // more messages from the worker after calling terminate().
+ // If we haven't crashed, then the test is a success.
+ that.complete(true);
+ }
+ });
+
+ // Send it to the worker.
+ worker.postMessage({key, data, nonce});
+ });
+ }
+);
/*]]>*/</script>
</head>
<body>
<div id="content">
<div id="head">
<b>Web</b>Crypto<br>