| 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:dom"); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 _nextBatch(); | 34 _nextBatch(); |
| 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.onerror = _onErrorClosure; | 44 window.addEventListener('error', _onErrorClosure, true); |
| 45 } | 45 } |
| 46 | 46 |
| 47 _platformCompleteTests(int testsPassed, int testsFailed, int testsErrors) { | 47 _platformCompleteTests(int testsPassed, int testsFailed, int testsErrors) { |
| 48 window.onerror = null; | 48 window.removeEventListener('error', _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 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 <td>Expectation: ${test.description}. ${test.message}</td> | 95 <td>Expectation: ${test.description}. ${test.message}</td> |
| 96 </tr>'''; | 96 </tr>'''; |
| 97 | 97 |
| 98 if (test.stackTrace != null) { | 98 if (test.stackTrace != null) { |
| 99 html += | 99 html += |
| 100 '<tr><td></td><td colspan="2"><pre>${test.stackTrace}</pre></td></tr>'; | 100 '<tr><td></td><td colspan="2"><pre>${test.stackTrace}</pre></td></tr>'; |
| 101 } | 101 } |
| 102 | 102 |
| 103 return html; | 103 return html; |
| 104 } | 104 } |
| OLD | NEW |