summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Antonio Kantek <kanant@google.com> 2024-01-06 02:34:24 +0000
committer Antonio Kantek <kanant@google.com> 2024-01-25 00:58:00 +0000
commit0ea09d37ed29281984f40fa05b5027bca81c2911 (patch)
tree6c7bb6ee442dfec7845e0613e5ba7bb6b9831ea0
parent6cf1cd9c502d998bb396d8f8d3eb179db56f095e (diff)
Add tests for ClientController#verifyClientAndPackageMatch
Bug: 314150112 Test: atest --host FrameworksInputMethodSystemServerTests_host:com.android.server.inputmethod.ClientControllerTest -c Test: atest FrameworksInputMethodSystemServerTests:com.android.server.inputmethod.ClientControllerTest -c Change-Id: I7058aab4b8b7308b285e7a90d42e17b458d5e9c9
-rw-r--r--services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/ClientControllerTest.java42
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);