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

Side by Side Diff: pkg/unittest/lib/html_layout_config.dart

Issue 11770004: Rename Date to DateTime. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 * A configuration for running layoutr tests with testrunner. 6 * A configuration for running layoutr tests with testrunner.
7 * This configuration is similar to the interactive_html_config 7 * This configuration is similar to the interactive_html_config
8 * as it runs each test in its own IFrame. However, where the former 8 * as it runs each test in its own IFrame. However, where the former
9 * recreated the IFrame for each test, here the IFrames are preserved. 9 * recreated the IFrame for each test, here the IFrames are preserved.
10 * Furthermore we post a message on completion. 10 * Furthermore we post a message on completion.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 */ 64 */
65 class ChildHtmlConfiguration extends Configuration { 65 class ChildHtmlConfiguration extends Configuration {
66 get name => 'ChildHtmlConfiguration'; 66 get name => 'ChildHtmlConfiguration';
67 // TODO(rnystrom): Get rid of this if we get canonical closures for methods. 67 // TODO(rnystrom): Get rid of this if we get canonical closures for methods.
68 EventListener _onErrorClosure; 68 EventListener _onErrorClosure;
69 69
70 /** The window to which results must be posted. */ 70 /** The window to which results must be posted. */
71 Window parentWindow; 71 Window parentWindow;
72 72
73 /** The time at which tests start. */ 73 /** The time at which tests start. */
74 Map<int,Date> _testStarts; 74 Map<int,DateTime> _testStarts;
75 75
76 ChildHtmlConfiguration() : 76 ChildHtmlConfiguration() :
77 _testStarts = new Map<int,Date>(); 77 _testStarts = new Map<int,DateTime>();
78 78
79 /** Don't start running tests automatically. */ 79 /** Don't start running tests automatically. */
80 get autoStart => false; 80 get autoStart => false;
81 81
82 void onInit() { 82 void onInit() {
83 _onErrorClosure = 83 _onErrorClosure =
84 (e) => handleExternalError(e, '(DOM callback has errors)'); 84 (e) => handleExternalError(e, '(DOM callback has errors)');
85 85
86 /** 86 /**
87 * The parent posts a 'start' message to kick things off, 87 * The parent posts a 'start' message to kick things off,
(...skipping 16 matching lines...) Expand all
104 } 104 }
105 105
106 void onStart() { 106 void onStart() {
107 // Listen for uncaught errors. 107 // Listen for uncaught errors.
108 window.on.error.add(_onErrorClosure); 108 window.on.error.add(_onErrorClosure);
109 } 109 }
110 110
111 /** Record the start time of the test. */ 111 /** Record the start time of the test. */
112 void onTestStart(TestCase testCase) { 112 void onTestStart(TestCase testCase) {
113 super.onTestStart(testCase); 113 super.onTestStart(testCase);
114 _testStarts[testCase.id]= new Date.now(); 114 _testStarts[testCase.id]= new DateTime.now();
115 } 115 }
116 116
117 /** 117 /**
118 * Tests can call [log] for diagnostic output. These log 118 * Tests can call [log] for diagnostic output. These log
119 * messages in turn get passed to this method, which adds 119 * messages in turn get passed to this method, which adds
120 * a timestamp and posts them back to the parent window. 120 * a timestamp and posts them back to the parent window.
121 */ 121 */
122 void logTestCaseMessage(TestCase testCase, String message) { 122 void logTestCaseMessage(TestCase testCase, String message) {
123 int elapsed; 123 int elapsed;
124 if (testCase == null) { 124 if (testCase == null) {
125 elapsed = -1; 125 elapsed = -1;
126 } else { 126 } else {
127 Date end = new Date.now(); 127 DateTime end = new DateTime.now();
128 elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; 128 elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds;
129 } 129 }
130 parentWindow.postMessage( 130 parentWindow.postMessage(
131 _Message.text(_Message.LOG, elapsed, message).toString(), '*'); 131 _Message.text(_Message.LOG, elapsed, message).toString(), '*');
132 } 132 }
133 133
134 /** 134 /**
135 * Get the elapsed time for the test, and post the test result 135 * Get the elapsed time for the test, and post the test result
136 * back to the parent window. If the test failed due to an exception 136 * back to the parent window. If the test failed due to an exception
137 * the stack is posted back too (before the test result). 137 * the stack is posted back too (before the test result).
138 */ 138 */
139 void onTestResult(TestCase testCase) { 139 void onTestResult(TestCase testCase) {
140 super.onTestResult(testCase); 140 super.onTestResult(testCase);
141 Date end = new Date.now(); 141 DateTime end = new DateTime.now();
142 int elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; 142 int elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds;
143 if (testCase.stackTrace != null) { 143 if (testCase.stackTrace != null) {
144 parentWindow.postMessage( 144 parentWindow.postMessage(
145 _Message.text(_Message.STACK, elapsed, testCase.stackTrace), '*'); 145 _Message.text(_Message.STACK, elapsed, testCase.stackTrace), '*');
146 } 146 }
147 parentWindow.postMessage( 147 parentWindow.postMessage(
148 _Message.text(testCase.result, elapsed, testCase.message), '*'); 148 _Message.text(testCase.result, elapsed, testCase.message), '*');
149 } 149 }
150 150
151 void onDone(int passed, int failed, int errors, List<TestCase> results, 151 void onDone(int passed, int failed, int errors, List<TestCase> results,
152 String uncaughtError) { 152 String uncaughtError) {
153 window.on.error.remove(_onErrorClosure); 153 window.on.error.remove(_onErrorClosure);
154 } 154 }
155 } 155 }
156 156
157 /** 157 /**
158 * The parent configuration runs in the top-level window; it wraps the tests 158 * The parent configuration runs in the top-level window; it wraps the tests
159 * in new functions that create child IFrames and run the real tests. 159 * in new functions that create child IFrames and run the real tests.
160 */ 160 */
161 class ParentHtmlConfiguration extends Configuration { 161 class ParentHtmlConfiguration extends Configuration {
162 get autoStart => false; 162 get autoStart => false;
163 get name => 'ParentHtmlConfiguration'; 163 get name => 'ParentHtmlConfiguration';
164 Map<int,Date> _testStarts; 164 Map<int,DateTime> _testStarts;
165 // TODO(rnystrom): Get rid of this if we get canonical closures for methods. 165 // TODO(rnystrom): Get rid of this if we get canonical closures for methods.
166 EventListener _onErrorClosure; 166 EventListener _onErrorClosure;
167 167
168 /** The stack that was posted back from the child, if any. */ 168 /** The stack that was posted back from the child, if any. */
169 String _stack; 169 String _stack;
170 170
171 int _testTime; 171 int _testTime;
172 /** 172 /**
173 * Whether or not we have already wrapped the TestCase test functions 173 * Whether or not we have already wrapped the TestCase test functions
174 * in new closures that instead create an IFrame and get it to run the 174 * in new closures that instead create an IFrame and get it to run the
175 * test. 175 * test.
176 */ 176 */
177 bool _doneWrap = false; 177 bool _doneWrap = false;
178 178
179 /** 179 /**
180 * We use this to make a single closure from _handleMessage so we 180 * We use this to make a single closure from _handleMessage so we
181 * can remove the handler later. 181 * can remove the handler later.
182 */ 182 */
183 Function _messageHandler; 183 Function _messageHandler;
184 184
185 ParentHtmlConfiguration() : 185 ParentHtmlConfiguration() :
186 _testStarts = new Map<int,Date>(); 186 _testStarts = new Map<int,DateTime>();
187 187
188 // We need to block until the test is done, so we make a 188 // We need to block until the test is done, so we make a
189 // dummy async callback that we will use to flag completion. 189 // dummy async callback that we will use to flag completion.
190 Function completeTest = null; 190 Function completeTest = null;
191 191
192 wrapTest(TestCase testCase) { 192 wrapTest(TestCase testCase) {
193 String baseUrl = window.location.toString(); 193 String baseUrl = window.location.toString();
194 String url = '${baseUrl}?t=${testCase.id}'; 194 String url = '${baseUrl}?t=${testCase.id}';
195 return () { 195 return () {
196 // Add the child IFrame. 196 // Add the child IFrame.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 testCases[i].test = wrapTest(testCases[i]); 245 testCases[i].test = wrapTest(testCases[i]);
246 testCases[i].setUp = null; 246 testCases[i].setUp = null;
247 testCases[i].tearDown = null; 247 testCases[i].tearDown = null;
248 } 248 }
249 } 249 }
250 window.on.message.add(_messageHandler); 250 window.on.message.add(_messageHandler);
251 } 251 }
252 252
253 void onTestStart(TestCase testCase) { 253 void onTestStart(TestCase testCase) {
254 var id = testCase.id; 254 var id = testCase.id;
255 _testStarts[testCase.id]= new Date.now(); 255 _testStarts[testCase.id]= new DateTime.now();
256 super.onTestStart(testCase); 256 super.onTestStart(testCase);
257 _stack = null; 257 _stack = null;
258 } 258 }
259 259
260 // Actually test logging is handled by the child, then posted 260 // Actually test logging is handled by the child, then posted
261 // back to the parent. So here we know that the [message] argument 261 // back to the parent. So here we know that the [message] argument
262 // is in the format used by [_Message]. 262 // is in the format used by [_Message].
263 void logTestCaseMessage(TestCase testCase, String message) { 263 void logTestCaseMessage(TestCase testCase, String message) {
264 var msg = new _Message.fromString(message); 264 var msg = new _Message.fromString(message);
265 document.query('#otherlogs').nodes.add( 265 document.query('#otherlogs').nodes.add(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 */ 301 */
302 void useHtmlLayoutConfiguration() { 302 void useHtmlLayoutConfiguration() {
303 if (window.location.search == '') { // This is the parent. 303 if (window.location.search == '') { // This is the parent.
304 _prepareDom(); 304 _prepareDom();
305 configure(new ParentHtmlConfiguration()); 305 configure(new ParentHtmlConfiguration());
306 } else { 306 } else {
307 configure(new ChildHtmlConfiguration()); 307 configure(new ChildHtmlConfiguration());
308 } 308 }
309 } 309 }
310 310
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698