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; |
| 15 |
14 function processMessage(msg) { | 16 function processMessage(msg) { |
15 if (window.layoutTestController) { | 17 if (testRunner) { |
16 if (msg == 'unittest-suite-done') { | 18 if (msg == 'unittest-suite-done') { |
17 window.layoutTestController.notifyDone(); | 19 testRunner.notifyDone(); |
18 } else if (msg == 'unittest-suite-wait-for-done') { | 20 } else if (msg == 'unittest-suite-wait-for-done') { |
19 window.layoutTestController.startedDartTest = true; | 21 testRunner.startedDartTest = true; |
20 } | 22 } |
21 } | 23 } |
22 } | 24 } |
23 | 25 |
24 function onReceive(e) { | 26 function onReceive(e) { |
25 processMessage(e.data); | 27 processMessage(e.data); |
26 } | 28 } |
27 | 29 |
28 if (window.layoutTestController) { | 30 if (testRunner) { |
29 window.layoutTestController.dumpAsText(); | 31 testRunner.dumpAsText(); |
30 window.layoutTestController.waitUntilDone(); | 32 testRunner.waitUntilDone(); |
31 } | 33 } |
32 window.addEventListener("message", onReceive, false); | 34 window.addEventListener("message", onReceive, false); |
33 | 35 |
34 function showErrorAndExit(message) { | 36 function showErrorAndExit(message) { |
35 if (message) { | 37 if (message) { |
36 var element = document.createElement('pre'); | 38 var element = document.createElement('pre'); |
37 element.innerHTML = message; | 39 element.innerHTML = message; |
38 document.body.appendChild(element); | 40 document.body.appendChild(element); |
39 } | 41 } |
40 if (window.layoutTestController) { | 42 if (testRunner) { |
41 window.layoutTestController.notifyDone(); | 43 testRunner.notifyDone(); |
42 } | 44 } |
43 } | 45 } |
44 | 46 |
45 function onLoad(e) { | 47 function onLoad(e) { |
46 // needed for dartium compilation errors. | 48 // needed for dartium compilation errors. |
47 if (window.compilationError) { | 49 if (window.compilationError) { |
48 showErrorAndExit(window.compilationError); | 50 showErrorAndExit(window.compilationError); |
49 } | 51 } |
50 } | 52 } |
51 | 53 |
52 window.addEventListener("DOMContentLoaded", onLoad, false); | 54 window.addEventListener("DOMContentLoaded", onLoad, false); |
53 | 55 |
54 // If nobody intercepts the error, finish the test. | 56 // If nobody intercepts the error, finish the test. |
55 window.addEventListener("error", function(e) { | 57 window.addEventListener("error", function(e) { |
56 // needed for dartium compilation errors. | 58 // needed for dartium compilation errors. |
57 showErrorAndExit(e && e.message); | 59 showErrorAndExit(e && e.message); |
58 }, false); | 60 }, false); |
59 | 61 |
60 document.onreadystatechange = function() { | 62 document.onreadystatechange = function() { |
61 if (document.readyState != "loaded") return; | 63 if (document.readyState != "loaded") return; |
62 // If 'startedDartTest' is not set, that means that the test did not have | 64 // If 'startedDartTest' is not set, that means that the test did not have |
63 // a chance to load. This will happen when a load error occurs in the VM. | 65 // a chance to load. This will happen when a load error occurs in the VM. |
64 // Give the machine time to start up. | 66 // Give the machine time to start up. |
65 setTimeout(function() { | 67 setTimeout(function() { |
66 // A window.postMessage might have been enqueued after this timeout. | 68 // A window.postMessage might have been enqueued after this timeout. |
67 // Just sleep another time to give the browser the time to process the | 69 // Just sleep another time to give the browser the time to process the |
68 // posted message. | 70 // posted message. |
69 setTimeout(function() { | 71 setTimeout(function() { |
70 if (layoutTestController && !layoutTestController.startedDartTest) { | 72 if (testRunner && !testRunner.startedDartTest) { |
71 layoutTestController.notifyDone(); | 73 testRunner.notifyDone(); |
72 } | 74 } |
73 }, 0); | 75 }, 0); |
74 }, 50); | 76 }, 50); |
75 }; | 77 }; |
OLD | NEW |