tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug613662.xhtml (3803B)


      1 <html xmlns="http://www.w3.org/1999/xhtml">
      2 <!--
      3 https://bugzilla.mozilla.org/show_bug.cgi?id=613662
      4 -->
      5 <head>
      6  <title>Test for Bug 613662</title>
      7  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      9 </head>
     10 <body>
     11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=613662">Mozilla Bug 613662</a>
     12 <p id="display"></p><div id="content" style="display: none"></div><div id="content2" style="display: none"></div><pre id="test">
     13 <script type="application/javascript"><![CDATA[
     14 
     15 SimpleTest.expectAssertions(1);
     16 
     17 /** Test for Bug 613662 */
     18 function test() {
     19  function testPositions(node) {
     20    node.insertAdjacentHTML("beforeBegin", "\u003Cscript>ok(false, 'script should not have run');\u003C/script><i></i>");
     21    is(node.previousSibling.localName, "i", "Should have had <i> as previous sibling");
     22    node.insertAdjacentHTML("Afterbegin", "<b></b>\u003Cscript>ok(false, 'script should not have run');\u003C/script>");
     23    is(node.firstChild.localName, "b", "Should have had <b> as first child");
     24    node.insertAdjacentHTML("BeforeEnd", "\u003Cscript>ok(false, 'script should not have run');\u003C/script><u></u>");
     25    is(node.lastChild.localName, "u", "Should have had <u> as last child");
     26    node.insertAdjacentHTML("afterend", "<a></a>\u003Cscript>ok(false, 'script should not have run');\u003C/script>");
     27    is(node.nextSibling.localName, "a", "Should have had <a> as next sibling");
     28  }
     29 
     30  var content = document.getElementById("content");
     31  testPositions(content); // without next sibling
     32  testPositions(content); // test again when there's next sibling
     33 
     34  try {
     35    content.insertAdjacentHTML("bar", "foo");
     36    ok(false, "insertAdjacentHTML should have thrown");
     37  } catch (e) {
     38    is(e.name, "SyntaxError", "insertAdjacentHTML should throw SyntaxError");
     39    is(e.code, 12, "insertAdjacentHTML should throw SYNTAX_ERR");
     40  }
     41 
     42  var parent = document.createElementNS("http://www.w3.org/1999/xhtml", "div");
     43  var child = document.createElementNS("http://www.w3.org/1999/xhtml", "div");
     44 
     45  try {
     46    child.insertAdjacentHTML("Beforebegin", "foo");
     47    ok(false, "insertAdjacentHTML should have thrown");
     48  } catch (e) {
     49    is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError");
     50    is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR");
     51  }
     52 
     53  try {
     54    child.insertAdjacentHTML("AfterEnd", "foo");
     55    ok(false, "insertAdjacentHTML should have thrown");
     56  } catch (e) {
     57    is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError");
     58    is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR");
     59  }
     60 
     61  child.insertAdjacentHTML("afterBegin", "foo"); // mustn't throw
     62  child.insertAdjacentHTML("beforeend", "foo"); // mustn't throw
     63 
     64  parent.appendChild(child);
     65  testPositions(child); // node not in tree but has parent
     66 
     67  content.appendChild(parent); // must not run scripts
     68 
     69  try {
     70    document.documentElement.insertAdjacentHTML("afterend", "<div></div>");
     71    ok(false, "insertAdjacentHTML should have thrown");
     72  } catch (e) {
     73    is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError");
     74    is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR");
     75  }
     76 
     77  // XML-only:
     78  try {
     79    content.insertAdjacentHTML("beforeend", "<p>");
     80    ok(false, "insertAdjacentHTML should have thrown");
     81  } catch (e) {
     82    is(e.name, "SyntaxError", "insertAdjacentHTML should throw SyntaxError");
     83    is(e.code, 12, "insertAdjacentHTML should throw SYNTAX_ERR");
     84  }
     85  SimpleTest.finish();
     86 }
     87 SimpleTest.waitForExplicitFinish();
     88 SimpleTest.executeSoon(test);
     89 ]]></script>
     90 </pre>
     91 </body>
     92 </html>