Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.contextmenu; | 5 package org.chromium.chrome.browser.contextmenu; |
| 6 | 6 |
| 7 import android.content.ClipData; | 7 import android.content.ClipData; |
| 8 import android.content.ClipboardManager; | 8 import android.content.ClipboardManager; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.support.test.filters.LargeTest; | 10 import android.support.test.filters.LargeTest; |
| 11 import android.support.test.filters.MediumTest; | 11 import android.support.test.filters.MediumTest; |
| 12 import android.support.test.filters.SmallTest; | |
| 13 import android.test.MoreAsserts; | |
| 12 import android.view.ContextMenu; | 14 import android.view.ContextMenu; |
| 13 import android.view.KeyEvent; | 15 import android.view.KeyEvent; |
| 14 | 16 |
| 15 import org.chromium.base.ThreadUtils; | 17 import org.chromium.base.ThreadUtils; |
| 16 import org.chromium.base.test.util.CallbackHelper; | 18 import org.chromium.base.test.util.CallbackHelper; |
| 17 import org.chromium.base.test.util.CommandLineFlags; | 19 import org.chromium.base.test.util.CommandLineFlags; |
| 18 import org.chromium.base.test.util.Feature; | 20 import org.chromium.base.test.util.Feature; |
| 19 import org.chromium.base.test.util.FlakyTest; | 21 import org.chromium.base.test.util.FlakyTest; |
| 20 import org.chromium.base.test.util.RetryOnFailure; | 22 import org.chromium.base.test.util.RetryOnFailure; |
| 21 import org.chromium.chrome.R; | 23 import org.chromium.chrome.R; |
| 22 import org.chromium.chrome.browser.ChromeSwitches; | 24 import org.chromium.chrome.browser.ChromeSwitches; |
| 23 import org.chromium.chrome.browser.compositor.layouts.LayoutManager; | 25 import org.chromium.chrome.browser.compositor.layouts.LayoutManager; |
| 24 import org.chromium.chrome.browser.download.DownloadTestBase; | 26 import org.chromium.chrome.browser.download.DownloadTestBase; |
| 25 import org.chromium.chrome.browser.firstrun.FirstRunStatus; | 27 import org.chromium.chrome.browser.firstrun.FirstRunStatus; |
| 26 import org.chromium.chrome.browser.tab.Tab; | 28 import org.chromium.chrome.browser.tab.Tab; |
| 27 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; | 29 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; |
| 28 import org.chromium.chrome.browser.tabmodel.TabModel; | 30 import org.chromium.chrome.browser.tabmodel.TabModel; |
| 29 import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils; | 31 import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils; |
| 30 import org.chromium.content.browser.test.util.Criteria; | 32 import org.chromium.content.browser.test.util.Criteria; |
| 31 import org.chromium.content.browser.test.util.CriteriaHelper; | 33 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 32 import org.chromium.content.browser.test.util.DOMUtils; | 34 import org.chromium.content.browser.test.util.DOMUtils; |
| 33 import org.chromium.content.browser.test.util.TestTouchUtils; | 35 import org.chromium.content.browser.test.util.TestTouchUtils; |
| 34 import org.chromium.net.test.EmbeddedTestServer; | 36 import org.chromium.net.test.EmbeddedTestServer; |
| 35 | 37 |
| 36 import java.io.IOException; | 38 import java.io.IOException; |
| 39 import java.util.ArrayList; | |
| 40 import java.util.Collections; | |
| 41 import java.util.List; | |
| 37 import java.util.concurrent.Callable; | 42 import java.util.concurrent.Callable; |
| 38 import java.util.concurrent.TimeoutException; | 43 import java.util.concurrent.TimeoutException; |
| 39 import java.util.concurrent.atomic.AtomicReference; | 44 import java.util.concurrent.atomic.AtomicReference; |
| 40 | 45 |
| 41 /** | 46 /** |
| 42 * Context menu related tests | 47 * Context menu related tests |
| 43 */ | 48 */ |
| 44 @CommandLineFlags.Add({ | 49 @CommandLineFlags.Add({ |
| 45 ChromeSwitches.GOOGLE_BASE_URL + "=http://example.com/", | 50 ChromeSwitches.GOOGLE_BASE_URL + "=http://example.com/", |
| 46 ChromeSwitches.HERB_FLAVOR_DISABLED_SWITCH}) | 51 ChromeSwitches.HERB_FLAVOR_DISABLED_SWITCH}) |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 // Verify that the background tabs were opened in the expected order. | 346 // Verify that the background tabs were opened in the expected order. |
| 342 String newTabUrl = mTestServer.getURL( | 347 String newTabUrl = mTestServer.getURL( |
| 343 "/chrome/test/data/android/contextmenu/test_link.html"); | 348 "/chrome/test/data/android/contextmenu/test_link.html"); |
| 344 assertEquals(newTabUrl, tabModel.getTabAt(indexOfLinkPage).getUrl()); | 349 assertEquals(newTabUrl, tabModel.getTabAt(indexOfLinkPage).getUrl()); |
| 345 | 350 |
| 346 String imageUrl = mTestServer.getURL( | 351 String imageUrl = mTestServer.getURL( |
| 347 "/chrome/test/data/android/contextmenu/test_link2.html"); | 352 "/chrome/test/data/android/contextmenu/test_link2.html"); |
| 348 assertEquals(imageUrl, tabModel.getTabAt(indexOfLinkPage2).getUrl()); | 353 assertEquals(imageUrl, tabModel.getTabAt(indexOfLinkPage2).getUrl()); |
| 349 } | 354 } |
| 350 | 355 |
| 356 @SmallTest | |
| 357 @Feature({"Browser", "ContextMenu"}) | |
| 358 public void testContextMenuRetrievesLinkOptions() | |
| 359 throws TimeoutException, InterruptedException { | |
| 360 Tab tab = getActivity().getActivityTab(); | |
| 361 ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testLink"); | |
| 362 | |
| 363 List<Integer> expectedItems = new ArrayList<>(); | |
| 364 Collections.addAll(expectedItems, R.id.contextmenu_open_in_new_tab, | |
| 365 R.id.contextmenu_open_in_incognito_tab, R.id.contextmenu_copy_li nk_address, | |
| 366 R.id.contextmenu_copy_link_text, R.id.contextmenu_save_link_as); | |
| 367 assertMenuItemsAreEqual(menu, expectedItems); | |
| 368 } | |
| 369 | |
| 370 @SmallTest | |
| 371 @Feature({"Browser", "ContextMenu"}) | |
| 372 public void testContextMenuRetrievesImageOptions() | |
| 373 throws TimeoutException, InterruptedException { | |
| 374 Tab tab = getActivity().getActivityTab(); | |
| 375 ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImage"); | |
| 376 | |
| 377 List<Integer> expectedItems = new ArrayList<>(); | |
| 378 Collections.addAll(expectedItems, R.id.contextmenu_save_image, | |
| 379 R.id.contextmenu_open_image_in_new_tab, R.id.contextmenu_search_ by_image, | |
| 380 R.id.contextmenu_share_image); | |
| 381 assertMenuItemsAreEqual(menu, expectedItems); | |
| 382 } | |
| 383 | |
| 384 @SmallTest | |
| 385 @Feature({"Browser", "ContextMenu"}) | |
| 386 public void testContextMenuRetrievesImageLinkOptions() | |
| 387 throws TimeoutException, InterruptedException { | |
| 388 Tab tab = getActivity().getActivityTab(); | |
| 389 ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImageLink" ); | |
| 390 | |
| 391 List<Integer> expectedItems = new ArrayList<>(); | |
| 392 Collections.addAll(expectedItems, R.id.contextmenu_open_in_new_tab, | |
| 393 R.id.contextmenu_open_in_incognito_tab, R.id.contextmenu_copy_li nk_address, | |
| 394 R.id.contextmenu_save_link_as, R.id.contextmenu_save_image, | |
| 395 R.id.contextmenu_open_image_in_new_tab, R.id.contextmenu_search_ by_image, | |
| 396 R.id.contextmenu_share_image); | |
| 397 assertMenuItemsAreEqual(menu, expectedItems); | |
| 398 } | |
| 399 | |
| 400 @SmallTest | |
| 401 @Feature({"Browser", "ContextMenu"}) | |
| 402 public void testContextMenuRetrievesVideoOptions() | |
| 403 throws TimeoutException, InterruptedException { | |
| 404 Tab tab = getActivity().getActivityTab(); | |
| 405 DOMUtils.clickNode(getActivity().getCurrentContentViewCore(), "videoDOME lement"); | |
| 406 ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "videoDOMElemen t"); | |
| 407 | |
| 408 List<Integer> expectedItems = new ArrayList<>(); | |
| 409 expectedItems.add(R.id.contextmenu_save_video); | |
| 410 assertMenuItemsAreEqual(menu, expectedItems); | |
| 411 } | |
| 412 | |
| 413 /** | |
| 414 * Takes all the visible items on the menu and compares them to a the list o f expected items. | |
| 415 * @param menu A context menu that is displaying visible items. | |
| 416 * @param expectedItems A list of items that is expected to appear within a context menu. The | |
| 417 * list does not need to be ordered. | |
| 418 */ | |
| 419 private void assertMenuItemsAreEqual(ContextMenu menu, List<Integer> expecte dItems) { | |
|
Ted C
2017/03/01 06:30:49
Does a vararg as the second param not work? It se
JJ
2017/03/01 17:43:11
Super sorry. Again, implemented in a different bra
| |
| 420 List<Integer> actualItems = new ArrayList<>(); | |
| 421 for (int i = 0; i < menu.size(); i++) { | |
| 422 if (menu.getItem(i).isVisible()) { | |
| 423 actualItems.add(menu.getItem(i).getItemId()); | |
| 424 } | |
| 425 } | |
| 426 | |
| 427 MoreAsserts.assertContentsInAnyOrder(actualItems, expectedItems.toArray( )); | |
| 428 } | |
| 429 | |
| 351 private void saveMediaFromContextMenu(String mediaDOMElement, int saveMenuID , | 430 private void saveMediaFromContextMenu(String mediaDOMElement, int saveMenuID , |
| 352 String expectedFilename) throws InterruptedException, TimeoutExcepti on, | 431 String expectedFilename) throws InterruptedException, TimeoutExcepti on, |
| 353 SecurityException, IOException { | 432 SecurityException, IOException { |
| 354 // Select "save [image/video]" in that menu. | 433 // Select "save [image/video]" in that menu. |
| 355 Tab tab = getActivity().getActivityTab(); | 434 Tab tab = getActivity().getActivityTab(); |
| 356 int callCount = getChromeDownloadCallCount(); | 435 int callCount = getChromeDownloadCallCount(); |
| 357 ContextMenuUtils.selectContextMenuItem(this, tab, mediaDOMElement, saveM enuID); | 436 ContextMenuUtils.selectContextMenuItem(this, tab, mediaDOMElement, saveM enuID); |
| 358 | 437 |
| 359 // Wait for the download to complete and see if we got the right file | 438 // Wait for the download to complete and see if we got the right file |
| 360 assertTrue(waitForChromeDownloadToFinish(callCount)); | 439 assertTrue(waitForChromeDownloadToFinish(callCount)); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 376 } | 455 } |
| 377 | 456 |
| 378 /** | 457 /** |
| 379 * Makes sure there are no files with names identical to the ones this test uses in the | 458 * Makes sure there are no files with names identical to the ones this test uses in the |
| 380 * downloads directory | 459 * downloads directory |
| 381 */ | 460 */ |
| 382 private void deleteTestFiles() { | 461 private void deleteTestFiles() { |
| 383 deleteFilesInDownloadDirectory(TEST_FILES); | 462 deleteFilesInDownloadDirectory(TEST_FILES); |
| 384 } | 463 } |
| 385 } | 464 } |
| OLD | NEW |