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>
35 if (window
.testRunner
)
36 testRunner
.waitUntilDone();
38 Markup
.useHTML5libOutputFormat();
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'
63 iframe
= document
.getElementsByTagName("iframe")[0],
64 stat
= document
.getElementsByTagName("p")[0].firstChild
,
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";
85 var xhr
= window
.XMLHttpRequest
? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
86 if (file
= test_files
.shift())
88 stat
.data
= "Retriving " + file
;
92 xhr
.open("GET", file
);
93 xhr
.onreadystatechange = function()
95 if (xhr
.readyState
=== 4)
97 tests
= xhr
.responseText
.split(/(?:^|\n\n)#data\n/);
104 if (window
.testRunner
)
105 testRunner
.notifyDone();
111 var input
, errorsStart
, fragmentStart
, contextElement
, domStart
, dom
;
112 if (data
= tests
.shift())
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
);
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
);
137 alert("Invalid test: " + data
);
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
);
162 overview
.innerHTML
= file
+ ": PASS";
163 document
.body
.appendChild(overview
);
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
);
177 var element
= document
.createElement(contextElement
);
180 element
.innerHTML
= input
;
183 process_result(input
, element
, expected
);
187 iframe
.contentWindow
.document
.open();
190 iframe
.contentWindow
.document
.write(lower_input
);
191 iframe
.contentWindow
.document
.write(upper_input
);
194 iframe
.contentWindow
.document
.close();
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
);
207 iframe
.onload = function()
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
);
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
;