1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/commandline/test/browser_cmd_pagemod_export.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,392 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Tests that the inspect command works as it should 1.8 + 1.9 +const TEST_URI = "http://example.com/browser/browser/devtools/commandline/"+ 1.10 + "test/browser_cmd_pagemod_export.html"; 1.11 + 1.12 +function test() { 1.13 + return Task.spawn(spawnTest).then(finish, helpers.handleError); 1.14 +} 1.15 + 1.16 +function spawnTest() { 1.17 + let options = yield helpers.openTab(TEST_URI); 1.18 + yield helpers.openToolbar(options); 1.19 + 1.20 + const documentElement = options.document.documentElement; 1.21 + const initialHtml = documentElement.innerHTML; 1.22 + function resetContent() { 1.23 + options.document.documentElement.innerHTML = initialHtml; 1.24 + } 1.25 + 1.26 + // Test exporting HTML 1.27 + let oldOpen = options.window.open; 1.28 + let openURL = ""; 1.29 + options.window.open = function(url) { 1.30 + // The URL is a data: URL that contains the document source 1.31 + openURL = decodeURIComponent(url); 1.32 + }; 1.33 + 1.34 + yield helpers.audit(options, [ 1.35 + { 1.36 + setup: 'export html', 1.37 + skipIf: true, 1.38 + check: { 1.39 + input: 'export html', 1.40 + hints: ' [destination]', 1.41 + markup: 'VVVVVVVVVVV', 1.42 + status: 'VALID', 1.43 + }, 1.44 + exec: { 1.45 + output: '' 1.46 + }, 1.47 + post: function() { 1.48 + isnot(openURL.indexOf('<html lang="en">'), -1, "export html works: <html>"); 1.49 + isnot(openURL.indexOf("<title>GCLI"), -1, "export html works: <title>"); 1.50 + isnot(openURL.indexOf('<p id="someid">#'), -1, "export html works: <p>"); 1.51 + } 1.52 + }, 1.53 + { 1.54 + setup: 'export html stdout', 1.55 + check: { 1.56 + input: 'export html stdout', 1.57 + hints: '', 1.58 + markup: 'VVVVVVVVVVVVVVVVVV', 1.59 + status: 'VALID', 1.60 + args: { 1.61 + destination: { value: "stdout" } 1.62 + }, 1.63 + }, 1.64 + exec: { 1.65 + output: [ 1.66 + /<html lang="en">/, 1.67 + /<title>GCLI/, 1.68 + /<p id="someid">#/ 1.69 + ] 1.70 + } 1.71 + } 1.72 + ]); 1.73 + 1.74 + options.window.open = oldOpen; 1.75 + oldOpen = undefined; 1.76 + 1.77 + // Test 'pagemod replace' 1.78 + yield helpers.audit(options, [ 1.79 + { 1.80 + setup: 'pagemod replace', 1.81 + check: { 1.82 + input: 'pagemod replace', 1.83 + hints: ' <search> <replace> [ignoreCase] [selector] [root] [attrOnly] [contentOnly] [attributes]', 1.84 + markup: 'VVVVVVVVVVVVVVV', 1.85 + status: 'ERROR' 1.86 + } 1.87 + }, 1.88 + { 1.89 + setup: 'pagemod replace some foo', 1.90 + check: { 1.91 + input: 'pagemod replace some foo', 1.92 + hints: ' [ignoreCase] [selector] [root] [attrOnly] [contentOnly] [attributes]', 1.93 + markup: 'VVVVVVVVVVVVVVVVVVVVVVVV', 1.94 + status: 'VALID' 1.95 + } 1.96 + }, 1.97 + { 1.98 + setup: 'pagemod replace some foo true', 1.99 + check: { 1.100 + input: 'pagemod replace some foo true', 1.101 + hints: ' [selector] [root] [attrOnly] [contentOnly] [attributes]', 1.102 + markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVV', 1.103 + status: 'VALID' 1.104 + } 1.105 + }, 1.106 + { 1.107 + setup: 'pagemod replace some foo true --attrOnly', 1.108 + check: { 1.109 + input: 'pagemod replace some foo true --attrOnly', 1.110 + hints: ' [selector] [root] [contentOnly] [attributes]', 1.111 + markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV', 1.112 + status: 'VALID' 1.113 + } 1.114 + }, 1.115 + { 1.116 + setup: 'pagemod replace sOme foOBar', 1.117 + exec: { 1.118 + output: /^[^:]+: 13\. [^:]+: 0\. [^:]+: 0\.\s*$/ 1.119 + }, 1.120 + post: function() { 1.121 + is(documentElement.innerHTML, initialHtml, "no change in the page"); 1.122 + } 1.123 + }, 1.124 + { 1.125 + setup: 'pagemod replace sOme foOBar true', 1.126 + exec: { 1.127 + output: /^[^:]+: 13\. [^:]+: 2\. [^:]+: 2\.\s*$/ 1.128 + }, 1.129 + post: function() { 1.130 + let html = documentElement.innerHTML; 1.131 + 1.132 + isnot(html.indexOf('<p class="foOBarclass">.foOBarclass'), -1, 1.133 + ".someclass changed to .foOBarclass"); 1.134 + isnot(html.indexOf('<p id="foOBarid">#foOBarid'), -1, 1.135 + "#someid changed to #foOBarid"); 1.136 + 1.137 + resetContent(); 1.138 + } 1.139 + }, 1.140 + { 1.141 + setup: 'pagemod replace some foobar --contentOnly', 1.142 + exec: { 1.143 + output: /^[^:]+: 13\. [^:]+: 2\. [^:]+: 0\.\s*$/ 1.144 + }, 1.145 + post: function() { 1.146 + let html = documentElement.innerHTML; 1.147 + 1.148 + isnot(html.indexOf('<p class="someclass">.foobarclass'), -1, 1.149 + ".someclass changed to .foobarclass (content only)"); 1.150 + isnot(html.indexOf('<p id="someid">#foobarid'), -1, 1.151 + "#someid changed to #foobarid (content only)"); 1.152 + 1.153 + resetContent(); 1.154 + } 1.155 + }, 1.156 + { 1.157 + setup: 'pagemod replace some foobar --attrOnly', 1.158 + exec: { 1.159 + output: /^[^:]+: 13\. [^:]+: 0\. [^:]+: 2\.\s*$/ 1.160 + }, 1.161 + post: function() { 1.162 + let html = documentElement.innerHTML; 1.163 + 1.164 + isnot(html.indexOf('<p class="foobarclass">.someclass'), -1, 1.165 + ".someclass changed to .foobarclass (attr only)"); 1.166 + isnot(html.indexOf('<p id="foobarid">#someid'), -1, 1.167 + "#someid changed to #foobarid (attr only)"); 1.168 + 1.169 + resetContent(); 1.170 + } 1.171 + }, 1.172 + { 1.173 + setup: 'pagemod replace some foobar --root head', 1.174 + exec: { 1.175 + output: /^[^:]+: 2\. [^:]+: 0\. [^:]+: 0\.\s*$/ 1.176 + }, 1.177 + post: function() { 1.178 + is(documentElement.innerHTML, initialHtml, "nothing changed"); 1.179 + } 1.180 + }, 1.181 + { 1.182 + setup: 'pagemod replace some foobar --selector .someclass,div,span', 1.183 + exec: { 1.184 + output: /^[^:]+: 4\. [^:]+: 1\. [^:]+: 1\.\s*$/ 1.185 + }, 1.186 + post: function() { 1.187 + let html = documentElement.innerHTML; 1.188 + 1.189 + isnot(html.indexOf('<p class="foobarclass">.foobarclass'), -1, 1.190 + ".someclass changed to .foobarclass"); 1.191 + isnot(html.indexOf('<p id="someid">#someid'), -1, 1.192 + "#someid did not change"); 1.193 + 1.194 + resetContent(); 1.195 + } 1.196 + }, 1.197 + ]); 1.198 + 1.199 + // Test 'pagemod remove element' 1.200 + yield helpers.audit(options, [ 1.201 + { 1.202 + setup: 'pagemod remove', 1.203 + check: { 1.204 + input: 'pagemod remove', 1.205 + hints: ' attribute', 1.206 + markup: 'IIIIIIIVIIIIII', 1.207 + status: 'ERROR' 1.208 + }, 1.209 + }, 1.210 + { 1.211 + setup: 'pagemod remove element', 1.212 + check: { 1.213 + input: 'pagemod remove element', 1.214 + hints: ' <search> [root] [stripOnly] [ifEmptyOnly]', 1.215 + markup: 'VVVVVVVVVVVVVVVVVVVVVV', 1.216 + status: 'ERROR' 1.217 + }, 1.218 + }, 1.219 + { 1.220 + setup: 'pagemod remove element foo', 1.221 + check: { 1.222 + input: 'pagemod remove element foo', 1.223 + hints: ' [root] [stripOnly] [ifEmptyOnly]', 1.224 + markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVV', 1.225 + status: 'VALID' 1.226 + }, 1.227 + }, 1.228 + { 1.229 + setup: 'pagemod remove element p', 1.230 + exec: { 1.231 + output: /^[^:]+: 3\. [^:]+: 3\.\s*$/ 1.232 + }, 1.233 + post: function() { 1.234 + let html = documentElement.innerHTML; 1.235 + 1.236 + is(html.indexOf('<p class="someclass">'), -1, "p.someclass removed"); 1.237 + is(html.indexOf('<p id="someid">'), -1, "p#someid removed"); 1.238 + is(html.indexOf("<p><strong>"), -1, "<p> wrapping <strong> removed"); 1.239 + isnot(html.indexOf("<span>"), -1, "<span> not removed"); 1.240 + 1.241 + resetContent(); 1.242 + } 1.243 + }, 1.244 + { 1.245 + setup: 'pagemod remove element p head', 1.246 + exec: { 1.247 + output: /^[^:]+: 0\. [^:]+: 0\.\s*$/ 1.248 + }, 1.249 + post: function() { 1.250 + is(documentElement.innerHTML, initialHtml, "nothing changed in the page"); 1.251 + } 1.252 + }, 1.253 + { 1.254 + setup: 'pagemod remove element p --ifEmptyOnly', 1.255 + exec: { 1.256 + output: /^[^:]+: 3\. [^:]+: 0\.\s*$/ 1.257 + }, 1.258 + post: function() { 1.259 + is(documentElement.innerHTML, initialHtml, "nothing changed in the page"); 1.260 + } 1.261 + }, 1.262 + { 1.263 + setup: 'pagemod remove element meta,title --ifEmptyOnly', 1.264 + exec: { 1.265 + output: /^[^:]+: 2\. [^:]+: 1\.\s*$/ 1.266 + }, 1.267 + post: function() { 1.268 + let html = documentElement.innerHTML; 1.269 + 1.270 + is(html.indexOf("<meta charset="), -1, "<meta> removed"); 1.271 + isnot(html.indexOf("<title>"), -1, "<title> not removed"); 1.272 + 1.273 + resetContent(); 1.274 + } 1.275 + }, 1.276 + { 1.277 + setup: 'pagemod remove element p --stripOnly', 1.278 + exec: { 1.279 + output: /^[^:]+: 3\. [^:]+: 3\.\s*$/ 1.280 + }, 1.281 + post: function() { 1.282 + let html = documentElement.innerHTML; 1.283 + 1.284 + is(html.indexOf('<p class="someclass">'), -1, "p.someclass removed"); 1.285 + is(html.indexOf('<p id="someid">'), -1, "p#someid removed"); 1.286 + is(html.indexOf("<p><strong>"), -1, "<p> wrapping <strong> removed"); 1.287 + isnot(html.indexOf(".someclass"), -1, ".someclass still exists"); 1.288 + isnot(html.indexOf("#someid"), -1, "#someid still exists"); 1.289 + isnot(html.indexOf("<strong>p"), -1, "<strong> still exists"); 1.290 + 1.291 + resetContent(); 1.292 + } 1.293 + }, 1.294 + ]); 1.295 + 1.296 + // Test 'pagemod remove attribute' 1.297 + yield helpers.audit(options, [ 1.298 + { 1.299 + setup: 'pagemod remove attribute', 1.300 + check: { 1.301 + input: 'pagemod remove attribute', 1.302 + hints: ' <searchAttributes> <searchElements> [root] [ignoreCase]', 1.303 + markup: 'VVVVVVVVVVVVVVVVVVVVVVVV', 1.304 + status: 'ERROR', 1.305 + args: { 1.306 + searchAttributes: { value: undefined, status: 'INCOMPLETE' }, 1.307 + searchElements: { value: undefined, status: 'INCOMPLETE' }, 1.308 + root: { value: undefined }, 1.309 + ignoreCase: { value: false }, 1.310 + } 1.311 + }, 1.312 + }, 1.313 + { 1.314 + setup: 'pagemod remove attribute foo bar', 1.315 + check: { 1.316 + input: 'pagemod remove attribute foo bar', 1.317 + hints: ' [root] [ignoreCase]', 1.318 + markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV', 1.319 + status: 'VALID', 1.320 + args: { 1.321 + searchAttributes: { value: 'foo' }, 1.322 + searchElements: { value: 'bar' }, 1.323 + root: { value: undefined }, 1.324 + ignoreCase: { value: false }, 1.325 + } 1.326 + }, 1.327 + post: function() { 1.328 + let deferred = promise.defer(); 1.329 + executeSoon(function() { 1.330 + deferred.resolve(); 1.331 + }); 1.332 + return deferred.promise; 1.333 + } 1.334 + }, 1.335 + { 1.336 + setup: 'pagemod remove attribute foo bar', 1.337 + exec: { 1.338 + output: /^[^:]+: 0\. [^:]+: 0\.\s*$/ 1.339 + }, 1.340 + post: function() { 1.341 + is(documentElement.innerHTML, initialHtml, "nothing changed in the page"); 1.342 + } 1.343 + }, 1.344 + { 1.345 + setup: 'pagemod remove attribute foo p', 1.346 + exec: { 1.347 + output: /^[^:]+: 3\. [^:]+: 0\.\s*$/ 1.348 + }, 1.349 + post: function() { 1.350 + is(documentElement.innerHTML, initialHtml, "nothing changed in the page"); 1.351 + } 1.352 + }, 1.353 + { 1.354 + setup: 'pagemod remove attribute id p,span', 1.355 + exec: { 1.356 + output: /^[^:]+: 5\. [^:]+: 1\.\s*$/ 1.357 + }, 1.358 + post: function() { 1.359 + is(documentElement.innerHTML.indexOf('<p id="someid">#someid'), -1, 1.360 + "p#someid attribute removed"); 1.361 + isnot(documentElement.innerHTML.indexOf("<p>#someid"), -1, 1.362 + "p with someid content still exists"); 1.363 + 1.364 + resetContent(); 1.365 + } 1.366 + }, 1.367 + { 1.368 + setup: 'pagemod remove attribute Class p', 1.369 + exec: { 1.370 + output: /^[^:]+: 3\. [^:]+: 0\.\s*$/ 1.371 + }, 1.372 + post: function() { 1.373 + is(documentElement.innerHTML, initialHtml, "nothing changed in the page"); 1.374 + } 1.375 + }, 1.376 + { 1.377 + setup: 'pagemod remove attribute Class p --ignoreCase', 1.378 + exec: { 1.379 + output: /^[^:]+: 3\. [^:]+: 1\.\s*$/ 1.380 + }, 1.381 + post: function() { 1.382 + is(documentElement.innerHTML.indexOf('<p class="someclass">.someclass'), -1, 1.383 + "p.someclass attribute removed"); 1.384 + isnot(documentElement.innerHTML.indexOf("<p>.someclass"), -1, 1.385 + "p with someclass content still exists"); 1.386 + 1.387 + resetContent(); 1.388 + } 1.389 + }, 1.390 + ]); 1.391 + 1.392 + // Shutdown 1.393 + yield helpers.closeToolbar(options); 1.394 + yield helpers.closeTab(options); 1.395 +}