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 /// A simple unit test library for running tests in a browser. | 5 /// A simple unit test library for running tests in a browser. |
6 library unittest.html_config; | 6 library unittest.html_config; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'dart:html'; | 10 import 'dart:html'; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 window.onHashChange.listen((_) { | 55 window.onHashChange.listen((_) { |
56 // Location may change from individual tests setting the hash tag. | 56 // Location may change from individual tests setting the hash tag. |
57 if (window.location.hash != null && | 57 if (window.location.hash != null && |
58 window.location.hash.contains('testFilter')) { | 58 window.location.hash.contains('testFilter')) { |
59 window.location.reload(); | 59 window.location.reload(); |
60 } | 60 } |
61 }); | 61 }); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 String _toHtml(TestCase test_) { | 65 String _toHtml(TestCase testCase) { |
66 if (!test_.isComplete) { | 66 if (!testCase.isComplete) { |
67 return ''' | 67 return ''' |
68 <tr> | 68 <tr> |
69 <td>${test_.id}</td> | 69 <td>${testCase.id}</td> |
70 <td class="unittest-error">NO STATUS</td> | 70 <td class="unittest-error">NO STATUS</td> |
71 <td>Test did not complete</td> | 71 <td>Test did not complete</td> |
72 </tr>'''; | 72 </tr>'''; |
73 } | 73 } |
74 | 74 |
75 var html = ''' | 75 var html = ''' |
76 <tr> | 76 <tr> |
77 <td>${test_.id}</td> | 77 <td>${testCase.id}</td> |
78 <td class="unittest-${test_.result}">${test_.result.toUpperCase()}</td> | 78 <td class="unittest-${testCase.result}"> |
79 <td>Expectation: <a href="#testFilter=${test_.description}">${test_.desc
ription}</a>. ${HTML_ESCAPE.convert(test_.message)}</td> | 79 ${testCase.result.toUpperCase()} |
| 80 </td> |
| 81 <td> |
| 82 <p>Expectation: |
| 83 <a href="#testFilter=${testCase.description}"> |
| 84 ${testCase.description} |
| 85 </a>. |
| 86 </p> |
| 87 <pre>${HTML_ESCAPE.convert(testCase.message)}</pre> |
| 88 </td> |
80 </tr>'''; | 89 </tr>'''; |
81 | 90 |
82 if (test_.stackTrace != null) { | 91 if (testCase.stackTrace != null) { |
83 html = '$html<tr><td></td><td colspan="2"><pre>' + | 92 html = '$html<tr><td></td><td colspan="2"><pre>' + |
84 HTML_ESCAPE.convert(test_.stackTrace.toString()) + | 93 HTML_ESCAPE.convert(testCase.stackTrace.toString()) + |
85 '</pre></td></tr>'; | 94 '</pre></td></tr>'; |
86 } | 95 } |
87 | 96 |
88 return html; | 97 return html; |
89 } | 98 } |
90 | 99 |
91 class HtmlConfiguration extends SimpleConfiguration { | 100 class HtmlConfiguration extends SimpleConfiguration { |
92 /// Whether this is run within dartium layout tests. | 101 /// Whether this is run within dartium layout tests. |
93 final bool _isLayoutTest; | 102 final bool _isLayoutTest; |
94 HtmlConfiguration(this._isLayoutTest); | 103 HtmlConfiguration(this._isLayoutTest); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 window.postMessage('unittest-suite-done', '*'); | 175 window.postMessage('unittest-suite-done', '*'); |
167 } | 176 } |
168 } | 177 } |
169 | 178 |
170 void useHtmlConfiguration([bool isLayoutTest = false]) { | 179 void useHtmlConfiguration([bool isLayoutTest = false]) { |
171 unittestConfiguration = isLayoutTest ? _singletonLayout : _singletonNotLayout; | 180 unittestConfiguration = isLayoutTest ? _singletonLayout : _singletonNotLayout; |
172 } | 181 } |
173 | 182 |
174 final _singletonLayout = new HtmlConfiguration(true); | 183 final _singletonLayout = new HtmlConfiguration(true); |
175 final _singletonNotLayout = new HtmlConfiguration(false); | 184 final _singletonNotLayout = new HtmlConfiguration(false); |
OLD | NEW |