Bug 1861400 - Remove sync if disabled by policy r=fxview-reviewers,nsharpley,kcochrane
Brings the Firefox View behavior in line with what is done in `browser-sync.js`. Differential Revision: https://phabricator.services.mozilla.com/D205881
This commit is contained in:
@@ -72,6 +72,7 @@
|
||||
>
|
||||
</moz-page-nav-button>
|
||||
<moz-page-nav-button
|
||||
class="sync-ui-item"
|
||||
view="syncedtabs"
|
||||
data-l10n-id="firefoxview-synced-tabs-nav"
|
||||
iconSrc="chrome://browser/content/firefoxview/view-syncedtabs.svg"
|
||||
@@ -95,7 +96,10 @@
|
||||
<view-recentlyclosed slot="recentlyclosed"></view-recentlyclosed>
|
||||
</div>
|
||||
<div>
|
||||
<view-syncedtabs slot="syncedtabs"></view-syncedtabs>
|
||||
<view-syncedtabs
|
||||
class="sync-ui-item"
|
||||
slot="syncedtabs"
|
||||
></view-syncedtabs>
|
||||
</div>
|
||||
</view-recentbrowsing>
|
||||
<view-history name="history" type="page"></view-history>
|
||||
@@ -104,7 +108,11 @@
|
||||
name="recentlyclosed"
|
||||
type="page"
|
||||
></view-recentlyclosed>
|
||||
<view-syncedtabs name="syncedtabs" type="page"></view-syncedtabs>
|
||||
<view-syncedtabs
|
||||
class="sync-ui-item"
|
||||
name="syncedtabs"
|
||||
type="page"
|
||||
></view-syncedtabs>
|
||||
</named-deck>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -80,6 +80,16 @@ async function updateSearchKeyboardShortcut() {
|
||||
searchKeyboardShortcut = key.toLocaleLowerCase();
|
||||
}
|
||||
|
||||
function updateSyncVisibility() {
|
||||
const syncEnabled = Services.prefs.getBoolPref(
|
||||
"identity.fxaccounts.enabled",
|
||||
false
|
||||
);
|
||||
for (const el of document.querySelectorAll(".sync-ui-item")) {
|
||||
el.hidden = !syncEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("DOMContentLoaded", async () => {
|
||||
recordEnteredTelemetry();
|
||||
|
||||
@@ -106,6 +116,7 @@ window.addEventListener("DOMContentLoaded", async () => {
|
||||
onViewsDeckViewChange();
|
||||
await updateSearchTextboxSize();
|
||||
await updateSearchKeyboardShortcut();
|
||||
updateSyncVisibility();
|
||||
|
||||
if (Cu.isInAutomation) {
|
||||
Services.obs.notifyObservers(null, "firefoxview-entered");
|
||||
@@ -150,12 +161,17 @@ window.addEventListener(
|
||||
document.body.textContent = "";
|
||||
topChromeWindow.removeEventListener("command", onCommand);
|
||||
Services.obs.removeObserver(onLocalesChanged, "intl:app-locales-changed");
|
||||
Services.prefs.removeObserver(
|
||||
"identity.fxaccounts.enabled",
|
||||
updateSyncVisibility
|
||||
);
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
|
||||
topChromeWindow.addEventListener("command", onCommand);
|
||||
Services.obs.addObserver(onLocalesChanged, "intl:app-locales-changed");
|
||||
Services.prefs.addObserver("identity.fxaccounts.enabled", updateSyncVisibility);
|
||||
|
||||
function onCommand(e) {
|
||||
if (document.hidden || !e.target.closest("#contentAreaContextMenu")) {
|
||||
|
||||
@@ -139,3 +139,36 @@ add_task(async function test_sync_error() {
|
||||
});
|
||||
await tearDown(sandbox);
|
||||
});
|
||||
|
||||
add_task(async function test_sync_disabled_by_policy() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["identity.fxaccounts.enabled", false]],
|
||||
});
|
||||
await withFirefoxView({}, async browser => {
|
||||
const { document } = browser.contentWindow;
|
||||
const recentBrowsingSyncedTabs = document.querySelector(
|
||||
"view-syncedtabs[slot=syncedtabs]"
|
||||
);
|
||||
const syncedtabsPageNavButton = document.querySelector(
|
||||
"moz-page-nav-button[view='syncedtabs']"
|
||||
);
|
||||
|
||||
ok(
|
||||
BrowserTestUtils.isHidden(recentBrowsingSyncedTabs),
|
||||
"Synced tabs should not be visible from recent browsing."
|
||||
);
|
||||
ok(
|
||||
BrowserTestUtils.isHidden(syncedtabsPageNavButton),
|
||||
"Synced tabs nav button should not be visible."
|
||||
);
|
||||
|
||||
document.location.assign(`${getFirefoxViewURL()}#syncedtabs`);
|
||||
await TestUtils.waitForTick();
|
||||
is(
|
||||
document.querySelector("moz-page-nav").currentView,
|
||||
"recentbrowsing",
|
||||
"Should not be able to navigate to synced tabs."
|
||||
);
|
||||
});
|
||||
await tearDown();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user