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

Conversation

bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Jul 8, 2021

Integration tests weren't running since they were in the androidTestDebug folder and not a androidTest folder. This changes the folder name and fix the tests that weren't running.

Part of: flutter/flutter#83358

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Note that unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@google-cla google-cla bot added the cla: yes label Jul 8, 2021
@github-actions github-actions bot added p: webview_flutter Edits files for a webview_flutter plugin platform-android labels Jul 8, 2021
@@ -9,6 +9,7 @@
<application
android:icon="@mipmap/ic_launcher"
android:label="webview_flutter_example"
android:usesCleartextTraffic="true"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the espresso package

@@ -532,6 +535,7 @@ void main() {
expect(fullScreen, _webviewBool(false));
});

// allowsInlineMediaPlayback is a noop on Android, so it is skipped.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/flutter/plugins/blob/master/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebView.java#L397

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.

@@ -1272,18 +1276,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")');
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 window.open is called with a url with https:// vs not. It loads normally when using a URL with https://, but appends the url to the current url when it doesnt. (e.g. https://flutter.dev/ turns into https://flutter.dev/about:blank)

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',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the weird bug where pageLoaded.complete() was called in the callback multiple times. From the Dart side, this caused a silent error and prevented the rest of the method calls from going through.

@bparrishMines bparrishMines changed the title lets see if integration tests run Fix webview_flutter Android integration tests Jul 18, 2021
@bparrishMines bparrishMines changed the title Fix webview_flutter Android integration tests Fix webview_flutter Android integration tests and add Expresso Jul 18, 2021
@stuartmorgan-g stuartmorgan-g changed the title Fix webview_flutter Android integration tests and add Expresso Fix webview_flutter Android integration tests and add Espresso Jul 19, 2021
@@ -0,0 +1,21 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is needed to use WebViewTestActivity.

@@ -56,7 +56,8 @@ flutter {

dependencies {
testImplementation 'junit:junit:4.12'
testImplementation "com.google.truth:truth:1.0"
Copy link

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?

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM!

@bparrishMines
Copy link
Contributor Author

@stuartmorgan @blasten I think this PR is ready to go, but the tests seem to be pretty flaky. Is it alright to submit this if the integration tests require 2-3 runs to pass? Should I investigate more about why they are flaky or could I just skip the flaky ones for now?

@stuartmorgan-g
Copy link
Contributor

@stuartmorgan @blasten I think this PR is ready to go, but the tests seem to be pretty flaky. Is it alright to submit this if the integration tests require 2-3 runs to pass? Should I investigate more about why they are flaky or could I just skip the flaky ones for now?

Let's skip the flaky tests, with a bug filed to follow up (please CC me, and mark it team)

@stuartmorgan-g
Copy link
Contributor

stuartmorgan-g commented Jul 22, 2021

With #4172 landed, you'll need to have this PR remove webview_flutter from the exclude list (currently in .cirrus.yml, but #4183 moves it if that lands before this does).

@bparrishMines
Copy link
Contributor Author

@stuartmorgan @blasten I skipped the flaky tests and added a link to flutter/flutter#86757. PTAL and I'll merge

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

Wow, that's a lot of flakes :(

But LGTM

@bparrishMines bparrishMines added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Jul 26, 2021
@fluttergithubbot fluttergithubbot merged commit 1dce6ab into flutter:master Jul 26, 2021
@bparrishMines bparrishMines deleted the androidTest branch July 26, 2021 18:35
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 27, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 27, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 27, 2021
@@ -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"

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.

fotiDim pushed a commit to fotiDim/plugins that referenced this pull request Sep 13, 2021
amantoux pushed a commit to amantoux/plugins that referenced this pull request Sep 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes p: webview_flutter Edits files for a webview_flutter plugin platform-android waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants