| 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 * Description text of the current test group. If multiple groups are nested, | 6 * Description text of the current test group. If multiple groups are nested, |
| 7 * this will contain all of their text concatenated. | 7 * this will contain all of their text concatenated. |
| 8 */ | 8 */ |
| 9 String _currentGroup = ''; | 9 String _currentGroup = ''; |
| 10 | 10 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 128 |
| 129 void forLayoutTests() { | 129 void forLayoutTests() { |
| 130 _isLayoutTest = true; | 130 _isLayoutTest = true; |
| 131 } | 131 } |
| 132 | 132 |
| 133 /** Runs all queued tests, one at a time. */ | 133 /** Runs all queued tests, one at a time. */ |
| 134 _runTests() { | 134 _runTests() { |
| 135 window.postMessage('unittest-suite-start', '*'); | 135 window.postMessage('unittest-suite-start', '*'); |
| 136 window.setTimeout(() { | 136 window.setTimeout(() { |
| 137 assert (_currentTest == 0); | 137 assert (_currentTest == 0); |
| 138 |
| 138 // Listen for uncaught errors. | 139 // Listen for uncaught errors. |
| 139 try { | 140 window.onerror = _onErrorClosure; |
| 140 window.on.error.add(_onErrorClosure); | |
| 141 } catch(var e) { | |
| 142 // TODO(jacobr): remove this horrible hack when dartc bugs are fixed. | |
| 143 window.dynamic.onerror = _onErrorClosure; | |
| 144 } | |
| 145 _nextBatch(); | 141 _nextBatch(); |
| 146 }, 0); | 142 }, 0); |
| 147 } | 143 } |
| 148 | 144 |
| 149 /** Runs a single test. */ | 145 /** Runs a single test. */ |
| 150 _runTest(TestCase testCase) { | 146 _runTest(TestCase testCase) { |
| 151 try { | 147 try { |
| 152 // TODO(sigmund): remove this declaration once dartc supports trapping error | 148 // TODO(sigmund): remove this declaration once dartc supports trapping error |
| 153 // traces. | 149 // traces. |
| 154 var trace = ''; | 150 var trace = ''; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 if (!testCase.isComplete && testCase.callbacks > 0) return; | 185 if (!testCase.isComplete && testCase.callbacks > 0) return; |
| 190 | 186 |
| 191 _currentTest++; | 187 _currentTest++; |
| 192 } | 188 } |
| 193 | 189 |
| 194 _completeTests(); | 190 _completeTests(); |
| 195 } | 191 } |
| 196 | 192 |
| 197 /** Publish results on the page and notify controller. */ | 193 /** Publish results on the page and notify controller. */ |
| 198 _completeTests() { | 194 _completeTests() { |
| 199 try { | 195 window.onerror = null; |
| 200 window.on.error.remove(_onErrorClosure); | |
| 201 } catch (var e) { | |
| 202 // TODO(jacobr): remove this horrible hack to work around dartc bugs. | |
| 203 window.dynamic.onerror = null; | |
| 204 } | |
| 205 | 196 |
| 206 _state = _UNINITIALIZED; | 197 _state = _UNINITIALIZED; |
| 207 | 198 |
| 208 int testsFailed = 0; | 199 int testsFailed = 0; |
| 209 int testsErrors = 0; | 200 int testsErrors = 0; |
| 210 int testsPassed = 0; | 201 int testsPassed = 0; |
| 211 | 202 |
| 212 for (TestCase t in _tests) { | 203 for (TestCase t in _tests) { |
| 213 if (t.success) testsPassed++; | 204 if (t.success) testsPassed++; |
| 214 if (t.fail) testsFailed++; | 205 if (t.fail) testsFailed++; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 236 <tr><td colspan='3'>Total | 227 <tr><td colspan='3'>Total |
| 237 <span class='unittest-pass'>${testsPassed} passed</span>, | 228 <span class='unittest-pass'>${testsPassed} passed</span>, |
| 238 <span class='unittest-fail'>${testsFailed} failed</span> | 229 <span class='unittest-fail'>${testsFailed} failed</span> |
| 239 <span class='unittest-error'>${testsErrors} errors</span> | 230 <span class='unittest-error'>${testsErrors} errors</span> |
| 240 </td></tr>"""); | 231 </td></tr>"""); |
| 241 } | 232 } |
| 242 newBody.add("</tbody></table>"); | 233 newBody.add("</tbody></table>"); |
| 243 document.body.innerHTML = newBody.toString(); | 234 document.body.innerHTML = newBody.toString(); |
| 244 } | 235 } |
| 245 | 236 |
| 246 window.dynamic/*TODO(5389254)*/.postMessage('unittest-suite-done', '*'); | 237 window.postMessage('unittest-suite-done', '*'); |
| 247 } | 238 } |
| 248 | 239 |
| 249 void _onError(e) { | 240 void _onError(e) { |
| 250 if (_currentTest < _tests.length) { | 241 if (_currentTest < _tests.length) { |
| 251 final testCase = _tests[_currentTest]; | 242 final testCase = _tests[_currentTest]; |
| 252 // TODO(vsm): figure out how to expose the stack trace here | 243 // TODO(vsm): figure out how to expose the stack trace here |
| 253 // Currently e.message works in dartium, but not in dartc. | 244 // Currently e.message works in dartium, but not in dartc. |
| 254 testCase.recordError('(DOM callback has errors) Caught ${e}', ''); | 245 testCase.recordError('(DOM callback has errors) Caught ${e}', ''); |
| 255 _state = _UNCAUGHT_ERROR; | 246 _state = _UNCAUGHT_ERROR; |
| 256 if (testCase.callbacks > 0) { | 247 if (testCase.callbacks > 0) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 274 _tests = <TestCase>[]; | 265 _tests = <TestCase>[]; |
| 275 _onErrorClosure = (e) { _onError(e); }; | 266 _onErrorClosure = (e) { _onError(e); }; |
| 276 | 267 |
| 277 // Immediately queue the suite up. It will run after a timeout (i.e. after | 268 // Immediately queue the suite up. It will run after a timeout (i.e. after |
| 278 // main() has returned). | 269 // main() has returned). |
| 279 listener(e) { | 270 listener(e) { |
| 280 _currentGroup = ''; | 271 _currentGroup = ''; |
| 281 _runTests(); | 272 _runTests(); |
| 282 }; | 273 }; |
| 283 | 274 |
| 284 try { | 275 window.addEventListener('DOMContentLoaded', listener, false); |
| 285 window.dynamic.on.contentLoaded.add(listener); | |
| 286 } catch(var e) { | |
| 287 // TODO(jacobr): remove this horrible hack to work around dartc bugs. | |
| 288 window.dynamic.addEventListener("DOMContentLoaded", listener, false); | |
| 289 } | |
| 290 | 276 |
| 291 _state = _READY; | 277 _state = _READY; |
| 292 } | 278 } |
| 293 | 279 |
| 294 /** | 280 /** |
| 295 * Wraps an value and provides an "==" operator that can be used to verify that | 281 * Wraps an value and provides an "==" operator that can be used to verify that |
| 296 * the value matches a given expectation. | 282 * the value matches a given expectation. |
| 297 */ | 283 */ |
| 298 class Expectation { | 284 class Expectation { |
| 299 final _value; | 285 final _value; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 '''; | 400 '''; |
| 415 | 401 |
| 416 if (stackTrace != null) { | 402 if (stackTrace != null) { |
| 417 message += | 403 message += |
| 418 '<tr><td></td><td colspan="2"><pre>${stackTrace}</pre></td></tr>'; | 404 '<tr><td></td><td colspan="2"><pre>${stackTrace}</pre></td></tr>'; |
| 419 } | 405 } |
| 420 } | 406 } |
| 421 } | 407 } |
| 422 | 408 |
| 423 typedef void TestFunction(); | 409 typedef void TestFunction(); |
| OLD | NEW |