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:20 -0700
changeset 335512 5e6976a28642d4d159071e14fd3251d76b9c46fa
parent 335511 f55bcdf46a0e9be3f53c869f832868cfe9db5522
child 335513 407ee2f67d7efbe7ef26865d93a5ebb525ed3fd3
push id1146
push userCallek@gmail.com
push dateMon, 25 Jul 2016 16:35:44 +0000
treeherdermozilla-release@a55778f9cd5a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey, abillings
bugs1281874
milestone48.0
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>