Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Fix webview_flutter Android integration tests and add Espresso #4147

Merged
merged 25 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
18e6d22
lets see if integration tests run
bparrishMines Jul 8, 2021
2025b84
change folder name
bparrishMines Jul 12, 2021
ddf5d91
create a running test with ./gradlew app:connectedAndroidTest -Ptarge…
bparrishMines Jul 13, 2021
562cc4d
see if tests run on ci?.
bparrishMines Jul 14, 2021
cad641b
fix a few tests
bparrishMines Jul 17, 2021
b94cfbb
try get all tests passing
bparrishMines Jul 17, 2021
744c395
fluttertestrunner and placeholder test
bparrishMines Jul 18, 2021
6d9f282
formatting
bparrishMines Jul 18, 2021
e5ea80c
fix blank test, formatting, license
bparrishMines Jul 18, 2021
2489c44
undo formatting change and remove navigation delegate
bparrishMines Jul 18, 2021
76d612e
Improve example test and version bump test dependencies
bparrishMines Jul 19, 2021
dc6be9a
remove assertequals
bparrishMines Jul 19, 2021
8713690
small format changes
bparrishMines Jul 19, 2021
648e94c
license
bparrishMines Jul 19, 2021
3619762
remove truth dependency, change core dep and follow example
bparrishMines Jul 19, 2021
ffe0058
undo the test change
bparrishMines Jul 19, 2021
f624087
Merge branch 'master' of github.com:flutter/plugins into androidTest
bparrishMines Jul 20, 2021
a10bfde
readd analysisoptions
bparrishMines Jul 20, 2021
42b7238
remove top line
bparrishMines Jul 20, 2021
927b9fe
empty commit to check for flakes
bparrishMines Jul 20, 2021
089fa76
skip tests
bparrishMines Jul 22, 2021
77b45f1
Merge branch 'master' of github.com:flutter/plugins into androidTest
bparrishMines Jul 22, 2021
7e73bb1
remove webview_flutter
bparrishMines Jul 22, 2021
79d82c4
Merge branch 'master' of github.com:flutter/plugins into androidTest
bparrishMines Jul 22, 2021
d34c705
Merge branch 'master' into androidTest
bparrishMines Jul 24, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ flutter {
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
api 'androidx.test:core:1.2.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.assertTrue;

import androidx.test.core.app.ActivityScenario;
import io.flutter.plugins.webviewflutter.WebViewFlutterPlugin;
import org.junit.Test;

public class WebViewTest {
@Test
public void webViewPluginIsAdded() {
final ActivityScenario<WebViewTestActivity> scenario =
ActivityScenario.launch(WebViewTestActivity.class);
scenario.onActivity(
activity -> {
assertTrue(activity.engine.getPlugins().has(WebViewFlutterPlugin.class));
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.flutter.plugins.webviewflutterexample">
<!-- Flutter needs it to communicate with the running application
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"needs internet permission to"

to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<application android:usesCleartextTraffic="true">
<activity
android:name=".WebViewTestActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.flutter.plugins.webviewflutterexample">

<application
android:usesCleartextTraffic="true"
android:icon="@mipmap/ic_launcher"
android:label="webview_flutter_example">
<meta-data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;

// Extends FlutterActivity to make the FlutterEngine accessible for testing.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about: Makes the FlutterEngine accessible for testing.

public class WebViewTestActivity extends FlutterActivity {
public FlutterEngine engine;

@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
super.configureFlutterEngine(flutterEngine);
engine = flutterEngine;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import 'package:integration_test/integration_test.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('initalUrl', (WidgetTester tester) async {
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
testWidgets('initialUrl', (WidgetTester tester) async {
final Completer<WebViewController> controllerCompleter =
Completer<WebViewController>();
await tester.pumpWidget(
Expand All @@ -36,8 +37,9 @@ void main() {
final WebViewController controller = await controllerCompleter.future;
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://flutter.dev/');
});
}, skip: true);

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
testWidgets('loadUrl', (WidgetTester tester) async {
final Completer<WebViewController> controllerCompleter =
Completer<WebViewController>();
Expand All @@ -57,8 +59,9 @@ void main() {
await controller.loadUrl('https://www.google.com/');
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://www.google.com/');
});
}, skip: true);

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
testWidgets('loadUrl with headers', (WidgetTester tester) async {
final Completer<WebViewController> controllerCompleter =
Completer<WebViewController>();
Expand Down Expand Up @@ -98,7 +101,7 @@ void main() {
final String content = await controller
.evaluateJavascript('document.documentElement.innerText');
expect(content.contains('flutter_test_header'), isTrue);
});
}, skip: Platform.isAndroid);

testWidgets('JavaScriptChannel', (WidgetTester tester) async {
final Completer<WebViewController> controllerCompleter =
Expand Down Expand Up @@ -274,6 +277,7 @@ void main() {
expect(customUserAgent2, 'Custom_User_Agent2');
});

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
testWidgets('use default platform userAgent after webView is rebuilt',
(WidgetTester tester) async {
final Completer<WebViewController> controllerCompleter =
Expand Down Expand Up @@ -323,7 +327,7 @@ void main() {

final String customUserAgent2 = await _getUserAgent(controller);
expect(customUserAgent2, defaultPlatformUserAgent);
});
}, skip: Platform.isAndroid);

group('Video playback policy', () {
late String videoTestBase64;
Expand Down Expand Up @@ -532,6 +536,7 @@ void main() {
expect(fullScreen, _webviewBool(false));
});

// allowsInlineMediaPlayback is a noop on Android, so it is skipped.
testWidgets(
'Video plays full screen when allowsInlineMediaPlayback is false',
(WidgetTester tester) async {
Expand Down Expand Up @@ -581,7 +586,7 @@ void main() {
String fullScreen =
await controller.evaluateJavascript('isFullScreen();');
expect(fullScreen, _webviewBool(true));
});
}, skip: Platform.isAndroid);
});

group('Audio playback policy', () {
Expand Down Expand Up @@ -796,6 +801,7 @@ void main() {
});

group('Programmatic Scroll', () {
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
testWidgets('setAndGetScrollPosition', (WidgetTester tester) async {
final String scrollTestPage = '''
<!DOCTYPE html>
Expand Down Expand Up @@ -870,7 +876,7 @@ void main() {
scrollPosY = await controller.getScrollY();
expect(scrollPosX, X_SCROLL * 2);
expect(scrollPosY, Y_SCROLL * 2);
});
}, skip: Platform.isAndroid);
});

group('SurfaceAndroidWebView', () {
Expand All @@ -882,6 +888,7 @@ void main() {
WebView.platform = null;
});

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
testWidgets('setAndGetScrollPosition', (WidgetTester tester) async {
final String scrollTestPage = '''
<!DOCTYPE html>
Expand Down Expand Up @@ -948,8 +955,9 @@ void main() {
scrollPosY = await controller.getScrollY();
expect(X_SCROLL * 2, scrollPosX);
expect(Y_SCROLL * 2, scrollPosY);
}, skip: !Platform.isAndroid);
}, skip: true);

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
testWidgets('inputs are scrolled into view when focused',
(WidgetTester tester) async {
final String scrollTestPage = '''
Expand Down Expand Up @@ -1053,7 +1061,7 @@ void main() {
lastInputClientRectRelativeToViewport['right'] <=
viewportRectRelativeToViewport['right'],
isTrue);
}, skip: !Platform.isAndroid);
}, skip: true);
});

group('NavigationDelegate', () {
Expand Down Expand Up @@ -1272,18 +1280,20 @@ 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")');
await pageLoaded.future;
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'about:blank');
expect(currentUrl, 'https://flutter.dev/');
});

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
testWidgets(
'can open new window and go back',
(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,
Expand All @@ -1301,15 +1311,22 @@ void main() {
),
);
final WebViewController controller = await controllerCompleter.future;
expect(controller.currentUrl(), completion('https://flutter.dev/'));
await pageLoaded.future;
pageLoaded = Completer<void>();

await controller
.evaluateJavascript('window.open("https://www.google.com")');
.evaluateJavascript('window.open("https://www.google.com/")');
await pageLoaded.future;
pageLoaded = Completer<void>();
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,
skip: true,
);

testWidgets(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
path: ../

dev_dependencies:
espresso: ^0.1.0+2
flutter_test:
sdk: flutter
flutter_driver:
Expand Down
1 change: 0 additions & 1 deletion script/configs/exclude_integration_android.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
- shared_preferences/shared_preferences
- url_launcher/url_launcher
- video_player/video_player
- webview_flutter

# Deprecated; no plan to backfill the missing files
- android_intent
Expand Down