| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 /** This file is sourced by both dom_config.dart and html_config.dart. */ | |
| 6 | |
| 7 /** Creates a table showing tests results in HTML. */ | |
| 8 void _showResultsInPage(int passed, int failed, int errors, | |
| 9 List<TestCase> results, bool isLayoutTest, String uncaughtError) { | |
| 10 if (isLayoutTest && (passed == results.length) && uncaughtError == null) { | |
| 11 document.body.innerHTML = "PASS"; | |
| 12 } else { | |
| 13 var newBody = new StringBuffer(); | |
| 14 newBody.add("<table class='unittest-table'><tbody>"); | |
| 15 newBody.add(passed == results.length && uncaughtError == null | |
| 16 ? "<tr><td colspan='3' class='unittest-pass'>PASS</td></tr>" | |
| 17 : "<tr><td colspan='3' class='unittest-fail'>FAIL</td></tr>"); | |
| 18 | |
| 19 for (final test_ in results) { | |
| 20 newBody.add(_toHtml(test_)); | |
| 21 } | |
| 22 | |
| 23 if (uncaughtError != null) { | |
| 24 newBody.add('''<tr> | |
| 25 <td>--</td> | |
| 26 <td class="unittest-error">ERROR</td> | |
| 27 <td>Uncaught error: $uncaughtError</td> | |
| 28 </tr>'''); | |
| 29 } | |
| 30 | |
| 31 if (passed == results.length && uncaughtError == null) { | |
| 32 newBody.add(""" | |
| 33 <tr><td colspan='3' class='unittest-pass'> | |
| 34 All ${passed} tests passed | |
| 35 </td></tr>"""); | |
| 36 } else { | |
| 37 newBody.add(""" | |
| 38 <tr><td colspan='3'>Total | |
| 39 <span class='unittest-pass'>${passed} passed</span>, | |
| 40 <span class='unittest-fail'>${failed} failed</span> | |
| 41 <span class='unittest-error'> | |
| 42 ${errors + (uncaughtError == null ? 0 : 1)} errors</span> | |
| 43 </td></tr>"""); | |
| 44 } | |
| 45 newBody.add("</tbody></table>"); | |
| 46 document.body.innerHTML = newBody.toString(); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 String _toHtml(TestCase test_) { | |
| 51 if (!test_.isComplete) { | |
| 52 return ''' | |
| 53 <tr> | |
| 54 <td>${test_.id}</td> | |
| 55 <td class="unittest-error">NO STATUS</td> | |
| 56 <td>Test did not complete</td> | |
| 57 </tr>'''; | |
| 58 } | |
| 59 | |
| 60 var html = ''' | |
| 61 <tr> | |
| 62 <td>${test_.id}</td> | |
| 63 <td class="unittest-${test_.result}">${test_.result.toUpperCase()}</td> | |
| 64 <td>Expectation: ${test_.description}. ${_htmlEscape(test_.message)}</td
> | |
| 65 </tr>'''; | |
| 66 | |
| 67 if (test_.stackTrace != null) { | |
| 68 html = '$html<tr><td></td><td colspan="2"><pre>${_htmlEscape(test_.stackTrac
e)}</pre></td></tr>'; | |
| 69 } | |
| 70 | |
| 71 return html; | |
| 72 } | |
| 73 | |
| 74 //TODO(pquitslund): Move to a common lib | |
| 75 String _htmlEscape(String string) { | |
| 76 return string.replaceAll('&', '&') | |
| 77 .replaceAll('<','<') | |
| 78 .replaceAll('>','>'); | |
| 79 } | |
| OLD | NEW |