Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1277)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java

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

Powered by Google App Engine
This is Rietveld 408576698