Chromium Code Reviews| Index: client/testing/unittest/unittest.dart |
| diff --git a/client/testing/unittest/unittest.dart b/client/testing/unittest/unittest.dart |
| index 045bbccfcd62b81d8c4db21effad8f3713559fbd..48ccc3a11fe4363e8e29e6f378b89c77e2133bcf 100644 |
| --- a/client/testing/unittest/unittest.dart |
| +++ b/client/testing/unittest/unittest.dart |
| @@ -9,4 +9,96 @@ |
| #import("dart:dom"); |
| -#source("unittestsuite.dart"); |
| +#source("shared.dart"); |
| + |
| +// TODO(rnystrom): Get rid of this if we get canonical closures for methods. |
| +EventListener _onErrorClosure; |
| + |
| +_initializePlatform() { |
|
Siggi Cherem (dart-lang)
2011/10/28 23:35:13
suggestion - what if we create an abstraction for
Bob Nystrom
2011/10/28 23:57:48
When would that field get initialized? Would the P
Siggi Cherem (dart-lang)
2011/10/29 00:13:19
Another idea ---
if you'd like to avoid adding cl
Siggi Cherem (dart-lang)
2011/10/29 00:13:19
Basically yes, it would be a const class - here is
|
| + _onErrorClosure = (e) { _onError(e); }; |
| +} |
| + |
| +_doLaterPlatform(void callback()) { |
| + window.setTimeout(callback, 0); |
| +} |
| + |
| +void _onError(e) { |
| + if (_currentTest < _tests.length) { |
| + final testCase = _tests[_currentTest]; |
| + // TODO(vsm): figure out how to expose the stack trace here |
| + // Currently e.message works in dartium, but not in dartc. |
| + testCase.recordError('(DOM callback has errors) Caught ${e}', ''); |
| + _state = _UNCAUGHT_ERROR; |
| + if (testCase.callbacks > 0) { |
| + _currentTest++; |
| + _nextBatch(); |
| + } |
| + } |
| +} |
| + |
| +/** Runs all queued tests, one at a time. */ |
| +_runTestsPlatform() { |
| + window.postMessage('unittest-suite-start', '*'); |
| + |
| + // Listen for uncaught errors. |
| + window.onerror = _onErrorClosure; |
| +} |
| + |
| +_completeTestsPlatform(int testsPassed, int testsFailed, int testsErrors) { |
| + window.onerror = null; |
| + |
| + if (_isLayoutTest && testsPassed == _tests.length) { |
| + document.body.innerHTML = "PASS"; |
| + } else { |
| + var newBody = new StringBuffer(); |
| + newBody.add("<table class='unittest-table'><tbody>"); |
| + newBody.add(testsPassed == _tests.length |
| + ? "<tr><td colspan='3' class='unittest-pass'>PASS</td></tr>" |
| + : "<tr><td colspan='3' class='unittest-fail'>FAIL</td></tr>"); |
| + |
| + for (final test in _tests) { |
| + newBody.add(_toHtml(test)); |
| + } |
| + |
| + if (testsPassed == _tests.length) { |
| + newBody.add("<tr><td colspan='3' class='unittest-pass'>All " |
| + + testsPassed + " tests passed</td></tr>"); |
| + } else { |
| + newBody.add(""" |
| + <tr><td colspan='3'>Total |
| + <span class='unittest-pass'>${testsPassed} passed</span>, |
| + <span class='unittest-fail'>${testsFailed} failed</span> |
| + <span class='unittest-error'>${testsErrors} errors</span> |
| + </td></tr>"""); |
| + } |
| + newBody.add("</tbody></table>"); |
| + document.body.innerHTML = newBody.toString(); |
| + } |
| + |
| + window.postMessage('unittest-suite-done', '*'); |
| +} |
| + |
| +String _toHtml(TestCase test) { |
| + if (!test.isComplete) { |
| + return ''' |
| + <tr> |
| + <td>${test.id}</td> |
| + <td class="unittest-error">NO STATUS</td> |
| + <td>Test did not complete</td> |
| + </tr>'''; |
| + } |
| + |
| + var html = ''' |
| + <tr> |
| + <td>${test.id}</td> |
| + <td class="unittest-${test.result}">${test.result.toUpperCase()}</td> |
| + <td>Expectation: ${test.description}. ${test.message}</td> |
| + </tr>'''; |
| + |
| + if (test.stackTrace != null) { |
| + html += |
| + '<tr><td></td><td colspan="2"><pre>${test.stackTrace}</pre></td></tr>'; |
| + } |
| + |
| + return html; |
| +} |