mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] remove all mocks from plugins_test (#81485)
This commit is contained in:
parent
82830fa1a0
commit
8041a2e5d5
@ -22,7 +22,7 @@ import 'package:flutter_tools/src/plugins.dart';
|
|||||||
import 'package:flutter_tools/src/project.dart';
|
import 'package:flutter_tools/src/project.dart';
|
||||||
import 'package:flutter_tools/src/version.dart';
|
import 'package:flutter_tools/src/version.dart';
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
import 'package:mockito/mockito.dart';
|
import 'package:test/fake.dart';
|
||||||
import 'package:yaml/yaml.dart';
|
import 'package:yaml/yaml.dart';
|
||||||
|
|
||||||
import '../src/common.dart';
|
import '../src/common.dart';
|
||||||
@ -33,14 +33,14 @@ import '../src/pubspec_schema.dart';
|
|||||||
void main() {
|
void main() {
|
||||||
group('plugins', () {
|
group('plugins', () {
|
||||||
FileSystem fs;
|
FileSystem fs;
|
||||||
MockFlutterProject flutterProject;
|
FakeFlutterProject flutterProject;
|
||||||
MockFlutterManifest flutterManifest;
|
FakeFlutterManifest flutterManifest;
|
||||||
MockIosProject iosProject;
|
FakeIosProject iosProject;
|
||||||
MockMacOSProject macosProject;
|
FakeMacOSProject macosProject;
|
||||||
MockAndroidProject androidProject;
|
FakeAndroidProject androidProject;
|
||||||
MockWebProject webProject;
|
FakeWebProject webProject;
|
||||||
MockWindowsProject windowsProject;
|
FakeWindowsProject windowsProject;
|
||||||
MockLinuxProject linuxProject;
|
FakeLinuxProject linuxProject;
|
||||||
FakeSystemClock systemClock;
|
FakeSystemClock systemClock;
|
||||||
FlutterVersion flutterVersion;
|
FlutterVersion flutterVersion;
|
||||||
// A Windows-style filesystem. This is not populated by default, so tests
|
// A Windows-style filesystem. This is not populated by default, so tests
|
||||||
@ -50,73 +50,69 @@ void main() {
|
|||||||
|
|
||||||
// Adds basic properties to the flutterProject and its subprojects.
|
// Adds basic properties to the flutterProject and its subprojects.
|
||||||
void setUpProject(FileSystem fileSystem) {
|
void setUpProject(FileSystem fileSystem) {
|
||||||
flutterProject = MockFlutterProject();
|
flutterProject = FakeFlutterProject();
|
||||||
|
flutterManifest = FakeFlutterManifest();
|
||||||
|
|
||||||
flutterManifest = MockFlutterManifest();
|
flutterProject
|
||||||
when(flutterManifest.dependencies).thenReturn(<String>{});
|
..manifest = flutterManifest
|
||||||
|
..directory = fileSystem.systemTempDirectory.childDirectory('app')
|
||||||
|
..flutterPluginsFile = flutterProject.directory.childFile('.flutter-plugins')
|
||||||
|
..flutterPluginsDependenciesFile = flutterProject.directory.childFile('.flutter-plugins-dependencies');
|
||||||
|
|
||||||
when(flutterProject.manifest).thenReturn(flutterManifest);
|
iosProject = FakeIosProject();
|
||||||
|
flutterProject.ios = iosProject;
|
||||||
when(flutterProject.directory).thenReturn(fileSystem.systemTempDirectory.childDirectory('app'));
|
|
||||||
// TODO(franciscojma): Remove logic for .flutter-plugins once it's deprecated.
|
|
||||||
when(flutterProject.flutterPluginsFile).thenReturn(flutterProject.directory.childFile('.flutter-plugins'));
|
|
||||||
when(flutterProject.flutterPluginsDependenciesFile).thenReturn(flutterProject.directory.childFile('.flutter-plugins-dependencies'));
|
|
||||||
|
|
||||||
iosProject = MockIosProject();
|
|
||||||
when(flutterProject.ios).thenReturn(iosProject);
|
|
||||||
final Directory iosDirectory = flutterProject.directory.childDirectory('ios');
|
final Directory iosDirectory = flutterProject.directory.childDirectory('ios');
|
||||||
when(iosProject.pluginRegistrantHost).thenReturn(flutterProject.directory.childDirectory('Runner'));
|
iosProject
|
||||||
when(iosProject.podfile).thenReturn(iosDirectory.childFile('Podfile'));
|
..pluginRegistrantHost = flutterProject.directory.childDirectory('Runner')
|
||||||
when(iosProject.podManifestLock).thenReturn(iosDirectory.childFile('Podfile.lock'));
|
..podfile = iosDirectory.childFile('Podfile')
|
||||||
when(iosProject.pluginConfigKey).thenReturn('ios');
|
..podManifestLock = iosDirectory.childFile('Podfile.lock')
|
||||||
when(iosProject.existsSync()).thenReturn(false);
|
..testExists = false;
|
||||||
|
|
||||||
macosProject = MockMacOSProject();
|
macosProject = FakeMacOSProject();
|
||||||
when(flutterProject.macos).thenReturn(macosProject);
|
flutterProject.macos = macosProject;
|
||||||
final Directory macosDirectory = flutterProject.directory.childDirectory('macos');
|
final Directory macosDirectory = flutterProject.directory.childDirectory('macos');
|
||||||
when(macosProject.podfile).thenReturn(macosDirectory.childFile('Podfile'));
|
|
||||||
when(macosProject.podManifestLock).thenReturn(macosDirectory.childFile('Podfile.lock'));
|
|
||||||
final Directory macosManagedDirectory = macosDirectory.childDirectory('Flutter');
|
final Directory macosManagedDirectory = macosDirectory.childDirectory('Flutter');
|
||||||
when(macosProject.managedDirectory).thenReturn(macosManagedDirectory);
|
macosProject
|
||||||
when(macosProject.pluginConfigKey).thenReturn('macos');
|
..podfile = macosDirectory.childFile('Podfile')
|
||||||
when(macosProject.existsSync()).thenReturn(false);
|
..podManifestLock = macosDirectory.childFile('Podfile.lock')
|
||||||
|
..managedDirectory = macosManagedDirectory
|
||||||
|
..exists = false;
|
||||||
|
|
||||||
androidProject = MockAndroidProject();
|
androidProject = FakeAndroidProject();
|
||||||
when(flutterProject.android).thenReturn(androidProject);
|
flutterProject.android = androidProject;
|
||||||
final Directory androidDirectory = flutterProject.directory.childDirectory('android');
|
final Directory androidDirectory = flutterProject.directory.childDirectory('android');
|
||||||
when(androidProject.pluginRegistrantHost).thenReturn(androidDirectory.childDirectory('app'));
|
androidProject
|
||||||
when(androidProject.hostAppGradleRoot).thenReturn(androidDirectory);
|
..pluginRegistrantHost = androidDirectory.childDirectory('app')
|
||||||
when(androidProject.pluginConfigKey).thenReturn('android');
|
..hostAppGradleRoot = androidDirectory
|
||||||
when(androidProject.existsSync()).thenReturn(false);
|
..exists = false;
|
||||||
|
|
||||||
webProject = MockWebProject();
|
webProject = FakeWebProject();
|
||||||
when(flutterProject.web).thenReturn(webProject);
|
flutterProject.web = webProject;
|
||||||
when(webProject.libDirectory).thenReturn(flutterProject.directory.childDirectory('lib'));
|
webProject
|
||||||
when(webProject.existsSync()).thenReturn(true);
|
..libDirectory = flutterProject.directory.childDirectory('lib')
|
||||||
when(webProject.pluginConfigKey).thenReturn('web');
|
..exists = false;
|
||||||
when(webProject.existsSync()).thenReturn(false);
|
|
||||||
|
|
||||||
windowsProject = MockWindowsProject();
|
windowsProject = FakeWindowsProject();
|
||||||
when(flutterProject.windows).thenReturn(windowsProject);
|
flutterProject.windows = windowsProject;
|
||||||
when(windowsProject.pluginConfigKey).thenReturn('windows');
|
|
||||||
final Directory windowsManagedDirectory = flutterProject.directory.childDirectory('windows').childDirectory('flutter');
|
final Directory windowsManagedDirectory = flutterProject.directory.childDirectory('windows').childDirectory('flutter');
|
||||||
when(windowsProject.managedDirectory).thenReturn(windowsManagedDirectory);
|
windowsProject
|
||||||
when(windowsProject.cmakeFile).thenReturn(windowsManagedDirectory.parent.childFile('CMakeLists.txt'));
|
..managedDirectory = windowsManagedDirectory
|
||||||
when(windowsProject.generatedPluginCmakeFile).thenReturn(windowsManagedDirectory.childFile('generated_plugins.mk'));
|
..cmakeFile = windowsManagedDirectory.parent.childFile('CMakeLists.txt')
|
||||||
when(windowsProject.pluginSymlinkDirectory).thenReturn(windowsManagedDirectory.childDirectory('ephemeral').childDirectory('.plugin_symlinks'));
|
..generatedPluginCmakeFile = windowsManagedDirectory.childFile('generated_plugins.mk')
|
||||||
when(windowsProject.existsSync()).thenReturn(false);
|
..pluginSymlinkDirectory = windowsManagedDirectory.childDirectory('ephemeral').childDirectory('.plugin_symlinks')
|
||||||
|
..exists = false;
|
||||||
|
|
||||||
linuxProject = MockLinuxProject();
|
linuxProject = FakeLinuxProject();
|
||||||
when(flutterProject.linux).thenReturn(linuxProject);
|
flutterProject.linux = linuxProject;
|
||||||
when(linuxProject.pluginConfigKey).thenReturn('linux');
|
|
||||||
final Directory linuxManagedDirectory = flutterProject.directory.childDirectory('linux').childDirectory('flutter');
|
final Directory linuxManagedDirectory = flutterProject.directory.childDirectory('linux').childDirectory('flutter');
|
||||||
final Directory linuxEphemeralDirectory = linuxManagedDirectory.childDirectory('ephemeral');
|
final Directory linuxEphemeralDirectory = linuxManagedDirectory.childDirectory('ephemeral');
|
||||||
when(linuxProject.managedDirectory).thenReturn(linuxManagedDirectory);
|
linuxProject
|
||||||
when(linuxProject.ephemeralDirectory).thenReturn(linuxEphemeralDirectory);
|
..managedDirectory = linuxManagedDirectory
|
||||||
when(linuxProject.pluginSymlinkDirectory).thenReturn(linuxEphemeralDirectory.childDirectory('.plugin_symlinks'));
|
..ephemeralDirectory = linuxEphemeralDirectory
|
||||||
when(linuxProject.cmakeFile).thenReturn(linuxManagedDirectory.parent.childFile('CMakeLists.txt'));
|
..pluginSymlinkDirectory = linuxEphemeralDirectory.childDirectory('.plugin_symlinks')
|
||||||
when(linuxProject.generatedPluginCmakeFile).thenReturn(linuxManagedDirectory.childFile('generated_plugins.mk'));
|
..cmakeFile = linuxManagedDirectory.parent.childFile('CMakeLists.txt')
|
||||||
when(linuxProject.existsSync()).thenReturn(false);
|
..generatedPluginCmakeFile = linuxManagedDirectory.childFile('generated_plugins.mk')
|
||||||
|
..exists = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
@ -404,7 +400,7 @@ dependencies:
|
|||||||
'/local_plugins/plugin_b'
|
'/local_plugins/plugin_b'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
when(iosProject.existsSync()).thenReturn(true);
|
iosProject.testExists = true;
|
||||||
|
|
||||||
await refreshPluginsList(flutterProject);
|
await refreshPluginsList(flutterProject);
|
||||||
|
|
||||||
@ -426,7 +422,7 @@ dependencies:
|
|||||||
final Directory pluginA = createPluginWithDependencies(name: 'plugin-a', dependencies: const <String>['plugin-b', 'plugin-c', 'random-package']);
|
final Directory pluginA = createPluginWithDependencies(name: 'plugin-a', dependencies: const <String>['plugin-b', 'plugin-c', 'random-package']);
|
||||||
final Directory pluginB = createPluginWithDependencies(name: 'plugin-b', dependencies: const <String>['plugin-c']);
|
final Directory pluginB = createPluginWithDependencies(name: 'plugin-b', dependencies: const <String>['plugin-c']);
|
||||||
final Directory pluginC = createPluginWithDependencies(name: 'plugin-c', dependencies: const <String>[]);
|
final Directory pluginC = createPluginWithDependencies(name: 'plugin-c', dependencies: const <String>[]);
|
||||||
when(iosProject.existsSync()).thenReturn(true);
|
iosProject.testExists = true;
|
||||||
|
|
||||||
final DateTime dateCreated = DateTime(1970, 1, 1);
|
final DateTime dateCreated = DateTime(1970, 1, 1);
|
||||||
systemClock.currentTime = dateCreated;
|
systemClock.currentTime = dateCreated;
|
||||||
@ -522,8 +518,8 @@ dependencies:
|
|||||||
simulatePodInstallRun(iosProject);
|
simulatePodInstallRun(iosProject);
|
||||||
simulatePodInstallRun(macosProject);
|
simulatePodInstallRun(macosProject);
|
||||||
createFakePlugin(fs);
|
createFakePlugin(fs);
|
||||||
when(iosProject.existsSync()).thenReturn(true);
|
iosProject.testExists = true;
|
||||||
when(macosProject.existsSync()).thenReturn(true);
|
macosProject.exists = true;
|
||||||
|
|
||||||
await refreshPluginsList(flutterProject, iosPlatform: true, macOSPlatform: true);
|
await refreshPluginsList(flutterProject, iosPlatform: true, macOSPlatform: true);
|
||||||
expect(iosProject.podManifestLock.existsSync(), false);
|
expect(iosProject.podManifestLock.existsSync(), false);
|
||||||
@ -537,8 +533,8 @@ dependencies:
|
|||||||
|
|
||||||
testUsingContext('No changes to the plugin list does not invalidate the Cocoapod lockfiles', () async {
|
testUsingContext('No changes to the plugin list does not invalidate the Cocoapod lockfiles', () async {
|
||||||
createFakePlugin(fs);
|
createFakePlugin(fs);
|
||||||
when(iosProject.existsSync()).thenReturn(true);
|
iosProject.testExists = true;
|
||||||
when(macosProject.existsSync()).thenReturn(true);
|
macosProject.exists = true;
|
||||||
|
|
||||||
// First call will create the .flutter-plugins-dependencies and the legacy .flutter-plugins file.
|
// First call will create the .flutter-plugins-dependencies and the legacy .flutter-plugins file.
|
||||||
// Since there was no plugins list, the lock files will be invalidated.
|
// Since there was no plugins list, the lock files will be invalidated.
|
||||||
@ -560,16 +556,14 @@ dependencies:
|
|||||||
});
|
});
|
||||||
|
|
||||||
group('injectPlugins', () {
|
group('injectPlugins', () {
|
||||||
MockXcodeProjectInterpreter xcodeProjectInterpreter;
|
FakeXcodeProjectInterpreter xcodeProjectInterpreter;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
xcodeProjectInterpreter = MockXcodeProjectInterpreter();
|
xcodeProjectInterpreter = FakeXcodeProjectInterpreter();
|
||||||
when(xcodeProjectInterpreter.isInstalled).thenReturn(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Registrant uses old embedding in app project', () async {
|
testUsingContext('Registrant uses old embedding in app project', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
androidProject.embeddingVersion = AndroidEmbeddingVersion.v1;
|
||||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v1);
|
|
||||||
|
|
||||||
await injectPlugins(flutterProject, androidPlatform: true);
|
await injectPlugins(flutterProject, androidPlatform: true);
|
||||||
|
|
||||||
@ -587,8 +581,7 @@ dependencies:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Registrant uses new embedding if app uses new embedding', () async {
|
testUsingContext('Registrant uses new embedding if app uses new embedding', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
|
||||||
|
|
||||||
await injectPlugins(flutterProject, androidPlatform: true);
|
await injectPlugins(flutterProject, androidPlatform: true);
|
||||||
|
|
||||||
@ -606,8 +599,7 @@ dependencies:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Registrant uses shim for plugins using old embedding if app uses new embedding', () async {
|
testUsingContext('Registrant uses shim for plugins using old embedding if app uses new embedding', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
|
||||||
|
|
||||||
createNewJavaPlugin1();
|
createNewJavaPlugin1();
|
||||||
createNewKotlinPlugin2();
|
createNewKotlinPlugin2();
|
||||||
@ -635,8 +627,7 @@ dependencies:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('exits the tool if an app uses the v1 embedding and a plugin only supports the v2 embedding', () async {
|
testUsingContext('exits the tool if an app uses the v1 embedding and a plugin only supports the v2 embedding', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
androidProject.embeddingVersion = AndroidEmbeddingVersion.v1;
|
||||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v1);
|
|
||||||
|
|
||||||
createNewJavaPlugin1();
|
createNewJavaPlugin1();
|
||||||
|
|
||||||
@ -657,8 +648,7 @@ dependencies:
|
|||||||
|
|
||||||
// Issue: https://github.com/flutter/flutter/issues/47803
|
// Issue: https://github.com/flutter/flutter/issues/47803
|
||||||
testUsingContext('exits the tool if a plugin sets an invalid android package in pubspec.yaml', () async {
|
testUsingContext('exits the tool if a plugin sets an invalid android package in pubspec.yaml', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
androidProject.embeddingVersion = AndroidEmbeddingVersion.v1;
|
||||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v1);
|
|
||||||
|
|
||||||
final Directory pluginDir = createPluginWithInvalidAndroidPackage();
|
final Directory pluginDir = createPluginWithInvalidAndroidPackage();
|
||||||
|
|
||||||
@ -682,8 +672,7 @@ dependencies:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('old embedding app uses a plugin that supports v1 and v2 embedding works', () async {
|
testUsingContext('old embedding app uses a plugin that supports v1 and v2 embedding works', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
androidProject.embeddingVersion = AndroidEmbeddingVersion.v1;
|
||||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v1);
|
|
||||||
|
|
||||||
createDualSupportJavaPlugin4();
|
createDualSupportJavaPlugin4();
|
||||||
|
|
||||||
@ -705,8 +694,7 @@ dependencies:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('new embedding app uses a plugin that supports v1 and v2 embedding', () async {
|
testUsingContext('new embedding app uses a plugin that supports v1 and v2 embedding', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
|
||||||
|
|
||||||
createDualSupportJavaPlugin4();
|
createDualSupportJavaPlugin4();
|
||||||
|
|
||||||
@ -728,8 +716,8 @@ dependencies:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Modules use new embedding', () async {
|
testUsingContext('Modules use new embedding', () async {
|
||||||
when(flutterProject.isModule).thenReturn(true);
|
flutterProject.isModule = true;
|
||||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||||
|
|
||||||
await injectPlugins(flutterProject, androidPlatform: true);
|
await injectPlugins(flutterProject, androidPlatform: true);
|
||||||
|
|
||||||
@ -747,8 +735,8 @@ dependencies:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Module using old plugin shows warning', () async {
|
testUsingContext('Module using old plugin shows warning', () async {
|
||||||
when(flutterProject.isModule).thenReturn(true);
|
flutterProject.isModule = true;
|
||||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||||
|
|
||||||
createOldJavaPlugin('plugin3');
|
createOldJavaPlugin('plugin3');
|
||||||
|
|
||||||
@ -767,8 +755,8 @@ dependencies:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Module using new plugin shows no warnings', () async {
|
testUsingContext('Module using new plugin shows no warnings', () async {
|
||||||
when(flutterProject.isModule).thenReturn(true);
|
flutterProject.isModule = true;
|
||||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||||
|
|
||||||
createNewJavaPlugin1();
|
createNewJavaPlugin1();
|
||||||
|
|
||||||
@ -788,8 +776,8 @@ dependencies:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Module using plugin with v1 and v2 support shows no warning', () async {
|
testUsingContext('Module using plugin with v1 and v2 support shows no warning', () async {
|
||||||
when(flutterProject.isModule).thenReturn(true);
|
flutterProject.isModule = true;
|
||||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||||
|
|
||||||
createDualSupportJavaPlugin4();
|
createDualSupportJavaPlugin4();
|
||||||
|
|
||||||
@ -809,8 +797,8 @@ dependencies:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Module using multiple old plugins all show warnings', () async {
|
testUsingContext('Module using multiple old plugins all show warnings', () async {
|
||||||
when(flutterProject.isModule).thenReturn(true);
|
flutterProject.isModule = true;
|
||||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||||
|
|
||||||
createOldJavaPlugin('plugin3');
|
createOldJavaPlugin('plugin3');
|
||||||
createOldJavaPlugin('plugin4');
|
createOldJavaPlugin('plugin4');
|
||||||
@ -833,8 +821,8 @@ dependencies:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Module using multiple old and new plugins should be wrapped with try catch', () async {
|
testUsingContext('Module using multiple old and new plugins should be wrapped with try catch', () async {
|
||||||
when(flutterProject.isModule).thenReturn(true);
|
flutterProject.isModule = true;
|
||||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||||
|
|
||||||
createOldJavaPlugin('abcplugin1');
|
createOldJavaPlugin('abcplugin1');
|
||||||
createNewJavaPlugin1();
|
createNewJavaPlugin1();
|
||||||
@ -859,20 +847,17 @@ dependencies:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Does not throw when AndroidManifest.xml is not found', () async {
|
testUsingContext('Does not throw when AndroidManifest.xml is not found', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
|
||||||
|
|
||||||
final File manifest = fs.file('AndroidManifest.xml');
|
final File manifest = fs.file('AndroidManifest.xml');
|
||||||
when(androidProject.appManifestFile).thenReturn(manifest);
|
androidProject.appManifestFile = manifest;
|
||||||
|
|
||||||
await injectPlugins(flutterProject, androidPlatform: true);
|
await injectPlugins(flutterProject, androidPlatform: true);
|
||||||
|
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: <Type, Generator>{
|
||||||
FileSystem: () => fs,
|
FileSystem: () => fs,
|
||||||
ProcessManager: () => FakeProcessManager.any(),
|
ProcessManager: () => FakeProcessManager.any(),
|
||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext("Registrant for web doesn't escape slashes in imports", () async {
|
testUsingContext("Registrant for web doesn't escape slashes in imports", () async {
|
||||||
when(flutterProject.isModule).thenReturn(true);
|
flutterProject.isModule = true;
|
||||||
final Directory webPluginWithNestedFile =
|
final Directory webPluginWithNestedFile =
|
||||||
fs.systemTempDirectory.createTempSync('flutter_web_plugin_with_nested.');
|
fs.systemTempDirectory.createTempSync('flutter_web_plugin_with_nested.');
|
||||||
webPluginWithNestedFile.childFile('pubspec.yaml').writeAsStringSync('''
|
webPluginWithNestedFile.childFile('pubspec.yaml').writeAsStringSync('''
|
||||||
@ -909,7 +894,7 @@ web_plugin_with_nested:${webPluginWithNestedFile.childDirectory('lib').uri.toStr
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Injecting creates generated macos registrant, but does not include Dart-only plugins', () async {
|
testUsingContext('Injecting creates generated macos registrant, but does not include Dart-only plugins', () async {
|
||||||
when(flutterProject.isModule).thenReturn(true);
|
flutterProject.isModule = true;
|
||||||
// Create a plugin without a pluginClass.
|
// Create a plugin without a pluginClass.
|
||||||
final Directory pluginDirectory = createFakePlugin(fs);
|
final Directory pluginDirectory = createFakePlugin(fs);
|
||||||
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||||
@ -932,7 +917,7 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('pluginClass: none doesn\'t trigger registrant entry on macOS', () async {
|
testUsingContext('pluginClass: none doesn\'t trigger registrant entry on macOS', () async {
|
||||||
when(flutterProject.isModule).thenReturn(true);
|
flutterProject.isModule = true;
|
||||||
// Create a plugin without a pluginClass.
|
// Create a plugin without a pluginClass.
|
||||||
final Directory pluginDirectory = createFakePlugin(fs);
|
final Directory pluginDirectory = createFakePlugin(fs);
|
||||||
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||||
@ -957,7 +942,7 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Invalid yaml does not crash plugin lookup.', () async {
|
testUsingContext('Invalid yaml does not crash plugin lookup.', () async {
|
||||||
when(flutterProject.isModule).thenReturn(true);
|
flutterProject.isModule = true;
|
||||||
// Create a plugin without a pluginClass.
|
// Create a plugin without a pluginClass.
|
||||||
final Directory pluginDirectory = createFakePlugin(fs);
|
final Directory pluginDirectory = createFakePlugin(fs);
|
||||||
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync(r'''
|
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync(r'''
|
||||||
@ -975,7 +960,6 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Injecting creates generated Linux registrant', () async {
|
testUsingContext('Injecting creates generated Linux registrant', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
|
||||||
createFakePlugin(fs);
|
createFakePlugin(fs);
|
||||||
|
|
||||||
await injectPlugins(flutterProject, linuxPlatform: true);
|
await injectPlugins(flutterProject, linuxPlatform: true);
|
||||||
@ -992,7 +976,6 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Injecting creates generated Linux registrant, but does not include Dart-only plugins', () async {
|
testUsingContext('Injecting creates generated Linux registrant, but does not include Dart-only plugins', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
|
||||||
// Create a plugin without a pluginClass.
|
// Create a plugin without a pluginClass.
|
||||||
final Directory pluginDirectory = createFakePlugin(fs);
|
final Directory pluginDirectory = createFakePlugin(fs);
|
||||||
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||||
@ -1016,7 +999,6 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('pluginClass: none doesn\'t trigger registrant entry on Linux', () async {
|
testUsingContext('pluginClass: none doesn\'t trigger registrant entry on Linux', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
|
||||||
// Create a plugin without a pluginClass.
|
// Create a plugin without a pluginClass.
|
||||||
final Directory pluginDirectory = createFakePlugin(fs);
|
final Directory pluginDirectory = createFakePlugin(fs);
|
||||||
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||||
@ -1041,7 +1023,6 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Injecting creates generated Linux plugin Cmake file', () async {
|
testUsingContext('Injecting creates generated Linux plugin Cmake file', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
|
||||||
createFakePlugin(fs);
|
createFakePlugin(fs);
|
||||||
|
|
||||||
await injectPlugins(flutterProject, linuxPlatform: true);
|
await injectPlugins(flutterProject, linuxPlatform: true);
|
||||||
@ -1060,7 +1041,6 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Generated Linux plugin files sorts by plugin name', () async {
|
testUsingContext('Generated Linux plugin files sorts by plugin name', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
|
||||||
createFakePlugins(fs, <String>[
|
createFakePlugins(fs, <String>[
|
||||||
'plugin_d',
|
'plugin_d',
|
||||||
'plugin_a',
|
'plugin_a',
|
||||||
@ -1084,7 +1064,6 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Injecting creates generated Windows registrant', () async {
|
testUsingContext('Injecting creates generated Windows registrant', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
|
||||||
createFakePlugin(fs);
|
createFakePlugin(fs);
|
||||||
|
|
||||||
await injectPlugins(flutterProject, windowsPlatform: true);
|
await injectPlugins(flutterProject, windowsPlatform: true);
|
||||||
@ -1101,7 +1080,6 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Injecting creates generated Windows registrant, but does not include Dart-only plugins', () async {
|
testUsingContext('Injecting creates generated Windows registrant, but does not include Dart-only plugins', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
|
||||||
// Create a plugin without a pluginClass.
|
// Create a plugin without a pluginClass.
|
||||||
final Directory pluginDirectory = createFakePlugin(fs);
|
final Directory pluginDirectory = createFakePlugin(fs);
|
||||||
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||||
@ -1124,7 +1102,6 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('pluginClass: none doesn\'t trigger registrant entry on Windows', () async {
|
testUsingContext('pluginClass: none doesn\'t trigger registrant entry on Windows', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
|
||||||
// Create a plugin without a pluginClass.
|
// Create a plugin without a pluginClass.
|
||||||
final Directory pluginDirectory = createFakePlugin(fs);
|
final Directory pluginDirectory = createFakePlugin(fs);
|
||||||
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||||
@ -1149,7 +1126,6 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Generated Windows plugin files sorts by plugin name', () async {
|
testUsingContext('Generated Windows plugin files sorts by plugin name', () async {
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
|
||||||
createFakePlugins(fs, <String>[
|
createFakePlugins(fs, <String>[
|
||||||
'plugin_d',
|
'plugin_d',
|
||||||
'plugin_a',
|
'plugin_a',
|
||||||
@ -1177,8 +1153,6 @@ flutter:
|
|||||||
setUpProject(fsWindows);
|
setUpProject(fsWindows);
|
||||||
createFakePlugin(fsWindows);
|
createFakePlugin(fsWindows);
|
||||||
|
|
||||||
when(flutterProject.isModule).thenReturn(false);
|
|
||||||
|
|
||||||
await injectPlugins(flutterProject, linuxPlatform: true, windowsPlatform: true);
|
await injectPlugins(flutterProject, linuxPlatform: true, windowsPlatform: true);
|
||||||
|
|
||||||
for (final CmakeBasedProject project in <CmakeBasedProject>[linuxProject, windowsProject]) {
|
for (final CmakeBasedProject project in <CmakeBasedProject>[linuxProject, windowsProject]) {
|
||||||
@ -1202,7 +1176,7 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Symlinks are created for Linux plugins', () async {
|
testUsingContext('Symlinks are created for Linux plugins', () async {
|
||||||
when(linuxProject.existsSync()).thenReturn(true);
|
linuxProject.exists = true;
|
||||||
createFakePlugin(fs);
|
createFakePlugin(fs);
|
||||||
// refreshPluginsList should call createPluginSymlinks.
|
// refreshPluginsList should call createPluginSymlinks.
|
||||||
await refreshPluginsList(flutterProject);
|
await refreshPluginsList(flutterProject);
|
||||||
@ -1215,7 +1189,7 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Symlinks are created for Windows plugins', () async {
|
testUsingContext('Symlinks are created for Windows plugins', () async {
|
||||||
when(windowsProject.existsSync()).thenReturn(true);
|
windowsProject.exists = true;
|
||||||
createFakePlugin(fs);
|
createFakePlugin(fs);
|
||||||
// refreshPluginsList should call createPluginSymlinks.
|
// refreshPluginsList should call createPluginSymlinks.
|
||||||
await refreshPluginsList(flutterProject);
|
await refreshPluginsList(flutterProject);
|
||||||
@ -1228,8 +1202,8 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Existing symlinks are removed when no longer in use with force', () {
|
testUsingContext('Existing symlinks are removed when no longer in use with force', () {
|
||||||
when(linuxProject.existsSync()).thenReturn(true);
|
linuxProject.exists = true;
|
||||||
when(windowsProject.existsSync()).thenReturn(true);
|
windowsProject.exists = true;
|
||||||
|
|
||||||
final List<File> dummyFiles = <File>[
|
final List<File> dummyFiles = <File>[
|
||||||
flutterProject.linux.pluginSymlinkDirectory.childFile('dummy'),
|
flutterProject.linux.pluginSymlinkDirectory.childFile('dummy'),
|
||||||
@ -1251,8 +1225,8 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Existing symlinks are removed automatically on refresh when no longer in use', () async {
|
testUsingContext('Existing symlinks are removed automatically on refresh when no longer in use', () async {
|
||||||
when(linuxProject.existsSync()).thenReturn(true);
|
linuxProject.exists = true;
|
||||||
when(windowsProject.existsSync()).thenReturn(true);
|
windowsProject.exists = true;
|
||||||
|
|
||||||
final List<File> dummyFiles = <File>[
|
final List<File> dummyFiles = <File>[
|
||||||
flutterProject.linux.pluginSymlinkDirectory.childFile('dummy'),
|
flutterProject.linux.pluginSymlinkDirectory.childFile('dummy'),
|
||||||
@ -1276,8 +1250,8 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('createPluginSymlinks is a no-op without force when up to date', () {
|
testUsingContext('createPluginSymlinks is a no-op without force when up to date', () {
|
||||||
when(linuxProject.existsSync()).thenReturn(true);
|
linuxProject.exists = true;
|
||||||
when(windowsProject.existsSync()).thenReturn(true);
|
windowsProject.exists = true;
|
||||||
|
|
||||||
final List<File> dummyFiles = <File>[
|
final List<File> dummyFiles = <File>[
|
||||||
flutterProject.linux.pluginSymlinkDirectory.childFile('dummy'),
|
flutterProject.linux.pluginSymlinkDirectory.childFile('dummy'),
|
||||||
@ -1300,8 +1274,8 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('createPluginSymlinks repairs missing links', () async {
|
testUsingContext('createPluginSymlinks repairs missing links', () async {
|
||||||
when(linuxProject.existsSync()).thenReturn(true);
|
linuxProject.exists = true;
|
||||||
when(windowsProject.existsSync()).thenReturn(true);
|
windowsProject.exists = true;
|
||||||
createFakePlugin(fs);
|
createFakePlugin(fs);
|
||||||
await refreshPluginsList(flutterProject);
|
await refreshPluginsList(flutterProject);
|
||||||
|
|
||||||
@ -1325,9 +1299,9 @@ flutter:
|
|||||||
});
|
});
|
||||||
|
|
||||||
group('pubspec', () {
|
group('pubspec', () {
|
||||||
|
|
||||||
Directory projectDir;
|
Directory projectDir;
|
||||||
Directory tempDir;
|
Directory tempDir;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_plugin_test.');
|
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_plugin_test.');
|
||||||
projectDir = tempDir.childDirectory('flutter_project');
|
projectDir = tempDir.childDirectory('flutter_project');
|
||||||
@ -1419,15 +1393,182 @@ flutter:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockAndroidProject extends Mock implements AndroidProject {}
|
class FakeFlutterManifest extends Fake implements FlutterManifest {
|
||||||
class MockFlutterManifest extends Mock implements FlutterManifest {}
|
@override
|
||||||
class MockFlutterProject extends Mock implements FlutterProject {}
|
Set<String> get dependencies => <String>{};
|
||||||
class MockIosProject extends Mock implements IosProject {}
|
}
|
||||||
class MockMacOSProject extends Mock implements MacOSProject {}
|
|
||||||
class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterpreter {}
|
class FakeXcodeProjectInterpreter extends Fake implements XcodeProjectInterpreter {
|
||||||
class MockWebProject extends Mock implements WebProject {}
|
@override
|
||||||
class MockWindowsProject extends Mock implements WindowsProject {}
|
bool get isInstalled => false;
|
||||||
class MockLinuxProject extends Mock implements LinuxProject {}
|
}
|
||||||
|
|
||||||
|
class FakeFlutterProject extends Fake implements FlutterProject {
|
||||||
|
@override
|
||||||
|
bool isModule = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
FlutterManifest manifest;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Directory directory;
|
||||||
|
|
||||||
|
@override
|
||||||
|
File flutterPluginsFile;
|
||||||
|
|
||||||
|
@override
|
||||||
|
File flutterPluginsDependenciesFile;
|
||||||
|
|
||||||
|
@override
|
||||||
|
IosProject ios;
|
||||||
|
|
||||||
|
@override
|
||||||
|
AndroidProject android;
|
||||||
|
|
||||||
|
@override
|
||||||
|
WebProject web;
|
||||||
|
|
||||||
|
@override
|
||||||
|
MacOSProject macos;
|
||||||
|
|
||||||
|
@override
|
||||||
|
LinuxProject linux;
|
||||||
|
|
||||||
|
@override
|
||||||
|
WindowsProject windows;
|
||||||
|
|
||||||
|
@override
|
||||||
|
WindowsUwpProject windowsUwp;
|
||||||
|
}
|
||||||
|
|
||||||
|
class FakeMacOSProject extends Fake implements MacOSProject {
|
||||||
|
@override
|
||||||
|
String pluginConfigKey = 'macos';
|
||||||
|
|
||||||
|
bool exists = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
File podfile;
|
||||||
|
|
||||||
|
@override
|
||||||
|
File podManifestLock;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Directory managedDirectory;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool existsSync() => exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
class FakeIosProject extends Fake implements IosProject {
|
||||||
|
@override
|
||||||
|
String pluginConfigKey = 'ios';
|
||||||
|
|
||||||
|
bool testExists = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool existsSync() => testExists;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get exists => testExists;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Directory pluginRegistrantHost;
|
||||||
|
|
||||||
|
@override
|
||||||
|
File podfile;
|
||||||
|
|
||||||
|
@override
|
||||||
|
File podManifestLock;
|
||||||
|
}
|
||||||
|
|
||||||
|
class FakeAndroidProject extends Fake implements AndroidProject {
|
||||||
|
@override
|
||||||
|
String pluginConfigKey = 'android';
|
||||||
|
|
||||||
|
bool exists = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Directory pluginRegistrantHost;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Directory hostAppGradleRoot;
|
||||||
|
|
||||||
|
@override
|
||||||
|
File appManifestFile;
|
||||||
|
|
||||||
|
AndroidEmbeddingVersion embeddingVersion;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool existsSync() => exists;
|
||||||
|
|
||||||
|
@override
|
||||||
|
AndroidEmbeddingVersion getEmbeddingVersion() {
|
||||||
|
return embeddingVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FakeWebProject extends Fake implements WebProject {
|
||||||
|
@override
|
||||||
|
String pluginConfigKey = 'web';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Directory libDirectory;
|
||||||
|
|
||||||
|
bool exists = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool existsSync() => exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
class FakeWindowsProject extends Fake implements WindowsProject {
|
||||||
|
@override
|
||||||
|
String pluginConfigKey = 'windows';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Directory managedDirectory;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Directory ephemeralDirectory;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Directory pluginSymlinkDirectory;
|
||||||
|
|
||||||
|
@override
|
||||||
|
File cmakeFile;
|
||||||
|
|
||||||
|
@override
|
||||||
|
File generatedPluginCmakeFile;
|
||||||
|
bool exists = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool existsSync() => exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
class FakeLinuxProject extends Fake implements LinuxProject {
|
||||||
|
@override
|
||||||
|
String pluginConfigKey = 'linux';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Directory managedDirectory;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Directory ephemeralDirectory;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Directory pluginSymlinkDirectory;
|
||||||
|
|
||||||
|
@override
|
||||||
|
File cmakeFile;
|
||||||
|
|
||||||
|
@override
|
||||||
|
File generatedPluginCmakeFile;
|
||||||
|
bool exists = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool existsSync() => exists;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
|
class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
|
||||||
FakeOperatingSystemUtils(this.name);
|
FakeOperatingSystemUtils(this.name);
|
||||||
|
Loading…
Reference in New Issue
Block a user