| 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 * 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_html_enhanced_config; | 11 library unittest_html_enhanced_config; |
| 12 | 12 |
| 13 import 'dart:async'; | 13 import 'dart:async'; |
| 14 import 'dart:collection' show LinkedHashMap; | 14 import 'dart:collection' show LinkedHashMap; |
| 15 import 'dart:convert'; |
| 15 import 'dart:html'; | 16 import 'dart:html'; |
| 16 import 'unittest.dart'; | 17 import 'unittest.dart'; |
| 17 | 18 |
| 18 class HtmlEnhancedConfiguration extends SimpleConfiguration { | 19 class HtmlEnhancedConfiguration extends SimpleConfiguration { |
| 19 /** Whether this is run within dartium layout tests. */ | 20 /** Whether this is run within dartium layout tests. */ |
| 20 final bool _isLayoutTest; | 21 final bool _isLayoutTest; |
| 21 HtmlEnhancedConfiguration(this._isLayoutTest); | 22 HtmlEnhancedConfiguration(this._isLayoutTest); |
| 22 | 23 |
| 23 var _onErrorSubscription = null; | 24 var _onErrorSubscription = null; |
| 24 var _onMessageSubscription = null; | 25 var _onMessageSubscription = null; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 229 |
| 229 document.body.children.clear(); | 230 document.body.children.clear(); |
| 230 document.body.children.add(te); | 231 document.body.children.add(te); |
| 231 } | 232 } |
| 232 } | 233 } |
| 233 | 234 |
| 234 void _buildRow(TestCase test_, Element te, String groupID, bool isVisible) { | 235 void _buildRow(TestCase test_, Element te, String groupID, bool isVisible) { |
| 235 var background = 'unittest-row-${test_.id % 2 == 0 ? "even" : "odd"}'; | 236 var background = 'unittest-row-${test_.id % 2 == 0 ? "even" : "odd"}'; |
| 236 var display = '${isVisible ? "unittest-row" : "unittest-row-hidden"}'; | 237 var display = '${isVisible ? "unittest-row" : "unittest-row-hidden"}'; |
| 237 | 238 |
| 238 // TODO (prujohn@gmail.com) I had to borrow this from html_print.dart | |
| 239 // Probably should put it in some more common location. | |
| 240 String _htmlEscape(String string) { | |
| 241 return string.replaceAll('&', '&') | |
| 242 .replaceAll('<','<') | |
| 243 .replaceAll('>','>'); | |
| 244 } | |
| 245 | |
| 246 addRowElement(id, status, description){ | 239 addRowElement(id, status, description){ |
| 247 te.children.add( | 240 te.children.add( |
| 248 new Element.html( | 241 new Element.html( |
| 249 ''' <div> | 242 ''' <div> |
| 250 <div class='$display unittest-row-${groupID} $background'> | 243 <div class='$display unittest-row-${groupID} $background'> |
| 251 <div ${_isIE ? "style='display:inline-block' ": ""} | 244 <div ${_isIE ? "style='display:inline-block' ": ""} |
| 252 class='unittest-row-id'>$id</div> | 245 class='unittest-row-id'>$id</div> |
| 253 <div ${_isIE ? "style='display:inline-block' ": ""} | 246 <div ${_isIE ? "style='display:inline-block' ": ""} |
| 254 class="unittest-row-status unittest-${test_.result}"> | 247 class="unittest-row-status unittest-${test_.result}"> |
| 255 $status</div> | 248 $status</div> |
| 256 <div ${_isIE ? "style='display:inline-block' ": ""} | 249 <div ${_isIE ? "style='display:inline-block' ": ""} |
| 257 class='unittest-row-description'>$description</div> | 250 class='unittest-row-description'>$description</div> |
| 258 </div> | 251 </div> |
| 259 </div>''' | 252 </div>''' |
| 260 ) | 253 ) |
| 261 ); | 254 ); |
| 262 } | 255 } |
| 263 | 256 |
| 264 if (!test_.isComplete) { | 257 if (!test_.isComplete) { |
| 265 addRowElement('${test_.id}', 'NO STATUS', 'Test did not complete.'); | 258 addRowElement('${test_.id}', 'NO STATUS', 'Test did not complete.'); |
| 266 return; | 259 return; |
| 267 } | 260 } |
| 268 | 261 |
| 269 addRowElement('${test_.id}', '${test_.result.toUpperCase()}', | 262 addRowElement('${test_.id}', '${test_.result.toUpperCase()}', |
| 270 '${test_.description}. ${_htmlEscape(test_.message)}'); | 263 '${test_.description}. ${HTML_ESCAPE.convert(test_.message)}'); |
| 271 | 264 |
| 272 if (test_.stackTrace != null) { | 265 if (test_.stackTrace != null) { |
| 273 addRowElement('', '', | 266 addRowElement('', '', |
| 274 '<pre>${_htmlEscape(test_.stackTrace.toString())}</pre>'); | 267 '<pre>${HTML_ESCAPE.convert(test_.stackTrace.toString())}</pre>'); |
| 275 } | 268 } |
| 276 } | 269 } |
| 277 | 270 |
| 278 | 271 |
| 279 static bool get _isIE => window.navigator.userAgent.contains('MSIE'); | 272 static bool get _isIE => window.navigator.userAgent.contains('MSIE'); |
| 280 | 273 |
| 281 String get _htmlTestCSS => | 274 String get _htmlTestCSS => |
| 282 ''' | 275 ''' |
| 283 body{ | 276 body{ |
| 284 font-size: 14px; | 277 font-size: 14px; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 | 410 |
| 418 '''; | 411 '''; |
| 419 } | 412 } |
| 420 | 413 |
| 421 void useHtmlEnhancedConfiguration([bool isLayoutTest = false]) { | 414 void useHtmlEnhancedConfiguration([bool isLayoutTest = false]) { |
| 422 unittestConfiguration = isLayoutTest ? _singletonLayout : _singletonNotLayout; | 415 unittestConfiguration = isLayoutTest ? _singletonLayout : _singletonNotLayout; |
| 423 } | 416 } |
| 424 | 417 |
| 425 final _singletonLayout = new HtmlEnhancedConfiguration(true); | 418 final _singletonLayout = new HtmlEnhancedConfiguration(true); |
| 426 final _singletonNotLayout = new HtmlEnhancedConfiguration(false); | 419 final _singletonNotLayout = new HtmlEnhancedConfiguration(false); |
| OLD | NEW |