Bug 1281874 P2 Verify that terminating a worker running web crypto works correctly. r=khuey
authorBen Kelly <ben@wanderview.com>
Fri, 01 Jul 2016 06:49:45 -0700
changeset 303422 28f16fa4bc48177695fa7b44c8031dd2bacbd526
parent 303421 00f81b0e199303e9eeef69c6f5dbb25713d925b7
child 303423 25d979f7c932e272ff80dfc5dd303674bcd6f21a
push id30388
push usercbook@mozilla.com
push dateSat, 02 Jul 2016 09:15:23 +0000
treeherdermozilla-central@39dffbba7642 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs1281874
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1281874 P2 Verify that terminating a worker running web crypto works correctly. r=khuey
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>