Bug 1181837 - 3 - Introduce openToolboxForTab in shared-head.js to let tests open toolboxes in existing tabs draft
authorPatrick Brosset <pbrosset@mozilla.com>
Fri, 08 Jan 2016 14:03:19 -0800
changeset 321236 c4b5bd497c9b4085eb2f2bfa0558e50303c3ef81
parent 321235 c1d7ede7b3df630b230b574d51d6b47054cc5dab
child 321237 d59efa9a4a23c03763838aaa5547ea658537d178
push id9354
push userpbrosset@mozilla.com
push dateWed, 13 Jan 2016 09:58:41 +0000
bugs1181837
milestone46.0a1
Bug 1181837 - 3 - Introduce openToolboxForTab in shared-head.js to let tests open toolboxes in existing tabs
devtools/client/framework/test/shared-head.js
--- a/devtools/client/framework/test/shared-head.js
+++ b/devtools/client/framework/test/shared-head.js
@@ -64,17 +64,17 @@ registerCleanupFunction(function* cleanu
 });
 
 /**
  * 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
  * @return a promise that resolves to the tab object when the url is loaded
  */
 var addTab = Task.async(function*(url) {
-  info("Adding a new tab with URL: '" + url + "'");
+  info("Adding a new tab with URL: " + url);
 
   let tab = gBrowser.selectedTab = gBrowser.addTab(url);
   yield once(gBrowser.selectedBrowser, "load", true);
 
   info("Tab added and finished loading");
 
   return tab;
 });
@@ -178,25 +178,57 @@ function loadHelperScript(filePath) {
  */
 function waitForTick() {
   let deferred = promise.defer();
   executeSoon(deferred.resolve);
   return deferred.promise;
 }
 
 /**
+ * Open the toolbox in a given tab.
+ * @param {XULNode} tab The tab the toolbox should be opened in.
+ * @param {String} toolId Optional. The ID of the tool to be selected.
+ * @param {String} hostType Optional. The type of toolbox host to be used.
+ * @return {Promise} Resolves with the toolbox, when it has been opened.
+ */
+var openToolboxForTab = Task.async(function*(tab, toolId, hostType) {
+  info("Opening the toolbox");
+
+  let toolbox;
+  let target = TargetFactory.forTab(tab);
+
+  // Check if the toolbox is already loaded.
+  toolbox = gDevTools.getToolbox(target);
+  if (toolbox) {
+    info("Toolbox is already opened");
+    return toolbox;
+  }
+
+  // If not, load it now.
+  toolbox = yield gDevTools.showToolbox(target, toolId, hostType);
+
+  // Make sure that the toolbox frame is focused.
+  yield new Promise(resolve => waitForFocus(resolve, toolbox.frame.contentWindow));
+
+  info("Toolbox opened and focused");
+
+  return toolbox;
+});
+
+/**
  * Add a new tab and open the toolbox in it.
  * @param {String} url The URL for the tab to be opened.
+ * @param {String} toolId Optional. The ID of the tool to be selected.
+ * @param {String} hostType Optional. The type of toolbox host to be used.
  * @return {Promise} Resolves when the tab has been added, loaded and the
  * toolbox has been opened. Resolves to the toolbox.
  */
-var openNewTabAndToolbox = Task.async(function*(url) {
+var openNewTabAndToolbox = Task.async(function*(url, toolId, hostType) {
   let tab = yield addTab(url);
-  let toolbox = yield gDevTools.showToolbox(TargetFactory.forTab(tab));
-  return toolbox;
+  return openToolboxForTab(tab, toolId, hostType)
 });
 
 /**
  * Close a toolbox and the current tab.
  * @param {Toolbox} toolbox The toolbox to close.
  * @return {Promise} Resolves when the toolbox and tab have been destroyed and
  * closed.
  */