Chromium Code Reviews| Index: lib/unittest/unittest_dom.dart |
| diff --git a/lib/unittest/unittest_dom.dart b/lib/unittest/unittest_dom.dart |
| index f69c9c96ece0afb9609a50c1d5e2a8943870a259..6e5e00bd59bfa8e3d07f57e6b6b0214da6a047e7 100644 |
| --- a/lib/unittest/unittest_dom.dart |
| +++ b/lib/unittest/unittest_dom.dart |
| @@ -5,11 +5,21 @@ |
| /** |
| * A simple unit test library for running tests in a browser. |
| */ |
| -#library("unittest"); |
| +#library('unittest'); |
| -#import("dart:dom"); |
| +#import('dart:dom'); |
| +#import('dart:isolate'); |
| -#source("shared.dart"); |
| +#source('config.dart'); |
| +#source('shared.dart'); |
| +#source('html_print.dart'); |
| + |
| +/** Whether this is run within dartium layout tests. */ |
| +bool _isLayoutTest = false; |
| + |
| +void forLayoutTests() { |
| + _isLayoutTest = true; |
| +} |
| // TODO(rnystrom): Get rid of this if we get canonical closures for methods. |
| EventListener _onErrorClosure; |
| @@ -18,10 +28,6 @@ _platformInitialize() { |
| _onErrorClosure = (e) { _onError(e); }; |
| } |
| -_platformDefer(void callback()) { |
| - window.setTimeout(callback, 0); |
| -} |
| - |
| void _onError(e) { |
| if (_currentTest < _tests.length) { |
| final testCase = _tests[_currentTest]; |
| @@ -44,70 +50,18 @@ _platformStartTests() { |
| window.addEventListener('error', _onErrorClosure, true); |
| } |
| -_platformCompleteTests(int testsPassed, int testsFailed, int testsErrors) { |
| +_platformCompleteTests(int testsPassed, int testsFailed, int testsErrors, |
| + List<TestCase> results) { |
| window.removeEventListener('error', _onErrorClosure); |
| - |
| - 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(); |
| - } |
| - |
| + _showResultsInPage( |
| + testsPassed, testsFailed, testsErrors, results, _isLayoutTest); |
| 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}. ${_htmlEscape(test_.message)}</td> |
| - </tr>'''; |
| - |
| - if (test_.stackTrace != null) { |
| - html += |
| - '<tr><td></td><td colspan="2"><pre>${_htmlEscape(test_.stackTrace)}</pre></td></tr>'; |
| - } |
| - |
| - return html; |
| +Configuration _defaultConfig() { |
| + return new Configuration( |
| + _platformInitialize, |
|
Bob Nystrom
2012/04/10 00:30:31
Instead of closures here, I would just subclass Co
Siggi Cherem (dart-lang)
2012/04/10 01:05:28
Done.
|
| + _platformStartTests, |
| + (testCase) {}, |
| + _platformCompleteTests); |
| } |
| - |
| -//TODO(pquitslund): Move to a common lib |
| -String _htmlEscape(String string) { |
| - return string.replaceAll('&', '&') |
| - .replaceAll('<','<') |
| - .replaceAll('>','>'); |
| -} |