| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// Helper library that creates an iframe sandbox that can be used to load | 5 /// Helper library that creates an iframe sandbox that can be used to load |
| 6 /// code. | 6 /// code. |
| 7 library trydart.test.sandbox; | 7 library trydart.test.sandbox; |
| 8 | 8 |
| 9 import 'dart:html'; | 9 import 'dart:html'; |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // stackoverflow. | 76 // stackoverflow. |
| 77 installErrorHandlerOn(iframe); | 77 installErrorHandlerOn(iframe); |
| 78 return iframe; | 78 return iframe; |
| 79 } | 79 } |
| 80 | 80 |
| 81 class Listener { | 81 class Listener { |
| 82 Completer completer; | 82 Completer completer; |
| 83 | 83 |
| 84 String expectedMessage; | 84 String expectedMessage; |
| 85 | 85 |
| 86 Stopwatch wallclock; |
| 87 |
| 88 int get elapsed => wallclock.elapsedMilliseconds ~/ 1000; |
| 89 |
| 86 void onMessage(MessageEvent e) { | 90 void onMessage(MessageEvent e) { |
| 87 String message = e.data; | 91 String message = e.data; |
| 88 if (expectedMessage == message) { | 92 if (expectedMessage == message) { |
| 89 completer.complete(); | 93 completer.complete(); |
| 90 } else { | 94 } else { |
| 91 switch (message) { | 95 switch (message) { |
| 92 case 'dart-calling-main': | 96 case 'dart-calling-main': |
| 93 case 'dart-main-done': | 97 case 'dart-main-done': |
| 94 case 'unittest-suite-done': | 98 case 'unittest-suite-done': |
| 95 case 'unittest-suite-fail': | 99 case 'unittest-suite-fail': |
| (...skipping 14 matching lines...) Expand all Loading... |
| 110 completer = new Completer(); | 114 completer = new Completer(); |
| 111 return completer.future; | 115 return completer.future; |
| 112 } else if (data is Iterable) { | 116 } else if (data is Iterable) { |
| 113 return Future.forEach(data, expect); | 117 return Future.forEach(data, expect); |
| 114 } else { | 118 } else { |
| 115 throw 'Unexpected data type: ${data.runtimeType}.'; | 119 throw 'Unexpected data type: ${data.runtimeType}.'; |
| 116 } | 120 } |
| 117 } | 121 } |
| 118 | 122 |
| 119 void start() { | 123 void start() { |
| 124 wallclock = new Stopwatch()..start(); |
| 120 window.onMessage.listen(onMessage); | 125 window.onMessage.listen(onMessage); |
| 121 } | 126 } |
| 122 } | 127 } |
| OLD | NEW |