Commit 9ac2e44e authored by Devon Carew's avatar Devon Carew Committed by GitHub

add a regression test for daemon device notification (#9618)

* add a regression test for daemon device notification

* revert event send simplification
parent d2c6b0a6
......@@ -521,28 +521,26 @@ class DeviceDomain extends Domain {
registerHandler('forward', forward);
registerHandler('unforward', unforward);
PollingDeviceDiscovery deviceDiscovery = new AndroidDevices();
if (deviceDiscovery.supportsPlatform)
_discoverers.add(deviceDiscovery);
addDeviceDiscoverer(new AndroidDevices());
addDeviceDiscoverer(new IOSDevices());
addDeviceDiscoverer(new IOSSimulators());
}
deviceDiscovery = new IOSDevices();
if (deviceDiscovery.supportsPlatform)
_discoverers.add(deviceDiscovery);
void addDeviceDiscoverer(PollingDeviceDiscovery discoverer) {
if (!discoverer.supportsPlatform)
return;
deviceDiscovery = new IOSSimulators();
if (deviceDiscovery.supportsPlatform)
_discoverers.add(deviceDiscovery);
_discoverers.add(discoverer);
for (PollingDeviceDiscovery discoverer in _discoverers) {
discoverer.onAdded.listen(_onDeviceEvent('device.added'));
discoverer.onRemoved.listen(_onDeviceEvent('device.removed'));
}
discoverer.onAdded.listen(_onDeviceEvent('device.added'));
discoverer.onRemoved.listen(_onDeviceEvent('device.removed'));
}
Future<Null> _deviceEvents = new Future<Null>.value();
Future<Null> _serializeDeviceEvents = new Future<Null>.value();
_DeviceEventHandler _onDeviceEvent(String eventName) {
return (Device device) {
_deviceEvents = _deviceEvents.then((_) async {
_serializeDeviceEvents = _serializeDeviceEvents.then((_) async {
sendEvent(eventName, await _deviceToMap(device));
});
};
......@@ -673,6 +671,7 @@ dynamic _toJsonable(dynamic obj) {
return obj;
if (obj is OperationResult)
return obj;
assert(false, 'obj not jsonable');
return '$obj';
}
......
......@@ -231,6 +231,31 @@ void main() {
responses.close();
commands.close();
});
_testUsingContext('device.notify', () {
final StreamController<Map<String, dynamic>> commands = new StreamController<Map<String, dynamic>>();
final StreamController<Map<String, dynamic>> responses = new StreamController<Map<String, dynamic>>();
daemon = new Daemon(
commands.stream,
responses.add,
notifyingLogger: notifyingLogger
);
final MockPollingDeviceDiscovery discoverer = new MockPollingDeviceDiscovery();
daemon.deviceDomain.addDeviceDiscoverer(discoverer);
discoverer.addDevice(new MockAndroidDevice());
return responses.stream.first.then((Map<String, dynamic> response) {
expect(response['event'], 'device.added');
expect(response['params'], isMap);
final Map<String, dynamic> params = response['params'];
expect(params['platform'], isNotEmpty); // the mock device has a platform of 'android-arm'
responses.close();
commands.close();
});
});
});
}
......
......@@ -29,6 +29,35 @@ class MockApplicationPackageStore extends ApplicationPackageStore {
);
}
class MockPollingDeviceDiscovery extends PollingDeviceDiscovery {
List<Device> _devices = <Device>[];
StreamController<Device> _onAddedController = new StreamController<Device>.broadcast();
StreamController<Device> _onRemovedController = new StreamController<Device>.broadcast();
MockPollingDeviceDiscovery() : super('mock');
@override
List<Device> pollingGetDevices() => _devices;
@override
bool get supportsPlatform => true;
void addDevice(MockAndroidDevice device) {
_devices.add(device);
_onAddedController.add(device);
}
@override
List<Device> get devices => _devices;
@override
Stream<Device> get onAdded => _onAddedController.stream;
@override
Stream<Device> get onRemoved => _onRemovedController.stream;
}
class MockAndroidDevice extends Mock implements AndroidDevice {
@override
Future<TargetPlatform> get targetPlatform async => TargetPlatform.android_arm;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment