| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Test controller logic - used by unit test harness to embed tests in | 6 * Test controller logic - used by unit test harness to embed tests in |
| 7 * DumpRenderTree. | 7 * DumpRenderTree. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 // Clear the console before every test run - this is Firebug specific code. | 10 // Clear the console before every test run - this is Firebug specific code. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 if (navigator.webkitStartDart) { | 26 if (navigator.webkitStartDart) { |
| 27 navigator.webkitStartDart(); | 27 navigator.webkitStartDart(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 // testRunner is provided by DRT or WebKit's layout tests. | 30 // testRunner is provided by DRT or WebKit's layout tests. |
| 31 // It is not available in selenium tests. | 31 // It is not available in selenium tests. |
| 32 var testRunner = window.testRunner || window.layoutTestController; | 32 var testRunner = window.testRunner || window.layoutTestController; |
| 33 | 33 |
| 34 var waitForDone = false; | 34 var waitForDone = false; |
| 35 | 35 |
| 36 function sendBackData() { |
| 37 if (window.opener) { |
| 38 window.opener.postMessage(window.document.body.innerHTML, "*"); |
| 39 } |
| 40 } |
| 41 |
| 36 function processMessage(msg) { | 42 function processMessage(msg) { |
| 37 if (typeof msg != 'string') return; | 43 if (typeof msg != 'string') return; |
| 38 if (msg == 'unittest-suite-done') { | 44 if (msg == 'unittest-suite-done') { |
| 39 if (testRunner) testRunner.notifyDone(); | 45 if (testRunner) testRunner.notifyDone(); |
| 46 sendBackData(); |
| 40 } else if (msg == 'unittest-suite-wait-for-done') { | 47 } else if (msg == 'unittest-suite-wait-for-done') { |
| 41 waitForDone = true; | 48 waitForDone = true; |
| 42 if (testRunner) testRunner.startedDartTest = true; | 49 if (testRunner) testRunner.startedDartTest = true; |
| 43 } else if (msg == 'dart-calling-main') { | 50 } else if (msg == 'dart-calling-main') { |
| 44 if (testRunner) testRunner.startedDartTest = true; | 51 if (testRunner) testRunner.startedDartTest = true; |
| 45 } else if (msg == 'dart-main-done') { | 52 } else if (msg == 'dart-main-done') { |
| 46 if (!waitForDone) { | 53 if (!waitForDone) { |
| 47 window.postMessage('unittest-suite-success', '*'); | 54 window.postMessage('unittest-suite-success', '*'); |
| 48 } | 55 } |
| 49 } else if (msg == 'unittest-suite-success') { | 56 } else if (msg == 'unittest-suite-success') { |
| 50 dartPrint('PASS'); | 57 dartPrint('PASS'); |
| 51 if (testRunner) testRunner.notifyDone(); | 58 if (testRunner) testRunner.notifyDone(); |
| 59 sendBackData(); |
| 52 } else if (msg == 'unittest-suite-fail') { | 60 } else if (msg == 'unittest-suite-fail') { |
| 53 showErrorAndExit('Some tests failed.'); | 61 showErrorAndExit('Some tests failed.'); |
| 54 } | 62 } |
| 55 } | 63 } |
| 56 | 64 |
| 57 function onReceive(e) { | 65 function onReceive(e) { |
| 58 processMessage(e.data); | 66 processMessage(e.data); |
| 59 } | 67 } |
| 60 | 68 |
| 61 if (testRunner) { | 69 if (testRunner) { |
| 62 testRunner.dumpAsText(); | 70 testRunner.dumpAsText(); |
| 63 testRunner.waitUntilDone(); | 71 testRunner.waitUntilDone(); |
| 64 } | 72 } |
| 65 window.addEventListener("message", onReceive, false); | 73 window.addEventListener("message", onReceive, false); |
| 66 | 74 |
| 67 function showErrorAndExit(message) { | 75 function showErrorAndExit(message) { |
| 68 if (message) { | 76 if (message) { |
| 69 dartPrint('Error: ' + String(message)); | 77 dartPrint('Error: ' + String(message)); |
| 70 } | 78 } |
| 71 // dart/tools/testing/run_selenium.py is looking for either PASS or | 79 // dart/tools/testing/run_selenium.py is looking for either PASS or |
| 72 // FAIL and will continue polling until one of these words show up. | 80 // FAIL and will continue polling until one of these words show up. |
| 73 dartPrint('FAIL'); | 81 dartPrint('FAIL'); |
| 74 if (testRunner) testRunner.notifyDone(); | 82 if (testRunner) testRunner.notifyDone(); |
| 83 sendBackData(); |
| 75 } | 84 } |
| 76 | 85 |
| 77 function onLoad(e) { | 86 function onLoad(e) { |
| 78 // needed for dartium compilation errors. | 87 // needed for dartium compilation errors. |
| 79 if (window.compilationError) { | 88 if (window.compilationError) { |
| 80 showErrorAndExit(window.compilationError); | 89 showErrorAndExit(window.compilationError); |
| 81 } | 90 } |
| 82 } | 91 } |
| 83 | 92 |
| 84 window.addEventListener("DOMContentLoaded", onLoad, false); | 93 window.addEventListener("DOMContentLoaded", onLoad, false); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 100 // If 'startedDartTest' is not set, that means that the test did not have | 109 // If 'startedDartTest' is not set, that means that the test did not have |
| 101 // a chance to load. This will happen when a load error occurs in the VM. | 110 // a chance to load. This will happen when a load error occurs in the VM. |
| 102 // Give the machine time to start up. | 111 // Give the machine time to start up. |
| 103 setTimeout(function() { | 112 setTimeout(function() { |
| 104 // A window.postMessage might have been enqueued after this timeout. | 113 // A window.postMessage might have been enqueued after this timeout. |
| 105 // Just sleep another time to give the browser the time to process the | 114 // Just sleep another time to give the browser the time to process the |
| 106 // posted message. | 115 // posted message. |
| 107 setTimeout(function() { | 116 setTimeout(function() { |
| 108 if (testRunner && !testRunner.startedDartTest) { | 117 if (testRunner && !testRunner.startedDartTest) { |
| 109 testRunner.notifyDone(); | 118 testRunner.notifyDone(); |
| 119 sendBackData(); |
| 110 } | 120 } |
| 111 }, 0); | 121 }, 0); |
| 112 }, 50); | 122 }, 50); |
| 113 }); | 123 }); |
| 114 | 124 |
| 115 // dart2js will generate code to call this function to handle the Dart | 125 // dart2js will generate code to call this function to handle the Dart |
| 116 // [print] method. The base [Configuration] (config.html) calls | 126 // [print] method. The base [Configuration] (config.html) calls |
| 117 // [print] with the secret messages "unittest-suite-success" and | 127 // [print] with the secret messages "unittest-suite-success" and |
| 118 // "unittest-suite-wait-for-done". These messages are then posted so | 128 // "unittest-suite-wait-for-done". These messages are then posted so |
| 119 // processMessage above will see them. | 129 // processMessage above will see them. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 135 try { | 145 try { |
| 136 main(); | 146 main(); |
| 137 } catch (e) { | 147 } catch (e) { |
| 138 dartPrint(e); | 148 dartPrint(e); |
| 139 if (e.stack) dartPrint(e.stack); | 149 if (e.stack) dartPrint(e.stack); |
| 140 window.postMessage('unittest-suite-fail', '*'); | 150 window.postMessage('unittest-suite-fail', '*'); |
| 141 return; | 151 return; |
| 142 } | 152 } |
| 143 window.postMessage('dart-main-done', '*'); | 153 window.postMessage('dart-main-done', '*'); |
| 144 } | 154 } |
| OLD | NEW |