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

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

mercurial