Convert test_records_crypto to sync.
authorEdward Lee <edilee@mozilla.com>
Tue, 09 Jun 2009 14:33:45 -0500
changeset 45551 b7d577acb1e7f6ed141056d6cb2bc8a79c8b9b70
parent 45550 96abc2c83eb8398fbc9b0a36f4f68e0ebef66f80
child 45552 cdfe3e5793ebd22eb08da838f49b1cb5dbe4e157
push id14033
push useredward.lee@engineering.uiuc.edu
push dateWed, 23 Jun 2010 22:21:35 +0000
treeherdermozilla-central@227db4ad8cdf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
Convert test_records_crypto to sync.
services/sync/tests/unit/test_records_crypto.js
--- a/services/sync/tests/unit/test_records_crypto.js
+++ b/services/sync/tests/unit/test_records_crypto.js
@@ -1,20 +1,18 @@
 try {
   Cu.import("resource://weave/log4moz.js");
   Cu.import("resource://weave/util.js");
-  Cu.import("resource://weave/async.js");
   Cu.import("resource://weave/auth.js");
   Cu.import("resource://weave/identity.js");
   Cu.import("resource://weave/base_records/keys.js");
   Cu.import("resource://weave/base_records/crypto.js");
 } catch (e) {
   do_throw(e);
 }
-Function.prototype.async = Async.sugar;
 
 let keys, cryptoMeta, cryptoWrap;
 
 function pubkey_handler(metadata, response) {
   let obj = {id: "ignore-me",
              modified: keys.pubkey.modified,
              payload: JSON.stringify(keys.pubkey.payload)};
   return httpd_basic_auth_handler(JSON.stringify(obj), metadata, response);
@@ -36,18 +34,17 @@ function crypted_resource_handler(metada
 
 function crypto_meta_handler(metadata, response) {
   let obj = {id: "ignore-me-4",
              modified: cryptoMeta.modified,
              payload: JSON.stringify(cryptoMeta.payload)};
   return httpd_basic_auth_handler(JSON.stringify(obj), metadata, response);
 }
 
-function async_test() {
-  let self = yield;
+function run_test() {
   let server;
 
   try {
     let log = Log4Moz.repository.getLogger();
     Log4Moz.repository.rootLogger.addAppender(new Log4Moz.DumpAppender());
 
     log.info("Setting up server and authenticator");
 
@@ -69,43 +66,35 @@ function async_test() {
                  getService(Ci.IWeaveCrypto);
     keys.symkey = crypto.generateRandomKey();
     keys.wrappedkey = crypto.wrapSymmetricKey(keys.symkey, keys.pubkey.keyData);
 
     log.info("Setting up keyring");
 
     cryptoMeta = new CryptoMeta("http://localhost:8080/crypto-meta", auth);
     cryptoMeta.generateIV();
-    yield cryptoMeta.addUnwrappedKey(self.cb, keys.pubkey, keys.symkey);
+    cryptoMeta.addUnwrappedKey(keys.pubkey, keys.symkey);
 
     log.info("Creating and encrypting a record");
 
     cryptoWrap = new CryptoWrapper("http://localhost:8080/crypted-resource", auth);
     cryptoWrap.encryption = "http://localhost:8080/crypto-meta";
     cryptoWrap.cleartext = "my payload here";
-    yield cryptoWrap.encrypt(self.cb, "my passphrase");
+    cryptoWrap.encrypt("my passphrase");
 
     log.info("Decrypting the record");
 
-    let payload = yield cryptoWrap.decrypt(self.cb, "my passphrase");
+    let payload = cryptoWrap.decrypt("my passphrase");
     do_check_eq(payload, "my payload here");
     do_check_neq(payload, cryptoWrap.payload); // wrap.data.payload is the encrypted one
 
     log.info("Re-encrypting the record with alternate payload");
 
     cryptoWrap.cleartext = "another payload";
-    yield cryptoWrap.encrypt(self.cb, "my passphrase");
-    payload = yield cryptoWrap.decrypt(self.cb, "my passphrase");
+    cryptoWrap.encrypt("my passphrase");
+    payload = cryptoWrap.decrypt("my passphrase");
     do_check_eq(payload, "another payload");
 
     log.info("Done!");
-    do_test_finished();
   }
   catch (e) { do_throw(e); }
   finally { server.stop(); }
-
-  self.done();
 }
-
-function run_test() {
-  async_test.async(this);
-  do_test_pending();
-}