Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /html/dom/documents/dom-tree-accessors/nameditem-names.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset=utf-8>
<title>Named items: supported property names</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<embed name="embed">
<form name="form">
</form>
<iframe name="iframe">
</iframe>
<img name="img">
<object data="/common/blank.html" type="text/html" name="object_with_name">
<embed name="embed_in_object">
<object name="object_in_object_with_name">
</object>
</object>
<object data="/common/blank.html" type="text/html" id="object_with_id">
<object id="object_in_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>
setup({ explicit_done: true });
window.addEventListener("load", function() {
var names = Object.getOwnPropertyNames(document);
test(function() {
assert_true(names.includes("embed"))
}, "An embed name appears in a document's property names.");
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("object_with_name"))
}, "An object name appears in a document's property names.");
test(function() {
assert_true(names.includes("object_with_id"))
}, "An object id appears in a document's property names.");
test(function() {
assert_not_equals(document.querySelector('[name="object_with_name"]').contentDocument, null,
"The object must successfully load its data resource");
assert_true(names.includes("embed_in_object"))
}, "An embed name appears in a document's property names when the embed is inside an object that is not showing its fallback content.");
test(function() {
assert_not_equals(document.querySelector('[name="object_with_name"]').contentDocument, null,
"The object must successfully load its data resource");
assert_true(names.includes("object_in_object_with_name"))
}, "An object name appears in a document's property names when the object is inside an object that is not showing its fallback content.");
test(function() {
assert_not_equals(document.querySelector("#object_with_id").contentDocument, null,
"The object must successfully load its data resource");
assert_true(names.includes("object_in_object_with_id"))
}, "An object id appears in a document's property names when the object is inside an object that is not showing its fallback content.");
// A name is only useful if the named getter resolves it, so check that the
// two algorithms agree for object elements and their descendants.
test(function() {
var object = document.querySelector('[name="object_with_name"]');
assert_equals(document.object_with_name, object);
}, "An object with object and embed descendants is returned by the named getter (name).");
test(function() {
var object = document.querySelector("#object_with_id");
assert_equals(document.object_with_id, object);
}, "An object with an object descendant is returned by the named getter (id).");
test(function() {
var object = document.querySelector('[name="object_with_name"]');
assert_equals(document.embed_in_object, object.querySelector("embed"));
}, "An embed inside an object that is not showing its fallback content is returned by the named getter.");
test(function() {
var object = document.querySelector('[name="object_with_name"]');
assert_equals(document.object_in_object_with_name, object.querySelector("object"));
}, "An object inside an object that is not showing its fallback content is returned by the named getter (name).");
test(function() {
var object = document.querySelector("#object_with_id");
assert_equals(document.object_in_object_with_id, object.querySelector("object"));
}, "An object inside an object that is not showing its fallback content is returned by the named getter (id).");
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.");
done();
});
</script>