зеркало из https://github.com/mozilla/gecko-dev.git
Bug 336267 - When disabling automatic updating and there is an update in progress ask the user if they want to cancel the update. r=flod,bytesized
Differential Revision: https://phabricator.services.mozilla.com/D32424 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
0ba5a5ddda
Коммит
e0d117996b
|
@ -1361,6 +1361,13 @@ var gMainPane = {
|
|||
Cu.reportError(error);
|
||||
await this.updateReadPrefs();
|
||||
await this.reportUpdatePrefWriteError(error);
|
||||
return;
|
||||
}
|
||||
|
||||
// If the value was changed to false the user should be given the option
|
||||
// to discard an update if there is one.
|
||||
if (!updateAutoValue) {
|
||||
await this.checkUpdateInProgress();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -1378,6 +1385,40 @@ var gMainPane = {
|
|||
null, null, null, null, {});
|
||||
},
|
||||
|
||||
async checkUpdateInProgress() {
|
||||
let um = Cc["@mozilla.org/updates/update-manager;1"].
|
||||
getService(Ci.nsIUpdateManager);
|
||||
if (!um.activeUpdate) {
|
||||
return;
|
||||
}
|
||||
|
||||
let [
|
||||
title, message, okButton, cancelButton,
|
||||
] = await document.l10n.formatValues([
|
||||
{id: "update-in-progress-title"},
|
||||
{id: "update-in-progress-message"},
|
||||
{id: "update-in-progress-ok-button"},
|
||||
{id: "update-in-progress-cancel-button"},
|
||||
]);
|
||||
|
||||
// Continue is the cancel button which is BUTTON_POS_1 and is set as the
|
||||
// default so pressing escape or using a platform standard method of closing
|
||||
// the UI will not discard the update.
|
||||
let buttonFlags =
|
||||
(Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_0) +
|
||||
(Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_1) +
|
||||
Ci.nsIPrompt.BUTTON_POS_1_DEFAULT;
|
||||
|
||||
let rv = Services.prompt.confirmEx(window, title, message, buttonFlags,
|
||||
okButton, cancelButton, null, null, {});
|
||||
if (rv != 1) {
|
||||
let aus = Cc["@mozilla.org/updates/update-service;1"].
|
||||
getService(Ci.nsIApplicationUpdateService);
|
||||
aus.stopDownload();
|
||||
um.cleanupActiveUpdate();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Displays the history of installed updates.
|
||||
*/
|
||||
|
|
|
@ -366,6 +366,15 @@ update-pref-write-failure-title = Write Failure
|
|||
# $path (String) - Path to the configuration file
|
||||
update-pref-write-failure-message = Unable to save preference. Could not write to file: { $path }
|
||||
|
||||
update-in-progress-title = Update In Progress
|
||||
|
||||
update-in-progress-message = Do you want { -brand-short-name } to continue with this update?
|
||||
|
||||
update-in-progress-ok-button = &Discard
|
||||
# Continue is the cancel button so pressing escape or using a platform standard
|
||||
# method of closing the UI will not discard the update.
|
||||
update-in-progress-cancel-button = &Continue
|
||||
|
||||
## General Section - Performance
|
||||
|
||||
performance-title = Performance
|
||||
|
|
|
@ -61,8 +61,6 @@ skip-if = os != 'win'
|
|||
reason = Windows only feature.
|
||||
[browser_aboutPrefs_fc_check_unsupported.js]
|
||||
[browser_aboutPrefs_settings.js]
|
||||
skip-if = os != 'win'
|
||||
reason = Tests that update config is properly written to file, which is a Windows-only feature
|
||||
|
||||
# Doorhanger Application Update Tests
|
||||
[browser_doorhanger_bc_check_cantApply.js]
|
||||
|
|
|
@ -14,7 +14,7 @@ async function changeAndVerifyPref(tab, newConfigValue) {
|
|||
radioElement.click();
|
||||
});
|
||||
|
||||
// At this point, we really need to wait for the change to finish being
|
||||
// On Windows, we really need to wait for the change to finish being
|
||||
// written to the disk before we go to verify anything. Unfortunately, it
|
||||
// would be difficult to check for quick changes to the attributes of the
|
||||
// about:preferences controls (to wait for the controls to be disabled and
|
||||
|
@ -22,17 +22,19 @@ async function changeAndVerifyPref(tab, newConfigValue) {
|
|||
// Application Update Service for the value of app.update.auto. It already
|
||||
// serializes reads and writes to the app update config file, so this will not
|
||||
// resolve until the file write is complete.
|
||||
|
||||
let configValueRead = await UpdateUtils.getAppUpdateAutoEnabled();
|
||||
is(configValueRead, newConfigValue,
|
||||
"Value returned should have matched the expected value");
|
||||
|
||||
let configFile = getUpdateDirFile(FILE_UPDATE_CONFIG_JSON);
|
||||
let decoder = new TextDecoder();
|
||||
let fileContents = await OS.File.read(configFile.path);
|
||||
let saveObject = JSON.parse(decoder.decode(fileContents));
|
||||
is(saveObject["app.update.auto"], newConfigValue,
|
||||
"Value in file should match expected");
|
||||
// Only Windows currently has the update configuration JSON file.
|
||||
if (AppConstants.platform == "win") {
|
||||
let configFile = getUpdateDirFile(FILE_UPDATE_CONFIG_JSON);
|
||||
let decoder = new TextDecoder();
|
||||
let fileContents = await OS.File.read(configFile.path);
|
||||
let saveObject = JSON.parse(decoder.decode(fileContents));
|
||||
is(saveObject["app.update.auto"], newConfigValue,
|
||||
"Value in file should match expected");
|
||||
}
|
||||
|
||||
await ContentTask.spawn(tab.linkedBrowser, {newConfigValue}, async function({newConfigValue}) {
|
||||
let updateRadioGroup = content.document.getElementById("updateRadioGroup");
|
||||
|
@ -45,9 +47,57 @@ add_task(async function testUpdateAutoPrefUI() {
|
|||
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:preferences");
|
||||
|
||||
await changeAndVerifyPref(tab, true);
|
||||
ok(!gUpdateManager.activeUpdate, "There should not be an active update");
|
||||
|
||||
await changeAndVerifyPref(tab, false);
|
||||
ok(!gUpdateManager.activeUpdate, "There should not be an active update");
|
||||
|
||||
let patchProps = {state: STATE_PENDING};
|
||||
let patches = getLocalPatchString(patchProps);
|
||||
let updateProps = {checkInterval: "1"};
|
||||
let updates = getLocalUpdateString(updateProps, patches);
|
||||
writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true);
|
||||
writeStatusFile(STATE_PENDING);
|
||||
reloadUpdateManagerData();
|
||||
ok(!!gUpdateManager.activeUpdate, "There should be an active update");
|
||||
|
||||
// A value of 0 will keep the update and a value of 1 will discard the update
|
||||
// when the prompt service is called when the value of app.update.auto is
|
||||
// changed to false.
|
||||
let discardUpdate = 0;
|
||||
let {prompt} = Services;
|
||||
let promptService = {
|
||||
QueryInterface: ChromeUtils.generateQI([Ci.nsIPromptService]),
|
||||
confirmEx(...args) {
|
||||
promptService._confirmExArgs = args;
|
||||
return discardUpdate;
|
||||
},
|
||||
};
|
||||
Services.prompt = promptService;
|
||||
registerCleanupFunction(() => {
|
||||
Services.prompt = prompt;
|
||||
});
|
||||
|
||||
// Setting the value to false will call the prompt service and with 1 for
|
||||
// discardUpdate the update won't be discarded so there should still be an
|
||||
// active update.
|
||||
discardUpdate = 1;
|
||||
await changeAndVerifyPref(tab, false);
|
||||
ok(!!gUpdateManager.activeUpdate, "There should be an active update");
|
||||
|
||||
// Setting the value to true should not call the prompt service so there
|
||||
// should still be an active update even with a value of 0 for
|
||||
// discardUpdate.
|
||||
discardUpdate = 0;
|
||||
await changeAndVerifyPref(tab, true);
|
||||
ok(!!gUpdateManager.activeUpdate, "There should be an active update");
|
||||
|
||||
// Setting the value to false will call the prompt service and with 0 for
|
||||
// discardUpdate the update should be discarded so there should not be an
|
||||
// active update.
|
||||
discardUpdate = 0;
|
||||
await changeAndVerifyPref(tab, false);
|
||||
ok(!gUpdateManager.activeUpdate, "There should not be an active update");
|
||||
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче