Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<meta charset=utf-8>
<title>Named items: objects</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<div id="test">
<object name=test1></object>
<object name=test2></object>
<object name=test2></object>
<object id=test3></object>
<object id=test4></object>
<object id=test4></object>
<object name=test5></object>
<object id=test5></object>
<object id=test6></object>
<object name=test6></object>
<object name=test7></object>
<object id=test8></object>
<object id=test9a></object>
<object name=test10a></object>
<object name=test11a id=test11b></object>
</div>
<script>
test(function() {
var object = document.getElementsByTagName("object")[0];
assert_equals(object.name, "test1");
assert_true("test1" in document, '"test1" in document should be true');
assert_equals(document.test1, object);
}, "If there is one object, it should be returned (name)");
test(function() {
var object1 = document.getElementsByTagName("object")[1];
assert_equals(object1.name, "test2");
var object2 = document.getElementsByTagName("object")[2];
assert_equals(object2.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, [object1, object2]);
}, "If there are two objects, a collection should be returned. (name)");
test(function() {
var object = document.getElementsByTagName("object")[3];
assert_equals(object.id, "test3");
assert_true("test3" in document, '"test3" in document should be true');
assert_equals(document.test3, object);
}, "If there is one object, it should be returned (id)");
test(function() {
var object1 = document.getElementsByTagName("object")[4];
assert_equals(object1.id, "test4");
var object2 = document.getElementsByTagName("object")[5];
assert_equals(object2.id, "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, [object1, object2]);
}, "If there are two objects, a collection should be returned. (id)");
test(function() {
var object1 = document.getElementsByTagName("object")[6];
assert_equals(object1.name, "test5");
var object2 = document.getElementsByTagName("object")[7];
assert_equals(object2.id, "test5");
assert_true("test5" in document, '"test5" in document should be true');
var collection = document.test5;
assert_class_string(collection, "HTMLCollection", "collection should be an HTMLCollection");
assert_array_equals(collection, [object1, object2]);
}, "If there are two objects, a collection should be returned. (name and id)");
test(function() {
var object1 = document.getElementsByTagName("object")[8];
assert_equals(object1.id, "test6");
var object2 = document.getElementsByTagName("object")[9];
assert_equals(object2.name, "test6");
assert_true("test6" in document, '"test6" in document should be true');
var collection = document.test6;
assert_class_string(collection, "HTMLCollection", "collection should be an HTMLCollection");
assert_array_equals(collection, [object1, object2]);
}, "If there are two objects, a collection should be returned. (id and name)");
test(function() {
var object = document.getElementsByTagName("object")[10];
assert_equals(object.name, "test7");
assert_true("test7" in document, 'test7 in document should be true');
assert_equals(document["test7"], object);
assert_equals(document.test7, object);
object.removeAttribute("name");
assert_false("test7" in document, 'test7 in document should be false');
assert_equals(document["test7"], undefined);
assert_equals(document.test7, undefined);
}, "Dynamically removing the name attribute from object elements, should not be accessible.");
test(function() {
var object = document.getElementsByTagName("object")[11];
assert_equals(object.id, "test8");
assert_true("test8" in document, 'test8 in document should be true');
assert_equals(document["test8"], object);
assert_equals(document.test8, object);
object.removeAttribute("id");
assert_false("test8" in document, 'test8 in document should be false');
assert_equals(document["test8"], undefined);
assert_equals(document.test8, undefined);
}, "Dynamically removing the id attribute from object elements, should not be accessible.");
test(function() {
var object = document.getElementsByTagName("object")[12];
assert_equals(object.id, "test9a");
assert_true("test9a" in document, 'test9a in document should be true');
assert_equals(document["test9a"], object);
assert_equals(document.test9a, object);
object.setAttribute("name", "test9a");
assert_true("test9a" in document, 'test9a in document should be true');
assert_equals(document["test9a"], object);
assert_equals(document.test9a, object);
object.setAttribute("name", "test9b");
assert_true("test9a" in document, 'test9a in document should be true');
assert_equals(document["test9a"], object);
assert_equals(document.test9a, object);
assert_true("test9b" in document, 'test9b in document should be true');
assert_equals(document["test9b"], object);
assert_equals(document.test9b, object);
object.setAttribute("name", "test9c");
assert_true("test9a" in document, 'test9a in document should be true');
assert_equals(document["test9a"], object);
assert_equals(document.test9a, object);
assert_false("test9b" in document, 'test9b in document should be false');
assert_equals(document["test9b"], undefined);
assert_equals(document.test9b, undefined);
assert_true("test9c" in document, 'test9c in document should be true');
assert_equals(document["test9c"], object);
assert_equals(document.test9c, object);
}, "Dynamically updating the name attribute from object elements, should be accessible by its name and id.");
test(function() {
var object = document.getElementsByTagName("object")[13];
assert_equals(object.name, "test10a");
assert_true("test10a" in document, 'test11a in document should be true');
assert_equals(document["test10a"], object);
assert_equals(document.test10a, object);
object.setAttribute("id", "test10a");
assert_true("test10a" in document, 'test10a in document should be true');
assert_equals(document["test10a"], object);
assert_equals(document.test10a, object);
object.setAttribute("id", "test10b");
assert_true("test10a" in document, 'test10a in document should be true');
assert_equals(document["test10a"], object);
assert_equals(document.test10a, object);
assert_true("test10b" in document, 'test10b in document should be false');
assert_equals(document["test10b"], object);
assert_equals(document.test10b, object);
object.setAttribute("id", "test10c");
assert_true("test10a" in document, 'test10a in document should be true');
assert_equals(document["test10a"], object);
assert_equals(document.test10a, object);
assert_false("test10b" in document, 'test10b in document should be false');
assert_equals(document["test10b"], undefined);
assert_equals(document.test10b, undefined);
assert_true("test10c" in document, 'test10b in document should be false');
assert_equals(document["test10c"], object);
assert_equals(document.test10c, object);
}, "Dynamically updating the id attribute from object elements, should be accessible by its name and id.");
test(function() {
var object = document.getElementsByTagName("object")[14];
assert_equals(object.name, "test11a");
assert_equals(object.id, "test11b");
assert_true("test11a" in document, 'test11a in document should be true');
assert_equals(document["test11a"], object);
assert_equals(document.test11a, object);
assert_true("test11b" in document, 'test11b in document should be true');
assert_equals(document["test11b"], object);
assert_equals(document.test11b, object);
object.remove();
assert_false("test11a" in document, 'test11a in document should be false');
assert_equals(document["test11a"], undefined);
assert_equals(document.test11a, undefined);
assert_false("test11b" in document, 'test11b in document should be false');
assert_equals(document["test11b"], undefined);
assert_equals(document.test11b, undefined);
}, "object elements that is removed, should not be accessible.");
</script>