Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 2 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | // Test outerHTML edition via the markup-view |
michael@0 | 8 | |
michael@0 | 9 | loadHelperScript("helper_outerhtml_test_runner.js"); |
michael@0 | 10 | |
michael@0 | 11 | const TEST_DATA = [ |
michael@0 | 12 | { |
michael@0 | 13 | selector: "#badMarkup1", |
michael@0 | 14 | oldHTML: '<div id="badMarkup1">badMarkup1</div>', |
michael@0 | 15 | newHTML: '<div id="badMarkup1">badMarkup1</div> hanging</div>', |
michael@0 | 16 | validate: function(pageNode, selectedNode) { |
michael@0 | 17 | is(pageNode, selectedNode, "Original element is selected"); |
michael@0 | 18 | |
michael@0 | 19 | let textNode = pageNode.nextSibling; |
michael@0 | 20 | |
michael@0 | 21 | is(textNode.nodeName, "#text", "Sibling is a text element"); |
michael@0 | 22 | is(textNode.data, " hanging", "New text node has expected text content"); |
michael@0 | 23 | } |
michael@0 | 24 | }, |
michael@0 | 25 | { |
michael@0 | 26 | selector: "#badMarkup2", |
michael@0 | 27 | oldHTML: '<div id="badMarkup2">badMarkup2</div>', |
michael@0 | 28 | newHTML: '<div id="badMarkup2">badMarkup2</div> hanging<div></div></div></div></body>', |
michael@0 | 29 | validate: function(pageNode, selectedNode) { |
michael@0 | 30 | is(pageNode, selectedNode, "Original element is selected"); |
michael@0 | 31 | |
michael@0 | 32 | let textNode = pageNode.nextSibling; |
michael@0 | 33 | |
michael@0 | 34 | is(textNode.nodeName, "#text", "Sibling is a text element"); |
michael@0 | 35 | is(textNode.data, " hanging", "New text node has expected text content"); |
michael@0 | 36 | } |
michael@0 | 37 | }, |
michael@0 | 38 | { |
michael@0 | 39 | selector: "#badMarkup3", |
michael@0 | 40 | oldHTML: '<div id="badMarkup3">badMarkup3</div>', |
michael@0 | 41 | newHTML: '<div id="badMarkup3">badMarkup3 <em>Emphasized <strong> and strong</div>', |
michael@0 | 42 | validate: function(pageNode, selectedNode) { |
michael@0 | 43 | is(pageNode, selectedNode, "Original element is selected"); |
michael@0 | 44 | |
michael@0 | 45 | let em = getNode("#badMarkup3 em"); |
michael@0 | 46 | let strong = getNode("#badMarkup3 strong"); |
michael@0 | 47 | |
michael@0 | 48 | is(em.textContent, "Emphasized and strong", "<em> was auto created"); |
michael@0 | 49 | is(strong.textContent, " and strong", "<strong> was auto created"); |
michael@0 | 50 | } |
michael@0 | 51 | }, |
michael@0 | 52 | { |
michael@0 | 53 | selector: "#badMarkup4", |
michael@0 | 54 | oldHTML: '<div id="badMarkup4">badMarkup4</div>', |
michael@0 | 55 | newHTML: '<div id="badMarkup4">badMarkup4</p>', |
michael@0 | 56 | validate: function(pageNode, selectedNode) { |
michael@0 | 57 | is(pageNode, selectedNode, "Original element is selected"); |
michael@0 | 58 | |
michael@0 | 59 | let div = getNode("#badMarkup4"); |
michael@0 | 60 | let p = getNode("#badMarkup4 p"); |
michael@0 | 61 | |
michael@0 | 62 | is(div.textContent, "badMarkup4", "textContent is correct"); |
michael@0 | 63 | is(div.tagName, "DIV", "did not change to <p> tag"); |
michael@0 | 64 | is(p.textContent, "", "The <p> tag has no children"); |
michael@0 | 65 | is(p.tagName, "P", "Created an empty <p> tag"); |
michael@0 | 66 | } |
michael@0 | 67 | }, |
michael@0 | 68 | { |
michael@0 | 69 | selector: "#badMarkup5", |
michael@0 | 70 | oldHTML: '<p id="badMarkup5">badMarkup5</p>', |
michael@0 | 71 | newHTML: '<p id="badMarkup5">badMarkup5 <div>with a nested div</div></p>', |
michael@0 | 72 | validate: function(pageNode, selectedNode) { |
michael@0 | 73 | is(pageNode, selectedNode, "Original element is selected"); |
michael@0 | 74 | |
michael@0 | 75 | let p = getNode("#badMarkup5"); |
michael@0 | 76 | let nodiv = getNode("#badMarkup5 div"); |
michael@0 | 77 | let div = getNode("#badMarkup5 ~ div"); |
michael@0 | 78 | |
michael@0 | 79 | ok(!nodiv, "The invalid markup got created as a sibling"); |
michael@0 | 80 | is(p.textContent, "badMarkup5 ", "The <p> tag does not take in the <div> content"); |
michael@0 | 81 | is(p.tagName, "P", "Did not change to a <div> tag"); |
michael@0 | 82 | is(div.textContent, "with a nested div", "textContent is correct"); |
michael@0 | 83 | is(div.tagName, "DIV", "Did not change to <p> tag"); |
michael@0 | 84 | } |
michael@0 | 85 | } |
michael@0 | 86 | ]; |
michael@0 | 87 | |
michael@0 | 88 | const TEST_URL = "data:text/html," + |
michael@0 | 89 | "<!DOCTYPE html>" + |
michael@0 | 90 | "<head><meta charset='utf-8' /></head>" + |
michael@0 | 91 | "<body>" + |
michael@0 | 92 | [outer.oldHTML for (outer of TEST_DATA)].join("\n") + |
michael@0 | 93 | "</body>" + |
michael@0 | 94 | "</html>"; |
michael@0 | 95 | |
michael@0 | 96 | let test = asyncTest(function*() { |
michael@0 | 97 | let {inspector} = yield addTab(TEST_URL).then(openInspector); |
michael@0 | 98 | inspector.markup._frame.focus(); |
michael@0 | 99 | yield runEditOuterHTMLTests(TEST_DATA, inspector); |
michael@0 | 100 | }); |