Jonah Williams | 186765b | 2020-10-05 14:45:39 -0700 | [diff] [blame] | 1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import 'package:file/file.dart'; |
| 6 | import 'package:file/memory.dart'; |
| 7 | import 'package:flutter_tools/src/platform_plugins.dart'; |
| 8 | |
| 9 | |
| 10 | import '../src/common.dart'; |
| 11 | |
| 12 | void main() { |
| 13 | testWithoutContext('AndroidPlugin throws tool exit if the plugin main class can not be found', () { |
| 14 | final FileSystem fileSystem = MemoryFileSystem.test(); |
| 15 | final AndroidPlugin androidPlugin = AndroidPlugin( |
| 16 | name: 'pluginA', |
| 17 | package: 'com.company', |
| 18 | pluginClass: 'PluginA', |
| 19 | pluginPath: '.pub_cache/plugin_a', |
| 20 | fileSystem: fileSystem, |
| 21 | ); |
| 22 | |
| 23 | expect(() => androidPlugin.toMap(), throwsToolExit( |
| 24 | message: "The plugin `pluginA` doesn't have a main class defined in " |
| 25 | '.pub_cache/plugin_a/android/src/main/java/com/company/PluginA.java ' |
| 26 | 'or .pub_cache/plugin_a/android/src/main/kotlin/com/company/PluginA.kt' |
| 27 | )); |
| 28 | }); |
| 29 | |
| 30 | testWithoutContext('AndroidPlugin parses embedding version 2 from the Java search path', () { |
| 31 | final FileSystem fileSystem = MemoryFileSystem.test(); |
| 32 | final AndroidPlugin androidPlugin = AndroidPlugin( |
| 33 | name: 'pluginA', |
| 34 | package: 'com.company', |
| 35 | pluginClass: 'PluginA', |
| 36 | pluginPath: '.pub_cache/plugin_a', |
| 37 | fileSystem: fileSystem, |
| 38 | ); |
| 39 | |
| 40 | fileSystem.file('.pub_cache/plugin_a/android/src/main/java/com/company/PluginA.java') |
| 41 | ..createSync(recursive: true) |
| 42 | ..writeAsStringSync('io.flutter.embedding.engine.plugins.FlutterPlugin'); |
| 43 | |
| 44 | expect(androidPlugin.toMap(), <String, Object>{ |
| 45 | 'name': 'pluginA', |
| 46 | 'package': 'com.company', |
| 47 | 'class': 'PluginA', |
| 48 | 'supportsEmbeddingV1': false, |
| 49 | 'supportsEmbeddingV2': true, |
| 50 | }); |
| 51 | }); |
| 52 | |
| 53 | testWithoutContext('AndroidPlugin parses embedding version 1 from the Java search path', () { |
| 54 | final FileSystem fileSystem = MemoryFileSystem.test(); |
| 55 | final AndroidPlugin androidPlugin = AndroidPlugin( |
| 56 | name: 'pluginA', |
| 57 | package: 'com.company', |
| 58 | pluginClass: 'PluginA', |
| 59 | pluginPath: '.pub_cache/plugin_a', |
| 60 | fileSystem: fileSystem, |
| 61 | ); |
| 62 | |
| 63 | fileSystem.file('.pub_cache/plugin_a/android/src/main/java/com/company/PluginA.java') |
| 64 | ..createSync(recursive: true) |
| 65 | ..writeAsStringSync('some.other.string'); |
| 66 | |
| 67 | expect(androidPlugin.toMap(), <String, Object>{ |
| 68 | 'name': 'pluginA', |
| 69 | 'package': 'com.company', |
| 70 | 'class': 'PluginA', |
| 71 | 'supportsEmbeddingV1': true, |
| 72 | 'supportsEmbeddingV2': false, |
| 73 | }); |
| 74 | }); |
| 75 | |
| 76 | testWithoutContext('AndroidPlugin parses embedding version 2 from the Kotlin search path', () { |
| 77 | final FileSystem fileSystem = MemoryFileSystem.test(); |
| 78 | final AndroidPlugin androidPlugin = AndroidPlugin( |
| 79 | name: 'pluginA', |
| 80 | package: 'com.company', |
| 81 | pluginClass: 'PluginA', |
| 82 | pluginPath: '.pub_cache/plugin_a', |
| 83 | fileSystem: fileSystem, |
| 84 | ); |
| 85 | |
| 86 | fileSystem.file('.pub_cache/plugin_a/android/src/main/kotlin/com/company/PluginA.kt') |
| 87 | ..createSync(recursive: true) |
| 88 | ..writeAsStringSync('io.flutter.embedding.engine.plugins.FlutterPlugin'); |
| 89 | |
| 90 | expect(androidPlugin.toMap(), <String, Object>{ |
| 91 | 'name': 'pluginA', |
| 92 | 'package': 'com.company', |
| 93 | 'class': 'PluginA', |
| 94 | 'supportsEmbeddingV1': false, |
| 95 | 'supportsEmbeddingV2': true, |
| 96 | }); |
| 97 | }); |
| 98 | |
| 99 | testWithoutContext('AndroidPlugin parses embedding version 1 from the Kotlin search path', () { |
| 100 | final FileSystem fileSystem = MemoryFileSystem.test(); |
| 101 | final AndroidPlugin androidPlugin = AndroidPlugin( |
| 102 | name: 'pluginA', |
| 103 | package: 'com.company', |
| 104 | pluginClass: 'PluginA', |
| 105 | pluginPath: '.pub_cache/plugin_a', |
| 106 | fileSystem: fileSystem, |
| 107 | ); |
| 108 | |
| 109 | fileSystem.file('.pub_cache/plugin_a/android/src/main/kotlin/com/company/PluginA.kt') |
| 110 | ..createSync(recursive: true) |
| 111 | ..writeAsStringSync('some.other.string'); |
| 112 | |
| 113 | expect(androidPlugin.toMap(), <String, Object>{ |
| 114 | 'name': 'pluginA', |
| 115 | 'package': 'com.company', |
| 116 | 'class': 'PluginA', |
| 117 | 'supportsEmbeddingV1': true, |
| 118 | 'supportsEmbeddingV2': false, |
| 119 | }); |
| 120 | }); |
| 121 | } |