Bug 1521534 - Make urlbar mochitests use a TEST_BASE_URL provided via head.js. r=Standard8
authorMarco Bonardo <mbonardo@mozilla.com>
Tue, 05 Mar 2019 15:22:12 +0000
changeset 520273 bd68f490ca078d2b7a5a10f47b2f9d5f1abbdbc4
parent 520272 ab3ace7e5b1ada049a7c6eaad31505412985522c
child 520279 996a48b306521112d483b3bd8bede1e4fa23d3fa
child 520280 1a681dc60b60a4040959de4b44fa8d6a4f8f08e1
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1521534
milestone67.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 1521534 - Make urlbar mochitests use a TEST_BASE_URL provided via head.js. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D22068
browser/components/urlbar/tests/browser/browser_keyword.js
browser/components/urlbar/tests/browser/browser_populateAfterPushState.js
browser/components/urlbar/tests/browser/browser_raceWithTabs.js
browser/components/urlbar/tests/browser/browser_redirect_error.js
browser/components/urlbar/tests/browser/browser_remotetab.js
browser/components/urlbar/tests/browser/browser_stop_pending.js
browser/components/urlbar/tests/browser/browser_switchTab_decodeuri.js
browser/components/urlbar/tests/browser/browser_switchTab_override.js
browser/components/urlbar/tests/browser/browser_tabMatchesInAwesomebar.js
browser/components/urlbar/tests/browser/browser_tabMatchesInAwesomebar_perwindowpb.js
browser/components/urlbar/tests/browser/browser_urlbarHashChangeProxyState.js
browser/components/urlbar/tests/browser/browser_urlbarValueOnTabSwitch.js
browser/components/urlbar/tests/browser/browser_urlbar_blanking.js
browser/components/urlbar/tests/browser/browser_urlbar_content_opener.js
browser/components/urlbar/tests/browser/browser_urlbar_locationchange_urlbar_edit_dos.js
browser/components/urlbar/tests/browser/browser_userTypedValue.js
browser/components/urlbar/tests/browser/head-common.js
browser/components/urlbar/tests/legacy/browser_switchtab_copy.js
browser/components/urlbar/tests/legacy/browser_switchtab_override_keynav.js
--- a/browser/components/urlbar/tests/browser/browser_keyword.js
+++ b/browser/components/urlbar/tests/browser/browser_keyword.js
@@ -24,19 +24,17 @@ function assertURL(result, expectedUrl, 
     // We need to make a real URI out of this to ensure it's normalised for
     // comparison.
     Assert.equal(result.url, PlacesUtils.mozActionURI("keyword",
       {url: expectedUrl, input, postData}),
       "Expect correct url");
   }
 }
 
-const TEST_PATH = getRootDirectory(gTestPath)
-  .replace("chrome://mochitests/content", "http://mochi.test:8888");
-const TEST_URL = `${TEST_PATH}print_postdata.sjs`;
+const TEST_URL = `${TEST_BASE_URL}print_postdata.sjs`;
 
 add_task(async function setup() {
   await PlacesUtils.keywords.insert({ keyword: "get",
                                       url: TEST_URL + "?q=%s" });
   await PlacesUtils.keywords.insert({ keyword: "post",
                                       url: TEST_URL,
                                       postData: "q=%s" });
   registerCleanupFunction(async function() {
@@ -51,32 +49,32 @@ add_task(async function setup() {
 add_task(async function test_display_keyword_without_query() {
   await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
 
   // Test a keyword that also has blank spaces to ensure they are ignored as well.
   let result = await promise_first_result("get  ");
 
   Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.KEYWORD,
     "Should have a keyword result");
-  Assert.equal(result.displayed.title, "mochi.test:8888",
+  Assert.equal(result.displayed.title, "example.com",
     "Node should contain the name of the bookmark");
   Assert.equal(result.displayed.action,
     Services.strings.createBundle("chrome://global/locale/autocomplete.properties")
             .GetStringFromName("visit"),
      "Should have visit indicated");
 });
 
 add_task(async function test_keyword_using_get() {
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
 
   let result = await promise_first_result("get something");
 
   Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.KEYWORD,
     "Should have a keyword result");
-  Assert.equal(result.displayed.title, "mochi.test:8888: something",
+  Assert.equal(result.displayed.title, "example.com: something",
      "Node should contain the name of the bookmark and query");
   Assert.ok(!result.displayed.action, "Should have an empty action");
 
   assertURL(result, TEST_URL + "?q=something", "get something");
 
   let element = await UrlbarTestUtils.waitForAutocompleteResultAt(window, 0);
 
   if (!UrlbarPrefs.get("quantumbar")) {
@@ -117,17 +115,17 @@ add_task(async function test_keyword_usi
 
 add_task(async function test_keyword_using_post() {
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
 
   let result = await promise_first_result("post something");
 
   Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.KEYWORD,
     "Should have a keyword result");
-  Assert.equal(result.displayed.title, "mochi.test:8888: something",
+  Assert.equal(result.displayed.title, "example.com: something",
      "Node should contain the name of the bookmark and query");
   Assert.ok(!result.displayed.action, "Should have an empty action");
 
   assertURL(result, TEST_URL, "post something", "q=something");
 
   // Click on the result
   info("Normal click on result");
   let tabPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
--- a/browser/components/urlbar/tests/browser/browser_populateAfterPushState.js
+++ b/browser/components/urlbar/tests/browser/browser_populateAfterPushState.js
@@ -4,20 +4,19 @@
 "use strict";
 
 /* When a user clears the URL bar, and then the page pushes state, we should
  * re-fill the URL bar so it doesn't remain empty indefinitely. See bug 1441039.
  * For normal loads, this happens automatically because a non-same-document state
  * change takes place.
  */
 add_task(async function() {
-  const TEST_PATH = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://example.com");
-  await BrowserTestUtils.withNewTab(TEST_PATH + "dummy_page.html", async function(browser) {
+  await BrowserTestUtils.withNewTab(TEST_BASE_URL + "dummy_page.html", async function(browser) {
     gURLBar.value = "";
 
-    let locationChangePromise = BrowserTestUtils.waitForLocationChange(gBrowser, TEST_PATH + "dummy_page2.html");
+    let locationChangePromise = BrowserTestUtils.waitForLocationChange(gBrowser, TEST_BASE_URL + "dummy_page2.html");
     await ContentTask.spawn(browser, null, function() {
       content.history.pushState({}, "Page 2", "dummy_page2.html");
     });
     await locationChangePromise;
-    is(gURLBar.value, TEST_PATH + "dummy_page2.html", "Should have updated the URL bar.");
+    is(gURLBar.value, TEST_BASE_URL + "dummy_page2.html", "Should have updated the URL bar.");
   });
 });
--- a/browser/components/urlbar/tests/browser/browser_raceWithTabs.js
+++ b/browser/components/urlbar/tests/browser/browser_raceWithTabs.js
@@ -1,11 +1,12 @@
-const TEST_PATH = getRootDirectory(gTestPath)
-  .replace("chrome://mochitests/content", "http://example.com");
-const TEST_URL = `${TEST_PATH}dummy_page.html`;
+/* Any copyright is dedicated to the Public Domain.
+ * https://creativecommons.org/publicdomain/zero/1.0/ */
+
+const TEST_URL = `${TEST_BASE_URL}dummy_page.html`;
 
 async function addBookmark(bookmark) {
   if (bookmark.keyword) {
     await PlacesUtils.keywords.insert({
       keyword: bookmark.keyword,
       url: bookmark.url,
     });
   }
--- a/browser/components/urlbar/tests/browser/browser_redirect_error.js
+++ b/browser/components/urlbar/tests/browser/browser_redirect_error.js
@@ -1,14 +1,12 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-const TEST_PATH = getRootDirectory(gTestPath)
-  .replace("chrome://mochitests/content", "http://example.com");
-const REDIRECT_FROM = `${TEST_PATH}redirect_error.sjs`;
+const REDIRECT_FROM = `${TEST_BASE_URL}redirect_error.sjs`;
 
 const REDIRECT_TO = "https://www.bank1.com/"; // Bad-cert host.
 
 function isRedirectedURISpec(aURISpec) {
   return isRedirectedURI(Services.io.newURI(aURISpec));
 }
 
 function isRedirectedURI(aURI) {
--- a/browser/components/urlbar/tests/browser/browser_remotetab.js
+++ b/browser/components/urlbar/tests/browser/browser_remotetab.js
@@ -5,19 +5,17 @@
  * This tests checks that the remote tab result is displayed and can be
  * selected.
  */
 
 "use strict";
 
 const {SyncedTabs} = ChromeUtils.import("resource://services-sync/SyncedTabs.jsm");
 
-const TEST_PATH = getRootDirectory(gTestPath)
-  .replace("chrome://mochitests/content", "http://example.org");
-const TEST_URL = `${TEST_PATH}dummy_page.html`;
+const TEST_URL = `${TEST_BASE_URL}dummy_page.html`;
 
 const REMOTE_TAB = {
   "id": "7cqCr77ptzX3",
   "type": "client",
   "lastModified": 1492201200,
   "name": "zcarter's Nightly on MacBook-Pro-25",
   "clientType": "desktop",
   "tabs": [
--- a/browser/components/urlbar/tests/browser/browser_stop_pending.js
+++ b/browser/components/urlbar/tests/browser/browser_stop_pending.js
@@ -54,18 +54,17 @@ add_task(async function() {
  * The URL bar continues to contain the URL of the page we wanted to visit.
  */
 add_task(async function() {
   let socket = Cc["@mozilla.org/network/server-socket;1"].createInstance(Ci.nsIServerSocket);
   socket.init(-1, true, -1);
   const PORT = socket.port;
   registerCleanupFunction(() => { socket.close(); });
 
-  const TEST_PATH = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "https://example.com");
-  const BASE_PAGE = TEST_PATH + "dummy_page.html";
+  const BASE_PAGE = TEST_BASE_URL + "dummy_page.html";
   const SLOW_HOST = `https://localhost:${PORT}/`;
   info("Using URLs: " + SLOW_HOST);
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, BASE_PAGE);
   info("opened tab");
   await ContentTask.spawn(tab.linkedBrowser, SLOW_HOST, URL => {
     let link = content.document.createElement("a");
     link.href = URL;
     link.textContent = "click me to open a slow page";
@@ -100,18 +99,17 @@ add_task(async function() {
   let socket = Cc["@mozilla.org/network/server-socket;1"].createInstance(Ci.nsIServerSocket);
   socket.init(-1, true, -1);
   const PORT1 = socket.port;
   let socket2 = Cc["@mozilla.org/network/server-socket;1"].createInstance(Ci.nsIServerSocket);
   socket2.init(-1, true, -1);
   const PORT2 = socket2.port;
   registerCleanupFunction(() => { socket.close(); socket2.close(); });
 
-  const TEST_PATH = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "https://example.com");
-  const BASE_PAGE = TEST_PATH + "dummy_page.html";
+  const BASE_PAGE = TEST_BASE_URL + "dummy_page.html";
   const SLOW_HOST1 = `https://localhost:${PORT1}/`;
   const SLOW_HOST2 = `https://localhost:${PORT2}/`;
   info("Using URLs: " + SLOW_HOST1 + " and " + SLOW_HOST2);
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, BASE_PAGE);
   info("opened tab");
   await ContentTask.spawn(tab.linkedBrowser, SLOW_HOST1, URL => {
     let link = content.document.createElement("a");
     link.href = URL;
--- a/browser/components/urlbar/tests/browser/browser_switchTab_decodeuri.js
+++ b/browser/components/urlbar/tests/browser/browser_switchTab_decodeuri.js
@@ -3,19 +3,17 @@
 
 /**
  * This test ensures that switch to tab still works when the URI contains an
  * encoded part.
  */
 
 "use strict";
 
-const TEST_PATH = getRootDirectory(gTestPath)
-  .replace("chrome://mochitests/content", "http://example.org");
-const TEST_URL = `${TEST_PATH}dummy_page.html#test%7C1`;
+const TEST_URL = `${TEST_BASE_URL}dummy_page.html#test%7C1`;
 
 add_task(async function test_switchtab_decodeuri() {
   info("Opening first tab");
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL);
 
   info("Opening and selecting second tab");
   gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
 
--- a/browser/components/urlbar/tests/browser/browser_switchTab_override.js
+++ b/browser/components/urlbar/tests/browser/browser_switchTab_override.js
@@ -4,19 +4,17 @@
 
 /**
  * This test ensures that overriding switch-to-tab correctly loads the page
  * rather than switching to it.
  */
 
 "use strict";
 
-const TEST_PATH = getRootDirectory(gTestPath)
-  .replace("chrome://mochitests/content", "http://example.org/");
-const TEST_URL = `${TEST_PATH}dummy_page.html`;
+const TEST_URL = `${TEST_BASE_URL}dummy_page.html`;
 
 
 add_task(async function test_switchtab_override() {
   info("Opening first tab");
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL);
 
   info("Opening and selecting second tab");
   let secondTab = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
--- a/browser/components/urlbar/tests/browser/browser_tabMatchesInAwesomebar.js
+++ b/browser/components/urlbar/tests/browser/browser_tabMatchesInAwesomebar.js
@@ -8,21 +8,19 @@
 
 /**
  * Tests for ensuring that the tab switch results correctly match what is
  * currently available.
  */
 
 requestLongerTimeout(2);
 
-const TEST_PATH = getRootDirectory(gTestPath)
-  .replace("chrome://mochitests/content", "http://example.com");
 const TEST_URL_BASES = [
-  `${TEST_PATH}dummy_page.html#tabmatch`,
-  `${TEST_PATH}moz.png#tabmatch`,
+  `${TEST_BASE_URL}dummy_page.html#tabmatch`,
+  `${TEST_BASE_URL}moz.png#tabmatch`,
 ];
 
 const RESTRICT_TOKEN_OPENPAGE = "%";
 
 var gTabCounter = 0;
 
 add_task(async function step_1() {
   info("Running step 1");
--- a/browser/components/urlbar/tests/browser/browser_tabMatchesInAwesomebar_perwindowpb.js
+++ b/browser/components/urlbar/tests/browser/browser_tabMatchesInAwesomebar_perwindowpb.js
@@ -3,19 +3,17 @@
 
 "use strict";
 
 /**
  * This test ensures that we don't move switch between tabs when one is in
  * private browsing and the other is normal, or vice-versa.
  */
 
-const TEST_PATH = getRootDirectory(gTestPath)
-  .replace("chrome://mochitests/content", "http://example.com");
-const TEST_URL = `${TEST_PATH}dummy_page.html`;
+const TEST_URL = `${TEST_BASE_URL}dummy_page.html`;
 
 add_task(async function() {
   let normalWindow = await BrowserTestUtils.openNewBrowserWindow();
   let privateWindow = await BrowserTestUtils.openNewBrowserWindow({private: true});
   await runTest(normalWindow, privateWindow, false);
   await BrowserTestUtils.closeWindow(normalWindow);
   await BrowserTestUtils.closeWindow(privateWindow);
 
--- a/browser/components/urlbar/tests/browser/browser_urlbarHashChangeProxyState.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarHashChangeProxyState.js
@@ -1,19 +1,19 @@
-"use strict";
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
 
-const TEST_PATH = getRootDirectory(gTestPath)
-  .replace("chrome://mochitests/content", "https://example.org");
+"use strict";
 
 /**
  * Check that navigating through both the URL bar and using in-page hash- or ref-
  * based links and back or forward navigation updates the URL bar and identity block correctly.
  */
 add_task(async function() {
-  let baseURL = `${TEST_PATH}dummy_page.html`;
+  let baseURL = `${TEST_BASE_URL}dummy_page.html`;
   let url = baseURL + "#foo";
   await BrowserTestUtils.withNewTab({ gBrowser, url }, async function(browser) {
     let identityBox = document.getElementById("identity-box");
     let expectedURL = url;
 
     let verifyURLBarState = testType => {
       is(gURLBar.textValue, expectedURL, "URL bar visible value should be correct " + testType);
       is(gURLBar.value, expectedURL, "URL bar value should be correct " + testType);
@@ -90,17 +90,17 @@ add_task(async function() {
 /**
  * Check that initial secure loads that swap remoteness
  * get the correct page icon when finished.
  */
 add_task(async function() {
   // Ensure there's no preloaded newtab browser, since that'll not fire a load event.
   gBrowser.removePreloadedBrowser();
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:newtab");
-  let url = `${TEST_PATH}dummy_page.html#foo`;
+  let url = `${TEST_BASE_URL}dummy_page.html#foo`;
   gURLBar.value = url;
   gURLBar.select();
   EventUtils.sendKey("return");
   await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
 
   is(gURLBar.textValue, url, "URL bar visible value should be correct when the page loads from about:newtab");
   is(gURLBar.value, url, "URL bar value should be correct when the page loads from about:newtab");
   let identityBox = document.getElementById("identity-box");
--- a/browser/components/urlbar/tests/browser/browser_urlbarValueOnTabSwitch.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarValueOnTabSwitch.js
@@ -4,19 +4,17 @@
 
 /**
  * This tests for the correct URL being displayed in the URL bar after switching
  * tabs which are in different states (e.g. deleted, partially deleted).
  */
 
 "use strict";
 
-const TEST_PATH = getRootDirectory(gTestPath)
-  .replace("chrome://mochitests/content", "http://example.com");
-const TEST_URL = `${TEST_PATH}dummy_page.html`;
+const TEST_URL = `${TEST_BASE_URL}dummy_page.html`;
 
 add_task(async function() {
   let charsToDelete, deletedURLTab, fullURLTab, partialURLTab, testPartialURL, testURL;
 
   charsToDelete = 5;
   deletedURLTab = BrowserTestUtils.addTab(gBrowser);
   fullURLTab = BrowserTestUtils.addTab(gBrowser);
   partialURLTab = BrowserTestUtils.addTab(gBrowser);
--- a/browser/components/urlbar/tests/browser/browser_urlbar_blanking.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbar_blanking.js
@@ -1,13 +1,14 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
 "use strict";
 
-const TEST_PATH = getRootDirectory(gTestPath)
-  .replace("chrome://mochitests/content", "http://www.example.com");
-const TEST_URL = `${TEST_PATH}file_blank_but_not_blank.html`;
+const TEST_URL = `${TEST_BASE_URL}file_blank_but_not_blank.html`;
 
 add_task(async function() {
   for (let page of gInitialPages) {
     if (page == "about:newtab") {
       // New tab preloading makes this a pain to test, so skip
       continue;
     }
     let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, page);
--- a/browser/components/urlbar/tests/browser/browser_urlbar_content_opener.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbar_content_opener.js
@@ -1,17 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
-const TEST_PATH = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "https://example.com");
-
 add_task(async function() {
-  await BrowserTestUtils.withNewTab(TEST_PATH + "dummy_page.html", async function(browser) {
+  await BrowserTestUtils.withNewTab(TEST_BASE_URL + "dummy_page.html", async function(browser) {
     let windowOpenedPromise = BrowserTestUtils.waitForNewWindow();
     await ContentTask.spawn(browser, null, function() {
       content.window.open("", "_BLANK", "toolbar=no,height=300,width=500");
     });
     let newWin = await windowOpenedPromise;
     is(newWin.gURLBar.value, "about:blank", "Should be displaying about:blank for the opened window.");
     await BrowserTestUtils.closeWindow(newWin);
   });
--- a/browser/components/urlbar/tests/browser/browser_urlbar_locationchange_urlbar_edit_dos.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbar_locationchange_urlbar_edit_dos.js
@@ -1,13 +1,14 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
 "use strict";
 
-const TEST_PATH = getRootDirectory(gTestPath)
-  .replace("chrome://mochitests/content", "http://www.example.com");
-const TEST_URL = `${TEST_PATH}file_urlbar_edit_dos.html`;
+const TEST_URL = `${TEST_BASE_URL}file_urlbar_edit_dos.html`;
 
 async function checkURLBarValueStays(browser) {
   gURLBar.select();
   EventUtils.sendString("a");
   is(gURLBar.value, "a", "URL bar value should match after sending a key");
   await new Promise(resolve => {
     let listener = {
       onLocationChange(aWebProgress, aRequest, aLocation, aFlags) {
--- a/browser/components/urlbar/tests/browser/browser_userTypedValue.js
+++ b/browser/components/urlbar/tests/browser/browser_userTypedValue.js
@@ -1,11 +1,13 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
 function test() {
-  const TEST_PATH = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "https://example.com");
-  const URI = TEST_PATH + "file_userTypedValue.html";
+  const URI = TEST_BASE_URL + "file_userTypedValue.html";
   window.browserDOMWindow.openURI(makeURI(URI),
                                   null,
                                   Ci.nsIBrowserDOMWindow.OPEN_NEWTAB,
                                   Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL,
                                   Services.scriptSecurityManager.getSystemPrincipal());
 
   is(gBrowser.userTypedValue, URI, "userTypedValue matches test URI");
   is(gURLBar.value, URI, "location bar value matches test URI");
--- a/browser/components/urlbar/tests/browser/head-common.js
+++ b/browser/components/urlbar/tests/browser/head-common.js
@@ -7,16 +7,20 @@ XPCOMUtils.defineLazyModuleGetters(this,
   PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
   PlacesTestUtils: "resource://testing-common/PlacesTestUtils.jsm",
   Preferences: "resource://gre/modules/Preferences.jsm",
   SearchTestUtils: "resource://testing-common/SearchTestUtils.jsm",
   UrlbarTestUtils: "resource://testing-common/UrlbarTestUtils.jsm",
   UrlbarTokenizer: "resource:///modules/UrlbarTokenizer.jsm",
 });
 
+XPCOMUtils.defineLazyGetter(this, "TEST_BASE_URL", () =>
+  getRootDirectory(gTestPath).replace("chrome://mochitests/content",
+                                      "https://example.com"));
+
 SearchTestUtils.init(Assert, registerCleanupFunction);
 
 function is_element_visible(element, msg) {
   isnot(element, null, "Element should not be null, when checking visibility");
   ok(BrowserTestUtils.is_visible(element), msg || "Element should be visible");
 }
 
 function is_element_hidden(element, msg) {
--- a/browser/components/urlbar/tests/legacy/browser_switchtab_copy.js
+++ b/browser/components/urlbar/tests/legacy/browser_switchtab_copy.js
@@ -1,15 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-const TEST_PATH = getRootDirectory(gTestPath)
-  .replace("chrome://mochitests/content", "http://example.com");
-const TEST_URL = `${TEST_PATH}dummy_page.html`;
+const TEST_URL = `${TEST_BASE_URL}dummy_page.html`;
 var testActionURL = "moz-action:switchtab," + JSON.stringify({url: TEST_URL});
 const testURL = gURLBar.trimValue(TEST_URL);
 var testTab;
 
 function runNextTest() {
   if (tests.length) {
     let t = tests.shift();
     waitForClipboard(t.expected, t.setup, function() {
--- a/browser/components/urlbar/tests/legacy/browser_switchtab_override_keynav.js
+++ b/browser/components/urlbar/tests/legacy/browser_switchtab_override_keynav.js
@@ -1,15 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-const TEST_PATH = getRootDirectory(gTestPath)
-  .replace("chrome://mochitests/content", "http://example.org");
-const TEST_URL = `${TEST_PATH}dummy_page.html`;
+const TEST_URL = `${TEST_BASE_URL}dummy_page.html`;
 
 add_task(async function test_switchtab_override_keynav() {
   info("Opening first tab");
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL);
 
   info("Opening and selecting second tab");
   let secondTab = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
   registerCleanupFunction(() => {