From 7c05ee5c8b7c934776d1c74a558f29dadde5ee9d Mon Sep 17 00:00:00 2001 From: 1 Date: Thu, 9 Mar 2023 22:01:50 +0000 Subject: Switch EXTRA_MODIFY_SHARE from PendingIntent to ChooserAction Honor the label provided in the action. Bug: 272008339 Test: atest IntentResolverUnitTests Test: atest CtsSharesheetDeviceTest Change-Id: I48f9bb46f1be1f8ab42a93169b4c5ab332cd8400 --- .../android/intentresolver/ChooserActionFactoryTest.kt | 12 ++++++++++-- .../intentresolver/UnbundledChooserActivityTest.java | 16 ++++++++++------ .../contentpreview/ChooserContentPreviewUiTest.kt | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) (limited to 'java/tests/src') diff --git a/java/tests/src/com/android/intentresolver/ChooserActionFactoryTest.kt b/java/tests/src/com/android/intentresolver/ChooserActionFactoryTest.kt index af134fcd..98c7d5ee 100644 --- a/java/tests/src/com/android/intentresolver/ChooserActionFactoryTest.kt +++ b/java/tests/src/com/android/intentresolver/ChooserActionFactoryTest.kt @@ -33,6 +33,7 @@ import com.android.intentresolver.flags.Flags import com.google.common.collect.ImmutableList import com.google.common.truth.Truth.assertThat import org.junit.After +import org.junit.Assert import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Test @@ -50,6 +51,7 @@ class ChooserActionFactoryTest { private val logger = mock() private val flags = mock() private val actionLabel = "Action label" + private val modifyShareLabel = "Modify share" private val testAction = "com.android.intentresolver.testaction" private val countdown = CountDownLatch(1) private val testReceiver: BroadcastReceiver = object : BroadcastReceiver() { @@ -115,7 +117,8 @@ class ChooserActionFactoryTest { fun testModifyShareAction() { val factory = createFactory(includeModifyShare = true) - factory.modifyShareAction!!.run() + val action = factory.modifyShareAction ?: error("Modify share action should not be null") + action.onClicked.run() Mockito.verify(logger).logActionSelected( eq(ChooserActivityLogger.SELECTION_TYPE_MODIFY_SHARE)) @@ -137,7 +140,12 @@ class ChooserActionFactoryTest { whenever(chooserRequest.chooserActions).thenReturn(ImmutableList.of(action)) if (includeModifyShare) { - whenever(chooserRequest.modifyShareAction).thenReturn(testPendingIntent) + val modifyShare = ChooserAction.Builder( + Icon.createWithResource("", Resources.ID_NULL), + modifyShareLabel, + testPendingIntent + ).build() + whenever(chooserRequest.modifyShareAction).thenReturn(modifyShare) } return ChooserActionFactory( diff --git a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java index 0aab0536..65e95e30 100644 --- a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java +++ b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java @@ -1726,13 +1726,17 @@ public class UnbundledChooserActivityTest { Context testContext = InstrumentationRegistry.getInstrumentation().getContext(); final String modifyShareAction = "test-broadcast-receiver-action"; Intent chooserIntent = Intent.createChooser(createSendTextIntent(), null); + String label = "modify share"; + PendingIntent pendingIntent = PendingIntent.getBroadcast( + testContext, + 123, + new Intent(modifyShareAction), + PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ONE_SHOT); + ChooserAction action = new ChooserAction.Builder(Icon.createWithBitmap( + createBitmap()), label, pendingIntent).build(); chooserIntent.putExtra( Intent.EXTRA_CHOOSER_MODIFY_SHARE_ACTION, - PendingIntent.getBroadcast( - testContext, - 123, - new Intent(modifyShareAction), - PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ONE_SHOT)); + action); // Start activity mActivityRule.launchActivity(chooserIntent); waitForIdle(); @@ -1747,7 +1751,7 @@ public class UnbundledChooserActivityTest { testContext.registerReceiver(testReceiver, new IntentFilter(modifyShareAction)); try { - onView(withText(R.string.select_text)).perform(click()); + onView(withText(label)).perform(click()); broadcastInvoked.await(); } finally { testContext.unregisterReceiver(testReceiver); diff --git a/java/tests/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUiTest.kt b/java/tests/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUiTest.kt index d870a8c2..23bfaf9f 100644 --- a/java/tests/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUiTest.kt +++ b/java/tests/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUiTest.kt @@ -54,7 +54,7 @@ class ChooserContentPreviewUiTest { override fun createEditButton(): ActionRow.Action? = null override fun createNearbyButton(): ActionRow.Action? = null override fun createCustomActions(): List = emptyList() - override fun getModifyShareAction(): Runnable? = null + override fun getModifyShareAction(): ActionRow.Action? = null override fun getExcludeSharedTextAction(): Consumer = Consumer {} } private val transitionCallback = mock() -- cgit v1.2.3-59-g8ed1b