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 switching the displayed source in the UI works as advertised. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_script-switching-02.html"; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gEditor, gSources; 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: michael@0: waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) michael@0: .then(testSourcesDisplay) michael@0: .then(testSwitchPaused1) michael@0: .then(testSwitchPaused2) michael@0: .then(testSwitchRunning) michael@0: .then(() => resumeDebuggerThenCloseAndFinish(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: let gLabel1 = "code_script-switching-01.js"; michael@0: let gLabel2 = "code_script-switching-02.js"; michael@0: let gParams = "?foo=bar,baz|lol"; michael@0: michael@0: function testSourcesDisplay() { michael@0: let deferred = promise.defer(); michael@0: michael@0: is(gSources.itemCount, 2, michael@0: "Found the expected number of sources."); michael@0: michael@0: ok(gSources.containsValue(EXAMPLE_URL + gLabel1), michael@0: "First source url is incorrect."); michael@0: ok(gSources.containsValue(EXAMPLE_URL + gLabel2 + gParams), michael@0: "Second source url is incorrect."); michael@0: michael@0: ok(gSources.getItemForAttachment(e => e.label == gLabel1), michael@0: "First source label is incorrect."); michael@0: ok(gSources.getItemForAttachment(e => e.label == gLabel2), michael@0: "Second source label is incorrect."); michael@0: michael@0: ok(gSources.selectedItem, michael@0: "There should be a selected item in the sources pane."); michael@0: is(gSources.selectedValue, EXAMPLE_URL + gLabel2 + gParams, michael@0: "The selected value is the sources pane is incorrect."); michael@0: michael@0: is(gEditor.getText().search(/firstCall/), -1, michael@0: "The first source is not displayed."); michael@0: is(gEditor.getText().search(/debugger/), 172, michael@0: "The second source is displayed."); michael@0: michael@0: ok(isCaretPos(gPanel, 1), michael@0: "Editor caret location is correct."); 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 debugger location is correct."); michael@0: ok(gEditor.hasLineClass(0, "debug-line"), michael@0: "The debugged line is highlighted appropriately."); michael@0: michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve); michael@0: gSources.selectedItem = e => e.attachment.label == gLabel1; michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testSwitchPaused1() { michael@0: let deferred = promise.defer(); michael@0: michael@0: ok(gSources.selectedItem, michael@0: "There should be a selected item in the sources pane."); michael@0: is(gSources.selectedValue, EXAMPLE_URL + gLabel1, michael@0: "The selected value is the sources pane is incorrect."); michael@0: 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: // The editor's debug location takes a tick to update. michael@0: executeSoon(() => { michael@0: ok(isCaretPos(gPanel, 1), michael@0: "Editor caret location is correct."); michael@0: michael@0: is(gEditor.getDebugLocation(), null, michael@0: "Editor debugger location is correct."); michael@0: ok(!gEditor.hasLineClass(5, "debug-line"), michael@0: "The debugged line highlight was removed."); michael@0: michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve); michael@0: gSources.selectedItem = e => e.attachment.label == gLabel2; michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testSwitchPaused2() { michael@0: let deferred = promise.defer(); michael@0: michael@0: ok(gSources.selectedItem, michael@0: "There should be a selected item in the sources pane."); michael@0: is(gSources.selectedValue, EXAMPLE_URL + gLabel2 + gParams, michael@0: "The selected value is the sources pane is incorrect."); michael@0: michael@0: is(gEditor.getText().search(/firstCall/), -1, michael@0: "The first source is not displayed."); michael@0: is(gEditor.getText().search(/debugger/), 172, michael@0: "The second source is displayed."); michael@0: michael@0: // The editor's debug location takes a tick to update. michael@0: executeSoon(() => { michael@0: ok(isCaretPos(gPanel, 1), michael@0: "Editor caret location is correct."); michael@0: is(gEditor.getDebugLocation(), 0, michael@0: "Editor debugger location is correct."); michael@0: ok(gEditor.hasLineClass(0, "debug-line"), michael@0: "The debugged line is highlighted appropriately."); michael@0: michael@0: // Step out three times. michael@0: waitForThreadEvents(gPanel, "paused").then(() => { michael@0: waitForThreadEvents(gPanel, "paused").then(() => { michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve); michael@0: gDebugger.gThreadClient.stepOut(); michael@0: }); michael@0: gDebugger.gThreadClient.stepOut(); michael@0: }); michael@0: gDebugger.gThreadClient.stepOut(); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testSwitchRunning() { michael@0: let deferred = promise.defer(); michael@0: michael@0: ok(gSources.selectedItem, michael@0: "There should be a selected item in the sources pane."); michael@0: is(gSources.selectedValue, EXAMPLE_URL + gLabel1, michael@0: "The selected value is the sources pane is incorrect."); michael@0: 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: // The editor's debug location takes a tick to update. michael@0: executeSoon(() => { michael@0: ok(isCaretPos(gPanel, 1), michael@0: "Editor caret location is correct."); michael@0: is(gEditor.getDebugLocation(), 0, michael@0: "Editor debugger location is correct."); michael@0: ok(gEditor.hasLineClass(0, "debug-line"), michael@0: "The debugged line is highlighted appropriately."); michael@0: michael@0: deferred.resolve(); michael@0: }); 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: gLabel1 = null; michael@0: gLabel2 = null; michael@0: gParams = null; michael@0: });