Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/resources/testharnessreport.js

Issue 2511333002: Cleanup after enabling WPTServe. (Closed)
Patch Set: Update a comment, remove the right testharnessreport.js Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * THIS FILE INTENTIONALLY LEFT BLANK
3 *
4 * More specifically, this file is intended for vendors to implement
5 * code needed to integrate testharness.js tests with their own test systems.
6 *
7 * Typically such integration will attach callbacks when each test is
8 * has run, using add_result_callback(callback(test)), or when the whole test fi le has
9 * completed, using add_completion_callback(callback(tests, harness_status)).
10 *
11 * For more documentation about the callback functions and the
12 * parameters they are called with see testharness.js
13 */
14
15 (function() {
16
17 var output_document = document;
18
19 // Setup for WebKit JavaScript tests
20 if (self.testRunner) {
21 testRunner.dumpAsText();
22 testRunner.waitUntilDone();
23 testRunner.setCanOpenWindows();
24 testRunner.setCloseRemainingWindowsWhenComplete(true);
25 testRunner.setDumpJavaScriptDialogs(false);
26 }
27
28 // Disable the default output of testharness.js. The default output formats
29 // test results into an HTML table. When that table is dumped as text, no
30 // spacing between cells is preserved, and it is therefore not readable. By
31 // setting output to false, the HTML table will not be created.
32 // Also, disable timeout (except for explicit timeout), since the Blink
33 // layout test runner has its own timeout mechanism.
34 // See: https://github.com/w3c/testharness.js/blob/master/docs/api.md#setup
35 setup({
36 "output": false,
37 "explicit_timeout": true
38 });
39
40 // Function used to convert the test status code into the corresponding
41 // string
42 function convertResult(resultStatus) {
43 switch (resultStatus) {
44 case 0:
45 return "PASS";
46 case 1:
47 return "FAIL";
48 case 2:
49 return "TIMEOUT";
50 default:
51 return "NOTRUN";
52 }
53 }
54
55 var localPathRegExp;
56 if (document.URL.startsWith("file:///")) {
57 var index = document.URL.indexOf("/external/wpt");
58 if (index >= 0) {
59 var localPath = document.URL.substring("file:///".length, index + "/ external/wpt".length);
60 localPathRegExp = new RegExp(localPath.replace(/(\W)/g, "\\$1"), "g" );
61 }
62 }
63
64 // Sanitizes the given text for display in test results.
65 function sanitize(text) {
66 if (!text) {
67 return "";
68 }
69 // Escape null characters, otherwise diff will think the file is binary.
70 text = text.replace(/\0/g, "\\0");
71 // Escape carriage returns as they break rietveld's difftools.
72 text = text.replace(/\r/g, "\\r");
73 // Replace machine-dependent path with "...".
74 if (localPathRegExp)
75 text = text.replace(localPathRegExp, "...");
76 return text;
77 }
78
79 function isWPTManualTest() {
80 var path = location.pathname;
81 if (location.hostname == 'web-platform.test' && path.endsWith('-manual.h tml'))
82 return true;
83 return /\/imported\/wpt\/.*-manual\.html$/.test(path);
84 }
85
86 // Returns a directory part relative to WPT root and a basename part of the
87 // current test. e.g.
88 // Current test: file:///.../LayoutTests/external/wpt/pointerevents/foobar.h tml
89 // Output: "/pointerevents/foobar"
90 function pathAndBaseNameInWPT() {
91 var path = location.pathname;
92 if (location.hostname == 'web-platform.test') {
93 var matches = path.match(/^(\/.*)\.html$/);
94 return matches ? matches[1] : null;
95 }
96 var matches = path.match(/imported\/wpt(\/.*)\.html$/);
97 return matches ? matches[1] : null;
98 }
99
100 function loadAutomationScript() {
101 var pathAndBase = pathAndBaseNameInWPT();
102 if (!pathAndBase)
103 return;
104 var automationPath = location.pathname.replace(/\/imported\/wpt\/.*$/, ' /external/wpt_automation');
105 if (location.hostname == 'web-platform.test')
106 automationPath = '/wpt_automation';
107
108 // Export importAutomationScript for use by the automation scripts.
109 window.importAutomationScript = function(relativePath) {
110 var script = document.createElement('script');
111 script.src = automationPath + relativePath;
112 document.head.appendChild(script);
113 }
114
115 var src;
116 if (pathAndBase.startsWith('/fullscreen/')) {
117 // Fullscreen tests all use the same automation script.
118 src = automationPath + '/fullscreen/auto-click.js';
119 } else if (pathAndBase.startsWith('/pointerevents/')
120 || pathAndBase.startsWith('/uievents/')) {
121 // Per-test automation scripts.
122 src = automationPath + pathAndBase + '-automation.js';
123 } else {
124 return;
125 }
126 var script = document.createElement('script');
127 script.src = src;
128 document.head.appendChild(script);
129 }
130
131 var didDispatchLoadEvent = false;
132 window.addEventListener('load', function() {
133 didDispatchLoadEvent = true;
134 if (isWPTManualTest()) {
135 setTimeout(loadAutomationScript, 0);
136 }
137 }, { once: true });
138
139 add_start_callback(function(properties) {
140 if (properties.output_document)
141 output_document = properties.output_document;
142 });
143
144 // Using a callback function, test results will be added to the page in a
145 // manner that allows dumpAsText to produce readable test results.
146 add_completion_callback(function (tests, harness_status) {
147
148 // Create element to hold results.
149 var results = output_document.createElement("pre");
150
151 // Declare result string.
152 var resultStr = "This is a testharness.js-based test.\n";
153
154 // Check harness_status. If it is not 0, tests did not execute
155 // correctly, output the error code and message.
156 if (harness_status.status != 0) {
157 resultStr += "Harness Error. harness_status.status = " +
158 harness_status.status +
159 " , harness_status.message = " +
160 harness_status.message +
161 "\n";
162 }
163 // reflection tests contain huge number of tests, and Chromium code
164 // review tool has the 1MB diff size limit. We merge PASS lines.
165 if (output_document.URL.indexOf("/html/dom/reflection") >= 0) {
166 for (var i = 0; i < tests.length; ++i) {
167 if (tests[i].status == 0) {
168 var colon = tests[i].name.indexOf(':');
169 if (colon > 0) {
170 var prefix = tests[i].name.substring(0, colon + 1);
171 var j = i + 1;
172 for (; j < tests.length; ++j) {
173 if (!tests[j].name.startsWith(prefix) || tests[j].st atus != 0)
174 break;
175 }
176 if ((j - i) > 1) {
177 resultStr += convertResult(tests[i].status) +
178 " " + sanitize(prefix) + " " + (j - i) + " tests \n"
179 i = j - 1;
180 continue;
181 }
182 }
183 }
184 resultStr += convertResult(tests[i].status) + " " +
185 sanitize(tests[i].name) + " " +
186 sanitize(tests[i].message) + "\n";
187 }
188 } else {
189 // Iterate through tests array and build string that contains
190 // results for all tests.
191 for (var i = 0; i < tests.length; ++i) {
192 resultStr += convertResult(tests[i].status) + " " +
193 sanitize(tests[i].name) + " " +
194 sanitize(tests[i].message) + "\n";
195 }
196 }
197
198 resultStr += "Harness: the test ran to completion.\n";
199
200 // Set results element's textContent to the results string.
201 results.textContent = resultStr;
202
203 function done() {
204 // A temporary workaround since |window.self| property lookup starts
205 // failing if the frame is detached. |output_document| may be an
206 // ancestor of |self| so clearing |textContent| may detach |self|.
207 // To get around this, cache window.self now and use the cached
208 // value.
209 // TODO(dcheng): Remove this hack after fixing window/self/frames
210 // lookup in https://crbug.com/618672
211 var cachedSelf = window.self;
212 if (cachedSelf.testRunner) {
213 // The following DOM operations may show console messages. We
214 // suppress them because they are not related to the running
215 // test.
216 testRunner.setDumpConsoleMessages(false);
217
218 // Anything isn't material to the testrunner output, so should
219 // be hidden from the text dump.
220 if (output_document.body && output_document.body.tagName == 'BOD Y')
221 output_document.body.textContent = '';
222 }
223
224 // Add results element to output_document.
225 if (!output_document.body || output_document.body.tagName != 'BODY') {
226 if (!output_document.documentElement)
227 output_document.appendChild(output_document.createElement('h tml'));
228 else if (output_document.body) // output_document.body is <frame set>.
229 output_document.body.remove();
230 output_document.documentElement.appendChild(output_document.crea teElement("body"));
231 }
232 output_document.body.appendChild(results);
233
234 if (cachedSelf.testRunner)
235 testRunner.notifyDone();
236 }
237
238 if (didDispatchLoadEvent || output_document.readyState != 'loading') {
239 // This function might not be the last 'completion callback', and
240 // another completion callback might generate more results. So, we
241 // don't dump the results immediately.
242 setTimeout(done, 0);
243 } else {
244 // Parsing the test HTML isn't finished yet.
245 window.addEventListener('load', done);
246 }
247 });
248
249 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698