Bug 808264 - Intermittent browser_webconsole_bug_782653_CSS_links_in_Style_Editor.js | Timed out while waiting for: Wait for the source-editor to load
authorMihai Sucan <mihai.sucan@gmail.com>
Thu, 15 Nov 2012 19:40:44 +0200
changeset 113409 495192ed8589fe54ce165998ec01104986b6ed43
parent 113408 fdad0a320e7d96494ada3014df2824540871cfcd
child 113410 52596d2fa339d948ea652d362b8e5d94f5764a09
push id18134
push usermihai.sucan@gmail.com
push dateThu, 15 Nov 2012 20:48:49 +0000
treeherdermozilla-inbound@495192ed8589 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs808264
milestone19.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 808264 - Intermittent browser_webconsole_bug_782653_CSS_links_in_Style_Editor.js | Timed out while waiting for: Wait for the source-editor to load
browser/devtools/webconsole/test/browser_webconsole_bug_782653_CSS_links_in_Style_Editor.js
--- 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
@@ -2,143 +2,134 @@
 /* ***** BEGIN LICENSE BLOCK *****
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  * ***** END LICENSE BLOCK ***** */
 
 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test" +
                  "/test-bug-782653-css-errors.html";
 
-let nodes;
+let nodes, hud, SEC;
 
-let styleEditorWin;
-
-function test() {
+function test()
+{
   addTab(TEST_URI);
   browser.addEventListener("load", function onLoad() {
     browser.removeEventListener("load", onLoad, true);
     openConsole(null, testViewSource);
   }, true);
 }
 
-function testViewSource(hud) {
+function testViewSource(aHud)
+{
+  hud = aHud;
+
+  registerCleanupFunction(function() {
+    nodes = hud = SEC = null;
+  });
+
+  let selector = ".webconsole-msg-cssparser .webconsole-location";
 
   waitForSuccess({
     name: "find the location node",
     validatorFn: function()
     {
-      return hud.outputNode.querySelector(".webconsole-location");
+      return hud.outputNode.querySelector(selector);
     },
     successFn: function()
     {
-      nodes = hud.outputNode.querySelectorAll(".webconsole-location");
+      nodes = hud.outputNode.querySelectorAll(selector);
+      is(nodes.length, 2, "correct number of css messages");
 
       Services.ww.registerNotification(observer);
 
       EventUtils.sendMouseEvent({ type: "click" }, nodes[0]);
     },
     failureFn: finishTest,
   });
 }
 
-function checkStyleEditorForSheetAndLine(aStyleSheetIndex, aLine, aCallback) {
-
-  function doCheck(aEditor) {
-    function checkLineAndCallback() {
-      info("In checkLineAndCallback()");
-      is(aEditor.sourceEditor.getCaretPosition().line, aLine,
-         "Correct line is selected");
-      if (aCallback) {
-        aCallback();
-      }
-    }
-
-    function checkForCorrectSheet() {
-      if (aEditor.styleSheetIndex != SEC.selectedStyleSheetIndex) {
-        ok(false, "Correct Style Sheet was not selected.");
-        if (aCallback) {
-          executeSoon(aCallback);
-        }
-        return;
-      }
-
-      info("Editor is already loaded, check the current line of caret");
-      executeSoon(checkLineAndCallback);
-    }
-
-    ok(aEditor, "aEditor is defined.");
-
-    // Source-editor is already loaded, check the current sheet and line.
-    if (aEditor.sourceEditor) {
-      checkForCorrectSheet();
-      return;
-    }
-
-    info("source editor is not loaded, waiting for it.");
-    // Source-editor is not loaded, polling regularly and waiting for it to load
-    waitForSuccess({
-      name: "Wait for the source-editor to load",
-      validatorFn: function()
-      {
-        return aEditor.sourceEditor;
-      },
-      successFn: checkForCorrectSheet,
-      failureFn: aCallback,
-    });
-  }
-
-  let SEC = styleEditorWin.styleEditorChrome;
-  ok(SEC, "Syle Editor Chrome is defined properly while calling for [" +
-          aStyleSheetIndex + ", " + aLine + "]");
-
-  // Editors are not ready, so wait for them.
-  if (!SEC.editors.length) {
-    info("Editor is not ready, waiting before doing check.");
-    SEC.addChromeListener({
-      onEditorAdded: function onEditorAdded(aChrome, aEditor) {
-        info("Editor loaded now. Removing listener and doing check.");
-        aChrome.removeChromeListener(this);
-        executeSoon(function() {
-          doCheck(aEditor);
-        });
-      }
-    });
-  }
-  // Execute soon so that selectedStyleSheetIndex has correct value.
-  else {
-    info("Editor is defined, opening the desired editor for now and " +
-         "checking later if it is correct");
-    for (let aEditor of SEC.editors) {
-      if (aEditor.styleSheetIndex == aStyleSheetIndex) {
-        doCheck(aEditor);
-        break;
-      }
-    }
-  }
-}
-
 let observer = {
-  observe: function(aSubject, aTopic, aData) {
+  observe: function(aSubject, aTopic, aData)
+  {
     if (aTopic != "domwindowopened") {
       return;
     }
     Services.ww.unregisterNotification(observer);
     info("Style Editor window was opened in response to clicking " +
          "the location node");
 
+    function sheetForNode(aNode)
+    {
+      let href = aNode.getAttribute("title");
+      let sheet, i = 0;
+      while((sheet = content.document.styleSheets[i++])) {
+        if (sheet.href == href) {
+          return sheet;
+        }
+      }
+      ok(false, "no sheet found");
+    }
+
     executeSoon(function() {
-      styleEditorWin = window.StyleEditor
-                             .StyleEditorManager
-                             .getEditorForWindow(content.window);
-      ok(styleEditorWin, "Style Editor Window is defined");
+      let styleEditorWin = window.StyleEditor.StyleEditorManager
+                          .getEditorForWindow(content.window);
+      ok(styleEditorWin, "Style Editor window is defined");
+
       waitForFocus(function() {
-        checkStyleEditorForSheetAndLine(0, 7, function() {
-          checkStyleEditorForSheetAndLine(1, 6, function() {
+        SEC = styleEditorWin.styleEditorChrome;
+        ok(SEC, "Style Editor Chrome is defined");
+
+        let sheet = sheetForNode(nodes[0]);
+        checkStyleEditorForSheetAndLine(sheet, 7, function() {
+          let sheet = sheetForNode(nodes[1]);
+          EventUtils.sendMouseEvent({ type: "click" }, nodes[1]);
+          checkStyleEditorForSheetAndLine(sheet, 6, function() {
             window.StyleEditor.toggle();
-            styleEditorWin = null;
             finishTest();
           });
-          EventUtils.sendMouseEvent({ type: "click" }, nodes[1]);
         });
       }, styleEditorWin);
     });
   }
 };
+
+function checkStyleEditorForSheetAndLine(aStyleSheet, aLine, aCallback)
+{
+  let editor = null;
+
+  let performLineCheck = {
+    name: "source editor load",
+    validatorFn: function()
+    {
+      return editor.sourceEditor;
+    },
+    successFn: function()
+    {
+      is(editor.sourceEditor.getCaretPosition().line, aLine,
+         "correct line is selected");
+      is(SEC.selectedStyleSheetIndex, editor.styleSheetIndex,
+         "correct stylesheet is selected in the editor");
+
+      executeSoon(aCallback);
+    },
+    failureFn: aCallback,
+  };
+
+  waitForSuccess({
+    name: "editor for stylesheet",
+    validatorFn: function()
+    {
+      for (let item of SEC.editors) {
+        if (item.styleSheet == aStyleSheet) {
+          editor = item;
+          return true;
+        }
+      }
+      return false;
+    },
+    successFn: function()
+    {
+      waitForSuccess(performLineCheck);
+    },
+    failureFn: finishTest,
+  });
+}