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: * Tests that the debugger commands work as they should. michael@0: */ michael@0: michael@0: const TEST_URI = EXAMPLE_URL + "doc_cmd-dbg.html"; michael@0: michael@0: function test() { michael@0: return Task.spawn(function() { michael@0: let options = yield helpers.openTab(TEST_URI); michael@0: yield helpers.openToolbar(options); michael@0: michael@0: yield helpers.audit(options, [{ michael@0: setup: "dbg open", michael@0: exec: { output: "" } michael@0: }]); michael@0: michael@0: let [gTab, gDebuggee, gPanel] = yield initDebugger(gBrowser.selectedTab); michael@0: let gDebugger = gPanel.panelWin; michael@0: let gThreadClient = gDebugger.gThreadClient; michael@0: michael@0: yield helpers.audit(options, [{ michael@0: setup: "dbg list", michael@0: exec: { output: /doc_cmd-dbg.html/ } michael@0: }]); michael@0: michael@0: let button = gDebuggee.document.querySelector("input[type=button]"); michael@0: let output = gDebuggee.document.querySelector("input[type=text]"); michael@0: michael@0: let cmd = function(aTyped, aState) { michael@0: return promise.all([ michael@0: waitForThreadEvents(gPanel, aState), michael@0: helpers.audit(options, [{ setup: aTyped, exec: { output: "" } }]) michael@0: ]); michael@0: }; michael@0: michael@0: let click = function(aElement, aState) { michael@0: return promise.all([ michael@0: waitForThreadEvents(gPanel, aState), michael@0: executeSoon(() => EventUtils.sendMouseEvent({ type: "click" }, aElement, gDebuggee)) michael@0: ]); michael@0: } michael@0: michael@0: yield cmd("dbg interrupt", "paused"); michael@0: is(gThreadClient.state, "paused", "Debugger is paused."); michael@0: michael@0: yield cmd("dbg continue", "resumed"); michael@0: isnot(gThreadClient.state, "paused", "Debugger has continued."); michael@0: michael@0: yield click(button, "paused"); michael@0: is(gThreadClient.state, "paused", "Debugger is paused again."); michael@0: michael@0: yield cmd("dbg step in", "paused"); michael@0: yield cmd("dbg step in", "paused"); michael@0: yield cmd("dbg step in", "paused"); michael@0: is(output.value, "step in", "Debugger stepped in."); michael@0: michael@0: yield cmd("dbg step over", "paused"); michael@0: is(output.value, "step over", "Debugger stepped over."); michael@0: michael@0: yield cmd("dbg step out", "paused"); michael@0: is(output.value, "step out", "Debugger stepped out."); michael@0: michael@0: yield cmd("dbg continue", "paused"); michael@0: is(output.value, "dbg continue", "Debugger continued."); michael@0: michael@0: let closeDebugger = function() { michael@0: let deferred = promise.defer(); michael@0: michael@0: helpers.audit(options, [{ michael@0: setup: "dbg close", michael@0: exec: { output: "" } michael@0: }]) michael@0: .then(() => { michael@0: let toolbox = gDevTools.getToolbox(options.target); michael@0: if (!toolbox) { michael@0: ok(true, "Debugger is closed."); michael@0: deferred.resolve(); michael@0: } else { michael@0: toolbox.on("destroyed", () => { michael@0: ok(true, "Debugger just closed."); michael@0: deferred.resolve(); michael@0: }); michael@0: } michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: }; michael@0: michael@0: // We close the debugger twice to ensure 'dbg close' doesn't error when michael@0: // toolbox is already closed. See bug 884638 for more info. michael@0: yield closeDebugger(); michael@0: yield closeDebugger(); michael@0: yield helpers.closeToolbar(options); michael@0: yield helpers.closeTab(options); michael@0: michael@0: }).then(finish, helpers.handleError); michael@0: }