|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Make sure that updating the editor mode sets the right highlighting engine, |
|
6 * and source URIs with extra query parameters also get the right engine. |
|
7 */ |
|
8 |
|
9 const TAB_URL = EXAMPLE_URL + "doc_editor-mode.html"; |
|
10 |
|
11 let gTab, gDebuggee, gPanel, gDebugger; |
|
12 let gEditor, gSources; |
|
13 |
|
14 function test() { |
|
15 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
16 gTab = aTab; |
|
17 gDebuggee = aDebuggee; |
|
18 gPanel = aPanel; |
|
19 gDebugger = gPanel.panelWin; |
|
20 gEditor = gDebugger.DebuggerView.editor; |
|
21 gSources = gDebugger.DebuggerView.Sources; |
|
22 |
|
23 waitForSourceAndCaretAndScopes(gPanel, "code_test-editor-mode", 1) |
|
24 .then(testInitialSource) |
|
25 .then(testSwitch1) |
|
26 .then(testSwitch2) |
|
27 .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) |
|
28 .then(null, aError => { |
|
29 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
30 }); |
|
31 |
|
32 gDebuggee.firstCall(); |
|
33 }); |
|
34 } |
|
35 |
|
36 function testInitialSource() { |
|
37 is(gSources.itemCount, 3, |
|
38 "Found the expected number of sources."); |
|
39 |
|
40 is(gEditor.getMode().name, "text", |
|
41 "Found the expected editor mode."); |
|
42 is(gEditor.getText().search(/firstCall/), -1, |
|
43 "The first source is not displayed."); |
|
44 is(gEditor.getText().search(/debugger/), 141, |
|
45 "The second source is displayed."); |
|
46 is(gEditor.getText().search(/banana/), -1, |
|
47 "The third source is not displayed."); |
|
48 |
|
49 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN); |
|
50 gSources.selectedItem = e => e.attachment.label == "code_script-switching-01.js"; |
|
51 return finished; |
|
52 } |
|
53 |
|
54 function testSwitch1() { |
|
55 is(gSources.itemCount, 3, |
|
56 "Found the expected number of sources."); |
|
57 |
|
58 is(gEditor.getMode().name, "javascript", |
|
59 "Found the expected editor mode."); |
|
60 is(gEditor.getText().search(/firstCall/), 118, |
|
61 "The first source is displayed."); |
|
62 is(gEditor.getText().search(/debugger/), -1, |
|
63 "The second source is not displayed."); |
|
64 is(gEditor.getText().search(/banana/), -1, |
|
65 "The third source is not displayed."); |
|
66 |
|
67 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN); |
|
68 gSources.selectedItem = e => e.attachment.label == "doc_editor-mode.html"; |
|
69 return finished; |
|
70 } |
|
71 |
|
72 function testSwitch2() { |
|
73 is(gSources.itemCount, 3, |
|
74 "Found the expected number of sources."); |
|
75 |
|
76 is(gEditor.getMode().name, "htmlmixed", |
|
77 "Found the expected editor mode."); |
|
78 is(gEditor.getText().search(/firstCall/), -1, |
|
79 "The first source is not displayed."); |
|
80 is(gEditor.getText().search(/debugger/), -1, |
|
81 "The second source is not displayed."); |
|
82 is(gEditor.getText().search(/banana/), 443, |
|
83 "The third source is displayed."); |
|
84 } |
|
85 |
|
86 registerCleanupFunction(function() { |
|
87 gTab = null; |
|
88 gDebuggee = null; |
|
89 gPanel = null; |
|
90 gDebugger = null; |
|
91 gEditor = null; |
|
92 gSources = null; |
|
93 }); |