| 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 if (navigator.webkitStartDart) { | 10 if (navigator.webkitStartDart) { |
| 11 navigator.webkitStartDart(); | 11 navigator.webkitStartDart(); |
| 12 } | 12 } |
| 13 | 13 |
| 14 // testRunner is provided by DRT or WebKit's layout tests. | 14 // testRunner is provided by DRT or WebKit's layout tests. |
| 15 // It is not available in selenium tests. | 15 // It is not available in selenium tests. |
| 16 var testRunner = window.testRunner || window.layoutTestController; | 16 var testRunner = window.testRunner || window.layoutTestController; |
| 17 | 17 |
| 18 var waitForDone = false; | 18 var waitForDone = false; |
| 19 | 19 |
| 20 // _callback and getMessages are used to retrieve console messages | |
| 21 // from the Chrome ConsoleCollector extension. run_selenium.py can | |
| 22 // call getMessages with execute_async_script, and when the messages | |
| 23 // are returned from the extension they can be returned via a callback | |
| 24 // provided by Selenium. _callback is used to hold a reference to | |
| 25 // that callback. The messages are returned from the extension via | |
| 26 // a window.postMessage call with type property 'gotMessages'. | |
| 27 var _callback; | |
| 28 function getMessages(callback) { | |
| 29 _callback = callback; | |
| 30 window.postMessage("getMessages", "*"); | |
| 31 } | |
| 32 | |
| 33 function processMessage(msg) { | 20 function processMessage(msg) { |
| 34 if (typeof msg != 'string') { | 21 if (typeof msg != 'string') return; |
| 35 if (msg.type == 'gotMessages') { | |
| 36 // Handle console messages from Chrome extension. | |
| 37 if (_callback) { | |
| 38 _callback(msg.messages); | |
| 39 _callback = null; | |
| 40 } | |
| 41 } | |
| 42 return; | |
| 43 } | |
| 44 if (msg == 'unittest-suite-done') { | 22 if (msg == 'unittest-suite-done') { |
| 45 if (testRunner) testRunner.notifyDone(); | 23 if (testRunner) testRunner.notifyDone(); |
| 46 } else if (msg == 'unittest-suite-wait-for-done') { | 24 } else if (msg == 'unittest-suite-wait-for-done') { |
| 47 waitForDone = true; | 25 waitForDone = true; |
| 48 if (testRunner) testRunner.startedDartTest = true; | 26 if (testRunner) testRunner.startedDartTest = true; |
| 49 } else if (msg == 'dart-calling-main') { | 27 } else if (msg == 'dart-calling-main') { |
| 50 if (testRunner) testRunner.startedDartTest = true; | 28 if (testRunner) testRunner.startedDartTest = true; |
| 51 } else if (msg == 'dart-main-done') { | 29 } else if (msg == 'dart-main-done') { |
| 52 if (!waitForDone) { | 30 if (!waitForDone) { |
| 53 window.postMessage('unittest-suite-success', '*'); | 31 window.postMessage('unittest-suite-success', '*'); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 function dartMainRunner(main) { | 112 function dartMainRunner(main) { |
| 135 window.postMessage('dart-calling-main', '*'); | 113 window.postMessage('dart-calling-main', '*'); |
| 136 try { | 114 try { |
| 137 main(); | 115 main(); |
| 138 } catch (e) { | 116 } catch (e) { |
| 139 window.postMessage('unittest-suite-fail', '*'); | 117 window.postMessage('unittest-suite-fail', '*'); |
| 140 return; | 118 return; |
| 141 } | 119 } |
| 142 window.postMessage('dart-main-done', '*'); | 120 window.postMessage('dart-main-done', '*'); |
| 143 } | 121 } |
| OLD | NEW |