1 <title>html5lib test runner</title>
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 <script src=../resources/dump-as-markup.js></script>
32 <p>Script did not run</p>
38 // 'resources/tests1.dat',
39 // 'resources/tests2.dat',
40 // 'resources/tests3.dat',
41 // 'resources/tests4.dat',
42 // 'resources/tests5.dat',
43 // 'resources/tests6.dat',
44 // 'resources/tests7.dat',
45 // 'resources/tests8.dat',
46 // 'resources/tests9.dat',
47 // 'resources/tests10.dat',
48 // 'resources/tests11.dat',
49 // 'resources/tests12.dat',
50 // 'resources/tests14.dat',
51 // 'resources/tests15.dat',
52 // 'resources/tests16.dat',
53 'resources/webkit01.dat',
54 // 'resources/doctype01.dat',
55 // 'resources/scriptdata01.dat',
56 // 'resources/entities01.dat',
57 // 'resources/comments01.dat'
60 iframe = document.getElementsByTagName("iframe")[0],
61 stat = document.getElementsByTagName("p")[0].firstChild,
68 iframe.contentWindow.document.open()
69 iframe.contentWindow.document.write("Test");
70 iframe.contentWindow.document.close();
71 var write = iframe.contentWindow.document.lastChild.lastChild.lastChild !== null;
72 var ignoreTitle = iframe.contentWindow.document.getElementsByTagName("title")[0] !== undefined;
74 window.onload = function()
76 stat.data = "Running";
82 var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
83 if (file = test_files.shift())
85 stat.data = "Retriving " + file;
89 xhr.open("GET", file);
90 xhr.onreadystatechange = function()
92 if (xhr.readyState === 4)
94 tests = xhr.responseText.split(/(?:^|\n\n)#data\n/);
105 var input, errorsStart, fragmentStart, contextElement, domStart, dom;
106 if (data = tests.shift())
109 stat.data = "Running test " + test_number + " of " + (test_number + tests.length) + " in " + file;
110 errorsStart = data.indexOf("\n#errors\n");
111 if (errorsStart !== -1)
113 input = data.substring(0, errorsStart);
114 fragmentStart = data.indexOf("\n#document-fragment\n")
115 domStart = data.indexOf("\n#document\n")
116 if (fragmentStart !== -1)
118 contextElement = data.substring(fragmentStart + 20, domStart);
122 dom = data.substring(domStart + 11);
123 if (dom.substring(dom.length - 1) === "\n")
125 dom = dom.substring(0, dom.length - 1);
127 run_test(input, contextElement, dom);
131 alert("Invalid test: " + data);
137 stat.data = "Finished running " + file;
138 var overview = document.createElement("p");
139 if (fail_list.length)
141 overview.innerHTML = file + ":<br>" + fail_list.join("<br>");
142 overview.className = "overview";
143 overview.title = "Click for more details";
144 overview.onclick = function()
146 this.nextSibling.style.display = this.nextSibling.style.display == "none" ? "block" : "none";
148 var detail = document.createElement("pre");
149 detail.appendChild(document.createTextNode(log.substring(2)));
150 detail.style.display = "none";
151 document.body.appendChild(overview);
152 document.body.appendChild(detail);
156 overview.innerHTML = file + ": PASS";
157 document.body.appendChild(overview);
164 function run_test(input, contextElement, expected)
166 while (++subtest_number < input.length) {
167 lower_input = input.substring(0, subtest_number);
168 upper_input = input.substring(subtest_number, input.length);
171 var element = document.createElement(contextElement);
174 element.innerHTML = input;
177 process_result(input, element, expected);
181 iframe.contentWindow.document.open();
184 iframe.contentWindow.document.write(lower_input);
185 iframe.contentWindow.document.write(upper_input);
188 iframe.contentWindow.document.close();
191 var title = iframe.contentWindow.document.getElementsByTagName("title")[0];
192 if (!title.innerHTML)
194 title.parentElement.removeChild(title);
197 process_result(input, iframe.contentWindow.document, expected);
201 iframe.onload = function()
205 var title = iframe.contentWindow.document.getElementsByTagName("title")[0];
206 if (!title.innerHTML)
208 title.parentElement.removeChild(title);
211 process_result(input, iframe.contentWindow.document, expected, true);
213 iframe.src = "data:text/html," + encodeURIComponent(input);
220 function process_result(input, result, expected, async)
222 result = Markup.get(result);
223 if (result !== expected)
225 fail_list.push(test_number + "." + subtest_number);
226 log += "\n\nTest " + (test_number) + " of " + (test_number + tests.length) + " in " + file + " failed. Input:\n" + input + "\nGot:\n" + result + "\nExpected:\n" + expected;