/* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ // Tests that the inspect command works as it should const TEST_URI = "http://example.com/browser/browser/devtools/commandline/"+ "test/browser_cmd_pagemod_export.html"; function test() { let initialHtml = ""; DeveloperToolbarTest.test(TEST_URI, [ init, testExportHtml, testPageModReplace, testPageModRemoveElement, testPageModRemoveAttribute ]); function init() { initialHtml = content.document.documentElement.innerHTML; } function testExportHtml() { helpers.setInput('export html'); helpers.check({ input: 'export html', hints: '', markup: 'VVVVVVVVVVV', status: 'VALID' }); let oldOpen = content.open; let openURL = ""; content.open = function(aUrl) { openURL = aUrl; }; DeveloperToolbarTest.exec({ blankOutput: true }); openURL = decodeURIComponent(openURL); isnot(openURL.indexOf(''), -1, "export html works: "); isnot(openURL.indexOf("
#'), -1, "export html works:
");
content.open = oldOpen;
}
function getContent() {
return content.document.documentElement.innerHTML;
}
function resetContent() {
content.document.documentElement.innerHTML = initialHtml;
}
function testPageModReplace() {
helpers.setInput('pagemod replace');
helpers.check({
input: 'pagemod replace',
hints: ' .foOBarclass'), -1,
".someclass changed to .foOBarclass");
isnot(getContent().indexOf(' #foOBarid'), -1,
"#someid changed to #foOBarid");
resetContent();
DeveloperToolbarTest.exec({
typed: "pagemod replace some foobar --contentOnly",
outputMatch: /^[^:]+: 13\. [^:]+: 2\. [^:]+: 0\.\s*$/
});
isnot(getContent().indexOf(' .foobarclass'), -1,
".someclass changed to .foobarclass (content only)");
isnot(getContent().indexOf(' #foobarid'), -1,
"#someid changed to #foobarid (content only)");
resetContent();
DeveloperToolbarTest.exec({
typed: "pagemod replace some foobar --attrOnly",
outputMatch: /^[^:]+: 13\. [^:]+: 0\. [^:]+: 2\.\s*$/
});
isnot(getContent().indexOf(' #someid'), -1,
"#someid changed to #foobarid (attr only)");
resetContent();
DeveloperToolbarTest.exec({
typed: "pagemod replace some foobar --root head",
outputMatch: /^[^:]+: 2\. [^:]+: 0\. [^:]+: 0\.\s*$/
});
is(getContent(), initialHtml, "nothing changed");
DeveloperToolbarTest.exec({
typed: "pagemod replace some foobar --selector .someclass,div,span",
outputMatch: /^[^:]+: 4\. [^:]+: 1\. [^:]+: 1\.\s*$/
});
isnot(getContent().indexOf(' #someid'), -1,
"#someid did not change");
resetContent();
}
function testPageModRemoveElement() {
helpers.setInput('pagemod remove');
helpers.check({
input: 'pagemod remove',
hints: '',
markup: 'IIIIIIIVIIIIII',
status: 'ERROR'
});
helpers.setInput('pagemod remove element');
helpers.check({
input: 'pagemod remove element',
hints: ' '), -1, "p.someclass removed");
is(getContent().indexOf(' '), -1, "p#someid removed");
is(getContent().indexOf(" "), -1, " wrapping removed");
isnot(getContent().indexOf(""), -1, " not removed");
resetContent();
DeveloperToolbarTest.exec({
typed: "pagemod remove element p head",
outputMatch: /^[^:]+: 0\. [^:]+: 0\.\s*$/
});
is(getContent(), initialHtml, "nothing changed in the page");
DeveloperToolbarTest.exec({
typed: "pagemod remove element p --ifEmptyOnly",
outputMatch: /^[^:]+: 3\. [^:]+: 0\.\s*$/
});
is(getContent(), initialHtml, "nothing changed in the page");
DeveloperToolbarTest.exec({
typed: "pagemod remove element meta,title --ifEmptyOnly",
outputMatch: /^[^:]+: 2\. [^:]+: 1\.\s*$/
});
is(getContent().indexOf(" removed");
isnot(getContent().indexOf(" '), -1, "p.someclass removed");
is(getContent().indexOf(' '), -1, "p#someid removed");
is(getContent().indexOf(" "), -1, " wrapping removed");
isnot(getContent().indexOf(".someclass"), -1, ".someclass still exists");
isnot(getContent().indexOf("#someid"), -1, "#someid still exists");
isnot(getContent().indexOf("p"), -1, " still exists");
resetContent();
}
function testPageModRemoveAttribute() {
helpers.setInput('pagemod remove attribute ');
helpers.check({
input: 'pagemod remove attribute ',
hints: ' #someid'), -1,
"p#someid attribute removed");
isnot(getContent().indexOf(" #someid"), -1,
"p with someid content still exists");
resetContent();
DeveloperToolbarTest.exec({
typed: "pagemod remove attribute Class p",
outputMatch: /^[^:]+: 3\. [^:]+: 0\.\s*$/
});
is(getContent(), initialHtml, "nothing changed in the page");
DeveloperToolbarTest.exec({
typed: "pagemod remove attribute Class p --ignoreCase",
outputMatch: /^[^:]+: 3\. [^:]+: 1\.\s*$/
});
is(getContent().indexOf(' .someclass'), -1,
"p.someclass attribute removed");
isnot(getContent().indexOf(" .someclass"), -1,
"p with someclass content still exists");
resetContent();
}
}