summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYeabkal Wubshit <yeabkal@google.com>2024-02-28 20:17:35 -0800
committerYeabkal Wubshit <yeabkal@google.com>2024-02-29 22:54:24 +0000
commit60508898c865eba3829b42017d22bd7f44a64622 (patch)
treeaf45b4b9b8a6479bcd0a0cf50882f598c7892c97
parenta80c18bc637a163fe652c1a68d69b54282128a62 (diff)
downloadPermission-60508898c865eba3829b42017d22bd7f44a64622.tar.gz
[RoleManagerTest][Wear]Use text selector for some buttonstemp_319669529
The resource selectors are not alwalys working well for Wear's Compose based UI, so we're here using text selectors, which work well. Bug: 312618575 Test: atest RoleManagerTest Merged-In: I9355c44d196061398015858c96f51bc78f8e4374 Change-Id: I9355c44d196061398015858c96f51bc78f8e4374
-rw-r--r--tests/cts/role/src/android/app/role/cts/RoleManagerTest.java30
1 files changed, 20 insertions, 10 deletions
diff --git a/tests/cts/role/src/android/app/role/cts/RoleManagerTest.java b/tests/cts/role/src/android/app/role/cts/RoleManagerTest.java
index c4fa9be93..001a761c2 100644
--- a/tests/cts/role/src/android/app/role/cts/RoleManagerTest.java
+++ b/tests/cts/role/src/android/app/role/cts/RoleManagerTest.java
@@ -129,6 +129,17 @@ public class RoleManagerTest {
private static final boolean sIsWatch = sPackageManager.hasSystemFeature(
PackageManager.FEATURE_WATCH);
+ // TODO(b/327528959): consider using resource selectors for Wear too, once the underlying
+ // issue is handled.
+ private static final BySelector NEGATIVE_BUTTON_SELECTOR =
+ sIsWatch ? By.text("Cancel") : By.res("android:id/button2");
+ private static final BySelector POSITIVE_BUTTON_SELECTOR =
+ sIsWatch ? By.text("Set as default") : By.res("android:id/button1");
+ private static final BySelector DONT_ASK_AGAIN_TOGGLE_SELECTOR =
+ sIsWatch
+ ? By.text("Don\u2019t ask again")
+ : By.res("com.android.permissioncontroller:id/dont_ask_again");
+
@Rule
public DisableAnimationRule mDisableAnimationRule = new DisableAnimationRule();
@@ -295,7 +306,7 @@ public class RoleManagerTest {
TestUtils.waitUntil("Find and respond to request role UI", () -> {
requestRole(ROLE_NAME);
- UiObject2 cancelButton = waitFindObjectOrNull(By.res("android:id/button2"));
+ UiObject2 cancelButton = waitFindObjectOrNull(NEGATIVE_BUTTON_SELECTOR);
if (cancelButton == null) {
// Dialog not found, try again later.
return false;
@@ -331,7 +342,7 @@ public class RoleManagerTest {
TestUtils.waitUntil("Find and respond to request role UI", () -> {
requestRole(ROLE_NAME);
- UiObject2 cancelButton = waitFindObjectOrNull(By.res("android:id/button2"));
+ UiObject2 cancelButton = waitFindObjectOrNull(NEGATIVE_BUTTON_SELECTOR);
if (cancelButton == null) {
// Dialog not found, try again later.
return false;
@@ -401,10 +412,9 @@ public class RoleManagerTest {
@Nullable
private UiObject2 findDontAskAgainCheck(boolean expected) throws UiObjectNotFoundException {
- BySelector selector = By.res("com.android.permissioncontroller:id/dont_ask_again");
return expected
- ? waitFindObject(selector)
- : waitFindObjectOrNull(selector, UNEXPECTED_TIMEOUT_MILLIS);
+ ? waitFindObject(DONT_ASK_AGAIN_TOGGLE_SELECTOR)
+ : waitFindObjectOrNull(DONT_ASK_AGAIN_TOGGLE_SELECTOR, UNEXPECTED_TIMEOUT_MILLIS);
}
@Nullable
@@ -415,7 +425,7 @@ public class RoleManagerTest {
@NonNull
private Pair<Integer, Intent> clickButtonAndWaitForResult(boolean positive)
throws InterruptedException, UiObjectNotFoundException {
- waitFindObject(By.res(positive ? "android:id/button1" : "android:id/button2")).click();
+ waitFindObject(positive ? POSITIVE_BUTTON_SELECTOR : NEGATIVE_BUTTON_SELECTOR).click();
return waitForResult();
}
@@ -478,7 +488,7 @@ public class RoleManagerTest {
.putExtra(Intent.EXTRA_PACKAGE_NAME, APP_28_PACKAGE_NAME)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
waitFindObject(By.text(APP_28_LABEL)).click();
- waitFindObject(By.res("android:id/button1")).click();
+ waitFindObject(POSITIVE_BUTTON_SELECTOR).click();
// TODO(b/149037075): Use TelecomManager.getDefaultDialerPackage() once the bug is fixed.
//TelecomManager telecomManager = sContext.getSystemService(TelecomManager.class);
@@ -499,7 +509,7 @@ public class RoleManagerTest {
.putExtra(Intent.EXTRA_PACKAGE_NAME, APP_28_PACKAGE_NAME)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
waitFindObject(By.text(APP_28_LABEL)).click();
- waitFindObject(By.res("android:id/button1")).click();
+ waitFindObject(POSITIVE_BUTTON_SELECTOR).click();
TestUtils.waitUntil("App is not set as default sms app", () -> Objects.equals(
Telephony.Sms.getDefaultSmsPackage(sContext), APP_28_PACKAGE_NAME));
@@ -551,7 +561,7 @@ public class RoleManagerTest {
.putExtra(Intent.EXTRA_PACKAGE_NAME, APP_PACKAGE_NAME)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
waitFindObject(By.text(APP_LABEL)).click();
- waitFindObject(By.res("android:id/button1")).click();
+ waitFindObject(POSITIVE_BUTTON_SELECTOR).click();
// TODO(b/149037075): Use TelecomManager.getDefaultDialerPackage() once the bug is fixed.
//TelecomManager telecomManager = sContext.getSystemService(TelecomManager.class);
@@ -597,7 +607,7 @@ public class RoleManagerTest {
.putExtra(Intent.EXTRA_PACKAGE_NAME, APP_PACKAGE_NAME)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
waitFindObject(By.text(APP_LABEL)).click();
- waitFindObject(By.res("android:id/button1")).click();
+ waitFindObject(POSITIVE_BUTTON_SELECTOR).click();
TestUtils.waitUntil("App is not set as default sms app", () -> Objects.equals(
Telephony.Sms.getDefaultSmsPackage(sContext), APP_PACKAGE_NAME));