Bug 1281874 P2 Verify that terminating a worker running web crypto works correctly. r=khuey a=abillings
authorBen Kelly <ben@wanderview.com>
Fri, 01 Jul 2016 06:49:35 -0700
changeset 339779 9056c1ff97a6ffa10e787e52b64f34fae9151e73
parent 339778 0ccbc3447026b29f51751c602336a36e7c6601ce
child 339780 4bae0c26ac7116579c5a4ee0e4cd945c2094939a
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey, abillings
bugs1281874
milestone49.0a2
Bug 1281874 P2 Verify that terminating a worker running web crypto works correctly. r=khuey a=abillings
dom/crypto/test/test_WebCrypto_Workers.html
--- 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>