From 9ea55f75c4bec45ea52bdc812769a3102003f753 Mon Sep 17 00:00:00 2001 From: Mark Hammond Date: Wed, 25 Sep 2019 04:31:20 +0000 Subject: [PATCH] Bug 1583414 - don't attempt to refresh the FxA device list if sync's not configured. r=eoger Differential Revision: https://phabricator.services.mozilla.com/D46889 --HG-- extra : moz-landing-system : lando --- browser/base/content/browser-sync.js | 18 ++++++++++-------- .../test/sync/browser_contextmenu_sendpage.js | 4 ++-- .../test/sync/browser_contextmenu_sendtab.js | 6 +++--- .../browser_policy_disable_fxaccounts.js | 4 ++-- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/browser/base/content/browser-sync.js b/browser/base/content/browser-sync.js index 384ad7f70372..0f37e5dc6e0c 100644 --- a/browser/base/content/browser-sync.js +++ b/browser/base/content/browser-sync.js @@ -117,7 +117,7 @@ var gSync = { ); XPCOMUtils.defineLazyPreferenceGetter( this, - "SYNC_ENABLED", + "FXA_ENABLED", "identity.fxaccounts.enabled" ); }, @@ -141,8 +141,8 @@ var gSync = { this._definePrefGetters(); - if (!this.SYNC_ENABLED) { - this.onSyncDisabled(); + if (!this.FXA_ENABLED) { + this.onFxaDisabled(); return; } @@ -313,7 +313,7 @@ var gSync = { if (gSync.sendTabConfiguredAndLoading) { bodyNode.setAttribute("state", "notready"); } - if (reloadDevices) { + if (reloadDevices && UIState.get().syncEnabled) { // Force a background Sync Services.tm.dispatchToMainThread(async () => { // `engines: []` = clients engine only + refresh FxA Devices. @@ -1032,8 +1032,8 @@ var gSync = { // can lead to a empty label for 'Send To Device' Menu. this.init(); - if (!this.SYNC_ENABLED) { - // These items are hidden in onSyncDisabled(). No need to do anything. + if (!this.FXA_ENABLED) { + // These items are hidden in onFxaDisabled(). No need to do anything. return; } let hasASendableURI = false; @@ -1064,7 +1064,7 @@ var gSync = { // "Send Page to Device" and "Send Link to Device" menu items updateContentContextMenu(contextMenu) { - if (!this.SYNC_ENABLED) { + if (!this.FXA_ENABLED) { // These items are hidden by default. No need to do anything. return; } @@ -1205,6 +1205,8 @@ var gSync = { if (!UIState.isReady()) { return; } + // Note we don't bother checking if sync is actually enabled - none of the + // UI which calls this function should be visible in that case. const state = UIState.get(); if (state.status == UIState.STATUS_SIGNED_IN) { this.updateSyncStatus({ syncing: true }); @@ -1338,7 +1340,7 @@ var gSync = { } }, - onSyncDisabled() { + onFxaDisabled() { const toHide = [...document.querySelectorAll(".sync-ui-item")]; for (const item of toHide) { item.hidden = true; diff --git a/browser/base/content/test/sync/browser_contextmenu_sendpage.js b/browser/base/content/test/sync/browser_contextmenu_sendpage.js index d695c91c42d7..2b44ccf131d6 100644 --- a/browser/base/content/test/sync/browser_contextmenu_sendpage.js +++ b/browser/base/content/test/sync/browser_contextmenu_sendpage.js @@ -311,8 +311,8 @@ add_task(async function test_page_contextmenu_login_failed() { }); add_task(async function test_page_contextmenu_fxa_disabled() { - const getter = sinon.stub(gSync, "SYNC_ENABLED").get(() => false); - gSync.onSyncDisabled(); // Would have been called on gSync initialization if SYNC_ENABLED had been set. + const getter = sinon.stub(gSync, "FXA_ENABLED").get(() => false); + gSync.onFxaDisabled(); // Would have been called on gSync initialization if FXA_ENABLED had been set. await openContentContextMenu("#moztext"); is( document.getElementById("context-sendpagetodevice").hidden, diff --git a/browser/base/content/test/sync/browser_contextmenu_sendtab.js b/browser/base/content/test/sync/browser_contextmenu_sendtab.js index c69b49014452..8e6343b2d324 100644 --- a/browser/base/content/test/sync/browser_contextmenu_sendtab.js +++ b/browser/base/content/test/sync/browser_contextmenu_sendtab.js @@ -177,9 +177,9 @@ add_task(async function test_tab_contextmenu_sync_not_ready_other_state() { }); add_task(async function test_tab_contextmenu_fxa_disabled() { - const getter = sinon.stub(gSync, "SYNC_ENABLED").get(() => false); - // Simulate onSyncDisabled() being called on window open. - gSync.onSyncDisabled(); + const getter = sinon.stub(gSync, "FXA_ENABLED").get(() => false); + // Simulate onFxaDisabled() being called on window open. + gSync.onFxaDisabled(); updateTabContextMenu(testTab); is( diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_fxaccounts.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_fxaccounts.js index 30b44a844506..78726470420d 100644 --- a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_fxaccounts.js +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_fxaccounts.js @@ -4,7 +4,7 @@ "use strict"; add_task(async function test_policy_disable_fxaccounts() { - is(gSync.SYNC_ENABLED, true, "Sync is enabled before setting the policy."); + is(gSync.FXA_ENABLED, true, "Sync is enabled before setting the policy."); await setupPolicyEngineWithJson({ policies: { @@ -12,5 +12,5 @@ add_task(async function test_policy_disable_fxaccounts() { }, }); - is(gSync.SYNC_ENABLED, false, "Sync is disabled after setting the policy."); + is(gSync.FXA_ENABLED, false, "Sync is disabled after setting the policy."); });