Cargoify servo

This commit is contained in:
Jack Moffitt 2014-08-28 09:34:23 -06:00
parent db2f642c32
commit c6ab60dbfc
1761 changed files with 8423 additions and 2294 deletions

92
tests/content/harness.js Normal file
View file

@ -0,0 +1,92 @@
function _oneline(x) {
var i = x.indexOf("\n");
return (i == -1) ? x : (x.slice(0, i) + "...");
}
var _expectations = 0;
var _tests = 0;
function expect(num) {
_expectations = num;
}
function _fail(s, m) {
_tests++;
// string split to avoid problems with tests that end up printing the value of window._fail.
window.alert(_oneline("TEST-UNEXPECTED" + "-FAIL | " + s + ": " + m));
}
function _pass(s, m) {
_tests++;
window.alert(_oneline("TEST-PASS | " + s + ": " + m));
}
function _printer(opstr, op) {
return function (a, b, msg) {
let f = op(a,b) ? _pass : _fail;
if (!msg) msg = "";
f(a + " " + opstr + " " + b, msg);
};
}
var is = _printer("===", function (a,b) { return a === b; });
var is_not = _printer("!==", function (a,b) { return a !== b; });
var is_a = _printer("is a", function (a,b) { return a instanceof b; });
var is_not_a = _printer("is not a", function (a,b) { return !(a instanceof b); });
var is_in = _printer("is in", function (a,b) { return a in b; });
var is_not_in = _printer("is not in", function (a,b) { return !(a in b); });
var as_str_is = _printer("as string is", function (a,b) { return String(a) == b; });
var lt = _printer("<", function (a,b) { return a < b; });
var gt = _printer(">", function (a,b) { return a > b; });
var leq = _printer("<=", function (a,b) { return a <= b; });
var geq = _printer(">=", function (a,b) { return a >= b; });
var starts_with = _printer("starts with", function (a,b) { return a.indexOf(b) == 0; });
function is_function(val, name) {
starts_with(String(val), "function " + name + "(");
}
function should_throw(f) {
try {
f();
_fail("operation should have thrown but did not");
} catch (x) {
_pass("operation successfully threw an exception", x.toString());
}
}
function should_not_throw(f) {
try {
f();
_pass("operation did not throw an exception");
} catch (x) {
_fail("operation should have not thrown", x.toString());
}
}
function check_selector(elem, selector, matches) {
is(elem.matches(selector), matches);
}
function check_disabled_selector(elem, disabled) {
check_selector(elem, ":disabled", disabled);
check_selector(elem, ":enabled", !disabled);
}
var _test_complete = false;
var _test_timeout = 10000; //10 seconds
function finish() {
if (_expectations > _tests) {
_fail('expected ' + _expectations + ' tests, fullfilled ' + _tests);
}
_test_complete = true;
window.close();
}
function _test_timed_out() {
if (!_test_complete) {
_fail('test timed out (' + _test_timeout/1000 + 's)');
finish();
}
}
setTimeout(_test_timed_out, _test_timeout);

BIN
tests/content/test.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
tests/content/test.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -0,0 +1,12 @@
<html>
<head>
<script src="harness.js"></script>
<script>
is_function(DOMParser, "DOMParser");
let parser = new DOMParser();
is_a(parser, DOMParser);
is_a(parser.parseFromString("", "text/html"), Document);
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,18 @@
<html>
<head>
<script src="harness.js"></script>
<script>
is_function(Event, "Event");
let ev = new Event("foopy", {cancelable: true});
is_a(ev, Event);
is(ev.type, 'foopy');
is(ev.defaultPrevented, false);
ev.preventDefault();
is(ev.defaultPrevented, true);
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,18 @@
<html>
<head>
<script src="harness.js"></script>
<script>
is_function(MouseEvent, "MouseEvent");
let ev = new MouseEvent("press", {bubbles: true, screenX: 150, detail: 100});
is_a(ev, Event);
is_a(ev, UIEvent);
is_a(ev, MouseEvent);
is(ev.screenX, 150);
is(ev.detail, 100);
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,18 @@
<html>
<head>
<script src="harness.js"></script>
<script>
function check_onload(listener) {
is(listener, window);
var ev = new Event('click', {bubbles: true, cancelable: true});
document.body.dispatchEvent(ev);
}
function check_onclick(listener) {
is(listener, document.body);
finish();
}
</script>
</head>
<body onload="check_onload(this)" onclick="check_onclick(this)">
</body>
</html>

View file

@ -0,0 +1,23 @@
<html>
<head>
<script src="harness.js"></script>
</head>
<table id="t">
<caption id="tcaption">old caption</caption>
</table>
<script>
var t = document.getElementById("t");
var tcaption = document.getElementById("tcaption");
is(t.caption, tcaption);
is(t.caption.innerHTML, "old caption");
var newCaption = document.createElement("caption");
newCaption.innerHTML = "new caption";
t.caption = newCaption;
is(newCaption.parentNode, t);
is(t.caption, newCaption);
finish();
</script>
</html>

View file

@ -0,0 +1,18 @@
<html>
<head>
<script src="./harness.js"></script>
<a id="foo" href="/nonexistent">test link</a>
<script>
var link = document.getElementById('foo');
link.addEventListener('click', function(ev) {
ev.preventDefault();
});
var ev = new Event('click', {bubbles: true, cancelable: true});
link.dispatchEvent(ev);
setTimeout(function() {
is(true, true, "load probably would have occurred by now");
finish();
}, 500);
</script>
</head>
</html>

View file

@ -0,0 +1,143 @@
<html>
<head>
<meta charset="utf-8">
<title>test_binding
page </title>
<base href="./"></base>
<script src="harness.js"></script>
<script>
function check_collection(obj, num, classes, name) {
is_a(obj, HTMLCollection);
is(obj.length, num);
is(obj[obj.length], undefined);
if (classes === undefined)
return;
classes = [Element, HTMLElement].concat(classes);
for (var i=0; i<obj.length; i++) {
is_not(obj[i], undefined);
is(obj[i].tagName, name);
for (var j=0; j<classes.length; j++) {
is_a(obj[i], classes[j]);
}
}
}
function check_tag(tagname, num, classes, tagname_upper) {
if (tagname_upper === undefined)
tagname_upper = tagname.toUpperCase();
check_collection(document.getElementsByTagName(tagname), num, classes, tagname_upper);
}
check_collection(document.links, 1, [HTMLAnchorElement], "A");
check_collection(document.images, 1, [HTMLImageElement], "IMG");
check_collection(document.embeds, 1, [HTMLEmbedElement], "EMBED");
check_collection(document.plugins, 1, [HTMLEmbedElement], "EMBED");
check_collection(document.scripts, 2, [HTMLScriptElement], "SCRIPT");
check_collection(document.applets, 1, [HTMLAppletElement], "APPLET");
check_collection(document.forms, 1, [HTMLFormElement], "FORM");
check_collection(document.getElementsByTagName("nosuchtag"), 0);
check_tag("section", 1, []);
check_tag("aside", 1, []);
check_tag("b", 1, []);
check_tag("i", 1, []);
check_tag("small", 1, []);
check_tag("head", 1, [HTMLHeadElement]);
check_tag("div", 3, [HTMLDivElement]);
check_tag("iframe", 1, [HTMLIFrameElement]);
check_tag("body", 1, [HTMLBodyElement]);
check_tag("area", 1, [HTMLAreaElement]);
check_tag("base", 1, [HTMLBaseElement]);
check_tag("data", 1, [HTMLDataElement]);
check_tag("ol", 1, [HTMLOListElement]);
check_tag("canvas", 1, [HTMLCanvasElement]);
check_tag("source", 2, [HTMLSourceElement]);
check_tag("time", 1, [HTMLTimeElement]);
check_tag("caption", 1, [HTMLTableCaptionElement]);
check_tag("textarea", 1, [HTMLTextAreaElement]);
check_tag("q", 1, [HTMLQuoteElement]);
check_tag("th", 1, [HTMLTableCellElement, HTMLTableHeaderCellElement]);
check_tag("td", 1, [HTMLTableCellElement, HTMLTableDataCellElement]);
check_tag("col", 1, [HTMLTableColElement]);
check_tag("colgroup", 1, [HTMLTableColElement]);
check_tag("input", 2, [HTMLInputElement]);
check_tag("li", 1, [HTMLLIElement]);
check_tag("progress", 1, [HTMLProgressElement]);
check_tag("template", 1, [HTMLTemplateElement]);
check_tag("pre", 1, [HTMLPreElement]);
check_tag("legend", 1, [HTMLLegendElement]);
check_tag("label", 1, [HTMLLabelElement]);
check_tag("track", 1, [HTMLTrackElement]);
check_tag("audio", 1, [HTMLMediaElement, HTMLAudioElement]);
check_tag("video", 1, [HTMLMediaElement, HTMLVideoElement]);
// Test non-ASCII tag names. Uppercasing is ASCII-only per spec:
// http://dom.spec.whatwg.org/#dom-element-tagname
check_tag("foo-á", 1, [HTMLUnknownElement], "FOO-á");
finish();
</script>
</head>
<body>
<div id="first" name="test">fffff<br><br><br><br>fffffffffffffffff</div>
<div id="second">ggg</div>
<span id="third" name="test">hhhhhhhh</span>
<div id="fourth">iiiiiiiiiiiiiiiiiii</div>
<a href="http://www.mozilla.org"></a>
<img src="test.jpg"/>
<embed></embed>
<form>
<fieldset>
<legend>legend</legend>
<label for="">label<input type="text" value="input" /></label>
</fieldset>
</form>
<hr />
<canvas/>
<p>pppppppppp</p>
<q>qqqqqqqqqqqqqqqqqqqqqqqqqqq</q>
<progress max="100" value="80">80%</progress>
<applet></applet>
<input type="text" value="input"/>
<iframe></iframe>
<ol type="1">
<li>li</li>
</ol>
<table>
<caption>sample table</caption>
<colgroup>
<col/>
</colgroup>
<tbody>
<tr><th>head</th></tr>
<tr><td>data</td></tr>
</tbody>
</table>
<section>section</section>
<aside>aside</aside>
<b>b</b>
<i>i</i>
<small>small</small>
<textarea>textarea</textarea>
<time datetime="2014-02-14">Valentines day</time>
<area></area>
<data></data>
<template></template>
<pre>pre</pre>
<audio>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
</audio>
<video src="">
<track></track>
</video>
<foo-á>hi</foo-á>
</body>
</html>

View file

@ -0,0 +1,19 @@
<html>
<head>
<title></title>
<script src="harness.js"></script>
</head>
<body>
<script>
var elem = document.createElement("foo");
is(elem.tagName, "FOO");
var elem = document.createElement("p");
is_a(elem, HTMLParagraphElement);
var elem = document.createElement("sPAn");
is_a(elem, HTMLSpanElement);
var text = document.createTextNode("hello");
is_a(text, Text);
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,13 @@
<html>
<head>
<script src="harness.js"></script>
<script>
is_a(window, Window);
is_a(document.documentElement, HTMLHtmlElement);
is_a(document.documentElement.firstChild, HTMLHeadElement);
is(document.documentElement.nextSibling, null);
is_a(document, Document);
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
let foo = document.getElementById("foo");
let doc = document.implementation.createHTMLDocument("title");
is(foo.ownerDocument, document);
let adopted_foo = doc.adoptNode(foo);
is(document.getElementById("foo"), null);
is(foo, adopted_foo);
is(foo.ownerDocument, doc);
is(foo.parentNode, null);
is(foo.childNodes.length, 1);
finish();
</script>
</head>
<body>
<div id="foo"><div id="bar"></div></div>
</body>
</html>

View file

@ -0,0 +1,73 @@
<html>
<head>
<script src="harness.js"></script>
</head>
<body>
<script>
// test1: existing document's body
{
is_not(document.body, null, "test1-0, existing document's body");
is_a(document.body, HTMLBodyElement, "test1-1, exising document's body");
is(document.body && document.body.tagName, "BODY", "test1-2, existing document's body");
}
// test2: replace document's body with new body
{
let new_body = document.createElement("body");
is_not(new_body, null, "test2-0, replace document's body with new body");
document.body = new_body;
is(new_body, document.body, "test2-1, replace document's body with new body");
}
// test3: replace document's body with new frameset
{
let new_frameset = document.createElement("frameset");
is_not(new_frameset, null, "test2-0, replace document's body with new frameset");
document.body = new_frameset;
is(new_frameset, document.body, "test2-1, replace document's body with new frameset");
}
// test4: append an invalid element to a new document
{
let new_document = new Document();
new_document.appendChild(new_document.createElement("html"));
let new_div = new_document.createElement("div");
is_not(new_div, null, "test4-0, append an invalid element to a new document");
should_throw(function() {
new_document.body = new_div;
});
is(new_document.body, null, "test4-1, append an invalid element to a new document");
}
// test5: append body to a new document
{
let new_document = document.implementation.createHTMLDocument();
let new_body = new_document.createElement("body");
is_not(new_body, null, "test5-0, append body to a new document");
is_a(new_body, HTMLBodyElement, "test5-1, append body to a new document");
is(new_body && new_body.tagName, "BODY", "test5-2, append body to a new document");
new_document.body = new_body;
is(new_document.body, new_body, "test5-3, append body to a new document");
}
// test6: append frameset to a new document
{
let new_document = document.implementation.createHTMLDocument();
let new_frameset = new_document.createElement("frameset");
is_not(new_frameset, null, "test6-0, append frameset to a new document");
is_a(new_frameset, HTMLFrameSetElement, "test6-1, append frameset to a new document");
is(new_frameset && new_frameset.tagName, "FRAMESET", "test6-2, append frameset to a new document");
new_document.body = new_frameset;
is(new_document.body, new_frameset, "test6-3, append frameset to a new document");
}
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,21 @@
<!DOCTYPE html>
<meta charset="UTF-8">
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: characterSet
{
is(document.characterSet, "utf-8", "test1-0, characterSet");
var xmldoc = new Document;
is(xmldoc.characterSet, "utf-8", "test2-1, characterSet");
var htmldoc = document.implementation.createHTMLDocument("title");
is(htmldoc.characterSet, "utf-8", "test2-2, characterSet");
}
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: default characterSet
{
// FIXME: https://github.com/mozilla-servo/libhubbub/issues/5
is(document.characterSet, "utf-8", "test1-0, default characterSet");
}
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<meta charset="unknown-charset">
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: unknown charset
{
is(document.characterSet, "utf-8", "test1-0, unknown charset");
}
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: long charset
{
is(document.characterSet, "windows-1252", "test1-0, long charset");
}
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<meta charset="iso-8859-1">
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: short charset
{
is(document.characterSet, "windows-1252", "test1-0, short charset");
}
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,21 @@
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: BackCompat
{
is(document.compatMode, "BackCompat", "test1-0, BackCompat");
}
// test2: Non-parsed documents
{
var xmldoc = new Document;
is(xmldoc.compatMode, "CSS1Compat", "test2-0, Non-parsed documents");
var htmldoc = document.implementation.createHTMLDocument("title");
is(htmldoc.compatMode, "CSS1Compat", "test2-1, Non-parsed documents");
}
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,13 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: Loose HTML
{
is(document.compatMode, "BackCompat", "test1-0, Loose HTML");
}
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,13 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: Strict HTML
{
is(document.compatMode, "CSS1Compat", "test1-0, Strict HTML");
}
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: HTML document
{
is_a(document, Document, "test1-0, HTML document");
is(document.contentType, "text/html", "test1-1, HTML document");
}
// test2: XML document
{
var doc = new Document;
is_a(doc, Document, "test2-0, XML document");
is(doc.contentType, "application/xml", "test2-1, XML document");
}
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,20 @@
<html>
<head>
<script src="harness.js"></script>
</head>
<datalist id="id">
<option value="A">
<option value="B">
<p>P</p>
<div>DIV</div>
<option value="C">
</datalist>
<script>
var datalist = document.getElementById("id");
is(datalist.options.length, 3);
is_a(datalist.options[0], HTMLOptionElement);
is_a(datalist.options[1], HTMLOptionElement);
is_a(datalist.options[2], HTMLOptionElement);
finish();
</script>
</html>

View file

@ -0,0 +1,26 @@
<html>
<head id="foo">
<title></title>
<script src="harness.js"></script>
</head>
<body>
<div id="bar"></div>
<script>
let gBody = document.getElementsByTagName("body")[0];
// Test the assertion with inserting node with child having id into the document (mozilla#2630)
// This need not to port to WPF-test because this tests servo's internally flags.
{
let TEST_ID = "test-9";
let a = document.createElement("a");
let b = document.createElement("b");
a.appendChild(b).id = TEST_ID;
gBody.appendChild(a);
let result = document.getElementById(TEST_ID);
is(result, b, "test 9-0");
}
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,15 @@
<html>
<head >
<title></title>
<script src="harness.js"></script>
</head>
<body>
<div name="foo"></div>
<script>
let nameList = document.getElementsByName("foo");
is_a(nameList, NodeList);
is_not_a(nameList, HTMLCollection);
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,46 @@
<html>
<head>
<script src="harness.js"></script>
</head>
<body>
<script>
// test1: existing document's head
{
is_not(document.head, null, "test1-0, existing document's head");
is_a(document.head, HTMLHeadElement, "test1-1, exising document's head");
is(document.head && document.head.tagName, "HEAD", "test1-2, existing document's head");
}
// test2: append head to a new document
{
let new_document = new Document();
new_document.appendChild(new_document.createElement("html"));
let new_head = new_document.createElement("head");
is_not(new_head, null, "test2-0, append head to a new document");
is_a(new_head, HTMLHeadElement, "test2-1, append head to a new document");
is(new_head && new_head.tagName, "head", "test2-2, append head to a new document");
// Document::head is read-only.
new_document.head = new_head;
is(new_document.head, null, "test2-3, append head to a new document");
new_document.documentElement.appendChild(new_head);
is(new_document.head, new_head, "test2-4, append head to a new document");
}
// test3: head's parent should be document element
{
let new_document = new Document();
let html = new_document.createElement("html");
let foo = new_document.createElement("foo");
let head = new_document.createElement("head");
new_document.appendChild(html);
html.appendChild(foo);
foo.appendChild(head);
is(new_document.head, null, "test3-0, head's parent should be document element");
}
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,81 @@
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: basic test
{
is_not(document.implementation, null, "test1-0, basic test");
is_a(document.implementation, DOMImplementation, "test1-1, basic test");
var implementation = document.implementation;
is(document.implementation, implementation, "test1-2, basic test");
}
// test2: createDocumentType
{
is(document.doctype, null, "test2-0, createDocumentType");
var doctype = document.implementation.createDocumentType("html", null, null);
is_a(doctype && doctype, DocumentType, "test2-1, createDocumentType");
doctype = document.implementation.createDocumentType("html:html", null, null);
is_a(doctype && doctype, DocumentType, "test2-2, createDocumentType");
}
// test3: createHTMLDocument
{
var htmldoc = document.implementation.createHTMLDocument("example title");
is_not(htmldoc, null, "test3-0, createHTMLDocument");
is_a(htmldoc, Document, "test3-1, createHTMLDocument");
is(htmldoc.childNodes.length, 2, "test3-3, createHTMLDocument");
is_a(htmldoc.doctype && htmldoc.doctype, DocumentType, "test3-4, createHTMLDocument");
is(htmldoc.doctype.name, "html", "test3-5, createHTMLDocument");
is_a(htmldoc.documentElement && htmldoc.documentElement, HTMLHtmlElement, "test3-6, createHTMLDocument");
is(htmldoc.documentElement.childNodes.length, 2, "test3-7, createHTMLDocument");
is(htmldoc.documentElement.tagName, "HTML", "test3-8, createHTMLDocument");
is_a(htmldoc.head && htmldoc.head, HTMLHeadElement, "test3-9, createHTMLDocument");
is(htmldoc.head.tagName, "HEAD", "test3-10, createHTMLDocument");
is(htmldoc.head, htmldoc.documentElement.childNodes[0], "test3-11, createHTMLDocument");
is(htmldoc.head.childNodes.length, 1, "test3-12, createHTMLDocument");
is_a(htmldoc.head.childNodes[0], HTMLTitleElement, "test3-13, createHTMLDocument");
is(htmldoc.head.childNodes[0].tagName, "TITLE", "test3-14, createHTMLDocument");
is(htmldoc.title, "example title", "test3-15, createHTMLDocument");
is_a(htmldoc.body && htmldoc.body, HTMLBodyElement, "test3-16, createHTMLDocument");
is(htmldoc.body.tagName, "BODY", "test3-17, createHTMLDocument");
is(htmldoc.body, htmldoc.documentElement.childNodes[1], "test3-18, createHTMLDocument");
is(htmldoc.body.childNodes.length, 0, "test3-19, createHTMLDocument");
}
// test4: createDocument
{
var doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
is_not(doc, null, "test4-0, createDocument");
is_a(doc, Document, "test4-1, createDocument");
is(doc.childNodes.length, 1, "test4-2, createDocument");
is(doc.doctype, null, "test4-3, createDocument");
is_a(doc.documentElement, HTMLHtmlElement, "test4-4, createDocument");
var doctype = document.implementation.createDocumentType("html", null, null);
doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', doctype);
is(doc.childNodes.length, 2, "test4-5, createDocument");
is(doc.doctype, doctype, "test4-6, createDocument");
is_a(doc.documentElement, HTMLHtmlElement, "test4-7, createDocument");
doctype = document.implementation.createDocumentType(
'svg:svg', '-//W3C//DTD SVG 1.1//EN',
'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
doc = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg:svg', doctype);
is(doc.childNodes.length, 2, "test4-8, createDocument");
is(doc.doctype, doctype, "test4-9, createDocument");
is_a(doc.documentElement, Element, "test4-10, createDocument");
}
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
var links = document.links;
is(links, document.links);
is(links.length, 0);
var anchor = document.createElement("a");
anchor.id = "anchor-with-href";
anchor.setAttribute("href", "http://www.google.com");
document.body.appendChild(anchor);
is(links.length, 1);
anchor = document.createElement("a");
anchor.id = "anchor-without-href";
document.body.appendChild(anchor);
is(links.length, 1);
anchor.setAttribute("href", "http://www.google.com");
is(links.length, 2);
anchor.removeAttribute("href", "http://www.google.com");
is(links.length, 1);
document.body.removeChild(document.getElementById("anchor-without-href"));
is(links.length, 1);
document.body.removeChild(document.getElementById("anchor-with-href"));
is(links, document.links);
is(links.length, 0);
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<script src="harness.js"></script>
<body>
<div id="div" class="div-class">A</div>
<p>P</p>
<script>
is(document.nodeValue, null);
var div = document.getElementById("div");
is(div.nodeValue, null);
is(div.firstChild.nodeValue, "A");
div.firstChild.nodeValue = "B";
is(div.firstChild.nodeValue, "B");
var commentNode = document.createComment("comment node");
is(commentNode.nodeValue, "comment node");
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,9 @@
<html>
<title>x</title>
<script src="harness.js"></script>
<script>
document.head.firstChild.appendChild(document.createElement("foo"));
is(document.title, "x");
finish();
</script>
</html>

View file

@ -0,0 +1,32 @@
<!doctype html>
<html>
<head>
<title></title>
<script src="harness.js"></script>
<script>
// test1: URL & documentURI
{
is_not(document.URL, null, "test1-0, URL & documentURI");
is_not(document.documentURI, null, "test1-1, URL & documentURI");
is(document.URL, document.documentURI, "test1-2, URL & documentURI");
}
// test2: new document
{
var doc = new Document();
is(doc.URL, "about:blank", "test2-0, new document");
}
// test3: current document
{
var url = document.URL.split("/");
is(url[0], "file:", "test3-0, current document");
is(url[url.length-1], "test_document_url.html", "test3-1, current document");
}
finish();
</script>
</head>
<body>
</body>
</html>

View file

@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
var div = document.createElement("div");
var classList = div.classList;
is(classList.length, 0);
is(classList.item(0), null);
should_throw(function () {
classList.contains("");
});
should_throw(function () {
classList.contains(" ");
});
var list = ["foo", " foo", "foo ", " foo ", " foo "];
for(var i = 0; i < list.length; i++) {
div.className = list[i];
is(div.className, list[i]);
is(classList.length, 1);
is(classList.item(0), "foo");
is(classList.item(1), null);
is(classList.contains("foo"), true);
is(classList.contains("bar"), false);
}
list = ["foo bar", " foo bar", " foo bar ", " foo bar "];
for(var i = 0; i < list.length; i++) {
div.className = list[i];
is(div.className, list[i]);
is(classList.length, 2);
is(classList.item(0), "foo");
is(classList.item(1), "bar");
is(classList.item(2), null);
is(classList.contains("foo"), true);
is(classList.contains("bar"), true);
is(classList.contains("baz"), false);
}
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,66 @@
<html>
<head id="foo">
<title></title>
<script src="harness.js"></script>
</head>
<body>
<div id="test" foo="bar"></div>
<script>
let test = document.getElementById("test");
{
let r1 = test.getAttribute("id");
is(r1, "test", "test1-0, Element.getAttribute().");
let r2 = test.getAttribute("foo");
is(r2, "bar", "test1-1, Element.getAttribute().");
}
{
let NAME = "hoge";
let VALUE = "fuga";
test.setAttribute(NAME, VALUE);
let r = test.getAttribute(NAME);
is(r, VALUE, "test2. Element.setAttribute().");
}
{
let NAME = "foo";
let VALUE = "mozilla";
test.setAttribute(NAME, VALUE);
let r = test.getAttribute(NAME);
is(r, VALUE, "test3, attribute update by Element.setAttribute().")
}
{
test.setAttribute("id", "bar");
test.removeAttribute("id");
let r1 = test.hasAttribute("id");
is(r1, false, "test4-0, Element.removeAttribute().");
let r2 = test.getAttribute("id");
is(r2, null, "test4-1, Element.removeAttribute().");
}
{
test.setAttribute("xml:lang", "en");
let r1 = test.hasAttribute("xml:lang");
is(r1, true, "test5-0, Element.setAttribute('xml:lang').");
let r2 = test.getAttribute("xml:lang");
is_not(r2, null, "test5-1, Element.setAttribute('xml:lang').");
}
should_throw(function () {
test.setAttributeNS("http://example.com", "xmlns", "foo");
});
should_throw(function () {
test.setAttributeNS("http://www.w3.org/2000/xmlns/", "attr", "value");
});
should_throw(function () {
test.setAttributeNS("http://www.w3.org/2000/xmlns/", "prefix:attr", "value");
});
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,21 @@
<html>
<head id="foo">
<script src="harness.js"></script>
</head>
<body>
<div></div>
<script>
var attrs = [];
for (var i = 'a'.charCodeAt(0); i != 'z'.charCodeAt(0); i++) {
document.getElementsByTagName('div')[0].setAttribute(String.fromCharCode(i),
i.toString());
}
var attributes = document.getElementsByTagName('div')[0].attributes;
for (var i = 0; i < attributes.length; i++) {
is(attributes[i].name, String.fromCharCode(i + 'a'.charCodeAt(0)));
is(attributes[i].value, (i + 'a'.charCodeAt(0)).toString());
}
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,21 @@
<!-- Remove this and update WPT metadata once DOMTokenList.toggle (#3138) is implemented. -->
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
let div = document.createElement("div");
div.className = "foo bar";
let classList = div.classList;
div.className = "";
is(classList.item(0), null, "classList.item(0) must return null when all classes have been removed");
is(classList[0], undefined, "classList[0] must be undefined when all classes have been removed");
finish();
</script>
</head>
<body>
</body>
</html>

View file

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
let foo1 = document.getElementById("foo-1");
let foo2 = document.getElementById("foo-2");
foo1.className += " bar";
is(foo1.className, "foo bar");
let foo3 = document.createElement("div");
foo3.id = "foo-3";
foo3.className = "foo";
document.body.appendChild(foo3);
is(foo3, document.getElementById("foo-3"));
let collection = document.getElementsByClassName("foo");
is(collection.length, 2);
is(collection[0].id, foo1.id);
is(collection[1].id, foo3.id);
collection = document.getElementsByClassName("bar");
is(collection.length, 1);
is(collection[0].id, foo1.id);
collection = document.getElementsByClassName("baz");
is(collection.length, 1);
is(collection[0].id, foo2.id);
finish();
</script>
</head>
<body>
<div id="foo-1" class="foo"></div>
<div id="foo-2" class="baz"></div>
</body>
</html>

View file

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
</head>
<body>
<div id="foo"></div>
<script>
let test = document.getElementById("foo");
is(test.matches("#foo"), true, "test-1");
is(test.matches("#not-foo"), false, "test-2");
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,18 @@
<html>
<head>
<script src="harness.js"></script>
<script>
var rect = window.document.head.getBoundingClientRect();
var rects = window.document.head.getClientRects();
is_a(rect, DOMRect);
is(rect.top, 0);
is(rect.bottom, 0);
is(rect.left, 0);
is(rect.right, 0);
is(rect.width, 0);
is(rect.height, 0);
is(rects.length, 0);
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,181 @@
<!DOCTYPE html>
<html>
<head>
<title>Tests for :enabled and :disabled selectors</title>
<script src="harness.js"></script>
<script>
{ // Simple initialization checks.
var list, i, elem;
// Examples of elements which are never :enabled or :disabled.
list = ['div', 'p', 'body', 'head', 'span'];
for(i = 0; i < list.length; i++) {
elem = document.createElement(list[i]);
check_selector(elem, ":enabled", false);
check_selector(elem, ":disabled", false);
}
// Anchor, Area and Link are :enabled with an href, but never :disabled.
list = ["a", "area", "link"];
for(i = 0; i < list.length; i++) {
elem = document.createElement(list[i]);
check_selector(elem, ":enabled", false);
check_selector(elem, ":disabled", false);
elem.setAttribute("href", "");
check_selector(elem, ":enabled", true);
check_selector(elem, ":disabled", false);
}
// These are :enabled (and not :disabled) by default.
// XXX: Add 'menuitem' here whenever available.
list = ['button', 'input', 'select', 'textarea', 'optgroup', 'option', 'fieldset'];
for(i = 0; i < list.length; i++) {
elem = document.createElement(list[i]);
check_disabled_selector(elem, false);
}
}
{ // Document elements tests.
var click_count = 0;
var click_event = new Event('click', {bubbles: true, cancelable: true});
var list, elem1, elem2, elem3, elem4, elem5;
function on_click(ev) { click_count++; }
list = ['button', 'input', 'option', 'select', 'textarea'];
for(i = 0; i < list.length; i++) {
click_count = 0;
elem1 = document.getElementById(list[i] + "-1");
is(elem1.disabled, false);
elem1.addEventListener('click', on_click);
elem1.dispatchEvent(click_event);
is(click_count, 1);
elem2 = document.getElementById(list[i] + "-2");
is(elem2.disabled, true);
// Only user-generated click events are prevented.
elem2.addEventListener('click', on_click);
elem2.dispatchEvent(click_event);
is(click_count, 2);
// This should look disabled, though - missing UA's CSS for :disabled?
elem3 = document.getElementById(list[i] + "-3");
is(elem3.disabled, false);
if (list[i] == 'option') { continue; }
elem4 = document.getElementById(list[i] + "-4");
is(elem4.disabled, false);
// This should look disabled, though - missing UA's CSS for :disabled?
elem5 = document.getElementById(list[i] + "-5");
is(elem5.disabled, false);
}
}
{ // JS tests (Button, Input, Select, TextArea).
var list = ['button', 'input', 'select', 'textarea'];
var fieldset = document.createElement("fieldset");
fieldset.disabled = true;
var div = document.createElement("div");
var elem;
for(i = 0; i < list.length; i++) {
elem = document.createElement(list[i]);
check_disabled_selector(elem, false);
div.appendChild(elem);
check_disabled_selector(elem, false);
fieldset.appendChild(div);
check_disabled_selector(elem, true);
document.body.appendChild(fieldset);
check_disabled_selector(elem, true);
document.body.removeChild(fieldset);
check_disabled_selector(elem, true);
fieldset.removeChild(div);
check_disabled_selector(elem, false);
div.removeChild(elem);
check_disabled_selector(elem, false);
}
}
{ // JS tests (Option).
var optgroup = document.createElement("optgroup");
optgroup.disabled = true;
var option = document.createElement("option");
check_disabled_selector(option, false);
optgroup.appendChild(option);
check_disabled_selector(option, true);
document.body.appendChild(optgroup);
check_disabled_selector(option, true);
document.body.removeChild(optgroup);
check_disabled_selector(option, true);
optgroup.removeChild(option);
check_disabled_selector(option, false);
}
finish();
</script>
</head>
<body>
<button id="button-1"></button>
<button id="button-2" disabled></button>
<input id="input-1"></input>
<input id="input-2" disabled></input>
<option id="option-1"></option>
<option id="option-2" disabled></option>
<select id="select-1"></select>
<select id="select-2" disabled></select>
<textarea id="textarea-1"></textarea>
<textarea id="textarea-2" disabled></textarea>
<optgroup disabled>
<option id="option-3"></option>
</optgroup>
<fieldset disabled>
<fieldset>
<button id="button-3"></button>
<input id="input-3"></input>
<select id="select-3"></select>
<textarea id="textarea-3"></textarea>
</fieldset>
</fieldset>
<fieldset disabled>
<legend>
<button id="button-4"></button>
<input id="input-4"></input>
<select id="select-4"></select>
<textarea id="textarea-4"></textarea>
</legend>
</fieldset>
<fieldset disabled>
<legend></legend>
<legend>
<button id="button-5"></button>
<input id="input-5"></input>
<select id="select-5"></select>
<textarea id="textarea-5"></textarea>
</legend>
</fieldset>
</body>
</html>

View file

@ -0,0 +1,51 @@
<html>
<head>
<script src="harness.js"></script>
</head>
<body>
<span>Paragraph containing <div>event listener</div>.</span>
<script>
var bodyTimes = 0;
function bodyListener(ev) {
bodyTimes++;
is(ev.currentTarget, document.getElementsByTagName('body')[0]);
is(ev.target, document.getElementsByTagName('div')[0]);
if (bodyTimes == 1) {
is(ev.eventPhase, ev.CAPTURING_PHASE);
} else if (bodyTimes == 2) {
is(ev.eventPhase, ev.BUBBLING_PHASE);
}
}
var spanTimes = 0;
function spanListener(ev) {
is(ev.currentTarget, document.getElementsByTagName('span')[0]);
is(ev.target, document.getElementsByTagName('div')[0]);
is(ev.eventPhase, ev.BUBBLING_PHASE);
spanTimes++;
}
var divTimes = 0;
function divListener(ev) {
var self = document.getElementsByTagName('div')[0];
is(ev.currentTarget, self);
is(ev.target, self);
is(ev.eventPhase, ev.AT_TARGET);
divTimes++;
}
document.getElementsByTagName('body')[0].addEventListener("foopy", bodyListener, true);
document.getElementsByTagName('body')[0].addEventListener("foopy", bodyListener, false);
document.getElementsByTagName('span')[0].addEventListener("foopy", spanListener, false);
document.getElementsByTagName('div')[0].addEventListener("foopy", divListener, false);
var ev = new Event('foopy', {bubbles: true});
is(ev.bubbles, true);
document.getElementsByTagName('div')[0].dispatchEvent(ev);
is(bodyTimes, 2, 'body listener should be called multiple times');
is(divTimes, 1, 'target listener should be called once');
is(spanTimes, 1, 'span listener should be called while bubbling');
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,21 @@
<!DOCTYPE html>
<script src="harness.js"></script>
<b><b><b></b></b></b>
<script>
var sawmiddle = -1;
var sawouter = -1;
var step = 0;
var outerb = document.getElementsByTagName('b')[0];
var middleb = outerb.firstChild;
var innerb = middleb.firstChild;
outerb.addEventListener("x", function() {
middleb.addEventListener("x", function() {
sawmiddle = step++;
}, true);
sawouter = step++;
}, true);
innerb.dispatchEvent(new Event("x"));
is(sawmiddle, 1);
is(sawouter, 0);
finish();
</script>

View file

@ -0,0 +1,42 @@
<html>
<head>
<script src="harness.js"></script>
</head>
<body>
<div id="foo"></div>
<script>
var sawBubble = false;
var sawCapture = false;
var sawBubbleTwice = false;
function handler(ev) {
is(ev.eventPhase, ev.AT_TARGET);
is(sawBubble, false);
is(sawCapture, false);
sawBubble = true;
}
function handler2(ev) {
is(ev.eventPhase, ev.AT_TARGET);
is(sawBubble, true);
is(sawCapture, false);
sawCapture = true;
}
function handler3(ev) {
is(ev.eventPhase, ev.AT_TARGET);
is(sawBubble, true);
is(sawCapture, true);
sawBubbleTwice = true;
}
var target = document.getElementById('foo');
target.addEventListener('foopy', handler, false);
target.addEventListener('foopy', handler2, true);
target.addEventListener('foopy', handler3, false);
var ev = new Event('foopy', {bubbles: true});
target.dispatchEvent(ev);
is(sawBubble, true);
is(sawCapture, true);
is(sawBubbleTwice, true);
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8">
<script src="harness.js"></script>
</head>
<body>
<a id="a" onclick="{">link</a>
<script>
var a = document.getElementById("a");
is(a.onclick, null, "invalid onclick attribute");
document.body.setAttribute("onx", "{");
document.body.setAttribute("ony", "}");
is(document.body.getAttribute("onx"), "{");
is(document.body.getAttribute("ony"), "}");
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,39 @@
<html>
<head>
<script src="harness.js"></script>
</head>
<body>
<script>
function onFoopy(ev) {
window.removeEventListener('foopy', onFoopy);
is(ev instanceof expected, true);
is(ev.type, 'foopy');
}
var expected;
var events = [['HTMLEvents', Event, function(ev) { ev.initEvent('foopy', true, true); }],
['UIEvents', UIEvent, function(ev) { ev.initUIEvent('foopy', true, true, null, 0); }],
['MouseEvents', MouseEvent,
function(ev) { ev.initMouseEvent('foopy', true, true, null, 0,
0, 0, 0, 0, false, false,
false, false, 0, null); }]];
for (var i = 0; i < events.length; i++) {
addEventListener('foopy', onFoopy);
expected = events[i][1];
var ev = document.createEvent(events[i][0]);
events[i][2](ev);
window.dispatchEvent(ev);
}
var constructors = [Event, UIEvent, MouseEvent];
for (var i = 0; i < constructors.length; i++) {
addEventListener('foopy', onFoopy);
expected = constructors[i];
var ev = new constructors[i]('foopy', {cancelable: true, bubbles: true});
window.dispatchEvent(ev);
}
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,35 @@
<html>
<head>
<script src="harness.js"></script>
<script>
is_function(DOMRect, "DOMRect");
var elems = document.getElementsByTagName('div');
var rect = elems[0].getBoundingClientRect();
is_a(rect, DOMRect);
geq(rect.top, 100);
geq(rect.bottom, 200);
geq(rect.left, 100);
geq(rect.right, 200);
is(rect.width, 100);
is(rect.height, 100);
is(rect.width, rect.right - rect.left);
is(rect.height, rect.bottom - rect.top);
finish();
</script>
<style>
div {
margin-top: 100px;
margin-left: 100px;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div>my div</div>
</body>
</html>

View file

@ -0,0 +1,13 @@
<html>
<head>
<script src="harness.js"></script>
<script>
is(window, window.window);
is(window, this);
for (var key in this) {
is(this[key], window[key]);
}
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,119 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
let foo1 = document.getElementById("foo-1");
let foo2 = document.getElementById("foo-2");
let bar = document.getElementById("bar");
let live = document.getElementById("live");
let child = document.createElement("p");
let p1 = document.getElementById("p1");
let p2 = document.getElementById("p2");
let p3 = document.getElementById("p3");
let htmlcollection = null;
// test1: HTMLCollection interface
{
htmlcollection = document.getElementsByClassName("foo");
is(htmlcollection.length, 2);
is(htmlcollection.item(0), foo1);
is(htmlcollection.item(1), foo2);
is(htmlcollection.item(2), null);
is(htmlcollection.namedItem("foo-1"), foo1);
is(htmlcollection.namedItem("bar"), null);
htmlcollection = document.getElementsByClassName("FOO");
is(htmlcollection.length, 0);
htmlcollection = document.getElementsByClassName("bar");
is(htmlcollection.length, 1);
is(htmlcollection.item(0), bar);
is(htmlcollection.item(1), null);
is(htmlcollection.namedItem("bar"), bar);
}
// test2: live HTMLCollection
{
htmlcollection = document.getElementsByClassName("live");
is(htmlcollection.length, 1);
is(htmlcollection.item(0), live);
let new_live = document.createElement("div");
new_live.className = "live";
document.body.appendChild(new_live);
is(htmlcollection.length, 2);
is(htmlcollection.item(1), new_live);
document.body.removeChild(new_live);
is(htmlcollection.length, 1);
}
// test3: getElementsByTagName
{
is(document.getElementsByTagName("DIV").length, 5);
is(document.getElementsByTagName("div").length,
document.documentElement.getElementsByTagName("div").length);
is(document.getElementsByTagName("p").length,
document.getElementById("class-example").getElementsByTagName("p").length);
}
// test4: getElementsByTagNameNS
{
htmlcollection = document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "div");
is(htmlcollection.length, 5);
let from_element = document.documentElement.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "div");
is(htmlcollection.length, from_element.length);
htmlcollection = document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "DIV");
is(htmlcollection.length, 0);
htmlcollection = document.getElementsByTagNameNS("", "div");
is(htmlcollection.length, 0);
htmlcollection = document.getElementsByTagNameNS("invalid", "div");
is(htmlcollection.length, 0);
from_element = document.getElementById("class-example").getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "p");
is(from_element.length, 3);
}
// test5: document.getElementsByClassName
{
htmlcollection = document.getElementsByClassName("aaa");
is(htmlcollection.length, 2);
is(htmlcollection.item(0), p1);
is(htmlcollection.item(1), p2);
htmlcollection = document.getElementsByClassName("ccc bbb");
is(htmlcollection.length, 1);
is(htmlcollection.item(0), p3);
htmlcollection = document.getElementsByClassName("aaa,bbb");
is(htmlcollection.length, 0);
let from_element = document.getElementById("class-example").getElementsByClassName("bbb");
is(from_element.length, 2);
is(from_element.item(0), p1);
is(from_element.item(1), p3);
}
finish();
</script>
</head>
<body>
<div id="foo-1" class="foo"></div>
<div id="foo-2" class="foo"></div>
<div id="bar" class="bar"></div>
<div id="live" class="live"></div>
<div id="class-example">
<p id="p1" class="aaa bbb"/>
<p id="p2" class="aaa ccc"/>
<p id="p3" class="bbb ccc"/>
</div>
</body>
</html>

View file

@ -0,0 +1,45 @@
<html>
<script src="harness.js"></script>
<fieldset id="fs">
<legend>Display</legend>
<input type=radio name=a>
<fieldset>
<button>Click!</button>
</fieldset>
<keygen name="key">
<textarea>
A
</textarea>
<select>
<option value="1"> A </option>
<option value="2" selected> B </option>
</select>
<form onsubmit="return false" oninput="o.value = a.valueAsNumber + b.valueAsNumber">
<input name=a type=number step=any> +
<input name=b type=number step=any> =
<output name=c for="a b"></output>
</form>
<figure>
<object type="application/x-java-applet">
<param name="code" value="MyJavaClass">
<p>You do not have Java available, or it is disabled.</p>
</object>
<figcaption>My Java Clock</figcaption>
</figure>
</fieldset>
<script>
var fs = document.getElementById("fs");
is(fs.elements.length, 10);
is_a(fs.elements[0], HTMLInputElement);
is_a(fs.elements[1], HTMLFieldSetElement);
is_a(fs.elements[2], HTMLButtonElement);
is_a(fs.elements[3], HTMLUnknownElement);
is_a(fs.elements[4], HTMLTextAreaElement);
is_a(fs.elements[5], HTMLSelectElement);
is_a(fs.elements[6], HTMLInputElement);
is_a(fs.elements[7], HTMLInputElement);
is_a(fs.elements[8], HTMLOutputElement);
is_a(fs.elements[9], HTMLObjectElement);
finish();
</script>
</html>

View file

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
is(document.getElementsByClassName("foo").length, 6);
is_not(document.getElementById("bar").className, "ggg foo");
finish();
</script>
</head>
<body>
<!-- \u0020 Space -->
<div id="foo-1" class="aaa&#32;foo"></div>
<!-- \u0009 Character tabulation -->
<div id="foo-2" class="bbb&#9;foo"></div>
<!-- \u000a Line feed -->
<div id="foo-3" class="ccc&#10;foo"></div>
<!-- \u000c Form feed -->
<div id="foo-4" class="ddd&#12;foo"></div>
<!-- \u000d Carriage return -->
<div id="foo-5" class="eee&#13;foo"></div>
<!-- Space -->
<div id="foo-6" class="fff foo"></div>
<!-- Non-HTML space character -->
<div id="bar" class="ggg&#11;foo"></div>
</body>
</html>

View file

@ -0,0 +1,32 @@
<html>
<head>
<title></title>
<script src="harness.js"></script>
</head>
<body>
<img src="test.png"/>
<script>
// Testing get/set of image width/height properties
var img = window.document.getElementsByTagName("img")[0];
function wait_for_img_load(f) {
if (img.width != 0) {
f();
} else {
window.setTimeout(function() { wait_for_img_load(f) }, 1);
}
}
wait_for_img_load(function() {
is(img.width, 500);
is(img.height, 378);
img.width = 200;
img.height = 100;
is(img.width, 200);
is(img.height, 100);
finish();
});
</script>
</body>
</html>

View file

@ -0,0 +1,9 @@
<html>
<head>
<script src="harness.js"></script>
</head>
<body onload="is_a(event, Event); finish()">
<script>
</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<html>
<head>
<script src="harness.js"></script>
<script>
var a = document.createElement("div");
a.appendChild(document.createElement("pre")).appendChild(new Text(""));
is(a.innerHTML, "<pre></pre>");
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,208 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Interfaces exposed on the window</title>
<script src="harness.js"></script>
<script>
// This is a list of all interfaces that are exposed to every webpage.
// Please only add things to this list with great care and proper review
// from the associated module peers.
// IMPORTANT: Do not change this list without review from
// a JavaScript Engine peer!
var ecmaGlobals = [
"Array",
"ArrayBuffer",
"Boolean",
"DataView",
"Date",
"Error",
"EvalError",
"Float32Array",
"Float64Array",
"Function",
"Infinity",
"Int16Array",
"Int32Array",
"Int8Array",
"InternalError",
"Iterator",
"JSON",
"Map",
"Math",
"NaN",
"Number",
"Object",
"Proxy",
"RangeError",
"ReferenceError",
"RegExp",
"Set",
"StopIteration",
"String",
"SyntaxError",
"TypeError",
"Uint16Array",
"Uint32Array",
"Uint8Array",
"Uint8ClampedArray",
"URIError",
"WeakMap",
];
// IMPORTANT: Do not change the list below without review from a DOM peer!
var interfaceNamesInGlobalScope = [
"Attr",
"Blob",
"CanvasRenderingContext2D",
"CharacterData",
"DOMRect",
"Comment",
"Console",
"CustomEvent",
"DedicatedWorkerGlobalScope", // #2823
"Document",
"DocumentFragment",
"DocumentType",
"DOMException",
"DOMImplementation",
"DOMParser",
"DOMTokenList",
"Element",
"Event",
"EventTarget",
"File",
"FormData",
"HTMLAnchorElement",
"HTMLAppletElement",
"HTMLAreaElement",
"HTMLAudioElement",
"HTMLBaseElement",
"HTMLBodyElement",
"HTMLBRElement",
"HTMLButtonElement",
"HTMLCanvasElement",
"HTMLCollection",
"HTMLDataElement",
"HTMLDataListElement",
"HTMLDirectoryElement",
"HTMLDivElement",
"HTMLDListElement",
"HTMLElement",
"HTMLEmbedElement",
"HTMLFieldSetElement",
"HTMLFontElement",
"HTMLFormElement",
"HTMLFrameElement",
"HTMLFrameSetElement",
"HTMLHeadElement",
"HTMLHeadingElement",
"HTMLHRElement",
"HTMLHtmlElement",
"HTMLIFrameElement",
"HTMLImageElement",
"HTMLInputElement",
"HTMLLabelElement",
"HTMLLegendElement",
"HTMLLIElement",
"HTMLLinkElement",
"HTMLMapElement",
"HTMLMediaElement",
"HTMLMetaElement",
"HTMLMeterElement",
"HTMLModElement",
"HTMLObjectElement",
"HTMLOListElement",
"HTMLOptGroupElement",
"HTMLOptionElement",
"HTMLOutputElement",
"HTMLParagraphElement",
"HTMLParamElement",
"HTMLPreElement",
"HTMLProgressElement",
"HTMLQuoteElement",
"HTMLScriptElement",
"HTMLSelectElement",
"HTMLSourceElement",
"HTMLSpanElement",
"HTMLStyleElement",
"HTMLTableCaptionElement",
"HTMLTableCellElement",
"HTMLTableColElement",
"HTMLTableDataCellElement",
"HTMLTableElement",
"HTMLTableHeaderCellElement",
"HTMLTableRowElement",
"HTMLTableSectionElement",
"HTMLTemplateElement",
"HTMLTextAreaElement",
"HTMLTimeElement",
"HTMLTitleElement",
"HTMLTrackElement",
"HTMLUListElement",
"HTMLUnknownElement",
"HTMLVideoElement",
"Location",
"MessageEvent",
"MouseEvent",
"NamedNodeMap",
"Navigator",
"Node",
"NodeIterator",
"NodeList",
"Performance",
"PerformanceTiming",
"ProcessingInstruction",
"ProgressEvent",
"Range",
"Screen",
"TestBinding", // XXX
"Text",
"TreeWalker",
"UIEvent",
"URLSearchParams",
"ValidityState",
"Window",
"Worker",
"WorkerGlobalScope", // #2823
"WorkerLocation", // #2823
"WorkerNavigator", // #2823
"XMLHttpRequest",
"XMLHttpRequestUpload",
];
function createInterfaceMap() {
var interfaceMap = {};
function addInterfaces(interfaces)
{
for (var entry of interfaces) {
interfaceMap[entry] = true;
}
}
addInterfaces(ecmaGlobals);
addInterfaces(interfaceNamesInGlobalScope);
return interfaceMap;
}
var interfaceMap = createInterfaceMap();
for (var name of Object.getOwnPropertyNames(window)) {
if (!/^[A-Z]/.test(name)) {
continue;
}
is_in(name, interfaceMap,
"If this is failing: DANGER, are you sure you want to expose the new " +
"interface " + name + " to all webpages as a property on the window? " +
"Do not make a change to this file without review from jdm or Ms2ger " +
"for that specific change!");
if (name in interfaceMap) {
delete interfaceMap[name];
}
}
for (var name of Object.keys(interfaceMap)) {
is_in(name, window, name + " should be defined on the global scope");
}
is(Object.keys(interfaceMap).length, 0,
"The following interface(s) are not enumerated: " + Object.keys(interfaceMap).join(", "));
finish();
</script>

View file

@ -0,0 +1,34 @@
<html>
<head>
<script src="harness.js"></script>
</head>
<body>
<script>
var onloads = 0;
function check(ev) {
is_a(ev, Event);
ev.preventDefault();
is(ev.defaultPrevented, false);
is(ev.target, document);
is(ev.currentTarget, window);
if (onloads == 2) {
finish();
}
}
window.onload = function(ev) {
_fail("this inline handler should be overwritten");
}
window.onload = function(ev) {
onloads++;
is(onloads, 1);
check(ev);
}
addEventListener("load", function(ev) {
onloads++;
is(onloads, 2);
check(ev);
});
</script>
</body>
</html>

View file

@ -0,0 +1,20 @@
<html>
<head>
<title></title>
<script src="harness.js"></script>
</head>
<body>
<script>
is(window.navigator, window.navigator);
is_a(window.navigator, Navigator);
var nav = window.navigator;
is(nav.product, "Gecko");
is(nav.taintEnabled(), false);
is(nav.appName, "Netscape");
is(nav.appCodeName, "Mozilla");
is(nav.platform, "");
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,233 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
function check_copy(orig, copy, type) {
is_not(orig, copy);
is_a(orig, type);
is_a(copy, type);
}
function create_element_and_check(localName, type) {
var element = document.createElement(localName);
var copy = element.cloneNode();
check_copy(element, copy, type);
}
// test1: createElement
{
create_element_and_check("a", HTMLAnchorElement);
create_element_and_check("abbr", HTMLElement);
create_element_and_check("acronym", HTMLElement);
create_element_and_check("address", HTMLElement);
create_element_and_check("applet", HTMLAppletElement);
create_element_and_check("area", HTMLAreaElement);
create_element_and_check("article", HTMLElement);
create_element_and_check("aside", HTMLElement);
create_element_and_check("audio", HTMLAudioElement);
create_element_and_check("b", HTMLElement);
create_element_and_check("base", HTMLBaseElement);
create_element_and_check("bdi", HTMLElement);
create_element_and_check("bdo", HTMLElement);
create_element_and_check("bgsound", HTMLElement);
create_element_and_check("big", HTMLElement);
create_element_and_check("blockquote",HTMLElement);
create_element_and_check("body", HTMLBodyElement);
create_element_and_check("br", HTMLBRElement);
create_element_and_check("button", HTMLButtonElement);
create_element_and_check("canvas", HTMLCanvasElement);
create_element_and_check("caption", HTMLTableCaptionElement);
create_element_and_check("center", HTMLElement);
create_element_and_check("cite", HTMLElement);
create_element_and_check("code", HTMLElement);
create_element_and_check("col", HTMLTableColElement);
create_element_and_check("colgroup", HTMLTableColElement);
create_element_and_check("data", HTMLDataElement);
create_element_and_check("datalist", HTMLDataListElement);
create_element_and_check("dd", HTMLElement);
create_element_and_check("del", HTMLModElement);
create_element_and_check("details", HTMLElement);
create_element_and_check("dfn", HTMLElement);
create_element_and_check("dir", HTMLDirectoryElement);
create_element_and_check("div", HTMLDivElement);
create_element_and_check("dl", HTMLDListElement);
create_element_and_check("dt", HTMLElement);
create_element_and_check("embed", HTMLEmbedElement);
create_element_and_check("fieldset", HTMLFieldSetElement);
create_element_and_check("figcaption",HTMLElement);
create_element_and_check("figure", HTMLElement);
create_element_and_check("font", HTMLFontElement);
create_element_and_check("footer", HTMLElement);
create_element_and_check("form", HTMLFormElement);
create_element_and_check("frame", HTMLFrameElement);
create_element_and_check("frameset", HTMLFrameSetElement);
create_element_and_check("h1", HTMLHeadingElement);
create_element_and_check("h2", HTMLHeadingElement);
create_element_and_check("h3", HTMLHeadingElement);
create_element_and_check("h4", HTMLHeadingElement);
create_element_and_check("h5", HTMLHeadingElement);
create_element_and_check("h6", HTMLHeadingElement);
create_element_and_check("head", HTMLHeadElement);
create_element_and_check("header", HTMLElement);
create_element_and_check("hgroup", HTMLElement);
create_element_and_check("hr", HTMLHRElement);
create_element_and_check("html", HTMLHtmlElement);
create_element_and_check("i", HTMLElement);
create_element_and_check("iframe", HTMLIFrameElement);
create_element_and_check("img", HTMLImageElement);
create_element_and_check("input", HTMLInputElement);
create_element_and_check("ins", HTMLModElement);
create_element_and_check("isindex", HTMLElement);
create_element_and_check("kbd", HTMLElement);
create_element_and_check("label", HTMLLabelElement);
create_element_and_check("legend", HTMLLegendElement);
create_element_and_check("li", HTMLLIElement);
create_element_and_check("link", HTMLLinkElement);
create_element_and_check("main", HTMLElement);
create_element_and_check("map", HTMLMapElement);
create_element_and_check("mark", HTMLElement);
create_element_and_check("marquee", HTMLElement);
create_element_and_check("meta", HTMLMetaElement);
create_element_and_check("meter", HTMLMeterElement);
create_element_and_check("nav", HTMLElement);
create_element_and_check("nobr", HTMLElement);
create_element_and_check("noframes", HTMLElement);
create_element_and_check("noscript", HTMLElement);
create_element_and_check("object", HTMLObjectElement);
create_element_and_check("ol", HTMLOListElement);
create_element_and_check("optgroup", HTMLOptGroupElement);
create_element_and_check("option", HTMLOptionElement);
create_element_and_check("output", HTMLOutputElement);
create_element_and_check("p", HTMLParagraphElement);
create_element_and_check("param", HTMLParamElement);
create_element_and_check("pre", HTMLPreElement);
create_element_and_check("progress", HTMLProgressElement);
create_element_and_check("q", HTMLQuoteElement);
create_element_and_check("rp", HTMLElement);
create_element_and_check("rt", HTMLElement);
create_element_and_check("ruby", HTMLElement);
create_element_and_check("s", HTMLElement);
create_element_and_check("samp", HTMLElement);
create_element_and_check("script", HTMLScriptElement);
create_element_and_check("section", HTMLElement);
create_element_and_check("select", HTMLSelectElement);
create_element_and_check("small", HTMLElement);
create_element_and_check("source", HTMLSourceElement);
create_element_and_check("spacer", HTMLElement);
create_element_and_check("span", HTMLSpanElement);
create_element_and_check("strike", HTMLElement);
create_element_and_check("style", HTMLStyleElement);
create_element_and_check("sub", HTMLElement);
create_element_and_check("summary", HTMLElement);
create_element_and_check("sup", HTMLElement);
create_element_and_check("table", HTMLTableElement);
create_element_and_check("tbody", HTMLTableSectionElement);
create_element_and_check("td", HTMLTableDataCellElement);
create_element_and_check("template", HTMLTemplateElement);
create_element_and_check("textarea", HTMLTextAreaElement);
create_element_and_check("th", HTMLTableHeaderCellElement);
create_element_and_check("time", HTMLTimeElement);
create_element_and_check("title", HTMLTitleElement);
create_element_and_check("tr", HTMLTableRowElement);
create_element_and_check("tt", HTMLElement);
create_element_and_check("track", HTMLTrackElement);
create_element_and_check("u", HTMLElement);
create_element_and_check("ul", HTMLUListElement);
create_element_and_check("var", HTMLElement);
create_element_and_check("video", HTMLVideoElement);
create_element_and_check("unknown", HTMLUnknownElement);
create_element_and_check("wbr", HTMLElement);
}
// test2: createDocumentFragment
{
var fragment = document.createDocumentFragment();
var copy = fragment.cloneNode();
check_copy(fragment, copy, DocumentFragment);
}
// test3: createTextNode
{
var text = document.createTextNode("hello world");
var copy = text.cloneNode();
check_copy(text, copy, Text);
is(text.data, copy.data);
is(text.wholeText, copy.wholeText);
}
// test4: createComment
{
var comment = document.createComment("a comment");
var copy = comment.cloneNode();
check_copy(comment, copy, Comment);
is(comment.data, copy.data);
}
// test5: createProcessingInstruction
{
var pi = document.createProcessingInstruction("target", "data");
var copy = pi.cloneNode();
check_copy(pi, copy, ProcessingInstruction);
is(pi.data, copy.data);
is(pi.target, pi.target);
}
// test6: implementation.createDocumentType
{
var doctype = document.implementation.createDocumentType("html", "public", "system");
var copy = doctype.cloneNode();
check_copy(doctype, copy, DocumentType);
is(doctype.name, copy.name);
is(doctype.publicId, copy.publicId);
is(doctype.systemId, copy.systemId);
}
// test7: implementation.createDocument
{
// FIXME: https://github.com/mozilla/servo/issues/1509
}
// test8: implementation.createHTMLDocument
{
var html = document.implementation.createHTMLDocument("title");
var copy = html.cloneNode();
check_copy(html, copy, Document);
is(html.title, copy.title);
}
// test9: node with children
{
var parent = document.createElement("div");
var child1 = document.createElement("div");
var child2 = document.createElement("div");
var grandChild = document.createElement("div");
child2.appendChild(grandChild);
parent.appendChild(child1);
parent.appendChild(child2);
var deep = true;
var copy = parent.cloneNode(deep);
check_copy(parent, copy, HTMLDivElement);
is(copy.childNodes.length, 2);
check_copy(child1, copy.childNodes[0], HTMLDivElement);
is(copy.childNodes[0].childNodes.length, 0);
check_copy(child2, copy.childNodes[1], HTMLDivElement);
is(copy.childNodes[1].childNodes.length, 1);
check_copy(grandChild, copy.childNodes[1].childNodes[0], HTMLDivElement);
deep = false;
copy = parent.cloneNode(deep);
check_copy(parent, copy, HTMLDivElement);
is(copy.childNodes.length, 0);
}
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
{
var elem = document.createElement("div");
var other = document.createElement("div");
is(elem.compareDocumentPosition(elem),0);
var nonTree = elem.compareDocumentPosition(other);
var prefix = Node.DOCUMENT_POSITION_DISCONNECTED + Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
is(nonTree == prefix + Node.DOCUMENT_POSITION_FOLLOWING || nonTree == prefix + Node.DOCUMENT_POSITION_PRECEDING,
true);
elem.appendChild(other);
is(elem.compareDocumentPosition(other), Node.DOCUMENT_POSITION_CONTAINED_BY + Node.DOCUMENT_POSITION_FOLLOWING);
is(other.compareDocumentPosition(elem), Node.DOCUMENT_POSITION_CONTAINS + Node.DOCUMENT_POSITION_PRECEDING);
var another = document.createElement("div");
other.appendChild(another);
is(elem.compareDocumentPosition(another), Node.DOCUMENT_POSITION_CONTAINED_BY + Node.DOCUMENT_POSITION_FOLLOWING);
is(another.compareDocumentPosition(elem), Node.DOCUMENT_POSITION_CONTAINS + Node.DOCUMENT_POSITION_PRECEDING);
var follower = document.createElement("div");
elem.appendChild(follower);
var preceder = document.createElement("div");
another.appendChild(preceder);
is(another.compareDocumentPosition(follower), Node.DOCUMENT_POSITION_FOLLOWING);
is(follower.compareDocumentPosition(another), Node.DOCUMENT_POSITION_PRECEDING);
is(follower.compareDocumentPosition(preceder), Node.DOCUMENT_POSITION_PRECEDING);
finish();
}
</script>
</head>
</html>

View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: Node.contains
{
var parent = document.createElement("div");
var child = document.createElement("div");
var child_of_child = document.createElement("div");
var other = document.createElement("div");
child.appendChild(child_of_child);
parent.appendChild(child);
is(parent.contains(parent), true, "test1-0, Node.contains");
is(parent.contains(child), true, "test1-1, Node.contains");
is(parent.contains(child_of_child), true, "test1-2, Node.contains");
is(parent.contains(other), false, "test1-3, Node.contains");
}
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,25 @@
<!doctype html>
<html>
<head>
<title>Node.insertBefore</title>
<script src="harness.js"></script>
</head>
<body>
<script type="text/javascript">
// test1: insertBefore
{
var root = document.createElement("div");
var after = document.createElement("div");
var before = document.createElement("div");
root.appendChild(after);
is(root.insertBefore(before, after), before, "test1-0, insertBefore");
is(root.childNodes[0], before, "test1-1, insertBefore");
is(root.childNodes[1], after, "test1-2, insertBefore");
finish();
}
</script>
</body>
</html>

View file

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: simple checks
{
var elem = document.createElement("div");
var other = document.createElement("div");
is(elem.isEqualNode(elem), true);
is(elem.isEqualNode(other), true);
is(other.isEqualNode(elem), true);
is(elem.isEqualNode(document), false);
}
// test2: non-element children
{
var parent_elem = document.createElement("div");
var child_elem = document.createElement("div");
parent_elem.appendChild(child_elem);
var other_parent = document.createElement("div");
var other_child = document.createElement("div");
other_parent.appendChild(other_child);
is(parent_elem.isEqualNode(other_parent), true);
is(child_elem.isEqualNode(other_child), true);
var child_text = document.createTextNode("lorem ipsum");
child_elem.appendChild(child_text);
is(parent_elem.isEqualNode(other_parent), false);
is(child_elem.isEqualNode(other_child), false);
}
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
</head>
<body>
<script>
// test1: Node.normalize
var parent1 = document.createElement("div");
var child1 = document.createTextNode("aaa");
var child2 = document.createTextNode("");
var child3 = document.createTextNode("bb");
var parent2 = document.createElement("div");
parent1.appendChild(child1);
parent1.appendChild(child2);
parent1.appendChild(child3);
parent2.appendChild(document.createTextNode(""));
parent1.normalize();
parent2.normalize();
is(Array.prototype.map.call(parent1.childNodes, function(el) {return el.length}).indexOf(0), -1, "Node.normalize removes empty text nodes");
is(parent1.childNodes.length, 1, "Node.normalize merges text nodes in one");
is(parent1.childNodes[0].length, 5, "test 1-2, Node.normalize merges text nodes values");
is(parent2.childNodes.length, 0, "Node.normalize removes empty text nodes even if there is only one text node");
is(child2.textContent, "", "Node.normalize doesn't change removed children original content")
is(child3.textContent, "bb", "Node.normalize doesn't change removed children original content")
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,52 @@
<!doctype html>
<html>
<head>
<script src="harness.js"></script>
</head>
<body>
<script>
// test1: 1-to-1
{
var root = document.createElement("div");
var elem = document.createElement("div");
var foo = document.createTextNode("foo");
var bar = document.createTextNode("bar");
elem.appendChild(bar);
is(elem.replaceChild(bar, bar), bar, "test1-0, 1-to-1");
is(elem.childNodes[0], bar, "test1-1, 1-to-1");
root.appendChild(foo);
is(root.replaceChild(bar, foo), foo, "test1-2, 1-to-1");
is(elem.childNodes.length, 0, "test1-3, 1-to-1");
is(root.childNodes[0], bar, "test1-4, 1-to-1");
elem.appendChild(foo);
is(root.replaceChild(elem, bar), bar, "test1-5, 1-to-1");
is(root.childNodes[0].childNodes[0], foo, "test1-6, 1-to-1");
}
// test2: doctype
{
var doc_doctype = document.doctype;
var new_doctype = document.implementation.createDocumentType("html", null, null);
is_not(doc_doctype, new_doctype, "test2-0, doctype");
is(document.replaceChild(new_doctype, doc_doctype), doc_doctype, "test2-1, doctype");
is(document.doctype, new_doctype, "test2-2, doctype");
}
// test3: documentElement
{
var doc_elem = document.documentElement;
var new_elem = document.createElement("html");
is_not(doc_elem, new_elem, "test3-0, documentElement");
is(document.replaceChild(new_elem, doc_elem), doc_elem, "test3-1, documentElement");
is(document.documentElement, new_elem, "test3-2, documentElement");
}
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,70 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
{ // document.querySelector
let div = document.getElementById("foo");
is(document.querySelector("#foo"), div);
div = document.getElementById("foo\\bar");
is(document.querySelector("#foo\\\\bar"), div);
div = document.getElementById("foo:bar");
is(document.querySelector("#foo\\:bar"), div);
div = document.getElementById("bar");
is(document.querySelector("div.myClass"), div);
is(document.querySelector("div:nth-of-type(4)"), div);
}
{ // element.querySelector
let body = document.body;
let div = document.getElementById("foo");
is(body.querySelector("#foo"), div);
div = document.getElementById("foo\\bar");
is(body.querySelector("#foo\\\\bar"), div);
div = document.getElementById("foo:bar");
is(body.querySelector("#foo\\:bar"), div);
div = document.getElementById("bar");
is(body.querySelector("div.myClass"), div);
is(body.querySelector("div:nth-of-type(4)"), div);
}
{ // docfrag.querySelector
let docfrag = document.createDocumentFragment();
let div = document.createElement("div");
div.id = "foo";
div.className = "myClass";
let child = document.createElement("div");
div.appendChild(child);
docfrag.appendChild(div);
let p = document.createElement("p");
p.id = "bar";
p.className = "myClass";
docfrag.appendChild(p);
is(docfrag.querySelector("#foo"), div);
is(docfrag.querySelector("div.myClass"), div);
is(docfrag.querySelector("#bar"), p);
is(docfrag.querySelector("p.myClass"), p);
is(docfrag.querySelector(".myClass"), div);
is(docfrag.querySelector("div > div"), child);
}
finish();
</script>
</head>
<body>
<div id="foo"></div>
<div id="foo\bar"></div>
<div id="foo:bar"></div>
<div id="bar" class="myClass"></p>
</body>
</html>

View file

@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
let foo = document.getElementById("foo");
let bar = document.getElementById("bar");
let baz = document.getElementById("baz");
{ // document.querySelector
let nodelist = document.querySelectorAll(".test");
is_a(nodelist, NodeList);
is(nodelist.length, 3);
is(nodelist.item(0), foo);
is(nodelist.item(1), bar);
is(nodelist.item(2), baz);
nodelist = document.querySelectorAll("div > .test");
is(nodelist.length, 3);
}
{ // element.querySelector
let div = document.getElementById("parent");
let nodelist = div.querySelectorAll(".test");
is(nodelist.length, 3);
nodelist = div.querySelectorAll("div:nth-of-type(1)");
is(nodelist.item(0), div);
}
{ // docfrag.querySelector
let docfrag = document.createDocumentFragment();
let div = document.createElement("div");
div.id = "foo";
div.className = "myClass";
let child = document.createElement("div");
div.appendChild(child);
docfrag.appendChild(div);
let nodelist = docfrag.querySelectorAll("#foo");
is(nodelist.item(0), div);
nodelist = docfrag.querySelectorAll("#foo:nth-child(1)");
is(nodelist.item(0), div);
}
finish();
</script>
</head>
<body>
<div id="parent">
<div id="foo" class="test"></div>
<div id="bar" class="test"></div>
<div id="baz" class="test"></div>
</div>
</body>
</html>

View file

@ -0,0 +1,25 @@
<html>
<head>
<title></title>
<script src="harness.js"></script>
</head>
<body>
<div id="div1"></div>
<script>
is_a(document.documentElement.parentNode, Document);
is(document.documentElement.parentElement, null);
var elem = document.createElement("p");
is(elem.parentNode, null);
is(elem.parentElement, null);
var child = document.createElement("p");
elem.appendChild(child);
is(child.parentNode, elem);
is(child.parentElement, elem);
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,24 @@
<html>
<head>
<meta charset="utf-8">
<script src="harness.js"></script>
</head>
<body>
<foo-á>foo</foo-á>
<script>
is_a(window.document, Node);
gc(); // ensure that our document rooting works; subsequent accesses should be valid.
is_a(window.document, Node);
is(window.document.nodeType, Node.DOCUMENT_NODE);
is_a(window.document.documentElement, Node);
is_a(window.document.documentElement, Element);
is_a(window.document.documentElement, HTMLElement);
is_a(window.document.documentElement, HTMLHtmlElement);
is_a(window.document, Document);
is(window.document.documentElement.tagName, "HTML");
is_a(window.document.getElementsByTagName('foo-á')[0], HTMLUnknownElement);
is(window.document.getElementsByTagName('foo-á')[0].tagName, "FOO-á");
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,14 @@
<html>
<head>
<title></title>
<script src="harness.js"></script>
</head>
<body>
<script>
is(window.document.title, '');
window.document.title = 'foo';
is(window.document.title, 'foo');
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,18 @@
<html>
<head id="foo">
<title></title>
<script src="harness.js"></script>
</head>
<script>
let script = document.getElementById("test");
{
is(script.src, "/x.js");
}
finish();
</script>
<body>
<script src="/x.js" id="test"/>
</body>
</html>

View file

@ -0,0 +1,101 @@
<html>
<head>
<title></title>
<script src="harness.js"></script>
</head>
<body>
<script>
expect(22);
function ok(msg) { _pass(msg, ""); }
function fail(msg) { _fail(msg, ""); }
</script>
<script type="">
ok('type is empty string');
</script>
<script language="">
ok('language is empty string');
</script>
<script type="text/javascript" language="vbscript">
ok('type is text/javascript, language ignored');
</script>
<script type="" language="fooscript">
ok('type is empty string, language ingored');
</script>
<script language="javascript">
ok('language is javascript');
</script>
<script language="ecmascript">
ok('language is ecmascript');
</script>
<!-- list found at http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting.html#support-the-scripting-language -->
<script type="application/ecmascript">
ok('type is application/ecmascript');
</script>
<script type="application/javascript">
ok('type is application/javascript');
</script>
<script type="application/x-ecmascript">
ok('type is application/x-ecmascript');
</script>
<script type="application/x-javascript">
ok('type is application/x-javascript');
</script>
<script type="text/ecmascript">
ok('type is text/ecmascript');
</script>
<script type="text/javascript">
ok('type is text/javascript');
</script>
<script type="text/javascript1.0">
ok('type is text/javascript1.0');
</script>
<script type="text/javascript1.1">
ok('type is text/javascript1.1');
</script>
<script type="text/javascript1.2">
ok('type is text/javascript1.2');
</script>
<script type="text/javascript1.3">
ok('type is text/javascript1.3');
</script>
<script type="text/javascript1.4">
ok('type is text/javascript1.4');
</script>
<script type="text/javascript1.5">
ok('type is text/javascript1.5');
</script>
<script type="text/jscript">
ok('type is text/jsscript');
</script>
<script type="text/livescript">
ok('type is text/livescript');
</script>
<script type="text/x-ecmascript">
ok('type is text/x-ecmascript');
</script>
<script type="text/x-javascript">
ok('type is text/x-javascript');
</script>
<!-- should not execute -->
<script type=" ">
fail('type is space');
</script>
<script type="foo">
fail('type is unknown');
</script>
<script type="text/javascript1.6">
fail('type is unknown');
</script>
<script language="text/javascript">
fail('language is text/javascript');
</script>
<script>
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,17 @@
<html>
<head>
<script src="harness.js"></script>
<script>
var div = document.getElementsByTagName('div')[0];
is(div.textContent, "this is\n text content");
var newContent = "new text con\ntent";
div.textContent = newContent;
is(div.textContent, newContent);
finish();
</script>
</head>
<body>
<div>this is
text content</div>
</body>
</html>

View file

@ -0,0 +1,12 @@
<html>
<head>
<title>starting title</title>
<script src="harness.js"></script>
<script>
is(document.title, "starting title");
document.title = "new title";
is(document.title, "new title");
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,7 @@
<!-- crashtest -->
<script src=harness.js></script>
<script>
new CustomEvent("foo", { detail: null });
gc();
finish();
</script>

View file

@ -0,0 +1,26 @@
<html>
<head>
<script src="harness.js"></script>
<select id="sel"></select>
<script>
var div = document.createElement('div');
var optgroup = document.createElement('optgroup');
var sel = document.getElementById('sel');
should_not_throw(function() {
var opt = document.createElement('option');
sel.add(opt);
sel.add(optgroup);
sel.add(opt, div);
sel.add(optgroup, div);
sel.add(opt, 5);
sel.add(optgroup, 5);
});
should_throw(function() { sel.add(div) });
should_not_throw(function() { sel.add(optgroup, function() {}) });
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,13 @@
<html>
<head>
<title></title>
<script src="harness.js"></script>
</head>
<body>
<script>
is(window, window.self);
is_a(window.self, Window);
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,28 @@
<html>
<head>
<title></title>
<script src="harness.js"></script>
</head>
<body>
<script>
is_not(window.performance, undefined);
is_a(window.performance, Performance);
is_not(window.performance.timing, undefined);
is_a(window.performance.timing, PerformanceTiming);
gt(window.performance.timing.navigationStart, 0);
var last = window.performance.now();
gt(last, 0);
// Check that window.performance.now() is monotonically increasing
for (var i = 0; i < 100; i++) {
var next = window.performance.now();
gt(next, last);
last = next;
}
finish();
</script>
</body>
</html>

View file

@ -0,0 +1,20 @@
<html>
<head>
<script src="harness.js"></script>
</head>
<body>
<script>
var x = 0;
var intervalID = setInterval(function() {
x += 1;
if (x == 2) {
clearInterval(intervalID);
setTimeout(function() {
is(x, 2);
finish();
}, 300);
}
}, 10);
</script>
</body>
</html>