summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yohei Yukawa <yukawa@google.com> 2019-01-28 19:08:03 -0800
committer Yohei Yukawa <yukawa@google.com> 2019-01-28 19:08:03 -0800
commit7b0459464c20669f98a21d0902f962ad91ed2cf0 (patch)
tree3ae7d5ae4d276bb212b26c0a538de24906c85108
parent4dbad5640d4fb31f297cf6d8631c9770da358a37 (diff)
Add a unit test for EditorInfo#targetInputMethodUser
This it a follow up CL to my previous CL [1], which introduced EditorInfo#targetInputMethodUser. Since EditorInfo#targetInputMethodUser is an @hide API, we cannot directly its behavior in CTS. To make sure that it can be transferred via IPCs , this CL introduces a simple unit test for it in FrameworksCoreTests. [1]: Ia7ea944438d69669ccdf9111b34ba400e786a602 0f5eade4a492fc91130da1aedcad0999932f4137 Bug: 120744418 Test: atest FrameworksCoreTests:EditorInfoTest Change-Id: I3e722b3ccbd2ff33c264d4d41aa63e704970e78d
-rw-r--r--core/tests/coretests/src/android/view/inputmethod/EditorInfoTest.java74
1 files changed, 74 insertions, 0 deletions
diff --git a/core/tests/coretests/src/android/view/inputmethod/EditorInfoTest.java b/core/tests/coretests/src/android/view/inputmethod/EditorInfoTest.java
new file mode 100644
index 000000000000..68099fe19d13
--- /dev/null
+++ b/core/tests/coretests/src/android/view/inputmethod/EditorInfoTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.inputmethod;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import android.os.Parcel;
+import android.os.UserHandle;
+
+import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Supplemental tests that cannot be covered by CTS (e.g. due to hidden API dependencies).
+ */
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class EditorInfoTest {
+ private static final int TEST_USER_ID = 42;
+
+ /**
+ * Makes sure that {@code null} {@link EditorInfo#targetInputMethodUser} can be copied via
+ * {@link Parcel}.
+ */
+ @Test
+ public void testNullTargetInputMethodUserParcelable() throws Exception {
+ final EditorInfo editorInfo = new EditorInfo();
+ editorInfo.targetInputMethodUser = null;
+ assertNull(cloneViaParcel(editorInfo).targetInputMethodUser);
+ }
+
+ /**
+ * Makes sure that non-{@code null} {@link EditorInfo#targetInputMethodUser} can be copied via
+ * {@link Parcel}.
+ */
+ @Test
+ public void testNonNullTargetInputMethodUserParcelable() throws Exception {
+ final EditorInfo editorInfo = new EditorInfo();
+ editorInfo.targetInputMethodUser = UserHandle.of(TEST_USER_ID);
+ assertEquals(UserHandle.of(TEST_USER_ID), cloneViaParcel(editorInfo).targetInputMethodUser);
+ }
+
+ private static EditorInfo cloneViaParcel(EditorInfo original) {
+ Parcel parcel = null;
+ try {
+ parcel = Parcel.obtain();
+ original.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ return EditorInfo.CREATOR.createFromParcel(parcel);
+ } finally {
+ if (parcel != null) {
+ parcel.recycle();
+ }
+ }
+ }
+}