Merge "Fix unit test for TVRemoteProviderWatcherTest.java." into rvc-dev

This commit is contained in:
Andrei Litvin
2020-04-17 17:07:37 +00:00
committed by Android (Google) Code Review
2 changed files with 21 additions and 11 deletions

View File

@@ -59,9 +59,9 @@ final class TvRemoteProviderWatcher {
private boolean mRunning;
TvRemoteProviderWatcher(Context context, Object lock) {
TvRemoteProviderWatcher(Context context, Object lock, Handler handler) {
mContext = context;
mHandler = new Handler(true);
mHandler = handler;
mUserId = UserHandle.myUserId();
mPackageManager = context.getPackageManager();
mLock = lock;
@@ -79,6 +79,10 @@ final class TvRemoteProviderWatcher {
});
}
TvRemoteProviderWatcher(Context context, Object lock) {
this(context, lock, new Handler(true));
}
public void start() {
if (DEBUG) Slog.d(TAG, "start()");
if (!mRunning) {

View File

@@ -29,6 +29,7 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Looper;
import androidx.test.filters.SmallTest;
@@ -88,7 +89,12 @@ public class TvRemoteProviderWatcherTest {
// Test intentionally includes empty spacing for a more complex test
when(mMockResources.getString(com.android.internal.R.string.config_tvRemoteServicePackage))
.thenReturn(",,foo, " + TV_REMOTE_SERVICE_PACKAGE_NAME + ",bar, baz,,");
assertTrue(mTvRemoteProviderWatcher.verifyServiceTrusted(createTvServiceInfo()));
// Re-create the object since package name is loaded in the constructor
TvRemoteProviderWatcher watcher =
new TvRemoteProviderWatcher(
mMockContext, new Object(), new Handler(Looper.getMainLooper()));
assertTrue(watcher.verifyServiceTrusted(createTvServiceInfo()));
}
@Test
@@ -96,7 +102,12 @@ public class TvRemoteProviderWatcherTest {
// Checks include empty strings to validate that processing as well
when(mMockResources.getString(com.android.internal.R.string.config_tvRemoteServicePackage))
.thenReturn(",,foo,, ,bar, baz,,");
assertFalse(mTvRemoteProviderWatcher.verifyServiceTrusted(createTvServiceInfo()));
// Re-create the object since package name is loaded in the constructor
TvRemoteProviderWatcher watcher =
new TvRemoteProviderWatcher(
mMockContext, new Object(), new Handler(Looper.getMainLooper()));
assertFalse(watcher.verifyServiceTrusted(createTvServiceInfo()));
}
@Test
@@ -139,14 +150,9 @@ public class TvRemoteProviderWatcherTest {
public void whitelistingPackageNameIsRequired() {
reset(mMockResources);
when(mMockResources.getString(anyInt())).thenReturn("");
// Create a new watcher, as the resources are read in the constructor of the class
if (Looper.myLooper() == null) {
Looper.prepare();
}
TvRemoteProviderWatcher watcher =
new TvRemoteProviderWatcher(mMockContext, new Object());
new TvRemoteProviderWatcher(
mMockContext, new Object(), new Handler(Looper.getMainLooper()));
assertFalse(watcher.verifyServiceTrusted(createTvServiceInfo()));
}