ios_workflow_test.dart 3.38 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 30
  });

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

    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 45 46 47
      featureFlags: TestFeatureFlags(isIOSEnabled: true),
    );

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

52
  testWithoutContext('iOS workflow applies on macOS, no Xcode', () {
53 54
    final IOSWorkflow iosWorkflow = IOSWorkflow(
      platform: FakePlatform(operatingSystem: 'macos'),
55 56 57 58 59 60
      xcode: Xcode.test(processManager: FakeProcessManager.any(),
        xcodeProjectInterpreter: XcodeProjectInterpreter.test(
          processManager: FakeProcessManager.any(),
          version: null,
        ),
      ),
61 62 63 64
      featureFlags: TestFeatureFlags(isIOSEnabled: true),
    );

    expect(iosWorkflow.appliesToHostPlatform, true);
65 66
    expect(iosWorkflow.canLaunchDevices, false);
    expect(iosWorkflow.canListDevices, false);
67 68 69 70
    expect(iosWorkflow.canListEmulators, false);
  });

  testWithoutContext('iOS workflow can launch and list devices when Xcode is set up', () {
71 72 73 74
    final Xcode xcode = Xcode.test(
      processManager: FakeProcessManager.any(),
      xcodeProjectInterpreter: XcodeProjectInterpreter.test(
        processManager: FakeProcessManager.any(),
75
        version: Version(1000, 0, 0)
76 77 78
      ),
    );

79 80 81 82 83 84
    final IOSWorkflow iosWorkflow = IOSWorkflow(
      platform: FakePlatform(operatingSystem: 'macos'),
      xcode: xcode,
      featureFlags: TestFeatureFlags(isIOSEnabled: true),
    );

85 86 87
    // Make sure we're testing the right Xcode state.
    expect(xcode.isInstalledAndMeetsVersionCheck, true);
    expect(xcode.isSimctlInstalled, true);
88 89
    expect(iosWorkflow.canLaunchDevices, true);
    expect(iosWorkflow.canListDevices, true);
90
    expect(iosWorkflow.canListEmulators, false);
91 92
  });
}