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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 switch (message) { | 95 switch (message) { |
96 case 'dart-calling-main': | 96 case 'dart-calling-main': |
97 case 'dart-main-done': | 97 case 'dart-main-done': |
98 case 'unittest-suite-done': | 98 case 'unittest-suite-done': |
99 case 'unittest-suite-fail': | 99 case 'unittest-suite-fail': |
100 case 'unittest-suite-success': | 100 case 'unittest-suite-success': |
101 case 'unittest-suite-wait-for-done': | 101 case 'unittest-suite-wait-for-done': |
102 break; | 102 break; |
103 | 103 |
104 default: | 104 default: |
105 completer.completeError('Unexpected message: "$message".'); | 105 completer.completeError( |
| 106 'Unexpected message: "$message" (expected "$expectedMessage").'); |
106 } | 107 } |
107 } | 108 } |
108 } | 109 } |
109 | 110 |
110 Future expect(data) { | 111 Future expect(data) { |
111 if (data is String) { | 112 if (data is String) { |
112 Expect.isTrue(completer == null || completer.isCompleted); | 113 Expect.isTrue(completer == null || completer.isCompleted); |
113 expectedMessage = data; | 114 expectedMessage = data; |
114 completer = new Completer(); | 115 completer = new Completer(); |
115 return completer.future; | 116 return completer.future; |
116 } else if (data is Iterable) { | 117 } else if (data is Iterable) { |
117 return Future.forEach(data, expect); | 118 return Future.forEach(data, expect); |
118 } else { | 119 } else { |
119 throw 'Unexpected data type: ${data.runtimeType}.'; | 120 throw 'Unexpected data type: ${data.runtimeType}.'; |
120 } | 121 } |
121 } | 122 } |
122 | 123 |
123 void start() { | 124 void start() { |
124 wallclock = new Stopwatch()..start(); | 125 wallclock = new Stopwatch()..start(); |
125 window.onMessage.listen(onMessage); | 126 window.onMessage.listen(onMessage); |
126 } | 127 } |
127 } | 128 } |
OLD | NEW |