android_studio_test.dart 5.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 6 7 8
import 'package:file/memory.dart';
import 'package:flutter_tools/src/android/android_studio.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';
9
import 'package:flutter_tools/src/ios/plist_parser.dart';
10
import 'package:mockito/mockito.dart';
11

12 13
import '../../src/common.dart';
import '../../src/context.dart';
14

15 16 17
const String homeLinux = '/home/me';
const String homeMac = '/Users/me';

18 19 20 21 22 23 24 25 26 27 28
const Map<String, dynamic> macStudioInfoPlist = <String, dynamic>{
  'CFBundleGetInfoString': 'Android Studio 3.3, build AI-182.5107.16.33.5199772. Copyright JetBrains s.r.o., (c) 2000-2018',
  'CFBundleShortVersionString': '3.3',
  'CFBundleVersion': 'AI-182.5107.16.33.5199772',
  'JVMOptions': <String, dynamic>{
    'Properties': <String, dynamic>{
      'idea.paths.selector': 'AndroidStudio3.3',
      'idea.platform.prefix': 'AndroidStudio',
    },
  },
};
29

30
class MockPlistUtils extends Mock implements PlistParser {}
31 32 33 34

Platform linuxPlatform() {
  return FakePlatform.fromPlatform(const LocalPlatform())
    ..operatingSystem = 'linux'
35
    ..environment = <String, String>{'HOME': homeLinux};
36 37
}

38 39 40 41 42
Platform macPlatform() {
  return FakePlatform.fromPlatform(const LocalPlatform())
    ..operatingSystem = 'macos'
    ..environment = <String, String>{'HOME': homeMac};
}
43

44
void main() {
45
  MemoryFileSystem fs;
46
  MockPlistUtils plistUtils;
47 48 49

  setUp(() {
    fs = MemoryFileSystem();
50
    plistUtils = MockPlistUtils();
51 52
  });

53
  group('pluginsPath on Linux', () {
54
    testUsingContext('extracts custom paths from home dir', () {
55 56 57 58 59 60 61
      const String installPath = '/opt/android-studio-with-cheese-5.0';
      const String studioHome = '$homeLinux/.AndroidStudioWithCheese5.0';
      const String homeFile = '$studioHome/system/.home';
      fs.directory(installPath).createSync(recursive: true);
      fs.file(homeFile).createSync(recursive: true);
      fs.file(homeFile).writeAsStringSync(installPath);

62
      final AndroidStudio studio =
63
      AndroidStudio.fromHomeDot(fs.directory(studioHome));
64 65 66 67 68
      expect(studio, isNotNull);
      expect(studio.pluginsPath,
          equals('/home/me/.AndroidStudioWithCheese5.0/config/plugins'));
    }, overrides: <Type, Generator>{
      FileSystem: () => fs,
Ian Hickson's avatar
Ian Hickson committed
69 70
      // Custom home paths are not supported on macOS nor Windows yet,
      // so we force the platform to fake Linux here.
71 72 73
      Platform: () => linuxPlatform(),
    });
  });
74 75 76 77 78 79 80

  group('pluginsPath on Mac', () {
    testUsingContext('extracts custom paths for directly downloaded Android Studio on Mac', () {
      final String studioInApplicationPlistFolder = fs.path.join('/', 'Application', 'Android Studio.app', 'Contents');
      fs.directory(studioInApplicationPlistFolder).createSync(recursive: true);

      final String plistFilePath = fs.path.join(studioInApplicationPlistFolder, 'Info.plist');
81
      when(plistUtils.parseFile(plistFilePath)).thenReturn(macStudioInfoPlist);
82 83 84 85 86 87 88 89 90
      final AndroidStudio studio = AndroidStudio.fromMacOSBundle(fs.directory(studioInApplicationPlistFolder)?.parent?.path);
      expect(studio, isNotNull);
      expect(studio.pluginsPath,
          equals(fs.path.join(homeMac, 'Library', 'Application Support', 'AndroidStudio3.3')));
    }, overrides: <Type, Generator>{
      FileSystem: () => fs,
      // Custom home paths are not supported on macOS nor Windows yet,
      // so we force the platform to fake Linux here.
      Platform: () => macPlatform(),
91
      PlistParser: () => plistUtils,
92 93 94 95 96
    });

    testUsingContext('extracts custom paths for Android Studio downloaded by JetBrainsToolbox on Mac', () {
      final String jetbrainsStudioInApplicationPlistFolder = fs.path.join(homeMac, 'Application', 'JetBrains Toolbox', 'Android Studio.app', 'Contents');
      fs.directory(jetbrainsStudioInApplicationPlistFolder).createSync(recursive: true);
97 98 99 100 101 102
      const Map<String, dynamic> jetbrainsInfoPlist = <String, dynamic>{
        'CFBundleLongVersionString': '3.3',
        'CFBundleShortVersionString': '3.3',
        'CFBundleVersion': '3.3',
        'JetBrainsToolboxApp': '$homeMac/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/183.5256920/Android Studio 3.3.app',
      };
103
      final String jetbrainsPlistFilePath = fs.path.join(jetbrainsStudioInApplicationPlistFolder, 'Info.plist');
104
      when(plistUtils.parseFile(jetbrainsPlistFilePath)).thenReturn(jetbrainsInfoPlist);
105 106 107 108

      final String studioInApplicationPlistFolder = fs.path.join(fs.path.join(homeMac, 'Library', 'Application Support'), 'JetBrains', 'Toolbox', 'apps', 'AndroidStudio', 'ch-0', '183.5256920', fs.path.join('Android Studio 3.3.app', 'Contents'));
      fs.directory(studioInApplicationPlistFolder).createSync(recursive: true);
      final String studioPlistFilePath = fs.path.join(studioInApplicationPlistFolder, 'Info.plist');
109
      when(plistUtils.parseFile(studioPlistFilePath)).thenReturn(macStudioInfoPlist);
110 111 112 113 114 115 116 117 118 119

      final AndroidStudio studio = AndroidStudio.fromMacOSBundle(fs.directory(jetbrainsStudioInApplicationPlistFolder)?.parent?.path);
      expect(studio, isNotNull);
      expect(studio.pluginsPath,
          equals(fs.path.join(homeMac, 'Library', 'Application Support', 'AndroidStudio3.3')));
    }, overrides: <Type, Generator>{
      FileSystem: () => fs,
      // Custom home paths are not supported on macOS nor Windows yet,
      // so we force the platform to fake Linux here.
      Platform: () => macPlatform(),
120
      PlistParser: () => plistUtils,
121 122 123
    });

  });
124
}