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

Side by Side Diff: pkg/unittest/html_enhanced_config.dart

Issue 10959025: Move the addition of an onError handler to earlier (onInit instead of onStart), while still support… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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/html_config.dart ('k') | pkg/unittest/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) 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 * Provides enhanced HTML output with collapsible group headers 8 * Provides enhanced HTML output with collapsible group headers
9 * and other at-a-glance information about the test results. 9 * and other at-a-glance information about the test results.
10 */ 10 */
11 #library('unittest'); 11 #library('unittest');
12 12
13 #import('dart:html'); 13 #import('dart:html');
14 #import('unittest.dart'); 14 #import('unittest.dart');
15 15
16 16
17 class HtmlEnhancedConfiguration extends Configuration { 17 class HtmlEnhancedConfiguration extends Configuration {
18 /** Whether this is run within dartium layout tests. */ 18 /** Whether this is run within dartium layout tests. */
19 final bool _isLayoutTest; 19 final bool _isLayoutTest;
20 HtmlEnhancedConfiguration(this._isLayoutTest); 20 HtmlEnhancedConfiguration(this._isLayoutTest);
21 21
22 // TODO(rnystrom): Get rid of this if we get canonical closures for methods. 22 // TODO(rnystrom): Get rid of this if we get canonical closures for methods.
23 EventListener _onErrorClosure; 23 EventListener _onErrorClosure;
24 24
25 void _installErrorHandler() {
26 if (_onErrorClosure == null) {
27 _onErrorClosure =
28 (e) => handleExternalError(e, '(DOM callback has errors)');
29 // Listen for uncaught errors.
30 window.on.error.add(_onErrorClosure);
31 }
32 }
33
34 void _uninstallErrorHandler() {
35 if (_onErrorClosure != null) {
36 window.on.error.remove(_onErrorClosure);
37 _onErrorClosure = null;
38 }
39 }
40
25 void onInit() { 41 void onInit() {
42 _installErrorHandler();
26 //initialize and load CSS 43 //initialize and load CSS
27 final String _CSSID = '_unittestcss_'; 44 final String _CSSID = '_unittestcss_';
28 45
29 var cssElement = document.head.query('#${_CSSID}'); 46 var cssElement = document.head.query('#${_CSSID}');
30 if (cssElement == null){ 47 if (cssElement == null){
31 document.head.elements.add(new Element.html( 48 document.head.elements.add(new Element.html(
32 '<style id="${_CSSID}"></style>')); 49 '<style id="${_CSSID}"></style>'));
33 cssElement = document.head.query('#${_CSSID}'); 50 cssElement = document.head.query('#${_CSSID}');
34 } 51 }
35 52
36 cssElement.innerHTML = _htmlTestCSS; 53 cssElement.innerHTML = _htmlTestCSS;
37
38 _onErrorClosure =
39 (e) => handleExternalError(e, '(DOM callback has errors)');
40 } 54 }
41 55
42 void onStart() { 56 void onStart() {
43 window.postMessage('unittest-suite-wait-for-done', '*'); 57 window.postMessage('unittest-suite-wait-for-done', '*');
44 // Listen for uncaught errors. 58 // Listen for uncaught errors.
45 window.on.error.add(_onErrorClosure); 59 window.on.error.add(_onErrorClosure);
46 } 60 }
47 61
48 void onTestResult(TestCase testCase) {} 62 void onTestResult(TestCase testCase) {}
49 63
50 void onDone(int passed, int failed, int errors, List<TestCase> results, 64 void onDone(int passed, int failed, int errors, List<TestCase> results,
51 String uncaughtError) { 65 String uncaughtError) {
52 window.on.error.remove(_onErrorClosure); 66 _uninstallErrorHandler();
53 67
54 _showInteractiveResultsInPage(passed, failed, errors, results, 68 _showInteractiveResultsInPage(passed, failed, errors, results,
55 _isLayoutTest, uncaughtError); 69 _isLayoutTest, uncaughtError);
56 70
57 window.postMessage('unittest-suite-done', '*'); 71 window.postMessage('unittest-suite-done', '*');
58 } 72 }
59 73
60 void _showInteractiveResultsInPage(int passed, int failed, int errors, 74 void _showInteractiveResultsInPage(int passed, int failed, int errors,
61 List<TestCase> results, bool isLayoutTest, String uncaughtError) { 75 List<TestCase> results, bool isLayoutTest, String uncaughtError) {
62 if (isLayoutTest && passed == results.length) { 76 if (isLayoutTest && passed == results.length) {
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 .unittest-row-description 387 .unittest-row-description
374 { 388 {
375 } 389 }
376 390
377 '''; 391 ''';
378 } 392 }
379 393
380 void useHtmlEnhancedConfiguration([bool isLayoutTest = false]) { 394 void useHtmlEnhancedConfiguration([bool isLayoutTest = false]) {
381 configure(new HtmlEnhancedConfiguration(isLayoutTest)); 395 configure(new HtmlEnhancedConfiguration(isLayoutTest));
382 } 396 }
OLDNEW
« no previous file with comments | « pkg/unittest/html_config.dart ('k') | pkg/unittest/interactive_html_config.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698