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

import 'package:flutter_tools/src/base/platform.dart';
6
import 'package:flutter_tools/src/base/version.dart';
7
import 'package:flutter_tools/src/ios/ios_workflow.dart';
8
import 'package:flutter_tools/src/ios/xcodeproj.dart';
9 10 11
import 'package:flutter_tools/src/macos/xcode.dart';

import '../../src/common.dart';
12
import '../../src/fake_process_manager.dart';
13
import '../../src/fakes.dart';
14 15 16 17 18

void main() {
  testWithoutContext('iOS workflow is disabled if feature is disabled', () {
    final IOSWorkflow iosWorkflow = IOSWorkflow(
      platform: FakePlatform(operatingSystem: 'macOS'),
19
      xcode: Xcode.test(processManager: FakeProcessManager.any()),
20 21 22 23
      featureFlags: TestFeatureFlags(isIOSEnabled: false),
    );

    expect(iosWorkflow.appliesToHostPlatform, false);
24 25
    expect(iosWorkflow.canLaunchDevices, false);
    expect(iosWorkflow.canListDevices, false);
26 27 28 29
  });

  testWithoutContext('iOS workflow is disabled on Linux', () {
    final IOSWorkflow iosWorkflow = IOSWorkflow(
30
      platform: FakePlatform(),
31
      xcode: Xcode.test(processManager: FakeProcessManager.any()),
32
      featureFlags: TestFeatureFlags(),
33 34 35
    );

    expect(iosWorkflow.appliesToHostPlatform, false);
36 37
    expect(iosWorkflow.canLaunchDevices, false);
    expect(iosWorkflow.canListDevices, false);
38 39 40 41 42
  });

  testWithoutContext('iOS workflow is disabled on windows', () {
    final IOSWorkflow iosWorkflow = IOSWorkflow(
      platform: FakePlatform(operatingSystem: 'windows'),
43
      xcode: Xcode.test(processManager: FakeProcessManager.any()),
44
      featureFlags: TestFeatureFlags(),
45 46 47
    );

    expect(iosWorkflow.appliesToHostPlatform, false);
48 49
    expect(iosWorkflow.canLaunchDevices, false);
    expect(iosWorkflow.canListDevices, false);
50 51
  });

52 53 54 55 56 57 58 59 60
  testWithoutContext('iOS workflow applies on macOS, no Xcode or simctl', () {
    final FakeProcessManager xcodeProcessManager = FakeProcessManager.list(<FakeCommand>[
      const FakeCommand(
        command: <String>[
          'xcrun', 'simctl', 'list', 'devices', 'booted',
        ],
        exitCode: 1,
      ),
    ]);
61 62
    final IOSWorkflow iosWorkflow = IOSWorkflow(
      platform: FakePlatform(operatingSystem: 'macos'),
63
      xcode: Xcode.test(processManager: xcodeProcessManager,
64 65 66 67 68
        xcodeProjectInterpreter: XcodeProjectInterpreter.test(
          processManager: FakeProcessManager.any(),
          version: null,
        ),
      ),
69
      featureFlags: TestFeatureFlags(),
70 71 72
    );

    expect(iosWorkflow.appliesToHostPlatform, true);
73 74
    expect(iosWorkflow.canLaunchDevices, false);
    expect(iosWorkflow.canListDevices, false);
75
    expect(iosWorkflow.canListEmulators, false);
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    expect(xcodeProcessManager, hasNoRemainingExpectations);
  });

  testWithoutContext('iOS workflow can list devices even when Xcode version is too low', () {
    final Xcode xcode = Xcode.test(
      processManager: FakeProcessManager.any(),
      xcodeProjectInterpreter: XcodeProjectInterpreter.test(
          processManager: FakeProcessManager.any(),
          version: Version(1, 0, 0)
      ),
    );

    final IOSWorkflow iosWorkflow = IOSWorkflow(
      platform: FakePlatform(operatingSystem: 'macos'),
      xcode: xcode,
      featureFlags: TestFeatureFlags(),
    );

    // Make sure we're testing the right Xcode state.
    // expect(xcode.isInstalledAndMeetsVersionCheck, true);
    expect(xcode.isSimctlInstalled, true);
    expect(iosWorkflow.canLaunchDevices, false);
    expect(iosWorkflow.canListDevices, true);
    expect(iosWorkflow.canListEmulators, false);
100 101
  });

102
  testWithoutContext('iOS workflow can launch devices when Xcode is set up', () {
103 104 105 106
    final Xcode xcode = Xcode.test(
      processManager: FakeProcessManager.any(),
      xcodeProjectInterpreter: XcodeProjectInterpreter.test(
        processManager: FakeProcessManager.any(),
107
        version: Version(1000, 0, 0)
108 109 110
      ),
    );

111 112 113
    final IOSWorkflow iosWorkflow = IOSWorkflow(
      platform: FakePlatform(operatingSystem: 'macos'),
      xcode: xcode,
114
      featureFlags: TestFeatureFlags(),
115 116
    );

117 118 119
    // Make sure we're testing the right Xcode state.
    expect(xcode.isInstalledAndMeetsVersionCheck, true);
    expect(xcode.isSimctlInstalled, true);
120 121
    expect(iosWorkflow.canLaunchDevices, true);
    expect(iosWorkflow.canListDevices, true);
122
    expect(iosWorkflow.canListEmulators, false);
123 124
  });
}