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

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: Address comments and keep Backwards-compatibility class Date. 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
« no previous file with comments | « pkg/unittest/lib/compact_vm_config.dart ('k') | pkg/unittest/lib/interactive_html_config.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 onSummary(int passed, int failed, int errors, List<TestCase> results, 151 void onSummary(int passed, int failed, int errors, List<TestCase> results,
152 String uncaughtError) { 152 String uncaughtError) {
153 } 153 }
154 154
155 void onDone(bool success) { 155 void onDone(bool success) {
156 window.on.error.remove(_onErrorClosure); 156 window.on.error.remove(_onErrorClosure);
157 } 157 }
158 } 158 }
159 159
160 /** 160 /**
161 * The parent configuration runs in the top-level window; it wraps the tests 161 * The parent configuration runs in the top-level window; it wraps the tests
162 * in new functions that create child IFrames and run the real tests. 162 * in new functions that create child IFrames and run the real tests.
163 */ 163 */
164 class ParentHtmlConfiguration extends Configuration { 164 class ParentHtmlConfiguration extends Configuration {
165 get autoStart => false; 165 get autoStart => false;
166 get name => 'ParentHtmlConfiguration'; 166 get name => 'ParentHtmlConfiguration';
167 Map<int,Date> _testStarts; 167 Map<int,DateTime> _testStarts;
168 // TODO(rnystrom): Get rid of this if we get canonical closures for methods. 168 // TODO(rnystrom): Get rid of this if we get canonical closures for methods.
169 EventListener _onErrorClosure; 169 EventListener _onErrorClosure;
170 170
171 /** The stack that was posted back from the child, if any. */ 171 /** The stack that was posted back from the child, if any. */
172 String _stack; 172 String _stack;
173 173
174 int _testTime; 174 int _testTime;
175 /** 175 /**
176 * Whether or not we have already wrapped the TestCase test functions 176 * Whether or not we have already wrapped the TestCase test functions
177 * in new closures that instead create an IFrame and get it to run the 177 * in new closures that instead create an IFrame and get it to run the
178 * test. 178 * test.
179 */ 179 */
180 bool _doneWrap = false; 180 bool _doneWrap = false;
181 181
182 /** 182 /**
183 * We use this to make a single closure from _handleMessage so we 183 * We use this to make a single closure from _handleMessage so we
184 * can remove the handler later. 184 * can remove the handler later.
185 */ 185 */
186 Function _messageHandler; 186 Function _messageHandler;
187 187
188 ParentHtmlConfiguration() : 188 ParentHtmlConfiguration() :
189 _testStarts = new Map<int,Date>(); 189 _testStarts = new Map<int,DateTime>();
190 190
191 // We need to block until the test is done, so we make a 191 // We need to block until the test is done, so we make a
192 // dummy async callback that we will use to flag completion. 192 // dummy async callback that we will use to flag completion.
193 Function completeTest = null; 193 Function completeTest = null;
194 194
195 wrapTest(TestCase testCase) { 195 wrapTest(TestCase testCase) {
196 String baseUrl = window.location.toString(); 196 String baseUrl = window.location.toString();
197 String url = '${baseUrl}?t=${testCase.id}'; 197 String url = '${baseUrl}?t=${testCase.id}';
198 return () { 198 return () {
199 // Add the child IFrame. 199 // Add the child IFrame.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 testCases[i].test = wrapTest(testCases[i]); 248 testCases[i].test = wrapTest(testCases[i]);
249 testCases[i].setUp = null; 249 testCases[i].setUp = null;
250 testCases[i].tearDown = null; 250 testCases[i].tearDown = null;
251 } 251 }
252 } 252 }
253 window.on.message.add(_messageHandler); 253 window.on.message.add(_messageHandler);
254 } 254 }
255 255
256 void onTestStart(TestCase testCase) { 256 void onTestStart(TestCase testCase) {
257 var id = testCase.id; 257 var id = testCase.id;
258 _testStarts[testCase.id]= new Date.now(); 258 _testStarts[testCase.id]= new DateTime.now();
259 super.onTestStart(testCase); 259 super.onTestStart(testCase);
260 _stack = null; 260 _stack = null;
261 } 261 }
262 262
263 // Actually test logging is handled by the child, then posted 263 // Actually test logging is handled by the child, then posted
264 // back to the parent. So here we know that the [message] argument 264 // back to the parent. So here we know that the [message] argument
265 // is in the format used by [_Message]. 265 // is in the format used by [_Message].
266 void logTestCaseMessage(TestCase testCase, String message) { 266 void logTestCaseMessage(TestCase testCase, String message) {
267 var msg = new _Message.fromString(message); 267 var msg = new _Message.fromString(message);
268 document.query('#otherlogs').nodes.add( 268 document.query('#otherlogs').nodes.add(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 void useHtmlLayoutConfiguration() { 307 void useHtmlLayoutConfiguration() {
308 if (config != null) return; 308 if (config != null) return;
309 if (window.location.search == '') { // This is the parent. 309 if (window.location.search == '') { // This is the parent.
310 _prepareDom(); 310 _prepareDom();
311 configure(new ParentHtmlConfiguration()); 311 configure(new ParentHtmlConfiguration());
312 } else { 312 } else {
313 configure(new ChildHtmlConfiguration()); 313 configure(new ChildHtmlConfiguration());
314 } 314 }
315 } 315 }
316 316
OLDNEW
« no previous file with comments | « pkg/unittest/lib/compact_vm_config.dart ('k') | pkg/unittest/lib/interactive_html_config.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698