michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Make sure that after selecting a different stack frame, resuming reselects michael@0: * the topmost stackframe, loads the right source in the editor pane and michael@0: * highlights the proper line. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gEditor, gSources, gFrames, gClassicFrames, gToolbar; michael@0: michael@0: function test() { michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: gTab = aTab; michael@0: gDebuggee = aDebuggee; michael@0: gPanel = aPanel; michael@0: gDebugger = gPanel.panelWin; michael@0: gEditor = gDebugger.DebuggerView.editor; michael@0: gSources = gDebugger.DebuggerView.Sources; michael@0: gFrames = gDebugger.DebuggerView.StackFrames; michael@0: gClassicFrames = gDebugger.DebuggerView.StackFramesClassicList; michael@0: gToolbar = gDebugger.DebuggerView.Toolbar; michael@0: michael@0: waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1).then(performTest); michael@0: gDebuggee.firstCall(); michael@0: }); michael@0: } michael@0: michael@0: function performTest() { michael@0: return Task.spawn(function() { michael@0: yield selectBottomFrame(); michael@0: testBottomFrame(0); michael@0: michael@0: yield performStep("StepOver"); michael@0: testTopFrame(3); michael@0: michael@0: yield selectBottomFrame(); michael@0: testBottomFrame(4); michael@0: michael@0: yield performStep("StepIn"); michael@0: testTopFrame(2); michael@0: michael@0: yield selectBottomFrame(); michael@0: testBottomFrame(4); michael@0: michael@0: yield performStep("StepOut"); michael@0: testTopFrame(2); michael@0: michael@0: yield resumeDebuggerThenCloseAndFinish(gPanel); michael@0: }); michael@0: michael@0: function selectBottomFrame() { michael@0: let updated = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES); michael@0: gClassicFrames.selectedIndex = gClassicFrames.itemCount - 1; michael@0: return updated.then(waitForTick); michael@0: } michael@0: michael@0: function testBottomFrame(debugLocation) { michael@0: is(gFrames.selectedIndex, 0, michael@0: "Oldest frame should be selected after click."); michael@0: is(gClassicFrames.selectedIndex, gFrames.itemCount - 1, michael@0: "Oldest frame should also be selected in the mirrored view."); michael@0: is(gSources.selectedIndex, 0, michael@0: "The first source is now selected in the widget."); michael@0: is(gEditor.getText().search(/firstCall/), 118, michael@0: "The first source is displayed."); michael@0: is(gEditor.getText().search(/debugger/), -1, michael@0: "The second source is not displayed."); michael@0: michael@0: is(gEditor.getDebugLocation(), debugLocation, michael@0: "Editor debugger location is correct."); michael@0: ok(gEditor.hasLineClass(debugLocation, "debug-line"), michael@0: "The debugged line is highlighted appropriately."); michael@0: } michael@0: michael@0: function performStep(type) { michael@0: let updated = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES); michael@0: gToolbar["_on" + type + "Pressed"](); michael@0: return updated.then(waitForTick); michael@0: } michael@0: michael@0: function testTopFrame(frameIndex) { michael@0: is(gFrames.selectedIndex, frameIndex, michael@0: "Topmost frame should be selected after click."); michael@0: is(gClassicFrames.selectedIndex, gFrames.itemCount - frameIndex - 1, michael@0: "Topmost frame should also be selected in the mirrored view."); michael@0: is(gSources.selectedIndex, 1, michael@0: "The second source is now selected in the widget."); michael@0: is(gEditor.getText().search(/firstCall/), -1, michael@0: "The second source is displayed."); michael@0: is(gEditor.getText().search(/debugger/), 172, michael@0: "The first source is not displayed."); michael@0: } michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: gTab = null; michael@0: gDebuggee = null; michael@0: gPanel = null; michael@0: gDebugger = null; michael@0: gEditor = null; michael@0: gSources = null; michael@0: gFrames = null; michael@0: gClassicFrames = null; michael@0: gToolbar = null; michael@0: });