dom/tests/mochitest/general/test_outerHTML.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/general/test_outerHTML.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=92264
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 92264</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body onload="runTest();">
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=92264">Mozilla Bug 92264</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none">
    1.18 +<div id="wrap"><dl></dl><p id="thep">foo<span>bar</span></p><ol></ol></div>
    1.19 +<table id="thetable"><tbody><tr><td>1</td></tr><tr id="thetr"><td>2</td></tr><tr><td>3</td></tr></tbody></table>
    1.20 +<iframe></iframe>
    1.21 +<div id="fragmentwrap"></div>
    1.22 +</div>
    1.23 +<pre id="test">
    1.24 +<script type="application/javascript">
    1.25 +
    1.26 +/** Test for Bug 92264 **/
    1.27 +
    1.28 +SimpleTest.waitForExplicitFinish();
    1.29 +
    1.30 +function runTest() {
    1.31 +
    1.32 +  var thep = document.getElementById("thep");
    1.33 +  var wrap = document.getElementById("wrap");
    1.34 +  is(thep.outerHTML, '<p id="thep">foo<span>bar</span></p>', "Unexpected thep outerHTML");
    1.35 +  thep.outerHTML = "<ul></ul><tr></tr><p></p>";
    1.36 +  is(wrap.innerHTML, "<dl></dl><ul></ul><p></p><ol></ol>", "Bad outerHTML parsing inside wrap");
    1.37 +
    1.38 +  var thetr = document.getElementById("thetr");
    1.39 +  thetr.outerHTML = "<tr><td>a</td></tr><div></div><tr><td>b</td></tr>";
    1.40 +  var thetable = document.getElementById("thetable");
    1.41 +  is(thetable.innerHTML, "<tbody><tr><td>1</td></tr><tr><td>a</td></tr><div></div><tr><td>b</td></tr><tr><td>3</td></tr></tbody>", "Wrong outerHTML parsing inside table");
    1.42 +
    1.43 +  var iframe = document.getElementsByTagName("iframe")[0];
    1.44 +  var oldbody = iframe.contentDocument.body;
    1.45 +  iframe.contentDocument.body.outerHTML = "<body></body>";
    1.46 +  isnot(oldbody, iframe.contentDocument.body, "Failed to replace body");
    1.47 +  is(iframe.contentDocument.getElementsByTagName("body").length, 1, "Should have gotten one body");
    1.48 +  // Yes, two heads per spec. Also Ragnarök and Chrome produce two heads.
    1.49 +  is(iframe.contentDocument.getElementsByTagName("head").length, 2, "Should have gotten two heads");
    1.50 +
    1.51 +  try {
    1.52 +    document.documentElement.outerHTML = "<html></html>";
    1.53 +    ok(false, "Should have thrown an exception");
    1.54 +  } catch(e) {
    1.55 +    is(e.name, "NoModificationAllowedError", "outerHTML should throw NoModificationAllowedError");
    1.56 +    is(e.code, 7, "outerHTML should throw NO_MODIFICATION_ALLOWED_ERR");
    1.57 +  }
    1.58 +
    1.59 +  var f = document.createDocumentFragment();
    1.60 +  var dl = document.createElement("dl");
    1.61 +  var p = document.createElement("p");
    1.62 +  var ol = document.createElement("ol");
    1.63 +  f.appendChild(dl);
    1.64 +  f.appendChild(p);
    1.65 +  f.appendChild(ol);
    1.66 +  p.outerHTML = "<ul></ul><tr></tr><body></body><p></p>";
    1.67 +  var fragmentwrap = document.getElementById("fragmentwrap");
    1.68 +  fragmentwrap.appendChild(f);
    1.69 +  is(fragmentwrap.innerHTML, "<dl></dl><ul></ul><p></p><ol></ol>", "Bad outerHTML parsing in fragment");
    1.70 +
    1.71 +  SimpleTest.finish();
    1.72 +}
    1.73 +
    1.74 +</script>
    1.75 +</pre>
    1.76 +</body>
    1.77 +</html>

mercurial