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 bogus source maps don't break debugging. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_minified_bogus_map.html"; michael@0: const JS_URL = EXAMPLE_URL + "code_math_bogus_map.min.js"; michael@0: michael@0: // This test causes an error to be logged in the console, which appears in TBPL michael@0: // logs, so we are disabling that here. michael@0: let { DevToolsUtils } = Cu.import("resource://gre/modules/devtools/DevToolsUtils.jsm", {}); michael@0: DevToolsUtils.reportingDisabled = true; michael@0: michael@0: let gPanel, gDebugger, gFrames, gSources, gPrefs, gOptions; michael@0: michael@0: function test() { michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: gPanel = aPanel; michael@0: gDebugger = gPanel.panelWin; michael@0: gFrames = gDebugger.DebuggerView.StackFrames; michael@0: gSources = gDebugger.DebuggerView.Sources; michael@0: gPrefs = gDebugger.Prefs; michael@0: gOptions = gDebugger.DebuggerView.Options; michael@0: michael@0: is(gPrefs.pauseOnExceptions, false, michael@0: "The pause-on-exceptions pref should be disabled by default."); michael@0: isnot(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true", michael@0: "The pause-on-exceptions menu item should not be checked."); michael@0: michael@0: waitForSourceShown(gPanel, JS_URL) michael@0: .then(checkInitialSource) michael@0: .then(enablePauseOnExceptions) michael@0: .then(disableIgnoreCaughtExceptions) michael@0: .then(testSetBreakpoint) michael@0: .then(reloadPage) michael@0: .then(testHitBreakpoint) michael@0: .then(enableIgnoreCaughtExceptions) michael@0: .then(disablePauseOnExceptions) 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: } michael@0: michael@0: function checkInitialSource() { michael@0: isnot(gSources.selectedValue.indexOf(".min.js"), -1, michael@0: "The debugger should show the minified js file."); michael@0: } michael@0: michael@0: function enablePauseOnExceptions() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gDebugger.gThreadClient.addOneTimeListener("resumed", () => { michael@0: is(gPrefs.pauseOnExceptions, true, michael@0: "The pause-on-exceptions pref should now be enabled."); michael@0: michael@0: ok(true, "Pausing on exceptions was enabled."); michael@0: deferred.resolve(); michael@0: }); michael@0: michael@0: gOptions._pauseOnExceptionsItem.setAttribute("checked", "true"); michael@0: gOptions._togglePauseOnExceptions(); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function disableIgnoreCaughtExceptions() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gDebugger.gThreadClient.addOneTimeListener("resumed", () => { michael@0: is(gPrefs.ignoreCaughtExceptions, false, michael@0: "The ignore-caught-exceptions pref should now be disabled."); michael@0: michael@0: ok(true, "Ignore caught exceptions was disabled."); michael@0: deferred.resolve(); michael@0: }); michael@0: michael@0: gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "false"); michael@0: gOptions._toggleIgnoreCaughtExceptions(); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testSetBreakpoint() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gDebugger.gThreadClient.setBreakpoint({ url: JS_URL, line: 3, column: 61 }, aResponse => { michael@0: ok(!aResponse.error, michael@0: "Should be able to set a breakpoint in a js file."); michael@0: ok(!aResponse.actualLocation, michael@0: "Should be able to set a breakpoint on line 3 and column 61."); michael@0: michael@0: deferred.resolve(); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function reloadPage() { michael@0: let loaded = waitForSourceAndCaret(gPanel, ".js", 3); michael@0: gDebugger.DebuggerController._target.activeTab.reload(); michael@0: return loaded.then(() => ok(true, "Page was reloaded and execution resumed.")); michael@0: } michael@0: michael@0: function testHitBreakpoint() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gDebugger.gThreadClient.resume(aResponse => { michael@0: ok(!aResponse.error, "Shouldn't get an error resuming."); michael@0: is(aResponse.type, "resumed", "Type should be 'resumed'."); michael@0: michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES).then(() => { michael@0: is(gFrames.itemCount, 1, "Should have one frame."); michael@0: michael@0: gDebugger.gThreadClient.resume(deferred.resolve); michael@0: }); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function enableIgnoreCaughtExceptions() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gDebugger.gThreadClient.addOneTimeListener("resumed", () => { michael@0: is(gPrefs.ignoreCaughtExceptions, true, michael@0: "The ignore-caught-exceptions pref should now be enabled."); michael@0: michael@0: ok(true, "Ignore caught exceptions was enabled."); michael@0: deferred.resolve(); michael@0: }); michael@0: michael@0: gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "true"); michael@0: gOptions._toggleIgnoreCaughtExceptions(); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function disablePauseOnExceptions() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gDebugger.gThreadClient.addOneTimeListener("resumed", () => { michael@0: is(gPrefs.pauseOnExceptions, false, michael@0: "The pause-on-exceptions pref should now be disabled."); michael@0: michael@0: ok(true, "Pausing on exceptions was disabled."); michael@0: deferred.resolve(); michael@0: }); michael@0: michael@0: gOptions._pauseOnExceptionsItem.setAttribute("checked", "false"); michael@0: gOptions._togglePauseOnExceptions(); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: gPanel = null; michael@0: gDebugger = null; michael@0: gFrames = null; michael@0: gSources = null; michael@0: gPrefs = null; michael@0: gOptions = null; michael@0: DevToolsUtils.reportingDisabled = false; michael@0: });