diff options
| -rw-r--r-- | services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/ClientControllerTest.java | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/ClientControllerTest.java b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/ClientControllerTest.java index 30afa72e0f03..eb89842f231d 100644 --- a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/ClientControllerTest.java +++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/ClientControllerTest.java @@ -23,6 +23,8 @@ import static com.google.common.truth.Truth.assertWithMessage; import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyInt; +import static org.mockito.Mockito.anyLong; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -53,6 +55,7 @@ public final class ClientControllerTest { private static final int ANY_DISPLAY_ID = Display.DEFAULT_DISPLAY; private static final int ANY_CALLER_UID = 1; private static final int ANY_CALLER_PID = 1; + private static final String SOME_PACKAGE_NAME = "some.package"; @Rule public final RavenwoodRule mRavenwood = new RavenwoodRule.Builder() @@ -81,7 +84,8 @@ public final class ClientControllerTest { } @Test - // TODO(b/314150112): Enable host side mode for this test once b/315544364 is fixed. + // TODO(b/314150112): Enable host side mode for this test once Ravenwood is enabled for + // inputmethod server classes. @IgnoreUnderRavenwood(blockedBy = {InputBinding.class, IInputMethodClientInvoker.class}) public void testAddClient_cannotAddTheSameClientTwice() { var invoker = IInputMethodClientInvoker.create(mClient, mHandler); @@ -103,7 +107,8 @@ public final class ClientControllerTest { } @Test - // TODO(b/314150112): Enable host side mode for this test once b/315544364 is fixed. + // TODO(b/314150112): Enable host side mode for this test once Ravenwood is enabled for + // inputmethod server classes. @IgnoreUnderRavenwood(blockedBy = {InputBinding.class, IInputMethodClientInvoker.class}) public void testAddClient() throws Exception { synchronized (ImfLock.class) { @@ -117,7 +122,8 @@ public final class ClientControllerTest { } @Test - // TODO(b/314150112): Enable host side mode for this test once b/315544364 is fixed. + // TODO(b/314150112): Enable host side mode for this test once Ravenwood is enabled for + // inputmethod server classes. @IgnoreUnderRavenwood(blockedBy = {InputBinding.class, IInputMethodClientInvoker.class}) public void testRemoveClient() { var callback = new TestClientControllerCallback(); @@ -137,6 +143,36 @@ public final class ClientControllerTest { assertThat(removed).isSameInstanceAs(added); } + @Test + // TODO(b/314150112): Enable host side mode for this test once Ravenwood is enabled for + // inputmethod server classes and updated to newer Mockito with static mock support (mock + // InputMethodUtils#checkIfPackageBelongsToUid instead of PackageManagerInternal#isSameApp) + @IgnoreUnderRavenwood(blockedBy = {InputMethodUtils.class}) + public void testVerifyClientAndPackageMatch() { + when(mMockPackageManagerInternal.isSameApp(eq(SOME_PACKAGE_NAME), /* flags= */ + anyLong(), eq(ANY_CALLER_UID), /* userId= */ anyInt())).thenReturn(true); + + synchronized (ImfLock.class) { + var invoker = IInputMethodClientInvoker.create(mClient, mHandler); + mController.addClient(invoker, mConnection, ANY_DISPLAY_ID, ANY_CALLER_UID, + ANY_CALLER_PID); + assertThat( + mController.verifyClientAndPackageMatch(mClient, SOME_PACKAGE_NAME)).isTrue(); + } + } + + @Test + public void testVerifyClientAndPackageMatch_unknownClient() { + synchronized (ImfLock.class) { + assertThrows(IllegalArgumentException.class, + () -> { + synchronized (ImfLock.class) { + mController.verifyClientAndPackageMatch(mClient, SOME_PACKAGE_NAME); + } + }); + } + } + private static class TestClientControllerCallback implements ClientControllerCallback { private final CountDownLatch mLatch = new CountDownLatch(1); |