Bug 728926 - Intermittent failure in browser_dbg_script-switching.js | The correct script was loaded initially. | The first script is displayed. r=rcampbell
authorMihai Sucan <mihai.sucan@gmail.com>
Thu, 05 Apr 2012 16:00:05 +0300
changeset 94542 5d654a428c971c877dc9bf72727f4c47004e5e3e
parent 94541 9f82d9ab3f1fa6da0058e09a68c3a9263acad720
child 94543 7e22d83d5c6ce2124f2c8363144230c9a1f3d2c2
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrcampbell
bugs728926
milestone14.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 728926 - Intermittent failure in browser_dbg_script-switching.js | The correct script was loaded initially. | The first script is displayed. r=rcampbell
browser/devtools/debugger/test/browser_dbg_script-switching.js
--- a/browser/devtools/debugger/test/browser_dbg_script-switching.js
+++ b/browser/devtools/debugger/test/browser_dbg_script-switching.js
@@ -15,94 +15,114 @@ let SourceEditor = tempScope.SourceEdito
 var gPane = null;
 var gTab = null;
 var gDebuggee = null;
 var gDebugger = null;
 var gScripts = null;
 
 function test()
 {
+  let scriptShown = false;
+  let framesAdded = false;
+
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.debuggerWindow;
 
-    testScriptsDisplay();
+    gPane.activeThread.addOneTimeListener("framesadded", function() {
+      framesAdded = true;
+      runTest();
+    });
+
+    gDebuggee.firstCall();
   });
+
+  window.addEventListener("Debugger:ScriptShown", function _onEvent(aEvent) {
+    let url = aEvent.detail.url;
+    if (url.indexOf("-02.js") != -1) {
+      scriptShown = true;
+      window.removeEventListener(aEvent.type, _onEvent);
+      runTest();
+    }
+  });
+
+  function runTest()
+  {
+    if (scriptShown && framesAdded) {
+      Services.tm.currentThread.dispatch({ run: testScriptsDisplay }, 0);
+    }
+  }
 }
 
 function testScriptsDisplay() {
-  gPane.activeThread.addOneTimeListener("framesadded", function() {
-    Services.tm.currentThread.dispatch({ run: function() {
-      gScripts = gDebugger.DebuggerView.Scripts._scripts;
+  gScripts = gDebugger.DebuggerView.Scripts._scripts;
 
-      is(gDebugger.StackFrames.activeThread.state, "paused",
-        "Should only be getting stack frames while paused.");
+  is(gDebugger.StackFrames.activeThread.state, "paused",
+    "Should only be getting stack frames while paused.");
 
-      is(gScripts.itemCount, 2, "Found the expected number of scripts.");
+  is(gScripts.itemCount, 2, "Found the expected number of scripts.");
 
-      for (let i = 0; i < gScripts.itemCount; i++) {
-        info("label: " + i + " " + gScripts.getItemAtIndex(i).getAttribute("label"));
-      }
+  for (let i = 0; i < gScripts.itemCount; i++) {
+    info("label: " + i + " " + gScripts.getItemAtIndex(i).getAttribute("label"));
+  }
 
-      let label1 = "test-script-switching-01.js";
-      let label2 = "test-script-switching-02.js";
-
-      ok(gDebugger.DebuggerView.Scripts.contains(EXAMPLE_URL +
-        label1), "First script url is incorrect.");
-      ok(gDebugger.DebuggerView.Scripts.contains(EXAMPLE_URL +
-        label2), "Second script url is incorrect.");
+  let label1 = "test-script-switching-01.js";
+  let label2 = "test-script-switching-02.js";
 
-      ok(gDebugger.DebuggerView.Scripts.containsLabel(
-        label1), "First script label is incorrect.");
-      ok(gDebugger.DebuggerView.Scripts.containsLabel(
-        label2), "Second script label is incorrect.");
+  ok(gDebugger.DebuggerView.Scripts.contains(EXAMPLE_URL +
+    label1), "First script url is incorrect.");
+  ok(gDebugger.DebuggerView.Scripts.contains(EXAMPLE_URL +
+    label2), "Second script url is incorrect.");
 
-
-      ok(gDebugger.editor.getText().search(/debugger/) != -1,
-        "The correct script was loaded initially.");
+  ok(gDebugger.DebuggerView.Scripts.containsLabel(
+    label1), "First script label is incorrect.");
+  ok(gDebugger.DebuggerView.Scripts.containsLabel(
+    label2), "Second script label is incorrect.");
 
-      is(gDebugger.editor.getDebugLocation(), 5,
-         "editor debugger location is correct.");
+  ok(gDebugger.editor.getText().search(/debugger/) != -1,
+    "The correct script was loaded initially.");
+
+  is(gDebugger.editor.getDebugLocation(), 5,
+     "editor debugger location is correct.");
 
-      gDebugger.editor.addEventListener(SourceEditor.EVENTS.TEXT_CHANGED,
-                                        function onChange() {
-        gDebugger.editor.removeEventListener(SourceEditor.EVENTS.TEXT_CHANGED,
-                                             onChange);
-        testSwitchPaused();
-      });
-      gScripts.selectedIndex = 0;
-      gDebugger.SourceScripts.onChange({ target: gScripts });
-    }}, 0);
+  window.addEventListener("Debugger:ScriptShown", function _onEvent(aEvent) {
+    let url = aEvent.detail.url;
+    if (url.indexOf("-01.js") != -1) {
+      window.removeEventListener(aEvent.type, _onEvent);
+      testSwitchPaused();
+    }
   });
 
-  gDebuggee.firstCall();
+  gDebugger.DebuggerView.Scripts.selectScript(EXAMPLE_URL + label1);
 }
 
 function testSwitchPaused()
 {
   ok(gDebugger.editor.getText().search(/debugger/) == -1,
     "The second script is no longer displayed.");
 
   ok(gDebugger.editor.getText().search(/firstCall/) != -1,
     "The first script is displayed.");
 
   is(gDebugger.editor.getDebugLocation(), -1,
      "editor debugger location has been cleared.");
 
   gDebugger.StackFrames.activeThread.resume(function() {
-    gDebugger.editor.addEventListener(SourceEditor.EVENTS.TEXT_CHANGED,
-                                      function onSecondChange() {
-      gDebugger.editor.removeEventListener(SourceEditor.EVENTS.TEXT_CHANGED,
-                                           onSecondChange);
-      testSwitchRunning();
+    window.addEventListener("Debugger:ScriptShown", function _onEvent(aEvent) {
+      let url = aEvent.detail.url;
+      if (url.indexOf("-02.js") != -1) {
+        window.removeEventListener(aEvent.type, _onEvent);
+        testSwitchRunning();
+      }
     });
-    gScripts.selectedIndex = 1;
-    gDebugger.SourceScripts.onChange({ target: gScripts });
+
+    gDebugger.DebuggerView.Scripts.selectScript(EXAMPLE_URL +
+                                                "test-script-switching-02.js");
   });
 }
 
 function testSwitchRunning()
 {
   ok(gDebugger.editor.getText().search(/debugger/) != -1,
     "The second script is displayed again.");