Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[file_selector_android] Attempt to close system dialogs before integration tests run #5805

Merged
merged 6 commits into from
Jan 4, 2024
Merged
Changes from all commits
Commits
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 @@ -20,6 +20,7 @@
import android.content.ClipData;
import android.content.Intent;
import android.net.Uri;
import androidx.test.core.app.ActivityScenario;
import androidx.test.espresso.intent.rule.IntentsRule;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import org.junit.Rule;
Expand All @@ -32,12 +33,28 @@ public class FileSelectorAndroidTest {

@Rule public IntentsRule intentsRule = new IntentsRule();

public void clearAnySystemDialog() {
myActivityTestRule
.getScenario()
.onActivity(
new ActivityScenario.ActivityAction<DriverExtensionActivity>() {
@Override
public void perform(DriverExtensionActivity activity) {
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
activity.sendBroadcast(closeDialog);
}
});
}

@Test
public void openImageFile() {
clearAnySystemDialog();

final Instrumentation.ActivityResult result =
new Instrumentation.ActivityResult(
Activity.RESULT_OK,
new Intent().setData(Uri.parse("content://file_selector_android_test/dummy.png")));

intending(hasAction(Intent.ACTION_OPEN_DOCUMENT)).respondWith(result);
onFlutterWidget(withText("Open an image")).perform(click());
onFlutterWidget(withText("Press to open an image file(png, jpg)")).perform(click());
Expand All @@ -48,6 +65,8 @@ public void openImageFile() {

@Test
public void openImageFiles() {
clearAnySystemDialog();

final ClipData.Item clipDataItem =
new ClipData.Item(Uri.parse("content://file_selector_android_test/dummy.png"));
final ClipData clipData = new ClipData("", new String[0], clipDataItem);
Expand Down