browser/devtools/commandline/test/browser_cmd_pagemod_export.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial