OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.download; |
| 6 |
| 7 import android.test.FlakyTest; |
| 8 |
| 9 import com.google.android.apps.chrome.R; |
| 10 |
| 11 import org.chromium.base.test.util.CommandLineFlags; |
| 12 import org.chromium.chrome.browser.ChromeSwitches; |
| 13 import org.chromium.chrome.browser.CompositorChromeActivity; |
| 14 import org.chromium.chrome.browser.Tab; |
| 15 import org.chromium.chrome.browser.compositor.layouts.LayoutManager; |
| 16 import org.chromium.chrome.test.util.ChromeTabUtils; |
| 17 import org.chromium.chrome.test.util.TestHttpServerClient; |
| 18 import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils; |
| 19 import org.chromium.content.browser.test.util.Criteria; |
| 20 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 21 |
| 22 import java.io.IOException; |
| 23 import java.util.concurrent.TimeoutException; |
| 24 |
| 25 /** |
| 26 * Context menu related tests |
| 27 */ |
| 28 @CommandLineFlags.Add(ChromeSwitches.GOOGLE_BASE_URL + "=http://example.com/") |
| 29 public class ContextMenuTest extends DownloadTestBase { |
| 30 private static final String TEST_URL = |
| 31 TestHttpServerClient.getUrl("chrome/test/data/android/context_menu_t
est.html"); |
| 32 |
| 33 @Override |
| 34 public void setUp() throws Exception { |
| 35 super.setUp(); |
| 36 loadUrl(TEST_URL); |
| 37 assertWaitForPageScaleFactorMatch(0.5f); |
| 38 } |
| 39 |
| 40 @Override |
| 41 public void startMainActivity() throws InterruptedException { |
| 42 startMainActivityFromLauncher(); |
| 43 } |
| 44 |
| 45 /* |
| 46 * Bug: http://crbug.com/332154 |
| 47 * @LargeTest |
| 48 * @Feature({"Browser"}) |
| 49 */ |
| 50 @FlakyTest |
| 51 public void testSaveDataUrl() |
| 52 throws InterruptedException, TimeoutException, SecurityException, IO
Exception { |
| 53 saveMediaFromContextMenu("dataUrlIcon", R.id.contextmenu_save_image, "do
wnload.gif"); |
| 54 } |
| 55 |
| 56 /* |
| 57 * Bug: http://crbug.com/332154 |
| 58 * @LargeTest |
| 59 * @Feature({"Browser"}) |
| 60 */ |
| 61 @FlakyTest |
| 62 public void testSaveImage() |
| 63 throws InterruptedException, TimeoutException, SecurityException, IO
Exception { |
| 64 saveMediaFromContextMenu("testImage", R.id.contextmenu_save_image, "goog
le.png"); |
| 65 } |
| 66 |
| 67 /* |
| 68 * Bug: http://crbug.com/332154 |
| 69 * @LargeTest |
| 70 * @Feature({"Browser"}) |
| 71 */ |
| 72 @FlakyTest |
| 73 public void testSaveVideo() |
| 74 throws InterruptedException, TimeoutException, SecurityException, IO
Exception { |
| 75 saveMediaFromContextMenu("videoDOMElement", R.id.contextmenu_save_video,
"test.mp4"); |
| 76 } |
| 77 |
| 78 // Open link and image in new tabs and Verify the order of indices of the ta
bs in the TabModel. |
| 79 // Also verify, that the parent page remains in front after opening links in
new tabs. |
| 80 /* |
| 81 * Bug: http://crbug.com/412816 |
| 82 * @LargeTest |
| 83 * @Feature({"Browser"}) |
| 84 */ |
| 85 @FlakyTest |
| 86 public void testOpenLinksInNewTabsAndVerifyTabIndexOrdering() |
| 87 throws InterruptedException, TimeoutException { |
| 88 int nOpenedTabs = getActivity().getCurrentTabModel().getCount(); |
| 89 Tab tab = getActivity().getActivityTab(); |
| 90 ContextMenuUtils.selectContextMenuItem(this, tab, "testLink", |
| 91 R.id.contextmenu_open_in_new_tab); |
| 92 getInstrumentation().waitForIdleSync(); |
| 93 int indexOfLinkPage = nOpenedTabs; |
| 94 nOpenedTabs += 1; |
| 95 assertEquals("Number of open tabs does not match", |
| 96 nOpenedTabs , getActivity().getCurrentTabModel().getCount()); |
| 97 |
| 98 // Wait for any new tab animation to finish if we're being driven by the
compositor. |
| 99 if (getActivity() instanceof CompositorChromeActivity) { |
| 100 final LayoutManager layoutDriver = ((CompositorChromeActivity) getAc
tivity()) |
| 101 .getCompositorViewHolder().getLayoutManager(); |
| 102 assertTrue("Background tab animation not finished.", |
| 103 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
| 104 @Override |
| 105 public boolean isSatisfied() { |
| 106 return layoutDriver.getActiveLayout().shouldDisplayC
ontentOverlay(); |
| 107 } |
| 108 })); |
| 109 } |
| 110 |
| 111 ContextMenuUtils.selectContextMenuItem(this, tab, "testImage", |
| 112 R.id.contextmenu_open_image_in_new_tab); |
| 113 getInstrumentation().waitForIdleSync(); |
| 114 int indexOfLogoPage = nOpenedTabs; |
| 115 nOpenedTabs += 1; |
| 116 assertEquals("Number of open tabs does not match", |
| 117 nOpenedTabs, getActivity().getCurrentTabModel().getCount()); |
| 118 |
| 119 // Verify the Url is still the same of Parent page. |
| 120 assertEquals(TEST_URL, getActivity().getActivityTab().getUrl()); |
| 121 |
| 122 // Switch to child tab page and verify Url. |
| 123 ChromeTabUtils.switchTabInCurrentTabModel(getActivity(), indexOfLinkPage
); |
| 124 String newTabUrl = TestHttpServerClient.getUrl("chrome/test/data/android
/about.html"); |
| 125 assertEquals(newTabUrl, getActivity().getActivityTab().getUrl()); |
| 126 |
| 127 // Switch to another child tab page and verify Url. |
| 128 ChromeTabUtils.switchTabInCurrentTabModel(getActivity(), indexOfLogoPage
); |
| 129 String logoTabUrl = TestHttpServerClient.getUrl("chrome/test/data/androi
d/google.png"); |
| 130 assertEquals(logoTabUrl, getActivity().getActivityTab().getUrl()); |
| 131 } |
| 132 |
| 133 private void saveMediaFromContextMenu(String mediaDOMElement, int saveMenuID
, |
| 134 String expectedFilename) throws InterruptedException, TimeoutExcepti
on, |
| 135 SecurityException, IOException { |
| 136 // Select "save [image/video]" in that menu. |
| 137 Tab tab = getActivity().getActivityTab(); |
| 138 ContextMenuUtils.selectContextMenuItem(this, tab, mediaDOMElement, saveM
enuID); |
| 139 |
| 140 // Wait for the download to complete and see if we got the right file |
| 141 assertTrue(waitForChromeDownloadToFinish()); |
| 142 checkLastDownload(expectedFilename); |
| 143 } |
| 144 } |
OLD | NEW |