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