tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 629031f7bd2c1e2db9e450d2fb69ea3b5e553a35
parent 79b1d440a6badab0b69de5166d7a0d7d0232d24b
Author: Sammy Khamis <skhamis@mozilla.com>
Date:   Thu,  4 Dec 2025 09:49:30 +0000

Bug 2003898 - Dont show connect another device button if no sync keys r=sync-reviewers,LougeniaBailey,markh

Differential Revision: https://phabricator.services.mozilla.com/D274987

Diffstat:
Mbrowser/base/content/browser-sync.js | 15+++++++++++++--
Mbrowser/base/content/test/sync/browser_sync.js | 2++
Mservices/sync/modules/UIState.sys.mjs | 5+++++
Mservices/sync/tests/unit/test_uistate.js | 17++++++++++++++++-
4 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/browser/base/content/browser-sync.js b/browser/base/content/browser-sync.js @@ -1195,10 +1195,14 @@ var gSync = { document, "PanelUI-fxa-menu-setup-sync-container" ); - const fxaToolbarMenuButton = document.getElementById( "fxa-toolbar-menu-button" ); + const syncSetupSeparator = PanelMultiView.getViewNode( + document, + "PanelUI-set-up-sync-separator" + ); + let fxaAvatarLabelEl = document.getElementById("fxa-avatar-label"); // Reset FxA/Sync UI elements to default, which is signed out @@ -1311,10 +1315,17 @@ var gSync = { if (this._shouldShowSyncOffIndicator()) { fxaToolbarMenuButton?.setAttribute("badge-status", "sync-disabled"); } - // Show the sync element depending on if the user is enrolled or not syncSetupEl.removeAttribute("hidden"); } + if (state.hasSyncKeys) { + cadButtonEl.removeAttribute("hidden"); + syncSetupSeparator.removeAttribute("hidden"); + } else { + cadButtonEl.setAttribute("hidden", "true"); + syncSetupSeparator.setAttribute("hidden", "true"); + } + // Reposition profiles elements emptyProfilesButton.remove(); profilesButton.remove(); diff --git a/browser/base/content/test/sync/browser_sync.js b/browser/base/content/test/sync/browser_sync.js @@ -790,6 +790,7 @@ add_task(async function test_new_sync_setup_ui() { let state = { status: UIState.STATUS_SIGNED_IN, syncEnabled: false, + hasSyncKeys: true, email: "foo@bar.com", displayName: "Foo Bar", avatarURL: "https://foo.bar", @@ -839,6 +840,7 @@ add_task(async function test_ui_my_services_signedin() { let state = { status: UIState.STATUS_SIGNED_IN, syncEnabled: true, + hasSyncKeys: true, email: "foo@bar.com", displayName: "Foo Bar", avatarURL: "https://foo.bar", diff --git a/services/sync/modules/UIState.sys.mjs b/services/sync/modules/UIState.sys.mjs @@ -10,8 +10,11 @@ * @property {string} [avatarURL] The user's FxA avatar URL. * @property {Date} [lastSync] The last sync time. * @property {boolean} [syncing] Whether or not we are currently syncing. + * @property {boolean} [hasSyncKeys] Whether the user has sync keys available. */ +import { SCOPE_APP_SYNC } from "resource://gre/modules/FxAccountsCommon.sys.mjs"; + const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { LOGIN_FAILED_LOGIN_REJECTED: "resource://services-sync/constants.sys.mjs", @@ -173,6 +176,8 @@ const UIStateInternal = { state.avatarURL = userData.avatar; state.avatarIsDefault = userData.avatarDefault; state.syncEnabled = !!syncUserName; + state.hasSyncKeys = + await this.fxAccounts.keys.hasKeysForScope(SCOPE_APP_SYNC); } state.status = status; }, diff --git a/services/sync/tests/unit/test_uistate.js b/services/sync/tests/unit/test_uistate.js @@ -74,6 +74,7 @@ add_task(async function test_refreshState_signedin() { hasLocalSession: () => Promise.resolve(true), keys: { canGetKeyForScope: () => Promise.resolve(true), + hasKeysForScope: () => Promise.resolve(true), }, }; @@ -86,6 +87,7 @@ add_task(async function test_refreshState_signedin() { equal(state.avatarURL, "https://foo/bar"); equal(state.lastSync, now); equal(state.syncing, false); + equal(state.hasSyncKeys, true); UIStateInternal.fxAccounts = fxAccountsOrig; Services.prefs.clearUserPref("services.sync.username"); @@ -134,6 +136,7 @@ add_task(async function test_refreshState_signedin_profile_unavailable() { hasLocalSession: () => Promise.resolve(true), keys: { canGetKeyForScope: () => Promise.resolve(true), + hasKeysForScope: () => Promise.resolve(true), }, _internal: { profile: { @@ -167,6 +170,9 @@ add_task(async function test_refreshState_unverified() { getSignedInUser: () => Promise.resolve({ verified: false, uid: "123", email: "foo@bar.com" }), hasLocalSession: () => Promise.resolve(true), + keys: { + hasKeysForScope: () => Promise.resolve(true), + }, }; let state = await UIState.refresh(); @@ -189,6 +195,9 @@ add_task(async function test_refreshState_unverified_nosession() { getSignedInUser: () => Promise.resolve({ verified: false, uid: "123", email: "foo@bar.com" }), hasLocalSession: () => Promise.resolve(false), + keys: { + hasKeysForScope: () => Promise.resolve(true), + }, }; let state = await UIState.refresh(); @@ -216,6 +225,7 @@ add_task(async function test_refreshState_loginFailed() { Promise.resolve({ verified: true, uid: "123", email: "foo@bar.com" }), keys: { canGetKeyForScope: () => Promise.resolve(true), + hasKeysForScope: () => Promise.resolve(true), }, }; @@ -271,6 +281,7 @@ async function configureUIState(syncing, lastSync = new Date()) { hasLocalSession: () => Promise.resolve(true), keys: { canGetKeyForScope: () => Promise.resolve(true), + hasKeysForScope: () => Promise.resolve(true), }, }; await UIState.refresh(); @@ -343,6 +354,7 @@ add_task(async function test_refreshState_signedin_with_synckeys() { hasLocalSession: () => Promise.resolve(true), keys: { canGetKeyForScope: () => Promise.resolve(true), + hasKeysForScope: () => Promise.resolve(true), }, }; @@ -371,13 +383,16 @@ add_task(async function test_refreshState_third_party_auth_no_sync() { email: "foo@bar.com", }), hasLocalSession: () => Promise.resolve(true), - keys: {}, + keys: { + hasKeysForScope: () => Promise.resolve(false), + }, }; let state = await UIState.refresh(); equal(state.status, UIState.STATUS_SIGNED_IN); equal(state.syncEnabled, false); + equal(state.hasSyncKeys, false); equal(state.uid, "123"); equal(state.email, "foo@bar.com");