Unverified Commit 2cd768b8 authored by Andrew Kolos's avatar Andrew Kolos Committed by GitHub

[flutter_tools] Reorganize android_studio_test.dart (#124834)

[flutter_tools] Reorganize android_studio_test.dart
parent fd7d2d27
...@@ -15,10 +15,12 @@ import '../../src/common.dart'; ...@@ -15,10 +15,12 @@ import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
import '../../src/fake_process_manager.dart'; import '../../src/fake_process_manager.dart';
const String homeLinux = '/home/me'; void main() {
const String homeMac = '/Users/me';
group('installation detection on MacOS', () {
const String homeMac = '/Users/me';
const Map<String, Object> macStudioInfoPlist = <String, Object>{ const Map<String, Object> macStudioInfoPlist3_3 = <String, Object>{
'CFBundleGetInfoString': 'Android Studio 3.3, build AI-182.5107.16.33.5199772. Copyright JetBrains s.r.o., (c) 2000-2018', 'CFBundleGetInfoString': 'Android Studio 3.3, build AI-182.5107.16.33.5199772. Copyright JetBrains s.r.o., (c) 2000-2018',
'CFBundleShortVersionString': '3.3', 'CFBundleShortVersionString': '3.3',
'CFBundleVersion': 'AI-182.5107.16.33.5199772', 'CFBundleVersion': 'AI-182.5107.16.33.5199772',
...@@ -28,9 +30,9 @@ const Map<String, Object> macStudioInfoPlist = <String, Object>{ ...@@ -28,9 +30,9 @@ const Map<String, Object> macStudioInfoPlist = <String, Object>{
'idea.platform.prefix': 'AndroidStudio', 'idea.platform.prefix': 'AndroidStudio',
}, },
}, },
}; };
const Map<String, Object> macStudioInfoPlist4_1 = <String, Object>{ const Map<String, Object> macStudioInfoPlist4_1 = <String, Object>{
'CFBundleGetInfoString': 'Android Studio 4.1, build AI-201.8743.12.41.6858069. Copyright JetBrains s.r.o., (c) 2000-2020', 'CFBundleGetInfoString': 'Android Studio 4.1, build AI-201.8743.12.41.6858069. Copyright JetBrains s.r.o., (c) 2000-2020',
'CFBundleShortVersionString': '4.1', 'CFBundleShortVersionString': '4.1',
'CFBundleVersion': 'AI-201.8743.12.41.6858069', 'CFBundleVersion': 'AI-201.8743.12.41.6858069',
...@@ -41,9 +43,9 @@ const Map<String, Object> macStudioInfoPlist4_1 = <String, Object>{ ...@@ -41,9 +43,9 @@ const Map<String, Object> macStudioInfoPlist4_1 = <String, Object>{
'idea.platform.prefix': 'AndroidStudio', 'idea.platform.prefix': 'AndroidStudio',
}, },
}, },
}; };
const Map<String, Object> macStudioInfoPlist2020_3 = <String, Object>{ const Map<String, Object> macStudioInfoPlist2020_3 = <String, Object>{
'CFBundleGetInfoString': 'Android Studio 2020.3, build AI-203.7717.56.2031.7583922. Copyright JetBrains s.r.o., (c) 2000-2021', 'CFBundleGetInfoString': 'Android Studio 2020.3, build AI-203.7717.56.2031.7583922. Copyright JetBrains s.r.o., (c) 2000-2021',
'CFBundleShortVersionString': '2020.3', 'CFBundleShortVersionString': '2020.3',
'CFBundleVersion': 'AI-203.7717.56.2031.7583922', 'CFBundleVersion': 'AI-203.7717.56.2031.7583922',
...@@ -54,9 +56,9 @@ const Map<String, Object> macStudioInfoPlist2020_3 = <String, Object>{ ...@@ -54,9 +56,9 @@ const Map<String, Object> macStudioInfoPlist2020_3 = <String, Object>{
'idea.platform.prefix': 'AndroidStudio', 'idea.platform.prefix': 'AndroidStudio',
}, },
}, },
}; };
const Map<String, Object> macStudioInfoPlist2022_1 = <String, Object>{ const Map<String, Object> macStudioInfoPlist2022_1 = <String, Object>{
'CFBundleGetInfoString': 'Android Studio 2022.1, build AI-221.6008.13.2211.9477386. Copyright JetBrains s.r.o., (c) 2000-2023', 'CFBundleGetInfoString': 'Android Studio 2022.1, build AI-221.6008.13.2211.9477386. Copyright JetBrains s.r.o., (c) 2000-2023',
'CFBundleShortVersionString': '2022.1', 'CFBundleShortVersionString': '2022.1',
'CFBundleVersion': 'AI-221.6008.13.2211.9477386', 'CFBundleVersion': 'AI-221.6008.13.2211.9477386',
...@@ -67,9 +69,9 @@ const Map<String, Object> macStudioInfoPlist2022_1 = <String, Object>{ ...@@ -67,9 +69,9 @@ const Map<String, Object> macStudioInfoPlist2022_1 = <String, Object>{
'idea.platform.prefix': 'AndroidStudio', 'idea.platform.prefix': 'AndroidStudio',
}, },
}, },
}; };
const Map<String, Object> macStudioInfoPlistEAP = <String, Object>{ const Map<String, Object> macStudioInfoPlistEAP = <String, Object>{
'CFBundleGetInfoString': 'Android Studio EAP AI-212.5712.43.2112.8233820, build AI-212.5712.43.2112.8233820. Copyright JetBrains s.r.o., (c) 2000-2022', 'CFBundleGetInfoString': 'Android Studio EAP AI-212.5712.43.2112.8233820, build AI-212.5712.43.2112.8233820. Copyright JetBrains s.r.o., (c) 2000-2022',
'CFBundleShortVersionString': 'EAP AI-212.5712.43.2112.8233820', 'CFBundleShortVersionString': 'EAP AI-212.5712.43.2112.8233820',
'CFBundleVersion': 'AI-212.5712.43.2112.8233820', 'CFBundleVersion': 'AI-212.5712.43.2112.8233820',
...@@ -80,67 +82,21 @@ const Map<String, Object> macStudioInfoPlistEAP = <String, Object>{ ...@@ -80,67 +82,21 @@ const Map<String, Object> macStudioInfoPlistEAP = <String, Object>{
'idea.platform.prefix': 'AndroidStudio', 'idea.platform.prefix': 'AndroidStudio',
}, },
}, },
}; };
final Platform linuxPlatform = FakePlatform(
environment: <String, String>{'HOME': homeLinux},
);
final Platform windowsPlatform = FakePlatform(
operatingSystem: 'windows',
environment: <String, String>{
'LOCALAPPDATA': r'C:\Users\Dash\AppData\Local',
}
);
Platform macPlatform() {
return FakePlatform(
operatingSystem: 'macos',
environment: <String, String>{'HOME': homeMac},
);
}
void main() {
late FileSystem fileSystem; late FileSystem fileSystem;
setUp(() {
fileSystem = MemoryFileSystem.test();
});
testUsingContext('pluginsPath on Linux extracts custom paths from home dir', () {
const String installPath = '/opt/android-studio-with-cheese-5.0';
const String studioHome = '$homeLinux/.AndroidStudioWithCheese5.0';
const String homeFile = '$studioHome/system/.home';
globals.fs.directory(installPath).createSync(recursive: true);
globals.fs.file(homeFile).createSync(recursive: true);
globals.fs.file(homeFile).writeAsStringSync(installPath);
final AndroidStudio studio =
AndroidStudio.fromHomeDot(globals.fs.directory(studioHome))!;
expect(studio, isNotNull);
expect(studio.pluginsPath,
equals('/home/me/.AndroidStudioWithCheese5.0/config/plugins'));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
// Custom home paths are not supported on macOS nor Windows yet,
// so we force the platform to fake Linux here.
Platform: () => linuxPlatform,
FileSystemUtils: () => FileSystemUtils(
fileSystem: fileSystem,
platform: linuxPlatform,
),
});
group('pluginsPath on Mac', () {
late FileSystemUtils fsUtils; late FileSystemUtils fsUtils;
late Platform platform; late Platform platform;
late FakePlistUtils plistUtils; late FakePlistUtils plistUtils;
late FakeProcessManager processManager; late FakeProcessManager processManager;
setUp(() { setUp(() {
fileSystem = MemoryFileSystem.test();
plistUtils = FakePlistUtils(); plistUtils = FakePlistUtils();
platform = macPlatform(); platform = FakePlatform(
operatingSystem: 'macos',
environment: <String, String>{'HOME': homeMac},
);
fsUtils = FileSystemUtils( fsUtils = FileSystemUtils(
fileSystem: fileSystem, fileSystem: fileSystem,
platform: platform, platform: platform,
...@@ -148,7 +104,7 @@ void main() { ...@@ -148,7 +104,7 @@ void main() {
processManager = FakeProcessManager.empty(); processManager = FakeProcessManager.empty();
}); });
testUsingContext('Can discover Android Studio >=4.1 location on Mac', () { testUsingContext('discovers Android Studio >=4.1 location', () {
final String studioInApplicationPlistFolder = globals.fs.path.join( final String studioInApplicationPlistFolder = globals.fs.path.join(
'/', '/',
'Application', 'Application',
...@@ -190,7 +146,7 @@ void main() { ...@@ -190,7 +146,7 @@ void main() {
PlistParser: () => plistUtils, PlistParser: () => plistUtils,
}); });
testUsingContext('Can discover Android Studio >=2020.3 location on Mac', () { testUsingContext('discovers Android Studio >=2020.3 location', () {
final String studioInApplicationPlistFolder = globals.fs.path.join( final String studioInApplicationPlistFolder = globals.fs.path.join(
'/', '/',
'Application', 'Application',
...@@ -232,7 +188,7 @@ void main() { ...@@ -232,7 +188,7 @@ void main() {
PlistParser: () => plistUtils, PlistParser: () => plistUtils,
}); });
testUsingContext('Can discover Android Studio <4.1 location on Mac', () { testUsingContext('discovers Android Studio <4.1 location', () {
final String studioInApplicationPlistFolder = globals.fs.path.join( final String studioInApplicationPlistFolder = globals.fs.path.join(
'/', '/',
'Application', 'Application',
...@@ -242,7 +198,7 @@ void main() { ...@@ -242,7 +198,7 @@ void main() {
globals.fs.directory(studioInApplicationPlistFolder).createSync(recursive: true); globals.fs.directory(studioInApplicationPlistFolder).createSync(recursive: true);
final String plistFilePath = globals.fs.path.join(studioInApplicationPlistFolder, 'Info.plist'); final String plistFilePath = globals.fs.path.join(studioInApplicationPlistFolder, 'Info.plist');
plistUtils.fileContents[plistFilePath] = macStudioInfoPlist; plistUtils.fileContents[plistFilePath] = macStudioInfoPlist3_3;
processManager.addCommand(FakeCommand( processManager.addCommand(FakeCommand(
command: <String>[ command: <String>[
globals.fs.path.join(studioInApplicationPlistFolder, 'jre', 'jdk', 'Contents', 'Home', 'bin', 'java'), globals.fs.path.join(studioInApplicationPlistFolder, 'jre', 'jdk', 'Contents', 'Home', 'bin', 'java'),
...@@ -273,7 +229,7 @@ void main() { ...@@ -273,7 +229,7 @@ void main() {
PlistParser: () => plistUtils, PlistParser: () => plistUtils,
}); });
testUsingContext('Can discover Android Studio EAP location on Mac', () { testUsingContext('discovers Android Studio EAP location', () {
final String studioInApplicationPlistFolder = globals.fs.path.join( final String studioInApplicationPlistFolder = globals.fs.path.join(
'/', '/',
'Application', 'Application',
...@@ -314,7 +270,7 @@ void main() { ...@@ -314,7 +270,7 @@ void main() {
PlistParser: () => plistUtils, PlistParser: () => plistUtils,
}); });
testUsingContext('Does not discover Android Studio with JetBrainsToolboxApp wrapper', () { testUsingContext('does not discover Android Studio with JetBrainsToolboxApp wrapper', () {
final String applicationPlistFolder = globals.fs.path.join( final String applicationPlistFolder = globals.fs.path.join(
'/', '/',
'Applications', 'Applications',
...@@ -351,7 +307,7 @@ void main() { ...@@ -351,7 +307,7 @@ void main() {
PlistParser: () => plistUtils, PlistParser: () => plistUtils,
}); });
testUsingContext('Can discover installation from Spotlight query', () { testUsingContext('discovers installation from Spotlight query', () {
// One in expected location. // One in expected location.
final String studioInApplication = fileSystem.path.join( final String studioInApplication = fileSystem.path.join(
'/', '/',
...@@ -446,7 +402,7 @@ void main() { ...@@ -446,7 +402,7 @@ void main() {
globals.fs.directory(applicationPlistFolder).createSync(recursive: true); globals.fs.directory(applicationPlistFolder).createSync(recursive: true);
final String applicationsPlistFilePath = globals.fs.path.join(applicationPlistFolder, 'Info.plist'); final String applicationsPlistFilePath = globals.fs.path.join(applicationPlistFolder, 'Info.plist');
plistUtils.fileContents[applicationsPlistFilePath] = macStudioInfoPlist; plistUtils.fileContents[applicationsPlistFilePath] = macStudioInfoPlist3_3;
final String homeDirectoryPlistFolder = globals.fs.path.join( final String homeDirectoryPlistFolder = globals.fs.path.join(
globals.fsUtils.homeDirPath!, globals.fsUtils.homeDirPath!,
...@@ -469,7 +425,7 @@ void main() { ...@@ -469,7 +425,7 @@ void main() {
PlistParser: () => plistUtils, PlistParser: () => plistUtils,
}); });
testUsingContext('extracts custom paths for directly downloaded Android Studio on Mac', () { testUsingContext('extracts custom paths for directly downloaded Android Studio', () {
final String studioInApplicationPlistFolder = globals.fs.path.join( final String studioInApplicationPlistFolder = globals.fs.path.join(
'/', '/',
'Application', 'Application',
...@@ -479,7 +435,7 @@ void main() { ...@@ -479,7 +435,7 @@ void main() {
globals.fs.directory(studioInApplicationPlistFolder).createSync(recursive: true); globals.fs.directory(studioInApplicationPlistFolder).createSync(recursive: true);
final String plistFilePath = globals.fs.path.join(studioInApplicationPlistFolder, 'Info.plist'); final String plistFilePath = globals.fs.path.join(studioInApplicationPlistFolder, 'Info.plist');
plistUtils.fileContents[plistFilePath] = macStudioInfoPlist; plistUtils.fileContents[plistFilePath] = macStudioInfoPlist3_3;
final AndroidStudio studio = AndroidStudio.fromMacOSBundle( final AndroidStudio studio = AndroidStudio.fromMacOSBundle(
globals.fs.directory(studioInApplicationPlistFolder).parent.path, globals.fs.directory(studioInApplicationPlistFolder).parent.path,
)!; )!;
...@@ -500,7 +456,7 @@ void main() { ...@@ -500,7 +456,7 @@ void main() {
PlistParser: () => plistUtils, PlistParser: () => plistUtils,
}); });
testUsingContext('Can find Android Studio 2020.3 bundled Java version on Mac', () { testUsingContext('finds Android Studio 2020.3 bundled Java version', () {
final String studioInApplicationPlistFolder = globals.fs.path.join( final String studioInApplicationPlistFolder = globals.fs.path.join(
'/', '/',
'Application', 'Application',
...@@ -539,7 +495,7 @@ void main() { ...@@ -539,7 +495,7 @@ void main() {
PlistParser: () => plistUtils, PlistParser: () => plistUtils,
}); });
testUsingContext('Can find Android Studio 2022.1 bundled Java version on Mac', () { testUsingContext('finds Android Studio 2022.1 bundled Java version', () {
final String studioInApplicationPlistFolder = globals.fs.path.join( final String studioInApplicationPlistFolder = globals.fs.path.join(
'/', '/',
'Application', 'Application',
...@@ -579,17 +535,25 @@ void main() { ...@@ -579,17 +535,25 @@ void main() {
}); });
}); });
late FileSystem windowsFileSystem; group('installation detection on Windows', () {
late Platform platform;
late FileSystem fileSystem;
setUp(() { setUp(() {
windowsFileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows); platform = FakePlatform(
operatingSystem: 'windows',
environment: <String, String>{
'LOCALAPPDATA': r'C:\Users\Dash\AppData\Local',
}
);
fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows);
}); });
testUsingContext('Can discover Android Studio 4.1 location on Windows', () { testUsingContext('discovers Android Studio 4.1 location', () {
windowsFileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio4.1\.home') fileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio4.1\.home')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(r'C:\Program Files\AndroidStudio'); ..writeAsStringSync(r'C:\Program Files\AndroidStudio');
windowsFileSystem.directory(r'C:\Program Files\AndroidStudio') fileSystem.directory(r'C:\Program Files\AndroidStudio')
.createSync(recursive: true); .createSync(recursive: true);
final AndroidStudio studio = AndroidStudio.allInstalled().single; final AndroidStudio studio = AndroidStudio.allInstalled().single;
...@@ -597,16 +561,16 @@ void main() { ...@@ -597,16 +561,16 @@ void main() {
expect(studio.version, Version(4, 1, 0)); expect(studio.version, Version(4, 1, 0));
expect(studio.studioAppName, 'Android Studio'); expect(studio.studioAppName, 'Android Studio');
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => windowsPlatform, Platform: () => platform,
FileSystem: () => windowsFileSystem, FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Can discover Android Studio 4.2 location on Windows', () { testUsingContext('discovers Android Studio 4.2 location', () {
windowsFileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio4.2\.home') fileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio4.2\.home')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(r'C:\Program Files\AndroidStudio'); ..writeAsStringSync(r'C:\Program Files\AndroidStudio');
windowsFileSystem.directory(r'C:\Program Files\AndroidStudio') fileSystem.directory(r'C:\Program Files\AndroidStudio')
.createSync(recursive: true); .createSync(recursive: true);
final AndroidStudio studio = AndroidStudio.allInstalled().single; final AndroidStudio studio = AndroidStudio.allInstalled().single;
...@@ -614,16 +578,16 @@ void main() { ...@@ -614,16 +578,16 @@ void main() {
expect(studio.version, Version(4, 2, 0)); expect(studio.version, Version(4, 2, 0));
expect(studio.studioAppName, 'Android Studio'); expect(studio.studioAppName, 'Android Studio');
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => windowsPlatform, Platform: () => platform,
FileSystem: () => windowsFileSystem, FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Can discover Android Studio 2020.3 location on Windows', () { testUsingContext('discovers Android Studio 2020.3 location', () {
windowsFileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio2020.3\.home') fileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio2020.3\.home')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(r'C:\Program Files\AndroidStudio'); ..writeAsStringSync(r'C:\Program Files\AndroidStudio');
windowsFileSystem.directory(r'C:\Program Files\AndroidStudio') fileSystem.directory(r'C:\Program Files\AndroidStudio')
.createSync(recursive: true); .createSync(recursive: true);
final AndroidStudio studio = AndroidStudio.allInstalled().single; final AndroidStudio studio = AndroidStudio.allInstalled().single;
...@@ -631,16 +595,16 @@ void main() { ...@@ -631,16 +595,16 @@ void main() {
expect(studio.version, Version(2020, 3, 0)); expect(studio.version, Version(2020, 3, 0));
expect(studio.studioAppName, 'Android Studio'); expect(studio.studioAppName, 'Android Studio');
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => windowsPlatform, Platform: () => platform,
FileSystem: () => windowsFileSystem, FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Does not discover Android Studio 4.1 location on Windows if LOCALAPPDATA is null', () { testUsingContext('does not discover Android Studio 4.1 location if LOCALAPPDATA is null', () {
windowsFileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio4.1\.home') fileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio4.1\.home')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(r'C:\Program Files\AndroidStudio'); ..writeAsStringSync(r'C:\Program Files\AndroidStudio');
windowsFileSystem.directory(r'C:\Program Files\AndroidStudio') fileSystem.directory(r'C:\Program Files\AndroidStudio')
.createSync(recursive: true); .createSync(recursive: true);
expect(AndroidStudio.allInstalled(), isEmpty); expect(AndroidStudio.allInstalled(), isEmpty);
...@@ -649,15 +613,15 @@ void main() { ...@@ -649,15 +613,15 @@ void main() {
operatingSystem: 'windows', operatingSystem: 'windows',
environment: <String, String>{}, // Does not include LOCALAPPDATA environment: <String, String>{}, // Does not include LOCALAPPDATA
), ),
FileSystem: () => windowsFileSystem, FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Does not discover Android Studio 4.2 location on Windows if LOCALAPPDATA is null', () { testUsingContext('does not discover Android Studio 4.2 location if LOCALAPPDATA is null', () {
windowsFileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio4.2\.home') fileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio4.2\.home')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(r'C:\Program Files\AndroidStudio'); ..writeAsStringSync(r'C:\Program Files\AndroidStudio');
windowsFileSystem.directory(r'C:\Program Files\AndroidStudio') fileSystem.directory(r'C:\Program Files\AndroidStudio')
.createSync(recursive: true); .createSync(recursive: true);
expect(AndroidStudio.allInstalled(), isEmpty); expect(AndroidStudio.allInstalled(), isEmpty);
...@@ -666,15 +630,15 @@ void main() { ...@@ -666,15 +630,15 @@ void main() {
operatingSystem: 'windows', operatingSystem: 'windows',
environment: <String, String>{}, // Does not include LOCALAPPDATA environment: <String, String>{}, // Does not include LOCALAPPDATA
), ),
FileSystem: () => windowsFileSystem, FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Does not discover Android Studio 2020.3 location on Windows if LOCALAPPDATA is null', () { testUsingContext('does not discover Android Studio 2020.3 location if LOCALAPPDATA is null', () {
windowsFileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio2020.3\.home') fileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio2020.3\.home')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(r'C:\Program Files\AndroidStudio'); ..writeAsStringSync(r'C:\Program Files\AndroidStudio');
windowsFileSystem.directory(r'C:\Program Files\AndroidStudio') fileSystem.directory(r'C:\Program Files\AndroidStudio')
.createSync(recursive: true); .createSync(recursive: true);
expect(AndroidStudio.allInstalled(), isEmpty); expect(AndroidStudio.allInstalled(), isEmpty);
...@@ -683,53 +647,62 @@ void main() { ...@@ -683,53 +647,62 @@ void main() {
operatingSystem: 'windows', operatingSystem: 'windows',
environment: <String, String>{}, // Does not include LOCALAPPDATA environment: <String, String>{}, // Does not include LOCALAPPDATA
), ),
FileSystem: () => windowsFileSystem, FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Can find Android Studio 2020.3 bundled Java version on Windows', () { testUsingContext('finds Android Studio 2020.3 bundled Java version', () {
windowsFileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio2020.3\.home') fileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio2020.3\.home')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(r'C:\Program Files\AndroidStudio'); ..writeAsStringSync(r'C:\Program Files\AndroidStudio');
windowsFileSystem.directory(r'C:\Program Files\AndroidStudio') fileSystem.directory(r'C:\Program Files\AndroidStudio')
.createSync(recursive: true); .createSync(recursive: true);
final AndroidStudio studio = AndroidStudio.allInstalled().single; final AndroidStudio studio = AndroidStudio.allInstalled().single;
expect(studio.javaPath, equals(r'C:\Program Files\AndroidStudio\jre')); expect(studio.javaPath, equals(r'C:\Program Files\AndroidStudio\jre'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => windowsPlatform, Platform: () => platform,
FileSystem: () => windowsFileSystem, FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Can find Android Studio 2022.1 bundled Java version on Windows', () { testUsingContext('finds Android Studio 2022.1 bundled Java version', () {
windowsFileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio2022.1\.home') fileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio2022.1\.home')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(r'C:\Program Files\AndroidStudio'); ..writeAsStringSync(r'C:\Program Files\AndroidStudio');
windowsFileSystem.directory(r'C:\Program Files\AndroidStudio') fileSystem.directory(r'C:\Program Files\AndroidStudio')
.createSync(recursive: true); .createSync(recursive: true);
final AndroidStudio studio = AndroidStudio.allInstalled().single; final AndroidStudio studio = AndroidStudio.allInstalled().single;
expect(studio.javaPath, equals(r'C:\Program Files\AndroidStudio\jbr')); expect(studio.javaPath, equals(r'C:\Program Files\AndroidStudio\jbr'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => windowsPlatform, Platform: () => platform,
FileSystem: () => windowsFileSystem, FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
});
group('Installation detection on Linux', () { group('installation detection on Linux', () {
const String homeLinux = '/home/me';
late FileSystem fileSystem;
late FileSystemUtils fsUtils; late FileSystemUtils fsUtils;
late Platform platform;
setUp(() { setUp(() {
platform = FakePlatform(
environment: <String, String>{'HOME': homeLinux},
);
fileSystem = MemoryFileSystem.test();
fsUtils = FileSystemUtils( fsUtils = FileSystemUtils(
fileSystem: fileSystem, fileSystem: fileSystem,
platform: linuxPlatform, platform: platform,
); );
}); });
testUsingContext('Discover Android Studio <4.1', () { testUsingContext('discovers Android Studio <4.1', () {
const String studioHomeFilePath = const String studioHomeFilePath =
'$homeLinux/.AndroidStudio4.0/system/.home'; '$homeLinux/.AndroidStudio4.0/system/.home';
const String studioInstallPath = '$homeLinux/AndroidStudio'; const String studioInstallPath = '$homeLinux/AndroidStudio';
...@@ -751,11 +724,11 @@ void main() { ...@@ -751,11 +724,11 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
FileSystemUtils: () => fsUtils, FileSystemUtils: () => fsUtils,
Platform: () => linuxPlatform, Platform: () => platform,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Discover Android Studio >=4.1', () { testUsingContext('discovers Android Studio >=4.1', () {
const String studioHomeFilePath = const String studioHomeFilePath =
'$homeLinux/.cache/Google/AndroidStudio4.1/.home'; '$homeLinux/.cache/Google/AndroidStudio4.1/.home';
const String studioInstallPath = '$homeLinux/AndroidStudio'; const String studioInstallPath = '$homeLinux/AndroidStudio';
...@@ -777,11 +750,11 @@ void main() { ...@@ -777,11 +750,11 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
FileSystemUtils: () => fsUtils, FileSystemUtils: () => fsUtils,
Platform: () => linuxPlatform, Platform: () => platform,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Discover when installed with Toolbox', () { testUsingContext('discovers when installed with Toolbox', () {
const String studioHomeFilePath = const String studioHomeFilePath =
'$homeLinux/.cache/Google/AndroidStudio4.1/.home'; '$homeLinux/.cache/Google/AndroidStudio4.1/.home';
const String studioInstallPath = const String studioInstallPath =
...@@ -806,11 +779,11 @@ void main() { ...@@ -806,11 +779,11 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
FileSystemUtils: () => fsUtils, FileSystemUtils: () => fsUtils,
Platform: () => linuxPlatform, Platform: () => platform,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Can find Android Studio 2020.3 bundled Java version on Linux', () { testUsingContext('finds Android Studio 2020.3 bundled Java version', () {
const String studioHomeFilePath = '$homeLinux/.cache/Google/AndroidStudio2020.3/.home'; const String studioHomeFilePath = '$homeLinux/.cache/Google/AndroidStudio2020.3/.home';
const String studioInstallPath = '$homeLinux/AndroidStudio'; const String studioInstallPath = '$homeLinux/AndroidStudio';
...@@ -826,11 +799,11 @@ void main() { ...@@ -826,11 +799,11 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
FileSystemUtils: () => fsUtils, FileSystemUtils: () => fsUtils,
Platform: () => linuxPlatform, Platform: () => platform,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Can find Android Studio 2022.1 bundled Java version on Linux', () { testUsingContext('finds Android Studio 2022.1 bundled Java version', () {
const String studioHomeFilePath = const String studioHomeFilePath =
'$homeLinux/.cache/Google/AndroidStudio2022.1/.home'; '$homeLinux/.cache/Google/AndroidStudio2022.1/.home';
const String studioInstallPath = '$homeLinux/AndroidStudio'; const String studioInstallPath = '$homeLinux/AndroidStudio';
...@@ -847,9 +820,34 @@ void main() { ...@@ -847,9 +820,34 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
FileSystemUtils: () => fsUtils, FileSystemUtils: () => fsUtils,
Platform: () => linuxPlatform, Platform: () => platform,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('pluginsPath extracts custom paths from home dir', () {
const String installPath = '/opt/android-studio-with-cheese-5.0';
const String studioHome = '$homeLinux/.AndroidStudioWithCheese5.0';
const String homeFile = '$studioHome/system/.home';
globals.fs.directory(installPath).createSync(recursive: true);
globals.fs.file(homeFile).createSync(recursive: true);
globals.fs.file(homeFile).writeAsStringSync(installPath);
final AndroidStudio studio =
AndroidStudio.fromHomeDot(globals.fs.directory(studioHome))!;
expect(studio, isNotNull);
expect(studio.pluginsPath,
equals('/home/me/.AndroidStudioWithCheese5.0/config/plugins'));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
// Custom home paths are not supported on macOS nor Windows yet,
// so we force the platform to fake Linux here.
Platform: () => platform,
FileSystemUtils: () => FileSystemUtils(
fileSystem: fileSystem,
platform: platform,
),
});
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment