Bug 1615283 - Converge random other navigation patterns to the unique navigateTo helper. r=nchevobbe
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 17 Feb 2020 16:52:32 +0000
changeset 514337 a838dc056fa9e1041ff06c92d41f09eba98aa415
parent 514336 6fc2ecf60dd13e772cd06feadedea8825be4c8a9
child 514338 cd53a0220c505f3dafd54b51071e4a2fe24c25a1
push id107514
push userapoirot@mozilla.com
push dateMon, 17 Feb 2020 16:53:40 +0000
treeherderautoland@cd53a0220c50 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnchevobbe
bugs1615283
milestone75.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 1615283 - Converge random other navigation patterns to the unique navigateTo helper. r=nchevobbe Differential Revision: https://phabricator.services.mozilla.com/D62806
devtools/client/accessibility/test/browser/browser_accessibility_reload.js
devtools/client/accessibility/test/browser/head.js
devtools/client/application/test/browser/browser_application_panel_list-domain-workers.js
devtools/client/application/test/browser/browser_application_panel_list-several-workers.js
devtools/client/application/test/browser/browser_application_panel_manifest-reload.js
devtools/client/application/test/browser/browser_application_panel_target-switching.js
devtools/client/application/test/browser/head.js
devtools/client/debugger/test/mochitest/browser_dbg-breakpoint-skipping-console.js
devtools/client/styleeditor/test/head.js
--- a/devtools/client/accessibility/test/browser/browser_accessibility_reload.js
+++ b/devtools/client/accessibility/test/browser/browser_accessibility_reload.js
@@ -70,17 +70,17 @@ const tests = [
       sidebar: {
         name: "Accessibility Panel Test",
         role: "document",
       },
     },
   },
   {
     desc: "Navigate to a new page.",
-    setup: async ({ panel }) => navigate(panel.target, buildURL(TEST_URI_2)),
+    setup: () => navigateTo(buildURL(TEST_URI_2)),
     expected: {
       tree: [
         {
           role: "document",
           name: `"Navigation Accessibility Panel"`,
         },
       ],
       sidebar: {
--- a/devtools/client/accessibility/test/browser/head.js
+++ b/devtools/client/accessibility/test/browser/head.js
@@ -796,19 +796,8 @@ function addA11YPanelTask(msg, uri, task
  * Reload panel target.
  * @param  {Object} target             Panel target.
  * @param  {String} waitForTargetEvent Event to wait for after reload.
  */
 function reload(target, waitForTargetEvent = "navigate") {
   executeSoon(() => target.reload());
   return once(target, waitForTargetEvent);
 }
-
-/**
- * Navigate to a new URL within the panel target.
- * @param  {Object} target             Panel target.
- * @param  {Srting} url                URL to navigate to.
- * @param  {String} waitForTargetEvent Event to wait for after reload.
- */
-function navigate(target, url, waitForTargetEvent = "navigate") {
-  executeSoon(() => target.navigateTo({ url }));
-  return once(target, waitForTargetEvent);
-}
--- a/devtools/client/application/test/browser/browser_application_panel_list-domain-workers.js
+++ b/devtools/client/application/test/browser/browser_application_panel_list-domain-workers.js
@@ -31,28 +31,28 @@ add_task(async function() {
     scopeEl.textContent.startsWith("example.com"),
     "First service worker registration is displayed for the correct domain"
   );
 
   info(
     "Navigate to another page for a different domain with no service worker"
   );
 
-  await navigate(toolbox, EMPTY_URL);
+  await navigateTo(EMPTY_URL);
   info("Wait until the service worker list is updated");
   await waitUntil(() => doc.querySelector(".worker-list-empty") !== null);
   ok(
     true,
     "No service workers are shown for an empty page in a different domain."
   );
 
   info(
     "Navigate to another page for a different domain with another service worker"
   );
-  await navigate(toolbox, OTHER_URL);
+  await navigateTo(OTHER_URL);
 
   info("Wait until the service worker appears in the application panel");
   await waitUntil(() => getWorkerContainers(doc).length === 1);
 
   scopeEl = getWorkerContainers(doc)[0].querySelector(".js-sw-scope");
   ok(
     scopeEl.textContent.startsWith("test1.example.com"),
     "Second service worker registration is displayed for the correct domain"
--- a/devtools/client/application/test/browser/browser_application_panel_list-several-workers.js
+++ b/devtools/client/application/test/browser/browser_application_panel_list-several-workers.js
@@ -27,17 +27,17 @@ add_task(async function() {
     getWorkerContainers(doc)[0].querySelector(".js-unregister-button")
   );
 
   ok(true, "First service worker registration is displayed");
 
   info(
     "Navigate to another page for the same domain with another service worker"
   );
-  await navigate(toolbox, OTHER_SCOPE_URL);
+  await navigateTo(OTHER_SCOPE_URL);
 
   info("Wait until the service worker appears in the application panel");
   await waitUntil(() => getWorkerContainers(doc).length === 2);
 
   info("Wait until the unregister button is displayed for the service worker");
   await waitUntil(() =>
     getWorkerContainers(doc)[1].querySelector(".js-unregister-button")
   );
--- a/devtools/client/application/test/browser/browser_application_panel_manifest-reload.js
+++ b/devtools/client/application/test/browser/browser_application_panel_manifest-reload.js
@@ -8,45 +8,45 @@
  * or navigating to a new page
  */
 
 add_task(async function() {
   await enableApplicationPanel();
 
   info("Loading a page with no manifest");
   let url = URL_ROOT + "resources/manifest/load-no-manifest.html";
-  const { panel, tab, toolbox } = await openNewTabAndApplicationPanel(url);
+  const { panel, tab } = await openNewTabAndApplicationPanel(url);
   const doc = panel.panelWin.document;
 
   selectPage(panel, "manifest");
 
   info("Waiting for the 'no manifest' message to appear");
   await waitUntil(() => doc.querySelector(".js-manifest-empty") !== null);
   ok(true, "Manifest page displays a 'no manifest' message");
 
   info("Navigating to a page with a manifest");
   url = URL_ROOT + "resources/manifest/load-ok.html";
-  await navigate(toolbox, url);
+  await navigateTo(url);
 
   info("Waiting for the manifest to show up");
   await waitUntil(() => doc.querySelector(".js-manifest") !== null);
   ok(true, "Manifest displayed successfully");
 
   info("Navigating to a page with a manifest that fails to load");
   url = URL_ROOT + "resources/manifest/load-fail.html";
-  await navigate(toolbox, url);
+  await navigateTo(url);
 
   info("Waiting for the manifest to fail to load");
   await waitUntil(
     () => doc.querySelector(".js-manifest-loaded-error") !== null
   );
   ok(true, "Manifest page displays loading error");
 
   info("Reloading");
-  await navigate(toolbox, url);
+  await navigateTo(url);
 
   info("Waiting for the loading message to appear");
   await waitUntil(() => doc.querySelector(".js-manifest-loading") !== null);
   info("Waiting for the manifest to fail to load");
   await waitUntil(
     () => doc.querySelector(".js-manifest-loaded-error") !== null
   );
   ok(true, "Manifest page displays loading error");
--- a/devtools/client/application/test/browser/browser_application_panel_target-switching.js
+++ b/devtools/client/application/test/browser/browser_application_panel_target-switching.js
@@ -25,44 +25,44 @@ add_task(async function() {
   const doc = panel.panelWin.document;
 
   info("Check for non-existing service worker");
   selectPage(panel, "service-workers");
   const isWorkerListEmpty = !!doc.querySelector(".worker-list-empty");
   ok(isWorkerListEmpty, "No Service Worker displayed");
 
   info("Navigate to a page that runs in the child process");
-  await navigate(toolbox, CONTENT_PROCESS_URI_WORKERS);
+  await navigateTo(CONTENT_PROCESS_URI_WORKERS);
 
   info("Wait until the service worker appears in the application panel");
   await waitUntil(() => getWorkerContainers(doc).length === 1);
 
   // close the tab
   info("Closing the tab.");
   await unregisterAllWorkers(toolbox.target.client);
   await BrowserTestUtils.removeTab(tab);
 });
 
 // test manifest when target switching
 add_task(async function() {
   await pushPref("devtools.target-switching.enabled", true);
   await enableApplicationPanel();
 
   info("Open a page that runs in the parent process");
-  const { panel, toolbox, tab } = await openNewTabAndApplicationPanel(
+  const { panel, tab } = await openNewTabAndApplicationPanel(
     PARENT_PROCESS_URI
   );
   const doc = panel.panelWin.document;
 
   info("Waiting for the 'no manifest' message to appear");
   selectPage(panel, "manifest");
   await waitUntil(() => doc.querySelector(".js-manifest-empty") !== null);
 
   info("Navigate to a page that runs in the child process");
-  await navigate(toolbox, CONTENT_PROCESS_URI_MANIFEST);
+  await navigateTo(CONTENT_PROCESS_URI_MANIFEST);
 
   info("Waiting for the manifest to load");
   selectPage(panel, "manifest");
   await waitUntil(() => doc.querySelector(".js-manifest") !== null);
   ok(true, "Manifest loaded successfully");
 
   // close the tab
   info("Closing the tab.");
--- a/devtools/client/application/test/browser/head.js
+++ b/devtools/client/application/test/browser/head.js
@@ -47,36 +47,16 @@ async function enableApplicationPanel() 
   // Enable application panel in DevTools.
   await pushPref("devtools.application.enabled", true);
 }
 
 function getWorkerContainers(doc) {
   return doc.querySelectorAll(".js-sw-container");
 }
 
-async function navigate(toolbox, url) {
-  const isTargetSwitchingEnabled = Services.prefs.getBoolPref(
-    "devtools.target-switching.enabled",
-    false
-  );
-
-  // when target switching, a new target will receive the "navigate" event
-  if (isTargetSwitchingEnabled) {
-    const onSwitched = once(toolbox, "switched-target");
-    toolbox.target.navigateTo({ url });
-    return onSwitched;
-  }
-
-  // when we are not target switching, the same target will receive the
-  // "navigate" event
-  const onNavigated = once(toolbox.target, "navigate");
-  toolbox.target.navigateTo({ url });
-  return onNavigated;
-}
-
 async function openNewTabAndApplicationPanel(url) {
   const tab = await addTab(url);
   const target = await TargetFactory.forTab(tab);
 
   const toolbox = await gDevTools.showToolbox(target, "application");
   const panel = toolbox.getCurrentPanel();
   return { panel, tab, target, toolbox };
 }
--- a/devtools/client/debugger/test/mochitest/browser_dbg-breakpoint-skipping-console.js
+++ b/devtools/client/debugger/test/mochitest/browser_dbg-breakpoint-skipping-console.js
@@ -6,13 +6,13 @@
  * Test that debugger statements are skipped when
  * skip pausing is enabled.
  */
 
 add_task(async function() {
   const toolbox = await initPane("doc-scripts.html", "webconsole", [
     ["devtools.debugger.skip-pausing", true]
   ]);
-  toolbox.target.navigateTo({ url: "doc-debugger-statements.html" });
+  await navigateTo(EXAMPLE_URL + "doc-debugger-statements.html");
 
   await hasConsoleMessage({ toolbox }, 'done!')
   ok(true, 'We reached the end');
 });
--- a/devtools/client/styleeditor/test/head.js
+++ b/devtools/client/styleeditor/test/head.js
@@ -41,29 +41,16 @@ var addTab = function(url, win) {
       function() {
         info("URL '" + url + "' loading complete");
         resolve(tab);
       }
     );
   });
 };
 
-/**
- * Navigate the currently selected tab to a new URL and wait for it to load.
- * @param {String} url The url to be loaded in the current tab.
- * @return a promise that resolves when the page has fully loaded.
- */
-var navigateTo = function(url) {
-  info(`Navigating to ${url}`);
-  const browser = gBrowser.selectedBrowser;
-
-  BrowserTestUtils.loadURI(browser, url);
-  return BrowserTestUtils.browserLoaded(browser);
-};
-
 var navigateToAndWaitForStyleSheets = async function(url, ui) {
   const onReset = ui.once("stylesheets-reset");
   await navigateTo(url);
   await onReset;
 };
 
 var reloadPageAndWaitForStyleSheets = async function(ui) {
   info("Reloading the page.");