parser/htmlparser/tests/mochitest/test_bug613662.xhtml

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/parser/htmlparser/tests/mochitest/test_bug613662.xhtml	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,137 @@
     1.4 +<html xmlns="http://www.w3.org/1999/xhtml">
     1.5 +<!--
     1.6 +https://bugzilla.mozilla.org/show_bug.cgi?id=613662
     1.7 +-->
     1.8 +<head>
     1.9 +  <title>Test for Bug 613662</title>
    1.10 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.11 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.12 +</head>
    1.13 +<body>
    1.14 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=613662">Mozilla Bug 613662</a>
    1.15 +<p id="display"></p><div id="content" style="display: none"></div><div id="content2" style="display: none"></div><pre id="test">
    1.16 +<script type="application/javascript"><![CDATA[
    1.17 +
    1.18 +SimpleTest.expectAssertions(1);
    1.19 +
    1.20 +/** Test for Bug 613662 **/
    1.21 +
    1.22 +function testPositions(node) {
    1.23 +  node.insertAdjacentHTML("beforeBegin", "\u003Cscript>ok(false, 'script should not have run');\u003C/script><i></i>");
    1.24 +  is(node.previousSibling.localName, "i", "Should have had <i> as previous sibling");
    1.25 +  node.insertAdjacentHTML("Afterbegin", "<b></b>\u003Cscript>ok(false, 'script should not have run');\u003C/script>");
    1.26 +  is(node.firstChild.localName, "b", "Should have had <b> as first child");
    1.27 +  node.insertAdjacentHTML("BeforeEnd", "\u003Cscript>ok(false, 'script should not have run');\u003C/script><u></u>");
    1.28 +  is(node.lastChild.localName, "u", "Should have had <u> as last child");
    1.29 +  node.insertAdjacentHTML("afterend", "<a></a>\u003Cscript>ok(false, 'script should not have run');\u003C/script>");
    1.30 +  is(node.nextSibling.localName, "a", "Should have had <a> as next sibling");
    1.31 +}
    1.32 +
    1.33 +var content = document.getElementById("content");
    1.34 +testPositions(content); // without next sibling
    1.35 +testPositions(content); // test again when there's next sibling
    1.36 +
    1.37 +try {
    1.38 +  content.insertAdjacentHTML("bar", "foo");
    1.39 +  ok(false, "insertAdjacentHTML should have thrown");
    1.40 +} catch (e) {
    1.41 +  is(e.name, "SyntaxError", "insertAdjacentHTML should throw SyntaxError");
    1.42 +  is(e.code, 12, "insertAdjacentHTML should throw SYNTAX_ERR");
    1.43 +}
    1.44 +
    1.45 +var parent = document.createElementNS("http://www.w3.org/1999/xhtml", "div");
    1.46 +var child = document.createElementNS("http://www.w3.org/1999/xhtml", "div");
    1.47 +
    1.48 +try {
    1.49 +  child.insertAdjacentHTML("Beforebegin", "foo");
    1.50 +  ok(false, "insertAdjacentHTML should have thrown");
    1.51 +} catch (e) {
    1.52 +  is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError");
    1.53 +  is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR");
    1.54 +}
    1.55 +
    1.56 +try {
    1.57 +  child.insertAdjacentHTML("AfterEnd", "foo");
    1.58 +  ok(false, "insertAdjacentHTML should have thrown");
    1.59 +} catch (e) {
    1.60 +  is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError");
    1.61 +  is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR");
    1.62 +}
    1.63 +
    1.64 +child.insertAdjacentHTML("afterBegin", "foo"); // mustn't throw
    1.65 +child.insertAdjacentHTML("beforeend", "foo"); // mustn't throw
    1.66 +
    1.67 +parent.appendChild(child);
    1.68 +testPositions(child); // node not in tree but has parent
    1.69 +
    1.70 +content.appendChild(parent); // must not run scripts
    1.71 +
    1.72 +try {
    1.73 +  document.documentElement.insertAdjacentHTML("afterend", "<div></div>");
    1.74 +  ok(false, "insertAdjacentHTML should have thrown");
    1.75 +} catch (e) {
    1.76 +  is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError");
    1.77 +  is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR");
    1.78 +}
    1.79 +
    1.80 +var content2 = document.getElementById("content2");
    1.81 +
    1.82 +var events = [
    1.83 +  [ "DOMNodeInserted", document.body ],
    1.84 +  [ "DOMNodeInserted", document.body ],
    1.85 +  [ "DOMSubtreeModified", null ],
    1.86 +  [ "DOMNodeInserted", content2 ],
    1.87 +  [ "DOMNodeInserted", content2 ],
    1.88 +  [ "DOMSubtreeModified", null ],
    1.89 +  [ "DOMNodeInserted", content2 ],
    1.90 +  [ "DOMNodeInserted", content2 ],
    1.91 +  [ "DOMSubtreeModified", null ],
    1.92 +  [ "DOMNodeInserted", document.body ],
    1.93 +  [ "DOMNodeInserted", document.body ],
    1.94 +  [ "DOMSubtreeModified", null ],
    1.95 +  [ "DOMNodeInserted", document.body ],
    1.96 +  [ "DOMNodeInserted", document.body ],
    1.97 +  [ "DOMSubtreeModified", null ],
    1.98 +  [ "DOMNodeInserted", content2 ],
    1.99 +  [ "DOMNodeInserted", content2 ],
   1.100 +  [ "DOMSubtreeModified", null ],
   1.101 +  [ "DOMNodeInserted", content2 ],
   1.102 +  [ "DOMNodeInserted", content2 ],
   1.103 +  [ "DOMSubtreeModified", null ],
   1.104 +  [ "DOMNodeInserted", document.body ],
   1.105 +  [ "DOMNodeInserted", document.body ],
   1.106 +  [ "DOMSubtreeModified", null ]
   1.107 +];
   1.108 +
   1.109 +function mutationEventListener(evt) {
   1.110 +  var expected = events.shift();
   1.111 +  is(evt.type, expected[0], "Unexpected mutation type");
   1.112 +  is(evt.relatedNode, expected[1], "Unexpected related node");
   1.113 +}
   1.114 +
   1.115 +document.addEventListener("DOMSubtreeModified", mutationEventListener, false);
   1.116 +document.addEventListener("DOMNodeInserted", mutationEventListener, false);
   1.117 +document.addEventListener("DOMNodeRemoved", mutationEventListener, false);
   1.118 +document.addEventListener("DOMNodeRemovedFromDocument", mutationEventListener, false);
   1.119 +document.addEventListener("DOMNodeInsertedIntoDocument", mutationEventListener, false);
   1.120 +document.addEventListener("DOMAttrModified", mutationEventListener, false);
   1.121 +document.addEventListener("DOMCharacterDataModified", mutationEventListener, false);
   1.122 +
   1.123 +testPositions(content2); // without next sibling
   1.124 +testPositions(content2); // test again when there's next sibling
   1.125 +
   1.126 +is(events.length, 0, "Not all expected events fired.");
   1.127 +
   1.128 +// XML-only:
   1.129 +try {
   1.130 +  content.insertAdjacentHTML("beforeend", "<p>");
   1.131 +  ok(false, "insertAdjacentHTML should have thrown");
   1.132 +} catch (e) {
   1.133 +  is(e.name, "SyntaxError", "insertAdjacentHTML should throw SyntaxError");
   1.134 +  is(e.code, 12, "insertAdjacentHTML should throw SYNTAX_ERR");
   1.135 +}
   1.136 +
   1.137 +]]></script>
   1.138 +</pre>
   1.139 +</body>
   1.140 +</html>

mercurial