OLD | NEW |
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 * This configuration can be used to rerun selected tests, as well | 6 * This configuration can be used to rerun selected tests, as well |
7 * as see diagnostic output from tests. It runs each test in its own | 7 * as see diagnostic output from tests. It runs each test in its own |
8 * IFrame, so the configuration consists of two parts - a 'parent' | 8 * IFrame, so the configuration consists of two parts - a 'parent' |
9 * config that manages all the tests, and a 'child' config for the | 9 * config that manages all the tests, and a 'child' config for the |
10 * IFrame that runs the individual tests. | 10 * IFrame that runs the individual tests. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 * an IFrame and post the results back to the parent. In principle | 78 * an IFrame and post the results back to the parent. In principle |
79 * this can run more than one test in the IFrame but currently only | 79 * this can run more than one test in the IFrame but currently only |
80 * one is used. | 80 * one is used. |
81 */ | 81 */ |
82 class ChildInteractiveHtmlConfiguration extends HtmlConfiguration { | 82 class ChildInteractiveHtmlConfiguration extends HtmlConfiguration { |
83 | 83 |
84 /** The window to which results must be posted. */ | 84 /** The window to which results must be posted. */ |
85 Window parentWindow; | 85 Window parentWindow; |
86 | 86 |
87 /** The time at which tests start. */ | 87 /** The time at which tests start. */ |
88 Map<int,Date> _testStarts; | 88 Map<int,DateTime> _testStarts; |
89 | 89 |
90 ChildInteractiveHtmlConfiguration() : | 90 ChildInteractiveHtmlConfiguration() : |
91 _testStarts = new Map<int,Date>(); | 91 _testStarts = new Map<int,DateTime>(); |
92 | 92 |
93 /** Don't start running tests automatically. */ | 93 /** Don't start running tests automatically. */ |
94 get autoStart => false; | 94 get autoStart => false; |
95 | 95 |
96 void onInit() { | 96 void onInit() { |
97 _installErrorHandler(); | 97 _installErrorHandler(); |
98 | 98 |
99 /** | 99 /** |
100 * The parent posts a 'start' message to kick things off, | 100 * The parent posts a 'start' message to kick things off, |
101 * which is handled by this handler. It saves the parent | 101 * which is handled by this handler. It saves the parent |
(...skipping 15 matching lines...) Expand all Loading... |
117 }); | 117 }); |
118 } | 118 } |
119 | 119 |
120 void onStart() { | 120 void onStart() { |
121 _installErrorHandler(); | 121 _installErrorHandler(); |
122 } | 122 } |
123 | 123 |
124 /** Record the start time of the test. */ | 124 /** Record the start time of the test. */ |
125 void onTestStart(TestCase testCase) { | 125 void onTestStart(TestCase testCase) { |
126 super.onTestStart(testCase); | 126 super.onTestStart(testCase); |
127 _testStarts[testCase.id]= new Date.now(); | 127 _testStarts[testCase.id]= new DateTime.now(); |
128 } | 128 } |
129 | 129 |
130 /** | 130 /** |
131 * Tests can call [logMessage] for diagnostic output. These log | 131 * Tests can call [logMessage] for diagnostic output. These log |
132 * messages in turn get passed to this method, which adds | 132 * messages in turn get passed to this method, which adds |
133 * a timestamp and posts them back to the parent window. | 133 * a timestamp and posts them back to the parent window. |
134 */ | 134 */ |
135 void logTestCaseMessage(TestCase testCase, String message) { | 135 void logTestCaseMessage(TestCase testCase, String message) { |
136 int elapsed; | 136 int elapsed; |
137 if (testCase == null) { | 137 if (testCase == null) { |
138 elapsed = -1; | 138 elapsed = -1; |
139 } else { | 139 } else { |
140 Date end = new Date.now(); | 140 DateTime end = new DateTime.now(); |
141 elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; | 141 elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; |
142 } | 142 } |
143 parentWindow.postMessage( | 143 parentWindow.postMessage( |
144 _Message.text(_Message.LOG, elapsed, message).toString(), '*'); | 144 _Message.text(_Message.LOG, elapsed, message).toString(), '*'); |
145 } | 145 } |
146 | 146 |
147 /** | 147 /** |
148 * Get the elapsed time for the test, anbd post the test result | 148 * Get the elapsed time for the test, anbd post the test result |
149 * back to the parent window. If the test failed due to an exception | 149 * back to the parent window. If the test failed due to an exception |
150 * the stack is posted back too (before the test result). | 150 * the stack is posted back too (before the test result). |
151 */ | 151 */ |
152 void onTestResult(TestCase testCase) { | 152 void onTestResult(TestCase testCase) { |
153 super.onTestResult(testCase); | 153 super.onTestResult(testCase); |
154 Date end = new Date.now(); | 154 DateTime end = new DateTime.now(); |
155 int elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; | 155 int elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; |
156 if (testCase.stackTrace != null) { | 156 if (testCase.stackTrace != null) { |
157 parentWindow.postMessage( | 157 parentWindow.postMessage( |
158 _Message.text(_Message.STACK, elapsed, testCase.stackTrace), '*'); | 158 _Message.text(_Message.STACK, elapsed, testCase.stackTrace), '*'); |
159 } | 159 } |
160 parentWindow.postMessage( | 160 parentWindow.postMessage( |
161 _Message.text(testCase.result, elapsed, testCase.message), '*'); | 161 _Message.text(testCase.result, elapsed, testCase.message), '*'); |
162 } | 162 } |
163 | 163 |
164 void onDone(int passed, int failed, int errors, List<TestCase> results, | 164 void onDone(int passed, int failed, int errors, List<TestCase> results, |
165 String uncaughtError) { | 165 String uncaughtError) { |
166 _uninstallErrorHandler(); | 166 _uninstallErrorHandler(); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 /** | 170 /** |
171 * The parent configuration runs in the top-level window; it wraps the tests | 171 * The parent configuration runs in the top-level window; it wraps the tests |
172 * in new functions that create child IFrames and run the real tests. | 172 * in new functions that create child IFrames and run the real tests. |
173 */ | 173 */ |
174 class ParentInteractiveHtmlConfiguration extends HtmlConfiguration { | 174 class ParentInteractiveHtmlConfiguration extends HtmlConfiguration { |
175 Map<int,Date> _testStarts; | 175 Map<int,DateTime> _testStarts; |
176 | 176 |
177 | 177 |
178 /** The stack that was posted back from the child, if any. */ | 178 /** The stack that was posted back from the child, if any. */ |
179 String _stack; | 179 String _stack; |
180 | 180 |
181 int _testTime; | 181 int _testTime; |
182 /** | 182 /** |
183 * Whether or not we have already wrapped the TestCase test functions | 183 * Whether or not we have already wrapped the TestCase test functions |
184 * in new closures that instead create an IFrame and get it to run the | 184 * in new closures that instead create an IFrame and get it to run the |
185 * test. | 185 * test. |
186 */ | 186 */ |
187 bool _doneWrap = false; | 187 bool _doneWrap = false; |
188 | 188 |
189 /** | 189 /** |
190 * We use this to make a single closure from _handleMessage so we | 190 * We use this to make a single closure from _handleMessage so we |
191 * can remove the handler later. | 191 * can remove the handler later. |
192 */ | 192 */ |
193 Function _messageHandler; | 193 Function _messageHandler; |
194 | 194 |
195 ParentInteractiveHtmlConfiguration() : | 195 ParentInteractiveHtmlConfiguration() : |
196 _testStarts = new Map<int,Date>(); | 196 _testStarts = new Map<int,DateTime>(); |
197 | 197 |
198 // We need to block until the test is done, so we make a | 198 // We need to block until the test is done, so we make a |
199 // dummy async callback that we will use to flag completion. | 199 // dummy async callback that we will use to flag completion. |
200 Function completeTest = null; | 200 Function completeTest = null; |
201 | 201 |
202 wrapTest(TestCase testCase) { | 202 wrapTest(TestCase testCase) { |
203 String baseUrl = window.location.toString(); | 203 String baseUrl = window.location.toString(); |
204 String url = '${baseUrl}?t=${testCase.id}'; | 204 String url = '${baseUrl}?t=${testCase.id}'; |
205 return () { | 205 return () { |
206 // Rebuild the child IFrame. | 206 // Rebuild the child IFrame. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 | 269 |
270 // Used for DOM element IDs for tests result list entries. | 270 // Used for DOM element IDs for tests result list entries. |
271 static const _testIdPrefix = 'test-'; | 271 static const _testIdPrefix = 'test-'; |
272 // Used for DOM element IDs for test log message lists. | 272 // Used for DOM element IDs for test log message lists. |
273 static const _actionIdPrefix = 'act-'; | 273 static const _actionIdPrefix = 'act-'; |
274 // Used for DOM element IDs for test checkboxes. | 274 // Used for DOM element IDs for test checkboxes. |
275 static const _selectedIdPrefix = 'selected-'; | 275 static const _selectedIdPrefix = 'selected-'; |
276 | 276 |
277 void onTestStart(TestCase testCase) { | 277 void onTestStart(TestCase testCase) { |
278 var id = testCase.id; | 278 var id = testCase.id; |
279 _testStarts[testCase.id]= new Date.now(); | 279 _testStarts[testCase.id]= new DateTime.now(); |
280 super.onTestStart(testCase); | 280 super.onTestStart(testCase); |
281 _stack = null; | 281 _stack = null; |
282 // Convert the group name to a DOM id. | 282 // Convert the group name to a DOM id. |
283 String groupId = _stringToDomId(testCase.currentGroup); | 283 String groupId = _stringToDomId(testCase.currentGroup); |
284 // Get the div for the group. If it doesn't exist, | 284 // Get the div for the group. If it doesn't exist, |
285 // create it. | 285 // create it. |
286 var groupDiv = document.query('#$groupId'); | 286 var groupDiv = document.query('#$groupId'); |
287 if (groupDiv == null) { | 287 if (groupDiv == null) { |
288 groupDiv = new Element.html(""" | 288 groupDiv = new Element.html(""" |
289 <div class='test-describe' id='$groupId'> | 289 <div class='test-describe' id='$groupId'> |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 display: block; | 664 display: block; |
665 list-style-type: disc; | 665 list-style-type: disc; |
666 -webkit-margin-before: 1em; | 666 -webkit-margin-before: 1em; |
667 -webkit-margin-after: 1em; | 667 -webkit-margin-after: 1em; |
668 -webkit-margin-start: 0px; | 668 -webkit-margin-start: 0px; |
669 -webkit-margin-end: 0px; | 669 -webkit-margin-end: 0px; |
670 -webkit-padding-start: 40px; | 670 -webkit-padding-start: 40px; |
671 } | 671 } |
672 | 672 |
673 """; | 673 """; |
OLD | NEW |