|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests if the sources cache knows how to cache sources when prompted. |
|
6 */ |
|
7 |
|
8 const TAB_URL = EXAMPLE_URL + "doc_function-search.html"; |
|
9 const TOTAL_SOURCES = 4; |
|
10 |
|
11 let gTab, gDebuggee, gPanel, gDebugger; |
|
12 let gEditor, gSources, gControllerSources; |
|
13 let gPrevLabelsCache, gPrevGroupsCache; |
|
14 |
|
15 function test() { |
|
16 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
17 gTab = aTab; |
|
18 gDebuggee = aDebuggee; |
|
19 gPanel = aPanel; |
|
20 gDebugger = gPanel.panelWin; |
|
21 gEditor = gDebugger.DebuggerView.editor; |
|
22 gSources = gDebugger.DebuggerView.Sources; |
|
23 gControllerSources = gDebugger.DebuggerController.SourceScripts; |
|
24 gPrevLabelsCache = gDebugger.SourceUtils._labelsCache; |
|
25 gPrevGroupsCache = gDebugger.SourceUtils._groupsCache; |
|
26 |
|
27 waitForSourceShown(gPanel, "-01.js") |
|
28 .then(initialChecks) |
|
29 .then(getTextForSourcesAndCheckIntegrity) |
|
30 .then(performReloadAndTestState) |
|
31 .then(() => closeDebuggerAndFinish(gPanel)) |
|
32 .then(null, aError => { |
|
33 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
34 }); |
|
35 }); |
|
36 } |
|
37 |
|
38 function initialChecks() { |
|
39 ok(gEditor.getText().contains("First source!"), |
|
40 "Editor text contents appears to be correct."); |
|
41 is(gSources.selectedItem.attachment.label, "code_function-search-01.js", |
|
42 "The currently selected label in the sources container is correct."); |
|
43 ok(gSources.selectedValue.contains("code_function-search-01.js"), |
|
44 "The currently selected value in the sources container appears to be correct."); |
|
45 |
|
46 is(gSources.itemCount, TOTAL_SOURCES, |
|
47 "There should be " + TOTAL_SOURCES + " sources present in the sources list."); |
|
48 is(gSources.visibleItems.length, TOTAL_SOURCES, |
|
49 "There should be " + TOTAL_SOURCES + " sources visible in the sources list."); |
|
50 is(gSources.attachments.length, TOTAL_SOURCES, |
|
51 "There should be " + TOTAL_SOURCES + " attachments stored in the sources container model.") |
|
52 is(gSources.values.length, TOTAL_SOURCES, |
|
53 "There should be " + TOTAL_SOURCES + " values stored in the sources container model.") |
|
54 |
|
55 info("Source labels: " + gSources.attachments.toSource()); |
|
56 info("Source values: " + gSources.values.toSource()); |
|
57 |
|
58 is(gSources.attachments[0].label, "code_function-search-01.js", |
|
59 "The first source label is correct."); |
|
60 ok(gSources.values[0].contains("code_function-search-01.js"), |
|
61 "The first source value appears to be correct."); |
|
62 |
|
63 is(gSources.attachments[1].label, "code_function-search-02.js", |
|
64 "The second source label is correct."); |
|
65 ok(gSources.values[1].contains("code_function-search-02.js"), |
|
66 "The second source value appears to be correct."); |
|
67 |
|
68 is(gSources.attachments[2].label, "code_function-search-03.js", |
|
69 "The third source label is correct."); |
|
70 ok(gSources.values[2].contains("code_function-search-03.js"), |
|
71 "The third source value appears to be correct."); |
|
72 |
|
73 is(gSources.attachments[3].label, "doc_function-search.html", |
|
74 "The third source label is correct."); |
|
75 ok(gSources.values[3].contains("doc_function-search.html"), |
|
76 "The third source value appears to be correct."); |
|
77 |
|
78 is(gDebugger.SourceUtils._labelsCache.size, TOTAL_SOURCES, |
|
79 "There should be " + TOTAL_SOURCES + " labels cached."); |
|
80 is(gDebugger.SourceUtils._groupsCache.size, TOTAL_SOURCES, |
|
81 "There should be " + TOTAL_SOURCES + " groups cached."); |
|
82 } |
|
83 |
|
84 function getTextForSourcesAndCheckIntegrity() { |
|
85 return gControllerSources.getTextForSources(gSources.values).then(testCacheIntegrity); |
|
86 } |
|
87 |
|
88 function performReloadAndTestState() { |
|
89 gDebugger.gTarget.once("will-navigate", testStateBeforeReload); |
|
90 gDebugger.gTarget.once("navigate", testStateAfterReload); |
|
91 return reloadActiveTab(gPanel, gDebugger.EVENTS.SOURCE_SHOWN); |
|
92 } |
|
93 |
|
94 function testCacheIntegrity(aSources) { |
|
95 for (let [url, contents] of aSources) { |
|
96 // Sources of a debugee don't always finish fetching consecutively. D'uh. |
|
97 let index = gSources.values.indexOf(url); |
|
98 |
|
99 ok(index >= 0 && index <= TOTAL_SOURCES, |
|
100 "Found a source url cached correctly (" + index + ")."); |
|
101 ok(contents.contains( |
|
102 ["First source!", "Second source!", "Third source!", "Peanut butter jelly time!"][index]), |
|
103 "Found a source's text contents cached correctly (" + index + ")."); |
|
104 |
|
105 info("Cached source url at " + index + ": " + url); |
|
106 info("Cached source text at " + index + ": " + contents); |
|
107 } |
|
108 } |
|
109 |
|
110 function testStateBeforeReload() { |
|
111 is(gSources.itemCount, 0, |
|
112 "There should be no sources present in the sources list during reload."); |
|
113 is(gDebugger.SourceUtils._labelsCache, gPrevLabelsCache, |
|
114 "The labels cache has been refreshed during reload and no new objects were created."); |
|
115 is(gDebugger.SourceUtils._groupsCache, gPrevGroupsCache, |
|
116 "The groups cache has been refreshed during reload and no new objects were created."); |
|
117 is(gDebugger.SourceUtils._labelsCache.size, 0, |
|
118 "There should be no labels cached during reload"); |
|
119 is(gDebugger.SourceUtils._groupsCache.size, 0, |
|
120 "There should be no groups cached during reload"); |
|
121 } |
|
122 |
|
123 function testStateAfterReload() { |
|
124 is(gSources.itemCount, TOTAL_SOURCES, |
|
125 "There should be " + TOTAL_SOURCES + " sources present in the sources list."); |
|
126 is(gDebugger.SourceUtils._labelsCache.size, TOTAL_SOURCES, |
|
127 "There should be " + TOTAL_SOURCES + " labels cached after reload."); |
|
128 is(gDebugger.SourceUtils._groupsCache.size, TOTAL_SOURCES, |
|
129 "There should be " + TOTAL_SOURCES + " groups cached after reload."); |
|
130 } |
|
131 |
|
132 registerCleanupFunction(function() { |
|
133 gTab = null; |
|
134 gDebuggee = null; |
|
135 gPanel = null; |
|
136 gDebugger = null; |
|
137 gEditor = null; |
|
138 gSources = null; |
|
139 gControllerSources = null; |
|
140 gPrevLabelsCache = null; |
|
141 gPrevGroupsCache = null; |
|
142 }); |