browser/devtools/debugger/test/browser_dbg_source-maps-02.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 we can toggle between the original and generated sources.
michael@0 6 */
michael@0 7
michael@0 8 const TAB_URL = EXAMPLE_URL + "doc_binary_search.html";
michael@0 9 const JS_URL = EXAMPLE_URL + "code_binary_search.js";
michael@0 10
michael@0 11 let gDebuggee, gPanel, gDebugger, gEditor;
michael@0 12 let gSources, gFrames, gPrefs, gOptions;
michael@0 13
michael@0 14 function test() {
michael@0 15 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 16 gDebuggee = aDebuggee;
michael@0 17 gPanel = aPanel;
michael@0 18 gDebugger = gPanel.panelWin;
michael@0 19 gEditor = gDebugger.DebuggerView.editor;
michael@0 20 gSources = gDebugger.DebuggerView.Sources;
michael@0 21 gFrames = gDebugger.DebuggerView.StackFrames;
michael@0 22 gPrefs = gDebugger.Prefs;
michael@0 23 gOptions = gDebugger.DebuggerView.Options;
michael@0 24
michael@0 25 waitForSourceShown(gPanel, ".coffee")
michael@0 26 .then(testToggleGeneratedSource)
michael@0 27 .then(testSetBreakpoint)
michael@0 28 .then(testToggleOnPause)
michael@0 29 .then(testResume)
michael@0 30 .then(() => closeDebuggerAndFinish(gPanel))
michael@0 31 .then(null, aError => {
michael@0 32 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
michael@0 33 });
michael@0 34 });
michael@0 35 }
michael@0 36
michael@0 37 function testToggleGeneratedSource() {
michael@0 38 let finished = waitForSourceShown(gPanel, ".js").then(() => {
michael@0 39 is(gPrefs.sourceMapsEnabled, false,
michael@0 40 "The source maps pref should have been set to false.");
michael@0 41 is(gOptions._showOriginalSourceItem.getAttribute("checked"), "false",
michael@0 42 "Source maps should now be disabled.")
michael@0 43
michael@0 44 is(gSources.selectedValue.indexOf(".coffee"), -1,
michael@0 45 "The debugger should not show the source mapped coffee source file.");
michael@0 46 isnot(gSources.selectedValue.indexOf(".js"), -1,
michael@0 47 "The debugger should show the generated js source file.");
michael@0 48
michael@0 49 is(gEditor.getText().indexOf("isnt"), -1,
michael@0 50 "The debugger's editor should not have the coffee source source displayed.");
michael@0 51 is(gEditor.getText().indexOf("function"), 36,
michael@0 52 "The debugger's editor should have the JS source displayed.");
michael@0 53 });
michael@0 54
michael@0 55 gOptions._showOriginalSourceItem.setAttribute("checked", "false");
michael@0 56 gOptions._toggleShowOriginalSource();
michael@0 57 gOptions._onPopupHidden();
michael@0 58
michael@0 59 return finished;
michael@0 60 }
michael@0 61
michael@0 62 function testSetBreakpoint() {
michael@0 63 let deferred = promise.defer();
michael@0 64
michael@0 65 gDebugger.gThreadClient.setBreakpoint({ url: JS_URL, line: 7 }, aResponse => {
michael@0 66 ok(!aResponse.error,
michael@0 67 "Should be able to set a breakpoint in a js file.");
michael@0 68
michael@0 69 gDebugger.gClient.addOneTimeListener("resumed", () => {
michael@0 70 waitForCaretAndScopes(gPanel, 7).then(() => {
michael@0 71 // Make sure that we have JavaScript stack frames.
michael@0 72 is(gFrames.itemCount, 1,
michael@0 73 "Should have only one frame.");
michael@0 74 is(gFrames.getItemAtIndex(0).attachment.url.indexOf(".coffee"), -1,
michael@0 75 "First frame should not be a coffee source frame.");
michael@0 76 isnot(gFrames.getItemAtIndex(0).attachment.url.indexOf(".js"), -1,
michael@0 77 "First frame should be a JS frame.");
michael@0 78
michael@0 79 deferred.resolve();
michael@0 80 });
michael@0 81
michael@0 82 // This will cause the breakpoint to be hit, and put us back in the
michael@0 83 // paused state.
michael@0 84 gDebuggee.binary_search([0, 2, 3, 5, 7, 10], 5);
michael@0 85 });
michael@0 86 });
michael@0 87
michael@0 88 return deferred.promise;
michael@0 89 }
michael@0 90
michael@0 91 function testToggleOnPause() {
michael@0 92 let finished = waitForSourceAndCaretAndScopes(gPanel, ".coffee", 5).then(() => {
michael@0 93 is(gPrefs.sourceMapsEnabled, true,
michael@0 94 "The source maps pref should have been set to true.");
michael@0 95 is(gOptions._showOriginalSourceItem.getAttribute("checked"), "true",
michael@0 96 "Source maps should now be enabled.")
michael@0 97
michael@0 98 isnot(gSources.selectedValue.indexOf(".coffee"), -1,
michael@0 99 "The debugger should show the source mapped coffee source file.");
michael@0 100 is(gSources.selectedValue.indexOf(".js"), -1,
michael@0 101 "The debugger should not show the generated js source file.");
michael@0 102
michael@0 103 is(gEditor.getText().indexOf("isnt"), 218,
michael@0 104 "The debugger's editor should have the coffee source source displayed.");
michael@0 105 is(gEditor.getText().indexOf("function"), -1,
michael@0 106 "The debugger's editor should not have the JS source displayed.");
michael@0 107
michael@0 108 // Make sure that we have coffee source stack frames.
michael@0 109 is(gFrames.itemCount, 1,
michael@0 110 "Should have only one frame.");
michael@0 111 is(gFrames.getItemAtIndex(0).attachment.url.indexOf(".js"), -1,
michael@0 112 "First frame should not be a JS frame.");
michael@0 113 isnot(gFrames.getItemAtIndex(0).attachment.url.indexOf(".coffee"), -1,
michael@0 114 "First frame should be a coffee source frame.");
michael@0 115 });
michael@0 116
michael@0 117 gOptions._showOriginalSourceItem.setAttribute("checked", "true");
michael@0 118 gOptions._toggleShowOriginalSource();
michael@0 119 gOptions._onPopupHidden();
michael@0 120
michael@0 121 return finished;
michael@0 122 }
michael@0 123
michael@0 124 function testResume() {
michael@0 125 let deferred = promise.defer();
michael@0 126
michael@0 127 gDebugger.gThreadClient.resume(aResponse => {
michael@0 128 ok(!aResponse.error, "Shouldn't get an error resuming.");
michael@0 129 is(aResponse.type, "resumed", "Type should be 'resumed'.");
michael@0 130
michael@0 131 deferred.resolve();
michael@0 132 });
michael@0 133
michael@0 134 return deferred.promise;
michael@0 135 }
michael@0 136
michael@0 137 registerCleanupFunction(function() {
michael@0 138 gDebuggee = null;
michael@0 139 gPanel = null;
michael@0 140 gDebugger = null;
michael@0 141 gEditor = null;
michael@0 142 gSources = null;
michael@0 143 gFrames = null;
michael@0 144 gPrefs = null;
michael@0 145 gOptions = null;
michael@0 146 });

mercurial