CTS tests for AppSearch.delete API.

Bug: 147636343
Test: CtsAppSearchTestCases
Change-Id: Ibc667e8526b1958be2f29e4bb67108a8f776b6d0
diff --git a/tests/appsearch/src/com/android/cts/appsearch/AppSearchManagerTest.java b/tests/appsearch/src/com/android/cts/appsearch/AppSearchManagerTest.java
index c8a51b8..59b15db 100644
--- a/tests/appsearch/src/com/android/cts/appsearch/AppSearchManagerTest.java
+++ b/tests/appsearch/src/com/android/cts/appsearch/AppSearchManagerTest.java
@@ -131,7 +131,6 @@
                         .setSubject("testPut example")
                         .setBody("This is the body of the testPut email")
                         .build();
-
         assertThat(mAppSearch.putDocuments(ImmutableList.of(inEmail)).isSuccess()).isTrue();
 
         // Query for the document
@@ -174,6 +173,44 @@
         assertThat(results).containsExactly(inDoc);
     }
 
+    @Test
+    public void testDelete() {
+        // Schema registration
+        assertThat(mAppSearch.setSchema(AppSearchEmail.SCHEMA).isSuccess()).isTrue();
+
+        // Index documents
+        AppSearchEmail email1 =
+                new AppSearchEmail.Builder("uri1")
+                        .setFrom("from@example.com")
+                        .setTo("to1@example.com", "to2@example.com")
+                        .setSubject("testPut example")
+                        .setBody("This is the body of the testPut email")
+                        .build();
+        AppSearchEmail email2 =
+                new AppSearchEmail.Builder("uri2")
+                        .setFrom("from@example.com")
+                        .setTo("to1@example.com", "to2@example.com")
+                        .setSubject("testPut example 2")
+                        .setBody("This is the body of the testPut second email")
+                        .build();
+        assertThat(mAppSearch.putDocuments(ImmutableList.of(email1, email2)).isSuccess()).isTrue();
+
+        // Check the presence of the documents
+        assertThat(doGet("uri1")).hasSize(1);
+        assertThat(doGet("uri2")).hasSize(1);
+
+        // Delete the document
+        assertThat(mAppSearch.delete(ImmutableList.of("uri1")).isSuccess()).isTrue();
+
+        // Make sure it's really gone
+        AppSearchBatchResult<String, AppSearchDocument> getResult =
+                mAppSearch.getDocuments(ImmutableList.of("uri1", "uri2"));
+        assertThat(getResult.isSuccess()).isFalse();
+        assertThat(getResult.getFailures().get("uri1").getResultCode())
+                .isEqualTo(AppSearchResult.RESULT_NOT_FOUND);
+        assertThat(getResult.getSuccesses().get("uri2")).isEqualTo(email2);
+    }
+
     private List<AppSearchDocument> doGet(String... uris) {
         AppSearchBatchResult<String, AppSearchDocument> result =
                 mAppSearch.getDocuments(Arrays.asList(uris));