Bug 1410360 - add mochitest for about:devtools tab selection behavior;r=ochameau
MozReview-Commit-ID: 8eX13qJ1jt8
--- a/devtools/shim/aboutdevtools/test/browser.ini
+++ b/devtools/shim/aboutdevtools/test/browser.ini
@@ -1,8 +1,9 @@
[DEFAULT]
tags = devtools
subsuite = devtools
support-files =
head.js
[browser_aboutdevtools_enables_devtools.js]
+[browser_aboutdevtools_focus_owner_tab.js]
[browser_aboutdevtools_reuse_existing.js]
new file mode 100644
--- /dev/null
+++ b/devtools/shim/aboutdevtools/test/browser_aboutdevtools_focus_owner_tab.js
@@ -0,0 +1,83 @@
+/* vim: set ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* eslint-env browser */
+
+/**
+ * When closing about:devtools, test that the tab where the user triggered about:devtools
+ * is selected again.
+ */
+add_task(async function () {
+ await pushPref("devtools.enabled", false);
+
+ info("Add an about:blank tab");
+ let tab1 = await addTab("data:text/html;charset=utf-8,tab1");
+ let tab2 = await addTab("data:text/html;charset=utf-8,tab2");
+ ok(tab1 === gBrowser.tabs[1], "tab1 is the second tab in the current browser window");
+
+ info("Select the first tab");
+ gBrowser.selectedTab = tab1;
+
+ synthesizeToggleToolboxKey();
+
+ info("Wait for the about:devtools tab to be selected");
+ await waitUntil(() => isAboutDevtoolsTab(gBrowser.selectedTab));
+ info("about:devtools was opened as expected.");
+
+ let aboutDevtoolsTab = gBrowser.selectedTab;
+ ok(aboutDevtoolsTab === gBrowser.tabs[2],
+ "about:devtools was opened next to its owner tab");
+
+ info("Move the owner tab to the end of the tabs array.");
+ gBrowser.moveTabTo(tab1, gBrowser.tabs.length - 1);
+ await removeTab(aboutDevtoolsTab);
+
+ await waitUntil(() => tab1 == gBrowser.selectedTab);
+ info("The correct tab was selected after closing about:devtools.");
+
+ await removeTab(tab1);
+ await removeTab(tab2);
+});
+
+/**
+ * When closing about:devtools, test that the current tab is not updated if
+ * about:devtools was not the selectedTab.
+ */
+add_task(async function () {
+ await pushPref("devtools.enabled", false);
+
+ info("Add an about:blank tab");
+ let tab1 = await addTab("data:text/html;charset=utf-8,tab1");
+ let tab2 = await addTab("data:text/html;charset=utf-8,tab2");
+ ok(tab1 === gBrowser.tabs[1], "tab1 is the second tab in the current browser window");
+
+ info("Select the first tab");
+ gBrowser.selectedTab = tab1;
+
+ synthesizeToggleToolboxKey();
+
+ info("Wait for the about:devtools tab to be selected");
+ await waitUntil(() => isAboutDevtoolsTab(gBrowser.selectedTab));
+ info("about:devtools was opened as expected.");
+
+ let aboutDevtoolsTab = gBrowser.selectedTab;
+ ok(aboutDevtoolsTab === gBrowser.tabs[2],
+ "about:devtools was opened next to its owner tab");
+
+ info("Select the second tab");
+ gBrowser.selectedTab = tab2;
+
+ let aboutDevtoolsDocument = aboutDevtoolsTab.linkedBrowser.contentDocument;
+ await waitUntil(() => aboutDevtoolsDocument.visibilityState === "hidden");
+
+ await removeTab(aboutDevtoolsTab);
+
+ ok(tab2 == gBrowser.selectedTab,
+ "Tab 2 should still be selected.");
+
+ await removeTab(tab1);
+ await removeTab(tab2);
+});
--- a/devtools/shim/aboutdevtools/test/browser_aboutdevtools_reuse_existing.js
+++ b/devtools/shim/aboutdevtools/test/browser_aboutdevtools_reuse_existing.js
@@ -35,29 +35,8 @@ add_task(async function () {
let aboutDevtoolsTabs = [...gBrowser.tabs].filter(isAboutDevtoolsTab);
ok(aboutDevtoolsTabs.length === 1, "Only one tab of about:devtools was opened.");
ok(aboutDevtoolsTabs[0] === aboutDevtoolsTab,
"The existing about:devtools tab was reused.");
await removeTab(aboutDevtoolsTab);
await removeTab(tab);
});
-
-/**
- * Helper to call the toggle devtools shortcut.
- */
-function synthesizeToggleToolboxKey() {
- info("Trigger the toogle toolbox shortcut");
- if (Services.appinfo.OS == "Darwin") {
- EventUtils.synthesizeKey("i", { accelKey: true, altKey: true });
- } else {
- EventUtils.synthesizeKey("i", { accelKey: true, shiftKey: true });
- }
-}
-
-/**
- * Helper to check if a given tab is about:devtools.
- */
-function isAboutDevtoolsTab(tab) {
- let browser = tab.linkedBrowser;
- let location = browser.documentURI.spec;
- return location.startsWith("about:devtools");
-}
--- a/devtools/shim/aboutdevtools/test/head.js
+++ b/devtools/shim/aboutdevtools/test/head.js
@@ -85,8 +85,29 @@ const openAboutDevTools = async function
* Set a temporary value for a preference, that will be cleaned up after the test.
*/
const pushPref = function (preferenceName, value) {
return new Promise(resolve => {
let options = {"set": [[preferenceName, value]]};
SpecialPowers.pushPrefEnv(options, resolve);
});
};
+
+/**
+ * Helper to call the toggle devtools shortcut.
+ */
+function synthesizeToggleToolboxKey() {
+ info("Trigger the toogle toolbox shortcut");
+ if (Services.appinfo.OS == "Darwin") {
+ EventUtils.synthesizeKey("i", { accelKey: true, altKey: true });
+ } else {
+ EventUtils.synthesizeKey("i", { accelKey: true, shiftKey: true });
+ }
+}
+
+/**
+ * Helper to check if a given tab is about:devtools.
+ */
+function isAboutDevtoolsTab(tab) {
+ let browser = tab.linkedBrowser;
+ let location = browser.documentURI.spec;
+ return location.startsWith("about:devtools");
+}