Bug 1508825 - Enable ESLint for dom/crypto (manual changes) r=Standard8,Ehsan
authorVolodymyr Klymenko <klymenkodp@gmail.com>>
Fri, 14 Dec 2018 22:54:56 +0000
changeset 510824 04a31c0080dcb451d71ac75f4b0a026dfd186281
parent 510823 2b3549145fc3405e6e0ba2b6db99a13328636098
child 510825 07c40fd43ee1f3220cc77f2d45de86a4418fc47f
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8, Ehsan
bugs1508825
milestone66.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 1508825 - Enable ESLint for dom/crypto (manual changes) r=Standard8,Ehsan Differential Revision: https://phabricator.services.mozilla.com/D13694
.eslintignore
dom/crypto/test/test-array.js
dom/crypto/test/test-vectors.js
dom/crypto/test/test-worker.js
dom/crypto/test/test_WebCrypto.html
dom/crypto/test/test_WebCrypto_DH.html
dom/crypto/test/test_WebCrypto_ECDH.html
dom/crypto/test/test_WebCrypto_ECDSA.html
dom/crypto/test/test_WebCrypto_HKDF.html
dom/crypto/test/test_WebCrypto_Normalize.html
dom/crypto/test/test_WebCrypto_PBKDF2.html
dom/crypto/test/test_WebCrypto_RSA_OAEP.html
dom/crypto/test/test_WebCrypto_RSA_PSS.html
dom/crypto/test/test_WebCrypto_Workers.html
dom/crypto/test/test_WebCrypto_Wrap_Unwrap.html
dom/crypto/test/test_indexedDB.html
dom/crypto/test/util.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -177,17 +177,16 @@ dom/base/test/unit_ipc/**
 dom/base/test/jsmodules/**
 dom/bindings/**
 dom/broadcastchannel/**
 dom/browser-element/**
 dom/cache/test/mochitest/**
 dom/cache/test/xpcshell/**
 dom/canvas/**
 dom/console/**
-dom/crypto/**
 dom/encoding/**
 dom/events/**
 dom/fetch/**
 dom/file/**
 dom/flex/**
 dom/grid/**
 dom/html/**
 dom/jsurl/**
--- a/dom/crypto/test/test-array.js
+++ b/dom/crypto/test/test-array.js
@@ -1,12 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+// This file expects utils.js to be included in its scope
+/* import-globals-from ./util.js */
 var MOCHITEST = false;
 
 function Test(name, test) {
   this.name = name;
   this.startTime = null;
   this.endTime = null;
   this.result = null;
   this.row = null;
@@ -29,17 +31,19 @@ function Test(name, test) {
     if (!passfail) {
       console.log("expected: " + util.abv2hex(x));
       console.log("   got: " + util.abv2hex(y));
     }
     this.complete(passfail);
   };
 
   this.complete = function(result) {
-    if (MOCHITEST) { ok(result, this.name); }
+    if (MOCHITEST) {
+      ok(result, this.name);
+    }
 
     // Note the end time
     this.endTime = new Date();
     // Set result
     this.result = result;
     // Re-draw the row
     this.draw();
     this.next();
@@ -55,38 +59,40 @@ function Test(name, test) {
     this.row = document.getElementById(id).getElementsByTagName("td");
   };
 
   this.draw = function() {
     if (!this.row) return;
 
     // Print the name of the test
     if (this.name) {
-      this.row[0].innerHTML = this.name;
+      this.row[0].textContent = this.name;
       var that = this;
-      this.row[0].onclick = function() { that.run(); };
+      this.row[0].onclick = function() {
+        that.run();
+      };
     } else {
       this.row[0] = "";
     }
 
     // Print the result of the test
-    if (this.result == true) {
+    if (this.result === true) {
       this.row[1].className = "pass";
       this.row[1].innerHTML = "PASS";
-    } else if (this.result == false) {
+    } else if (this.result === false) {
       this.row[1].className = "fail";
       this.row[1].innerHTML = "FAIL";
     } else {
       // this.row[1].innerHTML = "";
-      this.row[1].innerHTML = this.result;
+      this.row[1].textContent = this.result;
     }
 
     // Print the elapsed time, if known
     if (this.startTime && this.endTime) {
-      this.row[2].innerHTML = (this.endTime - this.startTime) + " ms";
+      this.row[2].textContent = (this.endTime - this.startTime) + " ms";
     } else {
       this.row[2].innerHTML = "";
     }
   };
 }
 
 function WorkerTest(worker, name, test) {
   this.name = `${name} (Worker)`;
@@ -138,23 +144,23 @@ var TestArray = {
 
     // Run the test in a worker too.
     this.tests.push(new WorkerTest(this.worker, name, testFn));
   },
 
   updateSummary() {
     this.pass = this.fail = this.pending = 0;
     for (var i = 0; i < this.tests.length; ++i) {
-      if (this.tests[i].result == true) this.pass++;
-      if (this.tests[i].result == false) this.fail++;
+      if (this.tests[i].result === true) this.pass++;
+      if (this.tests[i].result === false) this.fail++;
       if (this.tests[i].result == null) this.pending++;
     }
-    this.passSpan.innerHTML = this.pass;
-    this.failSpan.innerHTML = this.fail;
-    this.pendingSpan.innerHTML = this.pending;
+    this.passSpan.textContent = this.pass;
+    this.failSpan.textContent = this.fail;
+    this.pendingSpan.textContent = this.pending;
   },
 
   load() {
     // Grab reference to table and summary numbers
     this.table = document.getElementById("results");
     this.passSpan = document.getElementById("passN");
     this.failSpan = document.getElementById("failN");
     this.pendingSpan = document.getElementById("pendingN");
@@ -177,39 +183,45 @@ var TestArray = {
     this.currTest = 0;
     this.runNextTest();
   },
 
   runNextTest() {
     this.updateSummary();
     var i = this.currTest++;
     if (i >= this.tests.length) {
-      if (MOCHITEST) { SimpleTest.finish(); }
+      if (MOCHITEST) {
+        SimpleTest.finish();
+      }
       return;
     }
 
     var self = this;
     this.tests[i].oncomplete = function() {
       self.runNextTest();
     };
     this.tests[i].run();
   },
 };
 
 if (window.addEventListener) {
-  window.addEventListener("load", function() { TestArray.load(); } );
+  window.addEventListener("load", function() {
+    TestArray.load();
+  });
 } else {
-  window.attachEvent("onload", function() { TestArray.load(); } );
+  window.attachEvent("onload", function() {
+    TestArray.load();
+  });
 }
 
 function start() {
   TestArray.run();
 }
 
-MOCHITEST = ("SimpleTest" in window);
+MOCHITEST = "SimpleTest" in window;
 if (MOCHITEST) {
   SimpleTest.waitForExplicitFinish();
   SimpleTest.requestLongerTimeout(2);
   window.addEventListener("load", function() {
     SimpleTest.waitForFocus(start);
   });
 }
 
--- a/dom/crypto/test/test-vectors.js
+++ b/dom/crypto/test/test-vectors.js
@@ -1,13 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-tv = {
+// This file expects utils.js to be included in its scope
+/* import-globals-from ./util.js */
+let tv = {
   raw: util.hex2abv("f3095c4fe5e299477643c2310b44f0aa"),
 
   // this key had an inappropriate length (18 octets)
   negative_raw: util.hex2abv("f3095c4fe5e299477643c2310b44f0aabbcc"),
 
   // openssl genrsa 512 | openssl pkcs8 -topk8 -nocrypt
   pkcs8: util.hex2abv(
     "30820154020100300d06092a864886f70d01010105000482013e3082013a0201" +
--- a/dom/crypto/test/test-worker.js
+++ b/dom/crypto/test/test-worker.js
@@ -1,12 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+/* eslint-env worker */
+
+// This file expects utils.js to be included in its scope
+/* import-globals-from ./util.js */
 importScripts("util.js");
 importScripts("test-vectors.js");
 
 var window = this;
 
 function finish(result) {
   postMessage(result);
 }
@@ -29,16 +33,17 @@ function memcmp_complete(test, value) {
 
 function error(test) {
   return function(x) {
     throw x;
   };
 }
 
 onmessage = function(msg) {
+  // eslint-disable-next-line no-eval
   var test = eval("(" + msg.data + ")");
 
   try {
     test.call({complete: finish});
   } catch (err) {
     error(`Failed to run worker test: ${err}\n`);
   }
 };
--- a/dom/crypto/test/test_WebCrypto.html
+++ b/dom/crypto/test/test_WebCrypto.html
@@ -21,17 +21,16 @@
 
 <script>/* <![CDATA[*/
 "use strict";
 
 // -----------------------------------------------------------------------------
 TestArray.addTest(
   "Test for presence of WebCrypto API methods",
   function() {
-    var that = this;
     this.complete(
       exists(window.crypto.subtle) &&
       exists(window.crypto.subtle.encrypt) &&
       exists(window.crypto.subtle.decrypt) &&
       exists(window.crypto.subtle.sign) &&
       exists(window.crypto.subtle.verify) &&
       exists(window.crypto.subtle.digest) &&
       exists(window.crypto.subtle.importKey) &&
@@ -625,21 +624,16 @@ TestArray.addTest(
     var that = this;
 
     function doDecrypt(x, iv) {
       return crypto.subtle.decrypt(
         { name: "AES-CTR", counter: iv, length: 32 },
         x, tv.aes_ctr_dec.data);
     }
 
-    function decrypt(x) {
-      return decrypt(x, new Uint8Array(15))
-        .catch(function() { return decrypt(x, new Uint8Array(17)); });
-    }
-
     crypto.subtle.importKey("raw", tv.aes_ctr_dec.key, "AES-CTR", false, ["decrypt"])
       .then(doDecrypt)
       .then(
         error(that),
         complete(that)
       );
   }
 );
@@ -999,17 +993,16 @@ TestArray.addTest(
 );
 
 // -----------------------------------------------------------------------------
 TestArray.addTest(
   "RSASSA verification (SHA-256), failing verification",
   function() {
     var that = this;
     var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" };
-    var use = ["sign", "verify"];
 
     function doVerify(x) {
       return crypto.subtle.verify(alg.name, x, tv.rsassa.sig_fail, tv.rsassa.data);
     }
 
     crypto.subtle.importKey("spki", tv.rsassa.spki, alg, false, ["verify"])
       .then( doVerify )
       .then(
@@ -1098,17 +1091,17 @@ TestArray.addTest(
       frames[0].crypto.subtle, rsaAlg, false, ["sign", "verify"]);
 
     if (!checkPrototypes(p1, "Promise") ||
         !checkPrototypes(p2, "Promise") ||
         !checkPrototypes(p3, "Promise")) {
       error(that)();
     }
 
-    Promise.all([p1, p2, p3]).then(complete(that, keys => {
+    return Promise.all([p1, p2, p3]).then(complete(that, keys => {
       return keys.every(key => {
         if (key instanceof CryptoKey) {
           return checkPrototypes(key, "CryptoKey");
         }
 
         return checkPrototypes(key.publicKey, "CryptoKey") &&
                checkPrototypes(key.privateKey, "CryptoKey");
       });
--- a/dom/crypto/test/test_WebCrypto_DH.html
+++ b/dom/crypto/test/test_WebCrypto_DH.html
@@ -16,17 +16,16 @@
 <!-- Test vectors drawn from the literature -->
 <script src="./test-vectors.js"></script>
 
 <!-- General testing framework -->
 <script src="./test-array.js"></script>
 
 <script>/* <![CDATA[*/
 "use strict";
-
 // -----------------------------------------------------------------------------
 TestArray.addTest(
   "Generate a DH key",
   function() {
     var that = this;
     var alg = {
       name: "DH",
       prime: tv.dh.prime,
@@ -63,21 +62,17 @@ TestArray.addTest(
     var that = this;
     var alg = {
       name: "DH",
       prime: tv.dh.prime,
       generator: new Uint8Array([0x02]),
     };
 
     function doDerive(x) {
-      var alg = {
-        name: "DH",
-        public: x.publicKey,
-      };
-      return crypto.subtle.deriveBits(alg, x.privateKey, 128);
+      return crypto.subtle.deriveBits({ name: "DH", public: x.publicKey }, x.privateKey, 128);
     }
 
     crypto.subtle.generateKey(alg, false, ["deriveBits"])
       .then(doDerive, error(that))
       .then(complete(that, function(x) {
         return x.byteLength == 16;
       }), error(that));
   }
@@ -213,18 +208,17 @@ TestArray.addTest(
     var privKey;
     function setPriv(x) { privKey = x.privateKey; }
 
     function doImport() {
       return crypto.subtle.importKey("raw", tv.dh_nist.raw, alg, true, ["deriveBits"]);
     }
 
     function doDerive(pubKey) {
-      var alg = {name: "DH", public: pubKey};
-      return crypto.subtle.deriveBits(alg, privKey, 128);
+      return crypto.subtle.deriveBits({name: "DH", public: pubKey}, privKey, 128);
     }
 
     crypto.subtle.generateKey(alg, false, ["deriveBits"])
       .then(setPriv, error(that))
       .then(doImport, error(that))
       .then(doDerive, error(that))
       .then(complete(that, function(x) {
         return x.byteLength == 16;
--- a/dom/crypto/test/test_WebCrypto_ECDH.html
+++ b/dom/crypto/test/test_WebCrypto_ECDH.html
@@ -57,18 +57,17 @@ TestArray.addTest(
     var that = this;
     var alg = { name: "ECDH", namedCurve: "P-256" };
 
     var pair;
     function setKeyPair(x) { pair = x; }
 
     function doDerive(n) {
       return function(x) {
-        var alg = { name: "ECDH", public: pair.publicKey };
-        return crypto.subtle.deriveBits(alg, pair.privateKey, n * 8);
+        return crypto.subtle.deriveBits({ name: "ECDH", public: pair.publicKey }, pair.privateKey, n * 8);
       };
     }
 
     crypto.subtle.generateKey(alg, false, ["deriveBits"])
       .then(setKeyPair, error(that))
       .then(doDerive(2), error(that))
       .then(function(x) {
         // Deriving less bytes works.
@@ -160,18 +159,17 @@ TestArray.addTest(
     var that = this;
     var alg = { name: "ECDH" };
 
     var pubKey, privKey;
     function setPub(x) { pubKey = x; }
     function setPriv(x) { privKey = x; }
 
     function doDerive() {
-      var alg = { name: "ECDH", public: pubKey };
-      return crypto.subtle.deriveBits(alg, privKey, tv.ecdh_p256.secret.byteLength * 8);
+      return crypto.subtle.deriveBits({ name: "ECDH", public: pubKey }, privKey, tv.ecdh_p256.secret.byteLength * 8);
     }
 
     Promise.all([
       crypto.subtle.importKey("jwk", tv.ecdh_p256.jwk_priv, alg, false, ["deriveBits"])
         .then(setPriv, error(that)),
       crypto.subtle.importKey("jwk", tv.ecdh_p256.jwk_pub, alg, false, ["deriveBits"])
         .then(setPub, error(that)),
     ]).then(doDerive, error(that))
@@ -186,18 +184,17 @@ TestArray.addTest(
     var that = this;
     var alg = { name: "ECDH" };
 
     var pubKey, privKey;
     function setPub(x) { pubKey = x; }
     function setPriv(x) { privKey = x; }
 
     function doDerive() {
-      var alg = { name: "ECDH", public: pubKey };
-      return crypto.subtle.deriveBits(alg, privKey, tv.ecdh_p384.secret.byteLength * 8);
+      return crypto.subtle.deriveBits({ name: "ECDH", public: pubKey }, privKey, tv.ecdh_p384.secret.byteLength * 8);
     }
 
     Promise.all([
       crypto.subtle.importKey("jwk", tv.ecdh_p384.jwk_priv, alg, false, ["deriveBits"])
         .then(setPriv, error(that)),
       crypto.subtle.importKey("jwk", tv.ecdh_p384.jwk_pub, alg, false, ["deriveBits"])
         .then(setPub, error(that)),
     ]).then(doDerive, error(that))
@@ -212,18 +209,17 @@ TestArray.addTest(
     var that = this;
     var alg = { name: "ECDH" };
 
     var pubKey, privKey;
     function setPub(x) { pubKey = x; }
     function setPriv(x) { privKey = x; }
 
     function doDerive() {
-      var alg = { name: "ECDH", public: pubKey };
-      return crypto.subtle.deriveBits(alg, privKey, tv.ecdh_p521.secret.byteLength * 8);
+      return crypto.subtle.deriveBits({ name: "ECDH", public: pubKey }, privKey, tv.ecdh_p521.secret.byteLength * 8);
     }
 
     Promise.all([
       crypto.subtle.importKey("jwk", tv.ecdh_p521.jwk_priv, alg, false, ["deriveBits"])
         .then(setPriv, error(that)),
       crypto.subtle.importKey("jwk", tv.ecdh_p521.jwk_pub, alg, false, ["deriveBits"])
         .then(setPub, error(that)),
     ]).then(doDerive, error(that))
@@ -337,18 +333,17 @@ TestArray.addTest(
     var alg = { name: "ECDH" };
     var algDerived = { name: "HMAC", hash: {name: "SHA-1"} };
 
     var pubKey, privKey;
     function setPub(x) { pubKey = x; }
     function setPriv(x) { privKey = x; }
 
     function doDerive() {
-      var alg = { name: "ECDH", public: pubKey };
-      return crypto.subtle.deriveKey(alg, privKey, algDerived, false, ["sign", "verify"])
+      return crypto.subtle.deriveKey({ name: "ECDH", public: pubKey }, privKey, algDerived, false, ["sign", "verify"])
         .then(function(x) {
           if (!hasKeyFields(x)) {
             throw "Invalid key; missing field(s)";
           }
 
           // 512 bit is the default for HMAC-SHA1.
           if (x.algorithm.length != 512) {
             throw "Invalid key; incorrect length";
@@ -401,16 +396,17 @@ TestArray.addTest(
       return derived.then(function(x) {
         if (!util.memcmp(x, tv.ecdh_p256.spki)) {
           throw "exported key is invalid";
         }
 
         if (keys.length) {
           return nextKey();
         }
+        return Promise.resolve();
       });
     }
 
     nextKey().then(complete(that), error(that));
   }
 );
 
 // -----------------------------------------------------------------------------
@@ -420,18 +416,17 @@ TestArray.addTest(
     var that = this;
     var alg = { name: "ECDH" };
 
     var pubKey, privKey;
     function setPub(x) { pubKey = x; }
     function setPriv(x) { privKey = x; }
 
     function doDerive() {
-      var alg = { name: "ECDH", public: pubKey };
-      return crypto.subtle.deriveBits(alg, privKey, tv.ecdh_p256.secret.byteLength * 8);
+      return crypto.subtle.deriveBits({ name: "ECDH", public: pubKey }, privKey, tv.ecdh_p256.secret.byteLength * 8);
     }
 
     Promise.all([
       crypto.subtle.importKey("spki", tv.ecdh_p256.spki, alg, false, ["deriveBits"])
         .then(setPub),
       crypto.subtle.importKey("jwk", tv.ecdh_p256.jwk_priv, alg, false, ["deriveBits"])
         .then(setPriv),
     ]).then(doDerive)
@@ -457,69 +452,64 @@ TestArray.addTest(
 );
 
 // -----------------------------------------------------------------------------
 TestArray.addTest(
   "Test that importing bad raw ECDH keys fails",
   function() {
     var that = this;
     var alg = { name: "ECDH", namedCurve: "P-256" };
-    var tvs = tv.ecdh_p256_negative.raw_bad;
 
     crypto.subtle.importKey("raw", tv, alg, false, ["deriveBits"])
       .then(error(that), complete(that));
   }
 );
 
 // -----------------------------------------------------------------------------
 TestArray.addTest(
   "Test that importing ECDH keys with an unknown format fails",
   function() {
     var that = this;
     var alg = { name: "ECDH", namedCurve: "P-256" };
-    var tvs = tv.ecdh_p256.raw;
 
     crypto.subtle.importKey("unknown", tv, alg, false, ["deriveBits"])
       .then(error(that), complete(that));
   }
 );
 
 // -----------------------------------------------------------------------------
 TestArray.addTest(
   "Test that importing too short raw ECDH keys fails",
   function() {
     var that = this;
     var alg = { name: "ECDH", namedCurve: "P-256" };
-    var tvs = tv.ecdh_p256_negative.raw_short;
 
     crypto.subtle.importKey("raw", tv, alg, false, ["deriveBits"])
       .then(error(that), complete(that));
   }
 );
 
 // -----------------------------------------------------------------------------
 TestArray.addTest(
   "Test that importing too long raw ECDH keys fails",
   function() {
     var that = this;
     var alg = { name: "ECDH", namedCurve: "P-256" };
-    var tvs = tv.ecdh_p256_negative.raw_long;
 
     crypto.subtle.importKey("raw", tv, alg, false, ["deriveBits"])
       .then(error(that), complete(that));
   }
 );
 
 // -----------------------------------------------------------------------------
 TestArray.addTest(
   "Test that importing compressed raw ECDH keys fails",
   function() {
     var that = this;
     var alg = { name: "ECDH", namedCurve: "P-256" };
-    var tvs = tv.ecdh_p256_negative.raw_compressed;
 
     crypto.subtle.importKey("raw", tv, alg, false, ["deriveBits"])
       .then(error(that), complete(that));
   }
 );
 
 // -----------------------------------------------------------------------------
 TestArray.addTest(
@@ -528,18 +518,17 @@ TestArray.addTest(
     var that = this;
     var alg = { name: "ECDH", namedCurve: "P-256" };
 
     var pubKey, privKey;
     function setPub(x) { pubKey = x; }
     function setPriv(x) { privKey = x; }
 
     function doDerive() {
-      var alg = { name: "ECDH", public: pubKey };
-      return crypto.subtle.deriveBits(alg, privKey, tv.ecdh_p256.secret.byteLength * 8);
+      return crypto.subtle.deriveBits({ name: "ECDH", public: pubKey }, privKey, tv.ecdh_p256.secret.byteLength * 8);
     }
 
     Promise.all([
       crypto.subtle.importKey("raw", tv.ecdh_p256.raw, alg, false, ["deriveBits"])
         .then(setPub),
       crypto.subtle.importKey("jwk", tv.ecdh_p256.jwk_priv, alg, false, ["deriveBits"])
         .then(setPriv),
     ]).then(doDerive)
--- a/dom/crypto/test/test_WebCrypto_ECDSA.html
+++ b/dom/crypto/test/test_WebCrypto_ECDSA.html
@@ -130,20 +130,16 @@ TestArray.addTest(
 
 // -----------------------------------------------------------------------------
 TestArray.addTest(
   "Verify that ECDSA import fails with a known-bad public key",
   function() {
     var that = this;
     var alg = { name: "ECDSA", namedCurve: "P-256", hash: "SHA-256" };
 
-    function doVerify(x) {
-      return crypto.subtle.verify(alg, x, tv.ecdsa_verify.sig, tv.ecdsa_verify.data);
-    }
-
     crypto.subtle.importKey("jwk", tv.ecdsa_bad.pub_jwk, alg, true, ["verify"])
       .then(error(that), complete(that));
   }
 );
 
 // -----------------------------------------------------------------------------
 TestArray.addTest(
   "Raw import/export of a public ECDSA key (P-521)",
--- a/dom/crypto/test/test_WebCrypto_HKDF.html
+++ b/dom/crypto/test/test_WebCrypto_HKDF.html
@@ -141,33 +141,37 @@ TestArray.addTest(
 );
 
 // -----------------------------------------------------------------------------
 TestArray.addTest(
   "Derive known values from test vectors (SHA-1 and SHA-256)",
   function() {
     var that = this;
     var tests = tv.hkdf.slice();
+    if (!tests.length) {
+      error(that)("No tests found");
+      return;
+    }
 
     function next() {
       if (!tests.length) {
-        return;
+        return Promise.resolve();
       }
 
       var test = tests.shift();
-      var {key, data} = test;
+      var {key} = test;
 
       return crypto.subtle.importKey("raw", key, "HKDF", false, ["deriveBits"])
-        .then(function(key) {
+        .then(function(baseKey) {
           return crypto.subtle.deriveBits({
             name: "HKDF",
             hash: test.prf,
             salt: test.salt,
             info: test.info,
-          }, key, test.data.byteLength * 8);
+          }, baseKey, test.data.byteLength * 8);
         })
         .then(function(data) {
           if (!util.memcmp(data, test.data)) {
             throw new Error("derived bits don't match expected value");
           }
 
           // Next test vector.
           return next();
--- a/dom/crypto/test/test_WebCrypto_Normalize.html
+++ b/dom/crypto/test/test_WebCrypto_Normalize.html
@@ -24,33 +24,31 @@
 
 TestArray.addTest(
   "Test that we properly normalize algorithm names",
   function() {
     var that = this;
     var alg = { name: "hmac", hash: {name: "sHa-256"} };
 
     function doGenerateAesKey() {
-      var alg = { name: "AES-gcm", length: 192 };
-      return crypto.subtle.generateKey(alg, false, ["encrypt"]);
+      return crypto.subtle.generateKey({ name: "AES-gcm", length: 192 }, false, ["encrypt"]);
     }
 
     function doGenerateRsaOaepKey() {
-      var alg = {
+      var algo = {
         name: "rsa-OAEP",
         hash: "sha-1",
         modulusLength: 2048,
         publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
       };
-      return crypto.subtle.generateKey(alg, false, ["encrypt", "decrypt"]);
+      return crypto.subtle.generateKey(algo, false, ["encrypt", "decrypt"]);
     }
 
     function doGenerateRsaSsaPkcs1Key() {
-      var alg = { name: "RSASSA-pkcs1-V1_5", hash: "SHA-1" };
-      return crypto.subtle.importKey("pkcs8", tv.pkcs8, alg, true, ["sign"]);
+      return crypto.subtle.importKey("pkcs8", tv.pkcs8, { name: "RSASSA-pkcs1-V1_5", hash: "SHA-1" }, true, ["sign"]);
     }
 
     crypto.subtle.generateKey(alg, false, ["sign"])
       .then(doGenerateAesKey)
       .then(doGenerateRsaOaepKey)
       .then(doGenerateRsaSsaPkcs1Key)
       .then(complete(that), error(that));
   }
--- a/dom/crypto/test/test_WebCrypto_PBKDF2.html
+++ b/dom/crypto/test/test_WebCrypto_PBKDF2.html
@@ -71,23 +71,23 @@ TestArray.addTest(
     var alg = "PBKDF2";
     var key = tv.pbkdf2_sha1.password;
 
     function doDerive(x) {
       if (!hasKeyFields(x)) {
         throw "Invalid key; missing field(s)";
       }
 
-      var alg = {
+      var algo = {
         name: "PBKDF2",
         hash: "SHA-1",
         salt: tv.pbkdf2_sha1.salt,
         iterations: tv.pbkdf2_sha1.iterations,
       };
-      return crypto.subtle.deriveBits(alg, x, tv.pbkdf2_sha1.length);
+      return crypto.subtle.deriveBits(algo, x, tv.pbkdf2_sha1.length);
     }
     function fail(x) { console.log("failing"); error(that)(x); }
 
     crypto.subtle.importKey("raw", key, alg, false, ["deriveBits"])
       .then( doDerive, fail )
       .then( memcmp_complete(that, tv.pbkdf2_sha1.derived), fail );
   }
 );
@@ -99,23 +99,23 @@ TestArray.addTest(
     var that = this;
     var alg = "PBKDF2";
 
     function doDerive(x) {
       if (!hasKeyFields(x)) {
         throw "Invalid key; missing field(s)";
       }
 
-      var alg = {
+      var algo = {
         name: "PBKDF2",
         hash: "SHA-1",
         salt: tv.pbkdf2_sha1.salt,
         iterations: tv.pbkdf2_sha1.iterations,
       };
-      return crypto.subtle.deriveBits(alg, x, tv.pbkdf2_sha1.length);
+      return crypto.subtle.deriveBits(algo, x, tv.pbkdf2_sha1.length);
     }
     function fail(x) { console.log("failing"); error(that)(x); }
 
     crypto.subtle.importKey("jwk", tv.pbkdf2_sha1.jwk, alg, false, ["deriveBits"])
       .then( doDerive, fail )
       .then( memcmp_complete(that, tv.pbkdf2_sha1.derived), fail );
   }
 );
@@ -128,39 +128,39 @@ TestArray.addTest(
     var alg = "PBKDF2";
     var key = tv.pbkdf2_sha1.password;
 
     function doDerive(x) {
       if (!hasKeyFields(x)) {
         throw "Invalid key; missing field(s)";
       }
 
-      var alg = {
+      var algo = {
         name: "PBKDF2",
         hash: "SHA-1",
         salt: tv.pbkdf2_sha1.salt,
         iterations: tv.pbkdf2_sha1.iterations,
       };
 
       var algDerived = {
         name: "HMAC",
         hash: {name: "SHA-1"},
       };
 
-      return crypto.subtle.deriveKey(alg, x, algDerived, false, ["sign", "verify"])
-        .then(function(x) {
-          if (!hasKeyFields(x)) {
+      return crypto.subtle.deriveKey(algo, x, algDerived, false, ["sign", "verify"])
+        .then(function(y) {
+          if (!hasKeyFields(y)) {
             throw "Invalid key; missing field(s)";
           }
 
-          if (x.algorithm.length != 512) {
+          if (y.algorithm.length != 512) {
             throw "Invalid key; incorrect length";
           }
 
-          return x;
+          return y;
         });
     }
 
     function doSignAndVerify(x) {
       var data = new Uint8Array(1024);
 
       return crypto.subtle.sign("HMAC", x, data)
         .then(function(sig) {
@@ -212,23 +212,23 @@ TestArray.addTest(
     var alg = "PBKDF2";
     var key = tv.pbkdf2_sha256.password;
 
     function doDerive(x) {
       if (!hasKeyFields(x)) {
         throw "Invalid key; missing field(s)";
       }
 
-      var alg = {
+      var algo = {
         name: "PBKDF2",
         hash: "SHA-256",
         salt: tv.pbkdf2_sha256.salt,
         iterations: tv.pbkdf2_sha256.iterations,
       };
-      return crypto.subtle.deriveBits(alg, x, tv.pbkdf2_sha256.length);
+      return crypto.subtle.deriveBits(algo, x, tv.pbkdf2_sha256.length);
     }
     function fail(x) { console.log("failing"); error(that)(x); }
 
     crypto.subtle.importKey("raw", key, alg, false, ["deriveBits"])
       .then( doDerive, fail )
       .then( memcmp_complete(that, tv.pbkdf2_sha256.derived), fail );
   }
 );
@@ -241,23 +241,23 @@ TestArray.addTest(
     var alg = "PBKDF2";
     var key = tv.pbkdf2_sha256_no_pwd.password;
 
     function doDerive(x) {
       if (!hasKeyFields(x)) {
         throw "Invalid key; missing field(s)";
       }
 
-      var alg = {
+      var algo = {
         name: "PBKDF2",
         hash: "SHA-256",
         salt: tv.pbkdf2_sha256_no_pwd.salt,
         iterations: tv.pbkdf2_sha256_no_pwd.iterations,
       };
-      return crypto.subtle.deriveBits(alg, x, tv.pbkdf2_sha256_no_pwd.length);
+      return crypto.subtle.deriveBits(algo, x, tv.pbkdf2_sha256_no_pwd.length);
     }
     function fail(x) { console.log("failing"); error(that)(x); }
 
     crypto.subtle.importKey("raw", key, alg, false, ["deriveBits"])
       .then( doDerive, fail )
       .then( memcmp_complete(that, tv.pbkdf2_sha256_no_pwd.derived), fail );
   }
 );
--- a/dom/crypto/test/test_WebCrypto_RSA_OAEP.html
+++ b/dom/crypto/test/test_WebCrypto_RSA_OAEP.html
@@ -28,17 +28,16 @@ SimpleTest.requestLongerTimeout(2);
 // -----------------------------------------------------------------------------
 TestArray.addTest(
   "RSA-OAEP encrypt/decrypt round-trip",
   function() {
     var that = this;
     var privKey, pubKey;
     var alg = {name: "RSA-OAEP", hash: "SHA-1"};
 
-    var privKey, pubKey;
     function setPriv(x) { privKey = x; }
     function setPub(x) { pubKey = x; }
     function doEncrypt() {
       return crypto.subtle.encrypt(alg, pubKey, tv.rsaoaep.data);
     }
     function doDecrypt(x) {
       return crypto.subtle.decrypt(alg, privKey, x);
     }
@@ -107,26 +106,25 @@ TestArray.addTest(
   }
 );
 
 // -----------------------------------------------------------------------------
 TestArray.addTest(
   "RSA-OAEP input data length checks (2048-bit key)",
   function() {
     var that = this;
-    var privKey, pubKey;
+    var pubKey;
     var alg = {
       name: "RSA-OAEP",
       hash: "SHA-1",
       modulusLength: 2048,
       publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
     };
 
-    var privKey, pubKey;
-    function setKey(x) { pubKey = x.publicKey; privKey = x.privateKey; }
+    function setKey(x) { pubKey = x.publicKey; }
     function doEncrypt(n) {
       console.log("entered encrypt(" + n + ")");
       return function() {
         return crypto.subtle.encrypt(alg, pubKey, new Uint8Array(n));
       };
     }
 
     crypto.subtle.generateKey(alg, false, ["encrypt", "decrypt"])
--- a/dom/crypto/test/test_WebCrypto_RSA_PSS.html
+++ b/dom/crypto/test/test_WebCrypto_RSA_PSS.html
@@ -53,22 +53,20 @@ TestArray.addTest(
       modulusLength: 2048,
       publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
     };
 
     var privKey, pubKey;
     var data = crypto.getRandomValues(new Uint8Array(128));
     function setKey(x) { pubKey = x.publicKey; privKey = x.privateKey; }
     function doSign() {
-      var alg = {name: "RSA-PSS", saltLength: 32};
-      return crypto.subtle.sign(alg, privKey, data);
+      return crypto.subtle.sign({name: "RSA-PSS", saltLength: 32}, privKey, data);
     }
     function doVerify(x) {
-      var alg = {name: "RSA-PSS", saltLength: 32};
-      return crypto.subtle.verify(alg, pubKey, x, data);
+      return crypto.subtle.verify({name: "RSA-PSS", saltLength: 32}, pubKey, x, data);
     }
 
     crypto.subtle.generateKey(alg, false, ["sign", "verify"])
       .then(setKey, error(that))
       .then(doSign, error(that))
       .then(doVerify, error(that))
       .then(complete(that, x => x), error(that));
   }
@@ -78,18 +76,17 @@ TestArray.addTest(
 TestArray.addTest(
   "RSA-PSS verify known signature (SHA-1, 1024-bit)",
   function() {
     var that = this;
     var alg = {name: "RSA-PSS", hash: "SHA-1"};
     var vec = tv.rsapss;
 
     function doVerify(x) {
-      var alg = {name: "RSA-PSS", saltLength: vec.saltLength};
-      return crypto.subtle.verify(alg, x, vec.sig, vec.data);
+      return crypto.subtle.verify({name: "RSA-PSS", saltLength: vec.saltLength}, x, vec.sig, vec.data);
     }
 
     crypto.subtle.importKey("spki", vec.spki, alg, false, ["verify"])
       .then(doVerify, error(that))
       .then(complete(that, x => x), error(that));
   }
 );
 
@@ -97,27 +94,27 @@ TestArray.addTest(
 TestArray.addTest(
   "Test invalid RSA-PSS signatures",
   function() {
     var that = this;
     var alg = {name: "RSA-PSS", hash: "SHA-1"};
     var vec = tv.rsapss;
 
     function doVerify(x) {
-      var alg = {name: "RSA-PSS", saltLength: vec.saltLength};
+      var algo = {name: "RSA-PSS", saltLength: vec.saltLength};
       var clone1 = new Uint8Array(vec.data);
       var clone2 = new Uint8Array(vec.data);
       clone1[clone1.byteLength - 1] ^= 1;
       clone2[0] ^= 1;
 
       return Promise.all([
-        crypto.subtle.verify(alg, x, vec.sig, clone1),
-        crypto.subtle.verify(alg, x, vec.sig, clone2),
-        crypto.subtle.verify(alg, x, vec.sig, vec.data.slice(1)),
-        crypto.subtle.verify(alg, x, vec.sig, vec.data.slice(0, vec.data.byteLength - 1)),
+        crypto.subtle.verify(algo, x, vec.sig, clone1),
+        crypto.subtle.verify(algo, x, vec.sig, clone2),
+        crypto.subtle.verify(algo, x, vec.sig, vec.data.slice(1)),
+        crypto.subtle.verify(algo, x, vec.sig, vec.data.slice(0, vec.data.byteLength - 1)),
       ]);
     }
 
     crypto.subtle.importKey("spki", vec.spki, alg, false, ["verify"])
       .then(doVerify, error(that))
       .then(results => results.every(x => !x))
       .then(complete(that, x => x), error(that));
   }
@@ -126,18 +123,17 @@ TestArray.addTest(
 // -----------------------------------------------------------------------------
 TestArray.addTest(
   "RSA-PSS verify known signature (SHA-1, 1024-bit, JWK)",
   function() {
     var that = this;
     var alg = {name: "RSA-PSS", hash: "SHA-1"};
 
     function doVerify(x) {
-      var alg = {name: "RSA-PSS", saltLength: tv.rsapss.saltLength};
-      return crypto.subtle.verify(alg, x, tv.rsapss.sig, tv.rsapss.data);
+      return crypto.subtle.verify({name: "RSA-PSS", saltLength: tv.rsapss.saltLength}, x, tv.rsapss.sig, tv.rsapss.data);
     }
 
     crypto.subtle.importKey("jwk", tv.rsapss.jwk_pub, alg, false, ["verify"])
       .then(doVerify, error(that))
       .then(complete(that, x => x), error(that));
   }
 );
 
@@ -167,22 +163,20 @@ TestArray.addTest(
   "RSA-PSS import SPKI/PKCS#8 keys and sign/verify (SHA-1, 1024-bit)",
   function() {
     var that = this;
     var alg = {name: "RSA-PSS", hash: "SHA-1"};
 
     var privKey, pubKey;
     function setKeys([pub, priv]) { pubKey = pub; privKey = priv; }
     function doSign() {
-      var alg = {name: "RSA-PSS", saltLength: tv.rsapss.saltLength};
-      return crypto.subtle.sign(alg, privKey, tv.rsapss.data);
+      return crypto.subtle.sign({name: "RSA-PSS", saltLength: tv.rsapss.saltLength}, privKey, tv.rsapss.data);
     }
     function doVerify(x) {
-      var alg = {name: "RSA-PSS", saltLength: tv.rsapss.saltLength};
-      return crypto.subtle.verify(alg, pubKey, x, tv.rsapss.data);
+      return crypto.subtle.verify({name: "RSA-PSS", saltLength: tv.rsapss.saltLength}, pubKey, x, tv.rsapss.data);
     }
 
     var spki =
       crypto.subtle.importKey("spki", tv.rsapss.spki, alg, false, ["verify"]);
     var pkcs8 =
       crypto.subtle.importKey("pkcs8", tv.rsapss.pkcs8, alg, false, ["sign"]);
 
     Promise.all([spki, pkcs8])
@@ -198,22 +192,20 @@ TestArray.addTest(
   "RSA-PSS import JWK keys and sign/verify (SHA-1, 1024-bit)",
   function() {
     var that = this;
     var alg = {name: "RSA-PSS", hash: "SHA-1"};
 
     var privKey, pubKey;
     function setKeys([pub, priv]) { pubKey = pub; privKey = priv; }
     function doSign() {
-      var alg = {name: "RSA-PSS", saltLength: tv.rsapss.saltLength};
-      return crypto.subtle.sign(alg, privKey, tv.rsapss.data);
+      return crypto.subtle.sign({name: "RSA-PSS", saltLength: tv.rsapss.saltLength}, privKey, tv.rsapss.data);
     }
     function doVerify(x) {
-      var alg = {name: "RSA-PSS", saltLength: tv.rsapss.saltLength};
-      return crypto.subtle.verify(alg, pubKey, x, tv.rsapss.data);
+      return crypto.subtle.verify({name: "RSA-PSS", saltLength: tv.rsapss.saltLength}, pubKey, x, tv.rsapss.data);
     }
 
     var spki =
       crypto.subtle.importKey("jwk", tv.rsapss.jwk_pub, alg, false, ["verify"]);
     var pkcs8 =
       crypto.subtle.importKey("jwk", tv.rsapss.jwk_priv, alg, false, ["sign"]);
 
     Promise.all([spki, pkcs8])
@@ -336,26 +328,24 @@ TestArray.addTest(
       publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
     };
 
     var privKey, pubKey;
     var data = crypto.getRandomValues(new Uint8Array(128));
     function setKey(x) { pubKey = x.publicKey; privKey = x.privateKey; }
 
     function doSignTwice() {
-      var alg = {name: "RSA-PSS", saltLength: 0};
       return Promise.all([
-        crypto.subtle.sign(alg, privKey, data),
-        crypto.subtle.sign(alg, privKey, data),
+        crypto.subtle.sign({name: "RSA-PSS", saltLength: 0}, privKey, data),
+        crypto.subtle.sign({name: "RSA-PSS", saltLength: 0}, privKey, data),
       ]);
     }
 
     function doVerify(x) {
-      var alg = {name: "RSA-PSS", saltLength: 0};
-      return crypto.subtle.verify(alg, pubKey, x, data);
+      return crypto.subtle.verify({name: "RSA-PSS", saltLength: 0}, pubKey, x, data);
     }
 
     crypto.subtle.generateKey(alg, false, ["sign", "verify"])
       .then(setKey, error(that))
       .then(doSignTwice, error(that))
       .then(([sig1, sig2]) => {
         if (!util.memcmp(sig1, sig2)) {
           throw new Error("sig1 must be equal to sig2");
--- a/dom/crypto/test/test_WebCrypto_Workers.html
+++ b/dom/crypto/test/test_WebCrypto_Workers.html
@@ -37,18 +37,17 @@ TestArray.addTest(
     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 => {
       // Wait for ciphertext, check and decrypt.
       worker.addEventListener("message", ({data: ciphertext}) => {
-        var alg = { name: "AES-GCM", iv: nonce };
-        crypto.subtle.decrypt(alg, key, ciphertext)
+        crypto.subtle.decrypt({ name: "AES-GCM", iv: nonce }, key, ciphertext)
           .then(memcmp_complete(that, data), error(that));
       });
 
       // Send it to the worker.
       worker.postMessage({key, data, nonce});
     });
   }
 );
--- a/dom/crypto/test/test_WebCrypto_Wrap_Unwrap.html
+++ b/dom/crypto/test/test_WebCrypto_Wrap_Unwrap.html
@@ -93,17 +93,17 @@ TestArray.addTest(
   "Key unwrap known answer, using AES-GCM",
   function() {
     var that = this;
     var alg = {
       name: "AES-GCM",
       iv: tv.key_wrap_known_answer.wrapping_iv,
       tagLength: 128,
     };
-    var key, wrappingKey;
+    var wrappingKey;
 
     function doUnwrap(k) {
       wrappingKey = k;
       return crypto.subtle.unwrapKey(
                 "raw", tv.key_wrap_known_answer.wrapped_key,
                 wrappingKey, alg,
                 "AES-GCM", true, ["encrypt", "decrypt"]
              );
--- a/dom/crypto/test/test_indexedDB.html
+++ b/dom/crypto/test/test_indexedDB.html
@@ -34,19 +34,19 @@
 
     function runTest() {
       // Load the test app once, to generate and store keys.
       createMozBrowserFrame((frame, result) => {
         is(result, "ok", "stored keys successfully");
         frame.remove();
 
         // Load the test app again to retrieve stored keys.
-        createMozBrowserFrame((frame, result) => {
-          is(result, "ok", "retrieved keys successfully");
-          frame.remove();
+        createMozBrowserFrame((recFrame, recResult) => {
+          is(recResult, "ok", "retrieved keys successfully");
+          recFrame.remove();
           SimpleTest.finish();
         });
       });
     }
 
     addEventListener("load", function() {
       SpecialPowers.addPermission("browser", true, document);
       SpecialPowers.pushPrefEnv({set: [
--- a/dom/crypto/test/util.js
+++ b/dom/crypto/test/util.js
@@ -100,16 +100,16 @@ function hasBaseJwkFields(x) {
   return hasFields(x, ["kty", "alg", "ext", "key_ops"]);
 }
 
 function shallowArrayEquals(x, y) {
   if (x.length != y.length) {
     return false;
   }
 
-  for (i in x) {
+  for (let i in x) {
     if (x[i] != y[i]) {
       return false;
     }
   }
 
   return true;
 }