From a9bdc945c5623673a0ed630c548d7e561cb71e2c Mon Sep 17 00:00:00 2001 From: Andrey Epin Date: Tue, 31 Jan 2023 11:00:59 -0800 Subject: A payload re-selection test A Chooser payload reselection integration test. Bug: 262276456 Test: presubmits Change-Id: Ibd1560ce2f70028ffb7ea398a3f3fea1213e8094 --- .../UnbundledChooserActivityTest.java | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'java') diff --git a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java index 53c357d6..6f46201a 100644 --- a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java +++ b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java @@ -1739,6 +1739,64 @@ public class UnbundledChooserActivityTest { } } + @Test + public void testLaunchWithPayloadReselection() throws InterruptedException { + ChooserActivityOverrideData.getInstance().featureFlagRepository = + new FeatureFlagRepository() { + @Override + public boolean isEnabled(@NonNull UnreleasedFlag flag) { + return Flags.SHARESHEET_RESELECTION_ACTION.equals(flag) + || flag.getDefault(); + } + + @Override + public boolean isEnabled(@NonNull ReleasedFlag flag) { + return false; + } + }; + List resolvedComponentInfos = createResolvedComponentsForTest(2); + when( + ChooserActivityOverrideData + .getInstance() + .resolverListController + .getResolversForIntent( + Mockito.anyBoolean(), + Mockito.anyBoolean(), + Mockito.anyBoolean(), + Mockito.isA(List.class))) + .thenReturn(resolvedComponentInfos); + + Context testContext = InstrumentationRegistry.getInstrumentation().getContext(); + final String reselectionAction = "test-broadcast-receiver-action"; + Intent chooserIntent = Intent.createChooser(createSendTextIntent(), null); + chooserIntent.putExtra( + Intent.EXTRA_CHOOSER_PAYLOAD_RESELECTION_ACTION, + PendingIntent.getBroadcast( + testContext, + 123, + new Intent(reselectionAction), + PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ONE_SHOT)); + // Start activity + mActivityRule.launchActivity(chooserIntent); + waitForIdle(); + + final CountDownLatch broadcastInvoked = new CountDownLatch(1); + BroadcastReceiver testReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + broadcastInvoked.countDown(); + } + }; + testContext.registerReceiver(testReceiver, new IntentFilter(reselectionAction)); + + try { + onView(withText(R.string.select_text)).perform(click()); + broadcastInvoked.await(); + } finally { + testContext.unregisterReceiver(testReceiver); + } + } + @Test public void testUpdateMaxTargetsPerRow_columnCountIsUpdated() throws InterruptedException { updateMaxTargetsPerRowResource(/* targetsPerRow= */ 4); -- cgit v1.2.3-59-g8ed1b