Fix ActionBarTest for KEY_MENU with permanent menu key.
Bug: 70542855
When there is a permanent menu key, the action bar's option menu
doesn't open. Instead it opens an overflow menu. Therefore, the
action bar's menu listener is not triggered. Two tests check for
a callback from the action bar menu.
This disables the action bar menu tests when there is a permanent
menu key.
Test: ran ActionBarTest with an without permanent key
Change-Id: I7fa619607798e419afe535c0b52af6ed189f3e3f
Cherry-Picked from master: Id8583d87503cbdf6833ea85c097e3e95f8fce80c
(cherry picked from commit 88f2d8b7425677ea16f70f99c407f67baeb57df8)
Change-Id: I0b94938353dffe18b962fbb0bd9bccc6f4029a86
diff --git a/tests/app/src/android/app/cts/ActionBarTest.java b/tests/app/src/android/app/cts/ActionBarTest.java
index 2cfc970..d6e41a0 100644
--- a/tests/app/src/android/app/cts/ActionBarTest.java
+++ b/tests/app/src/android/app/cts/ActionBarTest.java
@@ -23,6 +23,7 @@
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
import android.view.KeyEvent;
+import android.view.ViewConfiguration;
import android.view.Window;
import java.util.concurrent.TimeUnit;
@@ -86,7 +87,9 @@
}
public void testOptionsMenuKey() throws Exception {
- if (!mActivity.getWindow().hasFeature(Window.FEATURE_OPTIONS_PANEL)) {
+ boolean hasPermanentMenuKey = ViewConfiguration.get(getActivity()).hasPermanentMenuKey();
+ if (!mActivity.getWindow().hasFeature(Window.FEATURE_OPTIONS_PANEL)
+ || hasPermanentMenuKey) {
return;
}
final boolean menuIsVisible[] = {false};
@@ -94,17 +97,20 @@
isVisible -> menuIsVisible[0] = isVisible);
// Wait here for test activity to gain focus before sending keyevent.
// Visibility listener needs the action bar to be visible.
- assertTrue(mActivity.windowFocusSignal.await(1000, TimeUnit.MILLISECONDS));
getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
getInstrumentation().waitForIdleSync();
assertTrue(menuIsVisible[0]);
+ assertTrue(mActivity.windowFocusSignal.await(1000, TimeUnit.MILLISECONDS));
getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
getInstrumentation().waitForIdleSync();
+ assertTrue(mActivity.windowFocusSignal.await(1000, TimeUnit.MILLISECONDS));
assertFalse(menuIsVisible[0]);
}
public void testOpenOptionsMenu() {
- if (!mActivity.getWindow().hasFeature(Window.FEATURE_OPTIONS_PANEL)) {
+ boolean hasPermanentMenuKey = ViewConfiguration.get(getActivity()).hasPermanentMenuKey();
+ if (!mActivity.getWindow().hasFeature(Window.FEATURE_OPTIONS_PANEL)
+ || hasPermanentMenuKey) {
return;
}
final boolean menuIsVisible[] = {false};