Bug 1489222 - Add mochitest to check navigation from ThisFirefox to Connect;r=daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 25 Sep 2018 09:49:24 +0200
changeset 438161 6e2aaef654b01aa7eca017a24819899ca2468521
parent 438160 573a32cebe76bbfc55ffc307abb907fb8a39d6bd
child 438162 1a3c36cf4ca771802b49a0cb7ed0d8b8c22265f9
push id34711
push useraciure@mozilla.com
push dateTue, 25 Sep 2018 21:49:34 +0000
treeherdermozilla-central@2e3e89c9c68c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaisuke
bugs1489222
milestone64.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 1489222 - Add mochitest to check navigation from ThisFirefox to Connect;r=daisuke Reviewers: daisuke Subscribers: MarcoM Bug #: 1489222 Differential Revision: https://phabricator.services.mozilla.com/D6485
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_navigate.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_network_runtimes.js
devtools/client/aboutdebugging-new/test/browser/head.js
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -5,10 +5,11 @@ support-files =
   debug-target-pane_collapsibilities_head.js
   head.js
   !/devtools/client/shared/test/shared-head.js
   !/devtools/client/shared/test/telemetry-test-helpers.js
 
 [browser_aboutdebugging_connect_networklocations.js]
 [browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js]
 [browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js]
+[browser_aboutdebugging_navigate.js]
 [browser_aboutdebugging_sidebar_network_runtimes.js]
 [browser_aboutdebugging_thisfirefox.js]
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js
@@ -1,21 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
-/* import-globals-from debug-target-pane_collapsibilities_head.js */
 
 "use strict";
 
 /**
  * Test that collapsibilities of DebugTargetPane on RuntimePage by mouse clicking.
  */
 
-Services.scriptloader.loadSubScript(
-  CHROME_URL_ROOT + "debug-target-pane_collapsibilities_head.js", this);
-
 add_task(async function() {
   prepareCollapsibilitiesTest();
 
   const { document, tab } = await openAboutDebugging();
 
   for (const { title } of TARGET_PANES) {
     const debugTargetPaneEl = getDebugTargetPane(title, document);
 
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js
@@ -1,21 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
-/* import-globals-from debug-target-pane_collapsibilities_head.js */
 
 "use strict";
 
 /**
  * Test for preference of DebugTargetPane collapsibilities.
  */
 
-Services.scriptloader.loadSubScript(
-  CHROME_URL_ROOT + "debug-target-pane_collapsibilities_head.js", this);
-
 add_task(async function() {
   prepareCollapsibilitiesTest();
 
   const { document, tab } = await openAboutDebugging();
 
   info("Collapse all pane");
   for (const { title } of TARGET_PANES) {
     const debugTargetPaneEl = getDebugTargetPane(title, document);
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_navigate.js
@@ -0,0 +1,79 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Check that navigating from This Firefox to Connect and back to This Firefox works and
+ * does not leak.
+ */
+
+const TAB_URL_1 = "data:text/html,<title>TAB1</title>";
+const TAB_URL_2 = "data:text/html,<title>TAB2</title>";
+
+add_task(async function() {
+  info("Force all debug target panes to be expanded");
+  prepareCollapsibilitiesTest();
+
+  const { document, tab } = await openAboutDebugging();
+
+  const connectSidebarItem = findSidebarItemByText("Connect", document);
+  ok(connectSidebarItem, "Found the Connect sidebar item");
+
+  const thisFirefoxSidebarItem = findSidebarItemByText("This Firefox", document);
+  ok(thisFirefoxSidebarItem, "Found the ThisFirefox sidebar item");
+  ok(isSidebarItemSelected(thisFirefoxSidebarItem),
+    "ThisFirefox sidebar item is selected by default");
+
+  info("Open a new background tab TAB1");
+  const backgroundTab1 = await addTab(TAB_URL_1, { background: true });
+
+  info("Wait for the tab to appear in the debug targets with the correct name");
+  await waitUntil(() => findDebugTargetByText("TAB1", document));
+
+  info("Click on the Connect item in the sidebar");
+  connectSidebarItem.click();
+
+  info("Wait until Connect page is displayed");
+  await waitUntil(() => document.querySelector(".js-connect-page"));
+  ok(isSidebarItemSelected(connectSidebarItem), "Connect sidebar item is selected");
+  ok(!document.querySelector(".js-runtime-page"), "Runtime page no longer rendered");
+
+  info("Open a new tab which should be listed when we go back to This Firefox");
+  const backgroundTab2 = await addTab(TAB_URL_2, { background: true });
+
+  info("Click on the ThisFirefox item in the sidebar");
+  thisFirefoxSidebarItem.click();
+
+  info("Wait until ThisFirefox page is displayed");
+  await waitUntil(() => document.querySelector(".js-runtime-page"));
+  ok(isSidebarItemSelected(thisFirefoxSidebarItem),
+    "ThisFirefox sidebar item is selected again");
+  ok(!document.querySelector(".js-connect-page"), "Connect page no longer rendered");
+
+  info("TAB2 should already be displayed in the debug targets");
+  await waitUntil(() => findDebugTargetByText("TAB2", document));
+
+  info("Remove first background tab");
+  await removeTab(backgroundTab1);
+
+  info("Check TAB1 disappears, meaning ThisFirefox client is correctly connected");
+  await waitUntil(() => !findDebugTargetByText("TAB1", document));
+
+  info("Remove second background tab");
+  await removeTab(backgroundTab2);
+
+  info("Check TAB2 disappears, meaning ThisFirefox client is correctly connected");
+  await waitUntil(() => !findDebugTargetByText("TAB2", document));
+
+  await removeTab(tab);
+});
+
+function isSidebarItemSelected(item) {
+  return item.classList.contains("js-sidebar-item-selected");
+}
+
+function findDebugTargetByText(text, document) {
+  const targets = [...document.querySelectorAll(".js-debug-target-item")];
+  return targets.find(target => target.textContent.includes(text));
+}
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_network_runtimes.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_network_runtimes.js
@@ -33,15 +33,8 @@ add_task(async function() {
 
   info("Wait for 'no devices' element to reappear");
   waitUntil(() => document.querySelector(".js-sidebar-no-devices"));
   ok(!findSidebarItemByText("localhost:6080", document),
     "Sidebar item for localhost:6080 removed");
 
   await removeTab(tab);
 });
-
-function findSidebarItemByText(text, document) {
-  const sidebarItems = document.querySelectorAll(".js-sidebar-item");
-  return [...sidebarItems].find(element => {
-    return element.textContent.includes(text);
-  });
-}
--- a/devtools/client/aboutdebugging-new/test/browser/head.js
+++ b/devtools/client/aboutdebugging-new/test/browser/head.js
@@ -1,22 +1,27 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /* eslint-env browser */
 /* eslint no-unused-vars: [2, {"vars": "local"}] */
 /* import-globals-from ../../../shared/test/shared-head.js */
+/* import-globals-from debug-target-pane_collapsibilities_head.js */
 
 "use strict";
 
 // Load the shared-head file first.
 Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/devtools/client/shared/test/shared-head.js",
   this);
 
+// Load collapsibilities helpers
+Services.scriptloader.loadSubScript(
+  CHROME_URL_ROOT + "debug-target-pane_collapsibilities_head.js", this);
+
 /**
  * Enable the new about:debugging panel.
  */
 async function enableNewAboutDebugging() {
   await pushPref("devtools.aboutdebugging.new-enabled", true);
 }
 
 async function openAboutDebugging(page, win) {
@@ -31,8 +36,15 @@ async function openAboutDebugging(page, 
   info("Wait until the main about debugging container is available");
   await waitUntil(() => document.querySelector(".app"));
 
   info("Wait until the client connection was established");
   await waitUntil(() => document.querySelector(".js-runtime-page"));
 
   return { tab, document, window };
 }
+
+function findSidebarItemByText(text, document) {
+  const sidebarItems = document.querySelectorAll(".js-sidebar-item");
+  return [...sidebarItems].find(element => {
+    return element.textContent.includes(text);
+  });
+}