| 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 sendDomToTestDriver() { | 36 function notifyStart() { |
| 37 if (window.opener) { |
| 38 window.opener.postMessage("STARTING", "*"); |
| 39 } |
| 40 } |
| 41 |
| 42 function notifyDone() { |
| 43 if (testRunner) testRunner.notifyDone(); |
| 44 // To support in browser launching of tests we post back start and result |
| 45 // messages to the window.opener. |
| 37 if (window.opener) { | 46 if (window.opener) { |
| 38 window.opener.postMessage(window.document.body.innerHTML, "*"); | 47 window.opener.postMessage(window.document.body.innerHTML, "*"); |
| 39 } | 48 } |
| 40 } | 49 } |
| 41 | 50 |
| 42 function processMessage(msg) { | 51 function processMessage(msg) { |
| 43 if (typeof msg != 'string') return; | 52 if (typeof msg != 'string') return; |
| 44 if (msg == 'unittest-suite-done') { | 53 if (msg == 'unittest-suite-done') { |
| 45 if (testRunner) testRunner.notifyDone(); | 54 notifyDone(); |
| 46 sendDomToTestDriver(); | |
| 47 } else if (msg == 'unittest-suite-wait-for-done') { | 55 } else if (msg == 'unittest-suite-wait-for-done') { |
| 48 waitForDone = true; | 56 waitForDone = true; |
| 49 if (testRunner) testRunner.startedDartTest = true; | 57 if (testRunner) testRunner.startedDartTest = true; |
| 50 } else if (msg == 'dart-calling-main') { | 58 } else if (msg == 'dart-calling-main') { |
| 51 if (testRunner) testRunner.startedDartTest = true; | 59 if (testRunner) testRunner.startedDartTest = true; |
| 52 } else if (msg == 'dart-main-done') { | 60 } else if (msg == 'dart-main-done') { |
| 53 if (!waitForDone) { | 61 if (!waitForDone) { |
| 54 window.postMessage('unittest-suite-success', '*'); | 62 window.postMessage('unittest-suite-success', '*'); |
| 55 } | 63 } |
| 56 } else if (msg == 'unittest-suite-success') { | 64 } else if (msg == 'unittest-suite-success') { |
| 57 dartPrint('PASS'); | 65 dartPrint('PASS'); |
| 58 if (testRunner) testRunner.notifyDone(); | 66 notifyDone(); |
| 59 sendDomToTestDriver(); | |
| 60 } else if (msg == 'unittest-suite-fail') { | 67 } else if (msg == 'unittest-suite-fail') { |
| 61 showErrorAndExit('Some tests failed.'); | 68 showErrorAndExit('Some tests failed.'); |
| 62 } | 69 } |
| 63 } | 70 } |
| 64 | 71 |
| 65 function onReceive(e) { | 72 function onReceive(e) { |
| 66 processMessage(e.data); | 73 processMessage(e.data); |
| 67 } | 74 } |
| 68 | 75 |
| 69 if (testRunner) { | 76 if (testRunner) { |
| 70 testRunner.dumpAsText(); | 77 testRunner.dumpAsText(); |
| 71 testRunner.waitUntilDone(); | 78 testRunner.waitUntilDone(); |
| 72 } | 79 } |
| 73 window.addEventListener("message", onReceive, false); | 80 window.addEventListener("message", onReceive, false); |
| 74 | 81 |
| 75 function showErrorAndExit(message) { | 82 function showErrorAndExit(message) { |
| 76 if (message) { | 83 if (message) { |
| 77 dartPrint('Error: ' + String(message)); | 84 dartPrint('Error: ' + String(message)); |
| 78 } | 85 } |
| 79 // dart/tools/testing/run_selenium.py is looking for either PASS or | 86 // dart/tools/testing/run_selenium.py is looking for either PASS or |
| 80 // FAIL and will continue polling until one of these words show up. | 87 // FAIL and will continue polling until one of these words show up. |
| 81 dartPrint('FAIL'); | 88 dartPrint('FAIL'); |
| 82 if (testRunner) testRunner.notifyDone(); | 89 notifyDone(); |
| 83 sendDomToTestDriver(); | |
| 84 } | 90 } |
| 85 | 91 |
| 86 function onLoad(e) { | 92 function onLoad(e) { |
| 87 // needed for dartium compilation errors. | 93 // needed for dartium compilation errors. |
| 88 if (window.compilationError) { | 94 if (window.compilationError) { |
| 89 showErrorAndExit(window.compilationError); | 95 showErrorAndExit(window.compilationError); |
| 90 } | 96 } |
| 91 } | 97 } |
| 92 | 98 |
| 93 window.addEventListener("DOMContentLoaded", onLoad, false); | 99 window.addEventListener("DOMContentLoaded", onLoad, false); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 108 if (document.readyState != "loaded") return; | 114 if (document.readyState != "loaded") return; |
| 109 // If 'startedDartTest' is not set, that means that the test did not have | 115 // If 'startedDartTest' is not set, that means that the test did not have |
| 110 // a chance to load. This will happen when a load error occurs in the VM. | 116 // a chance to load. This will happen when a load error occurs in the VM. |
| 111 // Give the machine time to start up. | 117 // Give the machine time to start up. |
| 112 setTimeout(function() { | 118 setTimeout(function() { |
| 113 // A window.postMessage might have been enqueued after this timeout. | 119 // A window.postMessage might have been enqueued after this timeout. |
| 114 // Just sleep another time to give the browser the time to process the | 120 // Just sleep another time to give the browser the time to process the |
| 115 // posted message. | 121 // posted message. |
| 116 setTimeout(function() { | 122 setTimeout(function() { |
| 117 if (testRunner && !testRunner.startedDartTest) { | 123 if (testRunner && !testRunner.startedDartTest) { |
| 118 testRunner.notifyDone(); | 124 notifyDone(); |
| 119 sendDomToTestDriver(); | |
| 120 } | 125 } |
| 121 }, 0); | 126 }, 0); |
| 122 }, 50); | 127 }, 50); |
| 123 }); | 128 }); |
| 124 | 129 |
| 125 // dart2js will generate code to call this function to handle the Dart | 130 // dart2js will generate code to call this function to handle the Dart |
| 126 // [print] method. The base [Configuration] (config.html) calls | 131 // [print] method. The base [Configuration] (config.html) calls |
| 127 // [print] with the secret messages "unittest-suite-success" and | 132 // [print] with the secret messages "unittest-suite-success" and |
| 128 // "unittest-suite-wait-for-done". These messages are then posted so | 133 // "unittest-suite-wait-for-done". These messages are then posted so |
| 129 // processMessage above will see them. | 134 // processMessage above will see them. |
| 130 function dartPrint(msg) { | 135 function dartPrint(msg) { |
| 131 if ((msg === 'unittest-suite-success') | 136 if ((msg === 'unittest-suite-success') |
| 132 || (msg === 'unittest-suite-wait-for-done')) { | 137 || (msg === 'unittest-suite-wait-for-done')) { |
| 133 window.postMessage(msg, '*'); | 138 window.postMessage(msg, '*'); |
| 134 return; | 139 return; |
| 135 } | 140 } |
| 136 var pre = document.createElement("pre"); | 141 var pre = document.createElement("pre"); |
| 137 pre.appendChild(document.createTextNode(String(msg))); | 142 pre.appendChild(document.createTextNode(String(msg))); |
| 138 document.body.appendChild(pre); | 143 document.body.appendChild(pre); |
| 139 } | 144 } |
| 140 | 145 |
| 141 // dart2js will generate code to call this function instead of calling | 146 // dart2js will generate code to call this function instead of calling |
| 142 // Dart [main] directly. The argument is a closure that invokes main. | 147 // Dart [main] directly. The argument is a closure that invokes main. |
| 143 function dartMainRunner(main) { | 148 function dartMainRunner(main) { |
| 149 // We call notifyStart here to notify the encapsulating browser. |
| 150 notifyStart(); |
| 144 window.postMessage('dart-calling-main', '*'); | 151 window.postMessage('dart-calling-main', '*'); |
| 145 try { | 152 try { |
| 146 main(); | 153 main(); |
| 147 } catch (e) { | 154 } catch (e) { |
| 148 dartPrint(e); | 155 dartPrint(e); |
| 149 if (e.stack) dartPrint(e.stack); | 156 if (e.stack) dartPrint(e.stack); |
| 150 window.postMessage('unittest-suite-fail', '*'); | 157 window.postMessage('unittest-suite-fail', '*'); |
| 151 return; | 158 return; |
| 152 } | 159 } |
| 153 window.postMessage('dart-main-done', '*'); | 160 window.postMessage('dart-main-done', '*'); |
| 154 } | 161 } |
| OLD | NEW |