diff options
Diffstat (limited to 'testing/web-platform/tests/dom/lists')
6 files changed, 210 insertions, 0 deletions
diff --git a/testing/web-platform/tests/dom/lists/DOMTokenList-Iterable.html b/testing/web-platform/tests/dom/lists/DOMTokenList-Iterable.html new file mode 100644 index 0000000000..4cf84b12a2 --- /dev/null +++ b/testing/web-platform/tests/dom/lists/DOMTokenList-Iterable.html @@ -0,0 +1,34 @@ +<!doctype html> +<meta charset="utf-8"> +<title>DOMTokenList Iterable Test</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<span class="foo Foo foo "></span> +<script> + var elementClasses; + setup(function() { + elementClasses = document.querySelector("span").classList; + }) + test(function() { + assert_true('length' in elementClasses); + }, 'DOMTokenList has length method.'); + test(function() { + assert_true('values' in elementClasses); + }, 'DOMTokenList has values method.'); + test(function() { + assert_true('entries' in elementClasses); + }, 'DOMTokenList has entries method.'); + test(function() { + assert_true('forEach' in elementClasses); + }, 'DOMTokenList has forEach method.'); + test(function() { + assert_true(Symbol.iterator in elementClasses); + }, 'DOMTokenList has Symbol.iterator.'); + test(function() { + var classList = []; + for (var className of elementClasses){ + classList.push(className); + } + assert_array_equals(classList, ['foo', 'Foo']); + }, 'DOMTokenList is iterable via for-of loop.'); +</script> diff --git a/testing/web-platform/tests/dom/lists/DOMTokenList-coverage-for-attributes.html b/testing/web-platform/tests/dom/lists/DOMTokenList-coverage-for-attributes.html new file mode 100644 index 0000000000..e5f060b8ac --- /dev/null +++ b/testing/web-platform/tests/dom/lists/DOMTokenList-coverage-for-attributes.html @@ -0,0 +1,55 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>DOMTokenList coverage for attributes</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +"use strict"; + +var pairs = [ + // Defined in DOM + {attr: "classList", sup: ["anyElement"]}, + // Defined in HTML except for a which is also SVG + {attr: "relList", sup: ["a", "area", "link"]}, + // Defined in HTML + {attr: "htmlFor", sup: ["output"]}, + {attr: "sandbox", sup: ["iframe"]}, + {attr: "sizes", sup: ["link"]} +]; +var namespaces = [ + "http://www.w3.org/1999/xhtml", + "http://www.w3.org/2000/svg", + "http://www.w3.org/1998/Math/MathML", + "http://example.com/", + "" +]; + +var elements = ["a", "area", "link", "iframe", "output", "td", "th"]; +function testAttr(pair, new_el){ + return (pair.attr === "classList" || + (pair.attr === "relList" && new_el.localName === "a" && + new_el.namespaceURI === "http://www.w3.org/2000/svg") || + (new_el.namespaceURI === "http://www.w3.org/1999/xhtml" && + pair.sup.indexOf(new_el.localName) != -1)); +} + +pairs.forEach(function(pair) { + namespaces.forEach(function(ns) { + elements.forEach(function(el) { + var new_el = document.createElementNS(ns, el); + if (testAttr(pair, new_el)) { + test(function() { + assert_class_string(new_el[pair.attr], "DOMTokenList"); + }, new_el.localName + "." + pair.attr + " in " + new_el.namespaceURI + " namespace should be DOMTokenList."); + } + else { + test(function() { + assert_equals(new_el[pair.attr], undefined); + }, new_el.localName + "." + pair.attr + " in " + new_el.namespaceURI + " namespace should be undefined."); + } + }); + }); +}); + +</script> diff --git a/testing/web-platform/tests/dom/lists/DOMTokenList-iteration.html b/testing/web-platform/tests/dom/lists/DOMTokenList-iteration.html new file mode 100644 index 0000000000..f713ad4aa0 --- /dev/null +++ b/testing/web-platform/tests/dom/lists/DOMTokenList-iteration.html @@ -0,0 +1,71 @@ +<!doctype html> +<meta charset=utf-8> +<title>DOMTokenList iteration: keys, values, etc.</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<span class=" a a b "></span> +<script> + test(() => { + var list = document.querySelector("span").classList; + assert_array_equals([...list], ["a", "b"]); + }, "classList"); + + test(() => { + var keys = document.querySelector("span").classList.keys(); + assert_false(keys instanceof Array, "must not be Array"); + keys = [...keys]; + assert_array_equals(keys, [0, 1]); + }, "classList.keys"); + + test(() => { + var values = document.querySelector("span").classList.values(); + assert_false(values instanceof Array, "must not be Array"); + values = [...values]; + assert_array_equals(values, ["a", "b"]); + }, "classList.values"); + + test(() => { + var entries = document.querySelector("span").classList.entries(); + assert_false(entries instanceof Array, "must not be Array"); + entries = [...entries]; + var keys = [...document.querySelector("span").classList.keys()]; + var values = [...document.querySelector("span").classList.values()]; + assert_equals(entries.length, keys.length, "entries.length == keys.length"); + assert_equals(entries.length, values.length, + "entries.length == values.length"); + for (var i = 0; i < entries.length; ++i) { + assert_array_equals(entries[i], [keys[i], values[i]], + "entries[" + i + "]"); + } + }, "classList.entries"); + + test(() => { + var list = document.querySelector("span").classList; + var values = [...list.values()]; + var keys = [...list.keys()]; + var entries = [...list.entries()]; + + var cur = 0; + var thisObj = {}; + list.forEach(function(value, key, listObj) { + assert_equals(listObj, list, "Entry " + cur + " listObj"); + assert_equals(this, thisObj, "Entry " + cur + " this"); + assert_equals(value, values[cur], "Entry " + cur + " value"); + assert_equals(key, keys[cur], "Entry " + cur + " key"); + cur++; + }, thisObj); + assert_equals(cur, entries.length, "length"); + }, "classList.forEach"); + + test(() => { + var list = document.querySelector("span").classList; + assert_equals(list[Symbol.iterator], Array.prototype[Symbol.iterator], + "[Symbol.iterator]"); + assert_equals(list.keys, Array.prototype.keys, ".keys"); + if (Array.prototype.values) { + assert_equals(list.values, Array.prototype.values, ".values"); + } + assert_equals(list.entries, Array.prototype.entries, ".entries"); + assert_equals(list.forEach, Array.prototype.forEach, ".forEach"); + }, "classList inheritance from Array.prototype"); +</script> diff --git a/testing/web-platform/tests/dom/lists/DOMTokenList-stringifier.html b/testing/web-platform/tests/dom/lists/DOMTokenList-stringifier.html new file mode 100644 index 0000000000..b125388e02 --- /dev/null +++ b/testing/web-platform/tests/dom/lists/DOMTokenList-stringifier.html @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>DOMTokenList stringifier</title> +<link rel=help href="https://dom.spec.whatwg.org/#dom-domtokenlist-stringifier"> +<link rel=author title=Ms2ger href="mailto:Ms2ger@gmail.com"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<span class=" a a b "></span> +<script> +test(function() { + assert_equals(String(document.createElement("span").classList), "", + "String(classList) should return the empty list for an undefined class attribute"); + var span = document.querySelector("span"); + assert_equals(span.getAttribute("class"), " a a b ", + "getAttribute should return the literal value"); + assert_equals(span.className, " a a b ", + "className should return the literal value"); + assert_equals(String(span.classList), " a a b ", + "String(classList) should return the literal value"); + assert_equals(span.classList.toString(), " a a b ", + "classList.toString() should return the literal value"); + assert_class_string(span.classList, "DOMTokenList"); +}); +</script> diff --git a/testing/web-platform/tests/dom/lists/DOMTokenList-value.html b/testing/web-platform/tests/dom/lists/DOMTokenList-value.html new file mode 100644 index 0000000000..b0e39111d9 --- /dev/null +++ b/testing/web-platform/tests/dom/lists/DOMTokenList-value.html @@ -0,0 +1,24 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>DOMTokenList value</title> +<link rel=help href="https://dom.spec.whatwg.org/#dom-domtokenlist-value"> +<link rel=author title=Tangresh href="mailto:dmenzi@tangresh.ch"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<span class=" a a b "></span> +<script> +test(function() { + assert_equals(String(document.createElement("span").classList.value), "", + "classList.value should return the empty list for an undefined class attribute"); + var span = document.querySelector("span"); + assert_equals(span.classList.value, " a a b ", + "value should return the literal value"); + span.classList.value = " foo bar foo "; + assert_equals(span.classList.value, " foo bar foo ", + "assigning value should set the literal value"); + assert_equals(span.classList.length, 2, + "length should be the number of tokens"); + assert_class_string(span.classList, "DOMTokenList"); + assert_class_string(span.classList.value, "String"); +}); +</script> diff --git a/testing/web-platform/tests/dom/lists/README.md b/testing/web-platform/tests/dom/lists/README.md new file mode 100644 index 0000000000..59c821a7da --- /dev/null +++ b/testing/web-platform/tests/dom/lists/README.md @@ -0,0 +1 @@ +See `../nodes/Element-classlist.html` for more DOMTokenList tests. |