Bug 1783862: Update browser by update action if possible. r=daleharvey
Differential Revision: https://phabricator.services.mozilla.com/D155544
This commit is contained in:
@@ -14,14 +14,21 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
|||||||
"resource:///modules/UrlbarProviderQuickActions.sys.mjs",
|
"resource:///modules/UrlbarProviderQuickActions.sys.mjs",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { AppConstants } = ChromeUtils.import(
|
||||||
|
"resource://gre/modules/AppConstants.jsm"
|
||||||
|
);
|
||||||
|
|
||||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||||
|
AppUpdater: "resource:///modules/AppUpdater.jsm",
|
||||||
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
|
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
|
||||||
ClientEnvironment: "resource://normandy/lib/ClientEnvironment.jsm",
|
ClientEnvironment: "resource://normandy/lib/ClientEnvironment.jsm",
|
||||||
DevToolsShim: "chrome://devtools-startup/content/DevToolsShim.jsm",
|
DevToolsShim: "chrome://devtools-startup/content/DevToolsShim.jsm",
|
||||||
ResetProfile: "resource://gre/modules/ResetProfile.jsm",
|
ResetProfile: "resource://gre/modules/ResetProfile.jsm",
|
||||||
});
|
});
|
||||||
|
|
||||||
const BASE_URL = "https://support.mozilla.org/kb/";
|
XPCOMUtils.defineLazyGetter(lazy, "BrowserUpdater", () => {
|
||||||
|
return AppConstants.MOZ_UPDATER ? new lazy.AppUpdater() : null;
|
||||||
|
});
|
||||||
|
|
||||||
let openUrlFun = url => () => openUrl(url);
|
let openUrlFun = url => () => openUrl(url);
|
||||||
let openUrl = url => {
|
let openUrl = url => {
|
||||||
@@ -196,7 +203,8 @@ const DEFAULT_ACTIONS = {
|
|||||||
update: {
|
update: {
|
||||||
l10nCommands: ["quickactions-cmd-update", "quickactions-update"],
|
l10nCommands: ["quickactions-cmd-update", "quickactions-update"],
|
||||||
label: "quickactions-update",
|
label: "quickactions-update",
|
||||||
onPick: openUrlFun(`${BASE_URL}update-firefox-latest-release`),
|
isActive: () => !!lazy.BrowserUpdater?.isReadyForRestart,
|
||||||
|
onPick: () => restartBrowser,
|
||||||
},
|
},
|
||||||
viewsource: {
|
viewsource: {
|
||||||
l10nCommands: ["quickactions-cmd-viewsource", "quickactions-viewsource"],
|
l10nCommands: ["quickactions-cmd-viewsource", "quickactions-viewsource"],
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ ChromeUtils.defineESModuleGetters(this, {
|
|||||||
"resource:///modules/UrlbarProviderQuickActions.sys.mjs",
|
"resource:///modules/UrlbarProviderQuickActions.sys.mjs",
|
||||||
});
|
});
|
||||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||||
|
AppConstants: "resource://gre/modules/AppConstants.jsm",
|
||||||
|
AppUpdater: "resource:///modules/AppUpdater.jsm",
|
||||||
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
|
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
|
||||||
DevToolsShim: "chrome://devtools-startup/content/DevToolsShim.jsm",
|
DevToolsShim: "chrome://devtools-startup/content/DevToolsShim.jsm",
|
||||||
});
|
});
|
||||||
@@ -590,3 +592,38 @@ add_task(async function test_clear() {
|
|||||||
dialogContentURI: "chrome://browser/content/sanitize.xhtml",
|
dialogContentURI: "chrome://browser/content/sanitize.xhtml",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function doUpdateActionTest(isActiveExpected, description) {
|
||||||
|
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||||
|
window,
|
||||||
|
value: "update",
|
||||||
|
});
|
||||||
|
|
||||||
|
await assertActionButtonStatus("update", isActiveExpected, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
add_task(async function test_update() {
|
||||||
|
if (!AppConstants.MOZ_UPDATER) {
|
||||||
|
await doUpdateActionTest(
|
||||||
|
false,
|
||||||
|
"Should be disabled since not AppConstants.MOZ_UPDATER"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sandbox = sinon.createSandbox();
|
||||||
|
try {
|
||||||
|
sandbox.stub(AppUpdater.prototype, "isReadyForRestart").get(() => false);
|
||||||
|
await doUpdateActionTest(
|
||||||
|
false,
|
||||||
|
"Should be disabled since AppUpdater.isReadyForRestart returns false"
|
||||||
|
);
|
||||||
|
sandbox.stub(AppUpdater.prototype, "isReadyForRestart").get(() => true);
|
||||||
|
await doUpdateActionTest(
|
||||||
|
true,
|
||||||
|
"Should be enabled since AppUpdater.isReadyForRestart returns true"
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
sandbox.restore();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user