2016-01-28 06:38:57 +00:00
|
|
|
// Copyright 2016 The Chromium Authors. All rights reserved.
|
2016-01-27 22:03:41 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2016-08-30 18:11:54 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2016-01-27 22:03:41 +00:00
|
|
|
import 'package:flutter_tools/src/device.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
2016-02-13 20:00:41 +00:00
|
|
|
import 'src/context.dart';
|
2016-02-07 03:19:50 +00:00
|
|
|
|
2016-03-10 01:43:14 +00:00
|
|
|
void main() {
|
2016-01-27 22:03:41 +00:00
|
|
|
group('DeviceManager', () {
|
2016-02-07 03:19:50 +00:00
|
|
|
testUsingContext('getDevices', () async {
|
2016-01-27 22:03:41 +00:00
|
|
|
// Test that DeviceManager.getDevices() doesn't throw.
|
2017-03-04 01:50:46 +00:00
|
|
|
final DeviceManager deviceManager = new DeviceManager();
|
2017-04-26 00:23:00 +00:00
|
|
|
final List<Device> devices = await deviceManager.getDevices().toList();
|
2016-01-27 22:03:41 +00:00
|
|
|
expect(devices, isList);
|
|
|
|
});
|
2016-08-30 18:11:54 +00:00
|
|
|
|
|
|
|
testUsingContext('getDeviceById', () async {
|
2017-03-04 01:50:46 +00:00
|
|
|
final _MockDevice device1 = new _MockDevice('Nexus 5', '0553790d0a4e726f');
|
|
|
|
final _MockDevice device2 = new _MockDevice('Nexus 5X', '01abfc49119c410e');
|
|
|
|
final _MockDevice device3 = new _MockDevice('iPod touch', '82564b38861a9a5');
|
|
|
|
final List<Device> devices = <Device>[device1, device2, device3];
|
|
|
|
final DeviceManager deviceManager = new TestDeviceManager(devices);
|
2016-08-30 18:11:54 +00:00
|
|
|
|
2016-09-01 16:37:58 +00:00
|
|
|
Future<Null> expectDevice(String id, List<Device> expected) async {
|
2017-04-26 00:23:00 +00:00
|
|
|
expect(await deviceManager.getDevicesById(id).toList(), expected);
|
2016-08-30 18:11:54 +00:00
|
|
|
}
|
2016-09-01 16:37:58 +00:00
|
|
|
expectDevice('01abfc49119c410e', <Device>[device2]);
|
|
|
|
expectDevice('Nexus 5X', <Device>[device2]);
|
|
|
|
expectDevice('0553790d0a4e726f', <Device>[device1]);
|
|
|
|
expectDevice('Nexus 5', <Device>[device1]);
|
|
|
|
expectDevice('0553790', <Device>[device1]);
|
|
|
|
expectDevice('Nexus', <Device>[device1, device2]);
|
2016-08-30 18:11:54 +00:00
|
|
|
});
|
2016-01-27 22:03:41 +00:00
|
|
|
});
|
|
|
|
}
|
2016-08-30 18:11:54 +00:00
|
|
|
|
2016-09-01 16:37:58 +00:00
|
|
|
class TestDeviceManager extends DeviceManager {
|
|
|
|
final List<Device> allDevices;
|
|
|
|
|
|
|
|
TestDeviceManager(this.allDevices);
|
|
|
|
|
|
|
|
@override
|
2017-04-26 00:23:00 +00:00
|
|
|
Stream<Device> getAllConnectedDevices() {
|
|
|
|
return new Stream<Device>.fromIterable(allDevices);
|
2016-09-01 16:37:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-30 18:11:54 +00:00
|
|
|
class _MockDevice extends Device {
|
|
|
|
@override
|
|
|
|
final String name;
|
|
|
|
|
|
|
|
_MockDevice(this.name, String id) : super(id);
|
|
|
|
|
|
|
|
@override
|
|
|
|
void noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
|
|
|
}
|