Bug 961621 - Fix for intermittent browser_webconsole_bug_766001_JS_Console_in_Debugger.js | Timed out while waiting for: correct source and line test for debugger for index 2; r=me
authorMihai Sucan <mihai.sucan@gmail.com>
Mon, 20 Jan 2014 23:09:18 +0200
changeset 164443 64e3364098fd
parent 164354 cdc0ab2c0cba
child 164444 6038ead525b2
push id26047
push userryanvm@gmail.com
push date2014-01-21 20:18 +0000
treeherdermozilla-central@dcb0a6baeadb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs961621
milestone29.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 961621 - Fix for intermittent browser_webconsole_bug_766001_JS_Console_in_Debugger.js | Timed out while waiting for: correct source and line test for debugger for index 2; r=me
browser/devtools/webconsole/hudservice.js
browser/devtools/webconsole/test/browser_webconsole_bug_766001_JS_Console_in_Debugger.js
browser/devtools/webconsole/test/head.js
--- a/browser/devtools/webconsole/hudservice.js
+++ b/browser/devtools/webconsole/hudservice.js
@@ -499,17 +499,20 @@ WebConsole.prototype = {
     let toolbox = gDevTools.getToolbox(this.target);
     if (!toolbox) {
       this.viewSource(aSourceURL, aSourceLine);
       return;
     }
 
     let showSource = ({ DebuggerView }) => {
       if (DebuggerView.Sources.containsValue(aSourceURL)) {
-        DebuggerView.setEditorLocation(aSourceURL, aSourceLine, { noDebug: true });
+        DebuggerView.setEditorLocation(aSourceURL, aSourceLine,
+                                       { noDebug: true }).then(() => {
+          this.ui.emit("source-in-debugger-opened");
+        });
         return;
       }
       toolbox.selectTool("webconsole");
       this.viewSource(aSourceURL, aSourceLine);
     }
 
     // If the Debugger was already open, switch to it and try to show the
     // source immediately. Otherwise, initialize it and wait for the sources
--- a/browser/devtools/webconsole/test/browser_webconsole_bug_766001_JS_Console_in_Debugger.js
+++ b/browser/devtools/webconsole/test/browser_webconsole_bug_766001_JS_Console_in_Debugger.js
@@ -2,115 +2,72 @@
 /* ***** 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-766001-js-console-links.html";
 
-let nodes, dbg, toolbox, target, index = 0, src, line;
+function test() {
+  let hud;
 
-function test()
-{
-  expectUncaughtException();
   requestLongerTimeout(2);
-  addTab(TEST_URI);
-  browser.addEventListener("load", function onLoad() {
-    browser.removeEventListener("load", onLoad, true);
-    openConsole(null, testViewSource);
-  }, true);
-}
+  Task.spawn(runner).then(finishTest);
+
+  function* runner() {
+    expectUncaughtException();
+    let {tab} = yield loadTab(TEST_URI);
+    hud = yield openConsole(tab);
 
-function testViewSource(aHud)
-{
-  registerCleanupFunction(function() {
-    nodes = dbg = toolbox = target = index = src = line = null;
-  });
+    let [exceptionRule, consoleRule] = yield waitForMessages({
+      webconsole: hud,
+      messages: [{
+        text: "document.bar",
+        category: CATEGORY_JS,
+        severity: SEVERITY_ERROR,
+      },
+      {
+        text: "Blah Blah",
+        category: CATEGORY_WEBDEV,
+        severity: SEVERITY_LOG,
+      }],
+    });
 
-  waitForMessages({
-    webconsole: aHud,
-    messages: [{
-      text: "document.bar",
-      category: CATEGORY_JS,
-      severity: SEVERITY_ERROR,
-    },
-    {
-      text: "Blah Blah",
-      category: CATEGORY_WEBDEV,
-      severity: SEVERITY_LOG,
-    }],
-  }).then(([exceptionRule, consoleRule]) => {
     let exceptionMsg = [...exceptionRule.matched][0];
     let consoleMsg = [...consoleRule.matched][0];
-    nodes = [exceptionMsg.querySelector(".location"),
-             consoleMsg.querySelector(".location")];
+    let nodes = [exceptionMsg.querySelector(".location"),
+                 consoleMsg.querySelector(".location")];
     ok(nodes[0], ".location node for the exception message");
     ok(nodes[1], ".location node for the console message");
 
-    target = TargetFactory.forTab(gBrowser.selectedTab);
-    toolbox = gDevTools.getToolbox(target);
-    toolbox.once("jsdebugger-selected", checkLineAndClickNext);
-
-    EventUtils.sendMouseEvent({ type: "click" }, nodes[index%2]);
-  });
-}
-
-function checkLineAndClickNext(aEvent, aPanel)
-{
-  if (index == 3) {
-    finishTest();
-    return;
-  }
-  info(aEvent + " event fired for index " + index);
+    for (let i = 0; i < nodes.length; i++) {
+      yield checkClickOnNode(i, nodes[i]);
+      yield gDevTools.showToolbox(hud.target, "webconsole");
+    }
 
-  dbg = aPanel;
-
-  src = nodes[index%2].getAttribute("title");
-  ok(src, "source url found for index " + index);
-  line = nodes[index%2].sourceLine;
-  ok(line, "found source line for index " + index);
+    // check again the first node.
+    yield checkClickOnNode(0, nodes[0]);
+  }
 
-  info("Waiting for the correct script to be selected for index " + index);
-  dbg.panelWin.on(dbg.panelWin.EVENTS.SOURCE_SHOWN, onSource);
-}
+  function* checkClickOnNode(index, node) {
+    info("checking click on node index " + index);
 
-function onSource(aEvent, aSource) {
-  if (aSource.url != src) {
-    return;
-  }
-  dbg.panelWin.off(dbg.panelWin.EVENTS.SOURCE_SHOWN, onSource);
+    let url = node.getAttribute("title");
+    ok(url, "source url found for index " + index);
 
-  ok(true, "Correct script is selected for index " + index);
-
-  checkCorrectLine(function() {
-    gDevTools.showToolbox(target, "webconsole").then(function() {
-      index++;
-      info("webconsole selected for index " + index);
+    let line = node.sourceLine;
+    ok(line, "found source line for index " + index);
 
-      toolbox.once("jsdebugger-selected", checkLineAndClickNext);
-
-      EventUtils.sendMouseEvent({ type: "click" }, nodes[index%2]);
+    executeSoon(() => {
+      EventUtils.sendMouseEvent({ type: "click" }, node);
     });
-  });
-}
 
-function checkCorrectLine(aCallback)
-{
-  waitForSuccess({
-    name: "correct source and line test for debugger for index " + index,
-    validatorFn: function()
-    {
-      let debuggerView = dbg.panelWin.DebuggerView;
-      if (debuggerView.editor &&
-          debuggerView.editor.getCursor().line == line - 1) {
-        return true;
-      }
-      return false;
-    },
-    successFn: function()
-    {
-      aCallback && executeSoon(aCallback);
-    },
-    failureFn: finishTest,
-    timeout: 10000,
-  });
+    yield hud.ui.once("source-in-debugger-opened", checkLine.bind(null, url, line));
+  }
+
+  function* checkLine(url, line) {
+    let toolbox = yield gDevTools.getToolbox(hud.target);
+    let {panelWin: { DebuggerView: view }} = toolbox.getPanel("jsdebugger");
+    is(view.Sources.selectedValue, url, "expected source url");
+    is(view.editor.getCursor().line, line - 1, "expected source line");
+  }
 }
--- a/browser/devtools/webconsole/test/head.js
+++ b/browser/devtools/webconsole/test/head.js
@@ -62,16 +62,30 @@ let tab, browser, hudId, hud, hudBox, fi
 
 function addTab(aURL)
 {
   gBrowser.selectedTab = gBrowser.addTab(aURL);
   tab = gBrowser.selectedTab;
   browser = gBrowser.getBrowserForTab(tab);
 }
 
+function loadTab(url) {
+  let deferred = promise.defer();
+
+  let tab = gBrowser.selectedTab = gBrowser.addTab(url);
+  let browser = gBrowser.getBrowserForTab(tab);
+
+  browser.addEventListener("load", function onLoad() {
+    browser.removeEventListener("load", onLoad, true);
+    deferred.resolve({tab: tab, browser: browser});
+  }, true);
+
+  return deferred.promise;
+}
+
 function afterAllTabsLoaded(callback, win) {
   win = win || window;
 
   let stillToLoad = 0;
 
   function onLoad() {
     this.removeEventListener("load", onLoad, true);
     stillToLoad--;