summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/dom/documents/dom-tree-accessors/nameditem-names.html
blob: 3f76d85a1bca783df916b159409a94c30488a2dd (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
<!DOCTYPE html>
<meta charset=utf-8>
<title>Named items: supported property names</title>
<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>
<embed name="exposed_embed">
  <embed name="not_exposed_embed">
  </embed>
</embed>
<form name="form">
</form>
<iframe name="iframe">
</iframe>
<img name="img">
<object name="exposed_object_with_name">
  <object name="not_exposed_object_with_name">
  </object>
</object>
<object id="exposed_object_with_id">
  <object id="not_exposed_object_with_id">
  </object>
</object>
<img name="img_with_id" id="img_id">
<img id="img_with_just_id">
<template id="template">
  <img name="img_in_template">
</template>
<img name="42">
<script>
var names = Object.getOwnPropertyNames(document);

test(function() {
  assert_true(names.includes("exposed_embed"))
}, "An embed name appears in a document's property names if the embed is exposed.");

test(function() {
  assert_false(names.includes("not_exposed_embed"))
}, "An embed name does not appears in a document's property names if the embed is inside another embed.");

test(function() {
  assert_true(names.includes("form"))
}, "A form name appears in a document's property names.");

test(function() {
  assert_true(names.includes("iframe"))
}, "An iframe name appears in a document's property names.");

test(function() {
  assert_true(names.includes("img"))
}, "An img name appears in a document's property names when the img has no id.");

test(function() {
  assert_true(names.includes("exposed_object"))
}, "An object name appears in a document's property names if the object is exposed.");

test(function() {
  assert_true(names.includes("exposed_object_with_id"))
}, "An object id appears in a document's property names if the object is exposed.");

test(function() {
  assert_false(names.includes("not_exposed_object_with_name"))
}, "An object name does not appear in a document's property names if the object is inside another object.");

test(function() {
  assert_false(names.includes("not_exposed_object_with_id"))
}, "An object id does not appear in a document's property names if the object is inside another object.");

test(function() {
  assert_true(names.includes("img_with_id"))
}, "An img name appears in a document's property names when the img has an id.");

test(function() {
  assert_true(names.includes("img_id"))
}, "An img id appears in a document's property names when the img has a name.");

test(function() {
  assert_false(names.includes("img_with_just_id"))
}, "An img id does not appear in a document's property names when the img has no name.");

test(function() {
  assert_true(names.includes("42"))
}, "A document's property names can include integer strings.");

test(function() {
  assert_false(names.includes("template"))
}, "A template name does not appear in a document's property names.");

test(function() {
  assert_false(names.includes("img_in_template"))
}, "An img name does not appear in a document's property names when the img is in a template's document fragment.");

test(function() {
  var form_index = names.indexOf("form");
  assert_equals(names.indexOf("iframe"), form_index + 1);
  assert_equals(names.indexOf("img"), form_index + 2);
  assert_greater_than(names.indexOf("img_id"), names.indexOf("img"));
  assert_greater_than(names.indexOf("42"), names.indexOf("img_id"));
}, "A document's property names appear in tree order.");
</script>