Skip to content

Commit c6b86c5

Browse files
[file_selector_android] Attempt to close system dialogs before integration tests run (#5805)
Attempt to close any system dialogs before running the test. This idea came from https://stackoverflow.com/questions/39457305/android-testing-waited-for-the-root-of-the-view-hierarchy-to-have-window-focus. There may be a system dialog before the test runs that prevents the FlutterView from getting focus. Which also prevents any of the espresso actions to run ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use `dart format`.) - [x] I signed the [CLA]. - [x] The title of the PR starts with the name of the package 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], or this PR is [exempt from version changes]. - [ ] I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [relevant style guides]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat [pub versioning philosophy]: https://dart.dev/tools/pub/versioning [exempt from version changes]: https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#version-and-changelog-updates [following repository CHANGELOG style]: https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changelog-style [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
1 parent e573185 commit c6b86c5

File tree

1 file changed

+19
-0
lines changed
  • packages/file_selector/file_selector_android/example/android/app/src/androidTest/java/dev/flutter/packages/file_selector_android_example

1 file changed

+19
-0
lines changed

packages/file_selector/file_selector_android/example/android/app/src/androidTest/java/dev/flutter/packages/file_selector_android_example/FileSelectorAndroidTest.java

+19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.content.ClipData;
2121
import android.content.Intent;
2222
import android.net.Uri;
23+
import androidx.test.core.app.ActivityScenario;
2324
import androidx.test.espresso.intent.rule.IntentsRule;
2425
import androidx.test.ext.junit.rules.ActivityScenarioRule;
2526
import org.junit.Rule;
@@ -32,12 +33,28 @@ public class FileSelectorAndroidTest {
3233

3334
@Rule public IntentsRule intentsRule = new IntentsRule();
3435

36+
public void clearAnySystemDialog() {
37+
myActivityTestRule
38+
.getScenario()
39+
.onActivity(
40+
new ActivityScenario.ActivityAction<DriverExtensionActivity>() {
41+
@Override
42+
public void perform(DriverExtensionActivity activity) {
43+
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
44+
activity.sendBroadcast(closeDialog);
45+
}
46+
});
47+
}
48+
3549
@Test
3650
public void openImageFile() {
51+
clearAnySystemDialog();
52+
3753
final Instrumentation.ActivityResult result =
3854
new Instrumentation.ActivityResult(
3955
Activity.RESULT_OK,
4056
new Intent().setData(Uri.parse("content://file_selector_android_test/dummy.png")));
57+
4158
intending(hasAction(Intent.ACTION_OPEN_DOCUMENT)).respondWith(result);
4259
onFlutterWidget(withText("Open an image")).perform(click());
4360
onFlutterWidget(withText("Press to open an image file(png, jpg)")).perform(click());
@@ -48,6 +65,8 @@ public void openImageFile() {
4865

4966
@Test
5067
public void openImageFiles() {
68+
clearAnySystemDialog();
69+
5170
final ClipData.Item clipDataItem =
5271
new ClipData.Item(Uri.parse("content://file_selector_android_test/dummy.png"));
5372
final ClipData clipData = new ClipData("", new String[0], clipDataItem);

0 commit comments

Comments
 (0)