Chromium Code Reviews| 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 var testRunner = window.testRunner || window.layoutTestController; | 14 var testRunner = window.testRunner || window.layoutTestController; |
| 15 | 15 |
| 16 var waitForDone = false; | |
| 17 | |
| 16 function processMessage(msg) { | 18 function processMessage(msg) { |
| 17 if (testRunner) { | 19 if (typeof msg != 'string') return; |
| 18 if (msg == 'unittest-suite-done') { | 20 if (msg == 'unittest-suite-done') { |
| 19 testRunner.notifyDone(); | 21 if (testRunner) testRunner.notifyDone(); |
| 20 } else if (msg == 'unittest-suite-wait-for-done') { | 22 } else if (msg == 'unittest-suite-wait-for-done') { |
| 21 testRunner.startedDartTest = true; | 23 waitForDone = true; |
| 24 if (testRunner) testRunner.startedDartTest = true; | |
| 25 } else if (msg == 'dart-calling-main') { | |
| 26 if (testRunner) testRunner.startedDartTest = true; | |
| 27 } else if (msg == 'dart-main-done') { | |
| 28 if (!waitForDone) { | |
| 29 window.postMessage('unittest-suite-success', '*'); | |
| 22 } | 30 } |
| 31 } else if (msg == 'unittest-suite-success') { | |
| 32 document.body.innerHTML += '<pre>PASS</pre>'; | |
| 33 if (testRunner) testRunner.notifyDone(); | |
| 34 } else if (msg == 'unittest-suite-fail') { | |
| 35 showErrorAndExit('Some tests failed.'); | |
| 23 } | 36 } |
| 24 } | 37 } |
| 25 | 38 |
| 26 function onReceive(e) { | 39 function onReceive(e) { |
| 27 processMessage(e.data); | 40 processMessage(e.data); |
| 28 } | 41 } |
| 29 | 42 |
| 30 if (testRunner) { | 43 if (testRunner) { |
| 31 testRunner.dumpAsText(); | 44 testRunner.dumpAsText(); |
| 32 testRunner.waitUntilDone(); | 45 testRunner.waitUntilDone(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 52 } | 65 } |
| 53 | 66 |
| 54 window.addEventListener("DOMContentLoaded", onLoad, false); | 67 window.addEventListener("DOMContentLoaded", onLoad, false); |
| 55 | 68 |
| 56 // If nobody intercepts the error, finish the test. | 69 // If nobody intercepts the error, finish the test. |
| 57 window.addEventListener("error", function(e) { | 70 window.addEventListener("error", function(e) { |
| 58 // needed for dartium compilation errors. | 71 // needed for dartium compilation errors. |
| 59 showErrorAndExit(e && e.message); | 72 showErrorAndExit(e && e.message); |
| 60 }, false); | 73 }, false); |
| 61 | 74 |
| 62 document.onreadystatechange = function() { | 75 document.addEventListener('readystatechange', function () { |
| 63 if (document.readyState != "loaded") return; | 76 if (document.readyState != "loaded") return; |
| 64 // If 'startedDartTest' is not set, that means that the test did not have | 77 // If 'startedDartTest' is not set, that means that the test did not have |
| 65 // a chance to load. This will happen when a load error occurs in the VM. | 78 // a chance to load. This will happen when a load error occurs in the VM. |
| 66 // Give the machine time to start up. | 79 // Give the machine time to start up. |
| 67 setTimeout(function() { | 80 setTimeout(function() { |
| 68 // A window.postMessage might have been enqueued after this timeout. | 81 // A window.postMessage might have been enqueued after this timeout. |
| 69 // Just sleep another time to give the browser the time to process the | 82 // Just sleep another time to give the browser the time to process the |
| 70 // posted message. | 83 // posted message. |
| 71 setTimeout(function() { | 84 setTimeout(function() { |
| 72 if (testRunner && !testRunner.startedDartTest) { | 85 if (testRunner && !testRunner.startedDartTest) { |
| 73 testRunner.notifyDone(); | 86 testRunner.notifyDone(); |
| 74 } | 87 } |
| 75 }, 0); | 88 }, 0); |
| 76 }, 50); | 89 }, 50); |
| 77 }; | 90 }); |
| 91 | |
| 92 function dartPrint(msg) { | |
| 93 if ((msg === 'unittest-suite-success') | |
|
kasperl
2012/09/10 10:46:30
Maybe this could be based on a message prefix like
| |
| 94 || (msg === 'unittest-suite-wait-for-done')) { | |
| 95 window.postMessage(msg, '*'); | |
| 96 return; | |
| 97 } | |
| 98 var pre = document.createElement("pre"); | |
| 99 pre.appendChild(document.createTextNode(String(msg))); | |
| 100 document.body.appendChild(pre); | |
| 101 } | |
| 102 | |
| 103 function dartMainRunner(main) { | |
| 104 window.postMessage('dart-calling-main', '*'); | |
| 105 main(); | |
| 106 window.postMessage('dart-main-done', '*'); | |
| 107 } | |
| OLD | NEW |