Revert "Adding tests for multiple provider support in AbstractMa..." Revert submission 17008428-cherrypick-multi-provider-cloudsearch-2yrjp5zxz1 Reason for revert: Broke TextToSpeech service Reverted Changes: If1d0ac733:Adding tests for multiple provider support in Abst... I1da7f54bc:Adding multiple provider support in AbstractMaster... Change-Id: I22cfed8847e4df885185fd5bb90cf691205e4dfb (cherry picked from commit c4e5c8930716902464f25f929177ce27b9840651) Merged-In: I22cfed8847e4df885185fd5bb90cf691205e4dfb
diff --git a/tests/cloudsearch/AndroidManifest.xml b/tests/cloudsearch/AndroidManifest.xml index b5de2b7..e063ee4 100644 --- a/tests/cloudsearch/AndroidManifest.xml +++ b/tests/cloudsearch/AndroidManifest.xml
@@ -22,25 +22,9 @@ <uses-permission android:name="android.permission.MANAGE_CLOUDSEARCH"/> <application> - <service android:name=".Cts1CloudSearchService" - android:exported="true" - android:label="CtsDummy1CloudSearchService"> - <intent-filter> - <!-- This constant must match CloudSearchService.SERVICE_INTERFACE --> - <action android:name="android.service.cloudsearch.CloudSearchService"/> - </intent-filter> - </service> - <service android:name=".Cts2CloudSearchService" - android:exported="true" - android:label="CtsDummy2CloudSearchService"> - <intent-filter> - <!-- This constant must match CloudSearchService.SERVICE_INTERFACE --> - <action android:name="android.service.cloudsearch.CloudSearchService"/> - </intent-filter> - </service> - <service android:name=".Cts3CloudSearchService" - android:exported="true" - android:label="CtsDummy3CloudSearchService"> + <service android:name=".CtsCloudSearchService" + android:exported="true" + android:label="CtsDummyCloudSearchService"> <intent-filter> <!-- This constant must match CloudSearchService.SERVICE_INTERFACE --> <action android:name="android.service.cloudsearch.CloudSearchService"/>
diff --git a/tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchManagerTest.java b/tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchManagerTest.java index ddd2774..b1ccee4 100644 --- a/tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchManagerTest.java +++ b/tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchManagerTest.java
@@ -63,97 +63,61 @@ new RequiredServiceRule(Context.CLOUDSEARCH_SERVICE); private CloudSearchManager mManager; - private Cts1CloudSearchService.Watcher mWatcher1; - private Cts2CloudSearchService.Watcher mWatcher2; - private Cts3CloudSearchService.Watcher mWatcher3; + private CtsCloudSearchService.Watcher mWatcher; @Before public void setUp() throws Exception { - mWatcher1 = Cts1CloudSearchService.setWatcher(); - mWatcher2 = Cts2CloudSearchService.setWatcher(); - mWatcher3 = Cts3CloudSearchService.setWatcher(); - + mWatcher = CtsCloudSearchService.setWatcher(); mManager = getContext().getSystemService(CloudSearchManager.class); - setService(Cts1CloudSearchService.SERVICE_NAME + ";" - + Cts2CloudSearchService.SERVICE_NAME + ";" - + Cts3CloudSearchService.SERVICE_NAME); + setService(CtsCloudSearchService.SERVICE_NAME); - mManager.search(CloudSearchTestUtils.getBasicSearchRequest("", ""), + mManager.search(CloudSearchTestUtils.getBasicSearchRequest(""), Executors.newSingleThreadExecutor(), this); - await(mWatcher1.created, "Waiting for search()"); - await(mWatcher2.created, "Waiting for search()"); - await(mWatcher3.created, "Waiting for search()"); - + await(mWatcher.created, "Waiting for onCreate()"); } @After public void tearDown() throws Exception { - Log.d(TAG, "Starting tear down, watcher is: "); + Log.d(TAG, "Starting tear down, watcher is: " + mWatcher); setService(null); - mWatcher1 = null; - mWatcher2 = null; - mWatcher3 = null; - Cts1CloudSearchService.clearWatcher(); - Cts2CloudSearchService.clearWatcher(); - Cts3CloudSearchService.clearWatcher(); + mWatcher = null; + CtsCloudSearchService.clearWatcher(); } @Test public void testCloudSearchServiceConnection() { assertNotNull(mManager); - await(mWatcher1.queried, "Waiting for search()"); - await(mWatcher2.queried, "Waiting for search()"); - await(mWatcher3.queried, "Waiting for search()"); + await(mWatcher.queried, "Waiting for search()"); } @Test public void testSuccessfulSearch() { assertNotNull(mManager); - mManager.search( - CloudSearchTestUtils.getBasicSearchRequest("Successful1 Successful2 Successful3", - ""), + await(mWatcher.queried, "Waiting for search()"); + mManager.search(CloudSearchTestUtils.getBasicSearchRequest("Successful"), Executors.newSingleThreadExecutor(), this); - await(mWatcher1.succeeded, "Waiting for successful search"); - await(mWatcher2.succeeded, "Waiting for successful search"); - await(mWatcher3.succeeded, "Waiting for successful search"); + await(mWatcher.succeeded, "Waiting for successful search"); } @Test public void testUnsuccessfulSearch() { assertNotNull(mManager); - mManager.search(CloudSearchTestUtils.getBasicSearchRequest( - "Unsuccessful1 Unsuccessful2 Unsuccessful3", ""), + await(mWatcher.queried, "Waiting for search()"); + mManager.search(CloudSearchTestUtils.getBasicSearchRequest("Unsuccessful"), Executors.newSingleThreadExecutor(), this); - await(mWatcher1.failed, "Waiting for unsuccessful search"); - await(mWatcher2.failed, "Waiting for unsuccessful search"); - await(mWatcher3.failed, "Waiting for unsuccessful search"); - } - - @Test - public void testSingleServiceSearch() { - setService(Cts1CloudSearchService.SERVICE_NAME); - assertNotNull(mManager); - mManager.search(CloudSearchTestUtils.getBasicSearchRequest("Unsuccessful1", ""), - Executors.newSingleThreadExecutor(), this); - await(mWatcher1.failed, "Waiting for unsuccessful search"); + await(mWatcher.failed, "Waiting for unsuccessful search"); } @Test public void testMultipleCallbacksSearch() { assertNotNull(mManager); - mManager.search(CloudSearchTestUtils.getBasicSearchRequest( - "Successful1 Successful2 Successful3 Unsuccessful1 Unsuccessful2 Unsuccessful3", - ""), + await(mWatcher.queried, "Waiting for search()"); + mManager.search(CloudSearchTestUtils.getBasicSearchRequest("Unsuccessful and Successful"), Executors.newSingleThreadExecutor(), this); // TODO(216520546) add a condition to send a SearchRequest without // CtsCloudSearchServiceas a provider. - - await(mWatcher1.succeeded, "Waiting for successful search"); - await(mWatcher2.succeeded, "Waiting for successful search"); - await(mWatcher3.succeeded, "Waiting for successful search"); - await(mWatcher1.failed, "Waiting for unsuccessful search"); - await(mWatcher2.failed, "Waiting for unsuccessful search"); - await(mWatcher3.failed, "Waiting for unsuccessful search"); + await(mWatcher.failed, "Waiting for unsuccessful search"); + await(mWatcher.succeeded, "Waiting for successful search"); } private void setService(String service) { @@ -188,29 +152,15 @@ @Override public void onSearchSucceeded(SearchRequest request, SearchResponse response) { - Log.e(TAG, "onSearchSucceeded: " + request.getQuery() + ";" + response.getSource()); - if (response.getSource().contains("1")) { - mWatcher1.succeeded.countDown(); - } - if (response.getSource().contains("2")) { - mWatcher2.succeeded.countDown(); - } - if (response.getSource().contains("3")) { - mWatcher3.succeeded.countDown(); + if (response.getStatusCode() == SearchResponse.SEARCH_STATUS_OK) { + mWatcher.succeeded.countDown(); } } @Override public void onSearchFailed(SearchRequest request, SearchResponse response) { - Log.e(TAG, "onSearchFailed: " + request.getQuery() + ";" + response.getSource()); - if (response.getSource().contains("1")) { - mWatcher1.failed.countDown(); - } - if (response.getSource().contains("2")) { - mWatcher2.failed.countDown(); - } - if (response.getSource().contains("3")) { - mWatcher3.failed.countDown(); + if (response.getStatusCode() == SearchResponse.SEARCH_STATUS_NO_INTERNET) { + mWatcher.failed.countDown(); } } }
diff --git a/tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchTestUtils.java b/tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchTestUtils.java index 6c22df7..ebcf967 100644 --- a/tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchTestUtils.java +++ b/tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchTestUtils.java
@@ -21,13 +21,12 @@ import android.os.Bundle; public class CloudSearchTestUtils { - public static SearchRequest getBasicSearchRequest(String query, String constraint) { + public static SearchRequest getBasicSearchRequest(String query) { final int rn = 20; final int offset = 0; Bundle constraints = new Bundle(); constraints.putBoolean(SearchRequest.CONSTRAINT_IS_PRESUBMIT_SUGGESTION, true); - constraints.putString(SearchRequest.CONSTRAINT_SEARCH_PROVIDER_FILTER, constraint); return new SearchRequest.Builder(query).setResultNumber(rn) .setResultOffset(offset).setSearchConstraints(constraints).build();
diff --git a/tests/cloudsearch/src/android/cloudsearch/cts/Cts1CloudSearchService.java b/tests/cloudsearch/src/android/cloudsearch/cts/Cts1CloudSearchService.java deleted file mode 100644 index 7820e1d..0000000 --- a/tests/cloudsearch/src/android/cloudsearch/cts/Cts1CloudSearchService.java +++ /dev/null
@@ -1,93 +0,0 @@ -/* - * Copyright (C) 2022 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.cloudsearch.cts; - -import android.app.cloudsearch.SearchRequest; -import android.app.cloudsearch.SearchResponse; -import android.service.cloudsearch.CloudSearchService; -import android.util.Log; - -import java.util.List; -import java.util.concurrent.CountDownLatch; - -public class Cts1CloudSearchService extends CloudSearchService { - - private static final boolean DEBUG = true; - public static final String MY_PACKAGE = "android.cloudsearch.cts"; - public static final String SERVICE_NAME = MY_PACKAGE + "/." - + Cts1CloudSearchService.class.getSimpleName(); - private static final String TAG = - "CloudSearchManagerTest CS1[" + Cts1CloudSearchService.class.getSimpleName() + "]"; - - private static Watcher sWatcher; - - @Override - public void onCreate() { - super.onCreate(); - if (DEBUG) Log.e(TAG, "onCreate CS1"); - } - - @Override - public void onSearch(SearchRequest request) { - if (DEBUG) Log.e(TAG, "onSearch CS1:" + request); - // Counting down created in onSearch because a mock search request is issued in setup(). - sWatcher.created.countDown(); - sWatcher.queried.countDown(); - if (request.getQuery().contains("Successful1")) { - sWatcher.succeeded.countDown(); - returnResults(request.getRequestId(), - CloudSearchTestUtils.getSearchResponse(SearchResponse.SEARCH_STATUS_OK)); - } - if (request.getQuery().contains("Unsuccessful1")) { - sWatcher.failed.countDown(); - returnResults(request.getRequestId(), CloudSearchTestUtils.getSearchResponse( - SearchResponse.SEARCH_STATUS_NO_INTERNET)); - } - } - - - public static Watcher setWatcher() { - if (DEBUG) { - Log.d(TAG, "----------------------------------------------"); - Log.d(TAG, " setWatcher"); - } - if (sWatcher != null) { - throw new IllegalStateException("Set watcher with watcher already set"); - } - sWatcher = new Watcher(); - return sWatcher; - } - - public static void clearWatcher() { - if (DEBUG) Log.d(TAG, "clearWatcher"); - sWatcher = null; - } - - public static final class Watcher { - public CountDownLatch created = new CountDownLatch(1); - public CountDownLatch destroyed = new CountDownLatch(1); - public CountDownLatch queried = new CountDownLatch(1); - public CountDownLatch succeeded = new CountDownLatch(2); - public CountDownLatch failed = new CountDownLatch(2); - - public List<SearchResponse> mSmartspaceTargets; - - public void setTargets(List<SearchResponse> targets) { - mSmartspaceTargets = targets; - } - } -}
diff --git a/tests/cloudsearch/src/android/cloudsearch/cts/Cts2CloudSearchService.java b/tests/cloudsearch/src/android/cloudsearch/cts/Cts2CloudSearchService.java deleted file mode 100644 index 36c56e2..0000000 --- a/tests/cloudsearch/src/android/cloudsearch/cts/Cts2CloudSearchService.java +++ /dev/null
@@ -1,93 +0,0 @@ -/* - * Copyright (C) 2022 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.cloudsearch.cts; - -import android.app.cloudsearch.SearchRequest; -import android.app.cloudsearch.SearchResponse; -import android.service.cloudsearch.CloudSearchService; -import android.util.Log; - -import java.util.List; -import java.util.concurrent.CountDownLatch; - -public class Cts2CloudSearchService extends CloudSearchService { - - private static final boolean DEBUG = true; - public static final String MY_PACKAGE = "android.cloudsearch.cts"; - public static final String SERVICE_NAME = MY_PACKAGE + "/." - + Cts2CloudSearchService.class.getSimpleName(); - private static final String TAG = - "CloudSearchManagerTest CS2[" + Cts2CloudSearchService.class.getSimpleName() + "]"; - - private static Watcher sWatcher; - - @Override - public void onCreate() { - super.onCreate(); - if (DEBUG) Log.e(TAG, "onCreate CS2"); - } - - @Override - public void onSearch(SearchRequest request) { - if (DEBUG) Log.e(TAG, "onSearch CS2:" + request); - // Counting down created in onSearch because a mock search request is issued in setup(). - sWatcher.created.countDown(); - sWatcher.queried.countDown(); - if (request.getQuery().contains("Successful2")) { - sWatcher.succeeded.countDown(); - returnResults(request.getRequestId(), - CloudSearchTestUtils.getSearchResponse(SearchResponse.SEARCH_STATUS_OK)); - } - if (request.getQuery().contains("Unsuccessful2")) { - sWatcher.failed.countDown(); - returnResults(request.getRequestId(), CloudSearchTestUtils.getSearchResponse( - SearchResponse.SEARCH_STATUS_NO_INTERNET)); - } - } - - - public static Watcher setWatcher() { - if (DEBUG) { - Log.d(TAG, "----------------------------------------------"); - Log.d(TAG, " setWatcher"); - } - if (sWatcher != null) { - throw new IllegalStateException("Set watcher with watcher already set"); - } - sWatcher = new Watcher(); - return sWatcher; - } - - public static void clearWatcher() { - if (DEBUG) Log.d(TAG, "clearWatcher"); - sWatcher = null; - } - - public static final class Watcher { - public CountDownLatch created = new CountDownLatch(1); - public CountDownLatch destroyed = new CountDownLatch(1); - public CountDownLatch queried = new CountDownLatch(1); - public CountDownLatch succeeded = new CountDownLatch(2); - public CountDownLatch failed = new CountDownLatch(2); - - public List<SearchResponse> mSmartspaceTargets; - - public void setTargets(List<SearchResponse> targets) { - mSmartspaceTargets = targets; - } - } -}
diff --git a/tests/cloudsearch/src/android/cloudsearch/cts/Cts3CloudSearchService.java b/tests/cloudsearch/src/android/cloudsearch/cts/CtsCloudSearchService.java similarity index 77% rename from tests/cloudsearch/src/android/cloudsearch/cts/Cts3CloudSearchService.java rename to tests/cloudsearch/src/android/cloudsearch/cts/CtsCloudSearchService.java index 7cf8fe2..99422d2 100644 --- a/tests/cloudsearch/src/android/cloudsearch/cts/Cts3CloudSearchService.java +++ b/tests/cloudsearch/src/android/cloudsearch/cts/CtsCloudSearchService.java
@@ -24,40 +24,46 @@ import java.util.List; import java.util.concurrent.CountDownLatch; -public class Cts3CloudSearchService extends CloudSearchService { +public class CtsCloudSearchService extends CloudSearchService { private static final boolean DEBUG = true; public static final String MY_PACKAGE = "android.cloudsearch.cts"; public static final String SERVICE_NAME = MY_PACKAGE + "/." - + Cts3CloudSearchService.class.getSimpleName(); + + CtsCloudSearchService.class.getSimpleName(); private static final String TAG = - "CloudSearchManagerTest CS3[" + Cts3CloudSearchService.class.getSimpleName() + "]"; + "CloudSearchManagerTest[" + CtsCloudSearchService.class.getSimpleName() + "]"; private static Watcher sWatcher; @Override public void onCreate() { super.onCreate(); - if (DEBUG) Log.e(TAG, "onCreate CS3"); + if (DEBUG) Log.d(TAG, "onCreate"); } @Override public void onSearch(SearchRequest request) { - if (DEBUG) Log.e(TAG, "onSearch CS3:" + request); // Counting down created in onSearch because a mock search request is issued in setup(). sWatcher.created.countDown(); sWatcher.queried.countDown(); - if (request.getQuery().contains("Successful3")) { + if (request.getQuery().equals("Successful")) { + sWatcher.succeeded.countDown(); + returnResults(request.getRequestId(), + CloudSearchTestUtils.getSearchResponse(SearchResponse.SEARCH_STATUS_OK)); + } else if (request.getQuery().equals("Unsuccessful")) { + sWatcher.failed.countDown(); + returnResults(request.getRequestId(), CloudSearchTestUtils.getSearchResponse( + SearchResponse.SEARCH_STATUS_NO_INTERNET)); + + } else { + // Count down a search failure once and a search success once + sWatcher.failed.countDown(); + returnResults(request.getRequestId(), CloudSearchTestUtils.getSearchResponse( + SearchResponse.SEARCH_STATUS_NO_INTERNET)); sWatcher.succeeded.countDown(); returnResults(request.getRequestId(), CloudSearchTestUtils.getSearchResponse(SearchResponse.SEARCH_STATUS_OK)); } - if (request.getQuery().contains("Unsuccessful3")) { - sWatcher.failed.countDown(); - returnResults(request.getRequestId(), CloudSearchTestUtils.getSearchResponse( - SearchResponse.SEARCH_STATUS_NO_INTERNET)); - } - }