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; | |
12 import android.view.ContextMenu; | 13 import android.view.ContextMenu; |
13 import android.view.KeyEvent; | 14 import android.view.KeyEvent; |
14 | 15 |
15 import org.chromium.base.ThreadUtils; | 16 import org.chromium.base.ThreadUtils; |
16 import org.chromium.base.test.util.CallbackHelper; | 17 import org.chromium.base.test.util.CallbackHelper; |
17 import org.chromium.base.test.util.CommandLineFlags; | 18 import org.chromium.base.test.util.CommandLineFlags; |
18 import org.chromium.base.test.util.Feature; | 19 import org.chromium.base.test.util.Feature; |
19 import org.chromium.base.test.util.FlakyTest; | 20 import org.chromium.base.test.util.FlakyTest; |
20 import org.chromium.base.test.util.RetryOnFailure; | 21 import org.chromium.base.test.util.RetryOnFailure; |
21 import org.chromium.chrome.R; | 22 import org.chromium.chrome.R; |
22 import org.chromium.chrome.browser.ChromeSwitches; | 23 import org.chromium.chrome.browser.ChromeSwitches; |
23 import org.chromium.chrome.browser.compositor.layouts.LayoutManager; | 24 import org.chromium.chrome.browser.compositor.layouts.LayoutManager; |
24 import org.chromium.chrome.browser.download.DownloadTestBase; | 25 import org.chromium.chrome.browser.download.DownloadTestBase; |
25 import org.chromium.chrome.browser.firstrun.FirstRunStatus; | 26 import org.chromium.chrome.browser.firstrun.FirstRunStatus; |
26 import org.chromium.chrome.browser.tab.Tab; | 27 import org.chromium.chrome.browser.tab.Tab; |
27 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; | 28 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; |
28 import org.chromium.chrome.browser.tabmodel.TabModel; | 29 import org.chromium.chrome.browser.tabmodel.TabModel; |
29 import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils; | 30 import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils; |
30 import org.chromium.content.browser.test.util.Criteria; | 31 import org.chromium.content.browser.test.util.Criteria; |
31 import org.chromium.content.browser.test.util.CriteriaHelper; | 32 import org.chromium.content.browser.test.util.CriteriaHelper; |
32 import org.chromium.content.browser.test.util.DOMUtils; | 33 import org.chromium.content.browser.test.util.DOMUtils; |
33 import org.chromium.content.browser.test.util.TestTouchUtils; | 34 import org.chromium.content.browser.test.util.TestTouchUtils; |
34 import org.chromium.net.test.EmbeddedTestServer; | 35 import org.chromium.net.test.EmbeddedTestServer; |
35 | 36 |
36 import java.io.IOException; | 37 import java.io.IOException; |
38 import java.util.ArrayList; | |
39 import java.util.Collections; | |
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 public void testContextMenuRetrievesLinkOptions() | |
358 throws TimeoutException, InterruptedException { | |
359 Tab tab = getActivity().getActivityTab(); | |
360 ContextMenu menu = ContextMenuUtils.openContextMenu(this, tab, "testLink "); | |
361 | |
362 List<Integer> expectedItems = new ArrayList<>(); | |
363 Collections.addAll(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 assertTrue(confirmMenuList(menu, expectedItems)); | |
367 } | |
368 | |
369 @SmallTest | |
370 @Feature({"Browser", "ContextMenu"}) | |
371 public void testContextMenuRetrievesImageOptions() | |
372 throws TimeoutException, InterruptedException { | |
373 Tab tab = getActivity().getActivityTab(); | |
374 ContextMenu menu = ContextMenuUtils.openContextMenu(this, tab, "testImag e"); | |
375 | |
376 List<Integer> expectedItems = new ArrayList<>(); | |
377 Collections.addAll(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 assertTrue(confirmMenuList(menu, expectedItems)); | |
381 } | |
382 | |
383 @SmallTest | |
384 @Feature({"Browser", "ContextMenu"}) | |
385 public void testContextMenuRetrievesImageLinkOptions() | |
386 throws TimeoutException, InterruptedException { | |
387 Tab tab = getActivity().getActivityTab(); | |
388 ContextMenu menu = ContextMenuUtils.openContextMenu(this, tab, "testImag eLink"); | |
389 | |
390 List<Integer> expectedItems = new ArrayList<>(); | |
391 Collections.addAll(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 assertTrue(confirmMenuList(menu, expectedItems)); | |
397 } | |
398 | |
399 @SmallTest | |
400 @Feature({"Browser", "ContextMenu"}) | |
401 public void testContextMenuRetrievesVideoOptions() | |
402 throws TimeoutException, InterruptedException { | |
403 Tab tab = getActivity().getActivityTab(); | |
404 DOMUtils.clickNode(this, getActivity().getCurrentContentViewCore(), "vid eoDOMElement"); | |
405 ContextMenu menu = ContextMenuUtils.openContextMenu(this, tab, "videoDOM Element"); | |
406 | |
407 List<Integer> expectedItems = new ArrayList<>(); | |
408 expectedItems.add(R.id.contextmenu_save_video); | |
409 assertTrue(confirmMenuList(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. | |
416 * @return Returns true when all the items in the menu are equal to the expe ctedItems. | |
417 */ | |
418 private boolean confirmMenuList(ContextMenu menu, List<Integer> expectedItem s) { | |
JJ
2017/02/22 00:57:43
Preemptive comment! For a while I thought of putti
David Trainor- moved to gerrit
2017/02/22 05:36:33
I see your point. IMO the (debatable) useful piec
JJ
2017/02/22 19:09:39
Interesting! I didn't think of it with line number
| |
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 // Leave the O(n logn) sort for when they're the same size | |
426 if (actualItems.size() != expectedItems.size()) return false; | |
427 | |
428 Collections.sort(expectedItems); | |
429 Collections.sort(actualItems); | |
430 return actualItems.equals(expectedItems); | |
431 } | |
432 | |
351 private void saveMediaFromContextMenu(String mediaDOMElement, int saveMenuID , | 433 private void saveMediaFromContextMenu(String mediaDOMElement, int saveMenuID , |
352 String expectedFilename) throws InterruptedException, TimeoutExcepti on, | 434 String expectedFilename) throws InterruptedException, TimeoutExcepti on, |
353 SecurityException, IOException { | 435 SecurityException, IOException { |
354 // Select "save [image/video]" in that menu. | 436 // Select "save [image/video]" in that menu. |
355 Tab tab = getActivity().getActivityTab(); | 437 Tab tab = getActivity().getActivityTab(); |
356 int callCount = getChromeDownloadCallCount(); | 438 int callCount = getChromeDownloadCallCount(); |
357 ContextMenuUtils.selectContextMenuItem(this, tab, mediaDOMElement, saveM enuID); | 439 ContextMenuUtils.selectContextMenuItem(this, tab, mediaDOMElement, saveM enuID); |
358 | 440 |
359 // Wait for the download to complete and see if we got the right file | 441 // Wait for the download to complete and see if we got the right file |
360 assertTrue(waitForChromeDownloadToFinish(callCount)); | 442 assertTrue(waitForChromeDownloadToFinish(callCount)); |
(...skipping 15 matching lines...) Expand all Loading... | |
376 } | 458 } |
377 | 459 |
378 /** | 460 /** |
379 * Makes sure there are no files with names identical to the ones this test uses in the | 461 * Makes sure there are no files with names identical to the ones this test uses in the |
380 * downloads directory | 462 * downloads directory |
381 */ | 463 */ |
382 private void deleteTestFiles() { | 464 private void deleteTestFiles() { |
383 deleteFilesInDownloadDirectory(TEST_FILES); | 465 deleteFilesInDownloadDirectory(TEST_FILES); |
384 } | 466 } |
385 } | 467 } |
OLD | NEW |