summaryrefslogtreecommitdiff
path: root/dom/base/test/test_bug744830.html
blob: 4376b7447e9530406e47cb8780e25c1cdea4f2b6 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=744830
-->
<head>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=166235">Mozilla Bug 166235</a>
<div id="testnodes"><span>hi</span> there <!-- mon ami --></div>
<pre id="test">
<script type="application/javascript">
  var t = document.getElementById('testnodes');
  is(t.innerHTML,
     "<span>hi</span> there <!-- mon ami -->",
     "comment nodes should be included");

  var PI = document.createProcessingInstruction('foo', 'bar="1.0"');
  t.appendChild(PI);
  is(t.innerHTML, '<span>hi</span> there <!-- mon ami --><?foo bar="1.0">',
    "pi nodes should be included");

  t.innerHTML = null;
  t.appendChild(document.createElement("textarea"));
  t.firstChild.appendChild(document.createTextNode("\nhello"));
  // This is the old behavior. Spec requires something else.
  is(t.innerHTML, "<textarea>\nhello</textarea>",
     "No extra newlines should be inserted to the textarea!");

  t.innerHTML = null;
  t.appendChild(document.createElementNS("http://www.w3.org/2000/svg", "svg:svg"));
  t.firstChild.textContent = "<foo>";
  is(t.innerHTML, "<svg>&lt;foo&gt;</svg>");

  t.innerHTML = null;
  t.appendChild(document.createElementNS("http://www.w3.org/1998/Math/MathML", "math:math"));
  t.firstChild.textContent = "<foo>";
  is(t.innerHTML, "<math>&lt;foo&gt;</math>");

  // Prefix is serialized if element isn't HTML/SVG/MathML
  t.innerHTML = null;
  t.appendChild(document.createElementNS("http://www.example.org", "ex:example"));
  t.firstChild.textContent = "<foo>";
  is(t.innerHTML, "<ex:example>&lt;foo&gt;</ex:example>");

  t.innerHTML = null;
  t.appendChild(document.createElementNS("http://www.example.org", "example"));
  t.firstChild.textContent = "<foo>";
  is(t.innerHTML, "<example>&lt;foo&gt;</example>");

  t.firstChild.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "us-en");
  is(t.innerHTML, '<example xml:lang="us-en">&lt;foo&gt;</example>');

  t.firstChild.setAttributeNS("http://www.w3.org/1999/xlink", "href", "foo");
  is(t.innerHTML, '<example xml:lang="us-en" xlink:href="foo">&lt;foo&gt;</example>');

  t.firstChild.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "http://foo");
  is(t.innerHTML, '<example xml:lang="us-en" xlink:href="foo" xmlns="http://foo">&lt;foo&gt;</example>');

  t.firstChild.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:bar", "http://bar");
  is(t.innerHTML, '<example xml:lang="us-en" xlink:href="foo" xmlns="http://foo" xmlns:bar="http://bar">&lt;foo&gt;</example>');

  t.firstChild.setAttributeNS("http://www.helloworldns.org", "hello:world", "!");
  is(t.innerHTML, '<example xml:lang="us-en" xlink:href="foo" xmlns="http://foo" xmlns:bar="http://bar" hello:world="!">&lt;foo&gt;</example>');

  t.firstChild.setAttribute("foo", '-"&\xA0-');
  is(t.innerHTML, '<example xml:lang="us-en" xlink:href="foo" xmlns="http://foo" xmlns:bar="http://bar" hello:world="!" foo="-&quot;&amp;&nbsp;-">&lt;foo&gt;</example>');

  t.innerHTML = null;
  t.appendChild(document.createElement("div"));
  t.firstChild.appendChild(document.implementation
                                   .createDocument(null, null, null)
                                   .createCDATASection("foo"));
  is(t.innerHTML, '<div>foo</div>');

  t.firstChild.textContent = "1&2<3>4\xA0";
  is(t.innerHTML, '<div>1&amp;2&lt;3&gt;4&nbsp;</div>');

  t.innerHTML = null;
  t.appendChild(document.createElement("script"));
  t.firstChild.textContent = "1&2<3>4\xA0";
  is(t.innerHTML, '<script>1&2<3>4\xA0\u003C/script>');

  t.innerHTML = null;
  t.appendChild(document.createElement("style"));
  t.firstChild.textContent = "1&2<3>4\xA0";
  is(t.innerHTML, '<style>1&2<3>4\xA0\u003C/style>');

  t.innerHTML = null;
  t.appendChild(document.createElement("span"));
  t.firstChild.setAttributeNS("ext", "attr", "foo");
  t.firstChild.textContent = "1&2<3>4\xA0";
  is(t.innerHTML, '<span attr="foo">1&amp;2&lt;3&gt;4&nbsp;\u003C/span>');

  t.innerHTML = null;
  t.appendChild(document.createElementNS("http://www.w3.org/2000/svg", "svg"));
  is(t.firstChild.namespaceURI, "http://www.w3.org/2000/svg");
  t.firstChild.appendChild(document.createElementNS("http://www.w3.org/2000/svg", "script"));
  is(t.firstChild.firstChild.namespaceURI, "http://www.w3.org/2000/svg");
  t.firstChild.firstChild.textContent = "1&2<3>4\xA0";
  is(t.innerHTML, '<svg><script>1&amp;2&lt;3&gt;4&nbsp;\u003C/script></svg>');

  t.innerHTML = null;
  t.appendChild(document.createElementNS("http://www.w3.org/2000/svg", "svg"));
  is(t.firstChild.namespaceURI, "http://www.w3.org/2000/svg");
  t.firstChild.appendChild(document.createElementNS("http://www.w3.org/2000/svg", "style"));
  is(t.firstChild.firstChild.namespaceURI, "http://www.w3.org/2000/svg");
  t.firstChild.firstChild.textContent = "1&2<3>4\xA0";
  is(t.innerHTML, '<svg><style>1&amp;2&lt;3&gt;4&nbsp;\u003C/style></svg>');

  t.innerHTML = null;
  t.appendChild(document.createElementNS("http://www.w3.org/1998/Math/MathML", "math"));
  is(t.firstChild.namespaceURI, "http://www.w3.org/1998/Math/MathML");
  t.firstChild.appendChild(document.createElementNS("http://www.w3.org/1998/Math/MathML", "script"));
  is(t.firstChild.firstChild.namespaceURI, "http://www.w3.org/1998/Math/MathML");
  t.firstChild.firstChild.textContent = "1&2<3>4\xA0";
  is(t.innerHTML, '<math><script>1&amp;2&lt;3&gt;4&nbsp;\u003C/script></math>');

  t.innerHTML = null;
  t.appendChild(document.createElementNS("http://www.w3.org/1998/Math/MathML", "math"));
  is(t.firstChild.namespaceURI, "http://www.w3.org/1998/Math/MathML");
  t.firstChild.appendChild(document.createElementNS("http://www.w3.org/1998/Math/MathML", "style"));
  is(t.firstChild.firstChild.namespaceURI, "http://www.w3.org/1998/Math/MathML");
  t.firstChild.firstChild.textContent = "1&2<3>4\xA0";
  is(t.innerHTML, '<math><style>1&amp;2&lt;3&gt;4&nbsp;\u003C/style></math>');
</script>
</pre>
</body>
</html>