CTS: 100% coverage for IME APIs added in API 25

With this CL, all the new IME APIs added in API 25 will be covered by
CTS.

Bug: 30844323
Change-Id: I202b27eae272a8a2d3432385d64fe975d1b5e280
diff --git a/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java b/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java
index ee61446..820c007 100644
--- a/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java
+++ b/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java
@@ -17,8 +17,10 @@
 package android.view.inputmethod.cts;
 
 import android.app.Instrumentation;
+import android.content.ClipDescription;
 import android.content.Context;
 import android.cts.util.PollingCheck;
+import android.net.Uri;
 import android.os.Bundle;
 import android.test.ActivityInstrumentationTestCase2;
 import android.text.Editable;
@@ -34,6 +36,7 @@
 import android.view.inputmethod.BaseInputConnection;
 import android.view.inputmethod.CompletionInfo;
 import android.view.inputmethod.ExtractedTextRequest;
+import android.view.inputmethod.InputContentInfo;
 import android.view.inputmethod.InputMethodManager;
 import android.view.inputmethod.cts.util.InputConnectionTestUtils;
 import android.widget.EditText;
@@ -487,4 +490,13 @@
         testDeleteSurroundingTextInCodePointsMain("01[><]456789", 0, 1, "01[><]56789");
         testDeleteSurroundingTextInCodePointsMain("01[><]456789", 1, 1, "0[><]56789");
     }
+
+    public void testCommitContent() {
+        final InputContentInfo inputContentInfo = new InputContentInfo(
+                Uri.parse("content://com.example/path"),
+                new ClipDescription("sample content", new String[]{"image/png"}),
+                Uri.parse("https://example.com"));
+        // The default implementation should do nothing and just return false.
+        assertFalse(mConnection.commitContent(inputContentInfo, 0 /* flags */, null /* opts */));
+    }
 }
diff --git a/tests/tests/view/src/android/view/inputmethod/cts/InputConnectionWrapperTest.java b/tests/tests/view/src/android/view/inputmethod/cts/InputConnectionWrapperTest.java
index deab56e..70fc4fa 100644
--- a/tests/tests/view/src/android/view/inputmethod/cts/InputConnectionWrapperTest.java
+++ b/tests/tests/view/src/android/view/inputmethod/cts/InputConnectionWrapperTest.java
@@ -102,7 +102,7 @@
                 Uri.parse("content://com.example/path"),
                 new ClipDescription("sample content", new String[]{"image/png"}),
                 Uri.parse("https://example.com"));
-        assertTrue(inputConnection.commitContent(inputContentInfo, 0 /* flags */, null /* opt */));
+        wrapper.commitContent(inputContentInfo, 0 /* flags */, null /* opts */);
         assertTrue(inputConnection.isCommitContentCalled);
     }
 
diff --git a/tests/tests/view/src/android/view/inputmethod/cts/InputContentInfoTest.java b/tests/tests/view/src/android/view/inputmethod/cts/InputContentInfoTest.java
index 30c86bf..d8eb897 100644
--- a/tests/tests/view/src/android/view/inputmethod/cts/InputContentInfoTest.java
+++ b/tests/tests/view/src/android/view/inputmethod/cts/InputContentInfoTest.java
@@ -39,6 +39,7 @@
         assertEquals("image/png", info.getDescription().getMimeType(0));
         assertEquals("sample content", info.getDescription().getLabel());
         assertEquals(Uri.parse("https://example.com"), info.getLinkUri());
+        assertEquals(0, info.describeContents());
 
         Parcel p = Parcel.obtain();
         info.writeToParcel(p, 0);
@@ -53,6 +54,20 @@
                 targetInfo.getDescription().getMimeType(0));
         assertEquals(info.getDescription().getLabel(), targetInfo.getDescription().getLabel());
         assertEquals(info.getLinkUri(), targetInfo.getLinkUri());
+        assertEquals(info.describeContents(), targetInfo.describeContents());
+    }
+
+    public void testOptionalConstructorParam() {
+        InputContentInfo info = new InputContentInfo(
+                Uri.parse("content://com.example/path"),
+                new ClipDescription("sample content", new String[]{"image/png"}));
+
+        assertEquals(Uri.parse("content://com.example/path"), info.getContentUri());
+        assertEquals(1, info.getDescription().getMimeTypeCount());
+        assertEquals("image/png", info.getDescription().getMimeType(0));
+        assertEquals("sample content", info.getDescription().getLabel());
+        assertNull(info.getLinkUri());
+        assertEquals(0, info.describeContents());
     }
 
     public void testContentUri() {
@@ -145,4 +160,24 @@
             fail("Unexpected exception=" + e);
         }
     }
+
+    public void testRequestAndReleasePermission() {
+        InputContentInfo info = new InputContentInfo(
+                Uri.parse("content://com.example/path"),
+                new ClipDescription("sample content", new String[]{"image/png"}),
+                Uri.parse("https://example.com"));
+
+        // Here we only assert that {request, release}Permission() do not crash, because ensuring
+        // the entire functionality of these methods requires end-to-end IME test environment, which
+        // we do not have yet in CTS.
+        // Note it is actually intentional that calling these methods here has no effect.  Those
+        // methods would have effect only after the object is passed from the IME process to the
+        // application process.
+        // TODO: Create an end-to-end CTS test for this functionality.
+        info.requestPermission();
+        info.releasePermission();
+        info.requestPermission();
+        info.releasePermission();
+    }
+
 }