Bug 1643578 - Test that extension as home page focuses address bar r=pbone
☠☠ backed out by 7590205c2184 ☠ ☠
authorKashav Madan <kmadan@mozilla.com>
Thu, 23 Jul 2020 17:36:35 +0000
changeset 541796 e87edc47ce4966ef9cf2df591dfa8a0d66f57116
parent 541795 5a1183eb910737e2141922797bab757b25332a77
child 541797 2c6272a20ddd8957e2da8a514a2fda45d470fa71
push id37633
push userccoroiu@mozilla.com
push dateFri, 24 Jul 2020 09:32:06 +0000
treeherdermozilla-central@141543043270 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbone
bugs1643578
milestone80.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1643578 - Test that extension as home page focuses address bar r=pbone Depends on D83754 Differential Revision: https://phabricator.services.mozilla.com/D83755
browser/base/content/test/tabs/browser_navigate_home_focuses_addressbar.js
--- a/browser/base/content/test/tabs/browser_navigate_home_focuses_addressbar.js
+++ b/browser/base/content/test/tabs/browser_navigate_home_focuses_addressbar.js
@@ -1,36 +1,77 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 
 const TEST_HTTP = httpURL("dummy_page.html");
 
-async function doNavigateHome(isHome, expectedURL, expectFocused) {
+async function doNavigateHome(expectedURL, expectFocused, waitForCondition) {
   await BrowserTestUtils.withNewTab(TEST_HTTP, async function(browser) {
     info("Tab ready");
 
     document.getElementById("home-button").click();
-    await BrowserTestUtils.browserLoaded(browser, false, isHome);
-    is(gURLBar.focused, expectFocused, "URL bar should" 
-      + (expectFocused ? "" : " not") + " be focused");
+    await BrowserTestUtils.browserLoaded(browser, false, HomePage.get());
+
+    if (waitForCondition) {
+      await waitForCondition(browser);
+    }
+
     is(gURLBar.value, expectedURL, "URL bar set correctly");
+    is(
+      gURLBar.focused,
+      expectFocused,
+      "URL bar should" + (expectFocused ? "" : " not") + " be focused"
+    );
   });
 }
 
 // Test for Bug 1634272
 add_task(async function testNavHomeDefault() {
-  await doNavigateHome((url) => url === HomePage.get(), "",
-    true);
+  await doNavigateHome("", true);
 });
 
-
-add_task(async function testNavHomePage() {
+add_task(async function testNavHomeHTTP() {
   await SpecialPowers.pushPrefEnv({
-    set: [["browser.startup.homepage", "http://example.com"]]
+    set: [["browser.startup.homepage", "http://example.com/"]],
   });
 
   // We don't focus the URL bar when the home page is a website.
-  await doNavigateHome((url) => url === "http://example.com/",
-      "example.com", false);
+  await doNavigateHome("example.com", false);
 
   await SpecialPowers.popPrefEnv();
 });
 
+// Test for Bug 1643578
+add_task(async function testNavHomeExtension() {
+  // Mostly copied from browser_ext_chrome_settings_overrides_home.js.
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      applications: {
+        gecko: { id: "extension@mochi.test" },
+      },
+      name: "Extension",
+      chrome_settings_overrides: { homepage: "ext.html" },
+      // We'll only focus the URL bar on a moz-extension:// home page if we're
+      // using the same custom URL for the newtab page.
+      chrome_url_overrides: { newtab: "ext.html" },
+    },
+    files: { "ext.html": "<h1>1</h1>" },
+    useAddonManager: "temporary",
+  });
+
+  await extension.startup();
+
+  // This is a little weird. On the initial home navigation, we ask the user
+  // for confirmation that the new extension should override the home page. This
+  // confirmation dialog is focused. Forcing an extra home navigation emulates
+  // clicking "keep changes" on that dialog, and avoids adding more complexity
+  // here.
+
+  // Ensure that we only proceed after the confirmation dialog has shown up.
+  await doNavigateHome("", false, browser =>
+    TestUtils.waitForCondition(() =>
+      browser.ownerDocument.getElementById("extension-homepage-notification")
+    )
+  );
+  await doNavigateHome("", true);
+
+  await extension.unload();
+});