Bug 1998886 - Add a method to change visibility based on prefs for about:preferences. r=hjones,cdupuis
Differential Revision: https://phabricator.services.mozilla.com/D271824
This commit is contained in:
committed by
hsohaney@mozilla.com
parent
4fa4e83399
commit
5146d651fb
@@ -50,6 +50,8 @@ export default class BackupSettings extends MozLitElement {
|
||||
static get queries() {
|
||||
return {
|
||||
scheduledBackupsButtonEl: "#backup-toggle-scheduled-button",
|
||||
archiveSectionEl: "#scheduled-backups",
|
||||
restoreSectionEl: "#restore-from-backup",
|
||||
triggerBackupButtonEl: "#backup-trigger-button",
|
||||
changePasswordButtonEl: "#backup-change-password-button",
|
||||
disableBackupEncryptionEl: "disable-backup-encryption",
|
||||
|
||||
@@ -25,29 +25,13 @@ add_setup(async () => {
|
||||
add_task(async function test_preferences_visibility() {
|
||||
await BrowserTestUtils.withNewTab("about:preferences#sync", async browser => {
|
||||
const sandbox = sinon.createSandbox();
|
||||
let backupSection =
|
||||
browser.contentDocument.querySelector("#dataBackupSection");
|
||||
let syncPane = gBrowser.contentWindow.gSyncPane;
|
||||
let settings = browser.contentDocument.querySelector("backup-settings");
|
||||
|
||||
const spy = sandbox.spy(syncPane, "updateBackupUIVisibility");
|
||||
Services.obs.addObserver(
|
||||
syncPane.updateBackupUIVisibility,
|
||||
"backup-service-status-updated"
|
||||
);
|
||||
|
||||
Assert.ok(backupSection, "Found backup preferences section");
|
||||
|
||||
const waitForCall = () =>
|
||||
BrowserTestUtils.waitForCondition(
|
||||
() => spy.callCount >= 1,
|
||||
`Waiting for updateBackupUIVisibility() to be called 1 time`
|
||||
);
|
||||
|
||||
// Our mochitest-browser tests are configured to have the section visible
|
||||
// by default.
|
||||
Assert.ok(
|
||||
BrowserTestUtils.isVisible(backupSection),
|
||||
BrowserTestUtils.isVisible(settings.restoreSectionEl) &&
|
||||
BrowserTestUtils.isVisible(settings.archiveSectionEl),
|
||||
"Backup section is visible"
|
||||
);
|
||||
|
||||
@@ -55,20 +39,17 @@ add_task(async function test_preferences_visibility() {
|
||||
set: [["privacy.sanitize.sanitizeOnShutdown", true]],
|
||||
});
|
||||
|
||||
await waitForCall();
|
||||
|
||||
Assert.ok(
|
||||
BrowserTestUtils.isHidden(backupSection),
|
||||
"Backup section is not available"
|
||||
!settings.restoreSectionEl && !settings.archiveSectionEl,
|
||||
"Backup section is not available when sanitizeOnShutdown is enabled"
|
||||
);
|
||||
|
||||
await SpecialPowers.popPrefEnv();
|
||||
|
||||
await waitForCall();
|
||||
|
||||
Assert.ok(
|
||||
BrowserTestUtils.isVisible(backupSection),
|
||||
"Backup section is visible"
|
||||
BrowserTestUtils.isVisible(settings.restoreSectionEl) &&
|
||||
BrowserTestUtils.isVisible(settings.archiveSectionEl),
|
||||
"Backup section is visible now"
|
||||
);
|
||||
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
@@ -76,42 +57,23 @@ add_task(async function test_preferences_visibility() {
|
||||
});
|
||||
|
||||
Assert.ok(
|
||||
BrowserTestUtils.isVisible(backupSection),
|
||||
"Backup section is now visible"
|
||||
);
|
||||
|
||||
let backupArchiveSection = settings.querySelector("#scheduled-backups");
|
||||
|
||||
Assert.ok(!backupArchiveSection, "Backup archive section is not available");
|
||||
|
||||
Assert.ok(
|
||||
settings.restoreFromBackupEl,
|
||||
"Backup restore section is available"
|
||||
BrowserTestUtils.isVisible(settings.restoreSectionEl) &&
|
||||
!settings.archiveSectionEl,
|
||||
"Backup section is still visible since restore is enabled"
|
||||
);
|
||||
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [[BACKUP_RESTORE_ENABLED_PREF, false]],
|
||||
});
|
||||
|
||||
await settings.updateComplete;
|
||||
|
||||
Assert.ok(
|
||||
BrowserTestUtils.isHidden(backupSection),
|
||||
"Backup section is not available"
|
||||
);
|
||||
|
||||
Assert.ok(
|
||||
!settings.restoreFromBackupEl,
|
||||
"Backup Restore section is not available"
|
||||
!settings.restoreSectionEl && !settings.archiveSectionEl,
|
||||
"Backup section is not available anymore after both archive and restore are disabled"
|
||||
);
|
||||
|
||||
await SpecialPowers.popPrefEnv();
|
||||
await SpecialPowers.popPrefEnv();
|
||||
|
||||
Services.obs.removeObserver(
|
||||
syncPane.updateBackupUIVisibility,
|
||||
"backup-service-status-updated"
|
||||
);
|
||||
sandbox.restore();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -442,6 +442,14 @@ async function gotoPref(
|
||||
spotlight(subcategory, category);
|
||||
}
|
||||
|
||||
// Handle any visibility changes that are controlled by pref logic.
|
||||
//
|
||||
// Take caution when trying to flip the hidden state to true since the
|
||||
// element might show up unexpectedly on different pages in about:preferences.
|
||||
//
|
||||
// See Bug 1999032 to remove this in favor of config-based prefs.
|
||||
categoryModule.handlePrefControlledSection?.();
|
||||
|
||||
// Record which category is shown
|
||||
Glean.aboutpreferences["show" + aShowReason].record({ value: category });
|
||||
|
||||
|
||||
@@ -246,21 +246,20 @@
|
||||
</vbox>
|
||||
</deck>
|
||||
<!-- Firefox Backup -->
|
||||
<vbox id="dataBackupSection" data-category="paneSync" data-hidden-from-search="true">
|
||||
<hbox id="backupCategory"
|
||||
class="subcategory"
|
||||
hidden="true"
|
||||
data-category="paneSync"
|
||||
>
|
||||
<html:h1 data-l10n-id="settings-data-backup-header"/>
|
||||
<hbox id="backupCategory"
|
||||
class="subcategory"
|
||||
hidden="true"
|
||||
data-category="paneSync"
|
||||
>
|
||||
<html:h1 data-l10n-id="settings-data-backup-header"/>
|
||||
</hbox>
|
||||
<groupbox id="dataBackupGroup"
|
||||
data-category="paneSync"
|
||||
data-subcategory="backup"
|
||||
hidden="true">
|
||||
<label class="search-header" hidden="true"><html:h2 data-l10n-id="settings-data-backup-header"/></label>
|
||||
<hbox flex="1">
|
||||
<html:backup-settings />
|
||||
</hbox>
|
||||
<groupbox id="dataBackupGroup"
|
||||
data-subcategory="backup"
|
||||
hidden="true">
|
||||
<label class="search-header" hidden="true"><html:h2 data-l10n-id="settings-data-backup-header"/></label>
|
||||
<hbox flex="1">
|
||||
<html:backup-settings />
|
||||
</hbox>
|
||||
</groupbox>
|
||||
</vbox>
|
||||
</groupbox>
|
||||
</html:template>
|
||||
|
||||
@@ -44,8 +44,6 @@ var gSyncPane = {
|
||||
.getElementById("weavePrefsDeck")
|
||||
.removeAttribute("data-hidden-from-search");
|
||||
|
||||
this.updateBackupUIVisibility();
|
||||
|
||||
// If the Service hasn't finished initializing, wait for it.
|
||||
let xps = Cc["@mozilla.org/weave/service;1"].getService(
|
||||
Ci.nsISupports
|
||||
@@ -56,8 +54,6 @@ var gSyncPane = {
|
||||
return;
|
||||
}
|
||||
|
||||
this._addPrefObservers();
|
||||
|
||||
// it may take some time before all the promises we care about resolve, so
|
||||
// pre-load what we can from synchronous sources.
|
||||
this._showLoadPage(xps);
|
||||
@@ -81,6 +77,26 @@ var gSyncPane = {
|
||||
xps.ensureLoaded();
|
||||
},
|
||||
|
||||
/**
|
||||
* This method allows us to override any hidden states that were set
|
||||
* during preferences.js init(). Currently, this is used to hide the
|
||||
* backup section if backup is disabled.
|
||||
*
|
||||
* Take caution when trying to flip the hidden state to true since the
|
||||
* element might show up unexpectedly on different pages in about:preferences
|
||||
* since this function will run at the end of preferences.js init().
|
||||
*
|
||||
* See Bug 1999032 to remove this in favor of config-based prefs.
|
||||
*/
|
||||
handlePrefControlledSection() {
|
||||
let bs = lazy.BackupService.init();
|
||||
|
||||
if (!bs.archiveEnabledStatus.enabled && !bs.restoreEnabledStatus.enabled) {
|
||||
document.getElementById("backupCategory").hidden = true;
|
||||
document.getElementById("dataBackupGroup").hidden = true;
|
||||
}
|
||||
},
|
||||
|
||||
_showLoadPage() {
|
||||
let maybeAcct = false;
|
||||
let username = Services.prefs.getCharPref("services.sync.username", "");
|
||||
@@ -297,44 +313,6 @@ var gSyncPane = {
|
||||
}
|
||||
},
|
||||
|
||||
updateBackupUIVisibility() {
|
||||
let bs = lazy.BackupService.get();
|
||||
let isBackupUIEnabled =
|
||||
bs.archiveEnabledStatus.enabled || bs.restoreEnabledStatus.enabled;
|
||||
|
||||
let dataBackupSectionEl = document.getElementById("dataBackupSection");
|
||||
|
||||
dataBackupSectionEl.toggleAttribute(
|
||||
"data-hidden-from-search",
|
||||
!isBackupUIEnabled
|
||||
);
|
||||
|
||||
let dataBackupGroupEl = document.getElementById("dataBackupGroup");
|
||||
let backupGroupHeaderEl = document.getElementById("backupCategory");
|
||||
|
||||
dataBackupSectionEl.hidden = !isBackupUIEnabled;
|
||||
dataBackupGroupEl.hidden = !isBackupUIEnabled;
|
||||
backupGroupHeaderEl.hidden = !isBackupUIEnabled;
|
||||
},
|
||||
|
||||
_addPrefObservers() {
|
||||
Services.obs.addObserver(
|
||||
this.updateBackupUIVisibility,
|
||||
"backup-service-status-updated"
|
||||
);
|
||||
|
||||
window.addEventListener(
|
||||
"unload",
|
||||
() => {
|
||||
Services.obs.removeObserver(
|
||||
this.updateBackupUIVisibility,
|
||||
"backup-service-status-updated"
|
||||
);
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
},
|
||||
|
||||
async _chooseWhatToSync(isSyncConfigured, why = null) {
|
||||
// Record the user opening the choose what to sync menu.
|
||||
fxAccounts.telemetry.recordOpenCWTSMenu(why).catch(err => {
|
||||
|
||||
@@ -26,6 +26,8 @@ run-if = ["updater"]
|
||||
|
||||
["browser_applications_selection.js"]
|
||||
|
||||
["browser_backup_visibility.js"]
|
||||
|
||||
["browser_basic_rebuild_fonts_test.js"]
|
||||
|
||||
["browser_browser_languages_subdialog.js"]
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Test that we don't show the backup section if backup is disabled
|
||||
*/
|
||||
add_task(async function () {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.backup.archive.enabled", false]],
|
||||
});
|
||||
|
||||
await openPreferencesViaOpenPreferencesAPI("paneSync", {
|
||||
leaveOpen: true,
|
||||
});
|
||||
|
||||
ok(
|
||||
gBrowser.contentDocument.getElementById("backupCategory").hidden,
|
||||
"backup category hidden"
|
||||
);
|
||||
|
||||
ok(
|
||||
gBrowser.contentDocument.getElementById("dataBackupGroup").hidden,
|
||||
"backup section is hidden"
|
||||
);
|
||||
|
||||
// Check that we don't get any results in sync when searching:
|
||||
await evaluateSearchResults("backup", "no-results-message");
|
||||
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
|
||||
/**
|
||||
* Test that we don't show the backup section if backup is disabled
|
||||
*/
|
||||
add_task(async function () {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.backup.archive.enabled", true]],
|
||||
});
|
||||
|
||||
await openPreferencesViaOpenPreferencesAPI("paneSync", {
|
||||
leaveOpen: true,
|
||||
});
|
||||
|
||||
ok(
|
||||
!gBrowser.contentDocument.getElementById("backupCategory").hidden,
|
||||
"backup category shown"
|
||||
);
|
||||
|
||||
ok(
|
||||
!gBrowser.contentDocument.getElementById("dataBackupGroup").hidden,
|
||||
"backup section is shown"
|
||||
);
|
||||
|
||||
// Check that we don't get any results in sync when searching:
|
||||
await evaluateSearchResults("backup", "dataBackupGroup");
|
||||
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
@@ -69,7 +69,10 @@ function checkElements(expectedPane) {
|
||||
}
|
||||
|
||||
// Backup is currently disabled by default. (bug 1895791)
|
||||
if (element.id == "dataBackupSection" && backupSectionDisabled) {
|
||||
if (
|
||||
(element.id == "dataBackupGroup" || element.id == "backupCategory") &&
|
||||
backupSectionDisabled
|
||||
) {
|
||||
is_element_hidden(element, "Disabled dataBackupSection should be hidden");
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user