summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHui Wu <huiwu@google.com>2022-09-22 22:40:13 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2022-09-22 22:40:13 +0000
commite45a50741116ceee0e691d2fb84f7a2e6cc0f7c2 (patch)
tree0390310663cc0399f9bb814080aca483f2bc6763
parentf92a6b8cdf916b0fc7f1dbdf01f46ef061466c5d (diff)
parent1975fdffb112c8e074f9cc2fa0cac6521d237f7f (diff)
downloadcts-e45a50741116ceee0e691d2fb84f7a2e6cc0f7c2.tar.gz
Merge "Remove cloudsearch api cts" into tm-qpr-dev
-rw-r--r--tests/cloudsearch/Android.bp35
-rw-r--r--tests/cloudsearch/AndroidManifest.xml59
-rw-r--r--tests/cloudsearch/AndroidTest.xml33
-rw-r--r--tests/cloudsearch/OWNERS3
-rw-r--r--tests/cloudsearch/TEST_MAPPING7
-rw-r--r--tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchManagerTest.java226
-rw-r--r--tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchTestUtils.java39
-rw-r--r--tests/cloudsearch/src/android/cloudsearch/cts/Cts1CloudSearchService.java93
-rw-r--r--tests/cloudsearch/src/android/cloudsearch/cts/Cts2CloudSearchService.java93
-rw-r--r--tests/cloudsearch/src/android/cloudsearch/cts/Cts3CloudSearchService.java94
-rw-r--r--tests/cloudsearch/src/android/cloudsearch/cts/SearchRequestTest.java81
-rw-r--r--tests/cloudsearch/src/android/cloudsearch/cts/SearchResponseTest.java102
-rw-r--r--tests/cloudsearch/src/android/cloudsearch/cts/SearchResultTest.java123
13 files changed, 0 insertions, 988 deletions
diff --git a/tests/cloudsearch/Android.bp b/tests/cloudsearch/Android.bp
deleted file mode 100644
index 99e7329a2c7..00000000000
--- a/tests/cloudsearch/Android.bp
+++ /dev/null
@@ -1,35 +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 {
- default_applicable_licenses: ["Android-Apache-2.0"],
-}
-
-android_test {
- name: "CtsCloudSearchServiceTestCases",
- defaults: ["cts_defaults"],
- static_libs: [
- "androidx.annotation_annotation",
- "compatibility-device-util-axt",
- "ctstestrunner-axt",
- "truth-prebuilt",
- ],
- srcs: ["src/**/*.java"],
- // Tag this module as a cts test artifact
- test_suites: [
- "cts",
- "general-tests",
- ],
- sdk_version: "test_current",
-}
diff --git a/tests/cloudsearch/AndroidManifest.xml b/tests/cloudsearch/AndroidManifest.xml
deleted file mode 100644
index b5de2b77404..00000000000
--- a/tests/cloudsearch/AndroidManifest.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- * 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.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="android.cloudsearch.cts"
- android:targetSandboxVersion="2">
-
- <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">
- <intent-filter>
- <!-- This constant must match CloudSearchService.SERVICE_INTERFACE -->
- <action android:name="android.service.cloudsearch.CloudSearchService"/>
- </intent-filter>
- </service>
-
- <uses-library android:name="android.test.runner"/>
-
- </application>
-
- <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
- android:label="CTS tests for the App CloudSearch System APIs."
- android:targetPackage="android.cloudsearch.cts">
- </instrumentation>
-
-</manifest>
diff --git a/tests/cloudsearch/AndroidTest.xml b/tests/cloudsearch/AndroidTest.xml
deleted file mode 100644
index 1ede8e7c752..00000000000
--- a/tests/cloudsearch/AndroidTest.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- 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.
--->
-<configuration description="Config for CloudSearch CTS tests.">
- <option name="test-suite-tag" value="cts"/>
- <option name="config-descriptor:metadata" key="component" value="framework"/>
- <option name="config-descriptor:metadata" key="parameter" value="not_instant_app"/>
- <option name="config-descriptor:metadata" key="parameter" value="not_multi_abi"/>
- <option name="config-descriptor:metadata" key="parameter" value="secondary_user"/>
- <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
- <option name="cleanup-apks" value="true"/>
- <option name="test-file-name" value="CtsCloudSearchServiceTestCases.apk"/>
- </target_preparer>
-
- <test class="com.android.tradefed.testtype.AndroidJUnitTest">
- <option name="package" value="android.cloudsearch.cts"/>
- <!-- 20x default timeout of 600sec -->
- <option name="shell-timeout" value="12000000"/>
- </test>
-
-</configuration>
diff --git a/tests/cloudsearch/OWNERS b/tests/cloudsearch/OWNERS
deleted file mode 100644
index 27493ba7213..00000000000
--- a/tests/cloudsearch/OWNERS
+++ /dev/null
@@ -1,3 +0,0 @@
-# Bug component: 758286
-huiwu@google.com
-srazdan@google.com
diff --git a/tests/cloudsearch/TEST_MAPPING b/tests/cloudsearch/TEST_MAPPING
deleted file mode 100644
index 8706339cd10..00000000000
--- a/tests/cloudsearch/TEST_MAPPING
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "presubmit": [
- {
- "name": "CtsCloudSearchServiceTestCases"
- }
- ]
-}
diff --git a/tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchManagerTest.java b/tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchManagerTest.java
deleted file mode 100644
index 88ad68585e7..00000000000
--- a/tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchManagerTest.java
+++ /dev/null
@@ -1,226 +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 static androidx.test.InstrumentationRegistry.getContext;
-
-import static com.google.common.truth.Truth.assertWithMessage;
-
-import static org.junit.Assert.assertNotNull;
-
-import android.app.cloudsearch.CloudSearchManager;
-import android.app.cloudsearch.SearchRequest;
-import android.app.cloudsearch.SearchResponse;
-import android.content.Context;
-import android.os.Process;
-import android.util.Log;
-
-import androidx.annotation.NonNull;
-import androidx.test.InstrumentationRegistry;
-import androidx.test.runner.AndroidJUnit4;
-
-import com.android.compatibility.common.util.RequiredServiceRule;
-import com.android.compatibility.common.util.SystemUtil;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Tests for {@link CloudSearchManager}
- *
- * atest CtsSmartspaceServiceTestCases
- */
-@RunWith(AndroidJUnit4.class)
-public class CloudSearchManagerTest implements CloudSearchManager.CallBack {
-
- private static final String TAG = "CloudSearchManagerTest";
- private static final boolean DEBUG = true;
-
- private static final long SERVICE_LIFECYCLE_TIMEOUT_MS = 40_000;
-
- @Rule
- public final RequiredServiceRule mRequiredServiceRule =
- new RequiredServiceRule(Context.CLOUDSEARCH_SERVICE);
-
- private CloudSearchManager mManager;
- private Cts1CloudSearchService.Watcher mWatcher1;
- private Cts2CloudSearchService.Watcher mWatcher2;
- private Cts3CloudSearchService.Watcher mWatcher3;
-
- @Before
- public void setUp() throws Exception {
- mWatcher1 = Cts1CloudSearchService.setWatcher();
- mWatcher2 = Cts2CloudSearchService.setWatcher();
- mWatcher3 = Cts3CloudSearchService.setWatcher();
-
- mManager = getContext().getSystemService(CloudSearchManager.class);
- setService(Cts1CloudSearchService.SERVICE_NAME + ";"
- + Cts2CloudSearchService.SERVICE_NAME + ";"
- + Cts3CloudSearchService.SERVICE_NAME);
-
- 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()");
-
- }
-
- @After
- public void tearDown() throws Exception {
- Log.d(TAG, "Starting tear down, watcher is: ");
- setService(null);
- mWatcher1 = null;
- mWatcher2 = null;
- mWatcher3 = null;
- Cts1CloudSearchService.clearWatcher();
- Cts2CloudSearchService.clearWatcher();
- Cts3CloudSearchService.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()");
- }
-
- @Test
- public void testSuccessfulSearch() {
- assertNotNull(mManager);
- mManager.search(
- CloudSearchTestUtils.getBasicSearchRequest("Successful1 Successful2 Successful3",
- ""),
- Executors.newSingleThreadExecutor(), this);
- await(mWatcher1.succeeded, "Waiting for successful search");
- await(mWatcher2.succeeded, "Waiting for successful search");
- await(mWatcher3.succeeded, "Waiting for successful search");
- }
-
- @Test
- public void testUnsuccessfulSearch() {
- assertNotNull(mManager);
- mManager.search(CloudSearchTestUtils.getBasicSearchRequest(
- "Unsuccessful1 Unsuccessful2 Unsuccessful3", ""),
- 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");
- }
-
- @Test
- public void testInvalidServiceSearch() {
- setService(Cts1CloudSearchService.SERVICE_NAME + ";"
- + "Invalid" + Cts2CloudSearchService.SERVICE_NAME);
- assertNotNull(mManager);
- mManager.search(CloudSearchTestUtils.getBasicSearchRequest("Successful1", ""),
- Executors.newSingleThreadExecutor(), this);
- await(mWatcher1.succeeded, "Waiting for successful search");
- }
-
- @Test
- public void testMultipleCallbacksSearch() {
- assertNotNull(mManager);
- mManager.search(CloudSearchTestUtils.getBasicSearchRequest(
- "Successful1 Successful2 Successful3 Unsuccessful1 Unsuccessful2 Unsuccessful3",
- ""),
- 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");
- }
-
- private void setService(String service) {
- Log.d(TAG, "Setting cloudsearch service to " + service);
- int userId = Process.myUserHandle().getIdentifier();
- if (service != null) {
- runShellCommand("cmd cloudsearch set temporary-service "
- + userId + " " + service + " 60000");
- } else {
- runShellCommand("cmd cloudsearch set temporary-service " + userId);
- }
- }
-
- private void await(@NonNull CountDownLatch latch, @NonNull String message) {
- try {
- assertWithMessage(message).that(
- latch.await(SERVICE_LIFECYCLE_TIMEOUT_MS, TimeUnit.MILLISECONDS)).isTrue();
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new IllegalStateException("Interrupted while: " + message);
- }
- }
-
- private void runShellCommand(String command) {
- Log.d(TAG, "runShellCommand(): " + command);
- try {
- SystemUtil.runShellCommand(InstrumentationRegistry.getInstrumentation(), command);
- } catch (Exception e) {
- throw new RuntimeException("Command '" + command + "' failed: ", e);
- }
- }
-
- @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();
- }
- }
-
- @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();
- }
- }
-}
diff --git a/tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchTestUtils.java b/tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchTestUtils.java
deleted file mode 100644
index 6c22df77c2f..00000000000
--- a/tests/cloudsearch/src/android/cloudsearch/cts/CloudSearchTestUtils.java
+++ /dev/null
@@ -1,39 +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.os.Bundle;
-
-public class CloudSearchTestUtils {
- public static SearchRequest getBasicSearchRequest(String query, String constraint) {
- 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();
- }
-
- public static SearchResponse getSearchResponse(int searchStatusCode) {
- return new SearchResponse.Builder(searchStatusCode).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 7726832c9ef..00000000000
--- 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();
- super.returnResults(request.getRequestId(),
- CloudSearchTestUtils.getSearchResponse(SearchResponse.SEARCH_STATUS_OK));
- }
- if (request.getQuery().contains("Unsuccessful1")) {
- sWatcher.failed.countDown();
- super.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 33cdec834c3..00000000000
--- 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();
- super.returnResults(request.getRequestId(),
- CloudSearchTestUtils.getSearchResponse(SearchResponse.SEARCH_STATUS_OK));
- }
- if (request.getQuery().contains("Unsuccessful2")) {
- sWatcher.failed.countDown();
- super.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/Cts3CloudSearchService.java
deleted file mode 100644
index d264ea41cd1..00000000000
--- a/tests/cloudsearch/src/android/cloudsearch/cts/Cts3CloudSearchService.java
+++ /dev/null
@@ -1,94 +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 Cts3CloudSearchService 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();
- private static final String TAG =
- "CloudSearchManagerTest CS3[" + Cts3CloudSearchService.class.getSimpleName() + "]";
-
- private static Watcher sWatcher;
-
- @Override
- public void onCreate() {
- super.onCreate();
- if (DEBUG) Log.e(TAG, "onCreate CS3");
- }
-
- @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")) {
- sWatcher.succeeded.countDown();
- super.returnResults(request.getRequestId(),
- CloudSearchTestUtils.getSearchResponse(SearchResponse.SEARCH_STATUS_OK));
- }
- if (request.getQuery().contains("Unsuccessful3")) {
- sWatcher.failed.countDown();
- super.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/SearchRequestTest.java b/tests/cloudsearch/src/android/cloudsearch/cts/SearchRequestTest.java
deleted file mode 100644
index 5966d955193..00000000000
--- a/tests/cloudsearch/src/android/cloudsearch/cts/SearchRequestTest.java
+++ /dev/null
@@ -1,81 +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 static com.google.common.truth.Truth.assertThat;
-
-import android.app.cloudsearch.SearchRequest;
-import android.os.Bundle;
-import android.os.Parcel;
-
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-/**
- * Tests for {@link SearchRequest}
- *
- * atest CtsCloudSearchServiceTestCases
- */
-@RunWith(AndroidJUnit4.class)
-public class SearchRequestTest {
-
- private static final String TAG = "CloudSearchTargetTest";
-
- @Test
- public void testCreateSearchRequest() {
- final String query = "bo";
- final int rn = 20;
- final int offset = 0;
- final float maxLatency = 100;
- Bundle constraints = new Bundle();
- constraints.putBoolean(SearchRequest.CONSTRAINT_IS_PRESUBMIT_SUGGESTION,
- true);
- final String pkgName = "android.cloudsearch.cts";
-
- SearchRequest request = new SearchRequest.Builder("").setResultNumber(rn)
- .setResultOffset(offset).setSearchConstraints(constraints).setQuery(query)
- .setMaxLatencyMillis(maxLatency).setCallerPackageName(pkgName).build();
-
- /** Check the original request. */
- assertThat(request.getQuery()).isEqualTo(query);
- assertThat(request.getResultNumber()).isEqualTo(rn);
- assertThat(request.getMaxLatencyMillis()).isEqualTo(maxLatency);
- assertThat(request.getResultOffset()).isEqualTo(offset);
- final Bundle sc = request.getSearchConstraints();
- assertThat(sc.getBoolean(SearchRequest.CONSTRAINT_IS_PRESUBMIT_SUGGESTION))
- .isEqualTo(true);
- assertThat(request.getCallerPackageName()).isEqualTo(pkgName);
-
- Parcel parcel = Parcel.obtain();
- parcel.setDataPosition(0);
- request.writeToParcel(parcel, 0);
- parcel.setDataPosition(0);
- SearchRequest copy = SearchRequest.CREATOR.createFromParcel(parcel);
- /** Check the copied request. */
- assertThat(copy.getQuery()).isEqualTo(query);
- assertThat(copy.getResultNumber()).isEqualTo(rn);
- assertThat(copy.getMaxLatencyMillis()).isEqualTo(maxLatency);
- assertThat(copy.getResultOffset()).isEqualTo(offset);
- final Bundle sccopy = request.getSearchConstraints();
- assertThat(sccopy.getBoolean(SearchRequest.CONSTRAINT_IS_PRESUBMIT_SUGGESTION))
- .isEqualTo(true);
- assertThat(copy.getCallerPackageName()).isEqualTo(pkgName);
-
- parcel.recycle();
- }
-}
diff --git a/tests/cloudsearch/src/android/cloudsearch/cts/SearchResponseTest.java b/tests/cloudsearch/src/android/cloudsearch/cts/SearchResponseTest.java
deleted file mode 100644
index 5a0e2919db6..00000000000
--- a/tests/cloudsearch/src/android/cloudsearch/cts/SearchResponseTest.java
+++ /dev/null
@@ -1,102 +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 static com.google.common.truth.Truth.assertThat;
-
-import android.app.cloudsearch.SearchResponse;
-import android.app.cloudsearch.SearchResult;
-import android.os.Bundle;
-import android.os.Parcel;
-
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Tests for {@link SearchResponse}
- *
- * atest CtsCloudSearchServiceTestCases
- */
-@RunWith(AndroidJUnit4.class)
-public class SearchResponseTest {
-
- private static final String TAG = "CloudSearchTargetTest";
-
- @Test
- public void testCreateSearchResponse() {
- final int status = SearchResponse.SEARCH_STATUS_OK;
- final String source = "DEFAULT";
- List<SearchResult> results = new ArrayList<SearchResult>();
-
- final String titleA = "title a";
- final String snippetA = "Good Snippet a";
- final float scoreA = 10;
- Bundle extraInfosA = new Bundle();
- extraInfosA.putBoolean(SearchResult.EXTRAINFO_APP_CONTAINS_IAP_DISCLAIMER,
- false);
- extraInfosA.putString(SearchResult.EXTRAINFO_APP_DEVELOPER_NAME,
- "best_app_developer a");
- SearchResult resultA = new SearchResult.Builder(titleA, extraInfosA)
- .setSnippet(snippetA).setScore(scoreA).build();
- results.add(resultA);
-
- final String titleB = "title B";
- final String snippetB = "Good Snippet B";
- final float scoreB = 20;
- Bundle extraInfosB = new Bundle();
- extraInfosB.putBoolean(SearchResult.EXTRAINFO_APP_CONTAINS_IAP_DISCLAIMER,
- true);
- extraInfosB.putString(SearchResult.EXTRAINFO_APP_DEVELOPER_NAME,
- "best_app_developer B");
- SearchResult resultB = new SearchResult.Builder(titleB, extraInfosB)
- .setSnippet(snippetB).setScore(scoreB).build();
- results.add(resultB);
-
- SearchResponse response = new SearchResponse.Builder(SearchResponse.SEARCH_STATUS_UNKNOWN)
- .setSearchResults(results).setStatusCode(status).build();
-
- /** Checks the original response. */
- assertThat(response.getStatusCode()).isEqualTo(status);
- assertThat(response.getSource()).isEqualTo(source);
- assertThat(response.getSearchResults().size()).isEqualTo(2);
- final SearchResult firstResult = response.getSearchResults().get(0);
- assertThat(firstResult.getTitle()).isEqualTo(titleA);
- final SearchResult secondResult = response.getSearchResults().get(1);
- assertThat(secondResult.getTitle()).isEqualTo(titleB);
-
- Parcel parcel = Parcel.obtain();
- parcel.setDataPosition(0);
- response.writeToParcel(parcel, 0);
- parcel.setDataPosition(0);
- SearchResponse copy = SearchResponse.CREATOR.createFromParcel(parcel);
-
- /** Checks the copied response. */
- assertThat(copy.getStatusCode()).isEqualTo(status);
- assertThat(copy.getSource()).isEqualTo(source);
- assertThat(copy.getSearchResults().size()).isEqualTo(2);
- final SearchResult firstResultCopy = copy.getSearchResults().get(0);
- assertThat(firstResultCopy.getTitle()).isEqualTo(titleA);
- final SearchResult secondResultCopy = copy.getSearchResults().get(1);
- assertThat(secondResultCopy.getTitle()).isEqualTo(titleB);
-
- parcel.recycle();
- }
-}
diff --git a/tests/cloudsearch/src/android/cloudsearch/cts/SearchResultTest.java b/tests/cloudsearch/src/android/cloudsearch/cts/SearchResultTest.java
deleted file mode 100644
index 9dd83f463fe..00000000000
--- a/tests/cloudsearch/src/android/cloudsearch/cts/SearchResultTest.java
+++ /dev/null
@@ -1,123 +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 static androidx.test.InstrumentationRegistry.getContext;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.app.PendingIntent;
-import android.app.cloudsearch.SearchResult;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.Parcel;
-
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-/**
- * Tests for {@link SearchResult}
- *
- * atest CtsCloudSearchServiceTestCases
- */
-@RunWith(AndroidJUnit4.class)
-public class SearchResultTest {
-
- private static final String TAG = "CloudSearchTargetTest";
-
- @Test
- public void testCreateSearchResult() {
- final String title = "title";
- final String snippet = "Good Snippet";
- final float score = 10;
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.android.com"));
- PendingIntent pendingIntent = PendingIntent.getActivity(getContext(),
- 1, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
-
- Bundle extraInfos = new Bundle();
- extraInfos.putBoolean(SearchResult.EXTRAINFO_APP_CONTAINS_IAP_DISCLAIMER,
- false);
- extraInfos.putString(SearchResult.EXTRAINFO_APP_DEVELOPER_NAME,
- "best_app_developer");
- extraInfos.putParcelable(SearchResult.EXTRAINFO_ACTION_INSTALL_BUTTON, pendingIntent);
- extraInfos.putParcelable(SearchResult.EXTRAINFO_ACTION_APP_CARD, pendingIntent);
- extraInfos.putString(SearchResult.EXTRAINFO_APP_PACKAGE_NAME,
- "best_package_name");
- extraInfos.putDouble(SearchResult.EXTRAINFO_APP_INSTALL_COUNT, 10);
-
- SearchResult result = new SearchResult.Builder(title, extraInfos)
- .setSnippet(snippet).setTitle(title).setExtraInfos(extraInfos)
- .setScore(score).build();
-
- /** Checks the original result. */
- assertThat(result.getTitle()).isEqualTo(title);
- assertThat(result.getSnippet()).isEqualTo(snippet);
- assertThat(result.getScore()).isEqualTo(score);
- final Bundle rExtraInfos = result.getExtraInfos();
- assertThat(rExtraInfos
- .getBoolean(SearchResult.EXTRAINFO_APP_CONTAINS_IAP_DISCLAIMER))
- .isEqualTo(false);
- assertThat(rExtraInfos
- .getString(SearchResult.EXTRAINFO_APP_DEVELOPER_NAME))
- .isEqualTo("best_app_developer");
- assertThat((PendingIntent) rExtraInfos
- .getParcelable(SearchResult.EXTRAINFO_ACTION_INSTALL_BUTTON))
- .isEqualTo(pendingIntent);
- assertThat((PendingIntent) rExtraInfos
- .getParcelable(SearchResult.EXTRAINFO_ACTION_APP_CARD))
- .isEqualTo(pendingIntent);
- assertThat(rExtraInfos
- .getString(SearchResult.EXTRAINFO_APP_PACKAGE_NAME))
- .isEqualTo("best_package_name");
- assertThat(rExtraInfos
- .getDouble(SearchResult.EXTRAINFO_APP_INSTALL_COUNT))
- .isEqualTo(10);
-
- Parcel parcel = Parcel.obtain();
- parcel.setDataPosition(0);
- result.writeToParcel(parcel, 0);
- parcel.setDataPosition(0);
- SearchResult copy = SearchResult.CREATOR.createFromParcel(parcel);
- /** Checks the copied result. */
- assertThat(copy.getTitle()).isEqualTo(title);
- assertThat(copy.getSnippet()).isEqualTo(snippet);
- assertThat(copy.getScore()).isEqualTo(score);
- final Bundle rExtraInfosCopy = copy.getExtraInfos();
- assertThat(rExtraInfosCopy
- .getBoolean(SearchResult.EXTRAINFO_APP_CONTAINS_IAP_DISCLAIMER))
- .isEqualTo(false);
- assertThat(rExtraInfosCopy
- .getString(SearchResult.EXTRAINFO_APP_DEVELOPER_NAME))
- .isEqualTo("best_app_developer");
- assertThat((PendingIntent) rExtraInfosCopy
- .getParcelable(SearchResult.EXTRAINFO_ACTION_INSTALL_BUTTON))
- .isEqualTo(pendingIntent);
- assertThat((PendingIntent) rExtraInfosCopy
- .getParcelable(SearchResult.EXTRAINFO_ACTION_APP_CARD))
- .isEqualTo(pendingIntent);
- assertThat(rExtraInfosCopy
- .getString(SearchResult.EXTRAINFO_APP_PACKAGE_NAME))
- .isEqualTo("best_package_name");
- assertThat(rExtraInfosCopy
- .getDouble(SearchResult.EXTRAINFO_APP_INSTALL_COUNT))
- .isEqualTo(10);
-
- parcel.recycle();
- }
-}