summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/general/test_outerHTML.xhtml
blob: e1274a2595f001987516ff44cd1dc4906aa70d3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=92264
-->
<head>
  <title>Test for Bug 92264</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body onload="runTest();">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=92264">Mozilla Bug 92264</a>
<p id="display"></p>
<div id="content" style="display: none">
<div id="wrap"><dl></dl><p id="thep">foo<span>bar</span></p><ol></ol></div>
<table id="thetable"><tbody><tr><td>1</td></tr><tr id="thetr"><td>2</td></tr><tr><td>3</td></tr></tbody></table>
<iframe></iframe>
<div id="fragmentwrap"></div>
</div>
<pre id="test">
<script type="application/javascript">
<![CDATA[

/** Test for Bug 92264 **/

SimpleTest.waitForExplicitFinish();

function runTest() {

  var thep = document.getElementById("thep");
  var wrap = document.getElementById("wrap");
  is(thep.outerHTML, '<p xmlns="http://www.w3.org/1999/xhtml" id="thep">foo<span>bar</span></p>', "Unexpected thep outerHTML");
  thep.outerHTML = "<ul></ul><tr></tr><p></p>";
  is(wrap.innerHTML, '<dl xmlns="http://www.w3.org/1999/xhtml"></dl><ul xmlns="http://www.w3.org/1999/xhtml"></ul><tr xmlns="http://www.w3.org/1999/xhtml"></tr><p xmlns="http://www.w3.org/1999/xhtml"></p><ol xmlns="http://www.w3.org/1999/xhtml"></ol>', "Bad outerHTML parsing inside wrap");

  var thetr = document.getElementById("thetr");
  thetr.outerHTML = "<tr><td>a</td></tr><div></div><tr><td>b</td></tr>";
  var thetable = document.getElementById("thetable");
  is(thetable.innerHTML, '<tbody xmlns="http://www.w3.org/1999/xhtml"><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");

  var iframe = document.getElementsByTagName("iframe")[0];
  var oldbody = iframe.contentDocument.body;
  iframe.contentDocument.body.outerHTML = "<body></body>";
  isnot(oldbody, iframe.contentDocument.body, "Failed to replace body");
  is(iframe.contentDocument.getElementsByTagName("body").length, 1, "Should have gotten one body");
  // Yes, two heads per spec. Also Ragnarök and Chrome produce two heads.
  is(iframe.contentDocument.getElementsByTagName("head").length, 2, "Should have gotten two heads");

  try {
    document.documentElement.outerHTML = "<html></html>";
    ok(false, "Should have thrown an exception");
  } catch(e) {
    is(e.name, "NoModificationAllowedError", "outerHTML should throw NoModificationAllowedError");
    is(e.code, 7, "outerHTML should throw NO_MODIFICATION_ALLOWED_ERR");
  }

  var f = document.createDocumentFragment();
  var dl = document.createElement("dl");
  var p = document.createElement("p");
  var ol = document.createElement("ol");
  f.appendChild(dl);
  f.appendChild(p);
  f.appendChild(ol);
  p.outerHTML = "<ul></ul><tr></tr><body></body><p></p>";
  var fragmentwrap = document.getElementById("fragmentwrap");
  fragmentwrap.appendChild(f);
  is(fragmentwrap.innerHTML, '<dl xmlns="http://www.w3.org/1999/xhtml"></dl><ul xmlns="http://www.w3.org/1999/xhtml"></ul><tr xmlns="http://www.w3.org/1999/xhtml"></tr><body xmlns="http://www.w3.org/1999/xhtml"></body><p xmlns="http://www.w3.org/1999/xhtml"></p><ol xmlns="http://www.w3.org/1999/xhtml"></ol>', "Bad outerHTML parsing in fragment");

  SimpleTest.finish();
}
]]>
</script>
</pre>
</body>
</html>