Bug 992198 - TPS.Sync() fails for special options like 'wipeRemote' if the user is not logged in yet. r=jgriffin a=lsblakk DONTBUILD
authorHenrik Skupin <mail@hskupin.info>
Wed, 09 Apr 2014 23:35:57 +0200
changeset 191829 3ffa2cf8610c05dac1705ca70eeadb865b7126a6
parent 191828 a559848a8a00d00c9a8e897510f00b0b67bea14e
child 191830 0fa9873c2881f2e87e7d049990e88b1740584f09
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin, lsblakk
bugs992198
milestone30.0a2
Bug 992198 - TPS.Sync() fails for special options like 'wipeRemote' if the user is not logged in yet. r=jgriffin a=lsblakk DONTBUILD
services/sync/tps/extensions/tps/resource/tps.jsm
--- a/services/sync/tps/extensions/tps/resource/tps.jsm
+++ b/services/sync/tps/extensions/tps/resource/tps.jsm
@@ -37,37 +37,47 @@ Cu.import("resource://tps/modules/window
 var hh = Cc["@mozilla.org/network/protocol;1?name=http"]
          .getService(Ci.nsIHttpProtocolHandler);
 var prefs = Cc["@mozilla.org/preferences-service;1"]
             .getService(Ci.nsIPrefBranch);
 
 var mozmillInit = {};
 Cu.import('resource://mozmill/modules/init.js', mozmillInit);
 
-const ACTION_ADD              = "add";
-const ACTION_VERIFY           = "verify";
-const ACTION_VERIFY_NOT       = "verify-not";
-const ACTION_MODIFY           = "modify";
-const ACTION_SYNC             = "sync";
-const ACTION_DELETE           = "delete";
-const ACTION_PRIVATE_BROWSING = "private-browsing";
-const ACTION_WIPE_REMOTE      = "wipe-remote";
-const ACTION_WIPE_SERVER      = "wipe-server";
-const ACTION_SET_ENABLED      = "set-enabled";
+// Options for wiping data during a sync
+const SYNC_RESET_CLIENT = "resetClient";
+const SYNC_WIPE_CLIENT  = "wipeClient";
+const SYNC_WIPE_REMOTE  = "wipeRemote";
 
-const ACTIONS = [ACTION_ADD, ACTION_VERIFY, ACTION_VERIFY_NOT,
-                 ACTION_MODIFY, ACTION_SYNC, ACTION_DELETE,
-                 ACTION_PRIVATE_BROWSING, ACTION_WIPE_REMOTE,
-                 ACTION_WIPE_SERVER, ACTION_SET_ENABLED];
+// Actions a test can perform
+const ACTION_ADD                = "add";
+const ACTION_DELETE             = "delete";
+const ACTION_MODIFY             = "modify";
+const ACTION_PRIVATE_BROWSING   = "private-browsing";
+const ACTION_SET_ENABLED        = "set-enabled";
+const ACTION_SYNC               = "sync";
+const ACTION_SYNC_RESET_CLIENT  = SYNC_RESET_CLIENT;
+const ACTION_SYNC_WIPE_CLIENT   = SYNC_WIPE_CLIENT;
+const ACTION_SYNC_WIPE_REMOTE   = SYNC_WIPE_REMOTE;
+const ACTION_VERIFY             = "verify";
+const ACTION_VERIFY_NOT         = "verify-not";
 
-const SYNC_WIPE_CLIENT  = "wipe-client";
-const SYNC_WIPE_REMOTE  = "wipe-remote";
-const SYNC_WIPE_SERVER  = "wipe-server";
-const SYNC_RESET_CLIENT = "reset-client";
-const SYNC_START_OVER   = "start-over";
+const ACTIONS = [
+  ACTION_ADD,
+  ACTION_DELETE,
+  ACTION_MODIFY,
+  ACTION_PRIVATE_BROWSING,
+  ACTION_SET_ENABLED,
+  ACTION_SYNC,
+  ACTION_SYNC_RESET_CLIENT,
+  ACTION_SYNC_WIPE_CLIENT,
+  ACTION_SYNC_WIPE_REMOTE,
+  ACTION_VERIFY,
+  ACTION_VERIFY_NOT,
+];
 
 const OBSERVER_TOPICS = ["fxaccounts:onlogin",
                          "fxaccounts:onlogout",
                          "private-browsing",
                          "quit-application-requested",
                          "sessionstore-windows-restored",
                          "weave:engine:start-tracking",
                          "weave:engine:stop-tracking",
@@ -87,16 +97,17 @@ let TPS = {
   _finalPhase: false,
   _isTracking: false,
   _operations_pending: 0,
   _phaseFinished: false,
   _phaselist: {},
   _setupComplete: false,
   _syncActive: false,
   _syncErrors: 0,
+  _syncWipeAction: null,
   _tabsAdded: 0,
   _tabsFinished: 0,
   _test: null,
   _usSinceEpoch: 0,
   _waitingForSync: false,
 
   _init: function TPS__init() {
     // Check if Firefox Accounts is enabled
@@ -153,16 +164,22 @@ let TPS = {
           break;
 
         case "sessionstore-windows-restored":
           Utils.nextTick(this.RunNextTestAction, this);
           break;
 
         case "weave:service:setup-complete":
           this._setupComplete = true;
+
+          if (this._syncWipeAction) {
+            Weave.Svc.Prefs.set("firstSync", this._syncWipeAction);
+            this._syncWipeAction = null;
+          }
+
           break;
 
         case "weave:service:sync:error":
           this._syncActive = false;
 
           if (this._waitingForSync && this._syncErrors == 0) {
             // if this is the first sync error, retry...
             Logger.logInfo("sync error; retrying...");
@@ -821,39 +838,41 @@ let TPS = {
                                           : this.config.sync_account;
     Authentication.signIn(account);
 
     this.waitForSetupComplete();
     Logger.AssertEqual(Weave.Status.service, Weave.STATUS_OK, "Weave status OK");
     this.waitForTracking();
   },
 
-  Sync: function TPS__Sync(options) {
-    Logger.logInfo("executing Sync " + (options ? options : ""));
+  /**
+   * Triggers a sync operation
+   *
+   * @param {String} [wipeAction]
+   *        Type of wipe to perform (resetClient, wipeClient, wipeRemote)
+   *
+   */
+  Sync: function TPS__Sync(wipeAction) {
+    Logger.logInfo("Executing Sync" + (wipeAction ? ": " + wipeAction : ""));
 
-    if (options == SYNC_WIPE_REMOTE) {
-      Weave.Svc.Prefs.set("firstSync", "wipeRemote");
+    // Force a wipe action if requested. In case of an initial sync the pref
+    // will be overwritten by Sync itself (see bug 992198), so ensure that we
+    // also handle it via the "weave:service:setup-complete" notification.
+    if (wipeAction) {
+      this._syncWipeAction = wipeAction;
+      Weave.Svc.Prefs.set("firstSync", wipeAction);
     }
-    else if (options == SYNC_WIPE_CLIENT) {
-      Weave.Svc.Prefs.set("firstSync", "wipeClient");
-    }
-    else if (options == SYNC_RESET_CLIENT) {
-      Weave.Svc.Prefs.set("firstSync", "resetClient");
-    }
-    else if (options) {
-      throw new Error("Unhandled options to Sync(): " + options);
-    } else {
+    else {
       Weave.Svc.Prefs.reset("firstSync");
     }
 
     this.Login(false);
 
     this._waitingForSync = true;
     this.StartAsyncOperation();
-
     Weave.Service.sync();
   },
 
   WipeServer: function TPS__WipeServer() {
     Logger.logInfo("Wiping data from server.");
 
     this.Login(false);
     Weave.Service.login();