| Index: lib/unittest/unittest_html.dart
|
| diff --git a/lib/unittest/unittest_html.dart b/lib/unittest/unittest_html.dart
|
| index a307c4a2a54cab01b0087b51497e1a39cb9ab104..b484c10400d4dd4c0ac70800f70409efebb7a2b5 100644
|
| --- a/lib/unittest/unittest_html.dart
|
| +++ b/lib/unittest/unittest_html.dart
|
| @@ -5,11 +5,21 @@
|
| /**
|
| * A simple unit test library for running tests in a browser.
|
| */
|
| -#library("unittest");
|
| +#library('unittest');
|
|
|
| -#import("dart:html");
|
| +#import('dart:html');
|
| +#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];
|
| @@ -46,68 +52,31 @@ _platformStartTests() {
|
|
|
| _platformCompleteTests(int testsPassed, int testsFailed, int testsErrors) {
|
| window.on.error.remove(_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, _tests, _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>''';
|
| +Configuration _defaultConfig() {
|
| + return new Configuration(
|
| + _platformInitialize,
|
| + _platformStartTests,
|
| + (testCase) {},
|
| + _platformCompleteTests);
|
| +}
|
|
|
| - if (test_.stackTrace != null) {
|
| - html +=
|
| - '<tr><td></td><td colspan="2"><pre>${_htmlEscape(test_.stackTrace)}</pre></td></tr>';
|
| +void serialInvokeAsync(List closures) {
|
| + final length = closures.length;
|
| + if (length > 0) {
|
| + int i = 0;
|
| + void invokeNext() {
|
| + closures[i]();
|
| + i++;
|
| + if (i < length) {
|
| + window.setTimeout(invokeNext, 0);
|
| + }
|
| + }
|
| + window.setTimeout(invokeNext, 0);
|
| }
|
| -
|
| - return html;
|
| }
|
|
|
| -//TODO(pquitslund): Move to a common lib
|
| -String _htmlEscape(String string) {
|
| - return string.replaceAll('&', '&')
|
| - .replaceAll('<','<')
|
| - .replaceAll('>','>');
|
| -}
|
|
|