Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / html5lib / resources / runner.js
blobdc35e4e5d0a582629a3543d3b8d72532a3f41538
1 // Copyright (c) 2008 Geoffrey Sneddon
2 //
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:
9 //
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
19 // THE SOFTWARE.
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();
36 Markup.noAutoDump();
37 Markup.useHTML5libOutputFormat();
39 var tests = [],
40 iframe = document.getElementsByTagName("iframe")[0],
41 stat = document.getElementsByTagName("p")[0].firstChild,
42 file = "",
43 test_number = 1,
44 fail_list = [],
45 log = "";
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)
54 write = false;
56 window.onload = function()
58 stat.data = "Running";
59 run();
62 function run()
64 var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
65 if (file = test_files.shift())
67 stat.data = "Retriving " + file;
68 test_number = 1;
69 fail_list = [];
70 log = "";
71 xhr.open("GET", file);
72 xhr.onreadystatechange = function()
74 if (xhr.readyState === 4)
76 tests = xhr.responseText.split(/(?:^|\n\n)#data\n/);
77 tests.shift();
78 test();
81 xhr.send(null);
82 } else {
83 if (window.testRunner)
84 testRunner.notifyDone();
88 function test()
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);
104 if (domStart !== -1)
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);
112 return;
115 alert("Invalid test: " + data);
116 test();
117 return;
119 else
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);
138 else
140 overview.innerHTML = file + ": PASS";
141 document.body.appendChild(overview);
143 stat.data = "";
144 run();
148 function run_test(input, contextElement, expected)
150 if (contextElement)
152 var element = document.createElement(contextElement);
155 element.innerHTML = input;
157 catch(e) {}
158 process_result(input, element, expected);
160 else if (write)
162 iframe.contentWindow.document.open();
165 iframe.contentWindow.document.write(input);
167 catch(e) {}
168 iframe.contentWindow.document.close();
169 if (ignoreTitle)
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);
179 else
181 iframe.onload = function()
183 if (ignoreTitle)
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;
205 test_number++;
206 test();