Bug 683254 - On startup with no network, sync icon spins endlessly. r=philikon
authorMarina Samuel <msamuel@mozilla.com>
Tue, 30 Aug 2011 15:38:31 -0700
changeset 76315 c70b87f433de872a0ebf95a7299494f9bf6c1b58
parent 76314 02ab0b42da6f24ff54ba0f7cb53443321f256a3a
child 76316 4090b403394a9bdae934a64a78b3fb132fd5ccc9
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersphilikon
bugs683254
milestone9.0a1
Bug 683254 - On startup with no network, sync icon spins endlessly. r=philikon
browser/base/content/browser-syncui.js
services/sync/modules/policies.js
services/sync/tests/unit/test_errorhandler.js
--- a/browser/base/content/browser-syncui.js
+++ b/browser/base/content/browser-syncui.js
@@ -45,17 +45,18 @@ let gSyncUI = {
          "weave:service:quota:remaining",
          "weave:service:setup-complete",
          "weave:service:login:start",
          "weave:service:login:finish",
          "weave:service:logout:finish",
          "weave:service:start-over",
          "weave:ui:login:error",
          "weave:ui:sync:error",
-         "weave:ui:sync:finish"],
+         "weave:ui:sync:finish",
+         "weave:ui:clear-error"],
 
   _unloaded: false,
 
   init: function SUI_init() {
     // Proceed to set up the UI if Sync has already started up.
     // Otherwise we'll do it when Sync is firing up.
     if (Weave.Status.ready) {
       this.initUI();
@@ -202,19 +203,17 @@ let gSyncUI = {
       title, description, null, Weave.Notifications.PRIORITY_INFO, buttons);
     Weave.Notifications.replaceTitle(notification);
     this._wasDelayed = true;
   },
 
   onLoginFinish: function SUI_onLoginFinish() {
     // Clear out any login failure notifications
     let title = this._stringBundle.GetStringFromName("error.login.title");
-    Weave.Notifications.removeAll(title);
-
-    this.updateUI();
+    this.clearError(title);
   },
 
   onLoginError: function SUI_onLoginError() {
     // if login fails, any other notifications are essentially moot
     Weave.Notifications.removeAll();
 
     // if we haven't set up the client, don't show errors
     if (this._needsSetup()) {
@@ -250,18 +249,17 @@ let gSyncUI = {
     this.updateUI();
   },
 
   onLogout: function SUI_onLogout() {
     this.updateUI();
   },
 
   onStartOver: function SUI_onStartOver() {
-    Weave.Notifications.removeAll();
-    this.updateUI();
+    this.clearError();
   },
 
   onQuotaNotice: function onQuotaNotice(subject, data) {
     let title = this._stringBundle.GetStringFromName("warning.sync.quota.label");
     let description = this._stringBundle.GetStringFromName("warning.sync.quota.description");
     let buttons = [];
     buttons.push(new Weave.NotificationButton(
       this._stringBundle.GetStringFromName("error.sync.viewQuotaButton.label"),
@@ -340,29 +338,32 @@ let gSyncUI = {
     // Show the day-of-week and time (HH:MM) of last sync
     let lastSyncDate = new Date(lastSync).toLocaleFormat("%a %H:%M");
     let lastSyncLabel =
       this._stringBundle.formatStringFromName("lastSync2.label", [lastSyncDate], 1);
 
     syncButton.setAttribute("tooltiptext", lastSyncLabel);
   },
 
+  clearError: function SUI_clearError(errorString) {
+    Weave.Notifications.removeAll(errorString);
+    this.updateUI();
+  },
+
   onSyncFinish: function SUI_onSyncFinish() {
     let title = this._stringBundle.GetStringFromName("error.sync.title");
 
     // Clear out sync failures on a successful sync
-    Weave.Notifications.removeAll(title);
+    this.clearError(title);
 
     if (this._wasDelayed && Weave.Status.sync != Weave.NO_SYNC_NODE_FOUND) {
       title = this._stringBundle.GetStringFromName("error.sync.no_node_found.title");
-      Weave.Notifications.removeAll(title);
+      this.clearError(title);
       this._wasDelayed = false;
     }
-
-    this.updateUI();
   },
 
   onSyncError: function SUI_onSyncError() {
     let title = this._stringBundle.GetStringFromName("error.sync.title");
 
     if (Weave.Status.login != Weave.LOGIN_SUCCEEDED) {
       this.onLoginError();
       return;
@@ -479,16 +480,19 @@ let gSyncUI = {
         this.onStartOver();
         break;
       case "weave:service:ready":
         this.initUI();
         break;
       case "weave:notification:added":
         this.initNotifications();
         break;
+      case "weave:ui:clear-error":
+        this.clearError();
+        break;
     }
   },
 
   QueryInterface: XPCOMUtils.generateQI([
     Ci.nsIObserver,
     Ci.nsISupportsWeakReference
   ])
 };
--- a/services/sync/modules/policies.js
+++ b/services/sync/modules/policies.js
@@ -489,16 +489,18 @@ let ErrorHandler = {
         Status.engines = [engine_name, exception.failureCode || ENGINE_UNKNOWN_FAIL];
         this._log.debug(engine_name + " failed: " + Utils.exceptionStr(exception));
         break;
       case "weave:service:login:error":
         if (this.shouldReportError()) {
           this.resetFileLog(Svc.Prefs.get("log.appender.file.logOnError"),
                             LOG_PREFIX_ERROR);
           Svc.Obs.notify("weave:ui:login:error");
+        } else {
+          Svc.Obs.notify("weave:ui:clear-error");
         }
 
         this.dontIgnoreErrors = false;
         break;
       case "weave:service:sync:error":
         if (Status.sync == CREDENTIALS_CHANGED) {
           Weave.Service.logout();
         }
--- a/services/sync/tests/unit/test_errorhandler.js
+++ b/services/sync/tests/unit/test_errorhandler.js
@@ -608,34 +608,26 @@ add_test(function test_sync_non_network_
 });
 
 add_test(function test_login_network_error() {
   Service.username = "johndoe";
   Service.password = "ilovejane";
   Service.passphrase = "abcdeabcdeabcdeabcdeabcdea";
   Service.clusterURL = "http://localhost:8080/";
 
-  Svc.Obs.add("weave:ui:login:error", function() {
-    do_throw("Should not get here!");
-  });
-
   // Test network errors are not reported.
-  Svc.Obs.add("weave:service:login:error", function onUIUpdate() {
-    Svc.Obs.remove("weave:service:login:error", onUIUpdate);
+  Svc.Obs.add("weave:ui:clear-error", function onClearError() {
+    Svc.Obs.remove("weave:ui:clear-error", onClearError);
 
-    // Wait until other login:error observers are called since
-    // it may change Status.sync.
-    Utils.nextTick(function() {
-      do_check_eq(Status.login, LOGIN_FAILED_NETWORK_ERROR);
+    do_check_eq(Status.login, LOGIN_FAILED_NETWORK_ERROR);
 
-      Service.startOver();
-      Status.resetSync();
-      Services.io.offline = false;
-      run_next_test();
-    });
+    Service.startOver();
+    Status.resetSync();
+    Services.io.offline = false;
+    run_next_test();
   });
 
   setLastSync(NON_PROLONGED_ERROR_DURATION);
   Service.sync();
 });
 
 add_test(function test_sync_network_error() {
   // Test network errors are not reported.