| 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. |
| 15 // It is not available in selenium tests. |
| 14 var testRunner = window.testRunner || window.layoutTestController; | 16 var testRunner = window.testRunner || window.layoutTestController; |
| 15 | 17 |
| 16 var waitForDone = false; | 18 var waitForDone = false; |
| 17 | 19 |
| 18 function processMessage(msg) { | 20 function processMessage(msg) { |
| 19 if (typeof msg != 'string') return; | 21 if (typeof msg != 'string') return; |
| 20 if (msg == 'unittest-suite-done') { | 22 if (msg == 'unittest-suite-done') { |
| 21 if (testRunner) testRunner.notifyDone(); | 23 if (testRunner) testRunner.notifyDone(); |
| 22 } else if (msg == 'unittest-suite-wait-for-done') { | 24 } else if (msg == 'unittest-suite-wait-for-done') { |
| 23 waitForDone = true; | 25 waitForDone = true; |
| 24 if (testRunner) testRunner.startedDartTest = true; | 26 if (testRunner) testRunner.startedDartTest = true; |
| 25 } else if (msg == 'dart-calling-main') { | 27 } else if (msg == 'dart-calling-main') { |
| 26 if (testRunner) testRunner.startedDartTest = true; | 28 if (testRunner) testRunner.startedDartTest = true; |
| 27 } else if (msg == 'dart-main-done') { | 29 } else if (msg == 'dart-main-done') { |
| 28 if (!waitForDone) { | 30 if (!waitForDone) { |
| 29 window.postMessage('unittest-suite-success', '*'); | 31 window.postMessage('unittest-suite-success', '*'); |
| 30 } | 32 } |
| 31 } else if (msg == 'unittest-suite-success') { | 33 } else if (msg == 'unittest-suite-success') { |
| 32 document.body.innerHTML += '<pre>PASS</pre>'; | 34 dartPrint('PASS'); |
| 33 if (testRunner) testRunner.notifyDone(); | 35 if (testRunner) testRunner.notifyDone(); |
| 34 } else if (msg == 'unittest-suite-fail') { | 36 } else if (msg == 'unittest-suite-fail') { |
| 35 showErrorAndExit('Some tests failed.'); | 37 showErrorAndExit('Some tests failed.'); |
| 36 } | 38 } |
| 37 } | 39 } |
| 38 | 40 |
| 39 function onReceive(e) { | 41 function onReceive(e) { |
| 40 processMessage(e.data); | 42 processMessage(e.data); |
| 41 } | 43 } |
| 42 | 44 |
| 43 if (testRunner) { | 45 if (testRunner) { |
| 44 testRunner.dumpAsText(); | 46 testRunner.dumpAsText(); |
| 45 testRunner.waitUntilDone(); | 47 testRunner.waitUntilDone(); |
| 46 } | 48 } |
| 47 window.addEventListener("message", onReceive, false); | 49 window.addEventListener("message", onReceive, false); |
| 48 | 50 |
| 49 function showErrorAndExit(message) { | 51 function showErrorAndExit(message) { |
| 50 if (message) { | 52 if (message) { |
| 51 var element = document.createElement('pre'); | 53 dartPrint('Error: ' + String(message)); |
| 52 element.innerHTML = message; | |
| 53 document.body.appendChild(element); | |
| 54 } | 54 } |
| 55 if (testRunner) { | 55 // dart/tools/testing/run_selenium.py is looking for either PASS or |
| 56 testRunner.notifyDone(); | 56 // FAIL and will continue polling until one of these words show up. |
| 57 } | 57 dartPrint('FAIL'); |
| 58 if (testRunner) testRunner.notifyDone(); |
| 58 } | 59 } |
| 59 | 60 |
| 60 function onLoad(e) { | 61 function onLoad(e) { |
| 61 // needed for dartium compilation errors. | 62 // needed for dartium compilation errors. |
| 62 if (window.compilationError) { | 63 if (window.compilationError) { |
| 63 showErrorAndExit(window.compilationError); | 64 showErrorAndExit(window.compilationError); |
| 64 } | 65 } |
| 65 } | 66 } |
| 66 | 67 |
| 67 window.addEventListener("DOMContentLoaded", onLoad, false); | 68 window.addEventListener("DOMContentLoaded", onLoad, false); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 103 } |
| 103 var pre = document.createElement("pre"); | 104 var pre = document.createElement("pre"); |
| 104 pre.appendChild(document.createTextNode(String(msg))); | 105 pre.appendChild(document.createTextNode(String(msg))); |
| 105 document.body.appendChild(pre); | 106 document.body.appendChild(pre); |
| 106 } | 107 } |
| 107 | 108 |
| 108 // dart2js will generate code to call this function instead of calling | 109 // dart2js will generate code to call this function instead of calling |
| 109 // Dart [main] directly. The argument is a closure that invokes main. | 110 // Dart [main] directly. The argument is a closure that invokes main. |
| 110 function dartMainRunner(main) { | 111 function dartMainRunner(main) { |
| 111 window.postMessage('dart-calling-main', '*'); | 112 window.postMessage('dart-calling-main', '*'); |
| 112 main(); | 113 try { |
| 114 main(); |
| 115 } catch (e) { |
| 116 window.postMessage('unittest-suite-fail', '*'); |
| 117 return; |
| 118 } |
| 113 window.postMessage('dart-main-done', '*'); | 119 window.postMessage('dart-main-done', '*'); |
| 114 } | 120 } |
| OLD | NEW |