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 /** Configuration for running tests in a browser using dart:dom. */ |
6 * A simple unit test library for running tests in a browser. | 6 #library('dom_config'); |
7 */ | |
8 #library('unittest'); | |
9 | 7 |
10 #import('dart:dom'); | 8 #import('dart:dom'); |
11 #import('dart:isolate'); | 9 #import('unittest.dart'); |
12 | 10 |
13 #source('config.dart'); | |
14 #source('shared.dart'); | |
15 #source('html_print.dart'); | 11 #source('html_print.dart'); |
16 | 12 |
17 /** Whether this is run within dartium layout tests. */ | 13 class DomConfiguration extends Configuration { |
18 bool _isLayoutTest = false; | 14 /** Whether this is run within dartium layout tests. */ |
15 final bool _isLayoutTest; | |
16 DomConfiguration(this._isLayoutTest); | |
Bob Nystrom
2012/04/12 16:45:49
Style nit, newline before this to separate from fi
Siggi Cherem (dart-lang)
2012/04/12 17:36:28
Done.
| |
19 | 17 |
20 void forLayoutTests() { | |
21 _isLayoutTest = true; | |
22 } | |
23 | |
24 class PlatformConfiguration extends Configuration { | |
25 // TODO(rnystrom): Get rid of this if we get canonical closures for methods. | 18 // TODO(rnystrom): Get rid of this if we get canonical closures for methods. |
26 EventListener _onErrorClosure; | 19 EventListener _onErrorClosure; |
27 | 20 |
28 void onInit() { | 21 void onInit() { |
29 _onErrorClosure = (e) { _onError(e); }; | 22 _onErrorClosure = (e) { |
30 } | |
31 | |
32 void _onError(e) { | |
33 if (_currentTest < _tests.length) { | |
34 final testCase = _tests[_currentTest]; | |
35 // TODO(vsm): figure out how to expose the stack trace here | 23 // TODO(vsm): figure out how to expose the stack trace here |
36 // Currently e.message works in dartium, but not in dartc. | 24 // Currently e.message works in dartium, but not in dartc. |
37 testCase.error('(DOM callback has errors) Caught ${e}', ''); | 25 notifyError('(DOM callback has errors) Caught ${e}', ''); |
Bob Nystrom
2012/04/12 16:45:49
$e
Siggi Cherem (dart-lang)
2012/04/12 17:36:28
Done.
| |
38 _state = _UNCAUGHT_ERROR; | 26 }; |
39 if (testCase.callbacks > 0) { | |
40 _currentTest++; | |
41 _testRunner(); | |
42 } | |
43 } | |
44 } | 27 } |
45 | 28 |
46 void onStart() { | 29 void onStart() { |
47 window.postMessage('unittest-suite-wait-for-done', '*'); | 30 window.postMessage('unittest-suite-wait-for-done', '*'); |
48 // Listen for uncaught errors. | 31 // Listen for uncaught errors. |
49 window.addEventListener('error', _onErrorClosure, true); | 32 window.addEventListener('error', _onErrorClosure, true); |
50 } | 33 } |
51 | 34 |
52 void onTestResult(TestCase testCase) {} | 35 void onTestResult(TestCase testCase) {} |
53 | 36 |
54 void onDone(int passed, int failed, int errors, List<TestCase> results) { | 37 void onDone(int passed, int failed, int errors, List<TestCase> results) { |
55 window.removeEventListener('error', _onErrorClosure); | 38 window.removeEventListener('error', _onErrorClosure); |
56 _showResultsInPage(passed, failed, errors, results, _isLayoutTest); | 39 _showResultsInPage(passed, failed, errors, results, _isLayoutTest); |
57 window.postMessage('unittest-suite-done', '*'); | 40 window.postMessage('unittest-suite-done', '*'); |
58 } | 41 } |
59 } | 42 } |
43 | |
44 void useDomConfiguration([bool isLayoutTest = false]) { | |
45 configure(new DomConfiguration(isLayoutTest)); | |
46 } | |
OLD | NEW |