| 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.os.Build; | 10 import android.os.Build; |
| 11 import android.test.FlakyTest; | |
| 12 import android.test.suitebuilder.annotation.LargeTest; | 11 import android.test.suitebuilder.annotation.LargeTest; |
| 13 import android.view.ContextMenu; | 12 import android.view.ContextMenu; |
| 14 | 13 |
| 15 import junit.framework.Assert; | 14 import junit.framework.Assert; |
| 16 | 15 |
| 17 import org.chromium.base.test.util.Feature; | 16 import org.chromium.base.test.util.Feature; |
| 18 import org.chromium.chrome.R; | 17 import org.chromium.chrome.R; |
| 19 import org.chromium.chrome.browser.TabBase; | 18 import org.chromium.chrome.browser.TabBase; |
| 20 import org.chromium.chrome.test.util.TabBaseTabUtils; | 19 import org.chromium.chrome.test.util.TabBaseTabUtils; |
| 21 import org.chromium.chrome.test.util.TabBaseTabUtils.TestCallbackHelperContainer
ForTab; | 20 import org.chromium.chrome.test.util.TabBaseTabUtils.TestCallbackHelperContainer
ForTab; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 34 public class ContextMenuTest extends ChromiumTestShellTestBase { | 33 public class ContextMenuTest extends ChromiumTestShellTestBase { |
| 35 @Override | 34 @Override |
| 36 public void setUp() throws Exception { | 35 public void setUp() throws Exception { |
| 37 super.setUp(); | 36 super.setUp(); |
| 38 launchChromiumTestShellWithUrl(TestHttpServerClient.getUrl( | 37 launchChromiumTestShellWithUrl(TestHttpServerClient.getUrl( |
| 39 "chrome/test/data/android/contextmenu/context_menu_test.html")); | 38 "chrome/test/data/android/contextmenu/context_menu_test.html")); |
| 40 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); | 39 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); |
| 41 assertWaitForPageScaleFactorMatch(0.5f); | 40 assertWaitForPageScaleFactorMatch(0.5f); |
| 42 } | 41 } |
| 43 | 42 |
| 44 // http://crbug.com/326769 | 43 @LargeTest |
| 45 @FlakyTest | |
| 46 // @LargeTest | |
| 47 @Feature({"Browser", "Main"}) | 44 @Feature({"Browser", "Main"}) |
| 48 public void testCopyLinkURL() throws InterruptedException, TimeoutException
{ | 45 public void testCopyLinkURL() throws InterruptedException, TimeoutException
{ |
| 49 TabBase tab = getActivity().getActiveTab(); | 46 TabBase tab = getActivity().getActiveTab(); |
| 50 ContextMenuUtils.selectContextMenuItem(this, tab, | 47 ContextMenuUtils.selectContextMenuItem(this, tab, |
| 51 TabBaseTabUtils.getTestCallbackHelperContainer(tab), "testLink", | 48 TabBaseTabUtils.getTestCallbackHelperContainer(tab), "testLink", |
| 52 R.id.contextmenu_copy_link_address_text); | 49 R.id.contextmenu_copy_link_address_text); |
| 53 | 50 |
| 54 assertStringContains("test_link.html", getClipboardText()); | 51 assertStringContains("test_link.html", getClipboardText()); |
| 55 } | 52 } |
| 56 | 53 |
| 57 // http://crbug.com/326769 | 54 @LargeTest |
| 58 @FlakyTest | |
| 59 // @LargeTest | |
| 60 @Feature({"Browser"}) | 55 @Feature({"Browser"}) |
| 61 public void testCopyImageLinkCopiesLinkURL() throws InterruptedException, Ti
meoutException { | 56 public void testCopyImageLinkCopiesLinkURL() throws InterruptedException, Ti
meoutException { |
| 62 TabBase tab = getActivity().getActiveTab(); | 57 TabBase tab = getActivity().getActiveTab(); |
| 63 ContextMenuUtils.selectContextMenuItem(this, tab, | 58 ContextMenuUtils.selectContextMenuItem(this, tab, |
| 64 TabBaseTabUtils.getTestCallbackHelperContainer(tab), "testImageL
ink", | 59 TabBaseTabUtils.getTestCallbackHelperContainer(tab), "testImageL
ink", |
| 65 R.id.contextmenu_copy_link_address_text); | 60 R.id.contextmenu_copy_link_address_text); |
| 66 | 61 |
| 67 assertStringContains("test_link.html", getClipboardText()); | 62 assertStringContains("test_link.html", getClipboardText()); |
| 68 } | 63 } |
| 69 | 64 |
| 70 // http://crbug.com/326769 | 65 @LargeTest |
| 71 @FlakyTest | |
| 72 // @LargeTest | |
| 73 @Feature({"Browser"}) | 66 @Feature({"Browser"}) |
| 74 public void testCopyLinkTextSimple() throws InterruptedException, TimeoutExc
eption { | 67 public void testCopyLinkTextSimple() throws InterruptedException, TimeoutExc
eption { |
| 75 TabBase tab = getActivity().getActiveTab(); | 68 TabBase tab = getActivity().getActiveTab(); |
| 76 ContextMenuUtils.selectContextMenuItem(this, tab, | 69 ContextMenuUtils.selectContextMenuItem(this, tab, |
| 77 TabBaseTabUtils.getTestCallbackHelperContainer(tab), "testLink", | 70 TabBaseTabUtils.getTestCallbackHelperContainer(tab), "testLink", |
| 78 R.id.contextmenu_copy_link_text); | 71 R.id.contextmenu_copy_link_text); |
| 79 | 72 |
| 80 assertEquals("Clipboard text was not what was expected", "Test Link", | 73 assertEquals("Clipboard text was not what was expected", "Test Link", |
| 81 getClipboardText()); | 74 getClipboardText()); |
| 82 } | 75 } |
| 83 | 76 |
| 84 // http://crbug.com/326769 | 77 @LargeTest |
| 85 @FlakyTest | |
| 86 // @LargeTest | |
| 87 @Feature({"Browser"}) | 78 @Feature({"Browser"}) |
| 88 public void testCopyLinkTextComplex() throws InterruptedException, TimeoutEx
ception { | 79 public void testCopyLinkTextComplex() throws InterruptedException, TimeoutEx
ception { |
| 89 TabBase tab = getActivity().getActiveTab(); | 80 TabBase tab = getActivity().getActiveTab(); |
| 90 ContextMenuUtils.selectContextMenuItem(this, tab, | 81 ContextMenuUtils.selectContextMenuItem(this, tab, |
| 91 TabBaseTabUtils.getTestCallbackHelperContainer(tab), "copyLinkTe
xtComplex", | 82 TabBaseTabUtils.getTestCallbackHelperContainer(tab), "copyLinkTe
xtComplex", |
| 92 R.id.contextmenu_copy_link_text); | 83 R.id.contextmenu_copy_link_text); |
| 93 | 84 |
| 94 assertEquals("Clipboard text was not what was expected", | 85 assertEquals("Clipboard text was not what was expected", |
| 95 "This is pretty extreme \n(newline). ", getClipboardText()); | 86 "This is pretty extreme \n(newline). ", getClipboardText()); |
| 96 } | 87 } |
| 97 | 88 |
| 98 // http://crbug.com/326769 | 89 @LargeTest |
| 99 @FlakyTest | |
| 100 // @LargeTest | |
| 101 @Feature({"Browser"}) | 90 @Feature({"Browser"}) |
| 102 public void testCopyImageToClipboard() throws InterruptedException, TimeoutE
xception { | 91 public void testCopyImageToClipboard() throws InterruptedException, TimeoutE
xception { |
| 103 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return; | 92 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return; |
| 104 | 93 |
| 105 TabBase tab = getActivity().getActiveTab(); | 94 TabBase tab = getActivity().getActiveTab(); |
| 106 ContextMenuUtils.selectContextMenuItem(this, tab, | 95 ContextMenuUtils.selectContextMenuItem(this, tab, |
| 107 TabBaseTabUtils.getTestCallbackHelperContainer(tab), "testImage"
, | 96 TabBaseTabUtils.getTestCallbackHelperContainer(tab), "testImage"
, |
| 108 R.id.contextmenu_copy_image); | 97 R.id.contextmenu_copy_image); |
| 109 | 98 |
| 110 String expectedUrl = TestHttpServerClient.getUrl( | 99 String expectedUrl = TestHttpServerClient.getUrl( |
| 111 "chrome/test/data/android/contextmenu/test_image.png"); | 100 "chrome/test/data/android/contextmenu/test_image.png"); |
| 112 | 101 |
| 113 assertEquals("Clipboard text is not correct", expectedUrl, getClipboardT
ext()); | 102 assertEquals("Clipboard text is not correct", expectedUrl, getClipboardT
ext()); |
| 114 } | 103 } |
| 115 | 104 |
| 116 // http://crbug.com/326769 | 105 @LargeTest |
| 117 @FlakyTest | |
| 118 // @LargeTest | |
| 119 @Feature({"Browser"}) | 106 @Feature({"Browser"}) |
| 120 public void testLongPressOnImage() throws InterruptedException, TimeoutExcep
tion { | 107 public void testLongPressOnImage() throws InterruptedException, TimeoutExcep
tion { |
| 121 final TabBase tab = getActivity().getActiveTab(); | 108 final TabBase tab = getActivity().getActiveTab(); |
| 122 | 109 |
| 123 TestCallbackHelperContainerForTab helper = | 110 TestCallbackHelperContainerForTab helper = |
| 124 TabBaseTabUtils.getTestCallbackHelperContainer(tab); | 111 TabBaseTabUtils.getTestCallbackHelperContainer(tab); |
| 125 | 112 |
| 126 OnPageFinishedHelper callback = helper.getOnPageFinishedHelper(); | 113 OnPageFinishedHelper callback = helper.getOnPageFinishedHelper(); |
| 127 int callbackCount = callback.getCallCount(); | 114 int callbackCount = callback.getCallCount(); |
| 128 | 115 |
| 129 ContextMenuUtils.selectContextMenuItem(this, tab, helper, "testImage", | 116 ContextMenuUtils.selectContextMenuItem(this, tab, helper, "testImage", |
| 130 R.id.contextmenu_open_image); | 117 R.id.contextmenu_open_image); |
| 131 | 118 |
| 132 callback.waitForCallback(callbackCount); | 119 callback.waitForCallback(callbackCount); |
| 133 | 120 |
| 134 String expectedUrl = TestHttpServerClient.getUrl( | 121 String expectedUrl = TestHttpServerClient.getUrl( |
| 135 "chrome/test/data/android/contextmenu/test_image.png"); | 122 "chrome/test/data/android/contextmenu/test_image.png"); |
| 136 | 123 |
| 137 final AtomicReference<String> actualUrl = new AtomicReference<String>(); | 124 final AtomicReference<String> actualUrl = new AtomicReference<String>(); |
| 138 getInstrumentation().runOnMainSync(new Runnable() { | 125 getInstrumentation().runOnMainSync(new Runnable() { |
| 139 @Override | 126 @Override |
| 140 public void run() { | 127 public void run() { |
| 141 actualUrl.set(tab.getUrl()); | 128 actualUrl.set(tab.getUrl()); |
| 142 } | 129 } |
| 143 }); | 130 }); |
| 144 | 131 |
| 145 assertEquals("Failed to navigate to the image", expectedUrl, actualUrl.g
et()); | 132 assertEquals("Failed to navigate to the image", expectedUrl, actualUrl.g
et()); |
| 146 } | 133 } |
| 147 | 134 |
| 148 // http://crbug.com/326769 | 135 @LargeTest |
| 149 @FlakyTest | |
| 150 // @LargeTest | |
| 151 @Feature({"Browser"}) | 136 @Feature({"Browser"}) |
| 152 public void testLongPressOnImageLink() throws InterruptedException, TimeoutE
xception { | 137 public void testLongPressOnImageLink() throws InterruptedException, TimeoutE
xception { |
| 153 final TabBase tab = getActivity().getActiveTab(); | 138 final TabBase tab = getActivity().getActiveTab(); |
| 154 | 139 |
| 155 TestCallbackHelperContainerForTab helper = | 140 TestCallbackHelperContainerForTab helper = |
| 156 TabBaseTabUtils.getTestCallbackHelperContainer(tab); | 141 TabBaseTabUtils.getTestCallbackHelperContainer(tab); |
| 157 | 142 |
| 158 OnPageFinishedHelper callback = helper.getOnPageFinishedHelper(); | 143 OnPageFinishedHelper callback = helper.getOnPageFinishedHelper(); |
| 159 int callbackCount = callback.getCallCount(); | 144 int callbackCount = callback.getCallCount(); |
| 160 | 145 |
| 161 ContextMenuUtils.selectContextMenuItem(this, tab, helper, "testImage", | 146 ContextMenuUtils.selectContextMenuItem(this, tab, helper, "testImage", |
| 162 R.id.contextmenu_open_image); | 147 R.id.contextmenu_open_image); |
| 163 | 148 |
| 164 callback.waitForCallback(callbackCount); | 149 callback.waitForCallback(callbackCount); |
| 165 | 150 |
| 166 final AtomicReference<String> actualTitle = new AtomicReference<String>(
); | 151 final AtomicReference<String> actualTitle = new AtomicReference<String>(
); |
| 167 getInstrumentation().runOnMainSync(new Runnable() { | 152 getInstrumentation().runOnMainSync(new Runnable() { |
| 168 @Override | 153 @Override |
| 169 public void run() { | 154 public void run() { |
| 170 actualTitle.set(tab.getTitle()); | 155 actualTitle.set(tab.getTitle()); |
| 171 } | 156 } |
| 172 }); | 157 }); |
| 173 | 158 |
| 174 assertTrue("Navigated to the wrong page.", actualTitle.get().startsWith(
"test_image.png")); | 159 assertTrue("Navigated to the wrong page.", actualTitle.get().startsWith(
"test_image.png")); |
| 175 } | 160 } |
| 176 | 161 |
| 177 // http://crbug.com/326769 | 162 @LargeTest |
| 178 @FlakyTest | |
| 179 // @LargeTest | |
| 180 @Feature({"Browser"}) | 163 @Feature({"Browser"}) |
| 181 public void testDismissContextMenuOnBack() throws InterruptedException, Time
outException { | 164 public void testDismissContextMenuOnBack() throws InterruptedException, Time
outException { |
| 182 TabBase tab = getActivity().getActiveTab(); | 165 TabBase tab = getActivity().getActiveTab(); |
| 183 ContextMenu menu = ContextMenuUtils.openContextMenu(this, tab, | 166 ContextMenu menu = ContextMenuUtils.openContextMenu(this, tab, |
| 184 TabBaseTabUtils.getTestCallbackHelperContainer(tab), "testImage"
); | 167 TabBaseTabUtils.getTestCallbackHelperContainer(tab), "testImage"
); |
| 185 assertNotNull("Context menu was not properly created", menu); | 168 assertNotNull("Context menu was not properly created", menu); |
| 186 assertFalse("Context menu did not have window focus", getActivity().hasW
indowFocus()); | 169 assertFalse("Context menu did not have window focus", getActivity().hasW
indowFocus()); |
| 187 | 170 |
| 188 KeyUtils.pressBack(getInstrumentation()); | 171 KeyUtils.pressBack(getInstrumentation()); |
| 189 | 172 |
| 190 Assert.assertTrue("Activity did not regain focus.", | 173 Assert.assertTrue("Activity did not regain focus.", |
| 191 CriteriaHelper.pollForCriteria(new Criteria() { | 174 CriteriaHelper.pollForCriteria(new Criteria() { |
| 192 @Override | 175 @Override |
| 193 public boolean isSatisfied() { | 176 public boolean isSatisfied() { |
| 194 return getActivity().hasWindowFocus(); | 177 return getActivity().hasWindowFocus(); |
| 195 } | 178 } |
| 196 })); | 179 })); |
| 197 } | 180 } |
| 198 | 181 |
| 199 // http://crbug.com/326769 | 182 @LargeTest |
| 200 @FlakyTest | |
| 201 // @LargeTest | |
| 202 @Feature({"Browser"}) | 183 @Feature({"Browser"}) |
| 203 public void testDismissContextMenuOnClick() throws InterruptedException, Tim
eoutException { | 184 public void testDismissContextMenuOnClick() throws InterruptedException, Tim
eoutException { |
| 204 TabBase tab = getActivity().getActiveTab(); | 185 TabBase tab = getActivity().getActiveTab(); |
| 205 ContextMenu menu = ContextMenuUtils.openContextMenu(this, tab, | 186 ContextMenu menu = ContextMenuUtils.openContextMenu(this, tab, |
| 206 TabBaseTabUtils.getTestCallbackHelperContainer(tab), "testImage"
); | 187 TabBaseTabUtils.getTestCallbackHelperContainer(tab), "testImage"
); |
| 207 assertNotNull("Context menu was not properly created", menu); | 188 assertNotNull("Context menu was not properly created", menu); |
| 208 assertFalse("Context menu did not have window focus", getActivity().hasW
indowFocus()); | 189 assertFalse("Context menu did not have window focus", getActivity().hasW
indowFocus()); |
| 209 | 190 |
| 210 TestTouchUtils.singleClickView(getInstrumentation(), tab.getPageInfo().g
etView(), 0, 0); | 191 TestTouchUtils.singleClickView(getInstrumentation(), tab.getPageInfo().g
etView(), 0, 0); |
| 211 | 192 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 225 assertNotNull("Primary clip is null", clipData); | 206 assertNotNull("Primary clip is null", clipData); |
| 226 assertTrue("Primary clip contains no items.", clipData.getItemCount() >
0); | 207 assertTrue("Primary clip contains no items.", clipData.getItemCount() >
0); |
| 227 return clipData.getItemAt(0).getText().toString(); | 208 return clipData.getItemAt(0).getText().toString(); |
| 228 } | 209 } |
| 229 | 210 |
| 230 private void assertStringContains(String subString, String superString) { | 211 private void assertStringContains(String subString, String superString) { |
| 231 assertTrue("String '" + superString + "' does not contain '" + subString
+ "'", | 212 assertTrue("String '" + superString + "' does not contain '" + subString
+ "'", |
| 232 superString.contains(subString)); | 213 superString.contains(subString)); |
| 233 } | 214 } |
| 234 } | 215 } |
| OLD | NEW |