Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(965)

Unified Diff: lib/unittest/unittest_html.dart

Issue 10031022: step 1 in making unittest platform independent. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/unittest/unittest_html.dart
diff --git a/lib/unittest/unittest_html.dart b/lib/unittest/unittest_html.dart
index a307c4a2a54cab01b0087b51497e1a39cb9ab104..f1f2ee191383923352e5f3f66fdaac0d35b037bd 100644
--- a/lib/unittest/unittest_html.dart
+++ b/lib/unittest/unittest_html.dart
@@ -5,109 +5,72 @@
/**
* 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');
-// TODO(rnystrom): Get rid of this if we get canonical closures for methods.
-EventListener _onErrorClosure;
+/** Whether this is run within dartium layout tests. */
+bool _isLayoutTest = false;
-_platformInitialize() {
- _onErrorClosure = (e) { _onError(e); };
+void forLayoutTests() {
+ _isLayoutTest = true;
}
-_platformDefer(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.error('(DOM callback has errors) Caught ${e}', '');
- _state = _UNCAUGHT_ERROR;
- if (testCase.callbacks > 0) {
- _currentTest++;
- _testRunner();
+void serialInvokeAsync(List closures) {
Bob Nystrom 2012/04/10 20:04:25 What is this and what is it used for? Needs docs.
Siggi Cherem (dart-lang) 2012/04/10 21:40:18 It was added by Jacob for some html tests. It was
+ 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);
}
}
-/** Runs all queued tests, one at a time. */
-_platformStartTests() {
- window.postMessage('unittest-suite-wait-for-done', '*');
-
- // Listen for uncaught errors.
- window.on.error.add(_onErrorClosure);
-}
-
-_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>");
+class PlatformConfiguration extends Configuration {
Bob Nystrom 2012/04/10 20:04:25 HtmlConfiguration
Siggi Cherem (dart-lang) 2012/04/10 21:40:18 See comment on DomConfiguration
+ // TODO(rnystrom): Get rid of this if we get canonical closures for methods.
+ EventListener _onErrorClosure;
- for (final test_ in _tests) {
- newBody.add(_toHtml(test_));
- }
+ void onInit() {
+ _onErrorClosure = (e) { _onError(e); };
+ }
- 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>""");
+ 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.error('(DOM callback has errors) Caught ${e}', '');
+ _state = _UNCAUGHT_ERROR;
+ if (testCase.callbacks > 0) {
+ _currentTest++;
+ _testRunner();
+ }
}
- 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>''';
+ void onStart() {
+ window.postMessage('unittest-suite-wait-for-done', '*');
+ // Listen for uncaught errors.
+ window.on.error.add(_onErrorClosure);
}
- 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>''';
+ void onTestResult(TestCase testCase) {}
- if (test_.stackTrace != null) {
- html +=
- '<tr><td></td><td colspan="2"><pre>${_htmlEscape(test_.stackTrace)}</pre></td></tr>';
+ onDone(int testsPassed, int testsFailed, int testsErrors,
eub 2012/04/10 18:06:02 Let's match the arg names between the parent class
Siggi Cherem (dart-lang) 2012/04/10 21:40:18 Done.
+ List<TestCase> results) {
+ window.on.error.remove(_onErrorClosure);
+ _showResultsInPage(
+ testsPassed, testsFailed, testsErrors, results, _isLayoutTest);
+ window.postMessage('unittest-suite-done', '*');
}
-
- return html;
}
-
-//TODO(pquitslund): Move to a common lib
-String _htmlEscape(String string) {
- return string.replaceAll('&', '&amp;')
- .replaceAll('<','&lt;')
- .replaceAll('>','&gt;');
-}

Powered by Google App Engine
This is Rietveld 408576698