summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-01-28 04:50:21 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-01-28 04:50:21 +0000
commit4b97c9dbe58f24b4490827999bbd49f5bdee3d90 (patch)
tree521bb68bd624ebe4374b4971e3cac81b3b02ba39
parentddba82ce350959307cca0f54ea9f06ca2f947fca (diff)
parente8319743accc1b7fb7205b8ee4fac5f48e2af3ef (diff)
downloadcts-snap-temp-L71600030001638955.tar.gz
Merge "[CDM][CTS] Make SystemDataTransferTest backward compatible" into snap-temp-L71600030001638955snap-temp-L71600030001638955
-rw-r--r--tests/tests/companion/uiautomation/src/android/companion/cts/uiautomation/SystemDataTransferTest.kt136
1 files changed, 64 insertions, 72 deletions
diff --git a/tests/tests/companion/uiautomation/src/android/companion/cts/uiautomation/SystemDataTransferTest.kt b/tests/tests/companion/uiautomation/src/android/companion/cts/uiautomation/SystemDataTransferTest.kt
index a540bf38799..7033f591d60 100644
--- a/tests/tests/companion/uiautomation/src/android/companion/cts/uiautomation/SystemDataTransferTest.kt
+++ b/tests/tests/companion/uiautomation/src/android/companion/cts/uiautomation/SystemDataTransferTest.kt
@@ -32,6 +32,7 @@ import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.PipedInputStream
import java.io.PipedOutputStream
+import java.lang.IllegalStateException
import java.nio.ByteBuffer
import java.nio.charset.StandardCharsets
import java.util.concurrent.CountDownLatch
@@ -40,9 +41,11 @@ import java.util.concurrent.TimeoutException
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicReference
import kotlin.test.assertEquals
+import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import libcore.util.EmptyArray
+import org.junit.Assume.assumeTrue
import org.junit.Test
import org.junit.runner.RunWith
@@ -56,11 +59,25 @@ import org.junit.runner.RunWith
class SystemDataTransferTest : UiAutomationTestBase(null, null) {
companion object {
private const val SYSTEM_DATA_TRANSFER_TIMEOUT = 10L // 10 seconds
+
+ private const val ACTION_CLICK_ALLOW = 1
+ private const val ACTION_CLICK_DISALLOW = 2
+ private const val ACTION_PRESS_BACK = 3
}
@CallSuper
override fun setUp() {
super.setUp()
+
+ // Assume Permission Transfer is enabled, otherwise skip the test.
+ try {
+ val association = associate()
+ cdm.buildPermissionTransferUserConsentIntent(association.id)
+ true
+ } catch (e: UnsupportedOperationException) {
+ false
+ }.apply { assumeTrue("This test requires Permission Transfer to be enabled.", this) }
+
withShellPermissionIdentity(MANAGE_COMPANION_DEVICES) {
cdm.enableSecureTransport(false)
}
@@ -75,92 +92,58 @@ class SystemDataTransferTest : UiAutomationTestBase(null, null) {
}
@Test
- fun test_userConsentDialogAllowed() {
- val association1 = associate()
-
- // First time request permission transfer should prompt a dialog
- val pendingUserConsent = cdm.buildPermissionTransferUserConsentIntent(association1.id)
- assertNotNull(pendingUserConsent)
- CompanionActivity.startIntentSender(pendingUserConsent)
- confirmationUi.waitUntilSystemDataTransferConfirmationVisible()
- confirmationUi.clickPositiveButton()
- val (resultCode: Int, _: Intent?) = CompanionActivity.waitForActivityResult()
- assertEquals(expected = RESULT_OK, actual = resultCode)
+ fun test_userConsent_allow() {
+ val association = associate()
- // Second time request permission transfer should get non null IntentSender
- val pendingUserConsent2 = cdm.buildPermissionTransferUserConsentIntent(association1.id)
- assertNotNull(pendingUserConsent2)
+ val resultCode = requestPermissionTransferUserConsent(association.id, ACTION_CLICK_ALLOW)
- // disassociate() should clean up the requests
- cdm.disassociate(association1.id)
- Thread.sleep(2_100)
- val association2 = associate()
- val pendingUserConsent3 = cdm.buildPermissionTransferUserConsentIntent(association2.id)
- assertNotNull(pendingUserConsent3)
+ assertEquals(expected = RESULT_OK, actual = resultCode)
}
@Test
- fun test_userConsentDialogDisallowed() {
- val association1 = associate()
+ fun test_userConsent_disallow() {
+ val association = associate()
+
+ val resultCode = requestPermissionTransferUserConsent(
+ association.id,
+ ACTION_CLICK_DISALLOW
+ )
- // First time request permission transfer should prompt a dialog
- val pendingUserConsent = cdm.buildPermissionTransferUserConsentIntent(association1.id)
- assertNotNull(pendingUserConsent)
- CompanionActivity.startIntentSender(pendingUserConsent)
- confirmationUi.waitUntilSystemDataTransferConfirmationVisible()
- confirmationUi.clickNegativeButton()
- val (resultCode: Int, _: Intent?) = CompanionActivity.waitForActivityResult()
assertEquals(expected = RESULT_CANCELED, actual = resultCode)
+ }
- // Second time request permission transfer should get non null IntentSender
- val pendingUserConsent2 = cdm.buildPermissionTransferUserConsentIntent(association1.id)
- assertNotNull(pendingUserConsent2)
+ @Test
+ fun test_userConsent_cancel() {
+ val association = associate()
- // disassociate() should clean up the requests
- cdm.disassociate(association1.id)
- Thread.sleep(2_100)
- val association2 = associate()
- val pendingUserConsent3 = cdm.buildPermissionTransferUserConsentIntent(association2.id)
- assertNotNull(pendingUserConsent3)
+ requestPermissionTransferUserConsent(association.id, ACTION_PRESS_BACK)
}
@Test
- fun test_userConsentDialogCanceled() {
- val association1 = associate()
+ fun test_userConsent_allowThenDisallow() {
+ val association = associate()
- // First time request permission transfer should prompt a dialog
- val pendingUserConsent = cdm.buildPermissionTransferUserConsentIntent(association1.id)
- assertNotNull(pendingUserConsent)
- CompanionActivity.startIntentSender(pendingUserConsent)
- confirmationUi.waitUntilSystemDataTransferConfirmationVisible()
- uiDevice.pressBack()
+ val resultCode = requestPermissionTransferUserConsent(association.id, ACTION_CLICK_ALLOW)
- // Second time request permission transfer should prompt a dialog
- val pendingUserConsent2 = cdm.buildPermissionTransferUserConsentIntent(association1.id)
- assertNotNull(pendingUserConsent2)
+ assertEquals(expected = RESULT_OK, actual = resultCode)
+
+ val resultCode2 = requestPermissionTransferUserConsent(
+ association.id,
+ ACTION_CLICK_DISALLOW
+ )
+ assertEquals(expected = RESULT_CANCELED, actual = resultCode2)
}
@Test
- fun test_userConsentDialogAllowedAndThenDisallowed() {
- val association1 = associate()
+ fun test_userConsent_disallowThenAllow() {
+ val association = associate()
- // First time request permission transfer should prompt a dialog
- val pendingUserConsent = cdm.buildPermissionTransferUserConsentIntent(association1.id)
- assertNotNull(pendingUserConsent)
- CompanionActivity.startIntentSender(pendingUserConsent)
- confirmationUi.waitUntilSystemDataTransferConfirmationVisible()
- confirmationUi.clickPositiveButton()
- val (resultCode: Int, _: Intent?) = CompanionActivity.waitForActivityResult()
- assertEquals(expected = RESULT_OK, actual = resultCode)
+ val resultCode = requestPermissionTransferUserConsent(association.id, ACTION_CLICK_DISALLOW)
- // Second time request permission transfer should prompt a dialog
- val pendingUserConsent2 = cdm.buildPermissionTransferUserConsentIntent(association1.id)
- assertNotNull(pendingUserConsent2)
- CompanionActivity.startIntentSender(pendingUserConsent2)
- confirmationUi.waitUntilSystemDataTransferConfirmationVisible()
- confirmationUi.clickNegativeButton()
- val (resultCode2: Int, _: Intent?) = CompanionActivity.waitForActivityResult()
- assertEquals(expected = RESULT_CANCELED, actual = resultCode2)
+ assertEquals(expected = RESULT_CANCELED, actual = resultCode)
+
+ val resultCode2 = requestPermissionTransferUserConsent(association.id, ACTION_CLICK_ALLOW)
+ assertEquals(expected = RESULT_OK, actual = resultCode2)
}
/**
@@ -185,7 +168,7 @@ class SystemDataTransferTest : UiAutomationTestBase(null, null) {
@Test
fun test_startSystemDataTransfer_success() {
val association = associate()
- requestPermissionTransferUserConsent(association.id)
+ requestPermissionTransferUserConsent(association.id, ACTION_CLICK_ALLOW)
// Generate data packet with successful response
val response = generatePacket(MESSAGE_RESPONSE_SUCCESS, "SUCCESS")
@@ -199,7 +182,7 @@ class SystemDataTransferTest : UiAutomationTestBase(null, null) {
@Test(expected = CompanionException::class)
fun test_startSystemDataTransfer_failure() {
val association = associate()
- requestPermissionTransferUserConsent(association.id)
+ requestPermissionTransferUserConsent(association.id, ACTION_CLICK_ALLOW)
// Generate data packet with failure as response
val response = generatePacket(MESSAGE_RESPONSE_FAILURE, "FAILURE")
@@ -265,12 +248,21 @@ class SystemDataTransferTest : UiAutomationTestBase(null, null) {
* Execute UI flow to request user consent for permission transfer for a given association
* and grant permission.
*/
- private fun requestPermissionTransferUserConsent(associationId: Int) {
+ private fun requestPermissionTransferUserConsent(associationId: Int, action: Int): Int {
val pendingUserConsent = cdm.buildPermissionTransferUserConsentIntent(associationId)
CompanionActivity.startIntentSender(pendingUserConsent!!)
confirmationUi.waitUntilSystemDataTransferConfirmationVisible()
- confirmationUi.clickPositiveButton()
- CompanionActivity.waitForActivityResult()
+ when (action) {
+ ACTION_CLICK_ALLOW -> confirmationUi.clickPositiveButton()
+ ACTION_CLICK_DISALLOW -> confirmationUi.clickNegativeButton()
+ ACTION_PRESS_BACK -> {
+ uiDevice.pressBack()
+ return -100 // an invalid result code which shouldn't be checked against
+ }
+ else -> throw IllegalStateException("Unknown action.")
+ }
+ val (resultCode: Int, _: Intent?) = CompanionActivity.waitForActivityResult()
+ return resultCode
}
/**