Bug 1354738 - Don't force Sync initialization on context menu open. r=markh
authorEdouard Oger <eoger@fastmail.com>
Mon, 17 Apr 2017 16:52:35 -0400
changeset 353609 f9788db4055dc371628ced452356d4db2e521b3a
parent 353608 3cf6b363d1b32dc330739ec14de47f73232b2fc8
child 353610 bd0d461eddc10ac23e4d268b6d3a9a50f82d913b
push id31673
push userkwierso@gmail.com
push dateTue, 18 Apr 2017 21:23:54 +0000
treeherdermozilla-central@1a81aadc2510 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs1354738
milestone55.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 1354738 - Don't force Sync initialization on context menu open. r=markh MozReview-Commit-ID: JBwGTW9nLSl
browser/base/content/browser-fxaccounts.js
browser/base/content/test/general/browser_contextmenu.js
browser/base/content/test/general/browser_visibleTabs_contextMenu.js
--- a/browser/base/content/browser-fxaccounts.js
+++ b/browser/base/content/browser-fxaccounts.js
@@ -60,20 +60,17 @@ var gFxAccounts = {
     return this.strings = Services.strings.createBundle(
       "chrome://browser/locale/accounts.properties"
     );
   },
 
   get loginFailed() {
     // Referencing Weave.Service will implicitly initialize sync, and we don't
     // want to force that - so first check if it is ready.
-    let service = Cc["@mozilla.org/weave/service;1"]
-                  .getService(Components.interfaces.nsISupports)
-                  .wrappedJSObject;
-    if (!service.ready) {
+    if (!this.weaveService.ready) {
       return false;
     }
     // LOGIN_FAILED_LOGIN_REJECTED explicitly means "you must log back in".
     // All other login failures are assumed to be transient and should go
     // away by themselves, so aren't reflected here.
     return Weave.Status.login == Weave.LOGIN_FAILED_LOGIN_REJECTED;
   },
 
@@ -371,29 +368,31 @@ var gFxAccounts = {
       const allDevicesLabel = this.strings.GetStringFromName("sendTabToAllDevices.menuitem");
       addTargetDevice("", allDevicesLabel);
     }
 
     devicesPopup.appendChild(fragment);
   },
 
   updateTabContextMenu(aPopupMenu, aTargetTab) {
-    if (!this.sendTabToDeviceEnabled) {
+    if (!this.sendTabToDeviceEnabled ||
+        !this.weaveService.ready) {
       return;
     }
 
     const targetURI = aTargetTab.linkedBrowser.currentURI.spec;
     const showSendTab = this.remoteClients.length > 0 && this.isSendableURI(targetURI);
 
     ["context_sendTabToDevice", "context_sendTabToDevice_separator"]
     .forEach(id => { document.getElementById(id).hidden = !showSendTab });
   },
 
   initPageContextMenu(contextMenu) {
-    if (!this.sendTabToDeviceEnabled) {
+    if (!this.sendTabToDeviceEnabled ||
+        !this.weaveService.ready) {
       return;
     }
 
     const remoteClientPresent = this.remoteClients.length > 0;
     // showSendLink and showSendPage are mutually exclusive
     let showSendLink = remoteClientPresent
                        && (contextMenu.onSaveableLink || contextMenu.onPlainTextLink);
     const showSendPage = !showSendLink && remoteClientPresent
@@ -417,8 +416,15 @@ var gFxAccounts = {
 };
 
 XPCOMUtils.defineLazyGetter(gFxAccounts, "FxAccountsCommon", function() {
   return Cu.import("resource://gre/modules/FxAccountsCommon.js", {});
 });
 
 XPCOMUtils.defineLazyModuleGetter(this, "EnsureFxAccountsWebChannel",
   "resource://gre/modules/FxAccountsWebChannel.jsm");
+
+
+XPCOMUtils.defineLazyGetter(gFxAccounts, "weaveService", function() {
+  return Components.classes["@mozilla.org/weave/service;1"]
+                   .getService(Components.interfaces.nsISupports)
+                   .wrappedJSObject;
+});
--- a/browser/base/content/test/general/browser_contextmenu.js
+++ b/browser/base/content/test/general/browser_contextmenu.js
@@ -891,16 +891,17 @@ add_task(function* test_input_spell_fals
 });
 
 const remoteClientsFixture = [ { id: 1, name: "Foo"}, { id: 2, name: "Bar"} ];
 
 add_task(function* test_plaintext_sendpagetodevice() {
   if (!gFxAccounts.sendTabToDeviceEnabled) {
     return;
   }
+  yield ensureSyncReady();
   const oldGetter = setupRemoteClientsFixture(remoteClientsFixture);
 
   let plainTextItemsWithSendPage =
                     ["context-navigation",   null,
                       ["context-back",         false,
                         "context-forward",      false,
                         "context-reload",       true,
                         "context-bookmarkpage", true], null,
@@ -928,16 +929,17 @@ add_task(function* test_plaintext_sendpa
 
   restoreRemoteClients(oldGetter);
 });
 
 add_task(function* test_link_sendlinktodevice() {
   if (!gFxAccounts.sendTabToDeviceEnabled) {
     return;
   }
+  yield ensureSyncReady();
   const oldGetter = setupRemoteClientsFixture(remoteClientsFixture);
 
   yield test_contextmenu("#test-link",
     ["context-openlinkintab", true,
      ...(hasContainers ? ["context-openlinkinusercontext-menu", true] : []),
      // We need a blank entry here because the containers submenu is
      // dynamically generated with no ids.
      ...(hasContainers ? ["", null] : []),
@@ -985,8 +987,15 @@ function* selectText(selector) {
     let div = doc.createRange();
     let element = doc.querySelector(contentSelector);
     Assert.ok(element, "Found element to select text from");
     div.setStartBefore(element);
     div.setEndAfter(element);
     win.getSelection().addRange(div);
   });
 }
+
+function ensureSyncReady() {
+  let service = Cc["@mozilla.org/weave/service;1"]
+                  .getService(Components.interfaces.nsISupports)
+                  .wrappedJSObject;
+  return service.whenLoaded();
+}
--- a/browser/base/content/test/general/browser_visibleTabs_contextMenu.js
+++ b/browser/base/content/test/general/browser_visibleTabs_contextMenu.js
@@ -16,16 +16,17 @@ add_task(function* test() {
   is(document.getElementById("context_closeTab").disabled, false, "Close Tab is enabled");
   is(document.getElementById("context_reloadAllTabs").disabled, false, "Reload All Tabs is enabled");
 
 
   if (gFxAccounts.sendTabToDeviceEnabled) {
     const origIsSendableURI = gFxAccounts.isSendableURI;
     gFxAccounts.isSendableURI = () => true;
     // Check the send tab to device menu item
+    yield ensureSyncReady();
     const oldGetter = setupRemoteClientsFixture(remoteClientsFixture);
     yield updateTabContextMenu(origTab, function* () {
       yield openMenuItemSubmenu("context_sendTabToDevice");
     });
     is(document.getElementById("context_sendTabToDevice").hidden, false, "Send tab to device is shown");
     let targets = document.getElementById("context_sendTabToDevicePopupMenu").childNodes;
     is(targets[0].getAttribute("label"), "Foo", "Foo target is present");
     is(targets[1].getAttribute("label"), "Bar", "Bar target is present");
@@ -71,8 +72,15 @@ add_task(function* test() {
   // Close Tabs To The End should now be enabled
   updateTabContextMenu(origTab);
   is(document.getElementById("context_closeTabsToTheEnd").disabled, false, "Close Tabs To The End is enabled");
 
   gBrowser.removeTab(testTab);
   gBrowser.removeTab(pinned);
 });
 
+function ensureSyncReady() {
+  let service = Cc["@mozilla.org/weave/service;1"]
+                  .getService(Components.interfaces.nsISupports)
+                  .wrappedJSObject;
+  return service.whenLoaded();
+}
+