| OLD | NEW |
| 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. |
| 11 * | 11 * |
| 12 * Note: this unit test configuration will not work with the debugger (the tests | 12 * Note: this unit test configuration will not work with the debugger (the tests |
| 13 * are executed in a separate IFrame). | 13 * are executed in a separate IFrame). |
| 14 */ | 14 */ |
| 15 library unittest_interactive_html_config; | 15 library unittest_interactive_html_config; |
| 16 | 16 |
| 17 // TODO(gram) - add options for: remove IFrame on done/keep | 17 // TODO(gram) - add options for: remove IFrame on done/keep |
| 18 // IFrame for failed tests/keep IFrame for all tests. | 18 // IFrame for failed tests/keep IFrame for all tests. |
| 19 | 19 |
| 20 import 'dart:html'; | 20 import 'dart:html'; |
| 21 import 'dart:async'; | 21 import 'dart:async'; |
| 22 import 'dart:json' as json; | 22 import 'dart:convert'; |
| 23 | 23 |
| 24 import 'package:stack_trace/stack_trace.dart'; | 24 import 'package:stack_trace/stack_trace.dart'; |
| 25 | 25 |
| 26 import 'unittest.dart'; | 26 import 'unittest.dart'; |
| 27 | 27 |
| 28 /** The messages exchanged between parent and child. */ | 28 /** The messages exchanged between parent and child. */ |
| 29 class _Message { | 29 class _Message { |
| 30 static const START = 'start'; | 30 static const START = 'start'; |
| 31 static const LOG = 'log'; | 31 static const LOG = 'log'; |
| 32 static const STACK = 'stack'; | 32 static const STACK = 'stack'; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 /** | 157 /** |
| 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.stringify(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 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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.parse(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'], |
| 252 frame['member']); | 252 frame['member']); |
| 253 })); | 253 })); |
| 254 } else { | 254 } else { |
| 255 _testTime = msg.elapsed; | 255 _testTime = msg.elapsed; |
| 256 logMessage(_Message.text(_Message.LOG, _testTime, 'Complete')); | 256 logMessage(_Message.text(_Message.LOG, _testTime, 'Complete')); |
| 257 if (msg.messageType == _Message.PASS) { | 257 if (msg.messageType == _Message.PASS) { |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 """; |
| OLD | NEW |