Bug 1497454: Add a test for focusing existing tab. r=jdescottes
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Thu, 11 Apr 2019 11:39:57 +0000
changeset 468985 52f6204043df2950fa8af7bddf62ed8942c2dbc9
parent 468984 8389653f29718f2c9a8d548606d760eff2e5b893
child 468986 03ed53e600d458cef860664cbee5d5fdaf8e33f3
push id35856
push usercsabou@mozilla.com
push dateFri, 12 Apr 2019 03:19:48 +0000
treeherdermozilla-central@940684cd1065 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1497454
milestone68.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 1497454: Add a test for focusing existing tab. r=jdescottes Depends on D26652 Differential Revision: https://phabricator.services.mozilla.com/D26653
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_devtoolstoolbox_focus.js
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -50,16 +50,17 @@ skip-if = (os == 'linux' && bits == 32) 
 [browser_aboutdebugging_connection_prompt_setting.js]
 [browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js]
 [browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js]
 [browser_aboutdebugging_debug-target-pane_empty.js]
 [browser_aboutdebugging_debug-target-pane_usb_runtime.js]
 [browser_aboutdebugging_devtools.js]
 [browser_aboutdebugging_devtoolstoolbox_contextmenu.js]
 [browser_aboutdebugging_devtoolstoolbox_contextmenu_markupview.js]
+[browser_aboutdebugging_devtoolstoolbox_focus.js]
 [browser_aboutdebugging_devtoolstoolbox_menubar.js]
 [browser_aboutdebugging_devtoolstoolbox_performance.js]
 [browser_aboutdebugging_devtoolstoolbox_reload.js]
 [browser_aboutdebugging_devtoolstoolbox_shortcuts.js]
 skip-if = (os == "win" && ccov) # Bug 1521349
 [browser_aboutdebugging_devtoolstoolbox_target_destroyed.js]
 skip-if = debug || asan # This test leaks. See bug 1529005
 [browser_aboutdebugging_devtoolstoolbox_tooltip_markupview.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_devtoolstoolbox_focus.js
@@ -0,0 +1,88 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-collapsibilities.js", this);
+
+/**
+ * Test whether the focus transfers to a tab which is already inspected .
+ */
+add_task(async function() {
+  info("Force all debug target panes to be expanded");
+  prepareCollapsibilitiesTest();
+
+  info("Select 'performance' panel as the initial tool since the tool does not listen " +
+       "any changes of the document without user action");
+  await pushPref("devtools.toolbox.selectedTool", "performance");
+
+  const { document, tab, window } = await openAboutDebugging();
+  await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+  const inspectionTarget = "about:debugging";
+  info(`Open ${ inspectionTarget } as inspection target`);
+  await waitUntil(() => findDebugTargetByText(inspectionTarget, document));
+  info(`Inspect ${ inspectionTarget } page in about:devtools-toolbox`);
+  const { devtoolsTab, devtoolsWindow } =
+    await openAboutDevtoolsToolbox(document, tab, window, inspectionTarget);
+
+  info("Check the tab state after clicking inspect button " +
+       "when another tab was selected");
+  gBrowser.selectedTab = tab;
+  clickInspectButton(inspectionTarget, document);
+  const devtoolsURL = devtoolsWindow.location.href;
+  assertDevtoolsToolboxTabState(devtoolsURL);
+
+  info("Check the tab state after clicking inspect button " +
+       "when the toolbox tab is in another window");
+  const newNavigator = gBrowser.replaceTabWithWindow(devtoolsTab);
+  await waitUntil(() =>
+    newNavigator.gBrowser &&
+    newNavigator.gBrowser.selectedTab.linkedBrowser
+                .contentWindow.location.href === devtoolsURL);
+  info("Create a tab in the window and select the tab " +
+       "so that the about:devtools-toolbox tab loses focus");
+  newNavigator.gBrowser.selectedTab = newNavigator.gBrowser.addTab("about:blank", {
+    triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
+  });
+  clickInspectButton(inspectionTarget, document);
+  assertDevtoolsToolboxTabState(devtoolsURL);
+
+  info("Close new navigator and wait until the debug target disappears");
+  const onToolboxDestroyed = gDevTools.once("toolbox-destroyed");
+  newNavigator.close();
+  await onToolboxDestroyed;
+  await waitUntil(() =>
+    !findDebugTargetByText("about:devtools-toolbox?", document));
+
+  await removeTab(tab);
+});
+
+function clickInspectButton(inspectionTarget, doc) {
+  const target = findDebugTargetByText(inspectionTarget, doc);
+  const button = target.querySelector(".js-debug-target-inspect-button");
+  button.click();
+}
+
+// Check that only one tab is currently opened for the provided URL.
+// Also check that this tab and the tab's window are focused.
+function assertDevtoolsToolboxTabState(devtoolsURL) {
+  const existingTabs = [];
+
+  for (const navigator of Services.wm.getEnumerator("navigator:browser")) {
+    for (const browser of navigator.gBrowser.browsers) {
+      if (browser.contentWindow && browser.contentWindow.location.href === devtoolsURL) {
+        const tab = navigator.gBrowser.getTabForBrowser(browser);
+        existingTabs.push(tab);
+      }
+    }
+  }
+
+  is(existingTabs.length, 1, `Only one tab is opened for ${ devtoolsURL }`);
+  const tab = existingTabs[0];
+  const navigator = tab.ownerGlobal;
+  is(navigator.gBrowser.selectedTab, tab, "The tab is selected");
+  const focusedNavigator = Services.wm.getMostRecentWindow("navigator:browser");
+  is(navigator, focusedNavigator, "The navigator is focused");
+}