Bug 681067 - give mozmill tests in TPS the ability to invoke a sync, a=testonly, DONTBUILD
authorJonathan Griffin <jgriffin@mozilla.com>
Thu, 01 Sep 2011 16:57:31 -0700
changeset 78052 7924c7d102ab9876c69b2747e0c82188f7e2e334
parent 77627 4090b403394a9bdae934a64a78b3fb132fd5ccc9
child 78053 ac2f7fe1b6bf301958501e2359248bd106d26bf0
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly, DONTBUILD
bugs681067
milestone9.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 681067 - give mozmill tests in TPS the ability to invoke a sync, a=testonly, DONTBUILD
services/sync/tests/tps/mozmill_sanity.js
services/sync/tests/tps/test_mozmill_sanity.js
services/sync/tps/extensions/tps/modules/logger.jsm
services/sync/tps/extensions/tps/modules/sync.jsm
services/sync/tps/extensions/tps/modules/tps.jsm
--- a/services/sync/tests/tps/mozmill_sanity.js
+++ b/services/sync/tests/tps/mozmill_sanity.js
@@ -30,31 +30,33 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * **** END LICENSE BLOCK ***** */
 
-var jum = {}; Components.utils.import('resource://mozmill/modules/jum.js', jum);
+Components.utils.import('resource://tps/sync.jsm');
 
 var setupModule = function(module) {
   controller = mozmill.getBrowserController();
-  jum.assert(true, "SetupModule passes");
+  assert.ok(true, "SetupModule passes");
 }
 
 var setupTest = function(module) {
-  jum.assert(true, "SetupTest passes");
+  assert.ok(true, "SetupTest passes");
 }
 
 var testTestStep = function() {
-  jum.assert(true, "test Passes");
+  assert.ok(true, "test Passes");
   controller.open("http://www.mozilla.org");
+  TPS.SetupSyncAccount();
+  assert.equal(TPS.Sync(SYNC_WIPE_SERVER), 0, "sync succeeded");
 }
 
 var teardownTest = function () {
-  jum.assert(true, "teardownTest passes");
+  assert.ok(true, "teardownTest passes");
 }
 
 var teardownModule = function() {
-  jum.assert(true, "teardownModule passes");
+  assert.ok(true, "teardownModule passes");
 }
--- a/services/sync/tests/tps/test_mozmill_sanity.js
+++ b/services/sync/tests/tps/test_mozmill_sanity.js
@@ -11,15 +11,14 @@ var phases = { "phase1": "profile1",
                "phase2": "profile2" };
 
 /*
  * Test phases
  */
 
 Phase('phase1', [
   [RunMozmillTest, 'mozmill_sanity.js'],
-  [Sync, SYNC_WIPE_SERVER]
 ]);
 
 Phase('phase2', [
   [Sync],
   [RunMozmillTest, 'mozmill_sanity2.js'],
 ]);
--- a/services/sync/tps/extensions/tps/modules/logger.jsm
+++ b/services/sync/tps/extensions/tps/modules/logger.jsm
@@ -52,16 +52,25 @@ var Logger =
   _potentialError: null,
 
   init: function (path) {
     if (this._converter != null) {
       // we're already open!
       return;
     }
 
+    let prefs = CC["@mozilla.org/preferences-service;1"]
+                .getService(CI.nsIPrefBranch);
+    if (path) {
+      prefs.setCharPref("tps.logfile", path);
+    }
+    else {
+      path = prefs.getCharPref("tps.logfile");
+    }
+
     this._file = CC["@mozilla.org/file/local;1"]
                  .createInstance(CI.nsILocalFile);
     this._file.initWithPath(path);
     var exists = this._file.exists();
 
     // Make a file output stream and converter to handle it.
     this._foStream = CC["@mozilla.org/network/file-output-stream;1"]
                      .createInstance(CI.nsIFileOutputStream);
new file mode 100644
--- /dev/null
+++ b/services/sync/tps/extensions/tps/modules/sync.jsm
@@ -0,0 +1,135 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is TPS.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Jonathan Griffin <jgriffin@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+
+var EXPORTED_SYMBOLS = ["TPS", "SYNC_WIPE_SERVER", "SYNC_RESET_CLIENT",
+                        "SYNC_WIPE_CLIENT"];
+
+const CC = Components.classes;
+const CI = Components.interfaces;
+const CU = Components.utils;
+
+CU.import("resource://gre/modules/XPCOMUtils.jsm");
+CU.import("resource://gre/modules/Services.jsm");
+CU.import("resource://tps/logger.jsm");
+CU.import("resource://services-sync/service.js");
+CU.import("resource://services-sync/util.js");
+var utils = {}; CU.import('resource://mozmill/modules/utils.js', utils);
+
+const SYNC_WIPE_SERVER = "wipe-server";
+const SYNC_RESET_CLIENT = "reset-client";
+const SYNC_WIPE_CLIENT = "wipe-client";
+
+var prefs = CC["@mozilla.org/preferences-service;1"]
+            .getService(CI.nsIPrefBranch);
+
+var syncFinishedCallback = function() {
+  Logger.logInfo('syncFinishedCallback returned ' + !TPS._waitingForSync);
+  return !TPS._waitingForSync;
+};
+
+var TPS = {
+  _waitingForSync: false,
+  _syncErrors: 0,
+
+  QueryInterface: XPCOMUtils.generateQI([CI.nsIObserver,
+                                         CI.nsISupportsWeakReference]),
+
+  observe: function TPS__observe(subject, topic, data) {
+    Logger.logInfo('Mozmill observed: ' + topic);
+    switch(topic) {
+      case "weave:service:sync:error":
+        if (this._waitingForSync && this._syncErrors == 0) {
+          Logger.logInfo("sync error; retrying...");
+          this._syncErrors++;
+          Utils.namedTimer(function() {
+            Weave.service.sync();
+          }, 1000, this, "resync");
+        }
+        else if (this._waitingForSync) {
+          this._syncErrors = "sync error, see log";
+          this._waitingForSync = false;
+        }
+        break;
+      case "weave:service:sync:finish":
+        if (this._waitingForSync) {
+          this._syncErrors = 0;
+          this._waitingForSync = false;
+        }
+        break;
+    }
+  },
+
+  SetupSyncAccount: function TPS__SetupSyncAccount() {
+    Weave.Service.account = prefs.getCharPref('tps.account.username');
+    Weave.Service.password = prefs.getCharPref('tps.account.password');
+    Weave.Service.passphrase = prefs.getCharPref('tps.account.passphrase');
+    Weave.Svc.Obs.notify("weave:service:setup-complete");
+  },
+
+  Sync: function TPS__Sync(options) {
+    Logger.logInfo('Mozmill starting sync operation: ' + options);
+    switch(options) {
+      case SYNC_WIPE_SERVER:
+        Weave.Svc.Prefs.set("firstSync", "wipeRemote");
+        break;
+      case SYNC_WIPE_CLIENT:
+        Weave.Svc.Prefs.set("firstSync", "wipeClient");
+        break;
+      case SYNC_RESET_CLIENT:
+        Weave.Svc.Prefs.set("firstSync", "resetClient");
+        break;
+      default:
+        Weave.Svc.Prefs.reset("firstSync");
+    }
+
+    if (Weave.Status.service != Weave.STATUS_OK) {
+      return "Sync status not ok: " + Weave.Status.service;
+    }
+
+    this._waitingForSync = true;
+    this._syncErrors = 0;
+    Weave.Service.sync();
+    utils.waitFor(syncFinishedCallback, null, 20000, 500, TPS);
+    return this._syncErrors;
+  },
+};
+
+Services.obs.addObserver(TPS, "weave:service:sync:finish", true);
+Services.obs.addObserver(TPS, "weave:service:sync:error", true);
+Logger.init();
+
+
--- a/services/sync/tps/extensions/tps/modules/tps.jsm
+++ b/services/sync/tps/extensions/tps/modules/tps.jsm
@@ -138,17 +138,17 @@ var TPS =
           if (this._waitingForSync && this._syncErrors == 0) {
             // if this is the first sync error, retry...
             Logger.logInfo("sync error; retrying...");
             this._syncErrors++;
             this._waitingForSync = false;
             Weave.Service.logout();
             Utils.nextTick(this.RunNextTestAction, this);
           }
-          else {
+          else if (this._waitingForSync) {
             // ...otherwise abort the test
             this.DumpError("sync error; aborting test");
             return;
           }
           break;
         case "weave:service:sync:finish":
           if (this._waitingForSync) {
             this._syncErrors = 0;
@@ -466,17 +466,17 @@ var TPS =
       Logger.logInfo("Firefox builddate: " + Services.appinfo.appBuildID);
       Logger.logInfo("Firefox version: " + Services.appinfo.version);
 
       // do some sync housekeeping
       if (Weave.Service.isLoggedIn) {
         this.DumpError("Sync logged in on startup...profile may be dirty");
         return;
       }
-      
+
       // setup observers
       Services.obs.addObserver(this, "weave:service:sync:finish", true);
       Services.obs.addObserver(this, "weave:service:sync:error", true);
       Services.obs.addObserver(this, "sessionstore-windows-restored", true);
       Services.obs.addObserver(this, "private-browsing", true);
 
       // parse the test file
       Services.scriptloader.loadSubScript(file, this);
@@ -493,17 +493,25 @@ var TPS =
         return;
       }
       Logger.logInfo("setting client.name to " + this.phases["phase" + this._currentPhase]);
       Weave.Svc.Prefs.set("client.name", this.phases["phase" + this._currentPhase]);
 
       // wipe the server at the end of the final test phase
       if (this.phases["phase" + (parseInt(this._currentPhase) + 1)] == undefined)
         this_phase.push([this.WipeServer]);
-      
+
+      // Store account details as prefs so they're accessible to the mozmill
+      // framework.
+      let prefs = CC["@mozilla.org/preferences-service;1"]
+                  .getService(CI.nsIPrefBranch);
+      prefs.setCharPref('tps.account.username', this.config.account.username);
+      prefs.setCharPref('tps.account.password', this.config.account.password);
+      prefs.setCharPref('tps.account.passphrase', this.config.account.passphrase);
+
       // start processing the test actions
       this._currentAction = 0;
     }
     catch(e) {
       this.DumpError("Exception caught: " + e);
       return;
     }
   },