Bug 1688802 - Remove focus from the address bar in about:welcome r=dao,k88hudson

Differential Revision: https://phabricator.services.mozilla.com/D103004
This commit is contained in:
Punam Dahiya 2021-02-16 21:07:41 +00:00
Родитель 9ff8284160
Коммит ae7e45b76f
3 изменённых файлов: 121 добавлений и 1 удалений

Просмотреть файл

@ -583,6 +583,15 @@ XPCOMUtils.defineLazyPreferenceGetter(
}
);
/* Import aboutWelcomeFeature from Nimbus Experiment API
to access experiment values */
XPCOMUtils.defineLazyGetter(this, "aboutWelcomeFeature", () => {
const { ExperimentFeature } = ChromeUtils.import(
"resource://messaging-system/experiments/ExperimentAPI.jsm"
);
return new ExperimentFeature("aboutwelcome");
});
customElements.setElementCreationCallback("translation-notification", () => {
Services.scriptloader.loadSubScript(
"chrome://browser/content/translation-notification.js",
@ -2199,7 +2208,16 @@ var gBrowserInit = {
let shouldRemoveFocusedAttribute = true;
this._callWithURIToLoad(uriToLoad => {
if (isBlankPageURL(uriToLoad) || uriToLoad == "about:privatebrowsing") {
// Check if user is enrolled in an aboutWelcome experiment that has skipFocus
// property set to true, if yes remove focus from urlbar for about:welcome
const aboutWelcomeSkipUrlBarFocus =
uriToLoad == "about:welcome" &&
aboutWelcomeFeature.getValue()?.skipFocus;
if (
(isBlankPageURL(uriToLoad) && !aboutWelcomeSkipUrlBarFocus) ||
uriToLoad == "about:privatebrowsing"
) {
gURLBar.select();
shouldRemoveFocusedAttribute = false;
return;

Просмотреть файл

@ -20,6 +20,7 @@ prefs =
[browser_aboutwelcome_actors.js]
[browser_aboutwelcome_simplified.js]
[browser_aboutwelcome_multistage.js]
[browser_aboutwelcome_skipFocus.js]
[browser_aboutwelcome_rtamo.js]
[browser_aboutwelcome_attribution.js]
skip-if = (os == "linux") # Test setup only implemented for OSX and Windows

Просмотреть файл

@ -0,0 +1,101 @@
"use strict";
const ABOUT_WELCOME_OVERRIDE_CONTENT_PREF =
"browser.aboutwelcome.overrideContent";
const TEST_MULTISTAGE_JSON = {
id: "multi-stage-welcome",
template: "multistage",
screens: [
{
id: "AW_STEP1",
order: 0,
content: {
title: "Step 1",
},
},
],
};
async function setAboutWelcomeOverrideContent(value) {
return pushPrefs([ABOUT_WELCOME_OVERRIDE_CONTENT_PREF, value]);
}
async function openAboutWelcomeBrowserWindow() {
let win = window.openDialog(
AppConstants.BROWSER_CHROME_URL,
"_blank",
"chrome,all,dialog=no",
"about:welcome"
);
await BrowserTestUtils.waitForEvent(win, "DOMContentLoaded");
let promises = [
BrowserTestUtils.firstBrowserLoaded(win, false),
BrowserTestUtils.browserStopped(
win.gBrowser.selectedBrowser,
"about:welcome"
),
];
await Promise.all(promises);
await new Promise(resolve => {
// 10 is an arbitrary value here, it needs to be at least 2 to avoid
// races with code initializing itself using idle callbacks.
(function waitForIdle(count = 10) {
if (!count) {
resolve();
return;
}
Services.tm.idleDispatchToMainThread(() => {
waitForIdle(count - 1);
});
})();
});
return win;
}
add_task(async function test_multistage_default() {
let win = await openAboutWelcomeBrowserWindow();
Assert.ok(win.gURLBar.focused, "Focus should be on awesome bar");
Assert.ok(
win.gURLBar.hasAttribute("focused"),
"Has focused attribute on urlBar"
);
registerCleanupFunction(async () => {
await BrowserTestUtils.closeWindow(win);
});
});
add_task(async function test_multistage_without_skipFocus() {
await setAboutWelcomeOverrideContent(JSON.stringify(TEST_MULTISTAGE_JSON));
let win = await openAboutWelcomeBrowserWindow();
Assert.ok(win.gURLBar.focused, "Focus should be on awesome bar");
Assert.ok(
win.gURLBar.hasAttribute("focused"),
"Has focused attribute on urlBar"
);
registerCleanupFunction(async () => {
await BrowserTestUtils.closeWindow(win);
});
});
add_task(async function test_multistage_with_skipFocus() {
await setAboutWelcomeOverrideContent(
JSON.stringify({ ...TEST_MULTISTAGE_JSON, skipFocus: true })
);
let win = await openAboutWelcomeBrowserWindow();
Assert.ok(!win.gURLBar.focused, "Focus should not be on awesome bar");
Assert.ok(
!win.gURLBar.hasAttribute("focused"),
"No focused attribute on urlBar"
);
registerCleanupFunction(async () => {
await BrowserTestUtils.closeWindow(win);
});
});