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: * Test that switching between stack frames properly sets the current debugger michael@0: * location in the source editor. 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; 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: michael@0: waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) michael@0: .then(initialChecks) michael@0: .then(testNewestTwoFrames) michael@0: .then(testOldestTwoFrames) michael@0: .then(testAfterResume) michael@0: .then(() => closeDebuggerAndFinish(gPanel)) michael@0: .then(null, aError => { michael@0: ok(false, "Got an error: " + aError.message + "\n" + aError.stack); michael@0: }); michael@0: michael@0: gDebuggee.firstCall(); michael@0: }); michael@0: } michael@0: michael@0: function initialChecks() { michael@0: is(gDebugger.gThreadClient.state, "paused", michael@0: "Should only be getting stack frames while paused."); michael@0: is(gFrames.itemCount, 4, michael@0: "Should have four frames."); michael@0: is(gClassicFrames.itemCount, 4, michael@0: "Should also have four frames in the mirrored view."); michael@0: } michael@0: michael@0: function testNewestTwoFrames() { michael@0: let deferred = promise.defer(); michael@0: michael@0: is(gFrames.selectedIndex, 3, michael@0: "Newest frame should be selected by default."); michael@0: is(gClassicFrames.selectedIndex, 0, michael@0: "Newest frame should be selected in the mirrored view as well."); michael@0: is(gSources.selectedIndex, 1, michael@0: "The second source is selected in the widget."); michael@0: ok(isCaretPos(gPanel, 1), michael@0: "Editor caret location is correct (1)."); michael@0: michael@0: // The editor's debug location takes a tick to update. michael@0: executeSoon(() => { michael@0: is(gEditor.getDebugLocation(), 0, michael@0: "Editor debug location is correct."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: gFrames.getItemAtIndex(2).target, michael@0: gDebugger); michael@0: michael@0: is(gFrames.selectedIndex, 2, michael@0: "Third frame should be selected after click."); michael@0: is(gClassicFrames.selectedIndex, 1, michael@0: "Third frame should be selected in the mirrored view as well."); michael@0: is(gSources.selectedIndex, 1, michael@0: "The second source is still selected in the widget."); michael@0: ok(isCaretPos(gPanel, 6), michael@0: "Editor caret location is correct (2)."); michael@0: michael@0: // The editor's debug location takes a tick to update. michael@0: executeSoon(() => { michael@0: is(gEditor.getDebugLocation(), 5, michael@0: "Editor debug location is correct."); michael@0: michael@0: deferred.resolve(); michael@0: }); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testOldestTwoFrames() { michael@0: let deferred = promise.defer(); michael@0: michael@0: waitForSourceAndCaret(gPanel, "-01.js", 1).then(waitForTick).then(() => { michael@0: is(gFrames.selectedIndex, 1, michael@0: "Second frame should be selected after click."); michael@0: is(gClassicFrames.selectedIndex, 2, michael@0: "Second frame should be selected in the mirrored view as well."); michael@0: is(gSources.selectedIndex, 0, michael@0: "The first source is now selected in the widget."); michael@0: ok(isCaretPos(gPanel, 1), michael@0: "Editor caret location is correct (3)."); michael@0: michael@0: // The editor's debug location takes a tick to update. michael@0: executeSoon(() => { michael@0: is(gEditor.getDebugLocation(), 0, michael@0: "Editor debug location is correct."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: gFrames.getItemAtIndex(0).target, michael@0: gDebugger); michael@0: michael@0: is(gFrames.selectedIndex, 0, michael@0: "Oldest frame should be selected after click."); michael@0: is(gClassicFrames.selectedIndex, 3, michael@0: "Oldest frame should be selected in the mirrored view as well."); michael@0: is(gSources.selectedIndex, 0, michael@0: "The first source is still selected in the widget."); michael@0: ok(isCaretPos(gPanel, 5), michael@0: "Editor caret location is correct (4)."); michael@0: michael@0: // The editor's debug location takes a tick to update. michael@0: executeSoon(() => { michael@0: is(gEditor.getDebugLocation(), 4, michael@0: "Editor debug location is correct."); michael@0: michael@0: deferred.resolve(); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: gDebugger.document.querySelector("#stackframe-2"), michael@0: gDebugger); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testAfterResume() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gDebugger.once(gDebugger.EVENTS.AFTER_FRAMES_CLEARED, () => { michael@0: is(gFrames.itemCount, 0, michael@0: "Should have no frames after resume."); michael@0: is(gClassicFrames.itemCount, 0, michael@0: "Should have no frames in the mirrored view as well."); michael@0: ok(isCaretPos(gPanel, 5), michael@0: "Editor caret location is correct after resume."); michael@0: is(gEditor.getDebugLocation(), null, michael@0: "Editor debug location is correct after resume."); michael@0: michael@0: deferred.resolve(); michael@0: }, true); michael@0: michael@0: gDebugger.gThreadClient.resume(); michael@0: michael@0: return deferred.promise; 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: }); michael@0: