Skip to content

Commit 8edaac3

Browse files
committed
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
1 parent b7a062c commit 8edaac3

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

browser/base/content/browser-sync.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,10 +1195,14 @@ var gSync = {
11951195
document,
11961196
"PanelUI-fxa-menu-setup-sync-container"
11971197
);
1198-
11991198
const fxaToolbarMenuButton = document.getElementById(
12001199
"fxa-toolbar-menu-button"
12011200
);
1201+
const syncSetupSeparator = PanelMultiView.getViewNode(
1202+
document,
1203+
"PanelUI-set-up-sync-separator"
1204+
);
1205+
12021206
let fxaAvatarLabelEl = document.getElementById("fxa-avatar-label");
12031207

12041208
// Reset FxA/Sync UI elements to default, which is signed out
@@ -1311,10 +1315,17 @@ var gSync = {
13111315
if (this._shouldShowSyncOffIndicator()) {
13121316
fxaToolbarMenuButton?.setAttribute("badge-status", "sync-disabled");
13131317
}
1314-
// Show the sync element depending on if the user is enrolled or not
13151318
syncSetupEl.removeAttribute("hidden");
13161319
}
13171320

1321+
if (state.hasSyncKeys) {
1322+
cadButtonEl.removeAttribute("hidden");
1323+
syncSetupSeparator.removeAttribute("hidden");
1324+
} else {
1325+
cadButtonEl.setAttribute("hidden", "true");
1326+
syncSetupSeparator.setAttribute("hidden", "true");
1327+
}
1328+
13181329
// Reposition profiles elements
13191330
emptyProfilesButton.remove();
13201331
profilesButton.remove();

browser/base/content/test/sync/browser_sync.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ add_task(async function test_new_sync_setup_ui() {
790790
let state = {
791791
status: UIState.STATUS_SIGNED_IN,
792792
syncEnabled: false,
793+
hasSyncKeys: true,
793794
email: "foo@bar.com",
794795
displayName: "Foo Bar",
795796
avatarURL: "https://foo.bar",
@@ -839,6 +840,7 @@ add_task(async function test_ui_my_services_signedin() {
839840
let state = {
840841
status: UIState.STATUS_SIGNED_IN,
841842
syncEnabled: true,
843+
hasSyncKeys: true,
842844
email: "foo@bar.com",
843845
displayName: "Foo Bar",
844846
avatarURL: "https://foo.bar",

services/sync/modules/UIState.sys.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
* @property {string} [avatarURL] The user's FxA avatar URL.
1111
* @property {Date} [lastSync] The last sync time.
1212
* @property {boolean} [syncing] Whether or not we are currently syncing.
13+
* @property {boolean} [hasSyncKeys] Whether the user has sync keys available.
1314
*/
1415

16+
import { SCOPE_APP_SYNC } from "resource://gre/modules/FxAccountsCommon.sys.mjs";
17+
1518
const lazy = {};
1619
ChromeUtils.defineESModuleGetters(lazy, {
1720
LOGIN_FAILED_LOGIN_REJECTED: "resource://services-sync/constants.sys.mjs",
@@ -173,6 +176,8 @@ const UIStateInternal = {
173176
state.avatarURL = userData.avatar;
174177
state.avatarIsDefault = userData.avatarDefault;
175178
state.syncEnabled = !!syncUserName;
179+
state.hasSyncKeys =
180+
await this.fxAccounts.keys.hasKeysForScope(SCOPE_APP_SYNC);
176181
}
177182
state.status = status;
178183
},

services/sync/tests/unit/test_uistate.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ add_task(async function test_refreshState_signedin() {
7474
hasLocalSession: () => Promise.resolve(true),
7575
keys: {
7676
canGetKeyForScope: () => Promise.resolve(true),
77+
hasKeysForScope: () => Promise.resolve(true),
7778
},
7879
};
7980

@@ -86,6 +87,7 @@ add_task(async function test_refreshState_signedin() {
8687
equal(state.avatarURL, "https://foo/bar");
8788
equal(state.lastSync, now);
8889
equal(state.syncing, false);
90+
equal(state.hasSyncKeys, true);
8991

9092
UIStateInternal.fxAccounts = fxAccountsOrig;
9193
Services.prefs.clearUserPref("services.sync.username");
@@ -134,6 +136,7 @@ add_task(async function test_refreshState_signedin_profile_unavailable() {
134136
hasLocalSession: () => Promise.resolve(true),
135137
keys: {
136138
canGetKeyForScope: () => Promise.resolve(true),
139+
hasKeysForScope: () => Promise.resolve(true),
137140
},
138141
_internal: {
139142
profile: {
@@ -216,6 +219,7 @@ add_task(async function test_refreshState_loginFailed() {
216219
Promise.resolve({ verified: true, uid: "123", email: "foo@bar.com" }),
217220
keys: {
218221
canGetKeyForScope: () => Promise.resolve(true),
222+
hasKeysForScope: () => Promise.resolve(true),
219223
},
220224
};
221225

@@ -271,6 +275,7 @@ async function configureUIState(syncing, lastSync = new Date()) {
271275
hasLocalSession: () => Promise.resolve(true),
272276
keys: {
273277
canGetKeyForScope: () => Promise.resolve(true),
278+
hasKeysForScope: () => Promise.resolve(true),
274279
},
275280
};
276281
await UIState.refresh();
@@ -343,6 +348,7 @@ add_task(async function test_refreshState_signedin_with_synckeys() {
343348
hasLocalSession: () => Promise.resolve(true),
344349
keys: {
345350
canGetKeyForScope: () => Promise.resolve(true),
351+
hasKeysForScope: () => Promise.resolve(true),
346352
},
347353
};
348354

@@ -371,13 +377,16 @@ add_task(async function test_refreshState_third_party_auth_no_sync() {
371377
email: "foo@bar.com",
372378
}),
373379
hasLocalSession: () => Promise.resolve(true),
374-
keys: {},
380+
keys: {
381+
hasKeysForScope: () => Promise.resolve(false),
382+
},
375383
};
376384

377385
let state = await UIState.refresh();
378386

379387
equal(state.status, UIState.STATUS_SIGNED_IN);
380388
equal(state.syncEnabled, false);
389+
equal(state.hasSyncKeys, false);
381390
equal(state.uid, "123");
382391
equal(state.email, "foo@bar.com");
383392

0 commit comments

Comments
 (0)