Replace test_bindings.html with various content tests

Fixes #631.
This commit is contained in:
Keegan McAllister 2013-10-14 16:40:01 -07:00
parent 4bb2a70e08
commit 396a375e9c
10 changed files with 311 additions and 369 deletions

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);
//alert(parser.parseFromString("<html></html>", "text/html"));
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,21 @@
<html>
<head>
<script src="harness.js"></script>
<script>
is_function(Event, "Event");
/* broken due to #1042
let ev = new Event("foopy");
is_a(ev, Event);
// FIXME: assert correct values
alert(ev.type);
alert(ev.defaultPrevented);
ev.preventDefault();
alert(ev.defaultPrevented);
*/
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,22 @@
<html>
<head>
<script src="harness.js"></script>
<script>
is_function(MouseEvent, "MouseEvent");
/* broken due to #1042
let ev = new MouseEvent("press", {bubbles: true, screenX: 150, detail: 100});
// FIXME: assert correct values
alert(ev);
alert(ev.screenX);
alert(ev.detail);
alert(ev.getModifierState("ctrl"));
is_a(ev, Event);
is_a(ev, UIEvent);
*/
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,140 @@
<html>
<head>
<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], null);
if (classes === undefined)
return;
classes = [Element, HTMLElement].concat(classes);
for (var i=0; i<obj.length; i++) {
isnot(obj[i], null);
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) {
check_collection(document.getElementsByTagName(tagname), num, classes, tagname.toUpperCase());
}
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.getElementsByName("test"), 2);
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]);
// FIXME: Test non-ASCII tag names
check_tag("foo", 1, [HTMLUnknownElement]);
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,14 @@
<html>
<head>
<script src="harness.js"></script>
<script>
is_a(window, Window);
is_a(document.documentElement, HTMLHtmlElement);
is_a(document.documentElement.firstChild, HTMLHtmlElement);
is(document.documentElement.nextSibling, null);
is_a(document, HTMLDocument);
is_a(document, Document);
finish();
</script>
</head>
</html>

View file

@ -0,0 +1,32 @@
<html>
<head>
<script src="harness.js"></script>
<script>
is_function(ClientRect, "ClientRect");
is_function(ClientRectList, "ClientRectList");
var elems = document.getElementsByTagName('div');
var rect = elems[0].getBoundingClientRect();
is_a(rect, ClientRect);
geq(rect.top, 100);
geq(rect.bottom, 100);
geq(rect.left, 100);
geq(rect.right, 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;
}
</style>
</head>
<body>
<div>my div</div>
</body>
</html>

View file

@ -0,0 +1,40 @@
<html>
<head>
<script src="harness.js"></script>
<script>
var elems = document.getElementsByTagName('div');
var rects = elems[0].getClientRects();
is_a(rects, ClientRectList);
is(rects.length, 3);
for (var i=0; i<rects.length; i++) {
var rect = rects[i];
is_a(rect, ClientRect);
geq(rect.top, 100);
geq(rect.bottom, 100);
geq(rect.left, 100);
geq(rect.right, 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;
}
</style>
</head>
<body>
<div>
my div
<div>foo</div>
<div>bar</div>
</div>
</body>
</html>

View file

@ -0,0 +1,18 @@
<html>
<head>
<script src="harness.js"></script>
<script>
var elems = document.getElementsByTagName('div');
is(elems.length, 2);
let elem = elems[0];
is(elem.nodeType, 1);
is_a(elem, HTMLDivElement);
is(elem.tagName, "DIV");
finish();
</script>
</head>
<body>
<div>div one</div>
<div>div two</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

@ -1,369 +0,0 @@
<!DOCTYPE html>
<html>
<!-- comment -->
<head>
<title>test_binding
page </title>
<base href="./"></base>
<script>
//window.alert(ClientRect);
//window.alert(ClientRectList);
window.alert(window);
var document = window.document;
window.alert("==1==");
window.alert(document.documentElement);
window.alert(document.documentElement.firstChild);
window.alert(document.documentElement.nextSibling);
window.alert(document instanceof HTMLDocument);
window.alert(document instanceof Document);
var elems = document.getElementsByTagName('div');
window.alert(elems.length);
let elem = elems[0];
window.alert(elem.nodeType);
window.alert(elem);
window.alert("==1.5==");
var rect = elem.getBoundingClientRect();
window.alert(rect);
window.alert(rect.top);
window.alert(rect.bottom);
window.alert(rect.left);
window.alert(rect.right);
window.alert(rect.width);
window.alert(rect.height);
window.alert("==2==");
var rects = elem.getClientRects();
window.alert("==3==");
window.alert(rects);
window.alert(rects.length);
window.alert("==4==");
let rect = rects[0];
window.alert(rect);
/*window.alert(Object.prototype.toString.call(rect.__proto__));
window.alert(rect.__proto__ === Object.getPrototypeOf(rect));
window.alert(rect.__proto__.top);
window.alert(Object.getPrototypeOf(rect).top);*/
window.alert(rect.top);
window.alert(rect.bottom);
window.alert(rect.left);
window.alert(rect.right);
window.alert(rect.width);
window.alert(rect.height);
window.alert("HTMLCollection:");
let tags = document.getElementsByTagName("div");
//let tag = tags[0];
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0]);
window.alert(tags[0].tagName);
window.alert(tags[0].getClientRects());
window.alert(tags[1]);
window.alert(tags[2]);
window.alert(tags[3]);
let tags = document.getElementsByName("test");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0]);
window.alert(tags[0].tagName);
window.alert(tags[1]);
window.alert(tags[1].tagName);
window.alert(tags[2]);
let tags = document.links;
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0]);
window.alert(tags[0].tagName);
let tags = document.images;
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0]);
window.alert(tags[0].tagName);
let tags = document.embeds;
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0]);
window.alert(tags[0].tagName);
let tags = document.plugins;
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0]);
window.alert(tags[0].tagName);
let tags = document.forms;
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0]);
window.alert(tags[0].tagName);
let tags = document.scripts;
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0]);
window.alert(tags[0].tagName);
let tags = document.applets;
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0]);
window.alert(tags[0].tagName);
window.alert("Document:");
let head = document.head;
window.alert(head);
window.alert(head.tagName);
window.alert("DOMParser:");
window.alert(DOMParser);
let parser = new DOMParser();
window.alert(parser);
//window.alert(parser.parseFromString("<html></html>", "text/html"));
window.alert("Event:");
window.alert(Event);
let ev = new Event("foopy");
window.alert(ev.type);
window.alert(ev.defaultPrevented);
ev.preventDefault();
window.alert(ev.defaultPrevented);
window.alert("MouseEvent:");
window.alert(MouseEvent);
let ev2 = new MouseEvent("press", {bubbles: true, screenX: 150, detail: 100});
window.alert(ev2);
window.alert(ev2.screenX);
window.alert(ev2.detail);
window.alert(ev2.getModifierState("ctrl"));
window.alert(ev2 instanceof Event);
window.alert(ev2 instanceof UIEvent);
window.alert(document.title);
document.title = "foo";
window.alert(document.title);
window.alert(document.links[0]);
window.alert(document.getElementsByTagName('iframe')[0]);
window.alert(document.getElementsByTagName("body")[0]);
window.alert(document.getElementsByTagName("area")[0]);
window.alert(document.getElementsByTagName("base")[0]);
window.alert(document.getElementsByTagName("data")[0]);
window.alert("OList:");
let tags = document.getElementsByTagName("ol");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0]);
window.alert(tags[0].tagName);
window.alert("HTMLElement:");
let tagList = ["section", "aside", "b", "i", "small"];
for (let i = 0, l = tagList.length; i < l; ++i) {
let tags = document.getElementsByTagName(tagList[i]);
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLElement);
}
window.alert("HTMLCanvasElement:");
let tags = document.getElementsByTagName("canvas");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLCanvasElement);
window.alert("HTMLSourceElement:");
let tags = document.getElementsByTagName("source");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLSourceElement);
window.alert("HTMLTimeElement:");
let tags = document.getElementsByTagName("time");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLTimeElement);
window.alert("HTMLTableCaptionElement:");
let tags = document.getElementsByTagName("caption");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLTableCaptionElement);
window.alert("HTMLTextAreaElement:");
let tags = document.getElementsByTagName("textarea");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLTextAreaElement);
window.alert("HTMLQuoteElement:");
let tags = document.getElementsByTagName("q");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLQuoteElement);
window.alert("HTMLTableHeaderCellElement:");
let tags = document.getElementsByTagName("th");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLTableCellElement);
window.alert(tags[0] instanceof HTMLTableHeaderCellElement);
window.alert("HTMLTableDataCellElement:");
let tags = document.getElementsByTagName("td");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLTableCellElement);
window.alert(tags[0] instanceof HTMLTableDataCellElement);
window.alert("HTMLTableColElement");
let tagList = ["col", "colgroup"];
for (let i = 0, l = tagList.length; i < l; ++i) {
let tags = document.getElementsByTagName(tagList[i]);
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLTableColElement);
}
window.alert("HTMLInputElement:");
let tags = document.getElementsByTagName("input");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLInputElement);
window.alert("HTMLLIElement:");
let tags = document.getElementsByTagName("li");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLLLIElement);
window.alert("HTMLProgressElement:");
let tags = document.getElementsByTagName("progress");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLProgressElement);
window.alert("HTMLTemplateElement:");
let tags = document.getElementsByTagName("template");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLTemplateElement);
window.alert("HTMLPreElement:");
let tags = document.getElementsByTagName("pre");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLPreElement);
window.alert("HTMLLegendElement:");
let tags = document.getElementsByTagName("legend");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLLegendElement);
window.alert("HTMLLabelElement:");
let tags = document.getElementsByTagName("label");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLLabelElement);
window.alert("HTMLTrackElement:");
let tags = document.getElementsByTagName("track");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLTrackElement);
window.alert("HTMLAudioElement:");
let tags = document.getElementsByTagName("audio");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLMediaElement);
window.alert(tags[0] instanceof HTMLAudioElement);
window.alert("HTMLVideoElement:");
let tags = document.getElementsByTagName("video");
window.alert(tags);
window.alert(tags.length);
window.alert(tags[0].tagName);
window.alert(tags[0] instanceof HTMLMediaElement);
window.alert(tags[0] instanceof HTMLVideoElement);
//TODO: Doesn't work until we throw proper exceptions instead of returning 0 on
// unwrap failure.
/*try {
Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rects), "length").get.call(window);
window.alert("hmm?");
} catch (x) {
window.alert("ok");
}*/
</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><td>head</td></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>
<audio>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
</audio>
<area></area>
<data></data>
<template></template>
<pre>pre</pre>
<video src="">
<track></track>
</video>
</body>
</html>