/* vim: set ts=2 et sw=2 tw=80: */ /* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ /* import-globals-from helper_outerhtml_test_runner.js */ "use strict"; // Test outerHTML edition via the markup-view loadHelperScript("helper_outerhtml_test_runner.js"); requestLongerTimeout(2); const TEST_DATA = [ { selector: "#badMarkup1", oldHTML: "
badMarkup1
", newHTML: "
badMarkup1
hanging", validate: function* ({pageNodeFront, selectedNodeFront, testActor}) { is(pageNodeFront, selectedNodeFront, "Original element is selected"); let textNodeName = yield testActor.eval(` content.document.querySelector("#badMarkup1").nextSibling.nodeName `); let textNodeData = yield testActor.eval(` content.document.querySelector("#badMarkup1").nextSibling.data `); is(textNodeName, "#text", "Sibling is a text element"); is(textNodeData, " hanging", "New text node has expected text content"); } }, { selector: "#badMarkup2", oldHTML: "
badMarkup2
", newHTML: "
badMarkup2
hanging
" + "", validate: function* ({pageNodeFront, selectedNodeFront, testActor}) { is(pageNodeFront, selectedNodeFront, "Original element is selected"); let textNodeName = yield testActor.eval(` content.document.querySelector("#badMarkup2").nextSibling.nodeName `); let textNodeData = yield testActor.eval(` content.document.querySelector("#badMarkup2").nextSibling.data `); is(textNodeName, "#text", "Sibling is a text element"); is(textNodeData, " hanging", "New text node has expected text content"); } }, { selector: "#badMarkup3", oldHTML: "
badMarkup3
", newHTML: "
badMarkup3 Emphasized " + "and strong
", validate: function* ({pageNodeFront, selectedNodeFront, testActor}) { is(pageNodeFront, selectedNodeFront, "Original element is selected"); let emText = yield testActor.getProperty("#badMarkup3 em", "textContent"); let strongText = yield testActor.getProperty("#badMarkup3 strong", "textContent"); is(emText, "Emphasized and strong", " was auto created"); is(strongText, " and strong", " was auto created"); } }, { selector: "#badMarkup4", oldHTML: "
badMarkup4
", newHTML: "
badMarkup4

", validate: function* ({pageNodeFront, selectedNodeFront, testActor}) { is(pageNodeFront, selectedNodeFront, "Original element is selected"); let divText = yield testActor.getProperty("#badMarkup4", "textContent"); let divTag = yield testActor.getProperty("#badMarkup4", "tagName"); let pText = yield testActor.getProperty("#badMarkup4 p", "textContent"); let pTag = yield testActor.getProperty("#badMarkup4 p", "tagName"); is(divText, "badMarkup4", "textContent is correct"); is(divTag, "DIV", "did not change to

tag"); is(pText, "", "The

tag has no children"); is(pTag, "P", "Created an empty

tag"); } }, { selector: "#badMarkup5", oldHTML: "

badMarkup5

", newHTML: "

badMarkup5

with a nested div

", validate: function* ({pageNodeFront, selectedNodeFront, testActor}) { is(pageNodeFront, selectedNodeFront, "Original element is selected"); let num = yield testActor.getNumberOfElementMatches("#badMarkup5 div"); let pText = yield testActor.getProperty("#badMarkup5", "textContent"); let pTag = yield testActor.getProperty("#badMarkup5", "tagName"); let divText = yield testActor.getProperty("#badMarkup5 ~ div", "textContent"); let divTag = yield testActor.getProperty("#badMarkup5 ~ div", "tagName"); is(num, 0, "The invalid markup got created as a sibling"); is(pText, "badMarkup5 ", "The p tag does not take in the div content"); is(pTag, "P", "Did not change to a
tag"); is(divText, "with a nested div", "textContent is correct"); is(divTag, "DIV", "Did not change to

tag"); } } ]; const TEST_URL = "data:text/html," + "" + "" + "" + TEST_DATA.map(outer => outer.oldHTML).join("\n") + "" + ""; add_task(function* () { let {inspector, testActor} = yield openInspectorForURL(TEST_URL); inspector.markup._frame.focus(); yield runEditOuterHTMLTests(TEST_DATA, inspector, testActor); });