-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Fix webview_flutter Android integration tests and add Espresso #4147
Changes from 10 commits
18e6d22
2025b84
ddf5d91
562cc4d
cad641b
b94cfbb
744c395
6d9f282
e5ea80c
2489c44
76d612e
dc6be9a
8713690
648e94c
3619762
ffe0058
f624087
a10bfde
42b7238
927b9fe
089fa76
77b45f1
7e73bb1
79d82c4
d34c705
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2013 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. | ||
|
||
package io.flutter.plugins.webviewflutterexample; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
public class WebViewTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what runner is this using? do you want to use AndroidJUnit4? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my understanding of Gradle, it uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also explained here https://developer.android.com/training/testing/junit-runner#ato-gradle There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sgtm |
||
@Test | ||
public void placeHolderTest() { | ||
assertEquals(1, 1); | ||
bparrishMines marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
<application | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="webview_flutter_example" | ||
android:usesCleartextTraffic="true" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the espresso package |
||
android:name="io.flutter.app.FlutterApplication"> | ||
<meta-data | ||
android:name="flutterEmbedding" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ import 'package:integration_test/integration_test.dart'; | |
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
testWidgets('initalUrl', (WidgetTester tester) async { | ||
testWidgets('initialUrl', (WidgetTester tester) async { | ||
final Completer<WebViewController> controllerCompleter = | ||
Completer<WebViewController>(); | ||
await tester.pumpWidget( | ||
|
@@ -532,6 +532,7 @@ void main() { | |
expect(fullScreen, _webviewBool(false)); | ||
}); | ||
|
||
// allowsInlineMediaPlayback is a noop on Android, so it is skipped. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test fails when running on Android, but it doesn't seem like there is anything we can do since a flag like this isn't supported on Android. At least according to the comment. |
||
testWidgets( | ||
'Video plays full screen when allowsInlineMediaPlayback is false', | ||
(WidgetTester tester) async { | ||
|
@@ -581,7 +582,7 @@ void main() { | |
String fullScreen = | ||
await controller.evaluateJavascript('isFullScreen();'); | ||
expect(fullScreen, _webviewBool(true)); | ||
}); | ||
}, skip: Platform.isAndroid); | ||
}); | ||
|
||
group('Audio playback policy', () { | ||
|
@@ -1272,18 +1273,19 @@ void main() { | |
), | ||
); | ||
final WebViewController controller = await controllerCompleter.future; | ||
await controller.evaluateJavascript('window.open("about:blank", "_blank")'); | ||
await controller | ||
.evaluateJavascript('window.open("https://flutter.dev/", "_blank")'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test would stall on Android. For some reason, Android has different behavior when a |
||
await pageLoaded.future; | ||
final String? currentUrl = await controller.currentUrl(); | ||
expect(currentUrl, 'about:blank'); | ||
expect(currentUrl, 'https://flutter.dev/'); | ||
}); | ||
|
||
testWidgets( | ||
'can open new window and go back', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed the weird bug where |
||
(WidgetTester tester) async { | ||
final Completer<WebViewController> controllerCompleter = | ||
Completer<WebViewController>(); | ||
final Completer<void> pageLoaded = Completer<void>(); | ||
Completer<void> pageLoaded = Completer<void>(); | ||
await tester.pumpWidget( | ||
Directionality( | ||
textDirection: TextDirection.ltr, | ||
|
@@ -1301,13 +1303,20 @@ void main() { | |
), | ||
); | ||
final WebViewController controller = await controllerCompleter.future; | ||
expect(controller.currentUrl(), completion('https://flutter.dev/')); | ||
await pageLoaded.future; | ||
pageLoaded = Completer<void>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can it have a different name, so there's no need to reassign a new completer? |
||
|
||
await controller | ||
.evaluateJavascript('window.open("https://www.google.com")'); | ||
.evaluateJavascript('window.open("https://www.google.com/")'); | ||
await pageLoaded.future; | ||
pageLoaded = Completer<void>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
expect(controller.currentUrl(), completion('https://www.google.com/')); | ||
|
||
expect(controller.canGoBack(), completion(true)); | ||
await controller.goBack(); | ||
expect(controller.currentUrl(), completion('https://www.flutter.dev')); | ||
await pageLoaded.future; | ||
expect(controller.currentUrl(), completion('https://flutter.dev/')); | ||
}, | ||
skip: !Platform.isAndroid, | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ dependencies: | |
path: ../ | ||
|
||
dev_dependencies: | ||
espresso: ^0.1.0+2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is used. is it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not in this PR, but I added it as part of "adding the test harness". I assumed that when another user wanted to create a PR and needed to add a test, that we didn't want to require them to add dependencies. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good |
||
flutter_test: | ||
sdk: flutter | ||
flutter_driver: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't seem used, is it?