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

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

Issue 145403005: pkg/unittest: formatter spin (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: review nits Created 6 years, 10 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/lib/html_enhanced_config.dart ('k') | pkg/unittest/lib/src/core_matchers.dart » ('j') | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 28 matching lines...) Expand all
39 final int elapsed; 39 final int elapsed;
40 final String body; 40 final String body;
41 41
42 static String text(String messageType, 42 static String text(String messageType,
43 [int elapsed = 0, String body = '']) => 43 [int elapsed = 0, String body = '']) =>
44 '$_PREFIX$messageType $elapsed $body'; 44 '$_PREFIX$messageType $elapsed $body';
45 45
46 _Message(this.messageType, [this.elapsed = 0, this.body = '']); 46 _Message(this.messageType, [this.elapsed = 0, this.body = '']);
47 47
48 factory _Message.fromString(String msg) { 48 factory _Message.fromString(String msg) {
49 if(!msg.startsWith(_PREFIX)) { 49 if (!msg.startsWith(_PREFIX)) {
50 return null; 50 return null;
51 } 51 }
52 int idx = msg.indexOf(' ', _PREFIX.length); 52 int idx = msg.indexOf(' ', _PREFIX.length);
53 var messageType = msg.substring(_PREFIX.length, idx); 53 var messageType = msg.substring(_PREFIX.length, idx);
54 ++idx; 54 ++idx;
55 int idx2 = msg.indexOf(' ', idx); 55 int idx2 = msg.indexOf(' ', idx);
56 var elapsed = int.parse(msg.substring(idx, idx2)); 56 var elapsed = int.parse(msg.substring(idx, idx2));
57 ++idx2; 57 ++idx2;
58 var body = msg.substring(idx2); 58 var body = msg.substring(idx2);
59 59
(...skipping 28 matching lines...) Expand all
88 * an IFrame and post the results back to the parent. In principle 88 * an IFrame and post the results back to the parent. In principle
89 * this can run more than one test in the IFrame but currently only 89 * this can run more than one test in the IFrame but currently only
90 * one is used. 90 * one is used.
91 */ 91 */
92 class ChildInteractiveHtmlConfiguration extends HtmlConfiguration { 92 class ChildInteractiveHtmlConfiguration extends HtmlConfiguration {
93 93
94 /** The window to which results must be posted. */ 94 /** The window to which results must be posted. */
95 WindowBase _parentWindow; 95 WindowBase _parentWindow;
96 96
97 /** The time at which tests start. */ 97 /** The time at which tests start. */
98 final Map<int,DateTime> _testStarts; 98 final Map<int, DateTime> _testStarts;
99 99
100 ChildInteractiveHtmlConfiguration() : 100 ChildInteractiveHtmlConfiguration() :
101 _testStarts = new Map<int,DateTime>(); 101 _testStarts = new Map<int,DateTime>();
102 102
103 /** Don't start running tests automatically. */ 103 /** Don't start running tests automatically. */
104 get autoStart => false; 104 get autoStart => false;
105 105
106 void onInit() { 106 void onInit() {
107 _installErrorHandler(); 107 _installErrorHandler();
108 108
109 /** 109 /**
110 * The parent posts a 'start' message to kick things off, 110 * The parent posts a 'start' message to kick things off,
111 * which is handled by this handler. It saves the parent 111 * which is handled by this handler. It saves the parent
112 * window, gets the test ID from the query parameter in the 112 * window, gets the test ID from the query parameter in the
113 * IFrame URL, sets that as a solo test and starts test execution. 113 * IFrame URL, sets that as a solo test and starts test execution.
114 */ 114 */
115 window.onMessage.listen((MessageEvent e) { 115 window.onMessage.listen((MessageEvent e) {
116 // Get the result, do any logging, then do a pass/fail. 116 // Get the result, do any logging, then do a pass/fail.
117 var m = new _Message.fromString(e.data); 117 var m = new _Message.fromString(e.data);
118 if (m != null && m.messageType == _Message.START) { 118 if (m != null && m.messageType == _Message.START) {
119 _parentWindow = e.source; 119 _parentWindow = e.source;
120 String search = window.location.search; 120 String search = window.location.search;
121 int pos = search.indexOf('t='); 121 int pos = search.indexOf('t=');
122 String ids = search.substring(pos+2); 122 String ids = search.substring(pos + 2);
123 int id = int.parse(ids); 123 int id = int.parse(ids);
124 setSoloTest(id); 124 setSoloTest(id);
125 runTests(); 125 runTests();
126 } 126 }
127 }); 127 });
128 } 128 }
129 129
130 void onStart() { 130 void onStart() {
131 _installErrorHandler(); 131 _installErrorHandler();
132 } 132 }
133 133
134 /** Record the start time of the test. */ 134 /** Record the start time of the test. */
135 void onTestStart(TestCase testCase) { 135 void onTestStart(TestCase testCase) {
136 super.onTestStart(testCase); 136 super.onTestStart(testCase);
137 _testStarts[testCase.id]= new DateTime.now(); 137 _testStarts[testCase.id] = new DateTime.now();
138 } 138 }
139 139
140 /** 140 /**
141 * Tests can call [logMessage] for diagnostic output. These log 141 * Tests can call [logMessage] for diagnostic output. These log
142 * messages in turn get passed to this method, which adds 142 * messages in turn get passed to this method, which adds
143 * a timestamp and posts them back to the parent window. 143 * a timestamp and posts them back to the parent window.
144 */ 144 */
145 void onLogMessage(TestCase testCase, String message) { 145 void onLogMessage(TestCase testCase, String message) {
146 int elapsed; 146 int elapsed;
147 if (testCase == null) { 147 if (testCase == null) {
(...skipping 10 matching lines...) Expand all
158 * Get the elapsed time for the test, and post the test result back to the 158 * Get the elapsed time for the test, and post the test result back to the
159 * parent window. If the test failed due to an exception the stack is posted 159 * parent window. If the test failed due to an exception the stack is posted
160 * back too (before the test result). 160 * back too (before the test result).
161 */ 161 */
162 void onTestResult(TestCase testCase) { 162 void onTestResult(TestCase testCase) {
163 super.onTestResult(testCase); 163 super.onTestResult(testCase);
164 DateTime end = new DateTime.now(); 164 DateTime end = new DateTime.now();
165 int elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; 165 int elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds;
166 if (testCase.stackTrace != null) { 166 if (testCase.stackTrace != null) {
167 var message = JSON.encode(testCase.stackTrace.frames.map((frame) { 167 var message = JSON.encode(testCase.stackTrace.frames.map((frame) {
168 return <String, dynamic>{ 168 return <String, dynamic> {
169 "uri": frame.uri.toString(), 169 "uri": frame.uri.toString(),
170 "line": frame.line, 170 "line": frame.line,
171 "column": frame.column, 171 "column": frame.column,
172 "member": frame.member 172 "member": frame.member
173 }; 173 };
174 }).toList()); 174 }).toList());
175 _parentWindow.postMessage( 175 _parentWindow.postMessage(
176 _Message.text(_Message.STACK, elapsed, message), '*'); 176 _Message.text(_Message.STACK, elapsed, message), '*');
177 } 177 }
178 _parentWindow.postMessage( 178 _parentWindow.postMessage(
179 _Message.text(testCase.result, elapsed, testCase.message), '*'); 179 _Message.text(testCase.result, elapsed, testCase.message), '*');
180 } 180 }
181 void onSummary(int passed, int failed, int errors, List<TestCase> results, 181 void onSummary(int passed, int failed, int errors, List<TestCase> results,
182 String uncaughtError) { 182 String uncaughtError) {
183 } 183 }
184 184
185 void onDone(bool success) { 185 void onDone(bool success) {
186 _uninstallErrorHandler(); 186 _uninstallErrorHandler();
187 } 187 }
188 } 188 }
189 189
190 /** 190 /**
191 * The parent configuration runs in the top-level window; it wraps the tests 191 * The parent configuration runs in the top-level window; it wraps the tests
192 * in new functions that create child IFrames and run the real tests. 192 * in new functions that create child IFrames and run the real tests.
193 */ 193 */
194 class ParentInteractiveHtmlConfiguration extends HtmlConfiguration { 194 class ParentInteractiveHtmlConfiguration extends HtmlConfiguration {
195 final Map<int,DateTime> _testStarts; 195 final Map<int, DateTime> _testStarts;
196 196
197 197
198 /** The stack that was posted back from the child, if any. */ 198 /** The stack that was posted back from the child, if any. */
199 Trace _stack; 199 Trace _stack;
200 200
201 int _testTime; 201 int _testTime;
202 /** 202 /**
203 * Whether or not we have already wrapped the TestCase test functions 203 * Whether or not we have already wrapped the TestCase test functions
204 * in new closures that instead create an IFrame and get it to run the 204 * in new closures that instead create an IFrame and get it to run the
205 * test. 205 * test.
(...skipping 25 matching lines...) Expand all
231 child.onLoad.listen((e) { 231 child.onLoad.listen((e) {
232 child.contentWindow.postMessage(_Message.text(_Message.START), '*'); 232 child.contentWindow.postMessage(_Message.text(_Message.START), '*');
233 }); 233 });
234 }; 234 };
235 } 235 }
236 236
237 void _handleMessage(MessageEvent e) { 237 void _handleMessage(MessageEvent e) {
238 // Get the result, do any logging, then do a pass/fail. 238 // Get the result, do any logging, then do a pass/fail.
239 var msg = new _Message.fromString(e.data); 239 var msg = new _Message.fromString(e.data);
240 240
241 if(msg == null) { 241 if (msg == null) {
242 return; 242 return;
243 } 243 }
244 if (msg.messageType == _Message.LOG) { 244 if (msg.messageType == _Message.LOG) {
245 logMessage(e.data); 245 logMessage(e.data);
246 } else if (msg.messageType == _Message.STACK) { 246 } else if (msg.messageType == _Message.STACK) {
247 _stack = new Trace(JSON.decode(msg.body).map((frame) { 247 _stack = new Trace(JSON.decode(msg.body).map((frame) {
248 return new Frame( 248 return new Frame(
249 Uri.parse(frame['uri']), 249 Uri.parse(frame['uri']),
250 frame['line'], 250 frame['line'],
251 frame['column'], 251 frame['column'],
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 295
296 // Used for DOM element IDs for tests result list entries. 296 // Used for DOM element IDs for tests result list entries.
297 static const _testIdPrefix = 'test-'; 297 static const _testIdPrefix = 'test-';
298 // Used for DOM element IDs for test log message lists. 298 // Used for DOM element IDs for test log message lists.
299 static const _actionIdPrefix = 'act-'; 299 static const _actionIdPrefix = 'act-';
300 // Used for DOM element IDs for test checkboxes. 300 // Used for DOM element IDs for test checkboxes.
301 static const _selectedIdPrefix = 'selected-'; 301 static const _selectedIdPrefix = 'selected-';
302 302
303 void onTestStart(TestCase testCase) { 303 void onTestStart(TestCase testCase) {
304 var id = testCase.id; 304 var id = testCase.id;
305 _testStarts[testCase.id]= new DateTime.now(); 305 _testStarts[testCase.id] = new DateTime.now();
306 super.onTestStart(testCase); 306 super.onTestStart(testCase);
307 _stack = null; 307 _stack = null;
308 // Convert the group name to a DOM id. 308 // Convert the group name to a DOM id.
309 String groupId = _stringToDomId(testCase.currentGroup); 309 String groupId = _stringToDomId(testCase.currentGroup);
310 // Get the div for the group. If it doesn't exist, 310 // Get the div for the group. If it doesn't exist,
311 // create it. 311 // create it.
312 var groupDiv = document.query('#$groupId'); 312 var groupDiv = document.query('#$groupId');
313 if (groupDiv == null) { 313 if (groupDiv == null) {
314 groupDiv = new Element.html(""" 314 groupDiv = new Element.html("""
315 <div class='test-describe' id='$groupId'> 315 <div class='test-describe' id='$groupId'>
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 ul, menu, dir { 700 ul, menu, dir {
701 display: block; 701 display: block;
702 list-style-type: disc; 702 list-style-type: disc;
703 -webkit-margin-before: 1em; 703 -webkit-margin-before: 1em;
704 -webkit-margin-after: 1em; 704 -webkit-margin-after: 1em;
705 -webkit-margin-start: 0px; 705 -webkit-margin-start: 0px;
706 -webkit-margin-end: 0px; 706 -webkit-margin-end: 0px;
707 -webkit-padding-start: 40px; 707 -webkit-padding-start: 40px;
708 } 708 }
709 """; 709 """;
OLDNEW
« no previous file with comments | « pkg/unittest/lib/html_enhanced_config.dart ('k') | pkg/unittest/lib/src/core_matchers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698