| 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 * 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 EventListener _onMessageClosure; | |
| 25 | 24 |
| 26 void onInit() { | 25 void onInit() { |
| 27 //initialize and load CSS | 26 //initialize and load CSS |
| 28 final String _CSSID = '_unittestcss_'; | 27 final String _CSSID = '_unittestcss_'; |
| 29 | 28 |
| 30 var cssElement = document.head.query('#${_CSSID}'); | 29 var cssElement = document.head.query('#${_CSSID}'); |
| 31 if (cssElement == null){ | 30 if (cssElement == null){ |
| 32 document.head.elements.add(new Element.html( | 31 document.head.elements.add(new Element.html( |
| 33 '<style id="${_CSSID}"></style>')); | 32 '<style id="${_CSSID}"></style>')); |
| 34 cssElement = document.head.query('#${_CSSID}'); | 33 cssElement = document.head.query('#${_CSSID}'); |
| 35 } | 34 } |
| 36 | 35 |
| 37 cssElement.innerHTML = _htmlTestCSS; | 36 cssElement.innerHTML = _htmlTestCSS; |
| 38 | 37 |
| 39 _onErrorClosure = | 38 _onErrorClosure = |
| 40 (e) => handleExternalError(e, '(DOM callback has errors)'); | 39 (e) => handleExternalError(e, '(DOM callback has errors)'); |
| 41 _onMessageClosure = (m) { | |
| 42 if (m.data == 'unittest-suite-external-error') { | |
| 43 handleExternalError('<unknown>', '(external error detected)'); | |
| 44 } | |
| 45 }; | |
| 46 } | 40 } |
| 47 | 41 |
| 48 void onStart() { | 42 void onStart() { |
| 49 window.postMessage('unittest-suite-wait-for-done', '*'); | 43 window.postMessage('unittest-suite-wait-for-done', '*'); |
| 50 // Listen for uncaught errors. | 44 // Listen for uncaught errors. |
| 51 window.on.error.add(_onErrorClosure); | 45 window.on.error.add(_onErrorClosure); |
| 52 window.on.error.add(_onMessageClosure); | |
| 53 } | 46 } |
| 54 | 47 |
| 55 void onTestResult(TestCase testCase) {} | 48 void onTestResult(TestCase testCase) {} |
| 56 | 49 |
| 57 void onDone(int passed, int failed, int errors, List<TestCase> results, | 50 void onDone(int passed, int failed, int errors, List<TestCase> results, |
| 58 String uncaughtError) { | 51 String uncaughtError) { |
| 59 window.on.error.remove(_onErrorClosure); | 52 window.on.error.remove(_onErrorClosure); |
| 60 window.on.error.remove(_onMessageClosure); | |
| 61 | 53 |
| 62 _showInteractiveResultsInPage(passed, failed, errors, results, | 54 _showInteractiveResultsInPage(passed, failed, errors, results, |
| 63 _isLayoutTest, uncaughtError); | 55 _isLayoutTest, uncaughtError); |
| 64 | 56 |
| 65 window.postMessage('unittest-suite-done', '*'); | 57 window.postMessage('unittest-suite-done', '*'); |
| 66 } | 58 } |
| 67 | 59 |
| 68 void _showInteractiveResultsInPage(int passed, int failed, int errors, | 60 void _showInteractiveResultsInPage(int passed, int failed, int errors, |
| 69 List<TestCase> results, bool isLayoutTest, String uncaughtError) { | 61 List<TestCase> results, bool isLayoutTest, String uncaughtError) { |
| 70 if (isLayoutTest && passed == results.length) { | 62 if (isLayoutTest && passed == results.length) { |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 .unittest-row-description | 373 .unittest-row-description |
| 382 { | 374 { |
| 383 } | 375 } |
| 384 | 376 |
| 385 '''; | 377 '''; |
| 386 } | 378 } |
| 387 | 379 |
| 388 void useHtmlEnhancedConfiguration([bool isLayoutTest = false]) { | 380 void useHtmlEnhancedConfiguration([bool isLayoutTest = false]) { |
| 389 configure(new HtmlEnhancedConfiguration(isLayoutTest)); | 381 configure(new HtmlEnhancedConfiguration(isLayoutTest)); |
| 390 } | 382 } |
| OLD | NEW |