| 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 |
| 20 function processMessage(msg) { | 33 function processMessage(msg) { |
| 21 if (typeof msg != 'string') return; | 34 if (typeof msg != 'string') { |
| 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 } |
| 22 if (msg == 'unittest-suite-done') { | 44 if (msg == 'unittest-suite-done') { |
| 23 if (testRunner) testRunner.notifyDone(); | 45 if (testRunner) testRunner.notifyDone(); |
| 24 } else if (msg == 'unittest-suite-wait-for-done') { | 46 } else if (msg == 'unittest-suite-wait-for-done') { |
| 25 waitForDone = true; | 47 waitForDone = true; |
| 26 if (testRunner) testRunner.startedDartTest = true; | 48 if (testRunner) testRunner.startedDartTest = true; |
| 27 } else if (msg == 'dart-calling-main') { | 49 } else if (msg == 'dart-calling-main') { |
| 28 if (testRunner) testRunner.startedDartTest = true; | 50 if (testRunner) testRunner.startedDartTest = true; |
| 29 } else if (msg == 'dart-main-done') { | 51 } else if (msg == 'dart-main-done') { |
| 30 if (!waitForDone) { | 52 if (!waitForDone) { |
| 31 window.postMessage('unittest-suite-success', '*'); | 53 window.postMessage('unittest-suite-success', '*'); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 function dartMainRunner(main) { | 134 function dartMainRunner(main) { |
| 113 window.postMessage('dart-calling-main', '*'); | 135 window.postMessage('dart-calling-main', '*'); |
| 114 try { | 136 try { |
| 115 main(); | 137 main(); |
| 116 } catch (e) { | 138 } catch (e) { |
| 117 window.postMessage('unittest-suite-fail', '*'); | 139 window.postMessage('unittest-suite-fail', '*'); |
| 118 return; | 140 return; |
| 119 } | 141 } |
| 120 window.postMessage('dart-main-done', '*'); | 142 window.postMessage('dart-main-done', '*'); |
| 121 } | 143 } |
| OLD | NEW |