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.List; | |
37 import java.util.concurrent.Callable; | 41 import java.util.concurrent.Callable; |
38 import java.util.concurrent.TimeoutException; | 42 import java.util.concurrent.TimeoutException; |
39 import java.util.concurrent.atomic.AtomicReference; | 43 import java.util.concurrent.atomic.AtomicReference; |
40 | 44 |
41 /** | 45 /** |
42 * Context menu related tests | 46 * Context menu related tests |
43 */ | 47 */ |
44 @CommandLineFlags.Add({ | 48 @CommandLineFlags.Add({ |
45 ChromeSwitches.GOOGLE_BASE_URL + "=http://example.com/", | 49 ChromeSwitches.GOOGLE_BASE_URL + "=http://example.com/", |
46 ChromeSwitches.HERB_FLAVOR_DISABLED_SWITCH}) | 50 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. | 345 // Verify that the background tabs were opened in the expected order. |
342 String newTabUrl = mTestServer.getURL( | 346 String newTabUrl = mTestServer.getURL( |
343 "/chrome/test/data/android/contextmenu/test_link.html"); | 347 "/chrome/test/data/android/contextmenu/test_link.html"); |
344 assertEquals(newTabUrl, tabModel.getTabAt(indexOfLinkPage).getUrl()); | 348 assertEquals(newTabUrl, tabModel.getTabAt(indexOfLinkPage).getUrl()); |
345 | 349 |
346 String imageUrl = mTestServer.getURL( | 350 String imageUrl = mTestServer.getURL( |
347 "/chrome/test/data/android/contextmenu/test_link2.html"); | 351 "/chrome/test/data/android/contextmenu/test_link2.html"); |
348 assertEquals(imageUrl, tabModel.getTabAt(indexOfLinkPage2).getUrl()); | 352 assertEquals(imageUrl, tabModel.getTabAt(indexOfLinkPage2).getUrl()); |
349 } | 353 } |
350 | 354 |
355 @SmallTest | |
356 @Feature({"Browser", "ContextMenu"}) | |
357 @RetryOnFailure | |
JJ
2017/03/01 17:43:11
By happenstance this test failed in my most recent
Ted C
2017/03/01 17:57:40
Looks like this whole class has them, so I guess t
JJ
2017/03/01 19:00:50
This seems to be the closest one: https://bugs.chr
| |
358 public void testContextMenuRetrievesLinkOptions() | |
359 throws TimeoutException, InterruptedException { | |
360 Tab tab = getActivity().getActivityTab(); | |
361 ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testLink"); | |
362 | |
363 Integer[] expectedItems = {R.id.contextmenu_open_in_new_tab, | |
364 R.id.contextmenu_open_in_incognito_tab, R.id.contextmenu_copy_li nk_address, | |
365 R.id.contextmenu_copy_link_text, R.id.contextmenu_save_link_as}; | |
366 assertMenuItemsAreEqual(menu, expectedItems); | |
367 } | |
368 | |
369 @SmallTest | |
370 @Feature({"Browser", "ContextMenu"}) | |
371 @RetryOnFailure | |
372 public void testContextMenuRetrievesImageOptions() | |
373 throws TimeoutException, InterruptedException { | |
374 Tab tab = getActivity().getActivityTab(); | |
375 ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImage"); | |
376 | |
377 Integer[] expectedItems = {R.id.contextmenu_save_image, | |
378 R.id.contextmenu_open_image_in_new_tab, R.id.contextmenu_search_ by_image, | |
379 R.id.contextmenu_share_image}; | |
380 assertMenuItemsAreEqual(menu, expectedItems); | |
381 } | |
382 | |
383 @SmallTest | |
384 @Feature({"Browser", "ContextMenu"}) | |
385 @RetryOnFailure | |
386 public void testContextMenuRetrievesImageLinkOptions() | |
387 throws TimeoutException, InterruptedException { | |
388 Tab tab = getActivity().getActivityTab(); | |
389 ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImageLink" ); | |
390 | |
391 Integer[] expectedItems = {R.id.contextmenu_open_in_new_tab, | |
392 R.id.contextmenu_open_in_incognito_tab, R.id.contextmenu_copy_li nk_address, | |
393 R.id.contextmenu_save_link_as, R.id.contextmenu_save_image, | |
394 R.id.contextmenu_open_image_in_new_tab, R.id.contextmenu_search_ by_image, | |
395 R.id.contextmenu_share_image}; | |
396 assertMenuItemsAreEqual(menu, expectedItems); | |
397 } | |
398 | |
399 @SmallTest | |
400 @Feature({"Browser", "ContextMenu"}) | |
401 @RetryOnFailure | |
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 Integer[] expectedItems = {R.id.contextmenu_save_video}; | |
409 assertMenuItemsAreEqual(menu, expectedItems); | |
410 } | |
411 | |
412 /** | |
413 * Takes all the visible items on the menu and compares them to a the list o f expected items. | |
414 * @param menu A context menu that is displaying visible items. | |
415 * @param expectedItems A list of items that is expected to appear within a context menu. The | |
416 * list does not need to be ordered. | |
417 */ | |
418 private void assertMenuItemsAreEqual(ContextMenu menu, Integer... expectedIt ems) { | |
419 List<Integer> actualItems = new ArrayList<>(); | |
420 for (int i = 0; i < menu.size(); i++) { | |
421 if (menu.getItem(i).isVisible()) { | |
422 actualItems.add(menu.getItem(i).getItemId()); | |
423 } | |
424 } | |
425 | |
426 MoreAsserts.assertContentsInAnyOrder(actualItems, expectedItems); | |
427 } | |
428 | |
351 private void saveMediaFromContextMenu(String mediaDOMElement, int saveMenuID , | 429 private void saveMediaFromContextMenu(String mediaDOMElement, int saveMenuID , |
352 String expectedFilename) throws InterruptedException, TimeoutExcepti on, | 430 String expectedFilename) throws InterruptedException, TimeoutExcepti on, |
353 SecurityException, IOException { | 431 SecurityException, IOException { |
354 // Select "save [image/video]" in that menu. | 432 // Select "save [image/video]" in that menu. |
355 Tab tab = getActivity().getActivityTab(); | 433 Tab tab = getActivity().getActivityTab(); |
356 int callCount = getChromeDownloadCallCount(); | 434 int callCount = getChromeDownloadCallCount(); |
357 ContextMenuUtils.selectContextMenuItem(this, tab, mediaDOMElement, saveM enuID); | 435 ContextMenuUtils.selectContextMenuItem(this, tab, mediaDOMElement, saveM enuID); |
358 | 436 |
359 // Wait for the download to complete and see if we got the right file | 437 // Wait for the download to complete and see if we got the right file |
360 assertTrue(waitForChromeDownloadToFinish(callCount)); | 438 assertTrue(waitForChromeDownloadToFinish(callCount)); |
(...skipping 15 matching lines...) Expand all Loading... | |
376 } | 454 } |
377 | 455 |
378 /** | 456 /** |
379 * Makes sure there are no files with names identical to the ones this test uses in the | 457 * Makes sure there are no files with names identical to the ones this test uses in the |
380 * downloads directory | 458 * downloads directory |
381 */ | 459 */ |
382 private void deleteTestFiles() { | 460 private void deleteTestFiles() { |
383 deleteFilesInDownloadDirectory(TEST_FILES); | 461 deleteFilesInDownloadDirectory(TEST_FILES); |
384 } | 462 } |
385 } | 463 } |
OLD | NEW |