Chromium Code Reviews| 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 * A simple unit test library for running tests in a browser. | 6 * A simple unit test library for running tests in a browser. |
| 7 */ | 7 */ |
| 8 #library('unittest'); | 8 #library('unittest'); |
| 9 | 9 |
| 10 #import('dart:html'); | 10 #import('dart:html'); |
| 11 #import('unittest.dart'); | 11 #import('unittest.dart'); |
| 12 | 12 |
| 13 #source('html_print.dart'); | 13 #source('html_print.dart'); |
| 14 | 14 |
| 15 class HtmlConfiguration extends Configuration { | 15 class HtmlConfiguration extends Configuration { |
| 16 /** Whether this is run within dartium layout tests. */ | 16 /** Whether this is run within dartium layout tests. */ |
| 17 final bool _isLayoutTest; | 17 final bool _isLayoutTest; |
| 18 HtmlConfiguration(this._isLayoutTest); | 18 HtmlConfiguration(this._isLayoutTest); |
| 19 | 19 |
| 20 // TODO(rnystrom): Get rid of this if we get canonical closures for methods. | 20 // TODO(rnystrom): Get rid of this if we get canonical closures for methods. |
| 21 EventListener _onErrorClosure; | 21 EventListener _onErrorClosure; |
| 22 | 22 |
| 23 void _installErrorHandler() { | |
| 24 if (_onErrorClosure == null) { | |
| 25 _onErrorClosure = | |
| 26 (e) => handleExternalError(e, '(DOM callback has errors)'); | |
| 27 // Listen for uncaught errors. | |
| 28 window.on.error.add(_onErrorClosure); | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 void _removeErrorHandler() { | |
|
Siggi Cherem (dart-lang)
2012/09/20 20:41:31
maybe rename [_removeErrorHandler] to [_uninstallE
gram
2012/09/20 20:48:29
Done.
| |
| 33 if (_onErrorClosure != null) { | |
| 34 window.on.error.remove(_onErrorClosure); | |
| 35 _onErrorClosure = null; | |
| 36 } | |
| 37 } | |
| 38 | |
| 23 void onInit() { | 39 void onInit() { |
| 24 _onErrorClosure = | 40 _installErrorHandler(); |
| 25 (e) => handleExternalError(e, '(DOM callback has errors)'); | |
| 26 } | 41 } |
| 27 | 42 |
| 28 void onStart() { | 43 void onStart() { |
| 44 _installErrorHandler(); | |
| 29 window.postMessage('unittest-suite-wait-for-done', '*'); | 45 window.postMessage('unittest-suite-wait-for-done', '*'); |
| 30 // Listen for uncaught errors. | |
| 31 window.on.error.add(_onErrorClosure); | |
| 32 } | 46 } |
| 33 | 47 |
| 34 void onTestResult(TestCase testCase) {} | 48 void onTestResult(TestCase testCase) {} |
| 35 | 49 |
| 36 void onDone(int passed, int failed, int errors, List<TestCase> results, | 50 void onDone(int passed, int failed, int errors, List<TestCase> results, |
| 37 String uncaughtError) { | 51 String uncaughtError) { |
| 38 window.on.error.remove(_onErrorClosure); | 52 _removeErrorHandler(); |
|
Siggi Cherem (dart-lang)
2012/09/20 20:41:31
since the idea of detaching/reataching it is mostl
gram
2012/09/20 20:48:29
Done.
| |
| 39 _showResultsInPage(passed, failed, errors, results, _isLayoutTest, | 53 _showResultsInPage(passed, failed, errors, results, _isLayoutTest, |
| 40 uncaughtError); | 54 uncaughtError); |
| 41 window.postMessage('unittest-suite-done', '*'); | 55 window.postMessage('unittest-suite-done', '*'); |
| 42 } | 56 } |
| 43 } | 57 } |
| 44 | 58 |
| 45 void useHtmlConfiguration([bool isLayoutTest = false]) { | 59 void useHtmlConfiguration([bool isLayoutTest = false]) { |
| 46 configure(new HtmlConfiguration(isLayoutTest)); | 60 configure(new HtmlConfiguration(isLayoutTest)); |
| 47 } | 61 } |
| OLD | NEW |