1 // Copyright (c) 2008 Geoffrey Sneddon
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 document
.writeln("<title>html5lib test runner</title>");
22 document
.writeln("<style>");
23 document
.writeln(".overview:hover {");
24 document
.writeln("background: #ccc;");
25 document
.writeln("}");
26 document
.writeln("iframe {");
27 document
.writeln("display: none;");
28 document
.writeln("}");
29 document
.writeln("</style>");
30 document
.writeln("<p>Script did not run</p>");
31 document
.writeln("<iframe></iframe>");
33 if (window
.testRunner
)
34 testRunner
.waitUntilDone();
37 Markup
.useHTML5libOutputFormat();
40 iframe
= document
.getElementsByTagName("iframe")[0],
41 stat
= document
.getElementsByTagName("p")[0].firstChild
,
47 iframe
.contentWindow
.document
.open()
48 iframe
.contentWindow
.document
.write("Test");
49 iframe
.contentWindow
.document
.close();
50 var write
= iframe
.contentWindow
.document
.lastChild
.lastChild
.lastChild
!== null;
51 var ignoreTitle
= iframe
.contentWindow
.document
.getElementsByTagName("title")[0] !== undefined;
53 if (window
.forceDataURLs
)
56 window
.onload = function()
58 stat
.data
= "Running";
64 var xhr
= window
.XMLHttpRequest
? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
65 if (file
= test_files
.shift())
67 stat
.data
= "Retriving " + file
;
71 xhr
.open("GET", file
);
72 xhr
.onreadystatechange = function()
74 if (xhr
.readyState
=== 4)
76 tests
= xhr
.responseText
.split(/(?:^|\n\n)#data\n/);
83 if (window
.testRunner
)
84 testRunner
.notifyDone();
90 var input
, errorsStart
, fragmentStart
, contextElement
, domStart
, dom
;
91 if (data
= tests
.shift())
93 stat
.data
= "Running test " + test_number
+ " of " + (test_number
+ tests
.length
) + " in " + file
;
94 errorsStart
= data
.indexOf("\n#errors\n");
95 if (errorsStart
!== -1)
97 input
= data
.substring(0, errorsStart
);
98 fragmentStart
= data
.indexOf("\n#document-fragment\n")
99 domStart
= data
.indexOf("\n#document\n")
100 if (fragmentStart
!== -1)
102 contextElement
= data
.substring(fragmentStart
+ 20, domStart
);
106 dom
= data
.substring(domStart
+ 11);
107 if (dom
.substring(dom
.length
- 1) === "\n")
109 dom
= dom
.substring(0, dom
.length
- 1);
111 run_test(input
, contextElement
, dom
);
115 alert("Invalid test: " + data
);
121 stat
.data
= "Finished running " + file
;
122 var overview
= document
.createElement("p");
123 if (fail_list
.length
)
125 overview
.innerHTML
= file
+ ":<br>" + fail_list
.join("<br>");
126 overview
.className
= "overview";
127 overview
.title
= "Click for more details";
128 overview
.onclick = function()
130 this.nextSibling
.style
.display
= this.nextSibling
.style
.display
== "none" ? "block" : "none";
132 var detail
= document
.createElement("pre");
133 detail
.appendChild(document
.createTextNode(log
.substring(2)));
134 detail
.style
.display
= "block";
135 document
.body
.appendChild(overview
);
136 document
.body
.appendChild(detail
);
140 overview
.innerHTML
= file
+ ": PASS";
141 document
.body
.appendChild(overview
);
148 function run_test(input
, contextElement
, expected
)
152 var element
= document
.createElement(contextElement
);
155 element
.innerHTML
= input
;
158 process_result(input
, element
, expected
);
162 iframe
.contentWindow
.document
.open();
165 iframe
.contentWindow
.document
.write(input
);
168 iframe
.contentWindow
.document
.close();
171 var title
= iframe
.contentWindow
.document
.getElementsByTagName("title")[0];
172 if (!title
.innerHTML
)
174 title
.parentElement
.removeChild(title
);
177 process_result(input
, iframe
.contentWindow
.document
, expected
);
181 iframe
.onload = function()
185 var title
= iframe
.contentWindow
.document
.getElementsByTagName("title")[0];
186 if (!title
.innerHTML
)
188 title
.parentElement
.removeChild(title
);
191 process_result(input
, iframe
.contentWindow
.document
, expected
);
193 iframe
.src
= "data:text/html," + encodeURIComponent(input
);
197 function process_result(input
, result
, expected
)
199 result
= Markup
.get(result
);
200 if (result
!== expected
)
202 fail_list
.push(test_number
);
203 log
+= "\n\nTest " + (test_number
) + " of " + (test_number
+ tests
.length
) + " in " + file
+ " failed. Input:\n" + input
+ "\nGot:\n" + result
+ "\nExpected:\n" + expected
;