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

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

Issue 10959025: Move the addition of an onError handler to earlier (onInit instead of onStart), while still support… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/unittest/html_enhanced_config.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * This configuration can be used to rerun selected tests, as well 6 * This configuration can be used to rerun selected tests, as well
7 * as see diagnostic output from tests. It runs each test in its own 7 * as see diagnostic output from tests. It runs each test in its own
8 * IFrame, so the configuration consists of two parts - a 'parent' 8 * IFrame, so the configuration consists of two parts - a 'parent'
9 * config that manages all the tests, and a 'child' config for the 9 * config that manages all the tests, and a 'child' config for the
10 * IFrame that runs the individual tests. 10 * IFrame that runs the individual tests.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 ++idx; 44 ++idx;
45 int idx2 = msg.indexOf(' ', idx); 45 int idx2 = msg.indexOf(' ', idx);
46 elapsed = int.parse(msg.substring(idx, idx2)); 46 elapsed = int.parse(msg.substring(idx, idx2));
47 ++idx2; 47 ++idx2;
48 body = msg.substring(idx2); 48 body = msg.substring(idx2);
49 } 49 }
50 50
51 String toString() => text(messageType, elapsed, body); 51 String toString() => text(messageType, elapsed, body);
52 } 52 }
53 53
54
55 class HtmlConfiguration extends Configuration {
56 // TODO(rnystrom): Get rid of this if we get canonical closures for methods.
57 EventListener _onErrorClosure;
58
59 void _installErrorHandler() {
60 if (_onErrorClosure == null) {
61 _onErrorClosure =
62 (e) => handleExternalError(e, '(DOM callback has errors)');
63 // Listen for uncaught errors.
64 window.on.error.add(_onErrorClosure);
65 }
66 }
67
68 void _uninstallErrorHandler() {
69 if (_onErrorClosure != null) {
70 window.on.error.remove(_onErrorClosure);
71 _onErrorClosure = null;
72 }
73 }
74 }
75
54 /** 76 /**
55 * The child configuration that is used to run individual tests in 77 * The child configuration that is used to run individual tests in
56 * an IFrame and post the results back to the parent. In principle 78 * an IFrame and post the results back to the parent. In principle
57 * this can run more than one test in the IFrame but currently only 79 * this can run more than one test in the IFrame but currently only
58 * one is used. 80 * one is used.
59 */ 81 */
60 class ChildInteractiveHtmlConfiguration extends Configuration { 82 class ChildInteractiveHtmlConfiguration extends HtmlConfiguration {
61 // TODO(rnystrom): Get rid of this if we get canonical closures for methods.
62 EventListener _onErrorClosure;
63 83
64 /** The window to which results must be posted. */ 84 /** The window to which results must be posted. */
65 Window parentWindow; 85 Window parentWindow;
66 86
67 /** The time at which tests start. */ 87 /** The time at which tests start. */
68 Map<int,Date> _testStarts; 88 Map<int,Date> _testStarts;
69 89
70 ChildInteractiveHtmlConfiguration() : 90 ChildInteractiveHtmlConfiguration() :
71 _testStarts = new Map<int,Date>(); 91 _testStarts = new Map<int,Date>();
72 92
73 /** Don't start running tests automatically. */ 93 /** Don't start running tests automatically. */
74 get autoStart => false; 94 get autoStart => false;
75 95
76 void onInit() { 96 void onInit() {
77 _onErrorClosure = 97 _installErrorHandler();
78 (e) => handleExternalError(e, '(DOM callback has errors)');
79 98
80 /** 99 /**
81 * The parent posts a 'start' message to kick things off, 100 * The parent posts a 'start' message to kick things off,
82 * which is handled by this handler. It saves the parent 101 * which is handled by this handler. It saves the parent
83 * window, gets the test ID from the query parameter in the 102 * window, gets the test ID from the query parameter in the
84 * IFrame URL, sets that as a solo test and starts test execution. 103 * IFrame URL, sets that as a solo test and starts test execution.
85 */ 104 */
86 window.on.message.add((MessageEvent e) { 105 window.on.message.add((MessageEvent e) {
87 // Get the result, do any logging, then do a pass/fail. 106 // Get the result, do any logging, then do a pass/fail.
88 var m = new _Message.fromString(e.data); 107 var m = new _Message.fromString(e.data);
89 if (m.messageType == _Message.START) { 108 if (m.messageType == _Message.START) {
90 parentWindow = e.source; 109 parentWindow = e.source;
91 String search = window.location.search; 110 String search = window.location.search;
92 int pos = search.indexOf('t='); 111 int pos = search.indexOf('t=');
93 String ids = search.substring(pos+2); 112 String ids = search.substring(pos+2);
94 int id = int.parse(ids); 113 int id = int.parse(ids);
95 setSoloTest(id); 114 setSoloTest(id);
96 runTests(); 115 runTests();
97 } 116 }
98 }); 117 });
99 } 118 }
100 119
101 void onStart() { 120 void onStart() {
102 // Listen for uncaught errors. 121 _installErrorHandler();
103 window.on.error.add(_onErrorClosure);
104 } 122 }
105 123
106 /** Record the start time of the test. */ 124 /** Record the start time of the test. */
107 void onTestStart(TestCase testCase) { 125 void onTestStart(TestCase testCase) {
108 super.onTestStart(testCase); 126 super.onTestStart(testCase);
109 _testStarts[testCase.id]= new Date.now(); 127 _testStarts[testCase.id]= new Date.now();
110 } 128 }
111 129
112 /** 130 /**
113 * Tests can call [logMessage] for diagnostic output. These log 131 * Tests can call [logMessage] for diagnostic output. These log
(...skipping 24 matching lines...) Expand all
138 if (testCase.stackTrace != null) { 156 if (testCase.stackTrace != null) {
139 parentWindow.postMessage( 157 parentWindow.postMessage(
140 _Message.text(_Message.STACK, elapsed, testCase.stackTrace), '*'); 158 _Message.text(_Message.STACK, elapsed, testCase.stackTrace), '*');
141 } 159 }
142 parentWindow.postMessage( 160 parentWindow.postMessage(
143 _Message.text(testCase.result, elapsed, testCase.message), '*'); 161 _Message.text(testCase.result, elapsed, testCase.message), '*');
144 } 162 }
145 163
146 void onDone(int passed, int failed, int errors, List<TestCase> results, 164 void onDone(int passed, int failed, int errors, List<TestCase> results,
147 String uncaughtError) { 165 String uncaughtError) {
148 window.on.error.remove(_onErrorClosure); 166 _uninstallErrorHandler();
149 } 167 }
150 } 168 }
151 169
152 /** 170 /**
153 * The parent configuration runs in the top-level window; it wraps the tests 171 * The parent configuration runs in the top-level window; it wraps the tests
154 * in new functions that create child IFrames and run the real tests. 172 * in new functions that create child IFrames and run the real tests.
155 */ 173 */
156 class ParentInteractiveHtmlConfiguration extends Configuration { 174 class ParentInteractiveHtmlConfiguration extends HtmlConfiguration {
157 Map<int,Date> _testStarts; 175 Map<int,Date> _testStarts;
158 // TODO(rnystrom): Get rid of this if we get canonical closures for methods. 176
159 EventListener _onErrorClosure;
160 177
161 /** The stack that was posted back from the child, if any. */ 178 /** The stack that was posted back from the child, if any. */
162 String _stack; 179 String _stack;
163 180
164 int _testTime; 181 int _testTime;
165 /** 182 /**
166 * Whether or not we have already wrapped the TestCase test functions 183 * Whether or not we have already wrapped the TestCase test functions
167 * in new closures that instead create an IFrame and get it to run the 184 * in new closures that instead create an IFrame and get it to run the
168 * test. 185 * test.
169 */ 186 */
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 } else if (msg.messageType == _Message.FAIL) { 233 } else if (msg.messageType == _Message.FAIL) {
217 currentTestCase.fail(msg.body, _stack); 234 currentTestCase.fail(msg.body, _stack);
218 } else if (msg.messageType == _Message.ERROR) { 235 } else if (msg.messageType == _Message.ERROR) {
219 currentTestCase.error(msg.body, _stack); 236 currentTestCase.error(msg.body, _stack);
220 } 237 }
221 completeTest(); 238 completeTest();
222 } 239 }
223 } 240 }
224 241
225 void onInit() { 242 void onInit() {
243 _installErrorHandler();
226 _messageHandler = _handleMessage; // We need to make just one closure. 244 _messageHandler = _handleMessage; // We need to make just one closure.
227 _onErrorClosure =
228 (e) => handleExternalError(e, '(DOM callback has errors)');
229 document.query('#group-divs').innerHTML = ""; 245 document.query('#group-divs').innerHTML = "";
230 } 246 }
231 247
232 void onStart() { 248 void onStart() {
233 // Listen for uncaught errors. 249 _installErrorHandler();
234 window.on.error.add(_onErrorClosure);
235 if (!_doneWrap) { 250 if (!_doneWrap) {
236 _doneWrap = true; 251 _doneWrap = true;
237 for (int i = 0; i < testCases.length; i++) { 252 for (int i = 0; i < testCases.length; i++) {
238 testCases[i].test = wrapTest(testCases[i]); 253 testCases[i].test = wrapTest(testCases[i]);
239 testCases[i].setUp = null; 254 testCases[i].setUp = null;
240 testCases[i].tearDown = null; 255 testCases[i].tearDown = null;
241 } 256 }
242 } 257 }
243 window.on.message.add(_messageHandler); 258 window.on.message.add(_messageHandler);
244 } 259 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 var actions = testItem.query('.test-actions'); 403 var actions = testItem.query('.test-actions');
389 for (Element e in actions.nodes) { 404 for (Element e in actions.nodes) {
390 e.classes.add(result); 405 e.classes.add(result);
391 } 406 }
392 actions.style.display = 'none'; 407 actions.style.display = 'none';
393 } 408 }
394 409
395 void onDone(int passed, int failed, int errors, List<TestCase> results, 410 void onDone(int passed, int failed, int errors, List<TestCase> results,
396 String uncaughtError) { 411 String uncaughtError) {
397 window.on.message.remove(_messageHandler); 412 window.on.message.remove(_messageHandler);
398 window.on.error.remove(_onErrorClosure); 413 _uninstallErrorHandler();
399 document.query('#busy').style.display = 'none'; 414 document.query('#busy').style.display = 'none';
400 InputElement startButton = document.query('#start'); 415 InputElement startButton = document.query('#start');
401 startButton.disabled = false; 416 startButton.disabled = false;
402 } 417 }
403 } 418 }
404 419
405 /** 420 /**
406 * Add the divs to the DOM if they are not present. We have a 'controls' 421 * Add the divs to the DOM if they are not present. We have a 'controls'
407 * div for control, 'specs' div with test results, a 'busy' div for the 422 * div for control, 'specs' div with test results, a 'busy' div for the
408 * animated GIF used to indicate tests are running, and a 'child' div to 423 * animated GIF used to indicate tests are running, and a 'child' div to
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 display: block; 664 display: block;
650 list-style-type: disc; 665 list-style-type: disc;
651 -webkit-margin-before: 1em; 666 -webkit-margin-before: 1em;
652 -webkit-margin-after: 1em; 667 -webkit-margin-after: 1em;
653 -webkit-margin-start: 0px; 668 -webkit-margin-start: 0px;
654 -webkit-margin-end: 0px; 669 -webkit-margin-end: 0px;
655 -webkit-padding-start: 40px; 670 -webkit-padding-start: 40px;
656 } 671 }
657 672
658 """; 673 """;
OLDNEW
« no previous file with comments | « pkg/unittest/html_enhanced_config.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698