CTS Tests for Activity#onProvideKeyboardShortcuts
Also fixes implementations of Window.Callback
Bug: 22405482
Change-Id: I8c7bbccc27f76728a111edab315c4acd74ed1f55
diff --git a/tests/app/app/AndroidManifest.xml b/tests/app/app/AndroidManifest.xml
index c45bb2f..c64e977 100644
--- a/tests/app/app/AndroidManifest.xml
+++ b/tests/app/app/AndroidManifest.xml
@@ -320,6 +320,8 @@
</intent-filter>
</activity>
+ <activity android:name="android.app.stubs.KeyboardShortcutsActivity" />
+
</application>
</manifest>
diff --git a/tests/app/app/src/android/app/stubs/KeyboardShortcutsActivity.java b/tests/app/app/src/android/app/stubs/KeyboardShortcutsActivity.java
new file mode 100644
index 0000000..dd9d1dc
--- /dev/null
+++ b/tests/app/app/src/android/app/stubs/KeyboardShortcutsActivity.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2016 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.app.stubs;
+
+import android.app.Activity;
+import android.view.Menu;
+
+public class KeyboardShortcutsActivity extends Activity {
+
+ public static final String ITEM_1_NAME = "item 1";
+ public static final char ITEM_1_SHORTCUT = 'i';
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ menu.add(ITEM_1_NAME).setAlphabeticShortcut(ITEM_1_SHORTCUT);
+ return true;
+ }
+}
diff --git a/tests/app/src/android/app/cts/ActivityKeyboardShortcutsTest.java b/tests/app/src/android/app/cts/ActivityKeyboardShortcutsTest.java
new file mode 100644
index 0000000..3e48b1e
--- /dev/null
+++ b/tests/app/src/android/app/cts/ActivityKeyboardShortcutsTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2016 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.app.cts;
+
+import android.app.Activity;
+import android.app.stubs.KeyboardShortcutsActivity;
+import android.test.ActivityInstrumentationTestCase2;
+import android.view.KeyEvent;
+import android.view.KeyboardShortcutGroup;
+import android.view.Menu;
+import android.widget.PopupMenu;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests functionality in Activity related to Keyboard Shortcuts.
+ */
+public class ActivityKeyboardShortcutsTest
+ extends ActivityInstrumentationTestCase2<KeyboardShortcutsActivity> {
+
+ private Activity mActivity;
+ private Menu mMenu;
+
+ public ActivityKeyboardShortcutsTest() {
+ super(KeyboardShortcutsActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ mMenu = new PopupMenu(mActivity, null).getMenu();
+ }
+
+ public void testOnProvideKeyboardShortcuts() {
+ List<KeyboardShortcutGroup> data = new ArrayList<>();
+ mActivity.onCreateOptionsMenu(mMenu);
+ mActivity.onProvideKeyboardShortcuts(data, mMenu);
+
+ assertEquals(1, data.size());
+ assertEquals(1, data.get(0).getItems().size());
+ assertEquals(KeyboardShortcutsActivity.ITEM_1_NAME,
+ data.get(0).getItems().get(0).getLabel());
+ assertEquals(KeyboardShortcutsActivity.ITEM_1_SHORTCUT,
+ data.get(0).getItems().get(0).getBaseCharacter());
+ assertEquals(KeyEvent.META_CTRL_ON, data.get(0).getItems().get(0).getModifiers());
+ }
+}
diff --git a/tests/tests/view/src/android/view/cts/WindowTest.java b/tests/tests/view/src/android/view/cts/WindowTest.java
index bc786af..d76b985 100644
--- a/tests/tests/view/src/android/view/cts/WindowTest.java
+++ b/tests/tests/view/src/android/view/cts/WindowTest.java
@@ -46,6 +46,7 @@
import android.view.InputDevice;
import android.view.InputQueue;
import android.view.KeyEvent;
+import android.view.KeyboardShortcutGroup;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@@ -62,6 +63,7 @@
import android.widget.Button;
import android.widget.TextView;
+import java.util.List;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
@@ -1149,5 +1151,8 @@
public void onWindowDismissed() {
}
+
+ public void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, Menu menu) {
+ }
}
}