Chromium Code Reviews| 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 library mocks; | 5 library mocks; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 @MirrorsUsed(targets: 'mocks', override: '*') | 9 @MirrorsUsed(targets: 'mocks', override: '*') |
| 10 import 'dart:mirrors'; | 10 import 'dart:mirrors'; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 * A [Matcher] that check that the given [Response] has an expected identifier | 51 * A [Matcher] that check that the given [Response] has an expected identifier |
| 52 * and no error. | 52 * and no error. |
| 53 */ | 53 */ |
| 54 Matcher isResponseSuccess(String id) => new _IsResponseSuccess(id); | 54 Matcher isResponseSuccess(String id) => new _IsResponseSuccess(id); |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * Returns a [Future] that completes after pumping the event queue [times] | 57 * Returns a [Future] that completes after pumping the event queue [times] |
| 58 * times. By default, this should pump the event queue enough times to allow | 58 * times. By default, this should pump the event queue enough times to allow |
| 59 * any code to run, as long as it's not waiting on some external event. | 59 * any code to run, as long as it's not waiting on some external event. |
| 60 */ | 60 */ |
| 61 Future pumpEventQueue([int times = 500]) { | 61 Future pumpEventQueue([int times = 5000]) { |
|
Brian Wilkerson
2015/08/11 18:13:01
I'm a little concerned that changing the limit wil
| |
| 62 if (times == 0) return new Future.value(); | 62 if (times == 0) return new Future.value(); |
| 63 // We use a delayed future to allow microtask events to finish. The | 63 // We use a delayed future to allow microtask events to finish. The |
| 64 // Future.value or Future() constructors use scheduleMicrotask themselves and | 64 // Future.value or Future() constructors use scheduleMicrotask themselves and |
| 65 // would therefore not wait for microtask callbacks that are scheduled after | 65 // would therefore not wait for microtask callbacks that are scheduled after |
| 66 // invoking this method. | 66 // invoking this method. |
| 67 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); | 67 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 typedef void MockServerOperationPerformFunction(AnalysisServer server); | 70 typedef void MockServerOperationPerformFunction(AnalysisServer server); |
| 71 | 71 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 } | 222 } |
| 223 | 223 |
| 224 void expectMsgCount({responseCount: 0, notificationCount: 0}) { | 224 void expectMsgCount({responseCount: 0, notificationCount: 0}) { |
| 225 expect(responsesReceived, hasLength(responseCount)); | 225 expect(responsesReceived, hasLength(responseCount)); |
| 226 expect(notificationsReceived, hasLength(notificationCount)); | 226 expect(notificationsReceived, hasLength(notificationCount)); |
| 227 } | 227 } |
| 228 | 228 |
| 229 @override | 229 @override |
| 230 void listen(void onRequest(Request request), | 230 void listen(void onRequest(Request request), |
| 231 {Function onError, void onDone()}) { | 231 {Function onError, void onDone()}) { |
| 232 requestController.stream.listen(onRequest, | 232 requestController.stream |
| 233 onError: onError, onDone: onDone); | 233 .listen(onRequest, onError: onError, onDone: onDone); |
| 234 } | 234 } |
| 235 | 235 |
| 236 @override | 236 @override |
| 237 void sendNotification(Notification notification) { | 237 void sendNotification(Notification notification) { |
| 238 // Don't deliver notifications after the connection is closed. | 238 // Don't deliver notifications after the connection is closed. |
| 239 if (_closed) { | 239 if (_closed) { |
| 240 return; | 240 return; |
| 241 } | 241 } |
| 242 notificationsReceived.add(notification); | 242 notificationsReceived.add(notification); |
| 243 // Wrap send notification in future to simulate websocket | 243 // Wrap send notification in future to simulate websocket |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 void add(T text) => controller.add(text); | 323 void add(T text) => controller.add(text); |
| 324 | 324 |
| 325 void allowMultipleListeners() { | 325 void allowMultipleListeners() { |
| 326 stream = stream.asBroadcastStream(); | 326 stream = stream.asBroadcastStream(); |
| 327 } | 327 } |
| 328 | 328 |
| 329 Future close([int code, String reason]) => | 329 Future close([int code, String reason]) => |
| 330 controller.close().then((_) => twin.controller.close()); | 330 controller.close().then((_) => twin.controller.close()); |
| 331 | 331 |
| 332 StreamSubscription<T> listen(void onData(T event), | 332 StreamSubscription<T> listen(void onData(T event), |
| 333 {Function onError, void onDone(), bool cancelOnError}) => stream.listen( | 333 {Function onError, void onDone(), bool cancelOnError}) => |
| 334 onData, | 334 stream.listen(onData, |
| 335 onError: onError, onDone: onDone, cancelOnError: cancelOnError); | 335 onError: onError, onDone: onDone, cancelOnError: cancelOnError); |
| 336 | 336 |
| 337 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 337 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 338 | 338 |
| 339 Stream<T> where(bool test(T)) => stream.where(test); | 339 Stream<T> where(bool test(T)) => stream.where(test); |
| 340 } | 340 } |
| 341 | 341 |
| 342 class MockSource extends StringTypedMock implements Source { | 342 class MockSource extends StringTypedMock implements Source { |
| 343 MockSource([String name = 'mocked.dart']) : super(name); | 343 MockSource([String name = 'mocked.dart']) : super(name); |
| 344 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 344 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 } | 461 } |
| 462 return mismatchDescription; | 462 return mismatchDescription; |
| 463 } | 463 } |
| 464 | 464 |
| 465 @override | 465 @override |
| 466 bool matches(item, Map matchState) { | 466 bool matches(item, Map matchState) { |
| 467 Response response = item; | 467 Response response = item; |
| 468 return response != null && response.id == _id && response.error == null; | 468 return response != null && response.id == _id && response.error == null; |
| 469 } | 469 } |
| 470 } | 470 } |
| OLD | NEW |