Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
fec95737
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
fec95737
编写于
1月 24, 2020
作者:
M
Matt Carroll
提交者:
GitHub
1月 24, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Prevent duplicate plugin registration in FlutterEnginePluginRegistry. (#49365) (#15956)
上级
9ee917c2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
89 addition
and
0 deletion
+89
-0
shell/platform/android/BUILD.gn
shell/platform/android/BUILD.gn
+1
-0
shell/platform/android/io/flutter/embedding/engine/FlutterEnginePluginRegistry.java
...flutter/embedding/engine/FlutterEnginePluginRegistry.java
+6
-0
shell/platform/android/test/io/flutter/FlutterTestSuite.java
shell/platform/android/test/io/flutter/FlutterTestSuite.java
+2
-0
shell/platform/android/test/io/flutter/embedding/engine/FlutterEnginePluginRegistryTest.java
...ter/embedding/engine/FlutterEnginePluginRegistryTest.java
+80
-0
未找到文件。
shell/platform/android/BUILD.gn
浏览文件 @
fec95737
...
...
@@ -421,6 +421,7 @@ action("robolectric_tests") {
"test/io/flutter/embedding/android/FlutterViewTest.java",
"test/io/flutter/embedding/android/RobolectricFlutterActivity.java",
"test/io/flutter/embedding/engine/FlutterEngineCacheTest.java",
"test/io/flutter/embedding/engine/FlutterEnginePluginRegistryTest.java",
"test/io/flutter/embedding/engine/FlutterEngineTest.java",
"test/io/flutter/embedding/engine/FlutterJNITest.java",
"test/io/flutter/embedding/engine/FlutterShellArgsTest.java",
...
...
shell/platform/android/io/flutter/embedding/engine/FlutterEnginePluginRegistry.java
浏览文件 @
fec95737
...
...
@@ -117,6 +117,12 @@ class FlutterEnginePluginRegistry implements PluginRegistry,
@Override
public
void
add
(
@NonNull
FlutterPlugin
plugin
)
{
if
(
has
(
plugin
.
getClass
()))
{
Log
.
w
(
TAG
,
"Attempted to register plugin ("
+
plugin
+
") but it was "
+
"already registered with this FlutterEngine ("
+
flutterEngine
+
")."
);
return
;
}
Log
.
v
(
TAG
,
"Adding plugin: "
+
plugin
);
// Add the plugin to our generic set of plugins and notify the plugin
// that is has been attached to an engine.
...
...
shell/platform/android/test/io/flutter/FlutterTestSuite.java
浏览文件 @
fec95737
...
...
@@ -13,6 +13,7 @@ import io.flutter.embedding.android.FlutterAndroidComponentTest;
import
io.flutter.embedding.android.FlutterFragmentTest
;
import
io.flutter.embedding.android.FlutterViewTest
;
import
io.flutter.embedding.engine.FlutterEngineCacheTest
;
import
io.flutter.embedding.engine.FlutterEnginePluginRegistryTest
;
import
io.flutter.embedding.engine.FlutterJNITest
;
import
io.flutter.embedding.engine.RenderingComponentTest
;
import
io.flutter.embedding.engine.plugins.shim.ShimPluginRegistryTest
;
...
...
@@ -35,6 +36,7 @@ import test.io.flutter.embedding.engine.dart.DartExecutorTest;
FlutterActivityTest
.
class
,
FlutterAndroidComponentTest
.
class
,
FlutterEngineCacheTest
.
class
,
FlutterEnginePluginRegistryTest
.
class
,
FlutterEngineTest
.
class
,
FlutterFragmentTest
.
class
,
FlutterJNITest
.
class
,
...
...
shell/platform/android/test/io/flutter/embedding/engine/FlutterEnginePluginRegistryTest.java
0 → 100644
浏览文件 @
fec95737
package
io.flutter.embedding.engine
;
import
android.content.Context
;
import
android.support.annotation.NonNull
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.robolectric.RobolectricTestRunner
;
import
org.robolectric.annotation.Config
;
import
io.flutter.embedding.engine.loader.FlutterLoader
;
import
io.flutter.embedding.engine.plugins.FlutterPlugin
;
import
io.flutter.plugin.platform.PlatformViewsController
;
import
static
junit
.
framework
.
TestCase
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
// Run with Robolectric so that Log calls don't crash.
@Config
(
manifest
=
Config
.
NONE
)
@RunWith
(
RobolectricTestRunner
.
class
)
public
class
FlutterEnginePluginRegistryTest
{
@Test
public
void
itDoesNotRegisterTheSamePluginTwice
()
{
Context
context
=
mock
(
Context
.
class
);
FlutterEngine
flutterEngine
=
mock
(
FlutterEngine
.
class
);
PlatformViewsController
platformViewsController
=
mock
(
PlatformViewsController
.
class
);
when
(
flutterEngine
.
getPlatformViewsController
()).
thenReturn
(
platformViewsController
);
FlutterLoader
flutterLoader
=
mock
(
FlutterLoader
.
class
);
FakeFlutterPlugin
fakePlugin1
=
new
FakeFlutterPlugin
();
FakeFlutterPlugin
fakePlugin2
=
new
FakeFlutterPlugin
();
FlutterEnginePluginRegistry
registry
=
new
FlutterEnginePluginRegistry
(
context
,
flutterEngine
,
flutterLoader
);
// Verify that the registry doesn't think it contains our plugin yet.
assertFalse
(
registry
.
has
(
fakePlugin1
.
getClass
()));
// Add our plugin to the registry.
registry
.
add
(
fakePlugin1
);
// Verify that the registry now thinks it contains our plugin.
assertTrue
(
registry
.
has
(
fakePlugin1
.
getClass
()));
assertEquals
(
1
,
fakePlugin1
.
attachmentCallCount
);
// Add a different instance of the same plugin class.
registry
.
add
(
fakePlugin2
);
// Verify that the registry did not detach the 1st plugin, and
// it did not attach the 2nd plugin.
assertEquals
(
1
,
fakePlugin1
.
attachmentCallCount
);
assertEquals
(
0
,
fakePlugin1
.
detachmentCallCount
);
assertEquals
(
0
,
fakePlugin2
.
attachmentCallCount
);
assertEquals
(
0
,
fakePlugin2
.
detachmentCallCount
);
}
private
static
class
FakeFlutterPlugin
implements
FlutterPlugin
{
public
int
attachmentCallCount
=
0
;
public
int
detachmentCallCount
=
0
;
@Override
public
void
onAttachedToEngine
(
@NonNull
FlutterPluginBinding
binding
)
{
attachmentCallCount
+=
1
;
}
@Override
public
void
onDetachedFromEngine
(
@NonNull
FlutterPluginBinding
binding
)
{
detachmentCallCount
+=
1
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录