From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../browser_aboutPrefs_backgroundUpdateSetting.js | 172 +++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 toolkit/mozapps/update/tests/browser/browser_aboutPrefs_backgroundUpdateSetting.js (limited to 'toolkit/mozapps/update/tests/browser/browser_aboutPrefs_backgroundUpdateSetting.js') diff --git a/toolkit/mozapps/update/tests/browser/browser_aboutPrefs_backgroundUpdateSetting.js b/toolkit/mozapps/update/tests/browser/browser_aboutPrefs_backgroundUpdateSetting.js new file mode 100644 index 0000000000..88afa8fdbe --- /dev/null +++ b/toolkit/mozapps/update/tests/browser/browser_aboutPrefs_backgroundUpdateSetting.js @@ -0,0 +1,172 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +"use strict"; + +/** + * This file tests the background update UI in about:preferences. + */ + +ChromeUtils.defineESModuleGetters(this, { + UpdateUtils: "resource://gre/modules/UpdateUtils.sys.mjs", +}); + +const BACKGROUND_UPDATE_PREF = "app.update.background.enabled"; + +add_task(async function testBackgroundUpdateSettingUI() { + if (!AppConstants.MOZ_UPDATE_AGENT) { + // The element that we are testing in about:preferences is #ifdef'ed out of + // the file if MOZ_UPDATE_AGENT isn't defined. So there is nothing to + // test in that case. + logTestInfo( + ` +=============================================================================== +WARNING! This test involves background update, but background tasks are + disabled. This test will unconditionally pass since the feature it + wants to test isn't available. +=============================================================================== +` + ); + // Some of our testing environments do not consider a test to have passed if + // it didn't make any assertions. + ok(true, "Unconditionally passing test"); + return; + } + + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "about:preferences" + ); + + const originalBackgroundUpdateVal = await UpdateUtils.readUpdateConfigSetting( + BACKGROUND_UPDATE_PREF + ); + const originalUpdateAutoVal = await UpdateUtils.getAppUpdateAutoEnabled(); + registerCleanupFunction(async () => { + await BrowserTestUtils.removeTab(tab); + await UpdateUtils.writeUpdateConfigSetting( + BACKGROUND_UPDATE_PREF, + originalBackgroundUpdateVal + ); + await UpdateUtils.setAppUpdateAutoEnabled(originalUpdateAutoVal); + }); + + // If auto update is disabled, the control for background update should be + // disabled, since we cannot update in the background if we can't update + // automatically. + await UpdateUtils.setAppUpdateAutoEnabled(false); + await SpecialPowers.spawn( + tab.linkedBrowser, + [UpdateUtils.PER_INSTALLATION_PREFS_SUPPORTED], + async perInstallationPrefsSupported => { + let backgroundUpdateCheckbox = + content.document.getElementById("backgroundUpdate"); + is( + backgroundUpdateCheckbox.hidden, + !perInstallationPrefsSupported, + `The background update UI should ${ + perInstallationPrefsSupported ? "not" : "" + } be hidden when and perInstallationPrefsSupported is ` + + `${perInstallationPrefsSupported}` + ); + if (perInstallationPrefsSupported) { + is( + backgroundUpdateCheckbox.disabled, + true, + `The background update UI should be disabled when auto update is ` + + `disabled` + ); + } + } + ); + + if (!UpdateUtils.PER_INSTALLATION_PREFS_SUPPORTED) { + // The remaining tests only make sense on platforms where per-installation + // prefs are supported and the UI will ever actually be displayed + return; + } + + await UpdateUtils.setAppUpdateAutoEnabled(true); + await UpdateUtils.writeUpdateConfigSetting(BACKGROUND_UPDATE_PREF, true); + + await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { + let backgroundUpdateCheckbox = + content.document.getElementById("backgroundUpdate"); + is( + backgroundUpdateCheckbox.disabled, + false, + `The background update UI should not be disabled when auto update is ` + + `enabled` + ); + + is( + backgroundUpdateCheckbox.checked, + true, + "After enabling background update, the checkbox should be checked" + ); + + // Note that this action results in asynchronous activity. Normally when + // we change the update config, we await on the function to wait for the + // value to be written to the disk. We can't easily await on the UI state + // though. Luckily, we don't have to because reads/writes of the config file + // are serialized. So when we verify the written value by awaiting on + // readUpdateConfigSetting(), that will also wait for the value to be + // written to disk and for this UI to react to that. + backgroundUpdateCheckbox.click(); + }); + + is( + await UpdateUtils.readUpdateConfigSetting(BACKGROUND_UPDATE_PREF), + false, + "Toggling the checkbox should have changed the setting value to false" + ); + + await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { + let backgroundUpdateCheckbox = + content.document.getElementById("backgroundUpdate"); + is( + backgroundUpdateCheckbox.checked, + false, + "After toggling the checked checkbox, it should be unchecked." + ); + + // Like the last call like this one, this initiates asynchronous behavior. + backgroundUpdateCheckbox.click(); + }); + + is( + await UpdateUtils.readUpdateConfigSetting(BACKGROUND_UPDATE_PREF), + true, + "Toggling the checkbox should have changed the setting value to true" + ); + + await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { + is( + content.document.getElementById("backgroundUpdate").checked, + true, + "After toggling the unchecked checkbox, it should be checked" + ); + }); + + // Test that the UI reacts to observed setting changes properly. + await UpdateUtils.writeUpdateConfigSetting(BACKGROUND_UPDATE_PREF, false); + + await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { + is( + content.document.getElementById("backgroundUpdate").checked, + false, + "Externally disabling background update should uncheck the checkbox" + ); + }); + + await UpdateUtils.writeUpdateConfigSetting(BACKGROUND_UPDATE_PREF, true); + + await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { + is( + content.document.getElementById("backgroundUpdate").checked, + true, + "Externally enabling background update should check the checkbox" + ); + }); +}); -- cgit v1.2.3