summaryrefslogtreecommitdiffstats
path: root/dom/html/test/test_getElementsByName_after_mutation.html
blob: f88b8d579ee75484c507c84fc74f505fabe0aac5 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1376695
-->
<head>
  <title>Test for Bug 1376695</title>
  <script 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=1376695">Mozilla Bug 1376695</a>
<p id="display"></p>
<div id="originalFoo" name="foo">
<pre id="test">
<script type="application/javascript">

/** Test to ensure that the list returned by getElementsByName is updated after
  * mutations.
  **/

var fooList = document.getElementsByName("foo");
var originalDiv = document.getElementById("originalFoo");

is(fooList.length, 1, "Should find one element with name 'foo' initially");
is(fooList[0], originalDiv, "Element should be the original div");

var newTree = document.createElement("p");
var child1 = document.createElement("div");
var child2 = document.createElement("div");
child2.setAttribute("name", "foo");

newTree.appendChild(child1);
newTree.appendChild(child2);
document.body.appendChild(newTree);

is(fooList.length, 2,
   "Should find two elements with name 'foo' after appending the new tree");
is(fooList[1], child2, "Element should be the new appended div with name 'foo'");

document.body.removeChild(newTree);

is(fooList.length, 1,
   "Should find one element with name 'foo' after removing the new tree");
is(fooList[0], originalDiv,
   "Element should be the original div after removing the new tree");

</script>
</pre>
</body>
</html>