2010-10-13 James Simonsen <simonjam@chromium.org>
[WebKit.git] / LayoutTests / html5lib / runner.html
1 <!doctype html>
2 <!--
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 -->
23 <title>html5lib test runner</title>
24 <script src=../resources/dump-as-markup.js></script>
25 <style>
26 .overview:hover {
27 background: #ccc;
28 }
29 iframe {
30 display: none;
31 }
32 </style>
33 <p>Script did not run</p>
34 <iframe></iframe>
35 <script>
36 Markup.noAutoDump();
37
38 var test_files = [
39         'resources/pending-spec-changes-plain-text-unsafe.dat',
40         'resources/pending-spec-changes.dat',
41         'resources/plain-text-unsafe.dat',
42         'resources/tests1.dat',
43         'resources/tests2.dat',
44         'resources/tests3.dat',
45         'resources/tests4.dat',
46         'resources/tests5.dat',
47         'resources/tests6.dat',
48         'resources/tests7.dat',
49         'resources/tests8.dat',
50         'resources/tests9.dat',
51         'resources/tests10.dat',
52         'resources/tests11.dat',
53         'resources/tests12.dat',
54         'resources/tests14.dat',
55         'resources/tests15.dat',
56         'resources/tests16.dat',
57         'resources/tests17.dat',
58         'resources/tests18.dat',
59         'resources/tests19.dat',
60         'resources/tests20.dat',
61         'resources/tests21.dat',
62         'resources/tests_innerHTML_1.dat',
63         'resources/webkit01.dat',
64         'resources/webkit02.dat',
65         'resources/doctype01.dat',
66         'resources/scriptdata01.dat',
67         'resources/html5test-com.dat',
68         'resources/entities01.dat',
69         'resources/entities02.dat',
70         'resources/comments01.dat',
71         'resources/adoption01.dat',
72         'resources/adoption02.dat',
73         'resources/inbody01.dat',
74         'resources/isindex.dat',
75         'resources/tables01.dat',
76         'resources/tricky01.dat',
77         'resources/scripted/adoption01.dat',
78         'resources/scripted/webkit01.dat'
79     ],
80     tests = [],
81     iframe = document.getElementsByTagName("iframe")[0],
82     stat = document.getElementsByTagName("p")[0].firstChild,
83     file = "",
84     test_number = 1,
85     fail_list = [],
86     log = "";
87
88 iframe.contentWindow.document.open()
89 iframe.contentWindow.document.write("Test");
90 iframe.contentWindow.document.close();
91 var write = iframe.contentWindow.document.lastChild.lastChild.lastChild !== null;
92 var ignoreTitle = iframe.contentWindow.document.getElementsByTagName("title")[0] !== undefined;
93
94 window.onload = function()
95 {
96     stat.data = "Running";
97     run();
98 }
99
100 function run()
101 {
102     var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
103     if (file = test_files.shift())
104     {
105         stat.data = "Retriving " + file;
106         test_number = 1;
107         fail_list = [];
108         log = "";
109         xhr.open("GET", file);
110         xhr.onreadystatechange = function()
111         {
112             if (xhr.readyState === 4)
113             {
114                 tests = xhr.responseText.split(/(?:^|\n\n)#data\n/);
115                 tests.shift();
116                 test();
117             }
118         }
119         xhr.send(null);
120     }
121 }
122
123 function test()
124 {
125     var input, errorsStart, fragmentStart, contextElement, domStart, dom;
126     if (data = tests.shift())
127     {
128         stat.data = "Running test " + test_number + " of " + (test_number + tests.length) + " in " + file;
129         errorsStart = data.indexOf("\n#errors\n");
130         if (errorsStart !== -1)
131         {
132             input = data.substring(0, errorsStart);
133             fragmentStart = data.indexOf("\n#document-fragment\n")
134             domStart = data.indexOf("\n#document\n")
135             if (fragmentStart !== -1)
136             {
137                 contextElement = data.substring(fragmentStart + 20, domStart);
138             }
139             if (domStart !== -1)
140             {
141                 dom = data.substring(domStart + 11);
142                 if (dom.substring(dom.length - 1) === "\n")
143                 {
144                     dom = dom.substring(0, dom.length - 1);
145                 }
146                 run_test(input, contextElement, dom);
147                 return;
148             }
149         }
150         alert("Invalid test: " + data);
151         test();
152         return;
153     }
154     else
155     {
156         stat.data = "Finished running " + file;
157         var overview = document.createElement("p");
158         if (fail_list.length)
159         {
160             overview.innerHTML = file + ":<br>" + fail_list.join("<br>");
161             overview.className = "overview";
162             overview.title = "Click for more details";
163             overview.onclick = function()
164             {
165                 this.nextSibling.style.display = this.nextSibling.style.display == "none" ? "block" : "none";
166             }
167             var detail = document.createElement("pre");
168             detail.appendChild(document.createTextNode(log.substring(2)));
169             detail.style.display = "block";
170             document.body.appendChild(overview);
171             document.body.appendChild(detail);
172         }
173         else
174         {
175             overview.innerHTML = file + ": PASS";
176             document.body.appendChild(overview);
177         }
178         stat.data = "";
179         run();
180     }
181 }
182
183 function run_test(input, contextElement, expected)
184 {
185     if (contextElement)
186     {
187         var element = document.createElement(contextElement);
188         try
189         {
190             element.innerHTML = input;
191         }
192         catch(e) {}
193         process_result(input, element, expected);
194     }
195     else if (write)
196     {
197         iframe.contentWindow.document.open();
198         try
199         {
200             iframe.contentWindow.document.write(input);
201         }
202         catch(e) {}
203         iframe.contentWindow.document.close();
204         if (ignoreTitle)
205         {
206             var title = iframe.contentWindow.document.getElementsByTagName("title")[0];
207             if (!title.innerHTML)
208             {
209                 title.parentElement.removeChild(title);
210             }
211         }
212         process_result(input, iframe.contentWindow.document, expected);
213     }
214     else
215     {
216         iframe.onload = function()
217         {
218             if (ignoreTitle)
219             {
220                 var title = iframe.contentWindow.document.getElementsByTagName("title")[0];
221                 if (!title.innerHTML)
222                 {
223                     title.parentElement.removeChild(title);
224                 }
225             }
226             process_result(input, iframe.contentWindow.document, expected);
227         }
228         iframe.src = "data:text/html," + encodeURIComponent(input);
229     }
230 }
231
232 function process_result(input, result, expected)
233 {
234     result = Markup.get(result);
235     if (result !== expected)
236     {
237         fail_list.push(test_number);
238         log += "\n\nTest " + (test_number) + " of " + (test_number + tests.length) + " in " + file + " failed. Input:\n" + input + "\nGot:\n" + result + "\nExpected:\n" + expected;
239     }
240     test_number++;
241     test();
242 }
243 </script>