Bug 587027 - Use as little memory as possible (part 2)
authorPhilipp von Weitershausen <philipp@weitershausen.de>
Wed, 25 Aug 2010 15:49:45 -0700
changeset 52157 7f6be7428f0f038529e1247db292f9cdb2615058
parent 52156 fccbb7bad369db106164e0ea7244a9dfbd95ee92
child 52158 cd4339510804697346a26b66c30d66512f0571ec
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
bugs587027
Bug 587027 - Use as little memory as possible (part 2) Fix tests
services/sync/tests/unit/test_load_modules.js
services/sync/tests/unit/test_service_attributes.js
services/sync/tests/unit/test_service_changePassword.js
services/sync/tests/unit/test_service_checkUsername.js
services/sync/tests/unit/test_service_cluster.js
services/sync/tests/unit/test_service_createAccount.js
services/sync/tests/unit/test_service_login.js
services/sync/tests/unit/test_service_migratePrefs.js
services/sync/tests/unit/test_service_passphraseUTF8.js
services/sync/tests/unit/test_service_passwordUTF8.js
services/sync/tests/unit/test_service_persistLogin.js
services/sync/tests/unit/test_service_startup.js
services/sync/tests/unit/test_service_sync_401.js
services/sync/tests/unit/test_service_sync_remoteSetup.js
services/sync/tests/unit/test_service_verifyLogin.js
services/sync/tests/unit/test_service_wipeServer.js
--- a/services/sync/tests/unit/test_load_modules.js
+++ b/services/sync/tests/unit/test_load_modules.js
@@ -12,16 +12,17 @@ const modules = [
                  "engines/passwords.js",
                  "engines/prefs.js",
                  "engines/tabs.js",
                  "engines.js",
                  "ext/Observers.js",
                  "ext/Preferences.js",
                  "identity.js",
                  "log4moz.js",
+                 "main.js",
                  "notifications.js",
                  "resource.js",
                  "service.js",
                  "stores.js",
                  "trackers.js",
                  "type_records/bookmark.js",
                  "type_records/clients.js",
                  "type_records/forms.js",
--- a/services/sync/tests/unit/test_service_attributes.js
+++ b/services/sync/tests/unit/test_service_attributes.js
@@ -1,122 +1,122 @@
 Cu.import("resource://services-sync/base_records/keys.js");
 Cu.import("resource://services-sync/constants.js");
 Cu.import("resource://services-sync/identity.js");
 Cu.import("resource://services-sync/service.js");
 Cu.import("resource://services-sync/status.js");
 Cu.import("resource://services-sync/util.js");
 
 function test_urlsAndIdentities() {
-  _("Various Weave.Service properties correspond to preference settings and update other object properties upon being set.");
+  _("Various Service properties correspond to preference settings and update other object properties upon being set.");
 
   try {
     _("Verify initial state");
     do_check_eq(Svc.Prefs.get("username"), undefined);
     do_check_eq(PubKeys.defaultKeyUri, undefined);
     do_check_eq(PrivKeys.defaultKeyUri, undefined);
     do_check_eq(ID.get("WeaveID").username, "");
     do_check_eq(ID.get("WeaveCryptoID").username, "");
 
-    do_check_true(!!Weave.Service.serverURL); // actual value may change
-    do_check_eq(Weave.Service.clusterURL, "");
-    do_check_eq(Weave.Service.infoURL, undefined);
-    do_check_eq(Weave.Service.storageURL, undefined);
-    do_check_eq(Weave.Service.metaURL, undefined);
+    do_check_true(!!Service.serverURL); // actual value may change
+    do_check_eq(Service.clusterURL, "");
+    do_check_eq(Service.infoURL, undefined);
+    do_check_eq(Service.storageURL, undefined);
+    do_check_eq(Service.metaURL, undefined);
 
     _("The 'username' attribute is normalized to lower case, updates preferences and identities.");
-    Weave.Service.username = "TarZan";
-    do_check_eq(Weave.Service.username, "tarzan");
+    Service.username = "TarZan";
+    do_check_eq(Service.username, "tarzan");
     do_check_eq(Svc.Prefs.get("username"), "tarzan");
     do_check_eq(ID.get("WeaveID").username, "tarzan");
     do_check_eq(ID.get("WeaveCryptoID").username, "tarzan");
 
     // Since we don't have a cluster URL yet, these will still not be defined.
-    do_check_eq(Weave.Service.infoURL, undefined);
-    do_check_eq(Weave.Service.storageURL, undefined);
-    do_check_eq(Weave.Service.metaURL, undefined);
+    do_check_eq(Service.infoURL, undefined);
+    do_check_eq(Service.storageURL, undefined);
+    do_check_eq(Service.metaURL, undefined);
     do_check_eq(PubKeys.defaultKeyUri, undefined);
     do_check_eq(PrivKeys.defaultKeyUri, undefined);
 
     _("Tabs are stripped from the 'username' attribute as they can't be part of a URI.");
-    Weave.Service.username = "jo\thn\tdoe";
+    Service.username = "jo\thn\tdoe";
 
-    do_check_eq(Weave.Service.username, "johndoe");
+    do_check_eq(Service.username, "johndoe");
     do_check_eq(Svc.Prefs.get("username"), "johndoe");
     do_check_eq(ID.get("WeaveID").username, "johndoe");
     do_check_eq(ID.get("WeaveCryptoID").username, "johndoe");
 
     _("The 'clusterURL' attribute updates preferences and cached URLs.");
-    Weave.Service.serverURL = "http://weave.server/";
-    Weave.Service.clusterURL = "http://weave.cluster/";
+    Service.serverURL = "http://weave.server/";
+    Service.clusterURL = "http://weave.cluster/";
     do_check_eq(Svc.Prefs.get("clusterURL"), "http://weave.cluster/");
 
-    do_check_eq(Weave.Service.infoURL,
+    do_check_eq(Service.infoURL,
                 "http://weave.cluster/1.0/johndoe/info/collections");
-    do_check_eq(Weave.Service.storageURL,
+    do_check_eq(Service.storageURL,
                 "http://weave.cluster/1.0/johndoe/storage/");
-    do_check_eq(Weave.Service.metaURL,
+    do_check_eq(Service.metaURL,
                 "http://weave.cluster/1.0/johndoe/storage/meta/global");
     do_check_eq(PubKeys.defaultKeyUri,
                 "http://weave.cluster/1.0/johndoe/storage/keys/pubkey");
     do_check_eq(PrivKeys.defaultKeyUri,
                 "http://weave.cluster/1.0/johndoe/storage/keys/privkey");
 
     _("The 'miscURL' and 'userURL' attributes can be relative to 'serverURL' or absolute.");
     Svc.Prefs.set("miscURL", "relative/misc/");
     Svc.Prefs.set("userURL", "relative/user/");
-    do_check_eq(Weave.Service.miscAPI,
+    do_check_eq(Service.miscAPI,
                 "http://weave.server/relative/misc/1.0/");
-    do_check_eq(Weave.Service.userAPI,
+    do_check_eq(Service.userAPI,
                 "http://weave.server/relative/user/1.0/");
 
     Svc.Prefs.set("miscURL", "http://weave.misc.services/");
     Svc.Prefs.set("userURL", "http://weave.user.services/");
-    do_check_eq(Weave.Service.miscAPI, "http://weave.misc.services/1.0/");
-    do_check_eq(Weave.Service.userAPI, "http://weave.user.services/1.0/");
+    do_check_eq(Service.miscAPI, "http://weave.misc.services/1.0/");
+    do_check_eq(Service.userAPI, "http://weave.user.services/1.0/");
 
-    do_check_eq(Weave.Service.pwResetURL,
+    do_check_eq(Service.pwResetURL,
                 "http://weave.server/weave-password-reset");
 
     _("Empty/false value for 'username' resets preference.");
-    Weave.Service.username = "";
+    Service.username = "";
     do_check_eq(Svc.Prefs.get("username"), undefined);
     do_check_eq(ID.get("WeaveID").username, "");
     do_check_eq(ID.get("WeaveCryptoID").username, "");
 
     _("The 'serverURL' attributes updates/resets preferences.");
     // Identical value doesn't do anything
-    Weave.Service.serverURL = Weave.Service.serverURL;
+    Service.serverURL = Service.serverURL;
     do_check_eq(Svc.Prefs.get("clusterURL"), "http://weave.cluster/");
 
-    Weave.Service.serverURL = "http://different.auth.node/";
+    Service.serverURL = "http://different.auth.node/";
     do_check_eq(Svc.Prefs.get("serverURL"), "http://different.auth.node/");
     do_check_eq(Svc.Prefs.get("clusterURL"), undefined);
 
   } finally {
     Svc.Prefs.resetBranch("");
   }
 }
 
 
 function test_syncID() {
-  _("Weave.Service.syncID is auto-generated, corresponds to preference.");
+  _("Service.syncID is auto-generated, corresponds to preference.");
   new FakeGUIDService();
 
   try {
     // Ensure pristine environment
     do_check_eq(Svc.Prefs.get("client.syncID"), undefined);
 
     // Performing the first get on the attribute will generate a new GUID.
-    do_check_eq(Weave.Service.syncID, "fake-guid-0");
+    do_check_eq(Service.syncID, "fake-guid-0");
     do_check_eq(Svc.Prefs.get("client.syncID"), "fake-guid-0");
 
     Svc.Prefs.set("client.syncID", Utils.makeGUID());
     do_check_eq(Svc.Prefs.get("client.syncID"), "fake-guid-1");
-    do_check_eq(Weave.Service.syncID, "fake-guid-1");
+    do_check_eq(Service.syncID, "fake-guid-1");
   } finally {
     Svc.Prefs.resetBranch("");
     new FakeGUIDService();
   }
 }
 
 
 function test_prefAttributes() {
@@ -126,77 +126,77 @@ function test_prefAttributes() {
   const TIMESTAMP2 = 1275493741122;
   const INTERVAL = 42 * 60 * 1000;   // 42 minutes
   const THRESHOLD = 3142;
   const SCORE = 2718;
   const NUMCLIENTS = 42;
 
   try {
     _("The 'nextSync' and 'nextHeartbeat' attributes store a millisecond timestamp to the nearest second.");
-    do_check_eq(Weave.Service.nextSync, 0);
-    do_check_eq(Weave.Service.nextHeartbeat, 0);
-    Weave.Service.nextSync = TIMESTAMP1;
-    Weave.Service.nextHeartbeat = TIMESTAMP2;
-    do_check_eq(Weave.Service.nextSync, Math.floor(TIMESTAMP1/1000)*1000);
-    do_check_eq(Weave.Service.nextHeartbeat, Math.floor(TIMESTAMP2/1000)*1000);
+    do_check_eq(Service.nextSync, 0);
+    do_check_eq(Service.nextHeartbeat, 0);
+    Service.nextSync = TIMESTAMP1;
+    Service.nextHeartbeat = TIMESTAMP2;
+    do_check_eq(Service.nextSync, Math.floor(TIMESTAMP1/1000)*1000);
+    do_check_eq(Service.nextHeartbeat, Math.floor(TIMESTAMP2/1000)*1000);
 
     _("'syncInterval' has a non-zero default value.");
     do_check_eq(Svc.Prefs.get('syncInterval'), undefined);
-    do_check_true(Weave.Service.syncInterval > 0);
+    do_check_true(Service.syncInterval > 0);
 
     _("'syncInterval' corresponds to a preference setting.");
-    Weave.Service.syncInterval = INTERVAL;
-    do_check_eq(Weave.Service.syncInterval, INTERVAL);
+    Service.syncInterval = INTERVAL;
+    do_check_eq(Service.syncInterval, INTERVAL);
     do_check_eq(Svc.Prefs.get('syncInterval'), INTERVAL);
 
     _("'syncInterval' ignored preference setting after partial sync..");
     Status.partial = true;
-    do_check_eq(Weave.Service.syncInterval, PARTIAL_DATA_SYNC);
+    do_check_eq(Service.syncInterval, PARTIAL_DATA_SYNC);
 
     _("'syncThreshold' corresponds to preference, has non-zero default.");
     do_check_eq(Svc.Prefs.get('syncThreshold'), undefined);
-    do_check_true(Weave.Service.syncThreshold > 0);
-    Weave.Service.syncThreshold = THRESHOLD;
-    do_check_eq(Weave.Service.syncThreshold, THRESHOLD);
+    do_check_true(Service.syncThreshold > 0);
+    Service.syncThreshold = THRESHOLD;
+    do_check_eq(Service.syncThreshold, THRESHOLD);
     do_check_eq(Svc.Prefs.get('syncThreshold'), THRESHOLD);
 
     _("'globalScore' corresponds to preference, defaults to zero.");
     do_check_eq(Svc.Prefs.get('globalScore'), undefined);
-    do_check_eq(Weave.Service.globalScore, 0);
-    Weave.Service.globalScore = SCORE;
-    do_check_eq(Weave.Service.globalScore, SCORE);
+    do_check_eq(Service.globalScore, 0);
+    Service.globalScore = SCORE;
+    do_check_eq(Service.globalScore, SCORE);
     do_check_eq(Svc.Prefs.get('globalScore'), SCORE);
 
     _("'numClients' corresponds to preference, defaults to zero.");
     do_check_eq(Svc.Prefs.get('numClients'), undefined);
-    do_check_eq(Weave.Service.numClients, 0);
-    Weave.Service.numClients = NUMCLIENTS;
-    do_check_eq(Weave.Service.numClients, NUMCLIENTS);
+    do_check_eq(Service.numClients, 0);
+    Service.numClients = NUMCLIENTS;
+    do_check_eq(Service.numClients, NUMCLIENTS);
     do_check_eq(Svc.Prefs.get('numClients'), NUMCLIENTS);
 
   } finally {
     Svc.Prefs.resetBranch("");
   }
 }
 
 
 function test_locked() {
   _("The 'locked' attribute can be toggled with lock() and unlock()");
 
   // Defaults to false
-  do_check_eq(Weave.Service.locked, false);
+  do_check_eq(Service.locked, false);
 
-  do_check_eq(Weave.Service.lock(), true);
-  do_check_eq(Weave.Service.locked, true);
+  do_check_eq(Service.lock(), true);
+  do_check_eq(Service.locked, true);
 
   // Locking again will return false
-  do_check_eq(Weave.Service.lock(), false);
+  do_check_eq(Service.lock(), false);
 
-  Weave.Service.unlock();
-  do_check_eq(Weave.Service.locked, false);
+  Service.unlock();
+  do_check_eq(Service.locked, false);
 }
 
 function run_test() {
   test_urlsAndIdentities();
   test_syncID();
   test_prefAttributes();
   test_locked();
 }
--- a/services/sync/tests/unit/test_service_changePassword.js
+++ b/services/sync/tests/unit/test_service_changePassword.js
@@ -1,9 +1,9 @@
-Cu.import("resource://services-sync/service.js");
+Cu.import("resource://services-sync/main.js");
 Cu.import("resource://services-sync/util.js");
 Cu.import("resource://services-sync/constants.js");
 
 function run_test() {
   var requestBody;
   function send(statusCode, status, body) {
     return function(request, response) {
       requestBody = readBytesFromInputStream(request.bodyInputStream);
--- a/services/sync/tests/unit/test_service_checkUsername.js
+++ b/services/sync/tests/unit/test_service_checkUsername.js
@@ -1,32 +1,33 @@
 Cu.import("resource://services-sync/service.js");
+Cu.import("resource://services-sync/util.js");
 
 function send(statusCode, status, body) {
   return function(request, response) {
     response.setStatusLine(request.httpVersion, statusCode, status);
     response.bodyOutputStream.write(body, body.length);
   };
 }
 
 function run_test() {
   do_test_pending();
   let server = httpd_setup({
     "/user/1.0/johndoe": send(200, "OK", "1"),
     "/user/1.0/janedoe": send(200, "OK", "0")
   });
   try {
-    Weave.Service.serverURL = "http://localhost:8080/";
+    Service.serverURL = "http://localhost:8080/";
 
     _("A 404 will be recorded as 'generic-server-error'");
-    do_check_eq(Weave.Service.checkUsername("jimdoe"), "generic-server-error");
+    do_check_eq(Service.checkUsername("jimdoe"), "generic-server-error");
 
     _("Username that's not available.");
-    do_check_eq(Weave.Service.checkUsername("johndoe"), "notAvailable");
+    do_check_eq(Service.checkUsername("johndoe"), "notAvailable");
 
     _("Username that's available.");
-    do_check_eq(Weave.Service.checkUsername("janedoe"), "available");
+    do_check_eq(Service.checkUsername("janedoe"), "available");
 
   } finally {
-    Weave.Svc.Prefs.resetBranch("");
+    Svc.Prefs.resetBranch("");
     server.stop(do_test_finished);
   }
 }
--- a/services/sync/tests/unit/test_service_cluster.js
+++ b/services/sync/tests/unit/test_service_cluster.js
@@ -14,135 +14,135 @@ function do_check_throws(func) {
 function send(statusCode, status, body) {
   return function(request, response) {
     response.setStatusLine(request.httpVersion, statusCode, status);
     response.bodyOutputStream.write(body, body.length);
   };
 }
 
 function test_findCluster() {
-  _("Test Weave.Service._findCluster()");
+  _("Test Service._findCluster()");
   let server;
   try {
-    Weave.Service.serverURL = "http://localhost:8080/";
-    Weave.Service.username = "johndoe";
+    Service.serverURL = "http://localhost:8080/";
+    Service.username = "johndoe";
 
     _("_findCluster() throws on network errors (e.g. connection refused).");
     do_check_throws(function() {
-      Weave.Service._findCluster();
+      Service._findCluster();
     });
 
     server = httpd_setup({
       "/user/1.0/johndoe/node/weave": send(200, "OK", "http://weave.user.node/"),
       "/user/1.0/jimdoe/node/weave": send(200, "OK", "null"),
       "/user/1.0/janedoe/node/weave": send(404, "Not Found", "Not Found"),
       "/user/1.0/juliadoe/node/weave": send(400, "Bad Request", "Bad Request"),
       "/user/1.0/joedoe/node/weave": send(500, "Server Error", "Server Error")
     });
 
     _("_findCluster() returns the user's cluster node");
-    let cluster = Weave.Service._findCluster();
+    let cluster = Service._findCluster();
     do_check_eq(cluster, "http://weave.user.node/");
 
     _("A 'null' response is converted to null.");
-    Weave.Service.username = "jimdoe";
-    cluster = Weave.Service._findCluster();
+    Service.username = "jimdoe";
+    cluster = Service._findCluster();
     do_check_eq(cluster, null);
 
     _("If a 404 is encountered, the server URL is taken as the cluster URL");
-    Weave.Service.username = "janedoe";
-    cluster = Weave.Service._findCluster();
-    do_check_eq(cluster, Weave.Service.serverURL);
+    Service.username = "janedoe";
+    cluster = Service._findCluster();
+    do_check_eq(cluster, Service.serverURL);
 
     _("A 400 response will throw an error.");
-    Weave.Service.username = "juliadoe";
+    Service.username = "juliadoe";
     do_check_throws(function() {
-      Weave.Service._findCluster();
+      Service._findCluster();
     });
 
     _("Any other server response (e.g. 500) will throw an error.");
-    Weave.Service.username = "joedoe";
+    Service.username = "joedoe";
     do_check_throws(function() {
-      Weave.Service._findCluster();
+      Service._findCluster();
     });
 
   } finally {
     Svc.Prefs.resetBranch("");
     if (server) {
       server.stop(runNextTest);
     }
   }
 }
 
 
 function test_setCluster() {
-  _("Test Weave.Service._setCluster()");
+  _("Test Service._setCluster()");
   let server = httpd_setup({
     "/user/1.0/johndoe/node/weave": send(200, "OK", "http://weave.user.node/"),
     "/user/1.0/jimdoe/node/weave": send(200, "OK", "null")
   });
   try {
-    Weave.Service.serverURL = "http://localhost:8080/";
-    Weave.Service.username = "johndoe";
+    Service.serverURL = "http://localhost:8080/";
+    Service.username = "johndoe";
 
     _("Check initial state.");
-    do_check_eq(Weave.Service.clusterURL, "");
+    do_check_eq(Service.clusterURL, "");
 
     _("Set the cluster URL.");
-    do_check_true(Weave.Service._setCluster());
-    do_check_eq(Weave.Service.clusterURL, "http://weave.user.node/");
+    do_check_true(Service._setCluster());
+    do_check_eq(Service.clusterURL, "http://weave.user.node/");
 
     _("Setting it again won't make a difference if it's the same one.");
-    do_check_false(Weave.Service._setCluster());
-    do_check_eq(Weave.Service.clusterURL, "http://weave.user.node/");
+    do_check_false(Service._setCluster());
+    do_check_eq(Service.clusterURL, "http://weave.user.node/");
 
     _("A 'null' response won't make a difference either.");
-    Weave.Service.username = "jimdoe";
-    do_check_false(Weave.Service._setCluster());
-    do_check_eq(Weave.Service.clusterURL, "http://weave.user.node/");      
+    Service.username = "jimdoe";
+    do_check_false(Service._setCluster());
+    do_check_eq(Service.clusterURL, "http://weave.user.node/");      
 
   } finally {
     Svc.Prefs.resetBranch("");
     server.stop(runNextTest);
   }
 }
 
 function test_updateCluster() {
-  _("Test Weave.Service._updateCluster()");
+  _("Test Service._updateCluster()");
   let server = httpd_setup({
     "/user/1.0/johndoe/node/weave": send(200, "OK", "http://weave.user.node/"),
     "/user/1.0/janedoe/node/weave": send(200, "OK", "http://weave.cluster.url/")
   });
   try {
-    Weave.Service.serverURL = "http://localhost:8080/";
-    Weave.Service.username = "johndoe";
+    Service.serverURL = "http://localhost:8080/";
+    Service.username = "johndoe";
 
     _("Check initial state.");
-    do_check_eq(Weave.Service.clusterURL, "");
+    do_check_eq(Service.clusterURL, "");
     do_check_eq(Svc.Prefs.get("lastClusterUpdate"), null);
 
     _("Set the cluster URL.");
     let before = Date.now();
-    do_check_true(Weave.Service._updateCluster());
-    do_check_eq(Weave.Service.clusterURL, "http://weave.user.node/");
+    do_check_true(Service._updateCluster());
+    do_check_eq(Service.clusterURL, "http://weave.user.node/");
     let lastUpdate = parseFloat(Svc.Prefs.get("lastClusterUpdate"));
     do_check_true(lastUpdate >= before);
 
     _("Trying to update the cluster URL within the backoff timeout won't do anything.");
-    do_check_false(Weave.Service._updateCluster());
-    do_check_eq(Weave.Service.clusterURL, "http://weave.user.node/");
+    do_check_false(Service._updateCluster());
+    do_check_eq(Service.clusterURL, "http://weave.user.node/");
     do_check_eq(parseFloat(Svc.Prefs.get("lastClusterUpdate")), lastUpdate);
 
     _("Time travel 30 mins into the past and the update will work.");
-    Weave.Service.username = "janedoe";
+    Service.username = "janedoe";
     Svc.Prefs.set("lastClusterUpdate", (lastUpdate - 30*60*1000).toString());
 
     before = Date.now();
-    do_check_true(Weave.Service._updateCluster());
-    do_check_eq(Weave.Service.clusterURL, "http://weave.cluster.url/");
+    do_check_true(Service._updateCluster());
+    do_check_eq(Service.clusterURL, "http://weave.cluster.url/");
     lastUpdate = parseFloat(Svc.Prefs.get("lastClusterUpdate"));
     do_check_true(lastUpdate >= before);
   
   } finally {
     Svc.Prefs.resetBranch("");
     server.stop(runNextTest);
   }
 }
--- a/services/sync/tests/unit/test_service_createAccount.js
+++ b/services/sync/tests/unit/test_service_createAccount.js
@@ -18,49 +18,49 @@ function run_test() {
 
   do_test_pending();
   let server = httpd_setup({
     "/user/1.0/johndoe": send(200, "OK", "0"),
     "/user/1.0/janedoe": send(400, "Bad Request", "2"),
     "/user/1.0/jimdoe": send(500, "Server Error", "Server Error")
   });
   try {
-    Weave.Service.serverURL = "http://localhost:8080/";
+    Service.serverURL = "http://localhost:8080/";
 
     _("Create an account.");
-    let res = Weave.Service.createAccount("johndoe", "mysecretpw", "john@doe",
+    let res = Service.createAccount("johndoe", "mysecretpw", "john@doe",
                                           "challenge", "response");
     do_check_eq(res, null);
     let payload = JSON.parse(requestBody);
     do_check_eq(payload.password, "mysecretpw");
     do_check_eq(payload.email, "john@doe");
     do_check_eq(payload["captcha-challenge"], "challenge");
     do_check_eq(payload["captcha-response"], "response");
 
     _("A non-ASCII password is UTF-8 encoded.");
-    res = Weave.Service.createAccount("johndoe", "moneyislike$\u20ac\xa5\u5143",
+    res = Service.createAccount("johndoe", "moneyislike$\u20ac\xa5\u5143",
                                       "john@doe", "challenge", "response");
     do_check_eq(res, null);
     payload = JSON.parse(requestBody);
     do_check_eq(payload.password,
                 Utils.encodeUTF8("moneyislike$\u20ac\xa5\u5143"));
 
     _("Invalid captcha or other user-friendly error.");
-    res = Weave.Service.createAccount("janedoe", "anothersecretpw", "jane@doe",
+    res = Service.createAccount("janedoe", "anothersecretpw", "jane@doe",
                                       "challenge", "response");
     do_check_eq(res, "invalid-captcha");
 
     _("Generic server error.");
-    res = Weave.Service.createAccount("jimdoe", "preciousss", "jim@doe",
+    res = Service.createAccount("jimdoe", "preciousss", "jim@doe",
                                       "challenge", "response");
     do_check_eq(res, "generic-server-error");
 
     _("Admin secret preference is passed as HTTP header token.");
-    Weave.Svc.Prefs.set("admin-secret", "my-server-secret");
-    res = Weave.Service.createAccount("johndoe", "mysecretpw", "john@doe",
+    Svc.Prefs.set("admin-secret", "my-server-secret");
+    res = Service.createAccount("johndoe", "mysecretpw", "john@doe",
                                       "challenge", "response");
     do_check_eq(secretHeader, "my-server-secret");
 
   } finally {
-    Weave.Svc.Prefs.resetBranch("");
+    Svc.Prefs.resetBranch("");
     server.stop(do_test_finished);
   }
 }
--- a/services/sync/tests/unit/test_service_login.js
+++ b/services/sync/tests/unit/test_service_login.js
@@ -26,86 +26,86 @@ function run_test() {
 
   do_test_pending();
   let server = httpd_setup({
     "/1.0/johndoe/info/collections": login_handler,
     "/1.0/janedoe/info/collections": login_handler
   });
 
   try {
-    Weave.Service.serverURL = "http://localhost:8080/";
-    Weave.Service.clusterURL = "http://localhost:8080/";
+    Service.serverURL = "http://localhost:8080/";
+    Service.clusterURL = "http://localhost:8080/";
     Svc.Prefs.set("autoconnect", false);
 
     _("Force the initial state.");
     Status.service = STATUS_OK;
     do_check_eq(Status.service, STATUS_OK);
 
     _("Try logging in. It wont' work because we're not configured yet.");
-    Weave.Service.login();
+    Service.login();
     do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
     do_check_eq(Status.login, LOGIN_FAILED_NO_USERNAME);
-    do_check_false(Weave.Service.isLoggedIn);
+    do_check_false(Service.isLoggedIn);
     do_check_false(Svc.Prefs.get("autoconnect"));
 
     _("Try again with username and password set.");
-    Weave.Service.username = "johndoe";
-    Weave.Service.password = "ilovejane";
-    Weave.Service.login();
+    Service.username = "johndoe";
+    Service.password = "ilovejane";
+    Service.login();
     do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
     do_check_eq(Status.login, LOGIN_FAILED_NO_PASSPHRASE);
-    do_check_false(Weave.Service.isLoggedIn);
+    do_check_false(Service.isLoggedIn);
     do_check_false(Svc.Prefs.get("autoconnect"));
 
     _("Success if passphrase is set.");
-    Weave.Service.passphrase = "foo";
-    Weave.Service.login();
+    Service.passphrase = "foo";
+    Service.login();
     do_check_eq(Status.service, STATUS_OK);
     do_check_eq(Status.login, LOGIN_SUCCEEDED);
-    do_check_true(Weave.Service.isLoggedIn);
+    do_check_true(Service.isLoggedIn);
     do_check_true(Svc.Prefs.get("autoconnect"));
 
     _("We can also pass username, password and passphrase to login().");
-    Weave.Service.login("janedoe", "incorrectpassword", "bar");
-    do_check_eq(Weave.Service.username, "janedoe");
-    do_check_eq(Weave.Service.password, "incorrectpassword");
-    do_check_eq(Weave.Service.passphrase, "bar");
+    Service.login("janedoe", "incorrectpassword", "bar");
+    do_check_eq(Service.username, "janedoe");
+    do_check_eq(Service.password, "incorrectpassword");
+    do_check_eq(Service.passphrase, "bar");
     do_check_eq(Status.service, LOGIN_FAILED);
     do_check_eq(Status.login, LOGIN_FAILED_LOGIN_REJECTED);
-    do_check_false(Weave.Service.isLoggedIn);
+    do_check_false(Service.isLoggedIn);
 
     _("Try again with correct password.");
-    Weave.Service.login("janedoe", "ilovejohn");
+    Service.login("janedoe", "ilovejohn");
     do_check_eq(Status.service, STATUS_OK);
     do_check_eq(Status.login, LOGIN_SUCCEEDED);
-    do_check_true(Weave.Service.isLoggedIn);
+    do_check_true(Service.isLoggedIn);
     do_check_true(Svc.Prefs.get("autoconnect"));
     
     _("Calling login() with parameters when the client is unconfigured sends notification.");
     let notified = false;
-    Weave.Svc.Obs.add("weave:service:setup-complete", function() {
+    Svc.Obs.add("weave:service:setup-complete", function() {
       notified = true;
     });
-    Weave.Service.username = "";
-    Weave.Service.password = "";
-    Weave.Service.passphrase = "";    
-    Weave.Service.login("janedoe", "ilovejohn", "bar");
+    Service.username = "";
+    Service.password = "";
+    Service.passphrase = "";    
+    Service.login("janedoe", "ilovejohn", "bar");
     do_check_true(notified);
     do_check_eq(Status.service, STATUS_OK);
     do_check_eq(Status.login, LOGIN_SUCCEEDED);
-    do_check_true(Weave.Service.isLoggedIn);
+    do_check_true(Service.isLoggedIn);
     do_check_true(Svc.Prefs.get("autoconnect"));
 
     _("Logout.");
-    Weave.Service.logout();
-    do_check_false(Weave.Service.isLoggedIn);
+    Service.logout();
+    do_check_false(Service.isLoggedIn);
     do_check_false(Svc.Prefs.get("autoconnect"));
 
     _("Logging out again won't do any harm.");
-    Weave.Service.logout();
-    do_check_false(Weave.Service.isLoggedIn);
+    Service.logout();
+    do_check_false(Service.isLoggedIn);
     do_check_false(Svc.Prefs.get("autoconnect"));
 
   } finally {
     Svc.Prefs.resetBranch("");
     server.stop(do_test_finished);
   }
 }
--- a/services/sync/tests/unit/test_service_migratePrefs.js
+++ b/services/sync/tests/unit/test_service_migratePrefs.js
@@ -33,16 +33,16 @@ function run_test() {
 
   _("Migrating should set a pref to make sure to not re-migrate");
   do_check_true(globalPref.get("services.sync.migrated"));
 
   _("Make sure re-migrate doesn't happen");
   globalPref.set("extensions.weave.tooLate", "already migrated!");
   do_check_eq(globalPref.get("extensions.weave.tooLate"), "already migrated!");
   do_check_eq(globalPref.get("services.sync.tooLate"), null);
-  Weave.Service._migratePrefs();
+  Service._migratePrefs();
   do_check_eq(globalPref.get("extensions.weave.tooLate"), "already migrated!");
   do_check_eq(globalPref.get("services.sync.tooLate"), null);
 
   _("Clearing out pref changes for other tests");
   globalPref.resetBranch("extensions.weave.");
   globalPref.resetBranch("services.sync.");
 }
--- a/services/sync/tests/unit/test_service_passphraseUTF8.js
+++ b/services/sync/tests/unit/test_service_passphraseUTF8.js
@@ -1,10 +1,10 @@
 Cu.import("resource://services-sync/base_records/keys.js");
-Cu.import("resource://services-sync/service.js");
+Cu.import("resource://services-sync/main.js");
 
 function run_test() {
   initTestLogging("Debug");
 
   // Test fixtures:
 
   // A private key with a unicode passphrase generated with Sync 1.4
   // and the corresponding public key.
--- a/services/sync/tests/unit/test_service_passwordUTF8.js
+++ b/services/sync/tests/unit/test_service_passwordUTF8.js
@@ -53,34 +53,34 @@ function change_password(request, respon
 
 function run_test() {
   do_test_pending();
   let server = httpd_setup({
     "/1.0/johndoe/info/collections": info_collections,
     "/user/1.0/johndoe/password": change_password
   });
 
-  Weave.Service.username = "johndoe";
-  Weave.Service.password = JAPANESE;
-  Weave.Service.passphrase = "Must exist, but contents irrelevant.";
-  Weave.Service.serverURL = "http://localhost:8080/";
+  Service.username = "johndoe";
+  Service.password = JAPANESE;
+  Service.passphrase = "Must exist, but contents irrelevant.";
+  Service.serverURL = "http://localhost:8080/";
 
   try {
     _("Try to log in with the password.");
     server_password = "foobar";
-    do_check_false(Weave.Service.verifyLogin());
+    do_check_false(Service.verifyLogin());
     do_check_eq(server_password, "foobar");
 
     _("Make the server password the low byte version of our password.  Login should work and have transparently changed the password to the UTF8 version.");
     server_password = LOWBYTES;
-    do_check_true(Weave.Service.verifyLogin());
+    do_check_true(Service.verifyLogin());
     do_check_eq(server_password, Utils.encodeUTF8(JAPANESE));
 
     _("Can't use a password that has the same low bytes as ours.");
-    Weave.Service.password = APPLES;
-    do_check_false(Weave.Service.verifyLogin());
+    Service.password = APPLES;
+    do_check_false(Service.verifyLogin());
     do_check_eq(server_password, Utils.encodeUTF8(JAPANESE));
 
   } finally {
     server.stop(do_test_finished);
-    Weave.Svc.Prefs.resetBranch("");
+    Svc.Prefs.resetBranch("");
   }
 }
--- a/services/sync/tests/unit/test_service_persistLogin.js
+++ b/services/sync/tests/unit/test_service_persistLogin.js
@@ -1,9 +1,9 @@
-Cu.import("resource://services-sync/service.js");
+Cu.import("resource://services-sync/main.js");
 Cu.import("resource://services-sync/constants.js");
 
 function run_test() {
   try {
     Weave.Service.username = "johndoe";
     Weave.Service.password = "ilovejane";
     Weave.Service.passphrase = "my preciousss";
 
--- a/services/sync/tests/unit/test_service_startup.js
+++ b/services/sync/tests/unit/test_service_startup.js
@@ -1,40 +1,41 @@
 Cu.import("resource://services-sync/ext/Observers.js");
 Cu.import("resource://services-sync/ext/Sync.js");
 Cu.import("resource://services-sync/identity.js");
 Cu.import("resource://services-sync/util.js");
+Cu.import("resource://services-sync/engines.js");
 
 function run_test() {
-  _("When imported, Weave.Service.onStartup is called");
+  _("When imported, Service.onStartup is called");
 
   // Test fixtures
   let observerCalled = false;
   Observers.add("weave:service:ready", function (subject, data) {
     observerCalled = true;
   });
   Svc.Prefs.set("registerEngines", "Tab,Bookmarks,Form,History");
   Svc.Prefs.set("username", "johndoe");
 
   try {
     Cu.import("resource://services-sync/service.js");
 
     _("Service is enabled.");
-    do_check_eq(Weave.Service.enabled, true);
+    do_check_eq(Service.enabled, true);
 
     _("Engines are registered.");
-    let engines = Weave.Engines.getAll();
+    let engines = Engines.getAll();
     do_check_true(Utils.deepEquals([engine.name for each (engine in engines)],
                                    ['tabs', 'bookmarks', 'forms', 'history']));
 
     _("Identities are registered.");
     do_check_eq(ID.get('WeaveID').username, "johndoe");
     do_check_eq(ID.get('WeaveCryptoID').username, "johndoe");
 
     _("Observers are notified of startup");
-    // Synchronize with Weave.Service.onStartup's async notification
+    // Synchronize with Service.onStartup's async notification
     Sync.sleep(0);
     do_check_true(observerCalled);
 
   } finally {
     Svc.Prefs.resetBranch("");
   }
 }
--- a/services/sync/tests/unit/test_service_sync_401.js
+++ b/services/sync/tests/unit/test_service_sync_401.js
@@ -1,9 +1,9 @@
-Cu.import("resource://services-sync/service.js");
+Cu.import("resource://services-sync/main.js");
 
 function login_handler(request, response) {
   // btoa('johndoe:ilovejane') == am9obmRvZTppbG92ZWphbmU=
   let body;
   if (request.hasHeader("Authorization") &&
       request.getHeader("Authorization") == "Basic am9obmRvZTppbG92ZWphbmU=") {
     body = "{}";
     response.setStatusLine(request.httpVersion, 200, "OK");
--- a/services/sync/tests/unit/test_service_sync_remoteSetup.js
+++ b/services/sync/tests/unit/test_service_sync_remoteSetup.js
@@ -1,9 +1,9 @@
-Cu.import("resource://services-sync/service.js");
+Cu.import("resource://services-sync/main.js");
 Cu.import("resource://services-sync/util.js");
 Cu.import("resource://services-sync/log4moz.js");
 
 function run_test() {
   let logger = Log4Moz.repository.rootLogger;
   Log4Moz.repository.rootLogger.addAppender(new Log4Moz.DumpAppender());
 
   let guidSvc = new FakeGUIDService();
--- a/services/sync/tests/unit/test_service_verifyLogin.js
+++ b/services/sync/tests/unit/test_service_verifyLogin.js
@@ -39,51 +39,51 @@ function run_test() {
   do_test_pending();
   let server = httpd_setup({
     "/api/1.0/johndoe/info/collections": login_handler,
     "/api/1.0/janedoe/info/collections": service_unavailable,
     "/user/1.0/johndoe/node/weave": send(200, "OK", "http://localhost:8080/api/")
   });
 
   try {
-    Weave.Service.serverURL = "http://localhost:8080/";
+    Service.serverURL = "http://localhost:8080/";
 
     _("Force the initial state.");
     Status.service = STATUS_OK;
     do_check_eq(Status.service, STATUS_OK);
 
     _("Credentials won't check out because we're not configured yet.");
-    do_check_false(Weave.Service.verifyLogin());
+    do_check_false(Service.verifyLogin());
     do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
     do_check_eq(Status.login, LOGIN_FAILED_NO_USERNAME);
 
     _("Try again with username and password set.");
-    Weave.Service.username = "johndoe";
-    Weave.Service.password = "ilovejane";
-    do_check_false(Weave.Service.verifyLogin());
+    Service.username = "johndoe";
+    Service.password = "ilovejane";
+    do_check_false(Service.verifyLogin());
     do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
     do_check_eq(Status.login, LOGIN_FAILED_NO_PASSPHRASE);
 
     _("verifyLogin() has found out the user's cluster URL, though.");
-    do_check_eq(Weave.Service.clusterURL, "http://localhost:8080/api/");
+    do_check_eq(Service.clusterURL, "http://localhost:8080/api/");
 
     _("Success if passphrase is set.");
-    Weave.Service.passphrase = "foo";
-    do_check_true(Weave.Service.verifyLogin());
+    Service.passphrase = "foo";
+    do_check_true(Service.verifyLogin());
     do_check_eq(Status.service, STATUS_OK);
     do_check_eq(Status.login, LOGIN_SUCCEEDED);
 
     _("If verifyLogin() encounters a server error, it flips on the backoff flag and notifies observers on a 503 with Retry-After.");
-    Weave.Service.username = "janedoe";
+    Service.username = "janedoe";
     do_check_false(Status.enforceBackoff);
     let backoffInterval;    
     Svc.Obs.add("weave:service:backoff:interval", function(subject, data) {
       backoffInterval = subject;
     });
-    do_check_false(Weave.Service.verifyLogin());
+    do_check_false(Service.verifyLogin());
     do_check_true(Status.enforceBackoff);
     do_check_eq(backoffInterval, 42);
     do_check_eq(Status.service, LOGIN_FAILED);
     do_check_eq(Status.login, LOGIN_FAILED_SERVER_ERROR);
 
   } finally {
     Svc.Prefs.resetBranch("");
     server.stop(do_test_finished);
--- a/services/sync/tests/unit/test_service_wipeServer.js
+++ b/services/sync/tests/unit/test_service_wipeServer.js
@@ -43,28 +43,28 @@ function createAndUploadSymKey(url) {
   let res = new Resource(meta.uri);
   res.put(meta);
   CryptoMetas.set(url, meta);
 }
 
 function setUpTestFixtures() {
   let cryptoService = new FakeCryptoService();
 
-  Weave.Service.clusterURL = "http://localhost:8080/";
-  Weave.Service.username = "johndoe";
-  Weave.Service.passphrase = "secret";
+  Service.clusterURL = "http://localhost:8080/";
+  Service.username = "johndoe";
+  Service.passphrase = "secret";
 
   createAndUploadKeypair();
   createAndUploadSymKey("http://localhost:8080/1.0/johndoe/storage/crypto/steam");
   createAndUploadSymKey("http://localhost:8080/1.0/johndoe/storage/crypto/petrol");
   createAndUploadSymKey("http://localhost:8080/1.0/johndoe/storage/crypto/diesel");
 }
 
 function test_withCollectionList_failOnCrypto() {
-  _("Weave.Service.wipeServer() deletes collections given as argument and aborts if a collection delete fails.");
+  _("Service.wipeServer() deletes collections given as argument and aborts if a collection delete fails.");
 
   let steam_coll = new FakeCollection();
   let petrol_coll = new FakeCollection();
   let diesel_coll = new FakeCollection();
   let crypto_steam = new ServerWBO('steam');
   let crypto_diesel = new ServerWBO('diesel');
 
   let server = httpd_setup({
@@ -92,17 +92,17 @@ function test_withCollectionList_failOnC
 
     do_check_true(CryptoMetas.contains("http://localhost:8080/1.0/johndoe/storage/crypto/steam"));
     do_check_true(CryptoMetas.contains("http://localhost:8080/1.0/johndoe/storage/crypto/petrol"));
     do_check_true(CryptoMetas.contains("http://localhost:8080/1.0/johndoe/storage/crypto/diesel"));
 
     _("wipeServer() will happily ignore the non-existent collection, delete the 'steam' collection and abort after an receiving an error on the 'petrol' collection's symkey.");
     let error;
     try {
-      Weave.Service.wipeServer(["non-existent", "steam", "petrol", "diesel"]);
+      Service.wipeServer(["non-existent", "steam", "petrol", "diesel"]);
     } catch(ex) {
       error = ex;
     }
     _("wipeServer() threw this exception: " + error);
     do_check_true(error != undefined);
 
     _("wipeServer stopped deleting after encountering an error with the 'petrol' collection's symkey, thus only 'steam' and 'petrol' have been deleted.");
     do_check_true(steam_coll.deleted);
@@ -119,17 +119,17 @@ function test_withCollectionList_failOnC
   } finally {
     server.stop(do_test_finished);
     Svc.Prefs.resetBranch("");
     CryptoMetas.clearCache();
   }
 }
 
 function test_withCollectionList_failOnCollection() {
-  _("Weave.Service.wipeServer() deletes collections given as argument.");
+  _("Service.wipeServer() deletes collections given as argument.");
 
   let steam_coll = new FakeCollection();
   let diesel_coll = new FakeCollection();
   let crypto_steam = new ServerWBO('steam');
   let crypto_petrol = new ServerWBO('petrol');
   let crypto_diesel = new ServerWBO('diesel');
 
   let server = httpd_setup({
@@ -157,17 +157,17 @@ function test_withCollectionList_failOnC
 
     do_check_true(CryptoMetas.contains("http://localhost:8080/1.0/johndoe/storage/crypto/steam"));
     do_check_true(CryptoMetas.contains("http://localhost:8080/1.0/johndoe/storage/crypto/petrol"));
     do_check_true(CryptoMetas.contains("http://localhost:8080/1.0/johndoe/storage/crypto/diesel"));
 
     _("wipeServer() will happily ignore the non-existent collection, delete the 'steam' collection and abort after an receiving an error on the 'petrol' collection.");
     let error;
     try {
-      Weave.Service.wipeServer(["non-existent", "steam", "petrol", "diesel"]);
+      Service.wipeServer(["non-existent", "steam", "petrol", "diesel"]);
     } catch(ex) {
       error = ex;
     }
     _("wipeServer() threw this exception: " + error);
     do_check_true(error != undefined);
 
     _("wipeServer stopped deleting after encountering an error with the 'petrol' collection, thus only 'steam' has been deleted.");
     do_check_true(steam_coll.deleted);