| 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"); | 8 #library("unittest"); |
| 9 | 9 |
| 10 #import("dart:dom"); | 10 #import("dart:html"); |
| 11 | 11 |
| 12 #source("shared.dart"); | 12 #source("shared.dart"); |
| 13 | 13 |
| 14 // TODO(rnystrom): Get rid of this if we get canonical closures for methods. | 14 // TODO(rnystrom): Get rid of this if we get canonical closures for methods. |
| 15 EventListener _onErrorClosure; | 15 EventListener _onErrorClosure; |
| 16 | 16 |
| 17 _platformInitialize() { | 17 _platformInitialize() { |
| 18 _onErrorClosure = (e) { _onError(e); }; | 18 _onErrorClosure = (e) { _onError(e); }; |
| 19 } | 19 } |
| 20 | 20 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 _testRunner(); | 34 _testRunner(); |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 /** Runs all queued tests, one at a time. */ | 39 /** Runs all queued tests, one at a time. */ |
| 40 _platformStartTests() { | 40 _platformStartTests() { |
| 41 window.postMessage('unittest-suite-wait-for-done', '*'); | 41 window.postMessage('unittest-suite-wait-for-done', '*'); |
| 42 | 42 |
| 43 // Listen for uncaught errors. | 43 // Listen for uncaught errors. |
| 44 window.addEventListener('error', _onErrorClosure, true); | 44 window.on.error.add(_onErrorClosure); |
| 45 } | 45 } |
| 46 | 46 |
| 47 _platformCompleteTests(int testsPassed, int testsFailed, int testsErrors) { | 47 _platformCompleteTests(int testsPassed, int testsFailed, int testsErrors) { |
| 48 window.removeEventListener('error', _onErrorClosure); | 48 window.on.error.remove(_onErrorClosure); |
| 49 | 49 |
| 50 if (_isLayoutTest && testsPassed == _tests.length) { | 50 if (_isLayoutTest && testsPassed == _tests.length) { |
| 51 document.body.innerHTML = "PASS"; | 51 document.body.innerHTML = "PASS"; |
| 52 } else { | 52 } else { |
| 53 var newBody = new StringBuffer(); | 53 var newBody = new StringBuffer(); |
| 54 newBody.add("<table class='unittest-table'><tbody>"); | 54 newBody.add("<table class='unittest-table'><tbody>"); |
| 55 newBody.add(testsPassed == _tests.length | 55 newBody.add(testsPassed == _tests.length |
| 56 ? "<tr><td colspan='3' class='unittest-pass'>PASS</td></tr>" | 56 ? "<tr><td colspan='3' class='unittest-pass'>PASS</td></tr>" |
| 57 : "<tr><td colspan='3' class='unittest-fail'>FAIL</td></tr>"); | 57 : "<tr><td colspan='3' class='unittest-fail'>FAIL</td></tr>"); |
| 58 | 58 |
| 59 for (final test_ in _tests) { | 59 for (final test_ in _tests) { |
| 60 newBody.add(_toHtml(test_)); | 60 newBody.add(_toHtml(test_)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 if (testsPassed == _tests.length) { | 63 if (testsPassed == _tests.length) { |
| 64 newBody.add("<tr><td colspan='3' class='unittest-pass'>All " | 64 newBody.add(""" |
| 65 + testsPassed + " tests passed</td></tr>"); | 65 <tr><td colspan='3' class='unittest-pass'> |
| 66 All ${testsPassed} tests passed |
| 67 </td></tr>"""); |
| 66 } else { | 68 } else { |
| 67 newBody.add(""" | 69 newBody.add(""" |
| 68 <tr><td colspan='3'>Total | 70 <tr><td colspan='3'>Total |
| 69 <span class='unittest-pass'>${testsPassed} passed</span>, | 71 <span class='unittest-pass'>${testsPassed} passed</span>, |
| 70 <span class='unittest-fail'>${testsFailed} failed</span> | 72 <span class='unittest-fail'>${testsFailed} failed</span> |
| 71 <span class='unittest-error'>${testsErrors} errors</span> | 73 <span class='unittest-error'>${testsErrors} errors</span> |
| 72 </td></tr>"""); | 74 </td></tr>"""); |
| 73 } | 75 } |
| 74 newBody.add("</tbody></table>"); | 76 newBody.add("</tbody></table>"); |
| 75 document.body.innerHTML = newBody.toString(); | 77 document.body.innerHTML = newBody.toString(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 102 | 104 |
| 103 return html; | 105 return html; |
| 104 } | 106 } |
| 105 | 107 |
| 106 //TODO(pquitslund): Move to a common lib | 108 //TODO(pquitslund): Move to a common lib |
| 107 String _htmlEscape(String string) { | 109 String _htmlEscape(String string) { |
| 108 return string.replaceAll('&', '&') | 110 return string.replaceAll('&', '&') |
| 109 .replaceAll('<','<') | 111 .replaceAll('<','<') |
| 110 .replaceAll('>','>'); | 112 .replaceAll('>','>'); |
| 111 } | 113 } |
| OLD | NEW |