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