Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_html_config; | 8 library unittest_html_config; |
| 9 | 9 |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| 11 import 'dart:convert'; | 11 import 'dart:convert'; |
| 12 import 'dart:html'; | 12 import 'dart:html'; |
| 13 import 'dart:js' as js; | |
| 13 import 'unittest.dart'; | 14 import 'unittest.dart'; |
| 14 | 15 |
| 15 /** Creates a table showing tests results in HTML. */ | 16 /** Creates a table showing tests results in HTML. */ |
| 16 void _showResultsInPage(int passed, int failed, int errors, | 17 void _showResultsInPage(int passed, int failed, int errors, |
| 17 List<TestCase> results, bool isLayoutTest, String uncaughtError) { | 18 List<TestCase> results, bool isLayoutTest, String uncaughtError) { |
| 18 if (isLayoutTest && (passed == results.length) && uncaughtError == null) { | 19 if (isLayoutTest && (passed == results.length) && uncaughtError == null) { |
| 19 document.body.innerHtml = "PASS"; | 20 document.body.innerHtml = "PASS"; |
| 20 } else { | 21 } else { |
| 21 var newBody = new StringBuffer(); | 22 var newBody = new StringBuffer(); |
| 22 newBody.write("<table class='unittest-table'><tbody>"); | 23 newBody.write("<table class='unittest-table'><tbody>"); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 /** Whether this is run within dartium layout tests. */ | 94 /** Whether this is run within dartium layout tests. */ |
| 94 final bool _isLayoutTest; | 95 final bool _isLayoutTest; |
| 95 HtmlConfiguration(this._isLayoutTest); | 96 HtmlConfiguration(this._isLayoutTest); |
| 96 | 97 |
| 97 StreamSubscription<Event> _onErrorSubscription; | 98 StreamSubscription<Event> _onErrorSubscription; |
| 98 StreamSubscription<Event> _onMessageSubscription; | 99 StreamSubscription<Event> _onMessageSubscription; |
| 99 | 100 |
| 100 void _installHandlers() { | 101 void _installHandlers() { |
| 101 if (_onErrorSubscription == null) { | 102 if (_onErrorSubscription == null) { |
| 102 _onErrorSubscription = window.onError.listen( | 103 _onErrorSubscription = window.onError.listen( |
| 103 (e) => handleExternalError(e, '(DOM callback has errors)')); | 104 (e) { |
| 105 // Some tests may expect this and have no way to suppress the error. | |
| 106 if (js.context['testExpectsGlobalError'] != true) { | |
|
vsm
2013/10/01 16:58:01
Perhaps it makes sense to clear this once it's bee
blois
2013/10/01 20:37:08
In a case such as innerHtml it'll be called multip
| |
| 107 handleExternalError(e, '(DOM callback has errors)'); | |
| 108 } | |
| 109 }); | |
| 104 } | 110 } |
| 105 if (_onMessageSubscription == null) { | 111 if (_onMessageSubscription == null) { |
| 106 _onMessageSubscription = window.onMessage.listen( | 112 _onMessageSubscription = window.onMessage.listen( |
| 107 (e) => processMessage(e)); | 113 (e) => processMessage(e)); |
| 108 } | 114 } |
| 109 } | 115 } |
| 110 | 116 |
| 111 void _uninstallHandlers() { | 117 void _uninstallHandlers() { |
| 112 if (_onErrorSubscription != null) { | 118 if (_onErrorSubscription != null) { |
| 113 _onErrorSubscription.cancel(); | 119 _onErrorSubscription.cancel(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 window.postMessage('unittest-suite-done', '*'); | 169 window.postMessage('unittest-suite-done', '*'); |
| 164 } | 170 } |
| 165 } | 171 } |
| 166 | 172 |
| 167 void useHtmlConfiguration([bool isLayoutTest = false]) { | 173 void useHtmlConfiguration([bool isLayoutTest = false]) { |
| 168 unittestConfiguration = isLayoutTest ? _singletonLayout : _singletonNotLayout; | 174 unittestConfiguration = isLayoutTest ? _singletonLayout : _singletonNotLayout; |
| 169 } | 175 } |
| 170 | 176 |
| 171 final _singletonLayout = new HtmlConfiguration(true); | 177 final _singletonLayout = new HtmlConfiguration(true); |
| 172 final _singletonNotLayout = new HtmlConfiguration(false); | 178 final _singletonNotLayout = new HtmlConfiguration(false); |
| OLD | NEW |