From 5844d7a3bc8cea2d65ee167f8283227f88adb8e1 Mon Sep 17 00:00:00 2001 From: Mihai Sucan Date: Thu, 5 Apr 2012 16:00:05 +0300 Subject: [PATCH] Bug 728926 - Intermittent failure in browser_dbg_script-switching.js | The correct script was loaded initially. | The first script is displayed. r=rcampbell --- .../test/browser_dbg_script-switching.js | 104 +++++++++++------- 1 file changed, 62 insertions(+), 42 deletions(-) diff --git a/browser/devtools/debugger/test/browser_dbg_script-switching.js b/browser/devtools/debugger/test/browser_dbg_script-switching.js index 9bdb87fded52..aa8ef71183ee 100644 --- a/browser/devtools/debugger/test/browser_dbg_script-switching.js +++ b/browser/devtools/debugger/test/browser_dbg_script-switching.js @@ -20,62 +20,80 @@ 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"; + 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."); + 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.DebuggerView.Scripts.containsLabel( - label1), "First script label is incorrect."); - ok(gDebugger.DebuggerView.Scripts.containsLabel( - label2), "Second script label is incorrect."); + ok(gDebugger.DebuggerView.Scripts.containsLabel( + label1), "First script label is incorrect."); + ok(gDebugger.DebuggerView.Scripts.containsLabel( + label2), "Second script label is incorrect."); + ok(gDebugger.editor.getText().search(/debugger/) != -1, + "The correct script was loaded initially."); - ok(gDebugger.editor.getText().search(/debugger/) != -1, - "The correct script was loaded initially."); + is(gDebugger.editor.getDebugLocation(), 5, + "editor debugger location is correct."); - 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() @@ -90,14 +108,16 @@ function testSwitchPaused() "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"); }); }