Merge pull request #141 from lightpanda-io/extract-wpt-tests-cases

wpt: extract wpt tests cases
This commit is contained in:
Pierre Tachoire
2024-01-03 10:56:01 +01:00
committed by GitHub
173 changed files with 11 additions and 17577 deletions

View File

@@ -14,7 +14,7 @@ on:
paths: paths:
- "src/**/*.zig" - "src/**/*.zig"
- "src/*.zig" - "src/*.zig"
- "test/wpt/**" - "tests/wpt/**"
- "vendor/**" - "vendor/**"
pull_request: pull_request:
@@ -28,7 +28,7 @@ on:
paths: paths:
- "src/**/*.zig" - "src/**/*.zig"
- "src/*.zig" - "src/*.zig"
- "test/wpt/**" - "tests/wpt/**"
- "vendor/**" - "vendor/**"
# Allows you to run this workflow manually from the Actions tab # Allows you to run this workflow manually from the Actions tab
workflow_dispatch: workflow_dispatch:

3
.gitmodules vendored
View File

@@ -19,3 +19,6 @@
[submodule "vendor/netsurf/libhubbub"] [submodule "vendor/netsurf/libhubbub"]
path = vendor/netsurf/libhubbub path = vendor/netsurf/libhubbub
url = https://source.netsurf-browser.org/libhubbub.git url = https://source.netsurf-browser.org/libhubbub.git
[submodule "tests/wpt"]
path = tests/wpt
url = https://github.com/lightpanda-io/wpt

View File

@@ -84,7 +84,8 @@ Browsercore is tested against the standardized [Web Platform
Tests](https://web-platform-tests.org/). Tests](https://web-platform-tests.org/).
The relevant tests cases for Browsercore are commit with the project. The relevant tests cases for Browsercore are commit with the project.
All the tests cases executed are located in `tests/wpt` dir. All the tests cases executed are located in `tests/wpt` dir and come from an
external repository: https://github.com/lightpanda-io/wpt
For reference, you can easily execute a WPT test case with your browser via For reference, you can easily execute a WPT test case with your browser via
[wpt.live](https://wpt.live). [wpt.live](https://wpt.live).
@@ -107,7 +108,8 @@ make wpt Node-childNodes.html
We add new tests cases files with implemented changes in Browsercore. We add new tests cases files with implemented changes in Browsercore.
Copy the test case you want to add from the [WPT Copy the test case you want to add from the [WPT
repo](https://github.com/web-platform-tests/wpt) into `tests/wpt` dir and commit repo](https://github.com/web-platform-tests/wpt) into `tests/wpt` dir, commit
the files. the files in the https://github.com/lightpanda-io/wpt repository and update the
git submodule in browsercore.
:warning: Please keep the original directory tree structure into `tests/wpt`. :warning: Please keep the original directory tree structure into `tests/wpt`.

1
tests/wpt Submodule

Submodule tests/wpt added at 26ad8ed75d

View File

@@ -1,29 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title>Objects whose prototype is an HTMLCollection</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<script>
test(function() {
var obj = Object.create(document.getElementsByTagName("script"));
assert_throws_js(TypeError, function() {
obj.length;
});
}, "HTMLCollection as a prototype should not allow getting .length on the base object")
test(function() {
var element = document.createElement("p");
element.id = "named";
document.body.appendChild(element);
this.add_cleanup(function() { element.remove() });
var collection = document.getElementsByTagName("p");
assert_equals(collection.named, element);
var object = Object.create(collection);
assert_equals(object.named, element);
object.named = "foo";
assert_equals(object.named, "foo");
assert_equals(collection.named, element);
}, "HTMLCollection as a prototype and setting own properties")
</script>

View File

@@ -1,45 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title>Deleting properties from HTMLCollection</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<i id=foo></i>
<script>
let c, expected;
setup(() => {
// These might be cached anyway, so explicitly use a single object.
c = document.getElementsByTagName("i");
expected = document.getElementById("foo");
});
test(() => {
assert_equals(c[0], expected, "before");
delete c[0];
assert_equals(c[0], expected, "after");
}, "Loose id");
test(() => {
assert_equals(c[0], expected, "before");
assert_throws_js(TypeError, function() {
"use strict";
delete c[0];
});
assert_equals(c[0], expected, "after");
}, "Strict id");
test(() => {
assert_equals(c.foo, expected, "before");
delete c.foo;
assert_equals(c.foo, expected, "after");
}, "Loose name");
test(() => {
assert_equals(c.foo, expected, "before");
assert_throws_js(TypeError, function() {
"use strict";
delete c.foo;
});
assert_equals(c.foo, expected, "after");
}, "Strict name");
</script>

View File

@@ -1,65 +0,0 @@
<!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>

View File

@@ -1,45 +0,0 @@
<!doctype html>
<meta charset="utf-8">
<link rel="help" href="https://dom.spec.whatwg.org/#interface-htmlcollection">
<link rel="help" href="https://webidl.spec.whatwg.org/#es-iterator">
<title>HTMLCollection @@iterator Test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<p id="1"></p>
<p id="2"></p>
<p id="3"></p>
<p id="4"></p>
<p id="5"></p>
<script>
"use strict";
const paragraphs = document.getElementsByTagName("p");
test(() => {
assert_true("length" in paragraphs);
}, "HTMLCollection has length method.");
test(() => {
assert_false("values" in paragraphs);
}, "HTMLCollection does not have iterable's values method.");
test(() => {
assert_false("entries" in paragraphs);
}, "HTMLCollection does not have iterable's entries method.");
test(() => {
assert_false("forEach" in paragraphs);
}, "HTMLCollection does not have iterable's forEach method.");
test(() => {
assert_true(Symbol.iterator in paragraphs);
}, "HTMLCollection has Symbol.iterator.");
test(() => {
const ids = "12345";
let idx = 0;
for (const element of paragraphs) {
assert_equals(element.getAttribute("id"), ids[idx++]);
}
}, "HTMLCollection is iterable via for-of loop.");
</script>

View File

@@ -1,93 +0,0 @@
function testHTMLCollection(name, hooks) {
test(() => {
const nodes = {
root: document.createElement("div"),
div1: document.createElement("div"),
div2: document.createElement("div"),
p: document.createElement("p")
};
nodes.div1.id = "div1";
nodes.div2.id = "div2";
const list = nodes.root.getElementsByTagName("div");
hooks.initial(list, nodes);
nodes.root.appendChild(nodes.div1);
nodes.root.appendChild(nodes.p);
nodes.root.appendChild(nodes.div2);
hooks.afterInsertion(list, nodes);
nodes.root.removeChild(nodes.div1);
hooks.afterRemoval(list, nodes);
}, `HTMLCollection live mutations: ${name}`);
}
testHTMLCollection("HTMLCollection.length", {
initial(list) {
assert_equals(list.length, 0);
},
afterInsertion(list) {
assert_equals(list.length, 2);
},
afterRemoval(list) {
assert_equals(list.length, 1);
}
});
testHTMLCollection("HTMLCollection.item(index)", {
initial(list) {
assert_equals(list.item(0), null);
},
afterInsertion(list, nodes) {
assert_equals(list.item(0), nodes.div1);
assert_equals(list.item(1), nodes.div2);
},
afterRemoval(list, nodes) {
assert_equals(list.item(0), nodes.div2);
}
});
testHTMLCollection("HTMLCollection[index]", {
initial(list) {
assert_equals(list[0], undefined);
},
afterInsertion(list, nodes) {
assert_equals(list[0], nodes.div1);
assert_equals(list[1], nodes.div2);
},
afterRemoval(list, nodes) {
assert_equals(list[0], nodes.div2);
}
});
testHTMLCollection("HTMLCollection.namedItem(index)", {
initial(list) {
assert_equals(list.namedItem("div1"), null);
assert_equals(list.namedItem("div2"), null);
},
afterInsertion(list, nodes) {
assert_equals(list.namedItem("div1"), nodes.div1);
assert_equals(list.namedItem("div2"), nodes.div2);
},
afterRemoval(list, nodes) {
assert_equals(list.namedItem("div1"), null);
assert_equals(list.namedItem("div2"), nodes.div2);
}
});
testHTMLCollection("HTMLCollection ownPropertyNames", {
initial(list) {
assert_object_equals(Object.getOwnPropertyNames(list), []);
},
afterInsertion(list) {
assert_object_equals(Object.getOwnPropertyNames(list), ["0", "1", "div1", "div2"]);
},
afterRemoval(list) {
assert_object_equals(Object.getOwnPropertyNames(list), ["0", "div2"]);
}
});

View File

@@ -1,109 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title>HTMLCollection getters and own properties</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<script>
function append(t, tag, name) {
var element = document.createElement(tag);
if (name) {
element.id = name;
}
document.body.appendChild(element);
t.add_cleanup(function() { element.remove(); });
return element;
}
test(function() {
var name = "named", tag = "a";
var c = document.getElementsByTagName(tag);
var element = append(this, tag, name);
assert_equals(c[name], element);
c[name] = "foo";
assert_equals(c[name], element);
}, "Setting non-array index while named property exists (loose)");
test(function() {
"use strict";
var name = "named", tag = "b";
var c = document.getElementsByTagName(tag);
var element = append(this, tag, name);
assert_equals(c[name], element);
assert_throws_js(TypeError, function() {
c[name] = "foo";
});
assert_equals(c[name], element);
}, "Setting non-array index while named property exists (strict)");
test(function() {
var name = "named", tag = "i";
var c = document.getElementsByTagName(tag);
assert_equals(c[name], undefined);
c[name] = "foo";
assert_equals(c[name], "foo");
var element = append(this, tag, name);
assert_equals(c[name], "foo");
assert_equals(c.namedItem(name), element);
}, "Setting non-array index while named property doesn't exist (loose)");
test(function() {
"use strict";
var name = "named", tag = "p";
var c = document.getElementsByTagName(tag);
assert_equals(c[name], undefined);
c[name] = "foo";
assert_equals(c[name], "foo");
var element = append(this, tag, name);
assert_equals(c[name], "foo");
assert_equals(c.namedItem(name), element);
}, "Setting non-array index while named property doesn't exist (strict)");
test(function() {
var tag = "q";
var c = document.getElementsByTagName(tag);
var element = append(this, tag);
assert_equals(c[0], element);
c[0] = "foo";
assert_equals(c[0], element);
}, "Setting array index while indexed property exists (loose)");
test(function() {
"use strict";
var tag = "s";
var c = document.getElementsByTagName(tag);
var element = append(this, tag);
assert_equals(c[0], element);
assert_throws_js(TypeError, function() {
c[0] = "foo";
});
assert_equals(c[0], element);
}, "Setting array index while indexed property exists (strict)");
test(function() {
var tag = "u";
var c = document.getElementsByTagName(tag);
assert_equals(c[0], undefined);
c[0] = "foo";
assert_equals(c[0], undefined);
var element = append(this, tag);
assert_equals(c[0], element);
}, "Setting array index while indexed property doesn't exist (loose)");
test(function() {
"use strict";
var tag = "u";
var c = document.getElementsByTagName(tag);
assert_equals(c[0], undefined);
assert_throws_js(TypeError, function() {
c[0] = "foo";
});
assert_equals(c[0], undefined);
var element = append(this, tag);
assert_equals(c[0], element);
}, "Setting array index while indexed property doesn't exist (strict)");
</script>

View File

@@ -1,179 +0,0 @@
<!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_js(TypeError, function() {
"use strict";
elements[0] = 5;
});
assert_throws_js(TypeError, function() {
Object.defineProperty(elements, 0, { value: 5 });
});
delete elements[0];
assert_equals(elements[0], old_item);
assert_throws_js(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_js(TypeError, function() {
"use strict";
elements[idx] = 5;
});
assert_throws_js(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_js(TypeError, function() {
"use strict";
delete elements[0];
});
assert_equals(elements[0], old_item);
}, 'Trying to delete an indexed property name should never work');
</script>

View File

@@ -1,135 +0,0 @@
<!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_js(TypeError, function() {
"use strict";
elements["some-id"] = 5;
});
assert_throws_js(TypeError, function() {
Object.defineProperty(elements, "some-id", { value: 5 });
});
delete elements["some-id"];
assert_equals(elements["some-id"], old_item);
assert_throws_js(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_js(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>

View File

@@ -1,54 +0,0 @@
<!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>

View File

@@ -1,30 +0,0 @@
<!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>

View File

@@ -1,166 +0,0 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>ChildNode.after</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-childnode-after">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function test_after(child, nodeName, innerHTML) {
test(function() {
var parent = document.createElement('div');
parent.appendChild(child);
child.after();
assert_equals(parent.innerHTML, innerHTML);
}, nodeName + '.after() without any argument.');
test(function() {
var parent = document.createElement('div');
parent.appendChild(child);
child.after(null);
var expected = innerHTML + 'null';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with null as an argument.');
test(function() {
var parent = document.createElement('div');
parent.appendChild(child);
child.after(undefined);
var expected = innerHTML + 'undefined';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with undefined as an argument.');
test(function() {
var parent = document.createElement('div');
parent.appendChild(child);
child.after('');
assert_equals(parent.lastChild.data, '');
}, nodeName + '.after() with the empty string as an argument.');
test(function() {
var parent = document.createElement('div');
parent.appendChild(child);
child.after('text');
var expected = innerHTML + 'text';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with only text as an argument.');
test(function() {
var parent = document.createElement('div');
var x = document.createElement('x');
parent.appendChild(child);
child.after(x);
var expected = innerHTML + '<x></x>';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with only one element as an argument.');
test(function() {
var parent = document.createElement('div');
var x = document.createElement('x');
parent.appendChild(child);
child.after(x, 'text');
var expected = innerHTML + '<x></x>text';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with one element and text as arguments.');
test(function() {
var parent = document.createElement('div');
parent.appendChild(child);
child.after('text', child);
var expected = 'text' + innerHTML;
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with context object itself as the argument.');
test(function() {
var parent = document.createElement('div')
var x = document.createElement('x');
parent.appendChild(x);
parent.appendChild(child);
child.after(child, x);
var expected = innerHTML + '<x></x>';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with context object itself and node as the arguments, switching positions.');
test(function() {
var parent = document.createElement('div');
var x = document.createElement('x');
var y = document.createElement('y');
var z = document.createElement('z');
parent.appendChild(y);
parent.appendChild(child);
parent.appendChild(x);
child.after(x, y, z);
var expected = innerHTML + '<x></x><y></y><z></z>';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with all siblings of child as arguments.');
test(function() {
var parent = document.createElement('div')
var x = document.createElement('x');
var y = document.createElement('y');
var z = document.createElement('z');
parent.appendChild(child);
parent.appendChild(x);
parent.appendChild(y);
parent.appendChild(z);
child.after(x, y);
var expected = innerHTML + '<x></x><y></y><z></z>';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.before() with some siblings of child as arguments; no changes in tree; viable sibling is first child.');
test(function() {
var parent = document.createElement('div')
var v = document.createElement('v');
var x = document.createElement('x');
var y = document.createElement('y');
var z = document.createElement('z');
parent.appendChild(child);
parent.appendChild(v);
parent.appendChild(x);
parent.appendChild(y);
parent.appendChild(z);
child.after(v, x);
var expected = innerHTML + '<v></v><x></x><y></y><z></z>';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with some siblings of child as arguments; no changes in tree.');
test(function() {
var parent = document.createElement('div');
var x = document.createElement('x');
var y = document.createElement('y');
parent.appendChild(child);
parent.appendChild(x);
parent.appendChild(y);
child.after(y, x);
var expected = innerHTML + '<y></y><x></x>';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() when pre-insert behaves like append.');
test(function() {
var parent = document.createElement('div');
var x = document.createElement('x');
var y = document.createElement('y');
parent.appendChild(child);
parent.appendChild(x);
parent.appendChild(document.createTextNode('1'));
parent.appendChild(y);
child.after(x, '2');
var expected = innerHTML + '<x></x>21<y></y>';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with one sibling of child and text as arguments.');
test(function() {
var x = document.createElement('x');
var y = document.createElement('y');
x.after(y);
assert_equals(x.nextSibling, null);
}, nodeName + '.after() on a child without any parent.');
}
test_after(document.createComment('test'), 'Comment', '<!--test-->');
test_after(document.createElement('test'), 'Element', '<test></test>');
test_after(document.createTextNode('test'), 'Text', 'test');
</script>
</html>

View File

@@ -1,13 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title>DOMImplementation.createDocument()</title>
<link rel="author" title="Nate Chapin" href="mailto:japhet@chromium.org">
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createdocument">
<link rel="help" href="https://bugs.chromium.org/p/chromium/issues/detail?id=1086801">
<meta name="assert" content="Calling on createDocument() on a DOMImplementation from a document with a null browsing context should not crash"/>
<iframe id="i"></iframe>
<script>
var doc = i.contentDocument;
i.remove();
doc.implementation.createDocument("", "");
</script>

View File

@@ -1,170 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title>DOMImplementation.createDocument(namespace, qualifiedName, doctype)</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createdocument">
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-createelementns">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-nodetype">
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-documentelement">
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-doctype">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="Document-createElementNS.js"></script>
<div id="log"></div>
<script>
var htmlNamespace = "http://www.w3.org/1999/xhtml"
var svgNamespace = "http://www.w3.org/2000/svg"
var mathMLNamespace = "http://www.w3.org/1998/Math/MathML"
// Make DocumentTypes distinct
function my_format_value(val) {
if (val instanceof DocumentType) {
return "DocumentType node <!DOCTYPE " + val.name
+ (val.publicId ? " " + val.publicId : "")
+ (val.systemId ? " " + val.systemId : "")
+ ">";
}
return format_value(val);
}
test(function() {
var tests = createElementNS_tests.map(function(t) {
return [t[0], t[1], null, t[2]]
}).concat([
/* Arrays with four elements:
* the namespace argument
* the qualifiedName argument
* the doctype argument
* the expected exception, or null if none
*/
[null, null, false, TypeError],
[null, "", null, null],
[undefined, null, undefined, null],
[undefined, undefined, undefined, null],
[undefined, "", undefined, null],
["http://example.com/", null, null, null],
["http://example.com/", "", null, null],
["/", null, null, null],
["/", "", null, null],
["http://www.w3.org/XML/1998/namespace", null, null, null],
["http://www.w3.org/XML/1998/namespace", "", null, null],
["http://www.w3.org/2000/xmlns/", null, null, null],
["http://www.w3.org/2000/xmlns/", "", null, null],
["foo:", null, null, null],
["foo:", "", null, null],
[null, null, document.implementation.createDocumentType("foo", "", ""), null],
[null, null, document.doctype, null], // This causes a horrible WebKit bug (now fixed in trunk).
[null, null, function() {
var foo = document.implementation.createDocumentType("bar", "", "");
document.implementation.createDocument(null, null, foo);
return foo;
}(), null], // DOCTYPE already associated with a document.
[null, null, function() {
var bar = document.implementation.createDocument(null, null, null);
return bar.implementation.createDocumentType("baz", "", "");
}(), null], // DOCTYPE created by a different implementation.
[null, null, function() {
var bar = document.implementation.createDocument(null, null, null);
var magic = bar.implementation.createDocumentType("quz", "", "");
bar.implementation.createDocument(null, null, magic);
return magic;
}(), null], // DOCTYPE created by a different implementation and already associated with a document.
[null, "foo", document.implementation.createDocumentType("foo", "", ""), null],
["foo", null, document.implementation.createDocumentType("foo", "", ""), null],
["foo", "bar", document.implementation.createDocumentType("foo", "", ""), null],
[htmlNamespace, "", null, null],
[svgNamespace, "", null, null],
[mathMLNamespace, "", null, null],
[null, "html", null, null],
[null, "svg", null, null],
[null, "math", null, null],
[null, "", document.implementation.createDocumentType("html",
"-//W3C//DTD XHTML 1.0 Transitional//EN",
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")],
[null, "", document.implementation.createDocumentType("svg",
"-//W3C//DTD SVG 1.1//EN",
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd")],
[null, "", document.implementation.createDocumentType("math",
"-//W3C//DTD MathML 2.0//EN",
"http://www.w3.org/Math/DTD/mathml2/mathml2.dtd")],
])
tests.forEach(function(t, i) {
var namespace = t[0], qualifiedName = t[1], doctype = t[2], expected = t[3]
test(function() {
if (expected != null) {
if (typeof expected == "string") {
assert_throws_dom(expected, function() { document.implementation.createDocument(namespace, qualifiedName, doctype) });
} else {
assert_throws_js(expected, function() { document.implementation.createDocument(namespace, qualifiedName, doctype) });
}
} else {
var doc = document.implementation.createDocument(namespace, qualifiedName, doctype)
assert_equals(doc.nodeType, Node.DOCUMENT_NODE)
assert_equals(doc.nodeType, doc.DOCUMENT_NODE)
assert_equals(doc.nodeName, "#document")
assert_equals(doc.nodeValue, null)
assert_equals(Object.getPrototypeOf(doc), XMLDocument.prototype)
var omitRootElement = qualifiedName === null || String(qualifiedName) === ""
if (omitRootElement) {
assert_equals(doc.documentElement, null)
} else {
var element = doc.documentElement
assert_not_equals(element, null)
assert_equals(element.nodeType, Node.ELEMENT_NODE)
assert_equals(element.ownerDocument, doc)
var qualified = String(qualifiedName), names = []
if (qualified.indexOf(":") >= 0) {
names = qualified.split(":", 2)
} else {
names = [null, qualified]
}
assert_equals(element.prefix, names[0])
assert_equals(element.localName, names[1])
assert_equals(element.namespaceURI, namespace === undefined ? null : namespace)
}
if (!doctype) {
assert_equals(doc.doctype, null)
} else {
assert_equals(doc.doctype, doctype)
assert_equals(doc.doctype.ownerDocument, doc)
}
assert_equals(doc.childNodes.length, !omitRootElement + !!doctype)
}
}, "createDocument test: " + t.map(my_format_value))
if (expected === null) {
test(function() {
var doc = document.implementation.createDocument(namespace, qualifiedName, doctype)
assert_equals(doc.location, null)
assert_equals(doc.compatMode, "CSS1Compat")
assert_equals(doc.characterSet, "UTF-8")
assert_equals(doc.contentType, namespace == htmlNamespace ? "application/xhtml+xml"
: namespace == svgNamespace ? "image/svg+xml"
: "application/xml")
assert_equals(doc.URL, "about:blank")
assert_equals(doc.documentURI, "about:blank")
assert_equals(doc.createElement("DIV").localName, "DIV");
}, "createDocument test: metadata for " +
[namespace, qualifiedName, doctype].map(my_format_value))
test(function() {
var doc = document.implementation.createDocument(namespace, qualifiedName, doctype)
assert_equals(doc.characterSet, "UTF-8", "characterSet");
assert_equals(doc.charset, "UTF-8", "charset");
assert_equals(doc.inputEncoding, "UTF-8", "inputEncoding");
}, "createDocument test: characterSet aliases for " +
[namespace, qualifiedName, doctype].map(my_format_value))
}
})
})
test(function() {
assert_throws_js(TypeError, function() {
document.implementation.createDocument()
}, "createDocument() should throw")
assert_throws_js(TypeError, function() {
document.implementation.createDocument('')
}, "createDocument('') should throw")
}, "createDocument with missing arguments");
</script>

View File

@@ -1,123 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title>DOMImplementation.createDocumentType(qualifiedName, publicId, systemId)</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype">
<link rel=help href="https://dom.spec.whatwg.org/#dom-documenttype-name">
<link rel=help href="https://dom.spec.whatwg.org/#dom-documenttype-publicid">
<link rel=help href="https://dom.spec.whatwg.org/#dom-documenttype-systemid">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-ownerdocument">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
test(function() {
var tests = [
["", "", "", "INVALID_CHARACTER_ERR"],
["test:root", "1234", "", null],
["test:root", "1234", "test", null],
["test:root", "test", "", null],
["test:root", "test", "test", null],
["_:_", "", "", null],
["_:h0", "", "", null],
["_:test", "", "", null],
["_:_.", "", "", null],
["_:a-", "", "", null],
["l_:_", "", "", null],
["ns:_0", "", "", null],
["ns:a0", "", "", null],
["ns0:test", "", "", null],
["ns:EEE.", "", "", null],
["ns:_-", "", "", null],
["a.b:c", "", "", null],
["a-b:c.j", "", "", null],
["a-b:c", "", "", null],
["foo", "", "", null],
["1foo", "", "", "INVALID_CHARACTER_ERR"],
["foo1", "", "", null],
["f1oo", "", "", null],
["@foo", "", "", "INVALID_CHARACTER_ERR"],
["foo@", "", "", "INVALID_CHARACTER_ERR"],
["f@oo", "", "", "INVALID_CHARACTER_ERR"],
["edi:{", "", "", "INVALID_CHARACTER_ERR"],
["edi:}", "", "", "INVALID_CHARACTER_ERR"],
["edi:~", "", "", "INVALID_CHARACTER_ERR"],
["edi:'", "", "", "INVALID_CHARACTER_ERR"],
["edi:!", "", "", "INVALID_CHARACTER_ERR"],
["edi:@", "", "", "INVALID_CHARACTER_ERR"],
["edi:#", "", "", "INVALID_CHARACTER_ERR"],
["edi:$", "", "", "INVALID_CHARACTER_ERR"],
["edi:%", "", "", "INVALID_CHARACTER_ERR"],
["edi:^", "", "", "INVALID_CHARACTER_ERR"],
["edi:&", "", "", "INVALID_CHARACTER_ERR"],
["edi:*", "", "", "INVALID_CHARACTER_ERR"],
["edi:(", "", "", "INVALID_CHARACTER_ERR"],
["edi:)", "", "", "INVALID_CHARACTER_ERR"],
["edi:+", "", "", "INVALID_CHARACTER_ERR"],
["edi:=", "", "", "INVALID_CHARACTER_ERR"],
["edi:[", "", "", "INVALID_CHARACTER_ERR"],
["edi:]", "", "", "INVALID_CHARACTER_ERR"],
["edi:\\", "", "", "INVALID_CHARACTER_ERR"],
["edi:/", "", "", "INVALID_CHARACTER_ERR"],
["edi:;", "", "", "INVALID_CHARACTER_ERR"],
["edi:`", "", "", "INVALID_CHARACTER_ERR"],
["edi:<", "", "", "INVALID_CHARACTER_ERR"],
["edi:>", "", "", "INVALID_CHARACTER_ERR"],
["edi:,", "", "", "INVALID_CHARACTER_ERR"],
["edi:a ", "", "", "INVALID_CHARACTER_ERR"],
["edi:\"", "", "", "INVALID_CHARACTER_ERR"],
["{", "", "", "INVALID_CHARACTER_ERR"],
["}", "", "", "INVALID_CHARACTER_ERR"],
["'", "", "", "INVALID_CHARACTER_ERR"],
["~", "", "", "INVALID_CHARACTER_ERR"],
["`", "", "", "INVALID_CHARACTER_ERR"],
["@", "", "", "INVALID_CHARACTER_ERR"],
["#", "", "", "INVALID_CHARACTER_ERR"],
["$", "", "", "INVALID_CHARACTER_ERR"],
["%", "", "", "INVALID_CHARACTER_ERR"],
["^", "", "", "INVALID_CHARACTER_ERR"],
["&", "", "", "INVALID_CHARACTER_ERR"],
["*", "", "", "INVALID_CHARACTER_ERR"],
["(", "", "", "INVALID_CHARACTER_ERR"],
[")", "", "", "INVALID_CHARACTER_ERR"],
["f:oo", "", "", null],
[":foo", "", "", "INVALID_CHARACTER_ERR"],
["foo:", "", "", "INVALID_CHARACTER_ERR"],
["prefix::local", "", "", "INVALID_CHARACTER_ERR"],
["foo", "foo", "", null],
["foo", "", "foo", null],
["foo", "f'oo", "", null],
["foo", "", "f'oo", null],
["foo", 'f"oo', "", null],
["foo", "", 'f"oo', null],
["foo", "f'o\"o", "", null],
["foo", "", "f'o\"o", null],
["foo", "foo>", "", null],
["foo", "", "foo>", null]
]
var doc = document.implementation.createHTMLDocument("title");
var doTest = function(aDocument, aQualifiedName, aPublicId, aSystemId) {
var doctype = aDocument.implementation.createDocumentType(aQualifiedName, aPublicId, aSystemId);
assert_equals(doctype.name, aQualifiedName, "name")
assert_equals(doctype.nodeName, aQualifiedName, "nodeName")
assert_equals(doctype.publicId, aPublicId, "publicId")
assert_equals(doctype.systemId, aSystemId, "systemId")
assert_equals(doctype.ownerDocument, aDocument, "ownerDocument")
assert_equals(doctype.nodeValue, null, "nodeValue")
}
tests.forEach(function(t) {
var qualifiedName = t[0], publicId = t[1], systemId = t[2], expected = t[3]
test(function() {
if (expected) {
assert_throws_dom(expected, function() {
document.implementation.createDocumentType(qualifiedName, publicId, systemId)
})
} else {
doTest(document, qualifiedName, publicId, systemId);
doTest(doc, qualifiedName, publicId, systemId);
}
}, "createDocumentType(" + format_value(qualifiedName) + ", " + format_value(publicId) + ", " + format_value(systemId) + ") should " +
(expected ? "throw " + expected : "work"));
});
})
</script>

View File

@@ -1,13 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title>DOMImplementation.createHTMLDocument()</title>
<link rel="author" title="Nate Chapin" href="mailto:japhet@chromium.org">
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument">
<link rel="help" href="https://bugs.chromium.org/p/chromium/issues/detail?id=1086800">
<meta name="assert" content="Calling on createHTMLDocument() on a DOMImplementation from a document with a null browsing context should not crash"/>
<iframe id="i"></iframe>
<script>
var doc = i.contentDocument;
i.remove();
doc.implementation.createHTMLDocument();
</script>

View File

@@ -1,16 +0,0 @@
<!DOCTYPE html>
<title>DOMImplementation.createHTMLDocument</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
// Test the document location getter is null outside of browser context
test(function() {
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);
var implementation = iframe.contentDocument.implementation;
iframe.remove();
assert_not_equals(implementation.createHTMLDocument(), null);
}, "createHTMLDocument(): from a saved and detached implementation does not return null")
</script>

View File

@@ -1,96 +0,0 @@
<!DOCTYPE html>
<meta charset=windows-1252>
<!-- Using windows-1252 to ensure that DOMImplementation.createHTMLDocument()
doesn't inherit utf-8 from the parent document. -->
<title>DOMImplementation.createHTMLDocument</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument">
<link rel=help href="https://dom.spec.whatwg.org/#dom-documenttype-name">
<link rel=help href="https://dom.spec.whatwg.org/#dom-documenttype-publicid">
<link rel=help href="https://dom.spec.whatwg.org/#dom-documenttype-systemid">
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-documentelement">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="DOMImplementation-createHTMLDocument.js"></script>
<div id="log"></div>
<script>
createHTMLDocuments(function(doc, expectedtitle, normalizedtitle) {
assert_true(doc instanceof Document, "Should be a Document")
assert_true(doc instanceof Node, "Should be a Node")
assert_equals(doc.childNodes.length, 2,
"Document should have two child nodes")
var doctype = doc.doctype
assert_true(doctype instanceof DocumentType,
"Doctype should be a DocumentType")
assert_true(doctype instanceof Node, "Doctype should be a Node")
assert_equals(doctype.name, "html")
assert_equals(doctype.publicId, "")
assert_equals(doctype.systemId, "")
var documentElement = doc.documentElement
assert_true(documentElement instanceof HTMLHtmlElement,
"Document element should be a HTMLHtmlElement")
assert_equals(documentElement.childNodes.length, 2,
"Document element should have two child nodes")
assert_equals(documentElement.localName, "html")
assert_equals(documentElement.tagName, "HTML")
var head = documentElement.firstChild
assert_true(head instanceof HTMLHeadElement,
"Head should be a HTMLHeadElement")
assert_equals(head.localName, "head")
assert_equals(head.tagName, "HEAD")
if (expectedtitle !== undefined) {
assert_equals(head.childNodes.length, 1)
var title = head.firstChild
assert_true(title instanceof HTMLTitleElement,
"Title should be a HTMLTitleElement")
assert_equals(title.localName, "title")
assert_equals(title.tagName, "TITLE")
assert_equals(title.childNodes.length, 1)
assert_equals(title.firstChild.data, expectedtitle)
} else {
assert_equals(head.childNodes.length, 0)
}
var body = documentElement.lastChild
assert_true(body instanceof HTMLBodyElement,
"Body should be a HTMLBodyElement")
assert_equals(body.localName, "body")
assert_equals(body.tagName, "BODY")
assert_equals(body.childNodes.length, 0)
})
test(function() {
var doc = document.implementation.createHTMLDocument("test");
assert_equals(doc.URL, "about:blank");
assert_equals(doc.documentURI, "about:blank");
assert_equals(doc.compatMode, "CSS1Compat");
assert_equals(doc.characterSet, "UTF-8");
assert_equals(doc.contentType, "text/html");
assert_equals(doc.createElement("DIV").localName, "div");
}, "createHTMLDocument(): metadata")
test(function() {
var doc = document.implementation.createHTMLDocument("test");
assert_equals(doc.characterSet, "UTF-8", "characterSet");
assert_equals(doc.charset, "UTF-8", "charset");
assert_equals(doc.inputEncoding, "UTF-8", "inputEncoding");
}, "createHTMLDocument(): characterSet aliases")
test(function() {
var doc = document.implementation.createHTMLDocument("test");
var a = doc.createElement("a");
// In UTF-8: 0xC3 0xA4
a.href = "http://example.org/?\u00E4";
assert_equals(a.href, "http://example.org/?%C3%A4");
}, "createHTMLDocument(): URL parsing")
// Test the document location getter is null outside of browser context
test(function() {
var doc = document.implementation.createHTMLDocument();
assert_equals(doc.location, null);
}, "createHTMLDocument(): document location getter is null")
</script>

View File

@@ -1,25 +0,0 @@
function createHTMLDocuments(checkDoc) {
var tests = [
["", "", ""],
[null, "null", "null"],
[undefined, undefined, ""],
["foo bar baz", "foo bar baz", "foo bar baz"],
["foo\t\tbar baz", "foo\t\tbar baz", "foo bar baz"],
["foo\n\nbar baz", "foo\n\nbar baz", "foo bar baz"],
["foo\f\fbar baz", "foo\f\fbar baz", "foo bar baz"],
["foo\r\rbar baz", "foo\r\rbar baz", "foo bar baz"],
]
tests.forEach(function(t, i) {
var title = t[0], expectedtitle = t[1], normalizedtitle = t[2]
test(function() {
var doc = document.implementation.createHTMLDocument(title);
checkDoc(doc, expectedtitle, normalizedtitle)
}, "createHTMLDocument test " + i + ": " + t.map(function(el) { return format_value(el) }))
})
test(function() {
var doc = document.implementation.createHTMLDocument();
checkDoc(doc, undefined, "")
}, "Missing title argument");
}

View File

@@ -1,155 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title>DOMImplementation.hasFeature(feature, version)</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-hasfeature">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
test(function() {
var tests = [
[],
["Core"],
["XML"],
["org.w3c.svg"],
["org.w3c.dom.svg"],
["http://www.w3.org/TR/SVG11/feature#Script"],
["Core", "1.0"],
["Core", "2.0"],
["Core", "3.0"],
["Core", "100.0"],
["XML", "1.0"],
["XML", "2.0"],
["XML", "3.0"],
["XML", "100.0"],
["Core", "1"],
["Core", "2"],
["Core", "3"],
["Core", "100"],
["XML", "1"],
["XML", "2"],
["XML", "3"],
["XML", "100"],
["Core", "1.1"],
["Core", "2.1"],
["Core", "3.1"],
["Core", "100.1"],
["XML", "1.1"],
["XML", "2.1"],
["XML", "3.1"],
["XML", "100.1"],
["Core", ""],
["XML", ""],
["core", ""],
["xml", ""],
["CoRe", ""],
["XmL", ""],
[" Core", ""],
[" XML", ""],
["Core ", ""],
["XML ", ""],
["Co re", ""],
["XM L", ""],
["aCore", ""],
["aXML", ""],
["Corea", ""],
["XMLa", ""],
["Coare", ""],
["XMaL", ""],
["Core", " "],
["XML", " "],
["Core", " 1.0"],
["Core", " 2.0"],
["Core", " 3.0"],
["Core", " 100.0"],
["XML", " 1.0"],
["XML", " 2.0"],
["XML", " 3.0"],
["XML", " 100.0"],
["Core", "1.0 "],
["Core", "2.0 "],
["Core", "3.0 "],
["Core", "100.0 "],
["XML", "1.0 "],
["XML", "2.0 "],
["XML", "3.0 "],
["XML", "100.0 "],
["Core", "1. 0"],
["Core", "2. 0"],
["Core", "3. 0"],
["Core", "100. 0"],
["XML", "1. 0"],
["XML", "2. 0"],
["XML", "3. 0"],
["XML", "100. 0"],
["Core", "a1.0"],
["Core", "a2.0"],
["Core", "a3.0"],
["Core", "a100.0"],
["XML", "a1.0"],
["XML", "a2.0"],
["XML", "a3.0"],
["XML", "a100.0"],
["Core", "1.0a"],
["Core", "2.0a"],
["Core", "3.0a"],
["Core", "100.0a"],
["XML", "1.0a"],
["XML", "2.0a"],
["XML", "3.0a"],
["XML", "100.0a"],
["Core", "1.a0"],
["Core", "2.a0"],
["Core", "3.a0"],
["Core", "100.a0"],
["XML", "1.a0"],
["XML", "2.a0"],
["XML", "3.a0"],
["XML", "100.a0"],
["Core", 1],
["Core", 2],
["Core", 3],
["Core", 100],
["XML", 1],
["XML", 2],
["XML", 3],
["XML", 100],
["Core", null],
["XML", null],
["core", null],
["xml", null],
["CoRe", null],
["XmL", null],
[" Core", null],
[" XML", null],
["Core ", null],
["XML ", null],
["Co re", null],
["XM L", null],
["aCore", null],
["aXML", null],
["Corea", null],
["XMLa", null],
["Coare", null],
["XMaL", null],
["Core", undefined],
["XML", undefined],
["This is filler text.", ""],
[null, ""],
[undefined, ""],
["org.w3c.svg", ""],
["org.w3c.svg", "1.0"],
["org.w3c.svg", "1.1"],
["org.w3c.dom.svg", ""],
["org.w3c.dom.svg", "1.0"],
["org.w3c.dom.svg", "1.1"],
["http://www.w3.org/TR/SVG11/feature#Script", "7.5"],
];
tests.forEach(function(data) {
test(function() {
assert_equals(document.implementation.hasFeature
.apply(document.implementation, data), true)
}, "hasFeature(" + data.map(format_value).join(", ") + ")")
})
})
</script>

View File

@@ -1,208 +0,0 @@
function test_getElementsByTagName(context, element) {
// TODO: getElementsByTagName("*")
test(function() {
assert_false(context.getElementsByTagName("html") instanceof NodeList,
"Should not return a NodeList")
assert_true(context.getElementsByTagName("html") instanceof HTMLCollection,
"Should return an HTMLCollection")
}, "Interfaces")
test(function() {
var firstCollection = context.getElementsByTagName("html"),
secondCollection = context.getElementsByTagName("html")
assert_true(firstCollection !== secondCollection ||
firstCollection === secondCollection)
}, "Caching is allowed")
test(function() {
var l = context.getElementsByTagName("nosuchtag")
l[5] = "foopy"
assert_equals(l[5], undefined)
assert_equals(l.item(5), null)
}, "Shouldn't be able to set unsigned properties on a HTMLCollection (non-strict mode)")
test(function() {
var l = context.getElementsByTagName("nosuchtag")
assert_throws_js(TypeError, function() {
"use strict";
l[5] = "foopy"
})
assert_equals(l[5], undefined)
assert_equals(l.item(5), null)
}, "Shouldn't be able to set unsigned properties on a HTMLCollection (strict mode)")
test(function() {
var l = context.getElementsByTagName("nosuchtag")
var fn = l.item;
assert_equals(fn, HTMLCollection.prototype.item);
l.item = "pass"
assert_equals(l.item, "pass")
assert_equals(HTMLCollection.prototype.item, fn);
}, "Should be able to set expando shadowing a proto prop (item)")
test(function() {
var l = context.getElementsByTagName("nosuchtag")
var fn = l.namedItem;
assert_equals(fn, HTMLCollection.prototype.namedItem);
l.namedItem = "pass"
assert_equals(l.namedItem, "pass")
assert_equals(HTMLCollection.prototype.namedItem, fn);
}, "Should be able to set expando shadowing a proto prop (namedItem)")
test(function() {
var t1 = element.appendChild(document.createElement("pre"));
t1.id = "x";
var t2 = element.appendChild(document.createElement("pre"));
t2.setAttribute("name", "y");
var t3 = element.appendChild(document.createElementNS("", "pre"));
t3.setAttribute("id", "z");
var t4 = element.appendChild(document.createElementNS("", "pre"));
t4.setAttribute("name", "w");
this.add_cleanup(function() {
element.removeChild(t1)
element.removeChild(t2)
element.removeChild(t3)
element.removeChild(t4)
});
var list = context.getElementsByTagName('pre');
var pre = list[0];
assert_equals(pre.id, "x");
var exposedNames = { 'x': 0, 'y': 1, 'z': 2 };
for (var exposedName in exposedNames) {
assert_equals(list[exposedName], list[exposedNames[exposedName]]);
assert_equals(list[exposedName], list.namedItem(exposedName));
assert_true(exposedName in list, "'" + exposedName + "' in list");
assert_true(list.hasOwnProperty(exposedName),
"list.hasOwnProperty('" + exposedName + "')");
}
var unexposedNames = ["w"];
for (var unexposedName of unexposedNames) {
assert_false(unexposedName in list);
assert_false(list.hasOwnProperty(unexposedName));
assert_equals(list[unexposedName], undefined);
assert_equals(list.namedItem(unexposedName), null);
}
assert_array_equals(Object.getOwnPropertyNames(list).sort(),
["0", "1", "2", "3", "x", "y", "z"]);
var desc = Object.getOwnPropertyDescriptor(list, '0');
assert_equals(typeof desc, "object", "descriptor should be an object");
assert_true(desc.enumerable, "desc.enumerable");
assert_true(desc.configurable, "desc.configurable");
desc = Object.getOwnPropertyDescriptor(list, 'x');
assert_equals(typeof desc, "object", "descriptor should be an object");
assert_false(desc.enumerable, "desc.enumerable");
assert_true(desc.configurable, "desc.configurable");
}, "hasOwnProperty, getOwnPropertyDescriptor, getOwnPropertyNames")
test(function() {
assert_equals(document.createElementNS("http://www.w3.org/1999/xhtml", "i").localName, "i") // Sanity
var t = element.appendChild(document.createElementNS("http://www.w3.org/1999/xhtml", "I"))
this.add_cleanup(function() {element.removeChild(t)})
assert_equals(t.localName, "I")
assert_equals(t.tagName, "I")
assert_equals(context.getElementsByTagName("I").length, 0)
assert_equals(context.getElementsByTagName("i").length, 0)
}, "HTML element with uppercase tagName never matches in HTML Documents")
test(function() {
var t = element.appendChild(document.createElementNS("test", "st"))
this.add_cleanup(function() {element.removeChild(t)})
assert_array_equals(context.getElementsByTagName("st"), [t])
assert_array_equals(context.getElementsByTagName("ST"), [])
}, "Element in non-HTML namespace, no prefix, lowercase name")
test(function() {
var t = element.appendChild(document.createElementNS("test", "ST"))
this.add_cleanup(function() {element.removeChild(t)})
assert_array_equals(context.getElementsByTagName("ST"), [t])
assert_array_equals(context.getElementsByTagName("st"), [])
}, "Element in non-HTML namespace, no prefix, uppercase name")
test(function() {
var t = element.appendChild(document.createElementNS("test", "te:st"))
this.add_cleanup(function() {element.removeChild(t)})
assert_array_equals(context.getElementsByTagName("st"), [])
assert_array_equals(context.getElementsByTagName("ST"), [])
assert_array_equals(context.getElementsByTagName("te:st"), [t])
assert_array_equals(context.getElementsByTagName("te:ST"), [])
}, "Element in non-HTML namespace, prefix, lowercase name")
test(function() {
var t = element.appendChild(document.createElementNS("test", "te:ST"))
this.add_cleanup(function() {element.removeChild(t)})
assert_array_equals(context.getElementsByTagName("st"), [])
assert_array_equals(context.getElementsByTagName("ST"), [])
assert_array_equals(context.getElementsByTagName("te:st"), [])
assert_array_equals(context.getElementsByTagName("te:ST"), [t])
}, "Element in non-HTML namespace, prefix, uppercase name")
test(function() {
var t = element.appendChild(document.createElement("aÇ"))
this.add_cleanup(function() {element.removeChild(t)})
assert_equals(t.localName, "aÇ")
assert_array_equals(context.getElementsByTagName("AÇ"), [t], "All uppercase input")
assert_array_equals(context.getElementsByTagName("aÇ"), [t], "Ascii lowercase input")
assert_array_equals(context.getElementsByTagName("aç"), [], "All lowercase input")
}, "Element in HTML namespace, no prefix, non-ascii characters in name")
test(function() {
var t = element.appendChild(document.createElementNS("test", "AÇ"))
this.add_cleanup(function() {element.removeChild(t)})
assert_array_equals(context.getElementsByTagName("AÇ"), [t])
assert_array_equals(context.getElementsByTagName("aÇ"), [])
assert_array_equals(context.getElementsByTagName("aç"), [])
}, "Element in non-HTML namespace, non-ascii characters in name")
test(function() {
var t = element.appendChild(document.createElementNS("http://www.w3.org/1999/xhtml", "test:aÇ"))
this.add_cleanup(function() {element.removeChild(t)})
assert_array_equals(context.getElementsByTagName("TEST:AÇ"), [t], "All uppercase input")
assert_array_equals(context.getElementsByTagName("test:aÇ"), [t], "Ascii lowercase input")
assert_array_equals(context.getElementsByTagName("test:aç"), [], "All lowercase input")
}, "Element in HTML namespace, prefix, non-ascii characters in name")
test(function() {
var t = element.appendChild(document.createElementNS("test", "TEST:AÇ"))
this.add_cleanup(function() {element.removeChild(t)})
assert_array_equals(context.getElementsByTagName("TEST:AÇ"), [t], "All uppercase input")
assert_array_equals(context.getElementsByTagName("test:aÇ"), [], "Ascii lowercase input")
assert_array_equals(context.getElementsByTagName("test:aç"), [], "All lowercase input")
}, "Element in non-HTML namespace, prefix, non-ascii characters in name")
test(function() {
var actual = context.getElementsByTagName("*");
var expected = [];
var get_elements = function(node) {
for (var i = 0; i < node.childNodes.length; i++) {
var child = node.childNodes[i];
if (child.nodeType === child.ELEMENT_NODE) {
expected.push(child);
get_elements(child);
}
}
}
get_elements(context);
assert_array_equals(actual, expected);
}, "getElementsByTagName('*')")
test(function() {
var t1 = element.appendChild(document.createElement("abc"));
this.add_cleanup(function() {element.removeChild(t1)});
var l = context.getElementsByTagName("abc");
assert_true(l instanceof HTMLCollection);
assert_equals(l.length, 1);
var t2 = element.appendChild(document.createElement("abc"));
assert_equals(l.length, 2);
element.removeChild(t2);
assert_equals(l.length, 1);
}, "getElementsByTagName() should be a live collection");
}

View File

@@ -1,50 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title>Document.adoptNode</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-adoptnode">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<!--creates an element with local name "x<": --><x<>x</x<>
<script>
test(function() {
var y = document.getElementsByTagName("x<")[0]
var child = y.firstChild
assert_equals(y.parentNode, document.body)
assert_equals(y.ownerDocument, document)
assert_equals(document.adoptNode(y), y)
assert_equals(y.parentNode, null)
assert_equals(y.firstChild, child)
assert_equals(y.ownerDocument, document)
assert_equals(child.ownerDocument, document)
var doc = document.implementation.createDocument(null, null, null)
assert_equals(doc.adoptNode(y), y)
assert_equals(y.parentNode, null)
assert_equals(y.firstChild, child)
assert_equals(y.ownerDocument, doc)
assert_equals(child.ownerDocument, doc)
}, "Adopting an Element called 'x<' should work.")
test(function() {
var x = document.createElement(":good:times:")
assert_equals(document.adoptNode(x), x);
var doc = document.implementation.createDocument(null, null, null)
assert_equals(doc.adoptNode(x), x)
assert_equals(x.parentNode, null)
assert_equals(x.ownerDocument, doc)
}, "Adopting an Element called ':good:times:' should work.")
test(function() {
var doctype = document.doctype;
assert_equals(doctype.parentNode, document)
assert_equals(doctype.ownerDocument, document)
assert_equals(document.adoptNode(doctype), doctype)
assert_equals(doctype.parentNode, null)
assert_equals(doctype.ownerDocument, document)
}, "Explicitly adopting a DocumentType should work.")
test(function() {
var doc = document.implementation.createDocument(null, null, null)
assert_throws_dom("NOT_SUPPORTED_ERR", function() { document.adoptNode(doc) })
}, "Adopting a Document should throw.")
</script>

View File

@@ -1,55 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title>Document.createAttribute</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=attributes.js></script>
<script src=productions.js></script>
<div id=log>
<script>
var xml_document;
setup(function() {
xml_document = document.implementation.createDocument(null, null, null);
});
invalid_names.forEach(function(name) {
test(function() {
assert_throws_dom("INVALID_CHARACTER_ERR", function() {
document.createAttribute(name, "test");
});
}, "HTML document.createAttribute(" + format_value(name) + ") should throw");
test(function() {
assert_throws_dom("INVALID_CHARACTER_ERR", function() {
xml_document.createAttribute(name, "test");
});
}, "XML document.createAttribute(" + format_value(name) + ") should throw");
});
valid_names.forEach(name => {
test(() => {
let attr = document.createAttribute(name);
attr_is(attr, "", name.toLowerCase(), null, null, name.toLowerCase());
}, `HTML document.createAttribute(${format_value(name)})`);
test(() => {
let attr = xml_document.createAttribute(name);
attr_is(attr, "", name, null, null, name);
}, `XML document.createAttribute(${format_value(name)})`);
});
var tests = ["title", "TITLE", null, undefined];
tests.forEach(function(name) {
test(function() {
var attribute = document.createAttribute(name);
attr_is(attribute, "", String(name).toLowerCase(), null, null, String(name).toLowerCase());
assert_equals(attribute.ownerElement, null);
}, "HTML document.createAttribute(" + format_value(name) + ")");
test(function() {
var attribute = xml_document.createAttribute(name);
attr_is(attribute, "", String(name), null, null, String(name));
assert_equals(attribute.ownerElement, null);
}, "XML document.createAttribute(" + format_value(name) + ")");
});
</script>

View File

@@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<title>document.createCDATASection</title>
<link rel="help" href="https://dom.spec.whatwg.org/#dom-document-createcdatasection"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="Document-createComment-createTextNode.js"></script>
</head>
<body>
<script>
"use strict";
test_create("createCDATASection", CDATASection, 4, "#cdata-section");
test(() => {
assert_throws_dom("InvalidCharacterError", () => document.createCDATASection(" ]" + "]> "));
}, "Creating a CDATA section containing the string \"]" + "]>\" must throw");
</script>
</body>
</html>

View File

@@ -1,16 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>document.createCDATASection must throw in HTML documents</title>
<link rel="help" href="https://dom.spec.whatwg.org/#dom-document-createcdatasection">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
"use strict";
setup({ single_test: true });
assert_throws_dom("NotSupportedError", () => document.createCDATASection("foo"));
done();
</script>

View File

@@ -1,22 +0,0 @@
function test_create(method, iface, nodeType, nodeName) {
["\u000b", "a -- b", "a-", "-b", null, undefined].forEach(function(value) {
test(function() {
var c = document[method](value);
var expected = String(value);
assert_true(c instanceof iface);
assert_true(c instanceof CharacterData);
assert_true(c instanceof Node);
assert_equals(c.ownerDocument, document);
assert_equals(c.data, expected, "data");
assert_equals(c.nodeValue, expected, "nodeValue");
assert_equals(c.textContent, expected, "textContent");
assert_equals(c.length, expected.length);
assert_equals(c.nodeType, nodeType);
assert_equals(c.nodeName, nodeName);
assert_equals(c.hasChildNodes(), false);
assert_equals(c.childNodes.length, 0);
assert_equals(c.firstChild, null);
assert_equals(c.lastChild, null);
}, method + "(" + format_value(value) + ")");
});
}

View File

@@ -1,21 +0,0 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Document.createComment</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-createcomment">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-ownerdocument">
<link rel=help href="https://dom.spec.whatwg.org/#dom-characterdata-data">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-nodevalue">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-textcontent">
<link rel=help href="https://dom.spec.whatwg.org/#dom-characterdata-length">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-nodetype">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-haschildnodes">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-childnodes">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-firstchild">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-lastchild">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="Document-createComment-createTextNode.js"></script>
<div id="log"></div>
<script>
test_create("createComment", Comment, 8, "#comment");
</script>

View File

@@ -1,158 +0,0 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Document.createElement</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-createelement">
<link rel=help href="https://dom.spec.whatwg.org/#dom-element-localname">
<link rel=help href="https://dom.spec.whatwg.org/#dom-element-tagname">
<link rel=help href="https://dom.spec.whatwg.org/#dom-element-prefix">
<link rel=help href="https://dom.spec.whatwg.org/#dom-element-namespaceuri">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<iframe src="/common/dummy.xml"></iframe>
<iframe src="/common/dummy.xhtml"></iframe>
<script>
function toASCIIUppercase(str) {
var diff = "a".charCodeAt(0) - "A".charCodeAt(0);
var res = "";
for (var i = 0; i < str.length; ++i) {
if ("a" <= str[i] && str[i] <= "z") {
res += String.fromCharCode(str.charCodeAt(i) - diff);
} else {
res += str[i];
}
}
return res;
}
function toASCIILowercase(str) {
var diff = "a".charCodeAt(0) - "A".charCodeAt(0);
var res = "";
for (var i = 0; i < str.length; ++i) {
if ("A" <= str[i] && str[i] <= "Z") {
res += String.fromCharCode(str.charCodeAt(i) + diff);
} else {
res += str[i];
}
}
return res;
}
var HTMLNS = "http://www.w3.org/1999/xhtml",
valid = [
undefined,
null,
"foo",
"f1oo",
"foo1",
"f\u0BC6",
"foo\u0BC6",
":",
":foo",
"f:oo",
"foo:",
"f:o:o",
"f::oo",
"f::oo:",
"foo:0",
"foo:_",
// combining char after :, invalid QName but valid Name
"foo:\u0BC6",
"foo:foo\u0BC6",
"foo\u0BC6:foo",
"xml",
"xmlns",
"xmlfoo",
"xml:foo",
"xmlns:foo",
"xmlfoo:bar",
"svg",
"math",
"FOO",
// Test that non-ASCII chars don't get uppercased/lowercased
"mar\u212a",
"\u0130nput",
"\u0131nput",
],
invalid = [
"",
"1foo",
"1:foo",
"fo o",
"\u0300foo",
"}foo",
"f}oo",
"foo}",
"\ufffffoo",
"f\uffffoo",
"foo\uffff",
"<foo",
"foo>",
"<foo>",
"f<oo",
"-foo",
".foo",
"\u0300",
]
var xmlIframe = document.querySelector('[src="/common/dummy.xml"]');
var xhtmlIframe = document.querySelector('[src="/common/dummy.xhtml"]');
function getWin(desc) {
if (desc == "HTML document") {
return window;
}
if (desc == "XML document") {
assert_equals(xmlIframe.contentDocument.documentElement.textContent,
"Dummy XML document", "XML document didn't load");
return xmlIframe.contentWindow;
}
if (desc == "XHTML document") {
assert_equals(xhtmlIframe.contentDocument.documentElement.textContent,
"Dummy XHTML document", "XHTML document didn't load");
return xhtmlIframe.contentWindow;
}
}
valid.forEach(function(t) {
["HTML document", "XML document", "XHTML document"].forEach(function(desc) {
async_test(function(testObj) {
window.addEventListener("load", function() {
testObj.step(function() {
var win = getWin(desc);
var doc = win.document;
var elt = doc.createElement(t)
assert_true(elt instanceof win.Element, "instanceof Element")
assert_true(elt instanceof win.Node, "instanceof Node")
assert_equals(elt.localName,
desc == "HTML document" ? toASCIILowercase(String(t))
: String(t),
"localName")
assert_equals(elt.tagName,
desc == "HTML document" ? toASCIIUppercase(String(t))
: String(t),
"tagName")
assert_equals(elt.prefix, null, "prefix")
assert_equals(elt.namespaceURI,
desc == "XML document" ? null : HTMLNS, "namespaceURI")
});
testObj.done();
});
}, "createElement(" + format_value(t) + ") in " + desc);
});
});
invalid.forEach(function(arg) {
["HTML document", "XML document", "XHTML document"].forEach(function(desc) {
async_test(function(testObj) {
window.addEventListener("load", function() {
testObj.step(function() {
let win = getWin(desc);
let doc = win.document;
assert_throws_dom("InvalidCharacterError", win.DOMException,
function() { doc.createElement(arg) })
});
testObj.done();
});
}, "createElement(" + format_value(arg) + ") in " + desc);
});
});
</script>

View File

@@ -1,224 +0,0 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Document.createElementNS</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-createelementns">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="Document-createElementNS.js"></script>
<div id="log"></div>
<iframe src="/common/dummy.xml"></iframe>
<iframe src="/common/dummy.xhtml"></iframe>
<script>
var tests = createElementNS_tests.concat([
/* Arrays with three elements:
* the namespace argument
* the qualifiedName argument
* the expected exception, or null if none
*/
["", "", "INVALID_CHARACTER_ERR"],
[null, "", "INVALID_CHARACTER_ERR"],
[undefined, "", "INVALID_CHARACTER_ERR"],
["http://example.com/", null, null],
["http://example.com/", "", "INVALID_CHARACTER_ERR"],
["/", null, null],
["/", "", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/XML/1998/namespace", null, null],
["http://www.w3.org/XML/1998/namespace", "", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/2000/xmlns/", null, "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", "", "INVALID_CHARACTER_ERR"],
["foo:", null, null],
["foo:", "", "INVALID_CHARACTER_ERR"],
])
var xmlIframe = document.querySelector('[src="/common/dummy.xml"]');
var xhtmlIframe = document.querySelector('[src="/common/dummy.xhtml"]');
function runTest(t, i, desc) {
async_test(function(testObj) {
window.addEventListener("load", function() {
testObj.step(function() {
var doc;
if (desc == "HTML document") {
doc = document;
} else if (desc == "XML document") {
doc = xmlIframe.contentDocument;
// Make sure we're testing the right document
assert_equals(doc.documentElement.textContent, "Dummy XML document");
} else if (desc == "XHTML document") {
doc = xhtmlIframe.contentDocument;
assert_equals(doc.documentElement.textContent, "Dummy XHTML document");
}
var namespace = t[0], qualifiedName = t[1], expected = t[2]
if (expected != null) {
assert_throws_dom(expected, doc.defaultView.DOMException, function() {doc.createElementNS(namespace, qualifiedName) });
} else {
var element = doc.createElementNS(namespace, qualifiedName)
assert_not_equals(element, null)
assert_equals(element.nodeType, Node.ELEMENT_NODE)
assert_equals(element.nodeType, element.ELEMENT_NODE)
assert_equals(element.nodeValue, null)
assert_equals(element.ownerDocument, doc)
var qualified = String(qualifiedName), names = []
if (qualified.indexOf(":") >= 0) {
names = qualified.split(":", 2)
} else {
names = [null, qualified]
}
assert_equals(element.prefix, names[0])
assert_equals(element.localName, names[1])
assert_equals(element.tagName, qualified)
assert_equals(element.nodeName, qualified)
assert_equals(element.namespaceURI,
namespace === undefined || namespace === "" ? null
: namespace)
}
});
testObj.done();
});
}, "createElementNS test in " + desc + ": " + t.map(format_value))
}
tests.forEach(function(t, i) {
runTest(t, i, "HTML document")
runTest(t, i, "XML document")
runTest(t, i, "XHTML document")
})
test(function() {
var HTMLNS = "http://www.w3.org/1999/xhtml";
var element = document.createElementNS(HTMLNS, "span");
assert_equals(element.namespaceURI, HTMLNS);
assert_equals(element.prefix, null);
assert_equals(element.localName, "span");
assert_equals(element.tagName, "SPAN");
assert_true(element instanceof Node, "Should be a Node");
assert_true(element instanceof Element, "Should be an Element");
assert_true(element instanceof HTMLElement, "Should be an HTMLElement");
assert_true(element instanceof HTMLSpanElement, "Should be an HTMLSpanElement");
}, "Lower-case HTML element without a prefix");
test(function() {
var HTMLNS = "http://www.w3.org/1999/xhtml";
var element = document.createElementNS(HTMLNS, "html:span");
assert_equals(element.namespaceURI, HTMLNS);
assert_equals(element.prefix, "html");
assert_equals(element.localName, "span");
assert_equals(element.tagName, "HTML:SPAN");
assert_true(element instanceof Node, "Should be a Node");
assert_true(element instanceof Element, "Should be an Element");
assert_true(element instanceof HTMLElement, "Should be an HTMLElement");
assert_true(element instanceof HTMLSpanElement, "Should be an HTMLSpanElement");
}, "Lower-case HTML element with a prefix");
test(function() {
var element = document.createElementNS("test", "span");
assert_equals(element.namespaceURI, "test");
assert_equals(element.prefix, null);
assert_equals(element.localName, "span");
assert_equals(element.tagName, "span");
assert_true(element instanceof Node, "Should be a Node");
assert_true(element instanceof Element, "Should be an Element");
assert_false(element instanceof HTMLElement, "Should not be an HTMLElement");
assert_false(element instanceof HTMLSpanElement, "Should not be an HTMLSpanElement");
}, "Lower-case non-HTML element without a prefix");
test(function() {
var element = document.createElementNS("test", "html:span");
assert_equals(element.namespaceURI, "test");
assert_equals(element.prefix, "html");
assert_equals(element.localName, "span");
assert_equals(element.tagName, "html:span");
assert_true(element instanceof Node, "Should be a Node");
assert_true(element instanceof Element, "Should be an Element");
assert_false(element instanceof HTMLElement, "Should not be an HTMLElement");
assert_false(element instanceof HTMLSpanElement, "Should not be an HTMLSpanElement");
}, "Lower-case non-HTML element with a prefix");
test(function() {
var HTMLNS = "http://www.w3.org/1999/xhtml";
var element = document.createElementNS(HTMLNS, "SPAN");
assert_equals(element.namespaceURI, HTMLNS);
assert_equals(element.prefix, null);
assert_equals(element.localName, "SPAN");
assert_equals(element.tagName, "SPAN");
assert_true(element instanceof Node, "Should be a Node");
assert_true(element instanceof Element, "Should be an Element");
assert_true(element instanceof HTMLElement, "Should be an HTMLElement");
assert_true(element instanceof HTMLUnknownElement, "Should be an HTMLUnknownElement");
assert_false(element instanceof HTMLSpanElement, "Should not be an HTMLSpanElement");
}, "Upper-case HTML element without a prefix");
test(function() {
var HTMLNS = "http://www.w3.org/1999/xhtml";
var element = document.createElementNS(HTMLNS, "html:SPAN");
assert_equals(element.namespaceURI, HTMLNS);
assert_equals(element.prefix, "html");
assert_equals(element.localName, "SPAN");
assert_equals(element.tagName, "HTML:SPAN");
assert_true(element instanceof Node, "Should be a Node");
assert_true(element instanceof Element, "Should be an Element");
assert_true(element instanceof HTMLElement, "Should be an HTMLElement");
assert_false(element instanceof HTMLSpanElement, "Should not be an HTMLSpanElement");
}, "Upper-case HTML element with a prefix");
test(function() {
var element = document.createElementNS("test", "SPAN");
assert_equals(element.namespaceURI, "test");
assert_equals(element.prefix, null);
assert_equals(element.localName, "SPAN");
assert_equals(element.tagName, "SPAN");
assert_true(element instanceof Node, "Should be a Node");
assert_true(element instanceof Element, "Should be an Element");
assert_false(element instanceof HTMLElement, "Should not be an HTMLElement");
assert_false(element instanceof HTMLSpanElement, "Should not be an HTMLSpanElement");
}, "Upper-case non-HTML element without a prefix");
test(function() {
var element = document.createElementNS("test", "html:SPAN");
assert_equals(element.namespaceURI, "test");
assert_equals(element.prefix, "html");
assert_equals(element.localName, "SPAN");
assert_equals(element.tagName, "html:SPAN");
assert_true(element instanceof Node, "Should be a Node");
assert_true(element instanceof Element, "Should be an Element");
assert_false(element instanceof HTMLElement, "Should not be an HTMLElement");
assert_false(element instanceof HTMLSpanElement, "Should not be an HTMLSpanElement");
}, "Upper-case non-HTML element with a prefix");
test(function() {
var element = document.createElementNS(null, "span");
assert_equals(element.namespaceURI, null);
assert_equals(element.prefix, null);
assert_equals(element.localName, "span");
assert_equals(element.tagName, "span");
assert_true(element instanceof Node, "Should be a Node");
assert_true(element instanceof Element, "Should be an Element");
assert_false(element instanceof HTMLElement, "Should not be an HTMLElement");
assert_false(element instanceof HTMLSpanElement, "Should not be an HTMLSpanElement");
}, "null namespace");
test(function() {
var element = document.createElementNS(undefined, "span");
assert_equals(element.namespaceURI, null);
assert_equals(element.prefix, null);
assert_equals(element.localName, "span");
assert_equals(element.tagName, "span");
assert_true(element instanceof Node, "Should be a Node");
assert_true(element instanceof Element, "Should be an Element");
assert_false(element instanceof HTMLElement, "Should not be an HTMLElement");
assert_false(element instanceof HTMLSpanElement, "Should not be an HTMLSpanElement");
}, "undefined namespace");
test(function() {
var element = document.createElementNS("", "span");
assert_equals(element.namespaceURI, null);
assert_equals(element.prefix, null);
assert_equals(element.localName, "span");
assert_equals(element.tagName, "span");
assert_true(element instanceof Node, "Should be a Node");
assert_true(element instanceof Element, "Should be an Element");
assert_false(element instanceof HTMLElement, "Should not be an HTMLElement");
assert_false(element instanceof HTMLSpanElement, "Should not be an HTMLSpanElement");
}, "empty string namespace");
</script>

View File

@@ -1,189 +0,0 @@
var createElementNS_tests = [
/* Arrays with three elements:
* the namespace argument
* the qualifiedName argument
* the expected exception, or null if none
*/
[null, null, null],
[null, undefined, null],
[null, "foo", null],
[null, "1foo", "INVALID_CHARACTER_ERR"],
[null, "f1oo", null],
[null, "foo1", null],
[null, "\u0BC6foo", null],
[null, "\u037Efoo", "INVALID_CHARACTER_ERR"],
[null, "}foo", "INVALID_CHARACTER_ERR"],
[null, "f}oo", "INVALID_CHARACTER_ERR"],
[null, "foo}", "INVALID_CHARACTER_ERR"],
[null, "\uFFFFfoo", "INVALID_CHARACTER_ERR"],
[null, "f\uFFFFoo", "INVALID_CHARACTER_ERR"],
[null, "foo\uFFFF", "INVALID_CHARACTER_ERR"],
[null, "<foo", "INVALID_CHARACTER_ERR"],
[null, "foo>", "INVALID_CHARACTER_ERR"],
[null, "<foo>", "INVALID_CHARACTER_ERR"],
[null, "f<oo", "INVALID_CHARACTER_ERR"],
[null, "^^", "INVALID_CHARACTER_ERR"],
[null, "fo o", "INVALID_CHARACTER_ERR"],
[null, "-foo", "INVALID_CHARACTER_ERR"],
[null, ".foo", "INVALID_CHARACTER_ERR"],
[null, ":foo", "INVALID_CHARACTER_ERR"],
[null, "f:oo", "NAMESPACE_ERR"],
[null, "foo:", "INVALID_CHARACTER_ERR"],
[null, "f:o:o", "INVALID_CHARACTER_ERR"],
[null, ":", "INVALID_CHARACTER_ERR"],
[null, "xml", null],
[null, "xmlns", "NAMESPACE_ERR"],
[null, "xmlfoo", null],
[null, "xml:foo", "NAMESPACE_ERR"],
[null, "xmlns:foo", "NAMESPACE_ERR"],
[null, "xmlfoo:bar", "NAMESPACE_ERR"],
[null, "null:xml", "NAMESPACE_ERR"],
["", null, null],
["", ":foo", "INVALID_CHARACTER_ERR"],
["", "f:oo", "NAMESPACE_ERR"],
["", "foo:", "INVALID_CHARACTER_ERR"],
[undefined, null, null],
[undefined, undefined, null],
[undefined, "foo", null],
[undefined, "1foo", "INVALID_CHARACTER_ERR"],
[undefined, "f1oo", null],
[undefined, "foo1", null],
[undefined, ":foo", "INVALID_CHARACTER_ERR"],
[undefined, "f:oo", "NAMESPACE_ERR"],
[undefined, "foo:", "INVALID_CHARACTER_ERR"],
[undefined, "f::oo", "INVALID_CHARACTER_ERR"],
[undefined, "xml", null],
[undefined, "xmlns", "NAMESPACE_ERR"],
[undefined, "xmlfoo", null],
[undefined, "xml:foo", "NAMESPACE_ERR"],
[undefined, "xmlns:foo", "NAMESPACE_ERR"],
[undefined, "xmlfoo:bar", "NAMESPACE_ERR"],
["http://example.com/", "foo", null],
["http://example.com/", "1foo", "INVALID_CHARACTER_ERR"],
["http://example.com/", "<foo>", "INVALID_CHARACTER_ERR"],
["http://example.com/", "fo<o", "INVALID_CHARACTER_ERR"],
["http://example.com/", "-foo", "INVALID_CHARACTER_ERR"],
["http://example.com/", ".foo", "INVALID_CHARACTER_ERR"],
["http://example.com/", "f1oo", null],
["http://example.com/", "foo1", null],
["http://example.com/", ":foo", "INVALID_CHARACTER_ERR"],
["http://example.com/", "f:oo", null],
["http://example.com/", "f:o:o", "INVALID_CHARACTER_ERR"],
["http://example.com/", "foo:", "INVALID_CHARACTER_ERR"],
["http://example.com/", "f::oo", "INVALID_CHARACTER_ERR"],
["http://example.com/", "a:0", "INVALID_CHARACTER_ERR"],
["http://example.com/", "0:a", "INVALID_CHARACTER_ERR"],
["http://example.com/", "a:_", null],
["http://example.com/", "a:\u0BC6", null],
["http://example.com/", "a:\u037E", "INVALID_CHARACTER_ERR"],
["http://example.com/", "a:\u0300", "INVALID_CHARACTER_ERR"],
["http://example.com/", "\u0BC6:a", null],
["http://example.com/", "\u0300:a", "INVALID_CHARACTER_ERR"],
["http://example.com/", "\u037E:a", "INVALID_CHARACTER_ERR"],
["http://example.com/", "a:a\u0BC6", null],
["http://example.com/", "a\u0BC6:a", null],
["http://example.com/", "xml:test", "NAMESPACE_ERR"],
["http://example.com/", "xmlns:test", "NAMESPACE_ERR"],
["http://example.com/", "test:xmlns", null],
["http://example.com/", "xmlns", "NAMESPACE_ERR"],
["http://example.com/", "_:_", null],
["http://example.com/", "_:h0", null],
["http://example.com/", "_:test", null],
["http://example.com/", "l_:_", null],
["http://example.com/", "ns:_0", null],
["http://example.com/", "ns:a0", null],
["http://example.com/", "ns0:test", null],
["http://example.com/", "a.b:c", null],
["http://example.com/", "a-b:c", null],
["http://example.com/", "xml", null],
["http://example.com/", "XMLNS", null],
["http://example.com/", "xmlfoo", null],
["http://example.com/", "xml:foo", "NAMESPACE_ERR"],
["http://example.com/", "XML:foo", null],
["http://example.com/", "xmlns:foo", "NAMESPACE_ERR"],
["http://example.com/", "XMLNS:foo", null],
["http://example.com/", "xmlfoo:bar", null],
["http://example.com/", "prefix::local", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:{", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:}", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:~", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:'", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:!", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:@", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:#", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:$", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:%", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:^", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:&", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:*", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:(", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:)", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:+", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:=", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:[", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:]", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:\\", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:/", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:;", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:`", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:<", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:>", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:,", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:a ", "INVALID_CHARACTER_ERR"],
["http://example.com/", "namespaceURI:\"", "INVALID_CHARACTER_ERR"],
["/", "foo", null],
["/", "1foo", "INVALID_CHARACTER_ERR"],
["/", "f1oo", null],
["/", "foo1", null],
["/", ":foo", "INVALID_CHARACTER_ERR"],
["/", "f:oo", null],
["/", "foo:", "INVALID_CHARACTER_ERR"],
["/", "xml", null],
["/", "xmlns", "NAMESPACE_ERR"],
["/", "xmlfoo", null],
["/", "xml:foo", "NAMESPACE_ERR"],
["/", "xmlns:foo", "NAMESPACE_ERR"],
["/", "xmlfoo:bar", null],
["http://www.w3.org/XML/1998/namespace", "foo", null],
["http://www.w3.org/XML/1998/namespace", "1foo", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/XML/1998/namespace", "f1oo", null],
["http://www.w3.org/XML/1998/namespace", "foo1", null],
["http://www.w3.org/XML/1998/namespace", ":foo", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/XML/1998/namespace", "f:oo", null],
["http://www.w3.org/XML/1998/namespace", "foo:", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/XML/1998/namespace", "xml", null],
["http://www.w3.org/XML/1998/namespace", "xmlns", "NAMESPACE_ERR"],
["http://www.w3.org/XML/1998/namespace", "xmlfoo", null],
["http://www.w3.org/XML/1998/namespace", "xml:foo", null],
["http://www.w3.org/XML/1998/namespace", "xmlns:foo", "NAMESPACE_ERR"],
["http://www.w3.org/XML/1998/namespace", "xmlfoo:bar", null],
["http://www.w3.org/XML/1998/namespaces", "xml:foo", "NAMESPACE_ERR"],
["http://www.w3.org/xml/1998/namespace", "xml:foo", "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", "foo", "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", "1foo", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/2000/xmlns/", "f1oo", "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", "foo1", "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", ":foo", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/2000/xmlns/", "f:oo", "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", "foo:", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/2000/xmlns/", "xml", "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", "xmlns", null],
["http://www.w3.org/2000/xmlns/", "xmlfoo", "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", "xml:foo", "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", "xmlns:foo", null],
["http://www.w3.org/2000/xmlns/", "xmlfoo:bar", "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", "foo:xmlns", "NAMESPACE_ERR"],
["foo:", "foo", null],
["foo:", "1foo", "INVALID_CHARACTER_ERR"],
["foo:", "f1oo", null],
["foo:", "foo1", null],
["foo:", ":foo", "INVALID_CHARACTER_ERR"],
["foo:", "f:oo", null],
["foo:", "foo:", "INVALID_CHARACTER_ERR"],
["foo:", "xml", null],
["foo:", "xmlns", "NAMESPACE_ERR"],
["foo:", "xmlfoo", null],
["foo:", "xml:foo", "NAMESPACE_ERR"],
["foo:", "xmlns:foo", "NAMESPACE_ERR"],
["foo:", "xmlfoo:bar", null],
]

View File

@@ -1,15 +0,0 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Document.createProcessingInstruction in XML documents</title>
<link rel="help" href="https://dom.spec.whatwg.org/#dom-document-createprocessinginstruction"/>
<link rel="help" href="https://dom.spec.whatwg.org/#dom-processinginstruction-target"/>
<link rel="help" href="https://dom.spec.whatwg.org/#dom-characterdata-data"/>
<link rel="help" href="https://dom.spec.whatwg.org/#dom-node-ownerdocument"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"/>
<script src="Document-createProcessingInstruction.js"/>
</body>
</html>

View File

@@ -1,11 +0,0 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Document.createProcessingInstruction in HTML documents</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-createprocessinginstruction">
<link rel=help href="https://dom.spec.whatwg.org/#dom-processinginstruction-target">
<link rel=help href="https://dom.spec.whatwg.org/#dom-characterdata-data">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-ownerdocument">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src="Document-createProcessingInstruction.js"></script>

View File

@@ -1,39 +0,0 @@
test(function() {
var invalid = [
["A", "?>"],
["\u00B7A", "x"],
["\u00D7A", "x"],
["A\u00D7", "x"],
["\\A", "x"],
["\f", "x"],
[0, "x"],
["0", "x"]
],
valid = [
["xml:fail", "x"],
["A\u00B7A", "x"],
["a0", "x"]
]
for (var i = 0, il = invalid.length; i < il; i++) {
test(function() {
assert_throws_dom("INVALID_CHARACTER_ERR", function() {
document.createProcessingInstruction(invalid[i][0], invalid[i][1])
})
}, "Should throw an INVALID_CHARACTER_ERR for target " +
format_value(invalid[i][0]) + " and data " +
format_value(invalid[i][1]) + ".")
}
for (var i = 0, il = valid.length; i < il; ++i) {
test(function() {
var pi = document.createProcessingInstruction(valid[i][0], valid[i][1]);
assert_equals(pi.target, valid[i][0]);
assert_equals(pi.data, valid[i][1]);
assert_equals(pi.ownerDocument, document);
assert_true(pi instanceof ProcessingInstruction);
assert_true(pi instanceof Node);
}, "Should get a ProcessingInstruction for target " +
format_value(valid[i][0]) + " and data " +
format_value(valid[i][1]) + ".")
}
})

View File

@@ -1,21 +0,0 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Document.createTextNode</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-createtextnode">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-ownerdocument">
<link rel=help href="https://dom.spec.whatwg.org/#dom-characterdata-data">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-nodevalue">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-textcontent">
<link rel=help href="https://dom.spec.whatwg.org/#dom-characterdata-length">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-nodetype">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-haschildnodes">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-childnodes">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-firstchild">
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-lastchild">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="Document-createComment-createTextNode.js"></script>
<div id="log"></div>
<script>
test_create("createTextNode", Text, 3, "#text");
</script>

View File

@@ -1,21 +0,0 @@
<!-- comment -->
<!doctype html>
<meta charset=utf-8>
<title>Document.doctype</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-doctype">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
test(function() {
assert_true(document.doctype instanceof DocumentType,
"Doctype should be a DocumentType");
assert_equals(document.doctype, document.childNodes[1]);
}, "Window document with doctype");
test(function() {
var newdoc = new Document();
newdoc.appendChild(newdoc.createElement("html"));
assert_equals(newdoc.doctype, null);
}, "new Document()");
</script>

View File

@@ -1,26 +0,0 @@
<!DOCTYPE html>
<title>Document.getElementsByClassName</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
test(function() {
var a = document.createElement("a"),
b = document.createElement("b");
a.className = "foo";
this.add_cleanup(function() {document.body.removeChild(a);});
document.body.appendChild(a);
var l = document.getElementsByClassName("foo");
assert_true(l instanceof HTMLCollection);
assert_equals(l.length, 1);
b.className = "foo";
document.body.appendChild(b);
assert_equals(l.length, 2);
document.body.removeChild(b);
assert_equals(l.length, 1);
}, "getElementsByClassName() should be a live collection");
</script>

View File

@@ -1,11 +0,0 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Document.getElementsByTagName</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-getelementsbytagname">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="Document-Element-getElementsByTagName.js"></script>
<div id="log"></div>
<script>
test_getElementsByTagName(document, document.body);
</script>

View File

@@ -1,67 +0,0 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Document.importNode</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-importnode">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
test(function() {
var doc = document.implementation.createHTMLDocument("Title");
var div = doc.body.appendChild(doc.createElement("div"));
div.appendChild(doc.createElement("span"));
assert_equals(div.ownerDocument, doc);
assert_equals(div.firstChild.ownerDocument, doc);
var newDiv = document.importNode(div);
assert_equals(div.ownerDocument, doc);
assert_equals(div.firstChild.ownerDocument, doc);
assert_equals(newDiv.ownerDocument, document);
assert_equals(newDiv.firstChild, null);
}, "No 'deep' argument.")
test(function() {
var doc = document.implementation.createHTMLDocument("Title");
var div = doc.body.appendChild(doc.createElement("div"));
div.appendChild(doc.createElement("span"));
assert_equals(div.ownerDocument, doc);
assert_equals(div.firstChild.ownerDocument, doc);
var newDiv = document.importNode(div, undefined);
assert_equals(div.ownerDocument, doc);
assert_equals(div.firstChild.ownerDocument, doc);
assert_equals(newDiv.ownerDocument, document);
assert_equals(newDiv.firstChild, null);
}, "Undefined 'deep' argument.")
test(function() {
var doc = document.implementation.createHTMLDocument("Title");
var div = doc.body.appendChild(doc.createElement("div"));
div.appendChild(doc.createElement("span"));
assert_equals(div.ownerDocument, doc);
assert_equals(div.firstChild.ownerDocument, doc);
var newDiv = document.importNode(div, true);
assert_equals(div.ownerDocument, doc);
assert_equals(div.firstChild.ownerDocument, doc);
assert_equals(newDiv.ownerDocument, document);
assert_equals(newDiv.firstChild.ownerDocument, document);
}, "True 'deep' argument.")
test(function() {
var doc = document.implementation.createHTMLDocument("Title");
var div = doc.body.appendChild(doc.createElement("div"));
div.appendChild(doc.createElement("span"));
assert_equals(div.ownerDocument, doc);
assert_equals(div.firstChild.ownerDocument, doc);
var newDiv = document.importNode(div, false);
assert_equals(div.ownerDocument, doc);
assert_equals(div.firstChild.ownerDocument, doc);
assert_equals(newDiv.ownerDocument, document);
assert_equals(newDiv.firstChild, null);
}, "False 'deep' argument.")
test(function() {
let doc = document.implementation.createHTMLDocument("Title");
doc.body.setAttributeNS("http://example.com/", "p:name", "value");
let originalAttr = doc.body.getAttributeNodeNS("http://example.com/", "name");
let imported = document.importNode(originalAttr, true);
assert_equals(imported.prefix, originalAttr.prefix);
assert_equals(imported.namespaceURI, originalAttr.namespaceURI);
assert_equals(imported.localName, originalAttr.localName);
}, "Import an Attr node with namespace/prefix correctly.");
</script>

View File

@@ -1,22 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>DocumentFragment constructor</title>
<link rel="help" href="https://dom.spec.whatwg.org/#dom-documentfragment-documentfragment">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
"use strict";
test(() => {
const fragment = new DocumentFragment();
assert_equals(fragment.ownerDocument, document);
}, "Sets the owner document to the current global object associated document");
test(() => {
const fragment = new DocumentFragment();
const text = document.createTextNode("");
fragment.appendChild(text);
assert_equals(fragment.firstChild, text);
}, "Create a valid document DocumentFragment");
</script>

View File

@@ -1,62 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>DocumentFragment.prototype.getElementById</title>
<link rel="help" href="https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid">
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<template>
<div id="bar">
<span id="foo" data-yes></span>
</div>
<div id="foo">
<span id="foo"></span>
<ul id="bar">
<li id="foo"></li>
</ul>
</div>
</template>
<script>
"use strict";
test(() => {
assert_equals(typeof DocumentFragment.prototype.getElementById, "function", "It must exist on the prototype");
assert_equals(typeof document.createDocumentFragment().getElementById, "function", "It must exist on an instance");
}, "The method must exist");
test(() => {
assert_equals(document.createDocumentFragment().getElementById("foo"), null);
assert_equals(document.createDocumentFragment().getElementById(""), null);
}, "It must return null when there are no matches");
test(() => {
const frag = document.createDocumentFragment();
frag.appendChild(document.createElement("div"));
frag.appendChild(document.createElement("span"));
frag.childNodes[0].id = "foo";
frag.childNodes[1].id = "foo";
assert_equals(frag.getElementById("foo"), frag.childNodes[0]);
}, "It must return the first element when there are matches");
test(() => {
const frag = document.createDocumentFragment();
frag.appendChild(document.createElement("div"));
frag.childNodes[0].setAttribute("id", "");
assert_equals(
frag.getElementById(""),
null,
"Even if there is an element with an empty-string ID attribute, it must not be returned"
);
}, "Empty string ID values");
test(() => {
const frag = document.querySelector("template").content;
assert_true(frag.getElementById("foo").hasAttribute("data-yes"));
}, "It must return the first element when there are matches, using a template");
</script>

View File

@@ -1,24 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>querySelectorAll should still work on DocumentFragments after they are modified</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!-- Regression test for https://github.com/jsdom/jsdom/issues/2290 -->
<script>
"use strict";
setup({ single_test: true });
const frag = document.createDocumentFragment();
frag.appendChild(document.createElement("div"));
assert_array_equals(frag.querySelectorAll("img"), [], "before modification");
frag.appendChild(document.createElement("div"));
// If the bug is present, this will throw.
assert_array_equals(frag.querySelectorAll("img"), [], "after modification");
done();
</script>

View File

@@ -1,17 +0,0 @@
<!DOCTYPE html PUBLIC "STAFF" "staffNS.dtd">
<title>DocumentType literals</title>
<link rel="help" href="https://dom.spec.whatwg.org/#dom-documenttype-name">
<link rel="help" href="https://dom.spec.whatwg.org/#dom-documenttype-publicid">
<link rel="help" href="https://dom.spec.whatwg.org/#dom-documenttype-systemid">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
test(function() {
var doctype = document.firstChild;
assert_true(doctype instanceof DocumentType)
assert_equals(doctype.name, "html")
assert_equals(doctype.publicId, 'STAFF')
assert_equals(doctype.systemId, 'staffNS.dtd')
})
</script>

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>Null test</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of firstElementChild and lastChildElement returning null</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle" font-weight="bold">Test</text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
assert_equals(parentEl.firstElementChild, null)
assert_equals(parentEl.lastElementChild, null)
})
]]></h:script>
</svg>

Before

Width:  |  Height:  |  Size: 787 B

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Null Test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of firstElementChild and lastChildElement returning null</h1>
<div id="log"></div>
<p id="parentEl" style="font-weight:bold;">Test.</p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
assert_equals(parentEl.firstElementChild, null)
assert_equals(parentEl.lastElementChild, null)
})
]]></script>
</body>
</html>

View File

@@ -1,15 +0,0 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Null test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of firstElementChild and lastChildElement returning null</h1>
<div id="log"></div>
<p id="parentEl" style="font-weight:bold;">Test.</p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl")
assert_equals(parentEl.firstElementChild, null)
assert_equals(parentEl.lastElementChild, null)
})
</script>

View File

@@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>Dynamic Adding of Elements</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of Dynamic Adding of Elements</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle">The result of this test is
<tspan id="first_element_child" font-weight="bold">unknown.</tspan></text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var newChild = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
parentEl.appendChild(newChild);
assert_equals(parentEl.childElementCount, 2)
})
]]></h:script>
</svg>

Before

Width:  |  Height:  |  Size: 913 B

View File

@@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dynamic Adding of Elements</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of Dynamic Adding of Elements</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is
<span id="first_element_child" style="font-weight:bold;">logged above.</span></p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var newChild = document.createElement("span");
parentEl.appendChild(newChild);
assert_equals(parentEl.childElementCount, 2)
})
]]></script>
</body>
</html>

View File

@@ -1,17 +0,0 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Dynamic Adding of Elements</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of Dynamic Adding of Elements</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is
<span id="first_element_child" style="font-weight:bold;">logged above.</span></p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl");
var newChild = document.createElement("span");
parentEl.appendChild(newChild);
assert_equals(parentEl.childElementCount, 2)
})
</script>

View File

@@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>Dynamic Removal of Elements</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of Dynamic Removal of Elements</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle">The result of this test is
<tspan id="first_element_child" font-weight="bold">unknown.</tspan><tspan id="last_element_child"> </tspan></text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var lec = parentEl.lastElementChild;
parentEl.removeChild(lec);
assert_equals(parentEl.childElementCount, 1)
})
]]></h:script>
</svg>

Before

Width:  |  Height:  |  Size: 907 B

View File

@@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dynamic Removal of Elements</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of Removal Adding of Elements</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is
<span id="first_element_child" style="font-weight:bold;">logged above.</span><span id="last_element_child"> </span></p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var lec = parentEl.lastElementChild;
parentEl.removeChild(lec);
assert_equals(parentEl.childElementCount, 1)
})
]]></script>
</body>
</html>

View File

@@ -1,17 +0,0 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Dynamic Removal of Elements</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of Dynamic Removal of Elements</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is
<span id="first_element_child" style="font-weight:bold;">unknown.</span><span id="last_element_child"> </span></p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl");
var lec = parentEl.lastElementChild;
parentEl.removeChild(lec);
assert_equals(parentEl.childElementCount, 1)
})
</script>

View File

@@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>childElementCount</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of childElementCount with No Child Element Nodes</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle" font-weight="bold">Test</text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
assert_equals(parentEl.childElementCount, 0)
})
]]></h:script>
</svg>

Before

Width:  |  Height:  |  Size: 735 B

View File

@@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>childElementCount without Child Element Nodes</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of childElementCount with No Child Element Nodes</h1>
<div id="log"></div>
<p id="parentEl" style="font-weight:bold;">Test.</p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
assert_equals(parentEl.childElementCount, 0)
})
]]></script>
</body>
</html>

View File

@@ -1,14 +0,0 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>childElementCount without Child Element Nodes</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of childElementCount with No Child Element Nodes</h1>
<div id="log"></div>
<p id="parentEl" style="font-weight:bold;">Test.</p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl")
assert_equals(parentEl.childElementCount, 0)
})
</script>

View File

@@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>childElementCount</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of childElementCount</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle">The result of <tspan id="first_element_child"><tspan>this</tspan> <tspan>test</tspan></tspan> is
<tspan id="middle_element_child" font-weight="bold">unknown.</tspan>
<tspan id="last_element_child" style="display:none;">fnord</tspan> </text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
assert_true("childElementCount" in parentEl)
assert_equals(parentEl.childElementCount, 3)
})
]]></h:script>
</svg>

Before

Width:  |  Height:  |  Size: 967 B

View File

@@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>childElementCount</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of childElementCount</h1>
<div id="log"></div>
<p id="parentEl">The result of <span id="first_element_child"><span>this</span> <span>test</span></span> is
<span id="middle_element_child" style="font-weight:bold;">unknown.</span>
<span id="last_element_child" style="display:none;">fnord</span> </p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
assert_true("childElementCount" in parentEl)
assert_equals(parentEl.childElementCount, 3)
})
]]></script>
</body>
</html>

View File

@@ -1,20 +0,0 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>childElementCount</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of childElementCount</h1>
<div id="log"></div>
<p id="parentEl">The result of <span id="first_element_child"><span>this</span> <span>test</span></span> is
<span id="middle_element_child" style="font-weight:bold;">given above.</span>
<span id="last_element_child" style="display:none;">fnord</span> </p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl")
assert_true("childElementCount" in parentEl)
assert_equals(parentEl.childElementCount, 3)
})
</script>

View File

@@ -1,58 +0,0 @@
<!DOCTYPE html>
<title>HTMLCollection edge cases</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<div id="test"><img><img id=foo><img id=foo><img name="bar"></div>
<script>
setup(function() {
// Add some non-HTML elements in there to test what happens with those.
var container = document.getElementById("test");
var child = document.createElementNS("", "img");
child.setAttribute("id", "baz");
container.appendChild(child);
child = document.createElementNS("", "img");
child.setAttribute("name", "qux");
container.appendChild(child);
});
test(function() {
var container = document.getElementById("test");
var result = container.children.item("foo");
assert_true(result instanceof Element, "Expected an Element.");
assert_false(result.hasAttribute("id"), "Expected the IDless Element.")
})
test(function() {
var container = document.getElementById("test");
var list = container.children;
var result = [];
for (var p in list) {
if (list.hasOwnProperty(p)) {
result.push(p);
}
}
assert_array_equals(result, ['0', '1', '2', '3', '4', '5']);
result = Object.getOwnPropertyNames(list);
assert_array_equals(result, ['0', '1', '2', '3', '4', '5', 'foo', 'bar', 'baz']);
// Mapping of exposed names to their indices in the list.
var exposedNames = { 'foo': 1, 'bar': 3, 'baz': 4 };
for (var exposedName in exposedNames) {
assert_true(exposedName in list);
assert_true(list.hasOwnProperty(exposedName));
assert_equals(list[exposedName], list.namedItem(exposedName));
assert_equals(list[exposedName], list.item(exposedNames[exposedName]));
assert_true(list[exposedName] instanceof Element);
}
var unexposedNames = ['qux'];
for (var unexposedName of unexposedNames) {
assert_false(unexposedName in list);
assert_false(list.hasOwnProperty(unexposedName));
assert_equals(list[unexposedName], undefined);
assert_equals(list.namedItem(unexposedName), null);
}
});
</script>

View File

@@ -1,478 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title>Test for the classList element attribute</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id="content"></div>
<script>
const SVG_NS = "http://www.w3.org/2000/svg";
const XHTML_NS = "http://www.w3.org/1999/xhtml"
const MATHML_NS = "http://www.w3.org/1998/Math/MathML";
function setClass(e, newVal) {
if (newVal === null) {
e.removeAttribute("class");
} else {
e.setAttribute("class", newVal);
}
}
function checkModification(e, funcName, args, expectedRes, before, after,
expectedException, desc) {
if (!Array.isArray(args)) {
args = [args];
}
test(function() {
var shouldThrow = typeof(expectedException) === "string";
if (shouldThrow) {
// If an exception is thrown, the class attribute shouldn't change.
after = before;
}
setClass(e, before);
var obs;
// If we have MutationObservers available, do some checks to make
// sure attribute sets are happening at sane times.
if (self.MutationObserver) {
obs = new MutationObserver(() => {});
obs.observe(e, { attributes: true });
}
if (shouldThrow) {
assert_throws_dom(expectedException, function() {
var list = e.classList;
var res = list[funcName].apply(list, args);
});
} else {
var list = e.classList;
var res = list[funcName].apply(list, args);
}
if (obs) {
var mutationRecords = obs.takeRecords();
obs.disconnect();
if (shouldThrow) {
assert_equals(mutationRecords.length, 0,
"There should have been no mutation");
} else if (funcName == "replace") {
assert_equals(mutationRecords.length == 1,
expectedRes,
"Should have a mutation exactly when replace() returns true");
} else {
// For other functions, would need to check when exactly
// mutations are supposed to happen.
}
}
if (!shouldThrow) {
assert_equals(res, expectedRes, "wrong return value");
}
var expectedAfter = after;
assert_equals(e.getAttribute("class"), expectedAfter,
"wrong class after modification");
}, "classList." + funcName + "(" + args.map(format_value).join(", ") +
") with attribute value " + format_value(before) + desc);
}
function assignToClassListStrict(e) {
"use strict";
e.classList = "foo";
e.removeAttribute("class");
}
function assignToClassList(e) {
var expect = e.classList;
e.classList = "foo";
assert_equals(e.classList, expect,
"classList should be unchanged after assignment");
e.removeAttribute("class");
}
function testClassList(e, desc) {
// assignment
test(function() {
assignToClassListStrict(e);
assignToClassList(e);
}, "Assigning to classList" + desc);
// supports
test(function() {
assert_throws_js(TypeError, function() {
e.classList.supports("a");
})
}, ".supports() must throw TypeError" + desc);
// length attribute
function checkLength(value, length) {
test(function() {
setClass(e, value);
assert_equals(e.classList.length, length);
}, "classList.length when " +
(value === null ? "removed" : "set to " + format_value(value)) + desc);
}
checkLength(null, 0);
checkLength("", 0);
checkLength(" \t \f", 0);
checkLength("a", 1);
checkLength("a A", 2);
checkLength("\r\na\t\f", 1);
checkLength("a a", 1);
checkLength("a a a a a a", 1);
checkLength("a a b b", 2);
checkLength("a A B b", 4);
checkLength("a b c c b a a b c c", 3);
checkLength(" a a b", 2);
checkLength("a\tb\nc\fd\re f", 6);
// [Stringifies]
function checkStringifier(value, expected) {
test(function() {
setClass(e, value);
assert_equals(e.classList.toString(), expected);
}, "classList.toString() when " +
(value === null ? "removed" : "set to " + format_value(value)) + desc);
}
checkStringifier(null, "");
checkStringifier("foo", "foo");
checkStringifier(" a a b", " a a b");
// item() method
function checkItems(attributeValue, expectedValues) {
function checkItemFunction(index, expected) {
assert_equals(e.classList.item(index), expected,
"classList.item(" + index + ")");
}
function checkItemArray(index, expected) {
assert_equals(e.classList[index], expected, "classList[" + index + "]");
}
test(function() {
setClass(e, attributeValue);
checkItemFunction(-1, null);
checkItemArray(-1, undefined);
var i = 0;
while (i < expectedValues.length) {
checkItemFunction(i, expectedValues[i]);
checkItemArray(i, expectedValues[i]);
i++;
}
checkItemFunction(i, null);
checkItemArray(i, undefined);
checkItemFunction(0xffffffff, null);
checkItemArray(0xffffffff, undefined);
checkItemFunction(0xfffffffe, null);
checkItemArray(0xfffffffe, undefined);
}, "classList.item() when set to " + format_value(attributeValue) + desc);
}
checkItems(null, []);
checkItems("a", ["a"]);
checkItems("aa AA aa", ["aa", "AA"]);
checkItems("a b", ["a", "b"]);
checkItems(" a a b", ["a", "b"]);
checkItems("\t\n\f\r a\t\n\f\r b\t\n\f\r ", ["a", "b"]);
// contains() method
function checkContains(attributeValue, args, expectedRes) {
if (!Array.isArray(expectedRes)) {
expectedRes = Array(args.length).fill(expectedRes);
}
setClass(e, attributeValue);
for (var i = 0; i < args.length; i++) {
test(function() {
assert_equals(e.classList.contains(args[i]), expectedRes[i],
"classList.contains(\"" + args[i] + "\")");
}, "classList.contains(" + format_value(args[i]) + ") when set to " +
format_value(attributeValue) + desc);
}
}
checkContains(null, ["a", "", " "], false);
checkContains("", ["a"], false);
checkContains("a", ["a"], true);
checkContains("a", ["aa", "b", "A", "a.", "a)",, "a'", 'a"', "a$", "a~",
"a?", "a\\"], false);
// All "ASCII whitespace" per spec, before and after
checkContains("a", ["a\t", "\ta", "a\n", "\na", "a\f", "\fa", "a\r", "\ra",
"a ", " a"], false);
checkContains("aa AA", ["aa", "AA", "aA"], [true, true, false]);
checkContains("a a a", ["a", "aa", "b"], [true, false, false]);
checkContains("a b c", ["a", "b"], true);
checkContains("null undefined", [null, undefined], true);
checkContains("\t\n\f\r a\t\n\f\r b\t\n\f\r ", ["a", "b"], true);
// add() method
function checkAdd(before, argument, after, param) {
var expectedException = undefined;
var noop = false;
if (param == "noop") {
noop = true;
} else {
expectedException = param;
}
checkModification(e, "add", argument, undefined, before, after,
expectedException, desc);
// Also check force toggle. The only difference is that it doesn't run the
// update steps for a no-op.
if (!Array.isArray(argument)) {
checkModification(e, "toggle", [argument, true], true, before,
noop ? before : after, expectedException, desc);
}
}
checkAdd(null, "", null, "SyntaxError");
checkAdd(null, ["a", ""], null, "SyntaxError");
checkAdd(null, " ", null, "InvalidCharacterError");
checkAdd(null, "\ta", null, "InvalidCharacterError");
checkAdd(null, "a\t", null, "InvalidCharacterError");
checkAdd(null, "\na", null, "InvalidCharacterError");
checkAdd(null, "a\n", null, "InvalidCharacterError");
checkAdd(null, "\fa", null, "InvalidCharacterError");
checkAdd(null, "a\f", null, "InvalidCharacterError");
checkAdd(null, "\ra", null, "InvalidCharacterError");
checkAdd(null, "a\r", null, "InvalidCharacterError");
checkAdd(null, " a", null, "InvalidCharacterError");
checkAdd(null, "a ", null, "InvalidCharacterError");
checkAdd(null, ["a", " "], null, "InvalidCharacterError");
checkAdd(null, ["a", "aa "], null, "InvalidCharacterError");
checkAdd("a", "a", "a");
checkAdd("aa", "AA", "aa AA");
checkAdd("a b c", "a", "a b c");
checkAdd("a a a b", "a", "a b", "noop");
checkAdd(null, "a", "a");
checkAdd("", "a", "a");
checkAdd(" ", "a", "a");
checkAdd(" \f", "a", "a");
checkAdd("a", "b", "a b");
checkAdd("a b c", "d", "a b c d");
checkAdd("a b c ", "d", "a b c d");
checkAdd(" a a b", "c", "a b c");
checkAdd(" a a b", "a", "a b", "noop");
checkAdd("\t\n\f\r a\t\n\f\r b\t\n\f\r ", "c", "a b c");
// multiple add
checkAdd("a b c ", ["d", "e"], "a b c d e");
checkAdd("a b c ", ["a", "a"], "a b c");
checkAdd("a b c ", ["d", "d"], "a b c d");
checkAdd("a b c a ", [], "a b c");
checkAdd(null, ["a", "b"], "a b");
checkAdd("", ["a", "b"], "a b");
checkAdd(null, null, "null");
checkAdd(null, undefined, "undefined");
// remove() method
function checkRemove(before, argument, after, param) {
var expectedException = undefined;
var noop = false;
if (param == "noop") {
noop = true;
} else {
expectedException = param;
}
checkModification(e, "remove", argument, undefined, before, after,
expectedException, desc);
// Also check force toggle. The only difference is that it doesn't run the
// update steps for a no-op.
if (!Array.isArray(argument)) {
checkModification(e, "toggle", [argument, false], false, before,
noop ? before : after, expectedException, desc);
}
}
checkRemove(null, "", null, "SyntaxError");
checkRemove(null, " ", null, "InvalidCharacterError");
checkRemove("\ta", "\ta", "\ta", "InvalidCharacterError");
checkRemove("a\t", "a\t", "a\t", "InvalidCharacterError");
checkRemove("\na", "\na", "\na", "InvalidCharacterError");
checkRemove("a\n", "a\n", "a\n", "InvalidCharacterError");
checkRemove("\fa", "\fa", "\fa", "InvalidCharacterError");
checkRemove("a\f", "a\f", "a\f", "InvalidCharacterError");
checkRemove("\ra", "\ra", "\ra", "InvalidCharacterError");
checkRemove("a\r", "a\r", "a\r", "InvalidCharacterError");
checkRemove(" a", " a", " a", "InvalidCharacterError");
checkRemove("a ", "a ", "a ", "InvalidCharacterError");
checkRemove("aa ", "aa ", null, "InvalidCharacterError");
checkRemove(null, "a", null);
checkRemove("", "a", "");
checkRemove("a b c", "d", "a b c", "noop");
checkRemove("a b c", "A", "a b c", "noop");
checkRemove(" a a a ", "a", "");
checkRemove("a b", "a", "b");
checkRemove("a b ", "a", "b");
checkRemove("a a b", "a", "b");
checkRemove("aa aa bb", "aa", "bb");
checkRemove("a a b a a c a a", "a", "b c");
checkRemove("a b c", "b", "a c");
checkRemove("aaa bbb ccc", "bbb", "aaa ccc");
checkRemove(" a b c ", "b", "a c");
checkRemove("a b b b c", "b", "a c");
checkRemove("a b c", "c", "a b");
checkRemove(" a b c ", "c", "a b");
checkRemove("a b c c c", "c", "a b");
checkRemove("a b a c a d a", "a", "b c d");
checkRemove("AA BB aa CC AA dd aa", "AA", "BB aa CC dd");
checkRemove("\ra\na\ta\f", "a", "");
checkRemove("\t\n\f\r a\t\n\f\r b\t\n\f\r ", "a", "b");
// multiple remove
checkRemove("a b c ", ["d", "e"], "a b c");
checkRemove("a b c ", ["a", "b"], "c");
checkRemove("a b c ", ["a", "c"], "b");
checkRemove("a b c ", ["a", "a"], "b c");
checkRemove("a b c ", ["d", "d"], "a b c");
checkRemove("a b c ", [], "a b c");
checkRemove(null, ["a", "b"], null);
checkRemove("", ["a", "b"], "");
checkRemove("a a", [], "a");
checkRemove("null", null, "");
checkRemove("undefined", undefined, "");
// toggle() method
function checkToggle(before, argument, expectedRes, after, expectedException) {
checkModification(e, "toggle", argument, expectedRes, before, after,
expectedException, desc);
}
checkToggle(null, "", null, null, "SyntaxError");
checkToggle(null, "aa ", null, null, "InvalidCharacterError");
checkToggle(null, "a", true, "a");
checkToggle("", "a", true, "a");
checkToggle(" ", "a", true, "a");
checkToggle(" \f", "a", true, "a");
checkToggle("a", "b", true, "a b");
checkToggle("a", "A", true, "a A");
checkToggle("a b c", "d", true, "a b c d");
checkToggle(" a a b", "d", true, "a b d");
checkToggle("a", "a", false, "");
checkToggle(" a a a ", "a", false, "");
checkToggle(" A A A ", "a", true, "A a");
checkToggle(" a b c ", "b", false, "a c");
checkToggle(" a b c b b", "b", false, "a c");
checkToggle(" a b c ", "c", false, "a b");
checkToggle(" a b c ", "a", false, "b c");
checkToggle(" a a b", "b", false, "a");
checkToggle("\t\n\f\r a\t\n\f\r b\t\n\f\r ", "a", false, "b");
checkToggle("\t\n\f\r a\t\n\f\r b\t\n\f\r ", "c", true, "a b c");
checkToggle("null", null, false, "");
checkToggle("", null, true, "null");
checkToggle("undefined", undefined, false, "");
checkToggle("", undefined, true, "undefined");
// replace() method
function checkReplace(before, token, newToken, expectedRes, after, expectedException) {
checkModification(e, "replace", [token, newToken], expectedRes, before,
after, expectedException, desc);
}
checkReplace(null, "", "a", null, null, "SyntaxError");
checkReplace(null, "", " ", null, null, "SyntaxError");
checkReplace(null, " ", "a", null, null, "InvalidCharacterError");
checkReplace(null, "\ta", "b", null, null, "InvalidCharacterError");
checkReplace(null, "a\t", "b", null, null, "InvalidCharacterError");
checkReplace(null, "\na", "b", null, null, "InvalidCharacterError");
checkReplace(null, "a\n", "b", null, null, "InvalidCharacterError");
checkReplace(null, "\fa", "b", null, null, "InvalidCharacterError");
checkReplace(null, "a\f", "b", null, null, "InvalidCharacterError");
checkReplace(null, "\ra", "b", null, null, "InvalidCharacterError");
checkReplace(null, "a\r", "b", null, null, "InvalidCharacterError");
checkReplace(null, " a", "b", null, null, "InvalidCharacterError");
checkReplace(null, "a ", "b", null, null, "InvalidCharacterError");
checkReplace(null, "a", "", null, null, "SyntaxError");
checkReplace(null, " ", "", null, null, "SyntaxError");
checkReplace(null, "a", " ", null, null, "InvalidCharacterError");
checkReplace(null, "b", "\ta", null, null, "InvalidCharacterError");
checkReplace(null, "b", "a\t", null, null, "InvalidCharacterError");
checkReplace(null, "b", "\na", null, null, "InvalidCharacterError");
checkReplace(null, "b", "a\n", null, null, "InvalidCharacterError");
checkReplace(null, "b", "\fa", null, null, "InvalidCharacterError");
checkReplace(null, "b", "a\f", null, null, "InvalidCharacterError");
checkReplace(null, "b", "\ra", null, null, "InvalidCharacterError");
checkReplace(null, "b", "a\r", null, null, "InvalidCharacterError");
checkReplace(null, "b", " a", null, null, "InvalidCharacterError");
checkReplace(null, "b", "a ", null, null, "InvalidCharacterError");
checkReplace("a", "a", "a", true, "a");
checkReplace("a", "a", "b", true, "b");
checkReplace("a", "A", "b", false, "a");
checkReplace("a b", "b", "A", true, "a A");
checkReplace("a b", "c", "a", false, "a b");
checkReplace("a b c", "d", "e", false, "a b c");
// https://github.com/whatwg/dom/issues/443
checkReplace("a a a b", "a", "a", true, "a b");
checkReplace("a a a b", "c", "d", false, "a a a b");
checkReplace(null, "a", "b", false, null);
checkReplace("", "a", "b", false, "");
checkReplace(" ", "a", "b", false, " ");
checkReplace(" a \f", "a", "b", true, "b");
checkReplace("a b c", "b", "d", true, "a d c");
checkReplace("a b c", "c", "a", true, "a b");
checkReplace("c b a", "c", "a", true, "a b");
checkReplace("a b a", "a", "c", true, "c b");
checkReplace("a b a", "b", "c", true, "a c");
checkReplace(" a a b", "a", "c", true, "c b");
checkReplace(" a a b", "b", "c", true, "a c");
checkReplace("\t\n\f\r a\t\n\f\r b\t\n\f\r ", "a", "c", true, "c b");
checkReplace("\t\n\f\r a\t\n\f\r b\t\n\f\r ", "b", "c", true, "a c");
checkReplace("a null", null, "b", true, "a b");
checkReplace("a b", "a", null, true, "null b");
checkReplace("a undefined", undefined, "b", true, "a b");
checkReplace("a b", "a", undefined, true, "undefined b");
}
var content = document.getElementById("content");
var htmlNode = document.createElement("div");
content.appendChild(htmlNode);
testClassList(htmlNode, " (HTML node)");
var xhtmlNode = document.createElementNS(XHTML_NS, "div");
content.appendChild(xhtmlNode);
testClassList(xhtmlNode, " (XHTML node)");
var mathMLNode = document.createElementNS(MATHML_NS, "math");
content.appendChild(mathMLNode);
testClassList(mathMLNode, " (MathML node)");
var xmlNode = document.createElementNS(null, "foo");
content.appendChild(xmlNode);
testClassList(xmlNode, " (XML node with null namespace)");
var fooNode = document.createElementNS("http://example.org/foo", "foo");
content.appendChild(fooNode);
testClassList(fooNode, " (foo node)");
</script>

View File

@@ -1,73 +0,0 @@
<!DOCTYPE HTML>
<meta charset=utf8>
<title>Test for Element.closest</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body id="body">
<div id="test8" class="div3" style="display:none">
<div id="test7" class="div2">
<div id="test6" class="div1">
<form id="test10" class="form2"></form>
<form id="test5" class="form1" name="form-a">
<input id="test1" class="input1" required>
<fieldset class="fieldset2" id="test2">
<select id="test3" class="select1" required>
<option default id="test4" value="">Test4</option>
<option selected id="test11">Test11</option>
<option id="test12">Test12</option>
<option id="test13">Test13</option>
</select>
<input id="test9" type="text" required>
</fieldset>
</form>
</div>
</div>
</div>
<div id=log></div>
<script>
do_test("select" , "test12", "test3");
do_test("fieldset" , "test13", "test2");
do_test("div" , "test13", "test6");
do_test("body" , "test3" , "body");
do_test("[default]" , "test4" , "test4");
do_test("[selected]" , "test4" , "");
do_test("[selected]" , "test11", "test11");
do_test('[name="form-a"]' , "test12", "test5");
do_test('form[name="form-a"]' , "test13", "test5");
do_test("input[required]" , "test9" , "test9");
do_test("select[required]" , "test9" , "");
do_test("div:not(.div1)" , "test13", "test7");
do_test("div.div3" , "test6" , "test8");
do_test("div#test7" , "test1" , "test7");
do_test(".div3 > .div2" , "test12", "test7");
do_test(".div3 > .div1" , "test12", "");
do_test("form > input[required]" , "test9" , "");
do_test("fieldset > select[required]", "test12", "test3");
do_test("input + fieldset" , "test6" , "");
do_test("form + form" , "test3" , "test5");
do_test("form + form" , "test5" , "test5");
do_test(":empty" , "test10", "test10");
do_test(":last-child" , "test11", "test2");
do_test(":first-child" , "test12", "test3");
do_test(":invalid" , "test11", "test2");
do_test(":scope" , "test4", "test4");
do_test("select > :scope" , "test4", "test4");
do_test("div > :scope" , "test4", "");
do_test(":has(> :scope)" , "test4", "test3");
function do_test(aSelector, aElementId, aTargetId) {
test(function() {
var el = document.getElementById(aElementId).closest(aSelector);
if (el === null) {
assert_equals("", aTargetId, aSelector);
} else {
assert_equals(el.id, aTargetId, aSelector);
}
}, "Element.closest with context node '" + aElementId + "' and selector '" + aSelector + "'");
}
</script>

View File

@@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
[
<!ENTITY tree "<span id='first_element_child' style='font-weight:bold;'>unknown.</span>">
]>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Entity References</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of Entity References</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is &tree;</p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
var fec = parentEl.firstElementChild;
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
})
]]></script>
</body>
</html>

View File

@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
[
<!ENTITY tree "<tspan id='first_element_child' font-weight='bold'>unknown.</tspan>">
]>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>Entity References</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of Entity References</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle">The result of this test is &tree;</text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
var fec = parentEl.firstElementChild;
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
})
]]></h:script>
</svg>

Before

Width:  |  Height:  |  Size: 1015 B

View File

@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:pickle="http://ns.example.org/pickle"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>firstElementChild with namespaces</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of firstElementChild with namespaces</text>
<g id="parentEl">
<pickle:dill id="first_element_child"/>
</g>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var fec = parentEl.firstElementChild;
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
assert_equals(fec.localName, "dill")
})
]]></h:script>
</svg>

Before

Width:  |  Height:  |  Size: 888 B

View File

@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:pickle="http://ns.example.org/pickle">
<head>
<title>firstElementChild with namespaces</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of firstElementChild with namespaces</h1>
<div id="parentEl">
<pickle:dill id="first_element_child"/>
</div>
<div id="log"></div>
<p id="parentEl">The result of this test is
<span id="first_element_child" style="font-weight:bold;">logged above.</span></p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var fec = parentEl.firstElementChild;
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
assert_equals(fec.localName, "dill")
})
]]></script>
</body>
</html>

View File

@@ -1,21 +0,0 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>firstElementChild with namespaces</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of firstElementChild with namespaces</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is a unknown.</p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl")
var el = document.createElementNS("http://ns.example.org/pickle", "pickle:dill")
el.setAttribute("id", "first_element_child")
parentEl.appendChild(el)
var fec = parentEl.firstElementChild
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
assert_equals(fec.localName, "dill")
})
</script>

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>firstElementChild</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of firstElementChild</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle">The result of this test is
<tspan id="first_element_child" font-weight="bold">unknown.</tspan></text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var fec = parentEl.firstElementChild;
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
})
]]></h:script>
</svg>

Before

Width:  |  Height:  |  Size: 889 B

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>firstElementChild</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of firstElementChild</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is
<span id="first_element_child" style="font-weight:bold;">logged above.</span></p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var fec = parentEl.firstElementChild;
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
})
]]></script>
</body>
</html>

View File

@@ -1,18 +0,0 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>firstElementChild</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of firstElementChild</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is
<span id="first_element_child" style="font-weight:bold;">logged above.</span></p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl");
var fec = parentEl.firstElementChild;
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
})
</script>

View File

@@ -1,43 +0,0 @@
<!DOCTYPE html>
<title>Element.getElementsByClassName</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
test(function() {
var a = document.createElement("a"), b = document.createElement("b")
b.className = "foo"
a.appendChild(b)
var list = a.getElementsByClassName("foo")
assert_array_equals(list, [b])
var secondList = a.getElementsByClassName("foo")
assert_true(list === secondList || list !== secondList, "Caching is allowed.")
}, "getElementsByClassName should work on disconnected subtrees.")
test(function() {
var list = document.getElementsByClassName("foo")
assert_false(list instanceof NodeList, "NodeList")
assert_true(list instanceof HTMLCollection, "HTMLCollection")
}, "Interface should be correct.")
test(function() {
var a = document.createElement("a");
var b = document.createElement("b");
var c = document.createElement("c");
b.className = "foo";
document.body.appendChild(a);
this.add_cleanup(function() {document.body.removeChild(a)});
a.appendChild(b);
var l = a.getElementsByClassName("foo");
assert_true(l instanceof HTMLCollection);
assert_equals(l.length, 1);
c.className = "foo";
a.appendChild(c);
assert_equals(l.length, 2);
a.removeChild(c);
assert_equals(l.length, 1);
}, "getElementsByClassName() should be a live collection");
</script>

View File

@@ -1,51 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title></title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<iframe src="Element-getElementsByTagName-change-document-HTMLNess-iframe.xml"></iframe>
<script>
setup({ single_test: true });
onload = function() {
var parent = document.createElement("div");
var child1 = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
child1.textContent = "xhtml:a";
var child2 = document.createElementNS("http://www.w3.org/1999/xhtml", "A");
child2.textContent = "xhtml:A";
var child3 = document.createElementNS("", "a");
child3.textContent = "a";
var child4 = document.createElementNS("", "A");
child4.textContent = "A";
parent.appendChild(child1);
parent.appendChild(child2);
parent.appendChild(child3);
parent.appendChild(child4);
var list = parent.getElementsByTagName("A");
assert_array_equals(list, [child1, child4],
"In an HTML document, should lowercase the tagname passed in for HTML " +
"elements only");
frames[0].document.documentElement.appendChild(parent);
assert_array_equals(list, [child1, child4],
"After changing document, should still be lowercasing for HTML");
assert_array_equals(parent.getElementsByTagName("A"),
[child2, child4],
"New list with same root and argument should not be lowercasing now");
// Now reinsert all those nodes into the parent, to blow away caches.
parent.appendChild(child1);
parent.appendChild(child2);
parent.appendChild(child3);
parent.appendChild(child4);
assert_array_equals(list, [child1, child4],
"After blowing away caches, should still have the same list");
assert_array_equals(parent.getElementsByTagName("A"),
[child2, child4],
"New list with same root and argument should still not be lowercasing");
done();
}
</script>

View File

@@ -1,30 +0,0 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Element.getElementsByTagName</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-element-getelementsbytagname">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="Document-Element-getElementsByTagName.js"></script>
<div id="log"></div>
<script>
var element;
setup(function() {
element = document.createElement("div");
element.appendChild(document.createTextNode("text"));
var p = element.appendChild(document.createElement("p"));
p.appendChild(document.createElement("a"))
.appendChild(document.createTextNode("link"));
p.appendChild(document.createElement("b"))
.appendChild(document.createTextNode("bold"));
p.appendChild(document.createElement("em"))
.appendChild(document.createElement("u"))
.appendChild(document.createTextNode("emphasized"));
element.appendChild(document.createComment("comment"));
});
test_getElementsByTagName(element, element);
test(function() {
assert_array_equals(element.getElementsByTagName(element.localName), []);
}, "Matching the context object");
</script>

View File

@@ -1,37 +0,0 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Element.getElementsByTagNameNS</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-element-getelementsbytagnamens">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="Document-Element-getElementsByTagNameNS.js"></script>
<div id="log"></div>
<script>
var element;
setup(function() {
element = document.createElement("div");
element.appendChild(document.createTextNode("text"));
var p = element.appendChild(document.createElement("p"));
p.appendChild(document.createElement("a"))
.appendChild(document.createTextNode("link"));
p.appendChild(document.createElement("b"))
.appendChild(document.createTextNode("bold"));
p.appendChild(document.createElement("em"))
.appendChild(document.createElement("u"))
.appendChild(document.createTextNode("emphasized"));
element.appendChild(document.createComment("comment"));
});
test_getElementsByTagNameNS(element, element);
test(function() {
assert_array_equals(element.getElementsByTagNameNS("*", element.localName), []);
}, "Matching the context object (wildcard namespace)");
test(function() {
assert_array_equals(
element.getElementsByTagNameNS("http://www.w3.org/1999/xhtml",
element.localName),
[]);
}, "Matching the context object (specific namespace)");
</script>

View File

@@ -1,32 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Element.prototype.hasAttribute</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-element-hasattribute">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<span data-e2="2" data-F2="3" id="t"></span>
<script>
"use strict";
test(() => {
const el = document.createElement("p");
el.setAttributeNS("foo", "x", "first");
assert_true(el.hasAttribute("x"));
}, "hasAttribute should check for attribute presence, irrespective of namespace");
test(() => {
const el = document.getElementById("t");
assert_true(el.hasAttribute("data-e2"));
assert_true(el.hasAttribute("data-E2"));
assert_true(el.hasAttribute("data-f2"));
assert_true(el.hasAttribute("data-F2"));
}, "hasAttribute should work with all attribute casings");
</script>

View File

@@ -1,40 +0,0 @@
<!doctype html>
<meta charset="utf-8">
<title></title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<button></button>
<div id="foo"></div>
<p data-foo=""></p>
<script>
test(function() {
var buttonElement = document.getElementsByTagName('button')[0];
assert_equals(buttonElement.hasAttributes(), false, 'hasAttributes() on empty element must return false.');
var emptyDiv = document.createElement('div');
assert_equals(emptyDiv.hasAttributes(), false, 'hasAttributes() on dynamically created empty element must return false.');
}, 'element.hasAttributes() must return false when the element does not have attribute.');
test(function() {
var divWithId = document.getElementById('foo');
assert_equals(divWithId.hasAttributes(), true, 'hasAttributes() on element with id attribute must return true.');
var divWithClass = document.createElement('div');
divWithClass.setAttribute('class', 'foo');
assert_equals(divWithClass.hasAttributes(), true, 'hasAttributes() on dynamically created element with class attribute must return true.');
var pWithCustomAttr = document.getElementsByTagName('p')[0];
assert_equals(pWithCustomAttr.hasAttributes(), true, 'hasAttributes() on element with custom attribute must return true.');
var divWithCustomAttr = document.createElement('div');
divWithCustomAttr.setAttribute('data-custom', 'foo');
assert_equals(divWithCustomAttr.hasAttributes(), true, 'hasAttributes() on dynamically created element with custom attribute must return true.');
}, 'element.hasAttributes() must return true when the element has attribute.');
</script>
</body>

View File

@@ -1,91 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title></title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id="target"></div>
<div id="parent"><span id=target2></span></div>
<div id="log" style="visibility:visible"></div>
<span id="test1"></span>
<span id="test2"></span>
<span id="test3"></span>
<span id="test4"></span>
<script>
var target = document.getElementById("target");
var target2 = document.getElementById("target2");
test(function() {
assert_throws_dom("SyntaxError", function() {
target.insertAdjacentElement("test", document.getElementById("test1"))
});
assert_throws_dom("SyntaxError", function() {
target2.insertAdjacentElement("test", document.getElementById("test1"))
});
}, "Inserting to an invalid location should cause a Syntax Error exception")
test(function() {
var el = target.insertAdjacentElement("beforebegin", document.getElementById("test1"));
assert_equals(target.previousSibling.id, "test1");
assert_equals(el.id, "test1");
el = target2.insertAdjacentElement("beforebegin", document.getElementById("test1"));
assert_equals(target2.previousSibling.id, "test1");
assert_equals(el.id, "test1");
}, "Inserted element should be target element's previous sibling for 'beforebegin' case")
test(function() {
var el = target.insertAdjacentElement("afterbegin", document.getElementById("test2"));
assert_equals(target.firstChild.id, "test2");
assert_equals(el.id, "test2");
el = target2.insertAdjacentElement("afterbegin", document.getElementById("test2"));
assert_equals(target2.firstChild.id, "test2");
assert_equals(el.id, "test2");
}, "Inserted element should be target element's first child for 'afterbegin' case")
test(function() {
var el = target.insertAdjacentElement("beforeend", document.getElementById("test3"));
assert_equals(target.lastChild.id, "test3");
assert_equals(el.id, "test3");
el = target2.insertAdjacentElement("beforeend", document.getElementById("test3"));
assert_equals(target2.lastChild.id, "test3");
assert_equals(el.id, "test3");
}, "Inserted element should be target element's last child for 'beforeend' case")
test(function() {
var el = target.insertAdjacentElement("afterend", document.getElementById("test4"));
assert_equals(target.nextSibling.id, "test4");
assert_equals(el.id, "test4");
el = target2.insertAdjacentElement("afterend", document.getElementById("test4"));
assert_equals(target2.nextSibling.id, "test4");
assert_equals(el.id, "test4");
}, "Inserted element should be target element's next sibling for 'afterend' case")
test(function() {
var docElement = document.documentElement;
docElement.style.visibility="hidden";
assert_throws_dom("HierarchyRequestError", function() {
var el = docElement.insertAdjacentElement("beforebegin", document.getElementById("test1"));
assert_equals(el, null);
});
var el = docElement.insertAdjacentElement("afterbegin", document.getElementById("test2"));
assert_equals(docElement.firstChild.id, "test2");
assert_equals(el.id, "test2");
el = docElement.insertAdjacentElement("beforeend", document.getElementById("test3"));
assert_equals(docElement.lastChild.id, "test3");
assert_equals(el.id, "test3");
assert_throws_dom("HierarchyRequestError", function() {
var el = docElement.insertAdjacentElement("afterend", document.getElementById("test4"));
assert_equals(el, null);
});
}, "Adding more than one child to document should cause a HierarchyRequestError exception")
</script>

View File

@@ -1,76 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title></title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<body style="visibility:hidden">
<div id="target"></div>
<div id="parent"><span id=target2></span></div>
<div id="log" style="visibility:visible"></div>
</body>
<script>
var target = document.getElementById("target");
var target2 = document.getElementById("target2");
test(function() {
assert_throws_dom("SyntaxError", function() {
target.insertAdjacentText("test", "text")
});
assert_throws_dom("SyntaxError", function() {
target2.insertAdjacentText("test", "test")
});
}, "Inserting to an invalid location should cause a Syntax Error exception")
test(function() {
target.insertAdjacentText("beforebegin", "test1");
assert_equals(target.previousSibling.nodeValue, "test1");
target2.insertAdjacentText("beforebegin", "test1");
assert_equals(target2.previousSibling.nodeValue, "test1");
}, "Inserted text node should be target element's previous sibling for 'beforebegin' case")
test(function() {
target.insertAdjacentText("afterbegin", "test2");
assert_equals(target.firstChild.nodeValue, "test2");
target2.insertAdjacentText("afterbegin", "test2");
assert_equals(target2.firstChild.nodeValue, "test2");
}, "Inserted text node should be target element's first child for 'afterbegin' case")
test(function() {
target.insertAdjacentText("beforeend", "test3");
assert_equals(target.lastChild.nodeValue, "test3");
target2.insertAdjacentText("beforeend", "test3");
assert_equals(target2.lastChild.nodeValue, "test3");
}, "Inserted text node should be target element's last child for 'beforeend' case")
test(function() {
target.insertAdjacentText("afterend", "test4");
assert_equals(target.nextSibling.nodeValue, "test4");
target2.insertAdjacentText("afterend", "test4");
assert_equals(target.nextSibling.nodeValue, "test4");
}, "Inserted text node should be target element's next sibling for 'afterend' case")
test(function() {
var docElement = document.documentElement;
docElement.style.visibility="hidden";
assert_throws_dom("HierarchyRequestError", function() {
docElement.insertAdjacentText("beforebegin", "text1")
});
docElement.insertAdjacentText("afterbegin", "test2");
assert_equals(docElement.firstChild.nodeValue, "test2");
docElement.insertAdjacentText("beforeend", "test3");
assert_equals(docElement.lastChild.nodeValue, "test3");
assert_throws_dom("HierarchyRequestError", function() {
docElement.insertAdjacentText("afterend", "test4")
});
}, "Adding more than one child to document should cause a HierarchyRequestError exception")
</script>

View File

@@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>lastElementChild</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of lastElementChild</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle">The result of <tspan id="first_element_child">this test</tspan> is <tspan id="last_element_child" font-weight="bold">not</tspan> known.</text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var lec = parentEl.lastElementChild;
assert_true(!!lec)
assert_equals(lec.nodeType, 1)
assert_equals(lec.getAttribute("id"), "last_element_child")
})
]]></h:script>
</svg>

Before

Width:  |  Height:  |  Size: 926 B

View File

@@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>firstElementChild</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of firstElementChild</h1>
<div id="log"></div>
<p id="parentEl">The result of <span id="first_element_child">this test</span> is <span id="last_element_child" style="font-weight:bold;">logged</span> above.</p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var lec = parentEl.lastElementChild;
assert_true(!!lec)
assert_equals(lec.nodeType, 1)
assert_equals(lec.getAttribute("id"), "last_element_child")
})
]]></script>
</body>
</html>

View File

@@ -1,17 +0,0 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>lastElementChild</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of lastElementChild</h1>
<div id="log"></div>
<p id="parentEl">The result of <span id="first_element_child">this test</span> is <span id="last_element_child" style="font-weight:bold;">logged</span> above.</p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl");
var lec = parentEl.lastElementChild;
assert_true(!!lec)
assert_equals(lec.nodeType, 1)
assert_equals(lec.getAttribute("id"), "last_element_child")
})
</script>

View File

@@ -1,65 +0,0 @@
function init(e, method) {
/*
* This test suite tests Selectors API methods in 4 different contexts:
* 1. Document node
* 2. In-document Element node
* 3. Detached Element node (an element with no parent, not in the document)
* 4. Document Fragment node
*
* For each context, the following tests are run:
*
* The interface check tests ensure that each type of node exposes the Selectors API methods.
*
* The matches() tests are run
* All the selectors tested for both the valid and invalid selector tests are found in selectors.js.
* See comments in that file for documentation of the format used.
*
* The level2-lib.js file contains all the common test functions for running each of the aforementioned tests
*/
var docType = "html"; // Only run tests suitable for HTML
// Prepare the nodes for testing
var doc = e.target.contentDocument; // Document Node tests
var element = doc.getElementById("root"); // In-document Element Node tests
//Setup the namespace tests
setupSpecialElements(doc, element);
var outOfScope = element.cloneNode(true); // Append this to the body before running the in-document
// Element tests, but after running the Document tests. This
// tests that no elements that are not descendants of element
// are selected.
traverse(outOfScope, function(elem) { // Annotate each element as being a clone; used for verifying
elem.setAttribute("data-clone", ""); // that none of these elements ever match.
});
var detached = element.cloneNode(true); // Detached Element Node tests
var fragment = doc.createDocumentFragment(); // Fragment Node tests
fragment.appendChild(element.cloneNode(true));
// Setup Tests
interfaceCheckMatches(method, "Document", doc);
interfaceCheckMatches(method, "Detached Element", detached);
interfaceCheckMatches(method, "Fragment", fragment);
interfaceCheckMatches(method, "In-document Element", element);
runSpecialMatchesTests(method, "DIV Element", element);
runSpecialMatchesTests(method, "NULL Element", document.createElement("null"));
runSpecialMatchesTests(method, "UNDEFINED Element", document.createElement("undefined"));
runInvalidSelectorTestMatches(method, "Document", doc, invalidSelectors);
runInvalidSelectorTestMatches(method, "Detached Element", detached, invalidSelectors);
runInvalidSelectorTestMatches(method, "Fragment", fragment, invalidSelectors);
runInvalidSelectorTestMatches(method, "In-document Element", element, invalidSelectors);
runMatchesTest(method, "In-document", doc, validSelectors, "html");
runMatchesTest(method, "Detached", detached, validSelectors, "html");
runMatchesTest(method, "Fragment", fragment, validSelectors, "html");
runMatchesTest(method, "In-document", doc, scopedSelectors, "html");
}

View File

@@ -1,24 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>matches/webkitMatchesSelector must work when an element has a namespace</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!-- Regression tests for https://github.com/jsdom/jsdom/issues/1846, https://github.com/jsdom/jsdom/issues/2247 -->
<script>
"use strict";
for (const method of ["matches", "webkitMatchesSelector"]) {
test(() => {
assert_true(document.createElementNS("", "element")[method]("element"));
}, `empty string namespace, ${method}`);
test(() => {
assert_true(document.createElementNS("urn:ns", "h")[method]("h"));
}, `has a namespace, ${method}`);
test(() => {
assert_true(document.createElementNS("urn:ns", "h")[method]("*|h"));
}, `has a namespace, *|, ${method}`);
}
</script>

View File

@@ -1,22 +0,0 @@
<!DOCTYPE html>
<meta charset="UTF-8">
<title>Selectors-API Level 2 Test Suite: HTML with Selectors Level 3</title>
<!-- Selectors API Test Suite Version 3 -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/dom/nodes/selectors.js"></script>
<script src="/dom/nodes/ParentNode-querySelector-All.js"></script>
<script src="Element-matches.js"></script>
<script src="Element-matches-init.js"></script>
<style>iframe { visibility: hidden; position: absolute; }</style>
<div id="log">This test requires JavaScript.</div>
<script>
async_test(function() {
var frame = document.createElement("iframe");
frame.onload = this.step_func_done(e => init(e, "matches" ));
frame.src = "/dom/nodes/ParentNode-querySelector-All-content.html#target";
document.body.appendChild(frame);
});
</script>

View File

@@ -1,135 +0,0 @@
/*
* Check that the matches() method exists on the given Node
*/
function interfaceCheckMatches(method, type, obj) {
if (obj.nodeType === obj.ELEMENT_NODE) {
test(function() {
assert_idl_attribute(obj, method, type + " supports " + method);
}, type + " supports " + method)
} else {
test(function() {
assert_false(method in obj, type + " supports " + method);
}, type + " should not support " + method)
}
}
function runSpecialMatchesTests(method, type, element) {
test(function() { // 1
if (element.tagName.toLowerCase() === "null") {
assert_true(element[method](null), "An element with the tag name '" + element.tagName.toLowerCase() + "' should match.");
} else {
assert_false(element[method](null), "An element with the tag name '" + element.tagName.toLowerCase() + "' should not match.");
}
}, type + "." + method + "(null)")
test(function() { // 2
if (element.tagName.toLowerCase() === "undefined") {
assert_true(element[method](undefined), "An element with the tag name '" + element.tagName.toLowerCase() + "' should match.");
} else {
assert_false(element[method](undefined), "An element with the tag name '" + element.tagName.toLowerCase() + "' should not match.");
}
}, type + "." + method + "(undefined)")
test(function() { // 3
assert_throws_js(element.ownerDocument.defaultView.TypeError, function() {
element[method]();
}, "This should throw a TypeError.")
}, type + "." + method + " no parameter")
}
/*
* Execute queries with the specified invalid selectors for matches()
* Only run these tests when errors are expected. Don't run for valid selector tests.
*/
function runInvalidSelectorTestMatches(method, type, root, selectors) {
if (root.nodeType === root.ELEMENT_NODE) {
for (var i = 0; i < selectors.length; i++) {
var s = selectors[i];
var n = s["name"];
var q = s["selector"];
test(function() {
assert_throws_dom(
"SyntaxError",
root.ownerDocument.defaultView.DOMException,
function() {
root[method](q)
}
);
}, type + "." + method + ": " + n + ": " + q);
}
}
}
function runMatchesTest(method, type, root, selectors, docType) {
var nodeType = getNodeType(root);
for (var i = 0; i < selectors.length; i++) {
var s = selectors[i];
var n = s["name"];
var q = s["selector"];
var e = s["expect"];
var u = s["unexpected"];
var ctx = s["ctx"];
var ref = s["ref"];
if ((!s["exclude"] || (s["exclude"].indexOf(nodeType) === -1 && s["exclude"].indexOf(docType) === -1))
&& (s["testType"] & TEST_MATCH) ) {
if (ctx && !ref) {
test(function() {
var j, element, refNode;
for (j = 0; j < e.length; j++) {
element = root.querySelector("#" + e[j]);
refNode = root.querySelector(ctx);
assert_true(element[method](q, refNode), "The element #" + e[j] + " should match the selector.")
}
if (u) {
for (j = 0; j < u.length; j++) {
element = root.querySelector("#" + u[j]);
refNode = root.querySelector(ctx);
assert_false(element[method](q, refNode), "The element #" + u[j] + " should not match the selector.")
}
}
}, type + " Element." + method + ": " + n + " (with refNode Element): " + q);
}
if (ref) {
test(function() {
var j, element, refNodes;
for (j = 0; j < e.length; j++) {
element = root.querySelector("#" + e[j]);
refNodes = root.querySelectorAll(ref);
assert_true(element[method](q, refNodes), "The element #" + e[j] + " should match the selector.")
}
if (u) {
for (j = 0; j < u.length; j++) {
element = root.querySelector("#" + u[j]);
refNodes = root.querySelectorAll(ref);
assert_false(element[method](q, refNodes), "The element #" + u[j] + " should not match the selector.")
}
}
}, type + " Element." + method + ": " + n + " (with refNodes NodeList): " + q);
}
if (!ctx && !ref) {
test(function() {
for (var j = 0; j < e.length; j++) {
var element = root.querySelector("#" + e[j]);
assert_true(element[method](q), "The element #" + e[j] + " should match the selector.")
}
if (u) {
for (j = 0; j < u.length; j++) {
element = root.querySelector("#" + u[j]);
assert_false(element[method](q), "The element #" + u[j] + " should not match the selector.")
}
}
}, type + " Element." + method + ": " + n + " (with no refNodes): " + q);
}
}
}
}

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>nextElementSibling</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of nextElementSibling</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle">The result of <tspan id="first_element_child">this test</tspan> is <tspan id="last_element_child" font-weight="bold">unknown.</tspan></text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var fec = document.getElementById("first_element_child");
var nes = fec.nextElementSibling;
assert_true(!!nes)
assert_equals(nes.nodeType, 1)
assert_equals(nes.getAttribute("id"), "last_element_child")
})
]]></h:script>
</svg>

Before

Width:  |  Height:  |  Size: 985 B

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>nextElementSibling</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of nextElementSibling</h1>
<div id="log"></div>
<p id="parentEl">The result of <span id="first_element_child">this test</span> is <span id="last_element_child" style="font-weight:bold;">unknown.</span></p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var fec = document.getElementById("first_element_child");
var nes = fec.nextElementSibling;
assert_true(!!nes)
assert_equals(nes.nodeType, 1)
assert_equals(nes.getAttribute("id"), "last_element_child")
})
]]></script>
</body>
</html>

View File

@@ -1,18 +0,0 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>nextElementSibling</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of nextElementSibling</h1>
<div id="log"></div>
<p id="parentEl">The result of <span id="first_element_child">this test</span> is <span id="last_element_child" style="font-weight:bold;">unknown.</span></p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl");
var fec = document.getElementById("first_element_child");
var nes = fec.nextElementSibling;
assert_true(!!nes)
assert_equals(nes.nodeType, 1)
assert_equals(nes.getAttribute("id"), "last_element_child")
})
</script>

View File

@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>previousElementSibling</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of previousElementSibling</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle">The result of <tspan id="first_element_child">this test</tspan> is
<tspan id="middle_element_child" font-weight="bold">unknown.</tspan>
<tspan id="last_element_child" display="none">fnord</tspan> </text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var lec = document.getElementById("last_element_child");
var pes = lec.previousElementSibling;
assert_true(!!pes)
assert_equals(pes.nodeType, 1)
assert_equals(pes.getAttribute("id"), "middle_element_child")
})
]]></h:script>
</svg>

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>previousElementSibling</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of previousElementSibling</h1>
<div id="log"></div>
<p id="parentEl">The result of <span id="first_element_child">this test</span> is
<span id="middle_element_child" style="font-weight:bold;">unknown.</span>
<span id="last_element_child" style="display:none;">fnord</span> </p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var lec = document.getElementById("last_element_child");
var pes = lec.previousElementSibling;
assert_true(!!pes)
assert_equals(pes.nodeType, 1)
assert_equals(pes.getAttribute("id"), "middle_element_child")
})
]]></script>
</body>
</html>

View File

@@ -1,23 +0,0 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>previousElementSibling</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of previousElementSibling</h1>
<div id="log"></div>
<p id="parentEl">The result of <span id="first_element_child">this test</span> is
<span id="middle_element_child" style="font-weight:bold;">unknown.</span>
<span id="last_element_child" style="display:none;">fnord</span> </p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl");
var lec = document.getElementById("last_element_child");
var pes = lec.previousElementSibling;
assert_true(!!pes)
assert_equals(pes.nodeType, 1)
assert_equals(pes.getAttribute("id"), "middle_element_child")
})
</script>

View File

@@ -1,16 +0,0 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Element.remove</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-childnode-remove">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="ChildNode-remove.js"></script>
<div id=log></div>
<script>
var node, parentNode;
setup(function() {
node = document.createElement("div");
parentNode = document.createElement("div");
});
testRemove(node, parentNode, "element");
</script>

View File

@@ -1,58 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Element.prototype.removeAttribute</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-element-removeattribute">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
"use strict";
test(() => {
const el = document.createElement("p");
el.setAttribute("x", "first");
el.setAttributeNS("foo", "x", "second");
assert_equals(el.attributes.length, 2);
assert_equals(el.getAttribute("x"), "first");
assert_equals(el.getAttributeNS(null, "x"), "first");
assert_equals(el.getAttributeNS("foo", "x"), "second");
// removeAttribute removes the first attribute with name "x" that
// we set on the element, irrespective of namespace.
el.removeAttribute("x");
// The only attribute remaining should be the second one.
assert_equals(el.getAttribute("x"), "second");
assert_equals(el.getAttributeNS(null, "x"), null);
assert_equals(el.getAttributeNS("foo", "x"), "second");
assert_equals(el.attributes.length, 1, "one attribute");
}, "removeAttribute should remove the first attribute, irrespective of namespace, when the first attribute is " +
"not in a namespace");
test(() => {
const el = document.createElement("p");
el.setAttributeNS("foo", "x", "first");
el.setAttributeNS("foo2", "x", "second");
assert_equals(el.attributes.length, 2);
assert_equals(el.getAttribute("x"), "first");
assert_equals(el.getAttributeNS("foo", "x"), "first");
assert_equals(el.getAttributeNS("foo2", "x"), "second");
// removeAttribute removes the first attribute with name "x" that
// we set on the element, irrespective of namespace.
el.removeAttribute("x");
// The only attribute remaining should be the second one.
assert_equals(el.getAttribute("x"), "second");
assert_equals(el.getAttributeNS("foo", "x"), null);
assert_equals(el.getAttributeNS("foo2", "x"), "second");
assert_equals(el.attributes.length, 1, "one attribute");
}, "removeAttribute should remove the first attribute, irrespective of namespace, when the first attribute is " +
"in a namespace");
</script>

View File

@@ -1,18 +0,0 @@
<!DOCTYPE html>
<title>Element.removeAttributeNS</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="attributes.js"></script>
<div id="log"></div>
<script>
var XML = "http://www.w3.org/XML/1998/namespace"
test(function() {
var el = document.createElement("foo")
el.setAttributeNS(XML, "a:bb", "pass")
attr_is(el.attributes[0], "pass", "bb", XML, "a", "a:bb")
el.removeAttributeNS(XML, "a:bb")
assert_equals(el.attributes.length, 1)
attr_is(el.attributes[0], "pass", "bb", XML, "a", "a:bb")
}, "removeAttributeNS should take a local name.")
</script>

View File

@@ -1,22 +0,0 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// Regression test for crbug.com/1138487.
//
// It was possible for a non-ASCII-lowercase string to be used when inserting
// into the attribute collection if a hashtable encountered it during probing
// while looking for the ASCII-lowercase equivalent.
//
// This caused such a string to be illegally used as an attribute name, thus
// causing inconsistent behavior in future attribute lookup.
test(() => {
const el = document.createElement('div');
el.setAttribute('labelXQL', 'abc');
el.setAttribute('_valueXQL', 'def');
assert_equals(el.getAttribute('labelXQL'), 'abc');
assert_equals(el.getAttribute('labelxql'), 'abc');
assert_equals(el.getAttribute('_valueXQL'), 'def');
assert_equals(el.getAttribute('_valuexql'), 'def');
}, "Attributes first seen in mixed ASCII case should not be corrupted.");
</script>

View File

@@ -1,38 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Element.prototype.setAttribute</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-element-setattribute">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
"use strict";
test(() => {
const el = document.createElement("p");
el.setAttributeNS("foo", "x", "first");
el.setAttributeNS("foo2", "x", "second");
el.setAttribute("x", "changed");
assert_equals(el.attributes.length, 2);
assert_equals(el.getAttribute("x"), "changed");
assert_equals(el.getAttributeNS("foo", "x"), "changed");
assert_equals(el.getAttributeNS("foo2", "x"), "second");
}, "setAttribute should change the first attribute, irrespective of namespace");
test(() => {
// https://github.com/whatwg/dom/issues/31
const el = document.createElement("p");
el.setAttribute("FOO", "bar");
assert_equals(el.getAttribute("foo"), "bar");
assert_equals(el.getAttribute("FOO"), "bar");
assert_equals(el.getAttributeNS("", "foo"), "bar");
assert_equals(el.getAttributeNS("", "FOO"), null);
}, "setAttribute should lowercase before setting");
</script>

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>Null test</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of previousElementSibling and nextElementSibling returning null</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle">The result of this test is <tspan id="first_element_child" font-weight="bold">unknown.</tspan></text>
<h:script><![CDATA[
test(function() {
var fec = document.getElementById("first_element_child");
assert_equals(fec.previousElementSibling, null)
assert_equals(fec.nextElementSibling, null)
})
]]></h:script>
</svg>

Before

Width:  |  Height:  |  Size: 869 B

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Null Test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of previousElementSibling and nextElementSibling returning null</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is <span id="first_element_child" style="font-weight:bold;">unknown.</span></p>
<script><![CDATA[
test(function() {
var fec = document.getElementById("first_element_child");
assert_equals(fec.previousElementSibling, null)
assert_equals(fec.nextElementSibling, null)
})
]]></script>
</body>
</html>

Some files were not shown because too many files have changed in this diff Show More