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("
#'), -1, "export html works:
"); 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: //, michael@0: /
#/
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: ' .foOBarclass'), -1,
michael@0: ".someclass changed to .foOBarclass");
michael@0: isnot(html.indexOf(' #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(' .foobarclass'), -1,
michael@0: ".someclass changed to .foobarclass (content only)");
michael@0: isnot(html.indexOf(' #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(' #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(' #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: ' '), -1, "p.someclass removed");
michael@0: is(html.indexOf(' '), -1, "p#someid removed");
michael@0: is(html.indexOf(" "), -1, " wrapping removed");
michael@0: isnot(html.indexOf(""), -1, " 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(" removed");
michael@0: isnot(html.indexOf(" '), -1, "p.someclass removed");
michael@0: is(html.indexOf(' '), -1, "p#someid removed");
michael@0: is(html.indexOf(" "), -1, " wrapping 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("p"), -1, " 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: ' #someid'), -1,
michael@0: "p#someid attribute removed");
michael@0: isnot(documentElement.innerHTML.indexOf(" #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(' .someclass'), -1,
michael@0: "p.someclass attribute removed");
michael@0: isnot(documentElement.innerHTML.indexOf(" .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: }