device_test.dart 1.9 KB
Newer Older
1
// Copyright 2016 The Chromium Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
import 'dart:async';

7 8 9
import 'package:flutter_tools/src/device.dart';
import 'package:test/test.dart';

10
import 'src/context.dart';
11

12
void main() {
13
  group('DeviceManager', () {
14
    testUsingContext('getDevices', () async {
15 16 17 18 19
      // Test that DeviceManager.getDevices() doesn't throw.
      DeviceManager deviceManager = new DeviceManager();
      List<Device> devices = await deviceManager.getDevices();
      expect(devices, isList);
    });
20 21 22 23 24 25

    testUsingContext('getDeviceById', () async {
      _MockDevice device1 = new _MockDevice('Nexus 5', '0553790d0a4e726f');
      _MockDevice device2 = new _MockDevice('Nexus 5X', '01abfc49119c410e');
      _MockDevice device3 = new _MockDevice('iPod touch', '82564b38861a9a5');
      List<Device> devices = <Device>[device1, device2, device3];
26
      DeviceManager deviceManager = new TestDeviceManager(devices);
27

28 29
      Future<Null> expectDevice(String id, List<Device> expected) async {
        expect(await deviceManager.getDevicesById(id), expected);
30
      }
31 32 33 34 35 36
      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]);
37
    });
38 39
  });
}
40

41 42 43 44 45 46 47 48 49 50 51
class TestDeviceManager extends DeviceManager {
  final List<Device> allDevices;

  TestDeviceManager(this.allDevices);

  @override
  Future<List<Device>> getAllConnectedDevices() async {
    return allDevices;
  }
}

52 53 54 55 56 57 58 59 60
class _MockDevice extends Device {
  @override
  final String name;

  _MockDevice(this.name, String id) : super(id);

  @override
  void noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}