Bug 1688802 - Remove focus from the address bar in about:welcome draft
authorPunam Dahiya <punamdahiya@yahoo.com>
Wed, 17 Feb 2021 06:22:56 +0000
changeset 3544879 3d824c8ecac43be38c3aea12bb91a584baba7601
parent 3543653 e4810a424e34b090575175fa8c7a79afc7946249
child 3544880 38c05c168db78d0af13e5ea46a85f8c2f37e8af6
push id656065
push userreviewbot
push dateWed, 17 Feb 2021 06:23:24 +0000
treeherdertry@38c05c168db7 [default view] [failures only]
bugs1688802
milestone87.0a1
Bug 1688802 - Remove focus from the address bar in about:welcome Summary: Differential Revision: https://phabricator.services.mozilla.com/D103004 Test Plan: Reviewers: Subscribers: Bug #: 1688802 Differential Diff: PHID-DIFF-xhd5kngr4327bqq7nrgg
browser/base/content/browser.js
browser/components/newtab/test/browser/browser.ini
browser/components/newtab/test/browser/browser_aboutwelcome_focus.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -578,16 +578,25 @@ XPCOMUtils.defineLazyPreferenceGetter(
   "gProtonTabs",
   "browser.proton.tabs.enabled",
   false,
   (pref, oldValue, newValue) => {
     document.documentElement.toggleAttribute("proton", newValue);
   }
 );
 
+/* 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",
     window
   );
 });
 
 var gBrowser;
@@ -2189,17 +2198,26 @@ var gBrowserInit = {
     // by default. If we are not sure the urlbar will be focused in this
     // window, we need to remove the attribute before first paint.
     // TODO (bug 1629956): The urlbar having the 'focused' attribute by default
     // isn't a useful optimization anymore since UrlbarInput needs layout
     // information to focus the urlbar properly.
     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;
       }
 
       if (gBrowser.selectedBrowser.isRemoteBrowser) {
         // If the initial browser is remote, in order to optimize for first paint,
         // we'll defer switching focus to that browser until it has painted.
--- a/browser/components/newtab/test/browser/browser.ini
+++ b/browser/components/newtab/test/browser/browser.ini
@@ -13,16 +13,17 @@ prefs =
   browser.newtabpage.activity-stream.discoverystream.enabled=true
   browser.newtabpage.activity-stream.discoverystream.endpoints=data:
   browser.newtabpage.activity-stream.feeds.system.topstories=true
   browser.newtabpage.activity-stream.feeds.section.topstories=true
   browser.newtabpage.activity-stream.feeds.section.topstories.options={"provider_name":""}
   messaging-system.log=all
 
 [browser_aboutwelcome_actors.js]
+[browser_aboutwelcome_focus.js]
 [browser_aboutwelcome_simplified.js]
 [browser_aboutwelcome_multistage.js]
 [browser_aboutwelcome_rtamo.js]
 [browser_aboutwelcome_attribution.js]
 skip-if = (os == "linux") # Test setup only implemented for OSX and Windows
 [browser_aboutwelcome_observer.js]
 [browser_as_load_location.js]
 [browser_as_render.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/newtab/test/browser/browser_aboutwelcome_focus.js
@@ -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);
+  });
+});