Bug 1274106 - Ensure opening tabs in background from about:debugging test. r=jdescottes, a=test-only
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 14 Sep 2016 07:41:08 -0700
changeset 333251 93266904a199ad4d2cb4ee36d0fb15b00fdc61d8
parent 333250 0437e13b60c39116f82158dfc77c3f72436100f2
child 333252 c1c3b1e2bf94289422620f27e546a42091f01f98
push id10030
push userryanvm@gmail.com
push dateMon, 19 Sep 2016 00:37:00 +0000
treeherdermozilla-aurora@896a7672b837 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes, test-only
bugs1274106
milestone50.0a2
Bug 1274106 - Ensure opening tabs in background from about:debugging test. r=jdescottes, a=test-only MozReview-Commit-ID: kSeAw9Xz1A
devtools/client/aboutdebugging/test/browser_service_workers_not_compatible.js
devtools/client/aboutdebugging/test/browser_tabs.js
devtools/client/aboutdebugging/test/head.js
devtools/client/framework/test/shared-head.js
--- a/devtools/client/aboutdebugging/test/browser_service_workers_not_compatible.js
+++ b/devtools/client/aboutdebugging/test/browser_service_workers_not_compatible.js
@@ -50,11 +50,11 @@ add_task(function* () {
   let win = OpenBrowserWindow({private: true});
   yield waitForDelayedStartupFinished(win);
 
   let { tab, document } = yield openAboutDebugging("workers", win);
   // Check that the warning img appears in the UI
   let img = document.querySelector(imgClass);
   ok(img, "warning message is rendered");
 
-  yield closeAboutDebugging(tab, win);
+  yield closeAboutDebugging(tab);
   win.close();
 });
--- a/devtools/client/aboutdebugging/test/browser_tabs.js
+++ b/devtools/client/aboutdebugging/test/browser_tabs.js
@@ -16,17 +16,17 @@ add_task(function* () {
   // Refresh tabsElement to get the .target-list element
   tabsElement = getTabList(document);
 
   let names = [...tabsElement.querySelectorAll(".target-name")];
   let initialTabCount = names.length;
 
   // Open a new tab in background and wait for its addition in the UI
   let onNewTab = waitForMutation(tabsElement, { childList: true });
-  let newTab = yield addTab(TAB_URL, null, true);
+  let newTab = yield addTab(TAB_URL, { background: true });
   yield onNewTab;
 
   // Check that the new tab appears in the UI, but with an empty name
   let newNames = [...tabsElement.querySelectorAll(".target-name")];
   newNames = newNames.filter(node => !names.includes(node));
   is(newNames.length, 1, "A new tab appeared in the list");
   let newTabTarget = newNames[0];
 
--- a/devtools/client/aboutdebugging/test/head.js
+++ b/devtools/client/aboutdebugging/test/head.js
@@ -27,17 +27,17 @@ registerCleanupFunction(() => {
 
 function* openAboutDebugging(page, win) {
   info("opening about:debugging");
   let url = "about:debugging";
   if (page) {
     url += "#" + page;
   }
 
-  let tab = yield addTab(url, win);
+  let tab = yield addTab(url, { window: win });
   let browser = tab.linkedBrowser;
   let document = browser.contentDocument;
 
   if (!document.querySelector(".app")) {
     yield waitForMutation(document.body, { childList: true });
   }
 
   return { tab, document };
@@ -59,59 +59,19 @@ function changeAboutDebuggingHash(docume
 
 function openPanel(document, panelId) {
   info(`Opening ${panelId} panel`);
   document.querySelector(`[aria-controls="${panelId}"]`).click();
   return waitForMutation(
     document.querySelector(".main-content"), {childList: true});
 }
 
-function closeAboutDebugging(tab, win) {
+function closeAboutDebugging(tab) {
   info("Closing about:debugging");
-  return removeTab(tab, win);
-}
-
-function addTab(url, win, backgroundTab = false) {
-  info("Adding tab: " + url);
-
-  return new Promise(done => {
-    let targetWindow = win || window;
-    let targetBrowser = targetWindow.gBrowser;
-
-    targetWindow.focus();
-    let tab = targetBrowser.addTab(url);
-    if (!backgroundTab) {
-      targetBrowser.selectedTab = tab;
-    }
-    let linkedBrowser = tab.linkedBrowser;
-
-    BrowserTestUtils.browserLoaded(linkedBrowser)
-      .then(function () {
-        info("Tab added and finished loading: " + url);
-        done(tab);
-      });
-  });
-}
-
-function removeTab(tab, win) {
-  info("Removing tab.");
-
-  return new Promise(done => {
-    let targetWindow = win || window;
-    let targetBrowser = targetWindow.gBrowser;
-    let tabContainer = targetBrowser.tabContainer;
-
-    tabContainer.addEventListener("TabClose", function onClose() {
-      tabContainer.removeEventListener("TabClose", onClose, false);
-      info("Tab removed and finished closing.");
-      done();
-    }, false);
-
-    targetBrowser.removeTab(tab);
-  });
+  return removeTab(tab);
 }
 
 function getSupportsFile(path) {
   let cr = Cc["@mozilla.org/chrome/chrome-registry;1"]
     .getService(Ci.nsIChromeRegistry);
   let uri = Services.io.newURI(CHROME_URL_ROOT + path, null, null);
   let fileurl = cr.convertChromeURL(uri);
   return fileurl.QueryInterface(Ci.nsIFileURL);
--- a/devtools/client/framework/test/shared-head.js
+++ b/devtools/client/framework/test/shared-head.js
@@ -101,37 +101,47 @@ registerCleanupFunction(function* cleanu
   while (gBrowser.tabs.length > 1) {
     yield closeTabAndToolbox(gBrowser.selectedTab);
   }
 });
 
 /**
  * Add a new test tab in the browser and load the given url.
  * @param {String} url The url to be loaded in the new tab
+ * @param {Object} options Object with various optional fields:
+ *   - {Boolean} background If true, open the tab in background
+ *   - {ChromeWindow} window Firefox top level window we should use to open the tab
  * @return a promise that resolves to the tab object when the url is loaded
  */
-var addTab = Task.async(function* (url) {
+var addTab = Task.async(function* (url, options = { background: false, window: window }) {
   info("Adding a new tab with URL: " + url);
 
-  let tab = gBrowser.selectedTab = gBrowser.addTab(url);
-  yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
+  let { background } = options;
+  let { gBrowser } = options.window ? options.window : window;
+
+  let tab = gBrowser.addTab(url);
+  if (!background) {
+    gBrowser.selectedTab = tab;
+  }
+  yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
 
   info("Tab added and finished loading");
 
   return tab;
 });
 
 /**
  * Remove the given tab.
  * @param {Object} tab The tab to be removed.
  * @return Promise<undefined> resolved when the tab is successfully removed.
  */
 var removeTab = Task.async(function* (tab) {
   info("Removing tab.");
 
+  let { gBrowser } = tab.ownerDocument.defaultView;
   let onClose = once(gBrowser.tabContainer, "TabClose");
   gBrowser.removeTab(tab);
   yield onClose;
 
   info("Tab removed and finished closing");
 });
 
 /**