| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.customtabs; | 5 package org.chromium.chrome.browser.customtabs; |
| 6 | 6 |
| 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; | 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; |
| 8 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_PHONE; | 8 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_PHONE; |
| 9 | 9 |
| 10 import android.app.Activity; | 10 import android.app.Activity; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 171 |
| 172 CriteriaHelper.pollForUIThreadCriteria(new Criteria("App menu was not sh
own") { | 172 CriteriaHelper.pollForUIThreadCriteria(new Criteria("App menu was not sh
own") { |
| 173 @Override | 173 @Override |
| 174 public boolean isSatisfied() { | 174 public boolean isSatisfied() { |
| 175 return mActivity.getAppMenuHandler().isAppMenuShowing(); | 175 return mActivity.getAppMenuHandler().isAppMenuShowing(); |
| 176 } | 176 } |
| 177 }); | 177 }); |
| 178 } | 178 } |
| 179 | 179 |
| 180 /** | 180 /** |
| 181 * @return The number of visible and enabled items in the given menu. |
| 182 */ |
| 183 private int getActualMenuSize(Menu menu) { |
| 184 int actualMenuSize = 0; |
| 185 for (int i = 0; i < menu.size(); i++) { |
| 186 MenuItem item = menu.getItem(i); |
| 187 if (item.isVisible() && item.isEnabled()) actualMenuSize++; |
| 188 } |
| 189 return actualMenuSize; |
| 190 } |
| 191 |
| 192 /** |
| 181 * Test the entries in the context menu shown when long clicking an image. | 193 * Test the entries in the context menu shown when long clicking an image. |
| 182 */ | 194 */ |
| 183 @SmallTest | 195 @SmallTest |
| 184 public void testContextMenuEntriesForImage() throws InterruptedException, Ti
meoutException { | 196 public void testContextMenuEntriesForImage() throws InterruptedException, Ti
meoutException { |
| 185 startCustomTabActivityWithIntent(createMinimalCustomTabIntent()); | 197 startCustomTabActivityWithIntent(createMinimalCustomTabIntent()); |
| 186 | 198 |
| 187 final int expectedMenuSize = 9; | 199 final int expectedMenuSize = 9; |
| 188 Menu menu = ContextMenuUtils.openContextMenu(this, getActivity().getActi
vityTab(), "logo"); | 200 Menu menu = ContextMenuUtils.openContextMenu(this, getActivity().getActi
vityTab(), "logo"); |
| 189 assertEquals(expectedMenuSize, menu.size()); | 201 assertEquals(expectedMenuSize, menu.size()); |
| 190 | 202 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 assertFalse(menu.findItem(R.id.contextmenu_save_image).isVisible()); | 251 assertFalse(menu.findItem(R.id.contextmenu_save_image).isVisible()); |
| 240 assertFalse(menu.findItem(R.id.contextmenu_open_image).isVisible()); | 252 assertFalse(menu.findItem(R.id.contextmenu_open_image).isVisible()); |
| 241 assertFalse(menu.findItem(R.id.contextmenu_search_by_image).isVisible())
; | 253 assertFalse(menu.findItem(R.id.contextmenu_search_by_image).isVisible())
; |
| 242 assertFalse(menu.findItem(R.id.contextmenu_save_video).isVisible()); | 254 assertFalse(menu.findItem(R.id.contextmenu_save_video).isVisible()); |
| 243 } | 255 } |
| 244 | 256 |
| 245 /** | 257 /** |
| 246 * Test the entries in the app menu. | 258 * Test the entries in the app menu. |
| 247 */ | 259 */ |
| 248 @SmallTest | 260 @SmallTest |
| 249 public void testCustomTabAppMenu() throws InterruptedException { | 261 public void testAppMenu() throws InterruptedException { |
| 250 Intent intent = createMinimalCustomTabIntent(); | 262 Intent intent = createMinimalCustomTabIntent(); |
| 251 int numMenuEntries = 1; | 263 int numMenuEntries = 1; |
| 252 addMenuEntriesToIntent(intent, numMenuEntries); | 264 addMenuEntriesToIntent(intent, numMenuEntries); |
| 253 startCustomTabActivityWithIntent(intent); | 265 startCustomTabActivityWithIntent(intent); |
| 254 | 266 |
| 255 openAppMenuAndAssertMenuShown(); | 267 openAppMenuAndAssertMenuShown(); |
| 268 Menu menu = getActivity().getAppMenuHandler().getAppMenu().getMenu(); |
| 256 final int expectedMenuSize = numMenuEntries + NUM_CHROME_MENU_ITEMS; | 269 final int expectedMenuSize = numMenuEntries + NUM_CHROME_MENU_ITEMS; |
| 257 Menu menu = getActivity().getAppMenuHandler().getAppMenu().getMenu(); | 270 final int actualMenuSize = getActualMenuSize(menu); |
| 271 |
| 258 assertNotNull("App menu is not initialized: ", menu); | 272 assertNotNull("App menu is not initialized: ", menu); |
| 259 assertEquals(expectedMenuSize, menu.size()); | 273 assertEquals(expectedMenuSize, actualMenuSize); |
| 260 assertNotNull(menu.findItem(R.id.forward_menu_id)); | 274 assertNotNull(menu.findItem(R.id.forward_menu_id)); |
| 261 assertNotNull(menu.findItem(R.id.info_menu_id)); | 275 assertNotNull(menu.findItem(R.id.info_menu_id)); |
| 262 assertNotNull(menu.findItem(R.id.reload_menu_id)); | 276 assertNotNull(menu.findItem(R.id.reload_menu_id)); |
| 263 assertNotNull(menu.findItem(R.id.find_in_page_id)); | 277 assertNotNull(menu.findItem(R.id.find_in_page_id)); |
| 264 assertNotNull(menu.findItem(R.id.open_in_chrome_id)); | 278 assertNotNull(menu.findItem(R.id.open_in_chrome_id)); |
| 279 assertFalse(menu.findItem(R.id.share_menu_id).isVisible()); |
| 280 assertFalse(menu.findItem(R.id.share_menu_id).isEnabled()); |
| 265 } | 281 } |
| 266 | 282 |
| 267 /** | 283 /** |
| 284 * Tests if the default share item can be shown in the app menu. |
| 285 */ |
| 286 @SmallTest |
| 287 public void testShareMenuItem() throws InterruptedException { |
| 288 Intent intent = createMinimalCustomTabIntent(); |
| 289 intent.putExtra(CustomTabsIntent.EXTRA_DEFAULT_SHARE_MENU_ITEM, true); |
| 290 startCustomTabActivityWithIntent(intent); |
| 291 |
| 292 openAppMenuAndAssertMenuShown(); |
| 293 Menu menu = getActivity().getAppMenuHandler().getAppMenu().getMenu(); |
| 294 assertTrue(menu.findItem(R.id.share_menu_id).isVisible()); |
| 295 assertTrue(menu.findItem(R.id.share_menu_id).isEnabled()); |
| 296 } |
| 297 |
| 298 |
| 299 /** |
| 268 * Test that only up to 5 entries are added to the custom menu. | 300 * Test that only up to 5 entries are added to the custom menu. |
| 269 */ | 301 */ |
| 270 @SmallTest | 302 @SmallTest |
| 271 public void testCustomTabMaxMenuItems() throws InterruptedException { | 303 public void testMaxMenuItems() throws InterruptedException { |
| 272 Intent intent = createMinimalCustomTabIntent(); | 304 Intent intent = createMinimalCustomTabIntent(); |
| 273 int numMenuEntries = 7; | 305 int numMenuEntries = 7; |
| 274 addMenuEntriesToIntent(intent, numMenuEntries); | 306 addMenuEntriesToIntent(intent, numMenuEntries); |
| 275 startCustomTabActivityWithIntent(intent); | 307 startCustomTabActivityWithIntent(intent); |
| 276 | 308 |
| 277 openAppMenuAndAssertMenuShown(); | 309 openAppMenuAndAssertMenuShown(); |
| 278 int expectedMenuSize = MAX_MENU_CUSTOM_ITEMS + NUM_CHROME_MENU_ITEMS; | |
| 279 Menu menu = getActivity().getAppMenuHandler().getAppMenu().getMenu(); | 310 Menu menu = getActivity().getAppMenuHandler().getAppMenu().getMenu(); |
| 311 final int expectedMenuSize = MAX_MENU_CUSTOM_ITEMS + NUM_CHROME_MENU_ITE
MS; |
| 312 final int actualMenuSize = getActualMenuSize(menu); |
| 280 assertNotNull("App menu is not initialized: ", menu); | 313 assertNotNull("App menu is not initialized: ", menu); |
| 281 assertEquals(expectedMenuSize, menu.size()); | 314 assertEquals(expectedMenuSize, actualMenuSize); |
| 282 } | 315 } |
| 283 | 316 |
| 284 /** | 317 /** |
| 285 * Test whether the custom menu is correctly shown and clicking it sends the
right | 318 * Test whether the custom menu is correctly shown and clicking it sends the
right |
| 286 * {@link PendingIntent}. | 319 * {@link PendingIntent}. |
| 287 */ | 320 */ |
| 288 @SmallTest | 321 @SmallTest |
| 289 public void testCustomMenuEntry() throws InterruptedException { | 322 public void testCustomMenuEntry() throws InterruptedException { |
| 290 Intent intent = createMinimalCustomTabIntent(); | 323 Intent intent = createMinimalCustomTabIntent(); |
| 291 final PendingIntent pi = addMenuEntriesToIntent(intent, 1); | 324 final PendingIntent pi = addMenuEntriesToIntent(intent, 1); |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 @Override | 810 @Override |
| 778 public void onSendFinished(PendingIntent pendingIntent, Intent intent, i
nt resultCode, | 811 public void onSendFinished(PendingIntent pendingIntent, Intent intent, i
nt resultCode, |
| 779 String resultData, Bundle resultExtras) { | 812 String resultData, Bundle resultExtras) { |
| 780 if (pendingIntent.equals(mPi)) { | 813 if (pendingIntent.equals(mPi)) { |
| 781 mUri = intent.getDataString(); | 814 mUri = intent.getDataString(); |
| 782 mIsSent.set(true); | 815 mIsSent.set(true); |
| 783 } | 816 } |
| 784 } | 817 } |
| 785 } | 818 } |
| 786 } | 819 } |
| OLD | NEW |