linux_device_test.dart 3.53 KB
Newer Older
1 2 3 4
// Copyright 2018 The Chromium Authors. All rights reserved.
// 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 8
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
9
import 'package:flutter_tools/src/linux/application_package.dart';
10 11
import 'package:flutter_tools/src/linux/linux_device.dart';
import 'package:flutter_tools/src/device.dart';
12
import 'package:flutter_tools/src/project.dart';
13 14
import 'package:mockito/mockito.dart';

15 16
import '../../src/common.dart';
import '../../src/context.dart';
17 18

void main() {
19 20
  final LinuxDevice device = LinuxDevice();
  final MockPlatform notLinux = MockPlatform();
21

22
  when(notLinux.isLinux).thenReturn(false);
23

24 25 26 27 28 29 30 31 32 33 34
  testUsingContext('LinuxDevice defaults', () async {
    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);
  });
35

36 37 38 39
  testUsingContext('LinuxDevice: no devices listed if platform unsupported', () async {
    expect(await LinuxDevices().devices, <Device>[]);
  }, overrides: <Type, Generator>{
    Platform: () => notLinux,
40
  });
41 42 43 44 45

  testUsingContext('LinuxDevice.isSupportedForProject is true with editable host app', () async {
    fs.file('pubspec.yaml').createSync();
    fs.file('.packages').createSync();
    fs.directory('linux').createSync();
46
    final FlutterProject flutterProject = FlutterProject.current();
47 48 49 50

    expect(LinuxDevice().isSupportedForProject(flutterProject), true);
  }, overrides: <Type, Generator>{
    FileSystem: () => MemoryFileSystem(),
51
    ProcessManager: () => FakeProcessManager.any(),
52 53 54 55 56
  });

  testUsingContext('LinuxDevice.isSupportedForProject is false with no host app', () async {
    fs.file('pubspec.yaml').createSync();
    fs.file('.packages').createSync();
57
    final FlutterProject flutterProject = FlutterProject.current();
58 59 60 61

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

65
  testUsingContext('LinuxDevice.executablePathForDevice uses the correct package executable', () async {
66 67 68 69 70 71 72 73 74 75 76 77 78
    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(),
79
    ProcessManager: () => FakeProcessManager.any(),
80
  });
81 82 83
}

class MockPlatform extends Mock implements Platform {}
84

85
class MockLinuxApp extends Mock implements LinuxApp {}