summaryrefslogtreecommitdiff
path: root/java/tests
diff options
context:
space:
mode:
author Xin Li <delphij@google.com> 2023-08-31 11:53:07 -0700
committer Xin Li <delphij@google.com> 2023-08-31 12:31:11 -0700
commit70b8273014ff735ecf18aaeeaf6fa8c0f613fd49 (patch)
treed95426955fa9e901d023bb63c64fe7c037b8cf9e /java/tests
parent80bfff1f0eef6db4e061d9892450737e110bad59 (diff)
parent398f5f236f5165448798a4216c814d03a9b93555 (diff)
Merge UP1A.230905.019
Merged-In: I26c6eef24e7f909842eb066a73286a7525124d21 Change-Id: I5073cf615f25b0c211518909d033ea53fe50244e
Diffstat (limited to 'java/tests')
-rw-r--r--java/tests/src/com/android/intentresolver/ChooserActionFactoryTest.kt152
1 files changed, 113 insertions, 39 deletions
diff --git a/java/tests/src/com/android/intentresolver/ChooserActionFactoryTest.kt b/java/tests/src/com/android/intentresolver/ChooserActionFactoryTest.kt
index d72c9aa6..8d994f08 100644
--- a/java/tests/src/com/android/intentresolver/ChooserActionFactoryTest.kt
+++ b/java/tests/src/com/android/intentresolver/ChooserActionFactoryTest.kt
@@ -25,48 +25,45 @@ import android.content.IntentFilter
import android.content.res.Resources
import android.graphics.drawable.Icon
import android.service.chooser.ChooserAction
-import android.view.View
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
-import com.android.intentresolver.flags.FeatureFlagRepository
import com.google.common.collect.ImmutableList
import com.google.common.truth.Truth.assertThat
+import java.util.concurrent.CountDownLatch
+import java.util.concurrent.TimeUnit
+import java.util.function.Consumer
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito
-import java.util.concurrent.Callable
-import java.util.concurrent.CountDownLatch
-import java.util.concurrent.TimeUnit
-import java.util.function.Consumer
@RunWith(AndroidJUnit4::class)
class ChooserActionFactoryTest {
private val context = InstrumentationRegistry.getInstrumentation().getContext()
private val logger = mock<ChooserActivityLogger>()
- private val flags = mock<FeatureFlagRepository>()
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() {
- override fun onReceive(context: Context, intent: Intent) {
- // Just doing at most a single countdown per test.
- countdown.countDown()
+ private val testReceiver: BroadcastReceiver =
+ object : BroadcastReceiver() {
+ override fun onReceive(context: Context, intent: Intent) {
+ // Just doing at most a single countdown per test.
+ countdown.countDown()
+ }
}
- }
- private object resultConsumer : Consumer<Int> {
- var latestReturn = Integer.MIN_VALUE
+ private val resultConsumer =
+ object : Consumer<Int> {
+ var latestReturn = Integer.MIN_VALUE
- override fun accept(resultCode: Int) {
- latestReturn = resultCode
+ override fun accept(resultCode: Int) {
+ latestReturn = resultCode
+ }
}
- }
-
@Before
fun setup() {
context.registerReceiver(testReceiver, IntentFilter(testAction))
@@ -91,7 +88,7 @@ class ChooserActionFactoryTest {
Mockito.verify(logger).logCustomActionSelected(eq(0))
assertEquals(Activity.RESULT_OK, resultConsumer.latestReturn)
- // Verify the pendingintent has been called
+ // Verify the pending intent has been called
countdown.await(500, TimeUnit.MILLISECONDS)
}
@@ -109,42 +106,119 @@ class ChooserActionFactoryTest {
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))
+ Mockito.verify(logger)
+ .logActionSelected(eq(ChooserActivityLogger.SELECTION_TYPE_MODIFY_SHARE))
assertEquals(Activity.RESULT_OK, resultConsumer.latestReturn)
- // Verify the pendingintent has been called
+ // Verify the pending intent has been called
countdown.await(500, TimeUnit.MILLISECONDS)
}
+ @Test
+ fun nonSendAction_noCopyRunnable() {
+ val targetIntent =
+ Intent(Intent.ACTION_SEND_MULTIPLE).apply {
+ putExtra(Intent.EXTRA_TEXT, "Text to show")
+ }
+
+ val chooserRequest =
+ mock<ChooserRequestParameters> {
+ whenever(this.targetIntent).thenReturn(targetIntent)
+ whenever(chooserActions).thenReturn(ImmutableList.of())
+ }
+ val testSubject =
+ ChooserActionFactory(
+ context,
+ chooserRequest,
+ mock(),
+ logger,
+ {},
+ { null },
+ mock(),
+ {},
+ )
+ assertThat(testSubject.copyButtonRunnable).isNull()
+ }
+
+ @Test
+ fun sendActionNoText_noCopyRunnable() {
+ val targetIntent = Intent(Intent.ACTION_SEND)
+
+ val chooserRequest =
+ mock<ChooserRequestParameters> {
+ whenever(this.targetIntent).thenReturn(targetIntent)
+ whenever(chooserActions).thenReturn(ImmutableList.of())
+ }
+ val testSubject =
+ ChooserActionFactory(
+ context,
+ chooserRequest,
+ mock(),
+ logger,
+ {},
+ { null },
+ mock(),
+ {},
+ )
+ assertThat(testSubject.copyButtonRunnable).isNull()
+ }
+
+ @Test
+ fun sendActionWithText_nonNullCopyRunnable() {
+ val targetIntent = Intent(Intent.ACTION_SEND).apply { putExtra(Intent.EXTRA_TEXT, "Text") }
+
+ val chooserRequest =
+ mock<ChooserRequestParameters> {
+ whenever(this.targetIntent).thenReturn(targetIntent)
+ whenever(chooserActions).thenReturn(ImmutableList.of())
+ }
+ val testSubject =
+ ChooserActionFactory(
+ context,
+ chooserRequest,
+ mock(),
+ logger,
+ {},
+ { null },
+ mock(),
+ {},
+ )
+ assertThat(testSubject.copyButtonRunnable).isNotNull()
+ }
+
private fun createFactory(includeModifyShare: Boolean = false): ChooserActionFactory {
- val testPendingIntent = PendingIntent.getActivity(context, 0, Intent(testAction),0)
+ val testPendingIntent = PendingIntent.getActivity(context, 0, Intent(testAction), 0)
val targetIntent = Intent()
- val action = ChooserAction.Builder(
- Icon.createWithResource("", Resources.ID_NULL),
- actionLabel,
- testPendingIntent
- ).build()
+ val action =
+ ChooserAction.Builder(
+ Icon.createWithResource("", Resources.ID_NULL),
+ actionLabel,
+ testPendingIntent
+ )
+ .build()
val chooserRequest = mock<ChooserRequestParameters>()
whenever(chooserRequest.targetIntent).thenReturn(targetIntent)
whenever(chooserRequest.chooserActions).thenReturn(ImmutableList.of(action))
if (includeModifyShare) {
- val modifyShare = ChooserAction.Builder(
- Icon.createWithResource("", Resources.ID_NULL),
- modifyShareLabel,
- testPendingIntent
- ).build()
+ val modifyShare =
+ ChooserAction.Builder(
+ Icon.createWithResource("", Resources.ID_NULL),
+ modifyShareLabel,
+ testPendingIntent
+ )
+ .build()
whenever(chooserRequest.modifyShareAction).thenReturn(modifyShare)
}
return ChooserActionFactory(
context,
chooserRequest,
- mock<ChooserIntegratedDeviceComponents>(),
+ mock(),
logger,
- Consumer<Boolean>{},
- Callable<View?>{null},
- mock<ChooserActionFactory.ActionActivityStarter>(),
- resultConsumer)
+ {},
+ { null },
+ mock(),
+ resultConsumer
+ )
}
-} \ No newline at end of file
+}