Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: dart/pkg/unittest/test_controller.js

Issue 10918168: Run dart2js tests unmodified in drt. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review comments Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 // dart2js will generate code to call this function to handle the Dart
93 // [print] method. The base [Configuration] (config.html) calls
94 // [print] with the secret messages "unittest-suite-success" and
95 // "unittest-suite-wait-for-done". These messages are then posted so
96 // processMessage above will see them.
97 function dartPrint(msg) {
98 if ((msg === 'unittest-suite-success')
99 || (msg === 'unittest-suite-wait-for-done')) {
100 window.postMessage(msg, '*');
101 return;
102 }
103 var pre = document.createElement("pre");
104 pre.appendChild(document.createTextNode(String(msg)));
105 document.body.appendChild(pre);
106 }
107
108 // dart2js will generate code to call this function instead of calling
109 // Dart [main] directly. The argument is a closure that invokes main.
110 function dartMainRunner(main) {
111 window.postMessage('dart-calling-main', '*');
112 main();
113 window.postMessage('dart-main-done', '*');
114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698