Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
80bc3f4a
Unverified
Commit
80bc3f4a
authored
Apr 06, 2020
by
Amir Hardon
Committed by
GitHub
Apr 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test creation of Android AlertDialogs with a platform view context (#53980)
parent
2d623278
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
169 additions
and
30 deletions
+169
-30
SimplePlatformView.java
.../flutter/integration/androidviews/SimplePlatformView.java
+27
-11
main.dart
dev/integration_tests/android_views/lib/main.dart
+13
-7
wm_integrations.dart
dev/integration_tests/android_views/lib/wm_integrations.dart
+104
-0
main_test.dart
...ntegration_tests/android_views/test_driver/main_test.dart
+25
-12
No files found.
dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/SimplePlatformView.java
View file @
80bc3f4a
...
...
@@ -4,35 +4,37 @@
package
io
.
flutter
.
integration
.
platformviews
;
import
android.app.AlertDialog
;
import
android.content.Context
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.widget.TextView
;
import
io.flutter.plugin.common.MethodCall
;
import
io.flutter.plugin.common.MethodChannel
;
import
io.flutter.plugin.platform.PlatformView
;
public
class
SimplePlatformView
implements
PlatformView
,
MethodChannel
.
MethodCallHandler
{
private
final
View
mV
iew
;
private
final
MethodChannel
m
M
ethodChannel
;
private
final
TouchPipe
mT
ouchPipe
;
private
final
View
v
iew
;
private
final
MethodChannel
methodChannel
;
private
final
io
.
flutter
.
integration
.
platformviews
.
TouchPipe
t
ouchPipe
;
SimplePlatformView
(
Context
context
,
MethodChannel
methodChannel
)
{
mM
ethodChannel
=
methodChannel
;
mV
iew
=
new
View
(
context
)
{
this
.
m
ethodChannel
=
methodChannel
;
v
iew
=
new
View
(
context
)
{
@Override
public
boolean
onTouchEvent
(
MotionEvent
event
)
{
return
super
.
onTouchEvent
(
event
);
}
};
mV
iew
.
setBackgroundColor
(
0xff0000ff
);
mM
ethodChannel
.
setMethodCallHandler
(
this
);
mTouchPipe
=
new
TouchPipe
(
mMethodChannel
,
mV
iew
);
v
iew
.
setBackgroundColor
(
0xff0000ff
);
this
.
m
ethodChannel
.
setMethodCallHandler
(
this
);
touchPipe
=
new
io
.
flutter
.
integration
.
platformviews
.
TouchPipe
(
this
.
methodChannel
,
v
iew
);
}
@Override
public
View
getView
()
{
return
mV
iew
;
return
v
iew
;
}
@Override
...
...
@@ -43,14 +45,28 @@ public class SimplePlatformView implements PlatformView, MethodChannel.MethodCal
public
void
onMethodCall
(
MethodCall
methodCall
,
MethodChannel
.
Result
result
)
{
switch
(
methodCall
.
method
)
{
case
"pipeTouchEvents"
:
mT
ouchPipe
.
enable
();
t
ouchPipe
.
enable
();
result
.
success
(
null
);
return
;
case
"stopTouchEvents"
:
mT
ouchPipe
.
disable
();
t
ouchPipe
.
disable
();
result
.
success
(
null
);
return
;
case
"showAlertDialog"
:
showAlertDialog
(
result
);
return
;
}
result
.
notImplemented
();
}
private
void
showAlertDialog
(
MethodChannel
.
Result
result
)
{
Context
context
=
view
.
getContext
();
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
context
);
TextView
textView
=
new
TextView
(
context
);
textView
.
setText
(
"Alert!"
);
builder
.
setView
(
textView
);
final
AlertDialog
alertDialog
=
builder
.
show
();
result
.
success
(
null
);
}
}
dev/integration_tests/android_views/lib/main.dart
View file @
80bc3f4a
...
...
@@ -4,11 +4,14 @@
import
'package:flutter/material.dart'
;
import
'package:flutter_driver/driver_extension.dart'
;
import
'motion_events_page.dart'
;
import
'page.dart'
;
import
'wm_integrations.dart'
;
final
List
<
PageWidget
>
_allPages
=
<
PageWidget
>[
const
MotionEventsPage
(),
const
WindowManagerIntegrationsPage
(),
];
void
main
(
)
{
...
...
@@ -20,17 +23,20 @@ class Home extends StatelessWidget {
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
body:
ListView
.
builder
(
itemCount:
_allPages
.
length
,
itemBuilder:
(
_
,
int
index
)
=>
ListTile
(
title:
Text
(
_allPages
[
index
].
title
),
key:
_allPages
[
index
].
tileKey
,
onTap:
()
=>
_pushPage
(
context
,
_allPages
[
index
]),
),
body:
ListView
(
children:
_allPages
.
map
((
PageWidget
p
)
=>
_buildPageListTile
(
context
,
p
)).
toList
(),
),
);
}
Widget
_buildPageListTile
(
BuildContext
context
,
PageWidget
page
)
{
return
ListTile
(
title:
Text
(
page
.
title
),
key:
page
.
tileKey
,
onTap:
()
{
_pushPage
(
context
,
page
);
},
);
}
void
_pushPage
(
BuildContext
context
,
PageWidget
page
)
{
Navigator
.
of
(
context
).
push
(
MaterialPageRoute
<
void
>(
builder:
(
_
)
=>
Scaffold
(
...
...
dev/integration_tests/android_views/lib/wm_integrations.dart
0 → 100644
View file @
80bc3f4a
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:ui'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/widgets.dart'
;
import
'page.dart'
;
class
WindowManagerIntegrationsPage
extends
PageWidget
{
const
WindowManagerIntegrationsPage
()
:
super
(
'Window Manager Integrations Tests'
,
const
ValueKey
<
String
>(
'WmIntegrationsListTile'
));
@override
Widget
build
(
BuildContext
context
)
=>
WindowManagerBody
();
}
class
WindowManagerBody
extends
StatefulWidget
{
@override
State
<
WindowManagerBody
>
createState
()
=>
WindowManagerBodyState
();
}
enum
_LastTestStatus
{
pending
,
success
,
error
}
class
WindowManagerBodyState
extends
State
<
WindowManagerBody
>
{
MethodChannel
viewChannel
;
_LastTestStatus
lastTestStatus
=
_LastTestStatus
.
pending
;
String
lastError
;
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'Window Manager Integrations'
),
),
body:
Column
(
children:
<
Widget
>[
SizedBox
(
height:
300
,
child:
AndroidView
(
viewType:
'simple_view'
,
onPlatformViewCreated:
onPlatformViewCreated
,
),
),
if
(
lastTestStatus
!=
_LastTestStatus
.
pending
)
_statusWidget
(),
if
(
viewChannel
!=
null
)
RaisedButton
(
key:
const
ValueKey
<
String
>(
'ShowAlertDialog'
),
child:
const
Text
(
'SHOW ALERT DIALOG'
),
onPressed:
onShowAlertDialogPressed
,
),
],
),
);
}
Widget
_statusWidget
()
{
assert
(
lastTestStatus
!=
_LastTestStatus
.
pending
);
final
String
message
=
lastTestStatus
==
_LastTestStatus
.
success
?
'Success'
:
lastError
;
return
Container
(
color:
lastTestStatus
==
_LastTestStatus
.
success
?
Colors
.
green
:
Colors
.
red
,
child:
Text
(
message
,
key:
const
ValueKey
<
String
>(
'Status'
),
style:
TextStyle
(
color:
lastTestStatus
==
_LastTestStatus
.
error
?
Colors
.
yellow
:
null
,
),
),
);
}
Future
<
void
>
onShowAlertDialogPressed
()
async
{
if
(
lastTestStatus
!=
_LastTestStatus
.
pending
)
{
setState
(()
{
lastTestStatus
=
_LastTestStatus
.
pending
;
});
}
try
{
await
viewChannel
.
invokeMethod
<
void
>(
'showAlertDialog'
);
setState
(()
{
lastTestStatus
=
_LastTestStatus
.
success
;
});
}
catch
(
e
)
{
setState
(()
{
lastTestStatus
=
_LastTestStatus
.
error
;
lastError
=
'
$e
'
;
});
}
}
void
onPlatformViewCreated
(
int
id
)
{
setState
(()
{
viewChannel
=
MethodChannel
(
'simple_view/
$id
'
);
});
}
}
dev/integration_tests/android_views/test_driver/main_test.dart
View file @
80bc3f4a
...
...
@@ -17,16 +17,29 @@ Future<void> main() async {
driver
.
close
();
});
group
(
'MotionEvents tests '
,
()
{
test
(
'recomposition'
,
()
async
{
final
SerializableFinder
motionEventsListTile
=
find
.
byValueKey
(
'MotionEventsListTile'
);
await
driver
.
tap
(
motionEventsListTile
);
await
driver
.
waitFor
(
find
.
byValueKey
(
'PlatformView'
));
final
String
errorMessage
=
await
driver
.
requestData
(
'run test'
);
expect
(
errorMessage
,
''
);
},
// TODO(amirh): enable this test https://github.com/flutter/flutter/issues/54022
skip:
true
);
});
test
(
'MotionEvent recomposition'
,
()
async
{
final
SerializableFinder
motionEventsListTile
=
find
.
byValueKey
(
'MotionEventsListTile'
);
await
driver
.
tap
(
motionEventsListTile
);
await
driver
.
waitFor
(
find
.
byValueKey
(
'PlatformView'
));
final
String
errorMessage
=
await
driver
.
requestData
(
'run test'
);
expect
(
errorMessage
,
''
);
},
// TODO(amirh): enable this test https://github.com/flutter/flutter/issues/54022
skip:
true
);
test
(
'AlertDialog from platform view context'
,
()
async
{
final
SerializableFinder
wmListTile
=
find
.
byValueKey
(
'WmIntegrationsListTile'
);
await
driver
.
tap
(
wmListTile
);
final
SerializableFinder
showAlertDialog
=
find
.
byValueKey
(
'ShowAlertDialog'
);
await
driver
.
waitFor
(
showAlertDialog
);
await
driver
.
tap
(
showAlertDialog
);
final
String
status
=
await
driver
.
getText
(
find
.
byValueKey
(
'Status'
));
expect
(
status
,
'Success'
);
},
// TODO(amirh): enable this test when https://github.com/flutter/flutter/issues/34248 is fixed.
skip:
true
,
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment