File: nameditem-02.html

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (174 lines) | stat: -rw-r--r-- 6,975 bytes parent folder | download | duplicates (12)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<meta charset=utf-8>
<title>Named items: iframes</title>
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-document-nameditem">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<div id="test">
<iframe name="test1"></iframe>

<iframe name="test2"></iframe>
<iframe name="test2"></iframe>

<iframe name="test3"></iframe>
<img name="test3">

<img name="test4">
<iframe name="test4"></iframe>

<iframe id="test5"></iframe>

<iframe name="test6" id="fail"></iframe>

<iframe name="fail" id="test7"></iframe>

<iframe name="42"></iframe>

<iframe name="test9" id="test9"></iframe>

<iframe></iframe>

<iframe name="test11a"></iframe>

<iframe name="test12"></iframe>
</div>
<script>
test(function() {
  var iframe = document.getElementsByTagName("iframe")[0];
  assert_equals(iframe.name, "test1");

  assert_true("test1" in document, '"test1" in document should be true');
  assert_equals(document.test1, iframe.contentWindow);
}, "If the only named item is an iframe, the contentWindow should be returned.");

test(function() {
  var iframe1 = document.getElementsByTagName("iframe")[1];
  assert_equals(iframe1.name, "test2");
  var iframe2 = document.getElementsByTagName("iframe")[2];
  assert_equals(iframe2.name, "test2");

  assert_true("test2" in document, '"test2" in document should be true');
  var collection = document.test2;
  assert_class_string(collection, "HTMLCollection", "collection should be an HTMLCollection");
  assert_array_equals(collection, [iframe1, iframe2]);
}, "If there are two iframes, a collection should be returned.");

test(function() {
  var iframe = document.getElementsByTagName("iframe")[3];
  assert_equals(iframe.name, "test3");
  var img = document.getElementsByTagName("img")[0];
  assert_equals(img.name, "test3");

  assert_true("test3" in document, '"test3" in document should be true');
  var collection = document.test3;
  assert_class_string(collection, "HTMLCollection", "collection should be an HTMLCollection");
  assert_array_equals(collection, [iframe, img]);
}, "If there are an iframe and another element (iframe first), a collection should be returned.");

test(function() {
  var iframe = document.getElementsByTagName("iframe")[4];
  assert_equals(iframe.name, "test4");
  var img = document.getElementsByTagName("img")[1];
  assert_equals(img.name, "test4");

  assert_true("test4" in document, '"test4" in document should be true');
  var collection = document.test4;
  assert_class_string(collection, "HTMLCollection", "collection should be an HTMLCollection");
  assert_array_equals(collection, [img, iframe]);
}, "If there are an iframe and another element (iframe last), a collection should be returned.");

test(function() {
  assert_false("test5" in document, '"test5" in document should be false');
  assert_equals(document.test5, undefined);
}, "If an iframe has an id and no name, it should not be returned.");

test(function() {
  var iframe = document.getElementsByTagName("iframe")[6];
  assert_equals(iframe.name, "test6");

  assert_true("test6" in document, '"test6" in document should be true');
  assert_equals(document.test6, iframe.contentWindow);
}, "If an iframe has a name and a different id, it should be returned by its name.");

test(function() {
  assert_false("test7" in document, '"test7" in document should be false');
  assert_equals(document.test7, undefined);
}, "If an iframe has an id and a different name, it should not be returned by its id.");

test(function() {
  var iframe = document.getElementsByTagName("iframe")[8];
  assert_equals(iframe.name, "42");

  assert_true(42 in document, '42 in document should be true');
  assert_equals(document[42], iframe.contentWindow);
}, "An iframe whose name looks like an array index should work.");

test(function() {
  var iframe = document.getElementsByTagName("iframe")[9];
  assert_equals(iframe.name, "test9");

  assert_true("test9" in document, 'test9 in document should be true');
  assert_equals(document["test9"], iframe.contentWindow);
  assert_equals(document.test9, iframe.contentWindow);

  iframe.removeAttribute("name");
  assert_false("test9" in document, 'test9 in document should be false');
  assert_equals(document["test9"], undefined);
  assert_equals(document.test9, undefined);
}, "Dynamically removing the name attribute from iframe elements, should not be accessible.");

test(function() {
  var iframe = document.getElementsByTagName("iframe")[10];
  iframe.setAttribute("name", "test10a");

  assert_true("test10a" in document, 'test10a in document should be true');
  assert_equals(document["test10a"], iframe.contentWindow);
  assert_equals(document.test10a, iframe.contentWindow);

  iframe.setAttribute("name", "test10b");
  assert_false("test10a" in document, 'test10a in document should be false');
  assert_equals(document["test10a"], undefined);
  assert_equals(document.test10a, undefined);
  assert_true("test10b" in document, 'test10b in document should be true');
  assert_equals(document["test10b"], iframe.contentWindow);
  assert_equals(document.test10b, iframe.contentWindow);
}, "Dynamically updating the name attribute from iframe elements, should be accessible by its name.");

test(function() {
  var iframe = document.getElementsByTagName("iframe")[11];
  assert_equals(iframe.name, "test11a");

  assert_true("test11a" in document, 'test11a in document should be true');
  assert_equals(document["test11a"], iframe.contentWindow);
  assert_equals(document.test11a, iframe.contentWindow);

  iframe.setAttribute("id", "test11a");
  assert_true("test11a" in document, 'test11a in document should be true');
  assert_equals(document["test11a"], iframe.contentWindow);
  assert_equals(document.test11a, iframe.contentWindow);

  iframe.setAttribute("id", "test11b");
  assert_true("test11a" in document, 'test11a in document should be true');
  assert_equals(document["test11a"], iframe.contentWindow);
  assert_equals(document.test11a, iframe.contentWindow);
  assert_false("test11b" in document, 'test11b in document should be false');
  assert_equals(document["test11b"], undefined);
  assert_equals(document.test11b, undefined);
}, "Dynamically updating the id attribute from iframe elements, should be accessible only by its name.");

test(function() {
  var iframe = document.getElementsByTagName("iframe")[12];
  assert_equals(iframe.name, "test12");

  assert_true("test12" in document, 'test12 in document should be true');
  assert_equals(document["test12"], iframe.contentWindow);
  assert_equals(document.test12, iframe.contentWindow);

  iframe.remove();
  assert_false("test12" in document, 'test12 in document should be false');
  assert_equals(document["test12"], undefined);
  assert_equals(document.test12, undefined);
}, "iframe elements that is removed, should not be accessible.");
</script>