| 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:html'; | 12 import 'dart:html'; |
| 12 import 'unittest.dart'; | 13 import 'unittest.dart'; |
| 13 | 14 |
| 14 /** Creates a table showing tests results in HTML. */ | 15 /** Creates a table showing tests results in HTML. */ |
| 15 void _showResultsInPage(int passed, int failed, int errors, | 16 void _showResultsInPage(int passed, int failed, int errors, |
| 16 List<TestCase> results, bool isLayoutTest, String uncaughtError) { | 17 List<TestCase> results, bool isLayoutTest, String uncaughtError) { |
| 17 if (isLayoutTest && (passed == results.length) && uncaughtError == null) { | 18 if (isLayoutTest && (passed == results.length) && uncaughtError == null) { |
| 18 document.body.innerHtml = "PASS"; | 19 document.body.innerHtml = "PASS"; |
| 19 } else { | 20 } else { |
| 20 var newBody = new StringBuffer(); | 21 var newBody = new StringBuffer(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 <td>${test_.id}</td> | 70 <td>${test_.id}</td> |
| 70 <td class="unittest-error">NO STATUS</td> | 71 <td class="unittest-error">NO STATUS</td> |
| 71 <td>Test did not complete</td> | 72 <td>Test did not complete</td> |
| 72 </tr>'''; | 73 </tr>'''; |
| 73 } | 74 } |
| 74 | 75 |
| 75 var html = ''' | 76 var html = ''' |
| 76 <tr> | 77 <tr> |
| 77 <td>${test_.id}</td> | 78 <td>${test_.id}</td> |
| 78 <td class="unittest-${test_.result}">${test_.result.toUpperCase()}</td> | 79 <td class="unittest-${test_.result}">${test_.result.toUpperCase()}</td> |
| 79 <td>Expectation: <a href="#testFilter=${test_.description}">${test_.desc
ription}</a>. ${_htmlEscape(test_.message)}</td> | 80 <td>Expectation: <a href="#testFilter=${test_.description}">${test_.desc
ription}</a>. ${HTML_ESCAPE.convert(test_.message)}</td> |
| 80 </tr>'''; | 81 </tr>'''; |
| 81 | 82 |
| 82 if (test_.stackTrace != null) { | 83 if (test_.stackTrace != null) { |
| 83 html = '$html<tr><td></td><td colspan="2"><pre>' + | 84 html = '$html<tr><td></td><td colspan="2"><pre>' + |
| 84 _htmlEscape(test_.stackTrace.toString()) + | 85 HTML_ESCAPE.convert(test_.stackTrace.toString()) + |
| 85 '</pre></td></tr>'; | 86 '</pre></td></tr>'; |
| 86 } | 87 } |
| 87 | 88 |
| 88 return html; | 89 return html; |
| 89 } | 90 } |
| 90 | 91 |
| 91 //TODO(pquitslund): Move to a common lib | |
| 92 String _htmlEscape(String string) { | |
| 93 return string.replaceAll('&', '&') | |
| 94 .replaceAll('<','<') | |
| 95 .replaceAll('>','>'); | |
| 96 } | |
| 97 | |
| 98 class HtmlConfiguration extends SimpleConfiguration { | 92 class HtmlConfiguration extends SimpleConfiguration { |
| 99 /** Whether this is run within dartium layout tests. */ | 93 /** Whether this is run within dartium layout tests. */ |
| 100 final bool _isLayoutTest; | 94 final bool _isLayoutTest; |
| 101 HtmlConfiguration(this._isLayoutTest); | 95 HtmlConfiguration(this._isLayoutTest); |
| 102 | 96 |
| 103 StreamSubscription<Event> _onErrorSubscription; | 97 StreamSubscription<Event> _onErrorSubscription; |
| 104 StreamSubscription<Event> _onMessageSubscription; | 98 StreamSubscription<Event> _onMessageSubscription; |
| 105 | 99 |
| 106 void _installHandlers() { | 100 void _installHandlers() { |
| 107 if (_onErrorSubscription == null) { | 101 if (_onErrorSubscription == null) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 window.postMessage('unittest-suite-done', '*'); | 163 window.postMessage('unittest-suite-done', '*'); |
| 170 } | 164 } |
| 171 } | 165 } |
| 172 | 166 |
| 173 void useHtmlConfiguration([bool isLayoutTest = false]) { | 167 void useHtmlConfiguration([bool isLayoutTest = false]) { |
| 174 unittestConfiguration = isLayoutTest ? _singletonLayout : _singletonNotLayout; | 168 unittestConfiguration = isLayoutTest ? _singletonLayout : _singletonNotLayout; |
| 175 } | 169 } |
| 176 | 170 |
| 177 final _singletonLayout = new HtmlConfiguration(true); | 171 final _singletonLayout = new HtmlConfiguration(true); |
| 178 final _singletonNotLayout = new HtmlConfiguration(false); | 172 final _singletonNotLayout = new HtmlConfiguration(false); |
| OLD | NEW |