Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * Test that bogus source maps don't break debugging. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | const TAB_URL = EXAMPLE_URL + "doc_minified_bogus_map.html"; |
michael@0 | 9 | const JS_URL = EXAMPLE_URL + "code_math_bogus_map.min.js"; |
michael@0 | 10 | |
michael@0 | 11 | // This test causes an error to be logged in the console, which appears in TBPL |
michael@0 | 12 | // logs, so we are disabling that here. |
michael@0 | 13 | let { DevToolsUtils } = Cu.import("resource://gre/modules/devtools/DevToolsUtils.jsm", {}); |
michael@0 | 14 | DevToolsUtils.reportingDisabled = true; |
michael@0 | 15 | |
michael@0 | 16 | let gPanel, gDebugger, gFrames, gSources, gPrefs, gOptions; |
michael@0 | 17 | |
michael@0 | 18 | function test() { |
michael@0 | 19 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 20 | gPanel = aPanel; |
michael@0 | 21 | gDebugger = gPanel.panelWin; |
michael@0 | 22 | gFrames = gDebugger.DebuggerView.StackFrames; |
michael@0 | 23 | gSources = gDebugger.DebuggerView.Sources; |
michael@0 | 24 | gPrefs = gDebugger.Prefs; |
michael@0 | 25 | gOptions = gDebugger.DebuggerView.Options; |
michael@0 | 26 | |
michael@0 | 27 | is(gPrefs.pauseOnExceptions, false, |
michael@0 | 28 | "The pause-on-exceptions pref should be disabled by default."); |
michael@0 | 29 | isnot(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true", |
michael@0 | 30 | "The pause-on-exceptions menu item should not be checked."); |
michael@0 | 31 | |
michael@0 | 32 | waitForSourceShown(gPanel, JS_URL) |
michael@0 | 33 | .then(checkInitialSource) |
michael@0 | 34 | .then(enablePauseOnExceptions) |
michael@0 | 35 | .then(disableIgnoreCaughtExceptions) |
michael@0 | 36 | .then(testSetBreakpoint) |
michael@0 | 37 | .then(reloadPage) |
michael@0 | 38 | .then(testHitBreakpoint) |
michael@0 | 39 | .then(enableIgnoreCaughtExceptions) |
michael@0 | 40 | .then(disablePauseOnExceptions) |
michael@0 | 41 | .then(() => closeDebuggerAndFinish(gPanel)) |
michael@0 | 42 | .then(null, aError => { |
michael@0 | 43 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 44 | }); |
michael@0 | 45 | }); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | function checkInitialSource() { |
michael@0 | 49 | isnot(gSources.selectedValue.indexOf(".min.js"), -1, |
michael@0 | 50 | "The debugger should show the minified js file."); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | function enablePauseOnExceptions() { |
michael@0 | 54 | let deferred = promise.defer(); |
michael@0 | 55 | |
michael@0 | 56 | gDebugger.gThreadClient.addOneTimeListener("resumed", () => { |
michael@0 | 57 | is(gPrefs.pauseOnExceptions, true, |
michael@0 | 58 | "The pause-on-exceptions pref should now be enabled."); |
michael@0 | 59 | |
michael@0 | 60 | ok(true, "Pausing on exceptions was enabled."); |
michael@0 | 61 | deferred.resolve(); |
michael@0 | 62 | }); |
michael@0 | 63 | |
michael@0 | 64 | gOptions._pauseOnExceptionsItem.setAttribute("checked", "true"); |
michael@0 | 65 | gOptions._togglePauseOnExceptions(); |
michael@0 | 66 | |
michael@0 | 67 | return deferred.promise; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function disableIgnoreCaughtExceptions() { |
michael@0 | 71 | let deferred = promise.defer(); |
michael@0 | 72 | |
michael@0 | 73 | gDebugger.gThreadClient.addOneTimeListener("resumed", () => { |
michael@0 | 74 | is(gPrefs.ignoreCaughtExceptions, false, |
michael@0 | 75 | "The ignore-caught-exceptions pref should now be disabled."); |
michael@0 | 76 | |
michael@0 | 77 | ok(true, "Ignore caught exceptions was disabled."); |
michael@0 | 78 | deferred.resolve(); |
michael@0 | 79 | }); |
michael@0 | 80 | |
michael@0 | 81 | gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "false"); |
michael@0 | 82 | gOptions._toggleIgnoreCaughtExceptions(); |
michael@0 | 83 | |
michael@0 | 84 | return deferred.promise; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | function testSetBreakpoint() { |
michael@0 | 88 | let deferred = promise.defer(); |
michael@0 | 89 | |
michael@0 | 90 | gDebugger.gThreadClient.setBreakpoint({ url: JS_URL, line: 3, column: 61 }, aResponse => { |
michael@0 | 91 | ok(!aResponse.error, |
michael@0 | 92 | "Should be able to set a breakpoint in a js file."); |
michael@0 | 93 | ok(!aResponse.actualLocation, |
michael@0 | 94 | "Should be able to set a breakpoint on line 3 and column 61."); |
michael@0 | 95 | |
michael@0 | 96 | deferred.resolve(); |
michael@0 | 97 | }); |
michael@0 | 98 | |
michael@0 | 99 | return deferred.promise; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function reloadPage() { |
michael@0 | 103 | let loaded = waitForSourceAndCaret(gPanel, ".js", 3); |
michael@0 | 104 | gDebugger.DebuggerController._target.activeTab.reload(); |
michael@0 | 105 | return loaded.then(() => ok(true, "Page was reloaded and execution resumed.")); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | function testHitBreakpoint() { |
michael@0 | 109 | let deferred = promise.defer(); |
michael@0 | 110 | |
michael@0 | 111 | gDebugger.gThreadClient.resume(aResponse => { |
michael@0 | 112 | ok(!aResponse.error, "Shouldn't get an error resuming."); |
michael@0 | 113 | is(aResponse.type, "resumed", "Type should be 'resumed'."); |
michael@0 | 114 | |
michael@0 | 115 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES).then(() => { |
michael@0 | 116 | is(gFrames.itemCount, 1, "Should have one frame."); |
michael@0 | 117 | |
michael@0 | 118 | gDebugger.gThreadClient.resume(deferred.resolve); |
michael@0 | 119 | }); |
michael@0 | 120 | }); |
michael@0 | 121 | |
michael@0 | 122 | return deferred.promise; |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | function enableIgnoreCaughtExceptions() { |
michael@0 | 126 | let deferred = promise.defer(); |
michael@0 | 127 | |
michael@0 | 128 | gDebugger.gThreadClient.addOneTimeListener("resumed", () => { |
michael@0 | 129 | is(gPrefs.ignoreCaughtExceptions, true, |
michael@0 | 130 | "The ignore-caught-exceptions pref should now be enabled."); |
michael@0 | 131 | |
michael@0 | 132 | ok(true, "Ignore caught exceptions was enabled."); |
michael@0 | 133 | deferred.resolve(); |
michael@0 | 134 | }); |
michael@0 | 135 | |
michael@0 | 136 | gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "true"); |
michael@0 | 137 | gOptions._toggleIgnoreCaughtExceptions(); |
michael@0 | 138 | |
michael@0 | 139 | return deferred.promise; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | function disablePauseOnExceptions() { |
michael@0 | 143 | let deferred = promise.defer(); |
michael@0 | 144 | |
michael@0 | 145 | gDebugger.gThreadClient.addOneTimeListener("resumed", () => { |
michael@0 | 146 | is(gPrefs.pauseOnExceptions, false, |
michael@0 | 147 | "The pause-on-exceptions pref should now be disabled."); |
michael@0 | 148 | |
michael@0 | 149 | ok(true, "Pausing on exceptions was disabled."); |
michael@0 | 150 | deferred.resolve(); |
michael@0 | 151 | }); |
michael@0 | 152 | |
michael@0 | 153 | gOptions._pauseOnExceptionsItem.setAttribute("checked", "false"); |
michael@0 | 154 | gOptions._togglePauseOnExceptions(); |
michael@0 | 155 | |
michael@0 | 156 | return deferred.promise; |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | registerCleanupFunction(function() { |
michael@0 | 160 | gPanel = null; |
michael@0 | 161 | gDebugger = null; |
michael@0 | 162 | gFrames = null; |
michael@0 | 163 | gSources = null; |
michael@0 | 164 | gPrefs = null; |
michael@0 | 165 | gOptions = null; |
michael@0 | 166 | DevToolsUtils.reportingDisabled = false; |
michael@0 | 167 | }); |