3 Copyright (c) 2008 Geoffrey Sneddon
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 <title>html5lib test runner</title>
24 <script src=../resources/dump-as-markup.js></script>
33 <p>Script did not run</p>
39 'resources/tests1.dat',
40 'resources/tests2.dat',
41 'resources/tests3.dat',
42 'resources/tests4.dat',
43 'resources/tests5.dat',
44 'resources/tests6.dat',
45 'resources/tests7.dat',
46 'resources/tests8.dat',
47 'resources/tests9.dat',
48 'resources/tests10.dat',
49 'resources/tests11.dat',
50 'resources/tests12.dat',
51 'resources/tests14.dat',
52 'resources/tests15.dat',
53 'resources/tests16.dat',
54 'resources/tests17.dat',
55 'resources/tests18.dat',
56 'resources/tests19.dat',
57 'resources/tests20.dat',
58 'resources/webkit01.dat',
59 'resources/webkit02.dat',
60 'resources/doctype01.dat',
61 'resources/scriptdata01.dat',
62 'resources/html5test-com.dat',
63 'resources/entities01.dat',
64 'resources/entities02.dat',
65 'resources/comments01.dat',
66 'resources/adoption01.dat',
67 'resources/adoption02.dat',
68 'resources/inbody01.dat',
69 'resources/isindex.dat',
70 'resources/tables01.dat',
71 'resources/tricky01.dat',
72 'resources/scripted/adoption01.dat',
73 'resources/scripted/webkit01.dat'
76 iframe = document.getElementsByTagName("iframe")[0],
77 stat = document.getElementsByTagName("p")[0].firstChild,
83 iframe.contentWindow.document.open()
84 iframe.contentWindow.document.write("Test");
85 iframe.contentWindow.document.close();
86 var write = iframe.contentWindow.document.lastChild.lastChild.lastChild !== null;
87 var ignoreTitle = iframe.contentWindow.document.getElementsByTagName("title")[0] !== undefined;
89 window.onload = function()
91 stat.data = "Running";
97 var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
98 if (file = test_files.shift())
100 stat.data = "Retriving " + file;
104 xhr.open("GET", file);
105 xhr.onreadystatechange = function()
107 if (xhr.readyState === 4)
109 tests = xhr.responseText.split(/(?:^|\n\n)#data\n/);
120 var input, errorsStart, fragmentStart, contextElement, domStart, dom;
121 if (data = tests.shift())
123 stat.data = "Running test " + test_number + " of " + (test_number + tests.length) + " in " + file;
124 errorsStart = data.indexOf("\n#errors\n");
125 if (errorsStart !== -1)
127 input = data.substring(0, errorsStart);
128 fragmentStart = data.indexOf("\n#document-fragment\n")
129 domStart = data.indexOf("\n#document\n")
130 if (fragmentStart !== -1)
132 contextElement = data.substring(fragmentStart + 20, domStart);
136 dom = data.substring(domStart + 11);
137 if (dom.substring(dom.length - 1) === "\n")
139 dom = dom.substring(0, dom.length - 1);
141 run_test(input, contextElement, dom);
145 alert("Invalid test: " + data);
151 stat.data = "Finished running " + file;
152 var overview = document.createElement("p");
153 if (fail_list.length)
155 overview.innerHTML = file + ":<br>" + fail_list.join("<br>");
156 overview.className = "overview";
157 overview.title = "Click for more details";
158 overview.onclick = function()
160 this.nextSibling.style.display = this.nextSibling.style.display == "none" ? "block" : "none";
162 var detail = document.createElement("pre");
163 detail.appendChild(document.createTextNode(log.substring(2)));
164 detail.style.display = "block";
165 document.body.appendChild(overview);
166 document.body.appendChild(detail);
170 overview.innerHTML = file + ": PASS";
171 document.body.appendChild(overview);
178 function run_test(input, contextElement, expected)
182 var element = document.createElement(contextElement);
185 element.innerHTML = input;
188 process_result(input, element, expected);
192 iframe.contentWindow.document.open();
195 iframe.contentWindow.document.write(input);
198 iframe.contentWindow.document.close();
201 var title = iframe.contentWindow.document.getElementsByTagName("title")[0];
202 if (!title.innerHTML)
204 title.parentElement.removeChild(title);
207 process_result(input, iframe.contentWindow.document, expected);
211 iframe.onload = function()
215 var title = iframe.contentWindow.document.getElementsByTagName("title")[0];
216 if (!title.innerHTML)
218 title.parentElement.removeChild(title);
221 process_result(input, iframe.contentWindow.document, expected);
223 iframe.src = "data:text/html," + encodeURIComponent(input);
227 function process_result(input, result, expected)
229 result = Markup.get(result);
230 if (result !== expected)
232 fail_list.push(test_number);
233 log += "\n\nTest " + (test_number) + " of " + (test_number + tests.length) + " in " + file + " failed. Input:\n" + input + "\nGot:\n" + result + "\nExpected:\n" + expected;