Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / html5lib / webkit-resumer.html
blob8bac2462bce283b673bb035cfac66bedd8992c53
1 <title>html5lib test runner</title>
2 <script>
3 // Copyright (c) 2008 Geoffrey Sneddon
4 //
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:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
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
21 // THE SOFTWARE.
22 </script>
23 <script src=../resources/dump-as-markup.js></script>
24 <style>
25 .overview:hover {
26 background: #ccc;
28 iframe {
29 display: none;
31 </style>
32 <p>Script did not run</p>
33 <iframe></iframe>
34 <script>
35 if (window.testRunner)
36 testRunner.waitUntilDone();
37 Markup.noAutoDump();
38 Markup.useHTML5libOutputFormat();
40 var test_files = [
41 // 'resources/tests1.dat',
42 // 'resources/tests2.dat',
43 // 'resources/tests3.dat',
44 // 'resources/tests4.dat',
45 // 'resources/tests5.dat',
46 // 'resources/tests6.dat',
47 // 'resources/tests7.dat',
48 // 'resources/tests8.dat',
49 // 'resources/tests9.dat',
50 // 'resources/tests10.dat',
51 // 'resources/tests11.dat',
52 // 'resources/tests12.dat',
53 // 'resources/tests14.dat',
54 // 'resources/tests15.dat',
55 // 'resources/tests16.dat',
56 'resources/webkit01.dat',
57 // 'resources/doctype01.dat',
58 // 'resources/scriptdata01.dat',
59 // 'resources/entities01.dat',
60 // 'resources/comments01.dat'
62 tests = [],
63 iframe = document.getElementsByTagName("iframe")[0],
64 stat = document.getElementsByTagName("p")[0].firstChild,
65 file = "",
66 test_number = 1,
67 subtest_number = 0,
68 fail_list = [],
69 log = "";
71 iframe.contentWindow.document.open()
72 iframe.contentWindow.document.write("Test");
73 iframe.contentWindow.document.close();
74 var write = iframe.contentWindow.document.lastChild.lastChild.lastChild !== null;
75 var ignoreTitle = iframe.contentWindow.document.getElementsByTagName("title")[0] !== undefined;
77 window.onload = function()
79 stat.data = "Running";
80 run();
83 function run()
85 var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
86 if (file = test_files.shift())
88 stat.data = "Retriving " + file;
89 test_number = 1;
90 fail_list = [];
91 log = "";
92 xhr.open("GET", file);
93 xhr.onreadystatechange = function()
95 if (xhr.readyState === 4)
97 tests = xhr.responseText.split(/(?:^|\n\n)#data\n/);
98 tests.shift();
99 test();
102 xhr.send(null);
103 } else {
104 if (window.testRunner)
105 testRunner.notifyDone();
109 function test()
111 var input, errorsStart, fragmentStart, contextElement, domStart, dom;
112 if (data = tests.shift())
114 subtest_number = 0;
115 stat.data = "Running test " + test_number + " of " + (test_number + tests.length) + " in " + file;
116 errorsStart = data.indexOf("\n#errors\n");
117 if (errorsStart !== -1)
119 input = data.substring(0, errorsStart);
120 fragmentStart = data.indexOf("\n#document-fragment\n")
121 domStart = data.indexOf("\n#document\n")
122 if (fragmentStart !== -1)
124 contextElement = data.substring(fragmentStart + 20, domStart);
126 if (domStart !== -1)
128 dom = data.substring(domStart + 11);
129 if (dom.substring(dom.length - 1) === "\n")
131 dom = dom.substring(0, dom.length - 1);
133 run_test(input, contextElement, dom);
134 return;
137 alert("Invalid test: " + data);
138 test();
139 return;
141 else
143 stat.data = "Finished running " + file;
144 var overview = document.createElement("p");
145 if (fail_list.length)
147 overview.innerHTML = file + ":<br>" + fail_list.join("<br>");
148 overview.className = "overview";
149 overview.title = "Click for more details";
150 overview.onclick = function()
152 this.nextSibling.style.display = this.nextSibling.style.display == "none" ? "block" : "none";
154 var detail = document.createElement("pre");
155 detail.appendChild(document.createTextNode(log.substring(2)));
156 detail.style.display = "none";
157 document.body.appendChild(overview);
158 document.body.appendChild(detail);
160 else
162 overview.innerHTML = file + ": PASS";
163 document.body.appendChild(overview);
165 stat.data = "";
166 run();
170 function run_test(input, contextElement, expected)
172 while (++subtest_number < input.length) {
173 lower_input = input.substring(0, subtest_number);
174 upper_input = input.substring(subtest_number, input.length);
175 if (contextElement)
177 var element = document.createElement(contextElement);
180 element.innerHTML = input;
182 catch(e) {}
183 process_result(input, element, expected);
185 else if (write)
187 iframe.contentWindow.document.open();
190 iframe.contentWindow.document.write(lower_input);
191 iframe.contentWindow.document.write(upper_input);
193 catch(e) {}
194 iframe.contentWindow.document.close();
195 if (ignoreTitle)
197 var title = iframe.contentWindow.document.getElementsByTagName("title")[0];
198 if (!title.innerHTML)
200 title.parentElement.removeChild(title);
203 process_result(input, iframe.contentWindow.document, expected);
205 else
207 iframe.onload = function()
209 if (ignoreTitle)
211 var title = iframe.contentWindow.document.getElementsByTagName("title")[0];
212 if (!title.innerHTML)
214 title.parentElement.removeChild(title);
217 process_result(input, iframe.contentWindow.document, expected, true);
219 iframe.src = "data:text/html," + encodeURIComponent(input);
220 break;
223 test();
226 function process_result(input, result, expected, async)
228 result = Markup.get(result);
229 if (result !== expected)
231 fail_list.push(test_number + "." + subtest_number);
232 log += "\n\nTest " + (test_number) + " of " + (test_number + tests.length) + " in " + file + " failed. Input:\n" + input + "\nGot:\n" + result + "\nExpected:\n" + expected;
234 test_number++;
235 if (async)
236 test();
238 </script>