Chromium Code Reviews| 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 library unittest_html_config; | 8 library unittest_html_config; |
| 9 | 9 |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 newBody.write(""" | 44 newBody.write(""" |
| 45 <tr><td colspan='3'>Total | 45 <tr><td colspan='3'>Total |
| 46 <span class='unittest-pass'>${passed} passed</span>, | 46 <span class='unittest-pass'>${passed} passed</span>, |
| 47 <span class='unittest-fail'>${failed} failed</span> | 47 <span class='unittest-fail'>${failed} failed</span> |
| 48 <span class='unittest-error'> | 48 <span class='unittest-error'> |
| 49 ${errors + (uncaughtError == null ? 0 : 1)} errors</span> | 49 ${errors + (uncaughtError == null ? 0 : 1)} errors</span> |
| 50 </td></tr>"""); | 50 </td></tr>"""); |
| 51 } | 51 } |
| 52 newBody.write("</tbody></table>"); | 52 newBody.write("</tbody></table>"); |
| 53 document.body.innerHtml = newBody.toString(); | 53 document.body.innerHtml = newBody.toString(); |
| 54 | |
| 55 window.onHashChange.listen((_) { | |
| 56 window.location.reload(); | |
| 57 }); | |
| 54 } | 58 } |
| 55 } | 59 } |
| 56 | 60 |
| 57 String _toHtml(TestCase test_) { | 61 String _toHtml(TestCase test_) { |
| 58 if (!test_.isComplete) { | 62 if (!test_.isComplete) { |
| 59 return ''' | 63 return ''' |
| 60 <tr> | 64 <tr> |
| 61 <td>${test_.id}</td> | 65 <td>${test_.id}</td> |
| 62 <td class="unittest-error">NO STATUS</td> | 66 <td class="unittest-error">NO STATUS</td> |
| 63 <td>Test did not complete</td> | 67 <td>Test did not complete</td> |
| 64 </tr>'''; | 68 </tr>'''; |
| 65 } | 69 } |
| 66 | 70 |
| 67 var html = ''' | 71 var html = ''' |
| 68 <tr> | 72 <tr> |
| 69 <td>${test_.id}</td> | 73 <td>${test_.id}</td> |
| 70 <td class="unittest-${test_.result}">${test_.result.toUpperCase()}</td> | 74 <td class="unittest-${test_.result}">${test_.result.toUpperCase()}</td> |
| 71 <td>Expectation: ${test_.description}. ${_htmlEscape(test_.message)}</td > | 75 <td>Expectation: <a href="#testFilter=${test_.description}">${test_.desc ription}</a>. ${_htmlEscape(test_.message)}</td> |
| 72 </tr>'''; | 76 </tr>'''; |
| 73 | 77 |
| 74 if (test_.stackTrace != null) { | 78 if (test_.stackTrace != null) { |
| 75 html = '$html<tr><td></td><td colspan="2"><pre>${_htmlEscape(test_.stackTrac e)}</pre></td></tr>'; | 79 html = '$html<tr><td></td><td colspan="2"><pre>${_htmlEscape(test_.stackTrac e)}</pre></td></tr>'; |
| 76 } | 80 } |
| 77 | 81 |
| 78 return html; | 82 return html; |
| 79 } | 83 } |
| 80 | 84 |
| 81 //TODO(pquitslund): Move to a common lib | 85 //TODO(pquitslund): Move to a common lib |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 if ('unittest-suite-external-error' == e.data) { | 123 if ('unittest-suite-external-error' == e.data) { |
| 120 handleExternalError('<unknown>', '(external error detected)'); | 124 handleExternalError('<unknown>', '(external error detected)'); |
| 121 } | 125 } |
| 122 } | 126 } |
| 123 | 127 |
| 124 void onInit() { | 128 void onInit() { |
| 125 _installHandlers(); | 129 _installHandlers(); |
| 126 window.postMessage('unittest-suite-wait-for-done', '*'); | 130 window.postMessage('unittest-suite-wait-for-done', '*'); |
| 127 } | 131 } |
| 128 | 132 |
| 133 void onStart() { | |
| 134 var hash = window.location.hash; | |
| 135 if (hash != null && hash.length > 1) { | |
| 136 var params = hash.substring(1).split('&'); | |
| 137 for (var param in params) { | |
| 138 var parts = param.split('='); | |
| 139 if (parts.length == 2 && parts[0] == 'testFilter') { | |
| 140 filterTests('^${parts[1]}'); | |
|
gram
2013/03/14 18:39:08
This is cool, but can you add some comments as to
blois
2013/03/14 21:37:19
Done.
| |
| 141 } | |
| 142 } | |
| 143 } | |
| 144 super.onStart(); | |
| 145 } | |
| 146 | |
| 129 void onSummary(int passed, int failed, int errors, List<TestCase> results, | 147 void onSummary(int passed, int failed, int errors, List<TestCase> results, |
| 130 String uncaughtError) { | 148 String uncaughtError) { |
| 131 _showResultsInPage(passed, failed, errors, results, _isLayoutTest, | 149 _showResultsInPage(passed, failed, errors, results, _isLayoutTest, |
| 132 uncaughtError); | 150 uncaughtError); |
| 133 } | 151 } |
| 134 | 152 |
| 135 void onDone(bool success) { | 153 void onDone(bool success) { |
| 136 _uninstallHandlers(); | 154 _uninstallHandlers(); |
| 137 window.postMessage('unittest-suite-done', '*'); | 155 window.postMessage('unittest-suite-done', '*'); |
| 138 } | 156 } |
| 139 } | 157 } |
| 140 | 158 |
| 141 void useHtmlConfiguration([bool isLayoutTest = false]) { | 159 void useHtmlConfiguration([bool isLayoutTest = false]) { |
| 142 if (config != null) return; | 160 if (config != null) return; |
| 143 configure(new HtmlConfiguration(isLayoutTest)); | 161 configure(new HtmlConfiguration(isLayoutTest)); |
| 144 } | 162 } |
| OLD | NEW |