Bug 1076828 - Remove leaks-related tests for WeaveCrypto. r?markh draft
authorEdouard Oger <eoger@fastmail.com>
Mon, 30 May 2016 01:57:44 -0700
changeset 372728 5e59eb1c48a7577b026a17971a7f6427b50b8386
parent 372484 2c7440e46d8786b2c82a1d2004e2b6d9d13f4046
child 522237 ad92a9bbf7d452dde4f68af18cf70ddf4406f1ec
push id19586
push userbmo:edouard.oger@gmail.com
push dateMon, 30 May 2016 09:02:49 +0000
reviewersmarkh
bugs1076828
milestone49.0a1
Bug 1076828 - Remove leaks-related tests for WeaveCrypto. r?markh MozReview-Commit-ID: 9z4L2HN5TlA
services/crypto/tests/unit/test_crypto_crypt.js
--- a/services/crypto/tests/unit/test_crypto_crypt.js
+++ b/services/crypto/tests/unit/test_crypto_crypt.js
@@ -1,30 +1,14 @@
 Cu.import("resource://services-crypto/WeaveCrypto.js");
 Cu.importGlobalProperties(['crypto']);
 
 var cryptoSvc = new WeaveCrypto();
 
-function run_test() {
-
-  if ("makeSECItem" in cryptoSvc)   // Only for js-ctypes WeaveCrypto.
-    test_makeSECItem();
-
-  if (this.gczeal) {
-    _("Running crypto tests with gczeal(2).");
-    gczeal(2);
-  }
-  test_bug_617650();
-  test_encrypt_decrypt();
-  test_key_memoization();
-  if (this.gczeal)
-    gczeal(0);
-}
-
-function test_key_memoization() {
+add_task(function* test_key_memoization() {
   let cryptoGlobal = cryptoSvc._getCrypto();
   let oldImport = cryptoGlobal.subtle.importKey;
   if (!oldImport) {
     _("Couldn't swizzle crypto.subtle.importKey; returning.");
     return;
   }
 
   let iv  = cryptoSvc.generateRandomIV();
@@ -45,56 +29,29 @@ function test_key_memoization() {
   // ... as should decryption.
   cryptoSvc.decrypt(cipherText, key, iv);
   cryptoSvc.decrypt(cipherText, key, iv);
   cryptoSvc.decrypt(cipherText, key, iv);
   do_check_eq(c, 2);
 
   // Un-swizzle.
   cryptoGlobal.subtle.importKey = oldImport;
-}
-
-function multiple_decrypts(iterations) {
-  let iv = cryptoSvc.generateRandomIV();
-  let key = cryptoSvc.generateRandomKey();
-  let cipherText = cryptoSvc.encrypt("Hello, world.", key, iv);
-
-  for (let i = 0; i < iterations; ++i) {
-    let clearText = cryptoSvc.decrypt(cipherText, key, iv);
-    do_check_eq(clearText + " " + i, "Hello, world. " + i);
-  }
-  _("Done with multiple_decrypts.");
-}
-
-function test_bug_617650() {
-  if (this.gczeal) {
-    gczeal(2);
-    // Few iterations, because gczeal(2) is expensive... and makes it fail much faster!
-    _("gczeal set to 2; attempting 10 iterations of multiple_decrypts.");
-    multiple_decrypts(10);
-    gczeal(0);
-  } else {
-    // We can't use gczeal on non-debug builds, so try lots of reps instead.
-    _("No gczeal (non-debug build?); attempting 10,000 iterations of multiple_decrypts.");
-    multiple_decrypts(10000);
-  }
-}
+});
 
 // Just verify that it gets populated with the correct bytes.
-function test_makeUint8Array() {
+add_task(function* test_makeUint8Array() {
   Components.utils.import("resource://gre/modules/ctypes.jsm");
 
   let item1 = cryptoSvc.makeUint8Array("abcdefghi", false);
   do_check_true(item1);
   for (let i = 0; i < 8; ++i)
     do_check_eq(item1[i], "abcdefghi".charCodeAt(i));
-}
+});
 
-function test_encrypt_decrypt() {
-
+add_task(function* test_encrypt_decrypt() {
   // First, do a normal run with expected usage... Generate a random key and
   // iv, encrypt and decrypt a string.
   var iv = cryptoSvc.generateRandomIV();
   do_check_eq(iv.length, 24);
 
   var key = cryptoSvc.generateRandomKey();
   do_check_eq(key.length, 44);
 
@@ -248,9 +205,9 @@ function test_encrypt_decrypt() {
 
   try {
     failure = false;
     clearText = cryptoSvc.decrypt(badcipher, key, iv);
   } catch (e) {
     failure = true;
   }
   do_check_true(failure);
-}
+});