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

Conversation

@bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Oct 29, 2021

Split of #4455

After reading through https://flutter.dev/docs/cookbook/testing/widget/introduction. It seems that this test isn't using a Widget test in the expected way. After more testing, the current solution does work in updating the widget, but still has a false positive for the 2nd reason below.

1. It's attempting to change the size of a WebView by pumping a new Widget.
2. I was able to make this test fail by adding a await Future.delayed(Duration(seconds: 2)); before the boolean check. This shows that resize is called regardless of changing the width and height.

This PR follows the Flutter cookbook example of a Widget test and creates a widget that changes the WebView on a button press. It also waits for the initial resize of the WebView from the initial load.

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.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • 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 Oct 29, 2021
@github-actions github-actions bot added p: webview_flutter Edits files for a webview_flutter plugin platform-android labels Oct 29, 2021
@bparrishMines bparrishMines changed the title fix resize test Fix Flaky Resize Test Oct 29, 2021
),
);
));
await tester.pump(Duration(seconds: 3));
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 is required to wait for the initial resize of the WebView. The line await pageFinishedCompleter.future; can finish before this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please capture this in a code comment, as it's non-obvious.

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 with nits.

(Related though: do we need three copies of this test? It's not clear to me where exactly the functionality that it's intended to test lives; are there important parts that live in both native an app-facing-package-dart?)

),
);
));
await tester.pump(Duration(seconds: 3));
Copy link
Contributor

Choose a reason for hiding this comment

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

Please capture this in a code comment, as it's non-obvious.

),
);
await tester.tap(find.byKey(const ValueKey('resizeButton')));
await tester.pump(Duration(seconds: 3));
Copy link
Contributor

Choose a reason for hiding this comment

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

How were the 3-second values chosen? It seems like a very arbitrary number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is mostly arbitrarily chosen :/. I just chose a safe value to wait for. I considered just waiting for the first call to resize, but I wasn't 100% sure it gets called every time on every platform.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, so it this always waiting 3 seconds? I'm not all that familiar with widget tests; I assumed this was a timeout. If it's a static 3 second wait, that's still going to be a source of flake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. I changed the tests to wait for resize completers.

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

amantoux pushed a commit to amantoux/plugins that referenced this pull request Dec 11, 2021
KyleFin pushed a commit to KyleFin/plugins that referenced this pull request Dec 21, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants