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

Side by Side Diff: pkg/unittest/html_config.dart

Issue 11301046: Restructure pkg/unittest and pkg/webdriver to follow the pub conventions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * A simple unit test library for running tests in a browser.
7 */
8 #library('unittest_html_config');
9
10 #import('dart:html');
11 #import('unittest.dart');
12
13 #source('html_print.dart');
14
15 class HtmlConfiguration extends Configuration {
16 /** Whether this is run within dartium layout tests. */
17 final bool _isLayoutTest;
18 HtmlConfiguration(this._isLayoutTest);
19
20 // TODO(rnystrom): Get rid of this if we get canonical closures for methods.
21 EventListener _onErrorClosure;
22 EventListener _onMessageClosure;
23
24 void _installHandlers() {
25 if (_onErrorClosure == null) {
26 _onErrorClosure =
27 (e) => handleExternalError(e, '(DOM callback has errors)');
28 // Listen for uncaught errors.
29 window.on.error.add(_onErrorClosure);
30 }
31 if (_onMessageClosure == null) {
32 _onMessageClosure = (e) => processMessage(e);
33 // Listen for errors from JS.
34 window.on.message.add(_onMessageClosure);
35 }
36 }
37
38 void _uninstallHandlers() {
39 if (_onErrorClosure != null) {
40 window.on.error.remove(_onErrorClosure);
41 _onErrorClosure = null;
42 }
43 if (_onMessageClosure != null) {
44 window.on.message.remove(_onMessageClosure);
45 _onMessageClosure = null;
46 }
47 }
48
49 void processMessage(e) {
50 if ('unittest-suite-external-error' == e.data) {
51 handleExternalError('<unknown>', '(external error detected)');
52 }
53 }
54
55 void onInit() {
56 _installHandlers();
57 }
58
59 void onStart() {
60 window.postMessage('unittest-suite-wait-for-done', '*');
61 }
62
63 void onTestResult(TestCase testCase) {}
64
65 void onDone(int passed, int failed, int errors, List<TestCase> results,
66 String uncaughtError) {
67 _uninstallHandlers();
68 _showResultsInPage(passed, failed, errors, results, _isLayoutTest,
69 uncaughtError);
70 window.postMessage('unittest-suite-done', '*');
71 }
72 }
73
74 void useHtmlConfiguration([bool isLayoutTest = false]) {
75 configure(new HtmlConfiguration(isLayoutTest));
76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698