michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Tests that the inspect command works as it should michael@0: michael@0: const TEST_URI = "http://example.com/browser/browser/devtools/commandline/"+ michael@0: "test/browser_cmd_pagemod_export.html"; michael@0: michael@0: function test() { michael@0: return Task.spawn(spawnTest).then(finish, helpers.handleError); michael@0: } michael@0: michael@0: function spawnTest() { michael@0: let options = yield helpers.openTab(TEST_URI); michael@0: yield helpers.openToolbar(options); michael@0: michael@0: const documentElement = options.document.documentElement; michael@0: const initialHtml = documentElement.innerHTML; michael@0: function resetContent() { michael@0: options.document.documentElement.innerHTML = initialHtml; michael@0: } michael@0: michael@0: // Test exporting HTML michael@0: let oldOpen = options.window.open; michael@0: let openURL = ""; michael@0: options.window.open = function(url) { michael@0: // The URL is a data: URL that contains the document source michael@0: openURL = decodeURIComponent(url); michael@0: }; michael@0: michael@0: yield helpers.audit(options, [ michael@0: { michael@0: setup: 'export html', michael@0: skipIf: true, michael@0: check: { michael@0: input: 'export html', michael@0: hints: ' [destination]', michael@0: markup: 'VVVVVVVVVVV', michael@0: status: 'VALID', michael@0: }, michael@0: exec: { michael@0: output: '' michael@0: }, michael@0: post: function() { michael@0: isnot(openURL.indexOf(''), -1, "export html works: "); michael@0: isnot(openURL.indexOf("GCLI"), -1, "export html works: <title>"); michael@0: isnot(openURL.indexOf('<p id="someid">#'), -1, "export html works: <p>"); michael@0: } michael@0: }, michael@0: { michael@0: setup: 'export html stdout', michael@0: check: { michael@0: input: 'export html stdout', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVVVVVVV', michael@0: status: 'VALID', michael@0: args: { michael@0: destination: { value: "stdout" } michael@0: }, michael@0: }, michael@0: exec: { michael@0: output: [ michael@0: /<html lang="en">/, michael@0: /<title>GCLI/, michael@0: /<p id="someid">#/ michael@0: ] michael@0: } michael@0: } michael@0: ]); michael@0: michael@0: options.window.open = oldOpen; michael@0: oldOpen = undefined; michael@0: michael@0: // Test 'pagemod replace' michael@0: yield helpers.audit(options, [ michael@0: { michael@0: setup: 'pagemod replace', michael@0: check: { michael@0: input: 'pagemod replace', michael@0: hints: ' <search> <replace> [ignoreCase] [selector] [root] [attrOnly] [contentOnly] [attributes]', michael@0: markup: 'VVVVVVVVVVVVVVV', michael@0: status: 'ERROR' michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod replace some foo', michael@0: check: { michael@0: input: 'pagemod replace some foo', michael@0: hints: ' [ignoreCase] [selector] [root] [attrOnly] [contentOnly] [attributes]', michael@0: markup: 'VVVVVVVVVVVVVVVVVVVVVVVV', michael@0: status: 'VALID' michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod replace some foo true', michael@0: check: { michael@0: input: 'pagemod replace some foo true', michael@0: hints: ' [selector] [root] [attrOnly] [contentOnly] [attributes]', michael@0: markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVV', michael@0: status: 'VALID' michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod replace some foo true --attrOnly', michael@0: check: { michael@0: input: 'pagemod replace some foo true --attrOnly', michael@0: hints: ' [selector] [root] [contentOnly] [attributes]', michael@0: markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV', michael@0: status: 'VALID' michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod replace sOme foOBar', michael@0: exec: { michael@0: output: /^[^:]+: 13\. [^:]+: 0\. [^:]+: 0\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: is(documentElement.innerHTML, initialHtml, "no change in the page"); michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod replace sOme foOBar true', michael@0: exec: { michael@0: output: /^[^:]+: 13\. [^:]+: 2\. [^:]+: 2\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: let html = documentElement.innerHTML; michael@0: michael@0: isnot(html.indexOf('<p class="foOBarclass">.foOBarclass'), -1, michael@0: ".someclass changed to .foOBarclass"); michael@0: isnot(html.indexOf('<p id="foOBarid">#foOBarid'), -1, michael@0: "#someid changed to #foOBarid"); michael@0: michael@0: resetContent(); michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod replace some foobar --contentOnly', michael@0: exec: { michael@0: output: /^[^:]+: 13\. [^:]+: 2\. [^:]+: 0\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: let html = documentElement.innerHTML; michael@0: michael@0: isnot(html.indexOf('<p class="someclass">.foobarclass'), -1, michael@0: ".someclass changed to .foobarclass (content only)"); michael@0: isnot(html.indexOf('<p id="someid">#foobarid'), -1, michael@0: "#someid changed to #foobarid (content only)"); michael@0: michael@0: resetContent(); michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod replace some foobar --attrOnly', michael@0: exec: { michael@0: output: /^[^:]+: 13\. [^:]+: 0\. [^:]+: 2\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: let html = documentElement.innerHTML; michael@0: michael@0: isnot(html.indexOf('<p class="foobarclass">.someclass'), -1, michael@0: ".someclass changed to .foobarclass (attr only)"); michael@0: isnot(html.indexOf('<p id="foobarid">#someid'), -1, michael@0: "#someid changed to #foobarid (attr only)"); michael@0: michael@0: resetContent(); michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod replace some foobar --root head', michael@0: exec: { michael@0: output: /^[^:]+: 2\. [^:]+: 0\. [^:]+: 0\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: is(documentElement.innerHTML, initialHtml, "nothing changed"); michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod replace some foobar --selector .someclass,div,span', michael@0: exec: { michael@0: output: /^[^:]+: 4\. [^:]+: 1\. [^:]+: 1\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: let html = documentElement.innerHTML; michael@0: michael@0: isnot(html.indexOf('<p class="foobarclass">.foobarclass'), -1, michael@0: ".someclass changed to .foobarclass"); michael@0: isnot(html.indexOf('<p id="someid">#someid'), -1, michael@0: "#someid did not change"); michael@0: michael@0: resetContent(); michael@0: } michael@0: }, michael@0: ]); michael@0: michael@0: // Test 'pagemod remove element' michael@0: yield helpers.audit(options, [ michael@0: { michael@0: setup: 'pagemod remove', michael@0: check: { michael@0: input: 'pagemod remove', michael@0: hints: ' attribute', michael@0: markup: 'IIIIIIIVIIIIII', michael@0: status: 'ERROR' michael@0: }, michael@0: }, michael@0: { michael@0: setup: 'pagemod remove element', michael@0: check: { michael@0: input: 'pagemod remove element', michael@0: hints: ' <search> [root] [stripOnly] [ifEmptyOnly]', michael@0: markup: 'VVVVVVVVVVVVVVVVVVVVVV', michael@0: status: 'ERROR' michael@0: }, michael@0: }, michael@0: { michael@0: setup: 'pagemod remove element foo', michael@0: check: { michael@0: input: 'pagemod remove element foo', michael@0: hints: ' [root] [stripOnly] [ifEmptyOnly]', michael@0: markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVV', michael@0: status: 'VALID' michael@0: }, michael@0: }, michael@0: { michael@0: setup: 'pagemod remove element p', michael@0: exec: { michael@0: output: /^[^:]+: 3\. [^:]+: 3\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: let html = documentElement.innerHTML; michael@0: michael@0: is(html.indexOf('<p class="someclass">'), -1, "p.someclass removed"); michael@0: is(html.indexOf('<p id="someid">'), -1, "p#someid removed"); michael@0: is(html.indexOf("<p><strong>"), -1, "<p> wrapping <strong> removed"); michael@0: isnot(html.indexOf("<span>"), -1, "<span> not removed"); michael@0: michael@0: resetContent(); michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod remove element p head', michael@0: exec: { michael@0: output: /^[^:]+: 0\. [^:]+: 0\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: is(documentElement.innerHTML, initialHtml, "nothing changed in the page"); michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod remove element p --ifEmptyOnly', michael@0: exec: { michael@0: output: /^[^:]+: 3\. [^:]+: 0\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: is(documentElement.innerHTML, initialHtml, "nothing changed in the page"); michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod remove element meta,title --ifEmptyOnly', michael@0: exec: { michael@0: output: /^[^:]+: 2\. [^:]+: 1\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: let html = documentElement.innerHTML; michael@0: michael@0: is(html.indexOf("<meta charset="), -1, "<meta> removed"); michael@0: isnot(html.indexOf("<title>"), -1, "<title> not removed"); michael@0: michael@0: resetContent(); michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod remove element p --stripOnly', michael@0: exec: { michael@0: output: /^[^:]+: 3\. [^:]+: 3\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: let html = documentElement.innerHTML; michael@0: michael@0: is(html.indexOf('<p class="someclass">'), -1, "p.someclass removed"); michael@0: is(html.indexOf('<p id="someid">'), -1, "p#someid removed"); michael@0: is(html.indexOf("<p><strong>"), -1, "<p> wrapping <strong> removed"); michael@0: isnot(html.indexOf(".someclass"), -1, ".someclass still exists"); michael@0: isnot(html.indexOf("#someid"), -1, "#someid still exists"); michael@0: isnot(html.indexOf("<strong>p"), -1, "<strong> still exists"); michael@0: michael@0: resetContent(); michael@0: } michael@0: }, michael@0: ]); michael@0: michael@0: // Test 'pagemod remove attribute' michael@0: yield helpers.audit(options, [ michael@0: { michael@0: setup: 'pagemod remove attribute', michael@0: check: { michael@0: input: 'pagemod remove attribute', michael@0: hints: ' <searchAttributes> <searchElements> [root] [ignoreCase]', michael@0: markup: 'VVVVVVVVVVVVVVVVVVVVVVVV', michael@0: status: 'ERROR', michael@0: args: { michael@0: searchAttributes: { value: undefined, status: 'INCOMPLETE' }, michael@0: searchElements: { value: undefined, status: 'INCOMPLETE' }, michael@0: root: { value: undefined }, michael@0: ignoreCase: { value: false }, michael@0: } michael@0: }, michael@0: }, michael@0: { michael@0: setup: 'pagemod remove attribute foo bar', michael@0: check: { michael@0: input: 'pagemod remove attribute foo bar', michael@0: hints: ' [root] [ignoreCase]', michael@0: markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV', michael@0: status: 'VALID', michael@0: args: { michael@0: searchAttributes: { value: 'foo' }, michael@0: searchElements: { value: 'bar' }, michael@0: root: { value: undefined }, michael@0: ignoreCase: { value: false }, michael@0: } michael@0: }, michael@0: post: function() { michael@0: let deferred = promise.defer(); michael@0: executeSoon(function() { michael@0: deferred.resolve(); michael@0: }); michael@0: return deferred.promise; michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod remove attribute foo bar', michael@0: exec: { michael@0: output: /^[^:]+: 0\. [^:]+: 0\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: is(documentElement.innerHTML, initialHtml, "nothing changed in the page"); michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod remove attribute foo p', michael@0: exec: { michael@0: output: /^[^:]+: 3\. [^:]+: 0\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: is(documentElement.innerHTML, initialHtml, "nothing changed in the page"); michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod remove attribute id p,span', michael@0: exec: { michael@0: output: /^[^:]+: 5\. [^:]+: 1\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: is(documentElement.innerHTML.indexOf('<p id="someid">#someid'), -1, michael@0: "p#someid attribute removed"); michael@0: isnot(documentElement.innerHTML.indexOf("<p>#someid"), -1, michael@0: "p with someid content still exists"); michael@0: michael@0: resetContent(); michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod remove attribute Class p', michael@0: exec: { michael@0: output: /^[^:]+: 3\. [^:]+: 0\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: is(documentElement.innerHTML, initialHtml, "nothing changed in the page"); michael@0: } michael@0: }, michael@0: { michael@0: setup: 'pagemod remove attribute Class p --ignoreCase', michael@0: exec: { michael@0: output: /^[^:]+: 3\. [^:]+: 1\.\s*$/ michael@0: }, michael@0: post: function() { michael@0: is(documentElement.innerHTML.indexOf('<p class="someclass">.someclass'), -1, michael@0: "p.someclass attribute removed"); michael@0: isnot(documentElement.innerHTML.indexOf("<p>.someclass"), -1, michael@0: "p with someclass content still exists"); michael@0: michael@0: resetContent(); michael@0: } michael@0: }, michael@0: ]); michael@0: michael@0: // Shutdown michael@0: yield helpers.closeToolbar(options); michael@0: yield helpers.closeTab(options); michael@0: }