aboutsummaryrefslogtreecommitdiff
path: root/tests/common/src/com/android/tv/testing/uihelper/UiDeviceAsserts.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/common/src/com/android/tv/testing/uihelper/UiDeviceAsserts.java')
-rw-r--r--tests/common/src/com/android/tv/testing/uihelper/UiDeviceAsserts.java73
1 files changed, 36 insertions, 37 deletions
diff --git a/tests/common/src/com/android/tv/testing/uihelper/UiDeviceAsserts.java b/tests/common/src/com/android/tv/testing/uihelper/UiDeviceAsserts.java
index c096d7d2..28ea163e 100644
--- a/tests/common/src/com/android/tv/testing/uihelper/UiDeviceAsserts.java
+++ b/tests/common/src/com/android/tv/testing/uihelper/UiDeviceAsserts.java
@@ -27,12 +27,9 @@ import android.support.test.uiautomator.SearchCondition;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.Until;
-
import junit.framework.Assert;
-/**
- * Asserts for {@link UiDevice}s.
- */
+/** Asserts for {@link UiDevice}s. */
public final class UiDeviceAsserts {
public static void assertHas(UiDevice uiDevice, BySelector bySelector, boolean expected) {
@@ -46,25 +43,25 @@ public final class UiDeviceAsserts {
}
/**
- * Assert that {@code searchCondition} becomes true within
- * {@value Constants#MAX_SHOW_DELAY_MILLIS} milliseconds.
+ * Assert that {@code searchCondition} becomes true within {@value
+ * Constants#MAX_SHOW_DELAY_MILLIS} milliseconds.
*
- * @param uiDevice the device under test.
+ * @param uiDevice the device under test.
* @param searchCondition the condition to wait for.
*/
- public static void assertWaitForCondition(UiDevice uiDevice,
- SearchCondition<Boolean> searchCondition) {
+ public static void assertWaitForCondition(
+ UiDevice uiDevice, SearchCondition<Boolean> searchCondition) {
assertWaitForCondition(uiDevice, searchCondition, Constants.MAX_SHOW_DELAY_MILLIS);
}
/**
* Assert that {@code searchCondition} becomes true within {@code timeout} milliseconds.
*
- * @param uiDevice the device under test.
+ * @param uiDevice the device under test.
* @param searchCondition the condition to wait for.
*/
- public static void assertWaitForCondition(UiDevice uiDevice,
- SearchCondition<Boolean> searchCondition, long timeout) {
+ public static void assertWaitForCondition(
+ UiDevice uiDevice, SearchCondition<Boolean> searchCondition, long timeout) {
boolean result = waitForCondition(uiDevice, searchCondition, timeout);
assertTrue(searchCondition + " not true after " + timeout / 1000.0 + " seconds.", result);
}
@@ -72,52 +69,55 @@ public final class UiDeviceAsserts {
/**
* Wait until {@code searchCondition} becomes true.
*
- * @param uiDevice The device under test.
+ * @param uiDevice The device under test.
* @param searchCondition The condition to wait for.
* @return {@code true} if the condition is met, otherwise {@code false}.
*/
- public static boolean waitForCondition(UiDevice uiDevice,
- SearchCondition<Boolean> searchCondition) {
+ public static boolean waitForCondition(
+ UiDevice uiDevice, SearchCondition<Boolean> searchCondition) {
return waitForCondition(uiDevice, searchCondition, Constants.MAX_SHOW_DELAY_MILLIS);
}
- private static boolean waitForCondition(UiDevice uiDevice,
- SearchCondition<Boolean> searchCondition, long timeout) {
- long adjustedTimeout = timeout + Math.max(Constants.MIN_EXTRA_TIMEOUT,
- (long) (timeout * Constants.EXTRA_TIMEOUT_PERCENT));
+ private static boolean waitForCondition(
+ UiDevice uiDevice, SearchCondition<Boolean> searchCondition, long timeout) {
+ long adjustedTimeout =
+ timeout
+ + Math.max(
+ Constants.MIN_EXTRA_TIMEOUT,
+ (long) (timeout * Constants.EXTRA_TIMEOUT_PERCENT));
return uiDevice.wait(searchCondition, adjustedTimeout);
}
/**
* Navigates through the focus items in a container returning the container child that has a
* descendant matching the {@code selector}.
- * <p>
- * The navigation starts in the {@code direction} specified and
- * {@link Direction#reverse(Direction) reverses} once if needed. Fails if there is not a
- * focused
- * descendant, or if after completing both directions no focused child has a descendant
- * matching
+ *
+ * <p>The navigation starts in the {@code direction} specified and {@link
+ * Direction#reverse(Direction) reverses} once if needed. Fails if there is not a focused
+ * descendant, or if after completing both directions no focused child has a descendant matching
* {@code selector}.
- * <p>
- * Fails if the menu item can not be navigated to.
*
- * @param uiDevice the device under test.
+ * <p>Fails if the menu item can not be navigated to.
+ *
+ * @param uiDevice the device under test.
* @param container contains children to navigate over.
- * @param selector the selector for the object to navigate to.
+ * @param selector the selector for the object to navigate to.
* @param direction the direction to start navigating.
* @return the object navigated to.
*/
- public static UiObject2 assertNavigateTo(UiDevice uiDevice, UiObject2 container,
- BySelector selector, Direction direction) {
+ public static UiObject2 assertNavigateTo(
+ UiDevice uiDevice, UiObject2 container, BySelector selector, Direction direction) {
int count = 0;
while (count < 2) {
BySelector hasFocusedDescendant = By.hasDescendant(FOCUSED_VIEW);
UiObject2 focusedChild = null;
- SearchCondition<Boolean> untilHasFocusedDescendant = Until
- .hasObject(hasFocusedDescendant);
+ SearchCondition<Boolean> untilHasFocusedDescendant =
+ Until.hasObject(hasFocusedDescendant);
- boolean result = container.wait(untilHasFocusedDescendant,
- UiObject2Asserts.getAdjustedTimeout(Constants.MAX_SHOW_DELAY_MILLIS));
+ boolean result =
+ container.wait(
+ untilHasFocusedDescendant,
+ UiObject2Asserts.getAdjustedTimeout(Constants.MAX_SHOW_DELAY_MILLIS));
if (!result) {
// HACK: Try direction anyways because play control does not always have a
// focused item.
@@ -147,6 +147,5 @@ public final class UiDeviceAsserts {
return null;
}
- private UiDeviceAsserts() {
- }
+ private UiDeviceAsserts() {}
}