diff options
author | Yusuf Ozuysal <yusufo@google.com> | 2015-09-02 18:00:55 -0700 |
---|---|---|
committer | Yusuf Ozuysal <yusufo@google.com> | 2015-09-03 01:01:51 +0000 |
commit | 1ecdcef6078be745fa8406cd9e71c77129501033 (patch) | |
tree | 77788d9895dc55cebe0049be82b9e264ef732b5c | |
parent | 926221f35b60f7375533a22ad7274a0a5584ba47 (diff) | |
download | chromium_src-1ecdcef6078be745fa8406cd9e71c77129501033.zip chromium_src-1ecdcef6078be745fa8406cd9e71c77129501033.tar.gz chromium_src-1ecdcef6078be745fa8406cd9e71c77129501033.tar.bz2 |
Limit the number of custom menu items to 5
Right now we don't have a strict limit on number of custom
menu items. Declaring this to be 5 initially.
BUG=527478
TEST=CustomTabActivityTest#testCustomTabMaxMenuItems
Review URL: https://codereview.chromium.org/1321203005 .
Cr-Commit-Position: refs/branch-heads/2490@{#144}
Cr-Branched-From: 7790a3535f2a81a03685eca31a32cf69ae0c114f-refs/heads/master@{#344925}
2 files changed, 33 insertions, 9 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java index ee99a09..c98aa5d 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java @@ -72,6 +72,7 @@ public class CustomTabIntentDataProvider { public static final String EXTRA_TINT_ACTION_BUTTON = "android.support.customtabs.extra.TINT_ACTION_BUTTON"; + private static final int MAX_CUSTOM_MENU_ITEMS = 5; private static final String BUNDLE_PACKAGE_NAME = "android:packageName"; private static final String BUNDLE_ENTER_ANIMATION_RESOURCE = "android:animEnterRes"; private static final String BUNDLE_EXIT_ANIMATION_RESOURCE = "android:animExitRes"; @@ -140,7 +141,8 @@ public class CustomTabIntentDataProvider { List<Bundle> menuItems = IntentUtils.getParcelableArrayListExtra(intent, CustomTabsIntent.EXTRA_MENU_ITEMS); if (menuItems != null) { - for (Bundle bundle : menuItems) { + for (int i = 0; i < Math.min(MAX_CUSTOM_MENU_ITEMS, menuItems.size()); i++) { + Bundle bundle = menuItems.get(i); String title = IntentUtils.safeGetString(bundle, CustomTabsIntent.KEY_MENU_ITEM_TITLE); PendingIntent pendingIntent = diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java index 56c1b36..52af904 100644 --- a/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java @@ -75,6 +75,8 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase { } } + private static final int MAX_MENU_CUSTOM_ITEMS = 5; + private static final int NUM_CHROME_MENU_ITEMS = 3; private static final String TEST_ACTION = "org.chromium.chrome.browser.customtabs.TEST_PENDING_INTENT_SENT"; private static final String TEST_PAGE = TestHttpServerClient.getUrl( @@ -104,17 +106,19 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase { * @param intent The intent to modify. * @return The pending intent associated with the menu entry. */ - private PendingIntent addMenuEntryToIntent(Intent intent) { + private PendingIntent addMenuEntriesToIntent(Intent intent, int numEntries) { Intent menuIntent = new Intent(); menuIntent.setClass(getInstrumentation().getContext(), DummyBroadcastReceiver.class); menuIntent.setAction(TEST_ACTION); PendingIntent pi = PendingIntent.getBroadcast(getInstrumentation().getTargetContext(), 0, menuIntent, 0); - Bundle bundle = new Bundle(); - bundle.putString(CustomTabsIntent.KEY_MENU_ITEM_TITLE, TEST_MENU_TITLE); - bundle.putParcelable(CustomTabsIntent.KEY_PENDING_INTENT, pi); ArrayList<Bundle> menuItems = new ArrayList<Bundle>(); - menuItems.add(bundle); + for (int i = 0; i < numEntries; i++) { + Bundle bundle = new Bundle(); + bundle.putString(CustomTabsIntent.KEY_MENU_ITEM_TITLE, TEST_MENU_TITLE); + bundle.putParcelable(CustomTabsIntent.KEY_PENDING_INTENT, pi); + menuItems.add(bundle); + } intent.putParcelableArrayListExtra(CustomTabsIntent.EXTRA_MENU_ITEMS, menuItems); return pi; } @@ -197,11 +201,12 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase { @SmallTest public void testCustomTabAppMenu() throws InterruptedException { Intent intent = createMinimalCustomTabIntent(); - addMenuEntryToIntent(intent); + int numMenuEntries = 1; + addMenuEntriesToIntent(intent, numMenuEntries); startCustomTabActivityWithIntent(intent); openAppMenuAndAssertMenuShown(); - final int expectedMenuSize = 4; + final int expectedMenuSize = numMenuEntries + NUM_CHROME_MENU_ITEMS; Menu menu = getActivity().getAppMenuHandler().getAppMenuForTest().getMenuForTest(); assertNotNull("App menu is not initialized: ", menu); assertEquals(expectedMenuSize, menu.size()); @@ -213,13 +218,30 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase { } /** + * Test that only up to 5 entries are added to the custom menu. + */ + @SmallTest + public void testCustomTabMaxMenuItems() throws InterruptedException { + Intent intent = createMinimalCustomTabIntent(); + int numMenuEntries = 7; + addMenuEntriesToIntent(intent, numMenuEntries); + startCustomTabActivityWithIntent(intent); + + openAppMenuAndAssertMenuShown(); + int expectedMenuSize = MAX_MENU_CUSTOM_ITEMS + NUM_CHROME_MENU_ITEMS; + Menu menu = getActivity().getAppMenuHandler().getAppMenuForTest().getMenuForTest(); + assertNotNull("App menu is not initialized: ", menu); + assertEquals(expectedMenuSize, menu.size()); + } + + /** * Test whether the custom menu is correctly shown and clicking it sends the right * {@link PendingIntent}. */ @SmallTest public void testCustomMenuEntry() throws InterruptedException { Intent intent = createMinimalCustomTabIntent(); - final PendingIntent pi = addMenuEntryToIntent(intent); + final PendingIntent pi = addMenuEntriesToIntent(intent, 1); startCustomTabActivityWithIntent(intent); final OnFinishedForTest onFinished = new OnFinishedForTest(pi); |