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