Bug 1147765 - Fix console and style inspector tests that interact with style editor. r=ejpbruel
authorSami Jaktholm <sjakthol@outlook.com>
Sat, 21 Mar 2015 19:03:35 +0200
changeset 265062 01a988be408b35ad13d57e277dc4ab2c995ccb15
parent 265061 34fab46bd28ab9709ae68bc25af9690d0bd6da64
child 265063 6e2c2cddd92e289f63d3a5e14fd52327736d2049
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersejpbruel
bugs1147765
milestone39.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 1147765 - Fix console and style inspector tests that interact with style editor. r=ejpbruel CLOSED TREE
browser/devtools/styleinspector/test/head.js
browser/devtools/webconsole/test/browser_webconsole_bug_782653_CSS_links_in_Style_Editor.js
--- a/browser/devtools/styleinspector/test/head.js
+++ b/browser/devtools/styleinspector/test/head.js
@@ -911,27 +911,43 @@ function getComputedViewLinkByIndex(view
  * to be ready
  * @return a promise that resolves to the editor when the stylesheet editor is
  * ready
  */
 function waitForStyleEditor(toolbox, href) {
   let def = promise.defer();
 
   info("Waiting for the toolbox to switch to the styleeditor");
-  toolbox.once("styleeditor-ready").then(() => {
+  toolbox.once("styleeditor-selected").then(() => {
     let panel = toolbox.getCurrentPanel();
     ok(panel && panel.UI, "Styleeditor panel switched to front");
 
-    panel.UI.on("editor-selected", function onEditorSelected(event, editor) {
+    // A helper that resolves the promise once it receives an editor that
+    // matches the expected href. Returns false if the editor was not correct.
+    let gotEditor = (event, editor) => {
       let currentHref = editor.styleSheet.href;
       if (!href || (href && currentHref.endsWith(href))) {
         info("Stylesheet editor selected");
-        panel.UI.off("editor-selected", onEditorSelected);
+        panel.UI.off("editor-selected", gotEditor);
+
         editor.getSourceEditor().then(editor => {
           info("Stylesheet editor fully loaded");
           def.resolve(editor);
         });
+
+        return true;
       }
-    });
+
+      info("The editor was incorrect. Waiting for editor-selected event.");
+      return false;
+    };
+
+    // The expected editor may already be selected. Check the if the currently
+    // selected editor is the expected one and if not wait for an
+    // editor-selected event.
+    if (!gotEditor("styleeditor-selected", panel.UI.selectedEditor)) {
+      // The expected editor is not selected (yet). Wait for it.
+      panel.UI.on("editor-selected", gotEditor);
+    }
   });
 
   return def.promise;
 }
--- a/browser/devtools/webconsole/test/browser_webconsole_bug_782653_CSS_links_in_Style_Editor.js
+++ b/browser/devtools/webconsole/test/browser_webconsole_bug_782653_CSS_links_in_Style_Editor.js
@@ -43,23 +43,17 @@ function testViewSource()
              error2Msg.querySelector(".message-location")];
     ok(nodes[0], ".message-location node for the first error");
     ok(nodes[1], ".message-location node for the second error");
 
     let target = TargetFactory.forTab(gBrowser.selectedTab);
     let toolbox = gDevTools.getToolbox(target);
     toolbox.once("styleeditor-selected", (event, panel) => {
       StyleEditorUI = panel.UI;
-
-      let count = 0;
-      StyleEditorUI.on("editor-added", function() {
-        if (++count == 2) {
-          deferred.resolve(panel);
-        }
-      });
+      deferred.resolve(panel);
     });
 
     EventUtils.sendMouseEvent({ type: "click" }, nodes[0]);
   });
 
   return deferred.promise;
 }