linux_device_test.dart 4.6 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter 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
import 'package:file/memory.dart';
6
import 'package:flutter_tools/src/base/file_system.dart';
7
import 'package:flutter_tools/src/base/platform.dart';
8
import 'package:flutter_tools/src/build_info.dart';
9 10
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
11
import 'package:flutter_tools/src/linux/application_package.dart';
12
import 'package:flutter_tools/src/linux/linux_device.dart';
13
import 'package:flutter_tools/src/project.dart';
14 15
import 'package:mockito/mockito.dart';

16 17
import '../../src/common.dart';
import '../../src/context.dart';
18
import '../../src/testbed.dart';
19 20

void main() {
21 22 23
  final LinuxDevice device = LinuxDevice();
  final MockPlatform notLinux = MockPlatform();
  when(notLinux.isLinux).thenReturn(false);
24

25 26 27 28
  final MockPlatform mockLinuxPlatform = MockPlatform();
  when(mockLinuxPlatform.isLinux).thenReturn(true);

  testWithoutContext('LinuxDevice defaults', () async {
29 30 31 32 33 34 35 36 37 38
    final PrebuiltLinuxApp linuxApp = PrebuiltLinuxApp(executable: 'foo');
    expect(await device.targetPlatform, TargetPlatform.linux_x64);
    expect(device.name, 'Linux');
    expect(await device.installApp(linuxApp), true);
    expect(await device.uninstallApp(linuxApp), true);
    expect(await device.isLatestBuildInstalled(linuxApp), true);
    expect(await device.isAppInstalled(linuxApp), true);
    expect(await device.stopApp(linuxApp), true);
    expect(device.category, Category.desktop);
  });
39

40
  testWithoutContext('LinuxDevice: no devices listed if platform unsupported', () async {
41 42
    expect(await LinuxDevices(
      platform: notLinux,
43 44 45 46 47 48 49 50
      featureFlags: TestFeatureFlags(isLinuxEnabled: true),
    ).devices, <Device>[]);
  });

  testWithoutContext('LinuxDevice: no devices listed if Linux feature flag disabled', () async {
    expect(await LinuxDevices(
      platform: mockLinuxPlatform,
      featureFlags: TestFeatureFlags(isLinuxEnabled: false),
51
    ).devices, <Device>[]);
52
  });
53

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
  testWithoutContext('LinuxDevice: devices', () async {
    expect(await LinuxDevices(
      platform: mockLinuxPlatform,
      featureFlags: TestFeatureFlags(isLinuxEnabled: true),
    ).devices, hasLength(1));
  });

  testWithoutContext('LinuxDevice: discoverDevices', () async {
    // Timeout ignored.
    final List<Device> devices = await LinuxDevices(
      platform: mockLinuxPlatform,
      featureFlags: TestFeatureFlags(isLinuxEnabled: true),
    ).discoverDevices(timeout: const Duration(seconds: 10));
    expect(devices, hasLength(1));
  });

70
  testUsingContext('LinuxDevice.isSupportedForProject is true with editable host app', () async {
71 72 73
    globals.fs.file('pubspec.yaml').createSync();
    globals.fs.file('.packages').createSync();
    globals.fs.directory('linux').createSync();
74
    final FlutterProject flutterProject = FlutterProject.current();
75 76 77 78

    expect(LinuxDevice().isSupportedForProject(flutterProject), true);
  }, overrides: <Type, Generator>{
    FileSystem: () => MemoryFileSystem(),
79
    ProcessManager: () => FakeProcessManager.any(),
80 81 82
  });

  testUsingContext('LinuxDevice.isSupportedForProject is false with no host app', () async {
83 84
    globals.fs.file('pubspec.yaml').createSync();
    globals.fs.file('.packages').createSync();
85
    final FlutterProject flutterProject = FlutterProject.current();
86 87 88 89

    expect(LinuxDevice().isSupportedForProject(flutterProject), false);
  }, overrides: <Type, Generator>{
    FileSystem: () => MemoryFileSystem(),
90
    ProcessManager: () => FakeProcessManager.any(),
91
  });
92

93
  testUsingContext('LinuxDevice.executablePathForDevice uses the correct package executable', () async {
94 95 96 97 98 99 100 101 102 103 104 105 106
    final MockLinuxApp mockApp = MockLinuxApp();
    const String debugPath = 'debug/executable';
    const String profilePath = 'profile/executable';
    const String releasePath = 'release/executable';
    when(mockApp.executable(BuildMode.debug)).thenReturn(debugPath);
    when(mockApp.executable(BuildMode.profile)).thenReturn(profilePath);
    when(mockApp.executable(BuildMode.release)).thenReturn(releasePath);

    expect(LinuxDevice().executablePathForDevice(mockApp, BuildMode.debug), debugPath);
    expect(LinuxDevice().executablePathForDevice(mockApp, BuildMode.profile), profilePath);
    expect(LinuxDevice().executablePathForDevice(mockApp, BuildMode.release), releasePath);
  }, overrides: <Type, Generator>{
    FileSystem: () => MemoryFileSystem(),
107
    ProcessManager: () => FakeProcessManager.any(),
108
  });
109 110 111
}

class MockPlatform extends Mock implements Platform {}
112

113
class MockLinuxApp extends Mock implements LinuxApp {}