aboutsummaryrefslogtreecommitdiff
path: root/tests/common/src
diff options
context:
space:
mode:
authorNick Chalko <nchalko@google.com>2015-11-04 15:15:29 -0800
committerNick Chalko <nchalko@google.com>2015-11-10 13:59:03 -0800
commit7d67089aa1e9aa2123c3cd2f386d7019a1544db1 (patch)
tree6f90c2065a853628dd7704788dd41b787acb6fae /tests/common/src
parent07b043dc3db83d6d20f0e8513b946830ab00e37b (diff)
downloadTV-7d67089aa1e9aa2123c3cd2f386d7019a1544db1.tar.gz
Sync to ub-tv-glee at 1.07.007
hash dce17da9f45fc4304787b1898d9915511b1df954 Change-Id: I08ac6fc0123a6653644281155e35c11b71bc5fa0
Diffstat (limited to 'tests/common/src')
-rw-r--r--tests/common/src/com/android/tv/testing/ChannelInfo.java2
-rw-r--r--tests/common/src/com/android/tv/testing/ComparatorTester.java2
-rw-r--r--tests/common/src/com/android/tv/testing/Utils.java55
-rw-r--r--tests/common/src/com/android/tv/testing/testinput/ChannelStateData.aidl2
-rw-r--r--tests/common/src/com/android/tv/testing/testinput/ITestInputControl.aidl2
-rw-r--r--tests/common/src/com/android/tv/testing/uihelper/LiveChannelsUiDeviceHelper.java2
-rw-r--r--tests/common/src/com/android/tv/testing/uihelper/MenuHelper.java4
7 files changed, 63 insertions, 6 deletions
diff --git a/tests/common/src/com/android/tv/testing/ChannelInfo.java b/tests/common/src/com/android/tv/testing/ChannelInfo.java
index 40a8bba8..28ba4a64 100644
--- a/tests/common/src/com/android/tv/testing/ChannelInfo.java
+++ b/tests/common/src/com/android/tv/testing/ChannelInfo.java
@@ -81,7 +81,7 @@ public final class ChannelInfo {
.setOriginalNetworkId(channelNumber);
if (context != null) {
// tests/input/tools/get_test_logos.sh only stores 1000 logos.
- int logo_num = (channelNumber % 1000) + 1;
+ int logo_num = (channelNumber % 1000);
builder.setLogoUrl(
"android.resource://com.android.tv.testinput/drawable/ch_" + logo_num
+ "_logo"
diff --git a/tests/common/src/com/android/tv/testing/ComparatorTester.java b/tests/common/src/com/android/tv/testing/ComparatorTester.java
index dc5cf00f..3774532f 100644
--- a/tests/common/src/com/android/tv/testing/ComparatorTester.java
+++ b/tests/common/src/com/android/tv/testing/ComparatorTester.java
@@ -125,4 +125,4 @@ public class ComparatorTester<T> {
}
}
}
-}
+} \ No newline at end of file
diff --git a/tests/common/src/com/android/tv/testing/Utils.java b/tests/common/src/com/android/tv/testing/Utils.java
index 33fe4c54..c1a7506f 100644
--- a/tests/common/src/com/android/tv/testing/Utils.java
+++ b/tests/common/src/com/android/tv/testing/Utils.java
@@ -25,11 +25,21 @@ import android.media.tv.TvContentRating;
import android.media.tv.TvInputInfo;
import android.media.tv.TvInputManager;
import android.net.Uri;
+import android.os.Looper;
import android.text.TextUtils;
+import android.util.Log;
+
+import com.android.tv.util.MainThreadExecutor;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.Random;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
/**
* An utility class for testing.
@@ -38,7 +48,11 @@ import java.io.OutputStream;
*
* @see com.android.tv.util.Utils#isRunningInTest
*/
-public class Utils {
+public final class Utils {
+ private static final String TAG ="Utils";
+
+ private static final long DEFAULT_RANDOM_SEED = getSeed();
+
public static String getUriStringForResource(Context context, int resId) {
if (resId == 0) {
return "";
@@ -105,5 +119,44 @@ public class Utils {
return ratings.toString();
}
+ /**
+ * Return the Random class which is needed to make random data for testing.
+ * Default seed of the random is today's date.
+ */
+ public static Random createTestRandom() {
+ return new Random(DEFAULT_RANDOM_SEED);
+ }
+
+ /**
+ * Executes a call on the main thread, blocking until it is completed.
+ *
+ * <p>Useful for doing things that are not thread-safe, such as looking at or modifying the view
+ * hierarchy.
+ *
+ * @param runnable The code to run on the main thread.
+ */
+ public static void runOnMainSync(Runnable runnable) {
+ if (Looper.myLooper() == Looper.getMainLooper()) {
+ runnable.run();
+ } else {
+ Future<?> temp = MainThreadExecutor.getInstance().submit(runnable);
+ try {
+ temp.get();
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ } catch (ExecutionException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ private static long getSeed() {
+ // Set random seed as the date to track failed test data easily.
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd", Locale.getDefault());
+ String today = dateFormat.format(new Date());
+ Log.d(TAG, "Today's random seed is " + today);
+ return Long.valueOf(today);
+ }
+
private Utils() {}
}
diff --git a/tests/common/src/com/android/tv/testing/testinput/ChannelStateData.aidl b/tests/common/src/com/android/tv/testing/testinput/ChannelStateData.aidl
index cdf43adb..8b3e7dcc 100644
--- a/tests/common/src/com/android/tv/testing/testinput/ChannelStateData.aidl
+++ b/tests/common/src/com/android/tv/testing/testinput/ChannelStateData.aidl
@@ -1,3 +1,3 @@
package com.android.tv.testing.testinput;
-parcelable ChannelStateData;
+parcelable ChannelStateData; \ No newline at end of file
diff --git a/tests/common/src/com/android/tv/testing/testinput/ITestInputControl.aidl b/tests/common/src/com/android/tv/testing/testinput/ITestInputControl.aidl
index a82f378b..15039000 100644
--- a/tests/common/src/com/android/tv/testing/testinput/ITestInputControl.aidl
+++ b/tests/common/src/com/android/tv/testing/testinput/ITestInputControl.aidl
@@ -6,4 +6,4 @@ import com.android.tv.testing.testinput.ChannelStateData;
/** Remote interface for controlling the test TV Input Service */
interface ITestInputControl {
void updateChannelState(int origId, in ChannelStateData data);
-}
+} \ No newline at end of file
diff --git a/tests/common/src/com/android/tv/testing/uihelper/LiveChannelsUiDeviceHelper.java b/tests/common/src/com/android/tv/testing/uihelper/LiveChannelsUiDeviceHelper.java
index 31204410..6757cf01 100644
--- a/tests/common/src/com/android/tv/testing/uihelper/LiveChannelsUiDeviceHelper.java
+++ b/tests/common/src/com/android/tv/testing/uihelper/LiveChannelsUiDeviceHelper.java
@@ -48,4 +48,4 @@ public class LiveChannelsUiDeviceHelper extends BaseUiDeviceHelper {
mUiDevice.pressBack();
}
}
-}
+} \ No newline at end of file
diff --git a/tests/common/src/com/android/tv/testing/uihelper/MenuHelper.java b/tests/common/src/com/android/tv/testing/uihelper/MenuHelper.java
index cb403a61..3d992618 100644
--- a/tests/common/src/com/android/tv/testing/uihelper/MenuHelper.java
+++ b/tests/common/src/com/android/tv/testing/uihelper/MenuHelper.java
@@ -121,6 +121,10 @@ public class MenuHelper extends BaseUiDeviceHelper {
R.string.options_item_channel_sources);
}
+ public UiObject2 assertPressOptionsAbout() {
+ return assertPressMenuItem(R.string.menu_title_options,
+ R.string.options_item_about);
+ }
public UiObject2 assertPressOptionsClosedCaptions() {
return assertPressMenuItem(R.string.menu_title_options,