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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/w3c/resources/testharnessreport.js

Issue 1898703003: Remove testharness.js and friends in LayoutTests/http/tests/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 // Setup for WebKit JavaScript tests
18 if (self.testRunner) {
19 testRunner.dumpAsText();
20 testRunner.waitUntilDone();
21 testRunner.setCanOpenWindows();
22 testRunner.setCloseRemainingWindowsWhenComplete(true);
23 }
24
25 // Disable the default output of testharness.js. The default output formats
26 // test results into an HTML table. When that table is dumped as text, no
27 // spacing between cells is preserved, and it is therefore not readable. By
28 // setting output to false, the HTML table will not be created.
29 setup({"output":false});
30
31 // Function used to convert the test status code into the corresponding
32 // string
33 function convertResult(resultStatus) {
34 switch (resultStatus) {
35 case 0:
36 return "PASS";
37 case 1:
38 return "FAIL";
39 case 2:
40 return "TIMEOUT";
41 default:
42 return "NOTRUN";
43 }
44 }
45
46 // Sanitizes the given text for display in test results.
47 function sanitize(text) {
48 if (!text) {
49 return "";
50 }
51 // Escape null characters, otherwise diff will think the file is binary.
52 text = text.replace(/\0/g, "\\0");
53 // Escape carriage returns as they break rietveld's difftools.
54 return text.replace(/\r/g, "\\r");
55 }
56
57 // If the test has a meta tag named flags and the content contains "dom",
58 // then it's a CSSWG test.
59 function isCSSWGTest() {
60 var flags = document.querySelector('meta[name=flags]'),
61 content = flags ? flags.getAttribute('content') : null;
62 return content && content.match(/\bdom\b/);
63 }
64
65 function isJSTest() {
66 return !!document.querySelector('script[src*="/resources/testharness"]') ;
67 }
68
69 var didDispatchLoadEvent = false;
70 var handleLoad = function() {
71 didDispatchLoadEvent = true;
72 window.removeEventListener('load', handleLoad);
73 };
74 window.addEventListener('load', handleLoad, false);
75
76 // Using a callback function, test results will be added to the page in a
77 // manner that allows dumpAsText to produce readable test results.
78 add_completion_callback(function (tests, harness_status) {
79
80 // Create element to hold results.
81 var results = document.createElement("pre");
82
83 // Declare result string.
84 var resultStr = "This is a testharness.js-based test.\n";
85
86 // Check harness_status. If it is not 0, tests did not execute
87 // correctly, output the error code and message.
88 if (harness_status.status != 0) {
89 resultStr += "Harness Error. harness_status.status = " +
90 harness_status.status +
91 " , harness_status.message = " +
92 harness_status.message +
93 "\n";
94 } else {
95 // Iterate through tests array and build string that contains
96 // results for all tests.
97 for (var i = 0; i < tests.length; ++i) {
98 resultStr += convertResult(tests[i].status) + " " +
99 sanitize(tests[i].name) + " " +
100 sanitize(tests[i].message) + "\n";
101 }
102 }
103 resultStr += "Harness: the test ran to completion.\n";
104
105 // Set results element's textContent to the results string.
106 results.textContent = resultStr;
107
108 function done() {
109 if (self.testRunner) {
110 var logDiv = document.getElementById('log');
111 if ((isCSSWGTest() || isJSTest()) && logDiv) {
112 // Assume it's a CSSWG style test, and anything other than
113 // the log div isn't material to the testrunner output, so
114 // should be hidden from the text dump.
115 document.body.textContent = '';
116 }
117 }
118
119 // Add results element to document.
120 if (!document.body) {
121 if (!document.documentElement)
122 document.appendChild(document.createElement('html'));
123 document.documentElement.appendChild(document.createElement("bod y"));
124 }
125 document.body.appendChild(results);
126
127 if (self.testRunner)
128 testRunner.notifyDone();
129 }
130
131 if (didDispatchLoadEvent || document.readyState != 'loading') {
132 // This function might not be the last 'completion callback', and
133 // another completion callback might generate more results. So, we
134 // don't dump the results immediately.
135 setTimeout(done, 0);
136 } else {
137 // Parsing the test HTML isn't finished yet.
138 window.addEventListener('load', done);
139 }
140 });
141
142 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698