summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/collections
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/dom/collections
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/dom/collections')
-rw-r--r--testing/web-platform/tests/dom/collections/HTMLCollection-as-proto-length-get-throws.html13
-rw-r--r--testing/web-platform/tests/dom/collections/HTMLCollection-empty-name.html65
-rw-r--r--testing/web-platform/tests/dom/collections/HTMLCollection-supported-property-indices.html179
-rw-r--r--testing/web-platform/tests/dom/collections/HTMLCollection-supported-property-names.html135
-rw-r--r--testing/web-platform/tests/dom/collections/domstringmap-supported-property-names.html54
-rw-r--r--testing/web-platform/tests/dom/collections/namednodemap-supported-property-names.html30
6 files changed, 476 insertions, 0 deletions
diff --git a/testing/web-platform/tests/dom/collections/HTMLCollection-as-proto-length-get-throws.html b/testing/web-platform/tests/dom/collections/HTMLCollection-as-proto-length-get-throws.html
new file mode 100644
index 000000000..225c9e61a
--- /dev/null
+++ b/testing/web-platform/tests/dom/collections/HTMLCollection-as-proto-length-get-throws.html
@@ -0,0 +1,13 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>Make sure browsers throw when getting .length on some random object whose proto is an HTMLCollection</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script>
+test(function() {
+ var obj = Object.create(document.getElementsByTagName("script"));
+ assert_throws(new TypeError(), function() {
+ obj.length;
+ });
+}, "HTMLcollection as a prototype should not allow getting .length on the base object")
+</script>
diff --git a/testing/web-platform/tests/dom/collections/HTMLCollection-empty-name.html b/testing/web-platform/tests/dom/collections/HTMLCollection-empty-name.html
new file mode 100644
index 000000000..4fc34db7f
--- /dev/null
+++ b/testing/web-platform/tests/dom/collections/HTMLCollection-empty-name.html
@@ -0,0 +1,65 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>HTMLCollection and empty names</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<div id=log></div>
+<div id=test>
+<div class=a id></div>
+<div class=a name></div>
+<a class=a name></a>
+</div>
+<script>
+test(function() {
+ var c = document.getElementsByTagName("*");
+ assert_false("" in c, "Empty string should not be in the collection.");
+ assert_equals(c[""], undefined, "Named getter should return undefined for empty string.");
+ assert_equals(c.namedItem(""), null, "namedItem should return null for empty string.");
+}, "Empty string as a name for Document.getElementsByTagName");
+
+test(function() {
+ var div = document.getElementById("test");
+ var c = div.getElementsByTagName("*");
+ assert_false("" in c, "Empty string should not be in the collection.");
+ assert_equals(c[""], undefined, "Named getter should return undefined for empty string.");
+ assert_equals(c.namedItem(""), null, "namedItem should return null for empty string.");
+}, "Empty string as a name for Element.getElementsByTagName");
+
+test(function() {
+ var c = document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "a");
+ assert_false("" in c, "Empty string should not be in the collection.");
+ assert_equals(c[""], undefined, "Named getter should return undefined for empty string.");
+ assert_equals(c.namedItem(""), null, "namedItem should return null for empty string.");
+}, "Empty string as a name for Document.getElementsByTagNameNS");
+
+test(function() {
+ var div = document.getElementById("test");
+ var c = div.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "a");
+ assert_false("" in c, "Empty string should not be in the collection.");
+ assert_equals(c[""], undefined, "Named getter should return undefined for empty string.");
+ assert_equals(c.namedItem(""), null, "namedItem should return null for empty string.");
+}, "Empty string as a name for Element.getElementsByTagNameNS");
+
+test(function() {
+ var c = document.getElementsByClassName("a");
+ assert_false("" in c, "Empty string should not be in the collection.");
+ assert_equals(c[""], undefined, "Named getter should return undefined for empty string.");
+ assert_equals(c.namedItem(""), null, "namedItem should return null for empty string.");
+}, "Empty string as a name for Document.getElementsByClassName");
+
+test(function() {
+ var div = document.getElementById("test");
+ var c = div.getElementsByClassName("a");
+ assert_false("" in c, "Empty string should not be in the collection.");
+ assert_equals(c[""], undefined, "Named getter should return undefined for empty string.");
+ assert_equals(c.namedItem(""), null, "namedItem should return null for empty string.");
+}, "Empty string as a name for Element.getElementsByClassName");
+
+test(function() {
+ var div = document.getElementById("test");
+ var c = div.children;
+ assert_false("" in c, "Empty string should not be in the collection.");
+ assert_equals(c[""], undefined, "Named getter should return undefined for empty string.");
+ assert_equals(c.namedItem(""), null, "namedItem should return null for empty string.");
+}, "Empty string as a name for Element.children");
+</script>
diff --git a/testing/web-platform/tests/dom/collections/HTMLCollection-supported-property-indices.html b/testing/web-platform/tests/dom/collections/HTMLCollection-supported-property-indices.html
new file mode 100644
index 000000000..62ee6bb6a
--- /dev/null
+++ b/testing/web-platform/tests/dom/collections/HTMLCollection-supported-property-indices.html
@@ -0,0 +1,179 @@
+<!doctype html>
+<meta charset=utf-8>
+<title></title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<!-- We want to use a tag name that will not interact with our test harness,
+ so just make one up. "foo" is a good one -->
+
+<!-- Ids that look like negative indices. These should come first, so we can
+ assert that lookups for nonnegative indices find these by index -->
+<foo id="-2"></foo>
+<foo id="-1"></foo>
+
+<!-- Ids that look like nonnegative indices -->
+<foo id="0"></foo>
+<foo id="1"></foo>
+
+<!-- Ids that look like nonnegative indices near 2^31 = 2147483648 -->
+<foo id="2147483645"></foo> <!-- 2^31 - 3 -->
+<foo id="2147483646"></foo> <!-- 2^31 - 2 -->
+<foo id="2147483647"></foo> <!-- 2^31 - 1 -->
+<foo id="2147483648"></foo> <!-- 2^31 -->
+<foo id="2147483649"></foo> <!-- 2^31 + 1 -->
+
+<!-- Ids that look like nonnegative indices near 2^32 = 4294967296 -->
+<foo id="4294967293"></foo> <!-- 2^32 - 3 -->
+<foo id="4294967294"></foo> <!-- 2^32 - 2 -->
+<foo id="4294967295"></foo> <!-- 2^32 - 1 -->
+<foo id="4294967296"></foo> <!-- 2^32 -->
+<foo id="4294967297"></foo> <!-- 2^32 + 1 -->
+
+<script>
+test(function() {
+ var collection = document.getElementsByTagName("foo");
+ assert_equals(collection.item(-2), null);
+ assert_equals(collection.item(-1), null);
+ assert_equals(collection.namedItem(-2), document.getElementById("-2"));
+ assert_equals(collection.namedItem(-1), document.getElementById("-1"));
+ assert_equals(collection[-2], document.getElementById("-2"));
+ assert_equals(collection[-1], document.getElementById("-1"));
+}, "Handling of property names that look like negative integers");
+
+test(function() {
+ var collection = document.getElementsByTagName("foo");
+ assert_equals(collection.item(0), document.getElementById("-2"));
+ assert_equals(collection.item(1), document.getElementById("-1"));
+ assert_equals(collection.namedItem(0), document.getElementById("0"));
+ assert_equals(collection.namedItem(1), document.getElementById("1"));
+ assert_equals(collection[0], document.getElementById("-2"));
+ assert_equals(collection[1], document.getElementById("-1"));
+}, "Handling of property names that look like small nonnegative integers");
+
+test(function() {
+ var collection = document.getElementsByTagName("foo");
+ assert_equals(collection.item(2147483645), null);
+ assert_equals(collection.item(2147483646), null);
+ assert_equals(collection.item(2147483647), null);
+ assert_equals(collection.item(2147483648), null);
+ assert_equals(collection.item(2147483649), null);
+ assert_equals(collection.namedItem(2147483645),
+ document.getElementById("2147483645"));
+ assert_equals(collection.namedItem(2147483646),
+ document.getElementById("2147483646"));
+ assert_equals(collection.namedItem(2147483647),
+ document.getElementById("2147483647"));
+ assert_equals(collection.namedItem(2147483648),
+ document.getElementById("2147483648"));
+ assert_equals(collection.namedItem(2147483649),
+ document.getElementById("2147483649"));
+ assert_equals(collection[2147483645], undefined);
+ assert_equals(collection[2147483646], undefined);
+ assert_equals(collection[2147483647], undefined);
+ assert_equals(collection[2147483648], undefined);
+ assert_equals(collection[2147483649], undefined);
+}, "Handling of property names that look like integers around 2^31");
+
+test(function() {
+ var collection = document.getElementsByTagName("foo");
+ assert_equals(collection.item(4294967293), null);
+ assert_equals(collection.item(4294967294), null);
+ assert_equals(collection.item(4294967295), null);
+ assert_equals(collection.item(4294967296), document.getElementById("-2"));
+ assert_equals(collection.item(4294967297), document.getElementById("-1"));
+ assert_equals(collection.namedItem(4294967293),
+ document.getElementById("4294967293"));
+ assert_equals(collection.namedItem(4294967294),
+ document.getElementById("4294967294"));
+ assert_equals(collection.namedItem(4294967295),
+ document.getElementById("4294967295"));
+ assert_equals(collection.namedItem(4294967296),
+ document.getElementById("4294967296"));
+ assert_equals(collection.namedItem(4294967297),
+ document.getElementById("4294967297"));
+ assert_equals(collection[4294967293], undefined);
+ assert_equals(collection[4294967294], undefined);
+ assert_equals(collection[4294967295], document.getElementById("4294967295"));
+ assert_equals(collection[4294967296], document.getElementById("4294967296"));
+ assert_equals(collection[4294967297], document.getElementById("4294967297"));
+}, "Handling of property names that look like integers around 2^32");
+
+test(function() {
+ var elements = document.getElementsByTagName("foo");
+ var old_item = elements[0];
+ var old_desc = Object.getOwnPropertyDescriptor(elements, 0);
+ assert_equals(old_desc.value, old_item);
+ assert_true(old_desc.enumerable);
+ assert_true(old_desc.configurable);
+ assert_false(old_desc.writable);
+
+ elements[0] = 5;
+ assert_equals(elements[0], old_item);
+ assert_throws(new TypeError(), function() {
+ "use strict";
+ elements[0] = 5;
+ });
+ assert_throws(new TypeError(), function() {
+ Object.defineProperty(elements, 0, { value: 5 });
+ });
+
+ delete elements[0];
+ assert_equals(elements[0], old_item);
+
+ assert_throws(new TypeError(), function() {
+ "use strict";
+ delete elements[0];
+ });
+ assert_equals(elements[0], old_item);
+}, 'Trying to set an expando that would shadow an already-existing indexed property');
+
+test(function() {
+ var elements = document.getElementsByTagName("foo");
+ var idx = elements.length;
+ var old_item = elements[idx];
+ var old_desc = Object.getOwnPropertyDescriptor(elements, idx);
+ assert_equals(old_item, undefined);
+ assert_equals(old_desc, undefined);
+
+ // [[DefineOwnProperty]] will disallow defining an indexed expando.
+ elements[idx] = 5;
+ assert_equals(elements[idx], undefined);
+ assert_throws(new TypeError(), function() {
+ "use strict";
+ elements[idx] = 5;
+ });
+ assert_throws(new TypeError(), function() {
+ Object.defineProperty(elements, idx, { value: 5 });
+ });
+
+ // Check that deletions out of range do not throw
+ delete elements[idx];
+ (function() {
+ "use strict";
+ delete elements[idx];
+ })();
+}, 'Trying to set an expando with an indexed property name past the end of the list');
+
+test(function(){
+ var elements = document.getElementsByTagName("foo");
+ var old_item = elements[0];
+ var old_desc = Object.getOwnPropertyDescriptor(elements, 0);
+ assert_equals(old_desc.value, old_item);
+ assert_true(old_desc.enumerable);
+ assert_true(old_desc.configurable);
+ assert_false(old_desc.writable);
+
+ Object.prototype[0] = 5;
+ this.add_cleanup(function () { delete Object.prototype[0]; });
+ assert_equals(elements[0], old_item);
+
+ delete elements[0];
+ assert_equals(elements[0], old_item);
+
+ assert_throws(new TypeError(), function() {
+ "use strict";
+ delete elements[0];
+ });
+ assert_equals(elements[0], old_item);
+}, 'Trying to delete an indexed property name should never work');
+</script>
diff --git a/testing/web-platform/tests/dom/collections/HTMLCollection-supported-property-names.html b/testing/web-platform/tests/dom/collections/HTMLCollection-supported-property-names.html
new file mode 100644
index 000000000..0a9df1ad6
--- /dev/null
+++ b/testing/web-platform/tests/dom/collections/HTMLCollection-supported-property-names.html
@@ -0,0 +1,135 @@
+<!doctype html>
+<meta charset=utf-8>
+<link rel=help href=https://dom.spec.whatwg.org/#interface-htmlcollection>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+
+<div id=log></div>
+
+<!-- with no attribute -->
+<span></span>
+
+<!-- with `id` attribute -->
+<span id=''></span>
+<span id='some-id'></span>
+<span id='some-id'></span><!-- to ensure no duplicates -->
+
+<!-- with `name` attribute -->
+<span name=''></span>
+<span name='some-name'></span>
+<span name='some-name'></span><!-- to ensure no duplicates -->
+
+<!-- with `name` and `id` attribute -->
+<span id='another-id' name='another-name'></span>
+
+<script>
+test(function () {
+ var elements = document.getElementsByTagName("span");
+ assert_array_equals(
+ Object.getOwnPropertyNames(elements),
+ ['0', '1', '2', '3', '4', '5', '6', '7', 'some-id', 'some-name', 'another-id', 'another-name']
+ );
+}, 'Object.getOwnPropertyNames on HTMLCollection');
+
+test(function () {
+ var elem = document.createElementNS('some-random-namespace', 'foo');
+ this.add_cleanup(function () {elem.remove();});
+ elem.setAttribute("name", "some-name");
+ document.body.appendChild(elem);
+
+ var elements = document.getElementsByTagName("foo");
+ assert_array_equals(Object.getOwnPropertyNames(elements), ['0']);
+}, 'Object.getOwnPropertyNames on HTMLCollection with non-HTML namespace');
+
+test(function () {
+ var elem = document.createElement('foo');
+ this.add_cleanup(function () {elem.remove();});
+ document.body.appendChild(elem);
+
+ var elements = document.getElementsByTagName("foo");
+ elements.someProperty = "some value";
+
+ assert_array_equals(Object.getOwnPropertyNames(elements), ['0', 'someProperty']);
+}, 'Object.getOwnPropertyNames on HTMLCollection with expando object');
+
+test(function() {
+ var elements = document.getElementsByTagName("span");
+ var old_item = elements["some-id"];
+ var old_desc = Object.getOwnPropertyDescriptor(elements, "some-id");
+ assert_equals(old_desc.value, old_item);
+ assert_false(old_desc.enumerable);
+ assert_true(old_desc.configurable);
+ assert_false(old_desc.writable);
+
+ elements["some-id"] = 5;
+ assert_equals(elements["some-id"], old_item);
+ assert_throws(new TypeError(), function() {
+ "use strict";
+ elements["some-id"] = 5;
+ });
+ assert_throws(new TypeError(), function() {
+ Object.defineProperty(elements, "some-id", { value: 5 });
+ });
+
+ delete elements["some-id"];
+ assert_equals(elements["some-id"], old_item);
+
+ assert_throws(new TypeError(), function() {
+ "use strict";
+ delete elements["some-id"];
+ });
+ assert_equals(elements["some-id"], old_item);
+
+}, 'Trying to set an expando that would shadow an already-existing named property');
+
+test(function() {
+ var elements = document.getElementsByTagName("span");
+ var old_item = elements["new-id"];
+ var old_desc = Object.getOwnPropertyDescriptor(elements, "new-id");
+ assert_equals(old_item, undefined);
+ assert_equals(old_desc, undefined);
+
+ elements["new-id"] = 5;
+ assert_equals(elements["new-id"], 5);
+
+ var span = document.createElement("span");
+ this.add_cleanup(function () {span.remove();});
+ span.id = "new-id";
+ document.body.appendChild(span);
+
+ assert_equals(elements.namedItem("new-id"), span);
+ assert_equals(elements["new-id"], 5);
+
+ delete elements["new-id"];
+ assert_equals(elements["new-id"], span);
+}, 'Trying to set an expando that shadows a named property that gets added later');
+
+test(function() {
+ var elements = document.getElementsByTagName("span");
+ var old_item = elements["new-id2"];
+ var old_desc = Object.getOwnPropertyDescriptor(elements, "new-id2");
+ assert_equals(old_item, undefined);
+ assert_equals(old_desc, undefined);
+
+ Object.defineProperty(elements, "new-id2", { configurable: false, writable:
+ false, value: 5 });
+ assert_equals(elements["new-id2"], 5);
+
+ var span = document.createElement("span");
+ this.add_cleanup(function () {span.remove();});
+ span.id = "new-id2";
+ document.body.appendChild(span);
+
+ assert_equals(elements.namedItem("new-id2"), span);
+ assert_equals(elements["new-id2"], 5);
+
+ delete elements["new-id2"];
+ assert_equals(elements["new-id2"], 5);
+
+ assert_throws(new TypeError(), function() {
+ "use strict";
+ delete elements["new-id2"];
+ });
+ assert_equals(elements["new-id2"], 5);
+}, 'Trying to set a non-configurable expando that shadows a named property that gets added later');
+</script>
diff --git a/testing/web-platform/tests/dom/collections/domstringmap-supported-property-names.html b/testing/web-platform/tests/dom/collections/domstringmap-supported-property-names.html
new file mode 100644
index 000000000..430aa44c3
--- /dev/null
+++ b/testing/web-platform/tests/dom/collections/domstringmap-supported-property-names.html
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>DOMStringMap Test: Supported property names</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+
+<div id="edge1" data-="012">Simple</div>
+
+<div id="edge2" data-id-="012">Simple</div>
+
+<div id="user" data-id="1234567890" data-user="johndoe" data-date-of-birth>
+ John Doe
+</div>
+
+<div id="user2" data-unique-id="1234567890"> Jane Doe </div>
+
+<div id="user3" data-unique-id="4324324241"> Jim Doe </div>
+
+<script>
+
+test(function() {
+ var element = document.querySelector('#edge1');
+ assert_array_equals(Object.getOwnPropertyNames(element.dataset),
+ [""]);
+}, "Object.getOwnPropertyNames on DOMStringMap, empty data attribute");
+
+test(function() {
+ var element = document.querySelector('#edge2');
+ assert_array_equals(Object.getOwnPropertyNames(element.dataset),
+ ["id-"]);
+}, "Object.getOwnPropertyNames on DOMStringMap, data attribute trailing hyphen");
+
+test(function() {
+ var element = document.querySelector('#user');
+ assert_array_equals(Object.getOwnPropertyNames(element.dataset),
+ ['id', 'user', 'dateOfBirth']);
+}, "Object.getOwnPropertyNames on DOMStringMap, multiple data attributes");
+
+test(function() {
+ var element = document.querySelector('#user2');
+ element.dataset.middleName = "mark";
+ assert_array_equals(Object.getOwnPropertyNames(element.dataset),
+ ['uniqueId', 'middleName']);
+}, "Object.getOwnPropertyNames on DOMStringMap, attribute set on dataset in JS");
+
+test(function() {
+ var element = document.querySelector('#user3');
+ element.setAttribute("data-age", 30);
+ assert_array_equals(Object.getOwnPropertyNames(element.dataset),
+ ['uniqueId', 'age']);
+}, "Object.getOwnPropertyNames on DOMStringMap, attribute set on element in JS");
+
+</script>
diff --git a/testing/web-platform/tests/dom/collections/namednodemap-supported-property-names.html b/testing/web-platform/tests/dom/collections/namednodemap-supported-property-names.html
new file mode 100644
index 000000000..2c5dee4ef
--- /dev/null
+++ b/testing/web-platform/tests/dom/collections/namednodemap-supported-property-names.html
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>NamedNodeMap Test: Supported property names</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<div id="simple" class="fancy">Simple</div>
+<input id="result" type="text" value="" width="200px">
+<script>
+
+test(function() {
+ var elt = document.querySelector('#simple');
+ assert_array_equals(Object.getOwnPropertyNames(elt.attributes),
+ ['0','1','id','class']);
+}, "Object.getOwnPropertyNames on NamedNodeMap");
+
+test(function() {
+ var result = document.getElementById("result");
+ assert_array_equals(Object.getOwnPropertyNames(result.attributes),
+ ['0','1','2','3','id','type','value','width']);
+}, "Object.getOwnPropertyNames on NamedNodeMap of input");
+
+test(function() {
+ var result = document.getElementById("result");
+ result.removeAttribute("width");
+ assert_array_equals(Object.getOwnPropertyNames(result.attributes),
+ ['0','1','2','id','type','value']);
+}, "Object.getOwnPropertyNames on NamedNodeMap after attribute removal");
+
+</script> \ No newline at end of file