|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Tests that the inspect command works as it should |
|
5 |
|
6 const TEST_URI = "http://example.com/browser/browser/devtools/commandline/"+ |
|
7 "test/browser_cmd_pagemod_export.html"; |
|
8 |
|
9 function test() { |
|
10 return Task.spawn(spawnTest).then(finish, helpers.handleError); |
|
11 } |
|
12 |
|
13 function spawnTest() { |
|
14 let options = yield helpers.openTab(TEST_URI); |
|
15 yield helpers.openToolbar(options); |
|
16 |
|
17 const documentElement = options.document.documentElement; |
|
18 const initialHtml = documentElement.innerHTML; |
|
19 function resetContent() { |
|
20 options.document.documentElement.innerHTML = initialHtml; |
|
21 } |
|
22 |
|
23 // Test exporting HTML |
|
24 let oldOpen = options.window.open; |
|
25 let openURL = ""; |
|
26 options.window.open = function(url) { |
|
27 // The URL is a data: URL that contains the document source |
|
28 openURL = decodeURIComponent(url); |
|
29 }; |
|
30 |
|
31 yield helpers.audit(options, [ |
|
32 { |
|
33 setup: 'export html', |
|
34 skipIf: true, |
|
35 check: { |
|
36 input: 'export html', |
|
37 hints: ' [destination]', |
|
38 markup: 'VVVVVVVVVVV', |
|
39 status: 'VALID', |
|
40 }, |
|
41 exec: { |
|
42 output: '' |
|
43 }, |
|
44 post: function() { |
|
45 isnot(openURL.indexOf('<html lang="en">'), -1, "export html works: <html>"); |
|
46 isnot(openURL.indexOf("<title>GCLI"), -1, "export html works: <title>"); |
|
47 isnot(openURL.indexOf('<p id="someid">#'), -1, "export html works: <p>"); |
|
48 } |
|
49 }, |
|
50 { |
|
51 setup: 'export html stdout', |
|
52 check: { |
|
53 input: 'export html stdout', |
|
54 hints: '', |
|
55 markup: 'VVVVVVVVVVVVVVVVVV', |
|
56 status: 'VALID', |
|
57 args: { |
|
58 destination: { value: "stdout" } |
|
59 }, |
|
60 }, |
|
61 exec: { |
|
62 output: [ |
|
63 /<html lang="en">/, |
|
64 /<title>GCLI/, |
|
65 /<p id="someid">#/ |
|
66 ] |
|
67 } |
|
68 } |
|
69 ]); |
|
70 |
|
71 options.window.open = oldOpen; |
|
72 oldOpen = undefined; |
|
73 |
|
74 // Test 'pagemod replace' |
|
75 yield helpers.audit(options, [ |
|
76 { |
|
77 setup: 'pagemod replace', |
|
78 check: { |
|
79 input: 'pagemod replace', |
|
80 hints: ' <search> <replace> [ignoreCase] [selector] [root] [attrOnly] [contentOnly] [attributes]', |
|
81 markup: 'VVVVVVVVVVVVVVV', |
|
82 status: 'ERROR' |
|
83 } |
|
84 }, |
|
85 { |
|
86 setup: 'pagemod replace some foo', |
|
87 check: { |
|
88 input: 'pagemod replace some foo', |
|
89 hints: ' [ignoreCase] [selector] [root] [attrOnly] [contentOnly] [attributes]', |
|
90 markup: 'VVVVVVVVVVVVVVVVVVVVVVVV', |
|
91 status: 'VALID' |
|
92 } |
|
93 }, |
|
94 { |
|
95 setup: 'pagemod replace some foo true', |
|
96 check: { |
|
97 input: 'pagemod replace some foo true', |
|
98 hints: ' [selector] [root] [attrOnly] [contentOnly] [attributes]', |
|
99 markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVV', |
|
100 status: 'VALID' |
|
101 } |
|
102 }, |
|
103 { |
|
104 setup: 'pagemod replace some foo true --attrOnly', |
|
105 check: { |
|
106 input: 'pagemod replace some foo true --attrOnly', |
|
107 hints: ' [selector] [root] [contentOnly] [attributes]', |
|
108 markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV', |
|
109 status: 'VALID' |
|
110 } |
|
111 }, |
|
112 { |
|
113 setup: 'pagemod replace sOme foOBar', |
|
114 exec: { |
|
115 output: /^[^:]+: 13\. [^:]+: 0\. [^:]+: 0\.\s*$/ |
|
116 }, |
|
117 post: function() { |
|
118 is(documentElement.innerHTML, initialHtml, "no change in the page"); |
|
119 } |
|
120 }, |
|
121 { |
|
122 setup: 'pagemod replace sOme foOBar true', |
|
123 exec: { |
|
124 output: /^[^:]+: 13\. [^:]+: 2\. [^:]+: 2\.\s*$/ |
|
125 }, |
|
126 post: function() { |
|
127 let html = documentElement.innerHTML; |
|
128 |
|
129 isnot(html.indexOf('<p class="foOBarclass">.foOBarclass'), -1, |
|
130 ".someclass changed to .foOBarclass"); |
|
131 isnot(html.indexOf('<p id="foOBarid">#foOBarid'), -1, |
|
132 "#someid changed to #foOBarid"); |
|
133 |
|
134 resetContent(); |
|
135 } |
|
136 }, |
|
137 { |
|
138 setup: 'pagemod replace some foobar --contentOnly', |
|
139 exec: { |
|
140 output: /^[^:]+: 13\. [^:]+: 2\. [^:]+: 0\.\s*$/ |
|
141 }, |
|
142 post: function() { |
|
143 let html = documentElement.innerHTML; |
|
144 |
|
145 isnot(html.indexOf('<p class="someclass">.foobarclass'), -1, |
|
146 ".someclass changed to .foobarclass (content only)"); |
|
147 isnot(html.indexOf('<p id="someid">#foobarid'), -1, |
|
148 "#someid changed to #foobarid (content only)"); |
|
149 |
|
150 resetContent(); |
|
151 } |
|
152 }, |
|
153 { |
|
154 setup: 'pagemod replace some foobar --attrOnly', |
|
155 exec: { |
|
156 output: /^[^:]+: 13\. [^:]+: 0\. [^:]+: 2\.\s*$/ |
|
157 }, |
|
158 post: function() { |
|
159 let html = documentElement.innerHTML; |
|
160 |
|
161 isnot(html.indexOf('<p class="foobarclass">.someclass'), -1, |
|
162 ".someclass changed to .foobarclass (attr only)"); |
|
163 isnot(html.indexOf('<p id="foobarid">#someid'), -1, |
|
164 "#someid changed to #foobarid (attr only)"); |
|
165 |
|
166 resetContent(); |
|
167 } |
|
168 }, |
|
169 { |
|
170 setup: 'pagemod replace some foobar --root head', |
|
171 exec: { |
|
172 output: /^[^:]+: 2\. [^:]+: 0\. [^:]+: 0\.\s*$/ |
|
173 }, |
|
174 post: function() { |
|
175 is(documentElement.innerHTML, initialHtml, "nothing changed"); |
|
176 } |
|
177 }, |
|
178 { |
|
179 setup: 'pagemod replace some foobar --selector .someclass,div,span', |
|
180 exec: { |
|
181 output: /^[^:]+: 4\. [^:]+: 1\. [^:]+: 1\.\s*$/ |
|
182 }, |
|
183 post: function() { |
|
184 let html = documentElement.innerHTML; |
|
185 |
|
186 isnot(html.indexOf('<p class="foobarclass">.foobarclass'), -1, |
|
187 ".someclass changed to .foobarclass"); |
|
188 isnot(html.indexOf('<p id="someid">#someid'), -1, |
|
189 "#someid did not change"); |
|
190 |
|
191 resetContent(); |
|
192 } |
|
193 }, |
|
194 ]); |
|
195 |
|
196 // Test 'pagemod remove element' |
|
197 yield helpers.audit(options, [ |
|
198 { |
|
199 setup: 'pagemod remove', |
|
200 check: { |
|
201 input: 'pagemod remove', |
|
202 hints: ' attribute', |
|
203 markup: 'IIIIIIIVIIIIII', |
|
204 status: 'ERROR' |
|
205 }, |
|
206 }, |
|
207 { |
|
208 setup: 'pagemod remove element', |
|
209 check: { |
|
210 input: 'pagemod remove element', |
|
211 hints: ' <search> [root] [stripOnly] [ifEmptyOnly]', |
|
212 markup: 'VVVVVVVVVVVVVVVVVVVVVV', |
|
213 status: 'ERROR' |
|
214 }, |
|
215 }, |
|
216 { |
|
217 setup: 'pagemod remove element foo', |
|
218 check: { |
|
219 input: 'pagemod remove element foo', |
|
220 hints: ' [root] [stripOnly] [ifEmptyOnly]', |
|
221 markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVV', |
|
222 status: 'VALID' |
|
223 }, |
|
224 }, |
|
225 { |
|
226 setup: 'pagemod remove element p', |
|
227 exec: { |
|
228 output: /^[^:]+: 3\. [^:]+: 3\.\s*$/ |
|
229 }, |
|
230 post: function() { |
|
231 let html = documentElement.innerHTML; |
|
232 |
|
233 is(html.indexOf('<p class="someclass">'), -1, "p.someclass removed"); |
|
234 is(html.indexOf('<p id="someid">'), -1, "p#someid removed"); |
|
235 is(html.indexOf("<p><strong>"), -1, "<p> wrapping <strong> removed"); |
|
236 isnot(html.indexOf("<span>"), -1, "<span> not removed"); |
|
237 |
|
238 resetContent(); |
|
239 } |
|
240 }, |
|
241 { |
|
242 setup: 'pagemod remove element p head', |
|
243 exec: { |
|
244 output: /^[^:]+: 0\. [^:]+: 0\.\s*$/ |
|
245 }, |
|
246 post: function() { |
|
247 is(documentElement.innerHTML, initialHtml, "nothing changed in the page"); |
|
248 } |
|
249 }, |
|
250 { |
|
251 setup: 'pagemod remove element p --ifEmptyOnly', |
|
252 exec: { |
|
253 output: /^[^:]+: 3\. [^:]+: 0\.\s*$/ |
|
254 }, |
|
255 post: function() { |
|
256 is(documentElement.innerHTML, initialHtml, "nothing changed in the page"); |
|
257 } |
|
258 }, |
|
259 { |
|
260 setup: 'pagemod remove element meta,title --ifEmptyOnly', |
|
261 exec: { |
|
262 output: /^[^:]+: 2\. [^:]+: 1\.\s*$/ |
|
263 }, |
|
264 post: function() { |
|
265 let html = documentElement.innerHTML; |
|
266 |
|
267 is(html.indexOf("<meta charset="), -1, "<meta> removed"); |
|
268 isnot(html.indexOf("<title>"), -1, "<title> not removed"); |
|
269 |
|
270 resetContent(); |
|
271 } |
|
272 }, |
|
273 { |
|
274 setup: 'pagemod remove element p --stripOnly', |
|
275 exec: { |
|
276 output: /^[^:]+: 3\. [^:]+: 3\.\s*$/ |
|
277 }, |
|
278 post: function() { |
|
279 let html = documentElement.innerHTML; |
|
280 |
|
281 is(html.indexOf('<p class="someclass">'), -1, "p.someclass removed"); |
|
282 is(html.indexOf('<p id="someid">'), -1, "p#someid removed"); |
|
283 is(html.indexOf("<p><strong>"), -1, "<p> wrapping <strong> removed"); |
|
284 isnot(html.indexOf(".someclass"), -1, ".someclass still exists"); |
|
285 isnot(html.indexOf("#someid"), -1, "#someid still exists"); |
|
286 isnot(html.indexOf("<strong>p"), -1, "<strong> still exists"); |
|
287 |
|
288 resetContent(); |
|
289 } |
|
290 }, |
|
291 ]); |
|
292 |
|
293 // Test 'pagemod remove attribute' |
|
294 yield helpers.audit(options, [ |
|
295 { |
|
296 setup: 'pagemod remove attribute', |
|
297 check: { |
|
298 input: 'pagemod remove attribute', |
|
299 hints: ' <searchAttributes> <searchElements> [root] [ignoreCase]', |
|
300 markup: 'VVVVVVVVVVVVVVVVVVVVVVVV', |
|
301 status: 'ERROR', |
|
302 args: { |
|
303 searchAttributes: { value: undefined, status: 'INCOMPLETE' }, |
|
304 searchElements: { value: undefined, status: 'INCOMPLETE' }, |
|
305 root: { value: undefined }, |
|
306 ignoreCase: { value: false }, |
|
307 } |
|
308 }, |
|
309 }, |
|
310 { |
|
311 setup: 'pagemod remove attribute foo bar', |
|
312 check: { |
|
313 input: 'pagemod remove attribute foo bar', |
|
314 hints: ' [root] [ignoreCase]', |
|
315 markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV', |
|
316 status: 'VALID', |
|
317 args: { |
|
318 searchAttributes: { value: 'foo' }, |
|
319 searchElements: { value: 'bar' }, |
|
320 root: { value: undefined }, |
|
321 ignoreCase: { value: false }, |
|
322 } |
|
323 }, |
|
324 post: function() { |
|
325 let deferred = promise.defer(); |
|
326 executeSoon(function() { |
|
327 deferred.resolve(); |
|
328 }); |
|
329 return deferred.promise; |
|
330 } |
|
331 }, |
|
332 { |
|
333 setup: 'pagemod remove attribute foo bar', |
|
334 exec: { |
|
335 output: /^[^:]+: 0\. [^:]+: 0\.\s*$/ |
|
336 }, |
|
337 post: function() { |
|
338 is(documentElement.innerHTML, initialHtml, "nothing changed in the page"); |
|
339 } |
|
340 }, |
|
341 { |
|
342 setup: 'pagemod remove attribute foo p', |
|
343 exec: { |
|
344 output: /^[^:]+: 3\. [^:]+: 0\.\s*$/ |
|
345 }, |
|
346 post: function() { |
|
347 is(documentElement.innerHTML, initialHtml, "nothing changed in the page"); |
|
348 } |
|
349 }, |
|
350 { |
|
351 setup: 'pagemod remove attribute id p,span', |
|
352 exec: { |
|
353 output: /^[^:]+: 5\. [^:]+: 1\.\s*$/ |
|
354 }, |
|
355 post: function() { |
|
356 is(documentElement.innerHTML.indexOf('<p id="someid">#someid'), -1, |
|
357 "p#someid attribute removed"); |
|
358 isnot(documentElement.innerHTML.indexOf("<p>#someid"), -1, |
|
359 "p with someid content still exists"); |
|
360 |
|
361 resetContent(); |
|
362 } |
|
363 }, |
|
364 { |
|
365 setup: 'pagemod remove attribute Class p', |
|
366 exec: { |
|
367 output: /^[^:]+: 3\. [^:]+: 0\.\s*$/ |
|
368 }, |
|
369 post: function() { |
|
370 is(documentElement.innerHTML, initialHtml, "nothing changed in the page"); |
|
371 } |
|
372 }, |
|
373 { |
|
374 setup: 'pagemod remove attribute Class p --ignoreCase', |
|
375 exec: { |
|
376 output: /^[^:]+: 3\. [^:]+: 1\.\s*$/ |
|
377 }, |
|
378 post: function() { |
|
379 is(documentElement.innerHTML.indexOf('<p class="someclass">.someclass'), -1, |
|
380 "p.someclass attribute removed"); |
|
381 isnot(documentElement.innerHTML.indexOf("<p>.someclass"), -1, |
|
382 "p with someclass content still exists"); |
|
383 |
|
384 resetContent(); |
|
385 } |
|
386 }, |
|
387 ]); |
|
388 |
|
389 // Shutdown |
|
390 yield helpers.closeToolbar(options); |
|
391 yield helpers.closeTab(options); |
|
392 } |