CTS test for SearchEvent.
Bug: 21664320
Change-Id: I2a40a6c753ea30118f66d3840c1122d3994693b1
diff --git a/tests/tests/view/AndroidManifest.xml b/tests/tests/view/AndroidManifest.xml
index e5e77bc..65e95d5 100644
--- a/tests/tests/view/AndroidManifest.xml
+++ b/tests/tests/view/AndroidManifest.xml
@@ -175,6 +175,14 @@
</intent-filter>
</activity>
+ <activity android:name="android.view.cts.SearchEventActivity"
+ android:label="SearchEventActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+ </intent-filter>
+ </activity>
+
<activity android:name="android.view.cts.CtsActivity"
android:label="CtsActivity">
<intent-filter>
diff --git a/tests/tests/view/src/android/view/cts/SearchEventActivity.java b/tests/tests/view/src/android/view/cts/SearchEventActivity.java
new file mode 100644
index 0000000..6cc8c85
--- /dev/null
+++ b/tests/tests/view/src/android/view/cts/SearchEventActivity.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2015 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.cts;
+
+import com.android.cts.view.R;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.SearchEvent;
+
+public class SearchEventActivity extends Activity {
+
+ private static SearchEvent mSearchEvent;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.windowstub_layout);
+ }
+
+ @Override
+ public boolean onSearchRequested() {
+ mSearchEvent = getSearchEvent();
+ return true;
+ }
+
+ public SearchEvent getTestSearchEvent() {
+ return mSearchEvent;
+ }
+
+ public void reset() {
+ mSearchEvent = null;
+ }
+}
diff --git a/tests/tests/view/src/android/view/cts/SearchEventTest.java b/tests/tests/view/src/android/view/cts/SearchEventTest.java
new file mode 100644
index 0000000..4df52a1
--- /dev/null
+++ b/tests/tests/view/src/android/view/cts/SearchEventTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2015 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.cts;
+
+import com.android.cts.view.R;
+
+import android.app.Instrumentation;
+import android.test.ActivityInstrumentationTestCase2;
+import android.view.InputDevice;
+import android.view.KeyEvent;
+import android.view.SearchEvent;
+
+public class SearchEventTest extends ActivityInstrumentationTestCase2<SearchEventActivity> {
+
+ private Instrumentation mInstrumentation;
+ private SearchEventActivity mActivity;
+
+ public SearchEventTest() {
+ super(SearchEventActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mInstrumentation = getInstrumentation();
+ mActivity = getActivity();
+ }
+
+ public void testTest() throws Exception {
+ mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_SEARCH);
+ SearchEvent se = mActivity.getTestSearchEvent();
+ assertNotNull(se);
+ InputDevice id = se.getInputDevice();
+ assertNotNull(id);
+ assertEquals(-1, id.getId());
+ }
+}