93b3af303f03f5f590a9d6e2abfcd4f78f0c97bc
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / w3c / resources / testharnessreport.js
1 /*\r
2  * THIS FILE INTENTIONALLY LEFT BLANK\r
3  *\r
4  * More specifically, this file is intended for vendors to implement\r
5  * code needed to integrate testharness.js tests with their own test systems.\r
6  *\r
7  * Typically such integration will attach callbacks when each test is\r
8  * has run, using add_result_callback(callback(test)), or when the whole test file has\r
9  * completed, using add_completion_callback(callback(tests, harness_status)).\r
10  *\r
11  * For more documentation about the callback functions and the\r
12  * parameters they are called with see testharness.js\r
13  */\r
14 \r
15 // Setup for WebKit JavaScript tests\r
16 if (self.testRunner) {\r
17     testRunner.dumpAsText();\r
18     testRunner.waitUntilDone();\r
19 }\r
20 \r
21 // Function used to convert the test status code into\r
22 // the corresponding string\r
23 function convertResult(resultStatus){\r
24         if(resultStatus == 0)\r
25                 return("PASS");\r
26         else if(resultStatus == 1)\r
27                 return("FAIL");\r
28         else if(resultStatus == 2)\r
29                 return("TIMEOUT");\r
30         else\r
31                 return("NOTRUN");\r
32 }\r
33 \r
34 /* Disable the default output of testharness.js.  The default output formats\r
35 *  test results into an HTML table.  When that table is dumped as text, no\r
36 *  spacing between cells is preserved, and it is therefore not readable. By\r
37 *  setting output to false, the HTML table will not be created\r
38 */\r
39 setup({"output":false});\r
40 \r
41 /*  Using a callback function, test results will be added to the page in a \r
42 *   manner that allows dumpAsText to produce readable test results\r
43 */\r
44 add_completion_callback(function (tests, harness_status){\r
45         \r
46         // Create element to hold results\r
47         var results = document.createElement("pre");\r
48         \r
49         // Declare result string\r
50         var resultStr = "\n";\r
51         \r
52         // Check harness_status.  If it is not 0, tests did not\r
53         // execute correctly, output the error code and message\r
54         if(harness_status.status != 0){\r
55                 resultStr += "Harness Error. harness_status.status = " + \r
56                                          harness_status.status +\r
57                                          " , harness_status.message = " +\r
58                                          harness_status.message;\r
59         }\r
60         else {\r
61                 // Iterate through tests array and build string that contains\r
62                 // results for all tests\r
63                 for(var i=0; i<tests.length; i++){                               \r
64                         resultStr += convertResult(tests[i].status) + " " + \r
65                                                 ( (tests[i].name!=null) ? tests[i].name : "" ) + " " +\r
66                                                 ( (tests[i].message!=null) ? tests[i].message : "" ) + \r
67                                                 "\n";\r
68                 }                       \r
69         }\r
70 \r
71         // Set results element's innerHTML to the results string\r
72         results.innerHTML = resultStr;\r
73 \r
74         // Add results element to document\r
75         document.body.appendChild(results);\r
76 \r
77         if (self.testRunner)\r
78                 testRunner.notifyDone();\r
79 });\r