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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/autofill/AutofillPopupTest.java

Issue 2858933002: Reland: Convert ChromeActivityTestCaseBase direct children to JUnit4 (Closed)
Patch Set: Patch takes out flaky tests Created 3 years, 7 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.autofill; 5 package org.chromium.chrome.browser.autofill;
6 6
7 import android.support.test.filters.MediumTest; 7 import android.support.test.filters.MediumTest;
8 import android.text.TextUtils; 8 import android.text.TextUtils;
9 import android.view.View; 9 import android.view.View;
10 import android.view.ViewGroup; 10 import android.view.ViewGroup;
11 11
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Rule;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17
18 import org.chromium.base.test.util.CommandLineFlags;
12 import org.chromium.base.test.util.Feature; 19 import org.chromium.base.test.util.Feature;
13 import org.chromium.base.test.util.RetryOnFailure; 20 import org.chromium.base.test.util.RetryOnFailure;
14 import org.chromium.base.test.util.UrlUtils; 21 import org.chromium.base.test.util.UrlUtils;
15 import org.chromium.chrome.browser.ChromeActivity; 22 import org.chromium.chrome.browser.ChromeActivity;
23 import org.chromium.chrome.browser.ChromeSwitches;
16 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; 24 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
17 import org.chromium.chrome.test.ChromeActivityTestCaseBase; 25 import org.chromium.chrome.test.ChromeActivityTestRule;
26 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
18 import org.chromium.components.autofill.AutofillPopup; 27 import org.chromium.components.autofill.AutofillPopup;
19 import org.chromium.content.browser.ContentViewCore; 28 import org.chromium.content.browser.ContentViewCore;
20 import org.chromium.content.browser.input.ChromiumBaseInputConnection; 29 import org.chromium.content.browser.input.ChromiumBaseInputConnection;
21 import org.chromium.content.browser.test.util.Criteria; 30 import org.chromium.content.browser.test.util.Criteria;
22 import org.chromium.content.browser.test.util.CriteriaHelper; 31 import org.chromium.content.browser.test.util.CriteriaHelper;
23 import org.chromium.content.browser.test.util.DOMUtils; 32 import org.chromium.content.browser.test.util.DOMUtils;
24 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper; 33 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper;
25 import org.chromium.content.browser.test.util.TouchCommon; 34 import org.chromium.content.browser.test.util.TouchCommon;
26 import org.chromium.content_public.browser.WebContents; 35 import org.chromium.content_public.browser.WebContents;
27 import org.chromium.ui.R; 36 import org.chromium.ui.R;
28 37
29 import java.util.ArrayList; 38 import java.util.ArrayList;
30 import java.util.List; 39 import java.util.List;
31 import java.util.concurrent.Callable; 40 import java.util.concurrent.Callable;
32 import java.util.concurrent.ExecutionException; 41 import java.util.concurrent.ExecutionException;
33 import java.util.concurrent.TimeoutException; 42 import java.util.concurrent.TimeoutException;
34 43
35 /** 44 /**
36 * Integration tests for the AutofillPopup. 45 * Integration tests for the AutofillPopup.
37 */ 46 */
47 @RunWith(ChromeJUnit4ClassRunner.class)
38 @RetryOnFailure 48 @RetryOnFailure
39 public class AutofillPopupTest extends ChromeActivityTestCaseBase<ChromeActivity > { 49 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
50 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
51 public class AutofillPopupTest {
52 @Rule
53 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
54 new ChromeActivityTestRule<>(ChromeActivity.class);
40 55
41 private static final String FIRST_NAME = "John"; 56 private static final String FIRST_NAME = "John";
42 private static final String LAST_NAME = "Smith"; 57 private static final String LAST_NAME = "Smith";
43 private static final String COMPANY_NAME = "Acme Inc."; 58 private static final String COMPANY_NAME = "Acme Inc.";
44 private static final String ADDRESS_LINE1 = "1 Main"; 59 private static final String ADDRESS_LINE1 = "1 Main";
45 private static final String ADDRESS_LINE2 = "Apt A"; 60 private static final String ADDRESS_LINE2 = "Apt A";
46 private static final String STREET_ADDRESS_TEXTAREA = ADDRESS_LINE1 + "\n" + ADDRESS_LINE2; 61 private static final String STREET_ADDRESS_TEXTAREA = ADDRESS_LINE1 + "\n" + ADDRESS_LINE2;
47 private static final String CITY = "San Francisco"; 62 private static final String CITY = "San Francisco";
48 private static final String DEPENDENT_LOCALITY = ""; 63 private static final String DEPENDENT_LOCALITY = "";
49 private static final String STATE = "CA"; 64 private static final String STATE = "CA";
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 + "<select id=\"co\" autocomplete=\"country\"><br>" 130 + "<select id=\"co\" autocomplete=\"country\"><br>"
116 + "<option value=\"GB\">Great Britain</option>" 131 + "<option value=\"GB\">Great Britain</option>"
117 + "<option value=\"BR\">Brazil</option>" 132 + "<option value=\"BR\">Brazil</option>"
118 + "</select>" 133 + "</select>"
119 + "<input type=\"submit\" />" 134 + "<input type=\"submit\" />"
120 + "</form></body></html>"); 135 + "</form></body></html>");
121 136
122 private AutofillTestHelper mHelper; 137 private AutofillTestHelper mHelper;
123 private List<AutofillLogger.LogEntry> mAutofillLoggedEntries; 138 private List<AutofillLogger.LogEntry> mAutofillLoggedEntries;
124 139
125 public AutofillPopupTest() { 140 @Before
126 super(ChromeActivity.class);
127 }
128
129 @Override
130 public void startMainActivity() throws InterruptedException {
131 // Don't launch activity automatically.
132 }
133
134 @Override
135 public void setUp() throws Exception { 141 public void setUp() throws Exception {
136 super.setUp();
137 mAutofillLoggedEntries = new ArrayList<AutofillLogger.LogEntry>(); 142 mAutofillLoggedEntries = new ArrayList<AutofillLogger.LogEntry>();
138 AutofillLogger.setLoggerForTesting( 143 AutofillLogger.setLoggerForTesting(
139 new AutofillLogger.Logger() { 144 new AutofillLogger.Logger() {
140 @Override 145 @Override
141 public void didFillField(AutofillLogger.LogEntry logEntry) { 146 public void didFillField(AutofillLogger.LogEntry logEntry) {
142 mAutofillLoggedEntries.add(logEntry); 147 mAutofillLoggedEntries.add(logEntry);
143 } 148 }
144 } 149 }
145 ); 150 );
146 } 151 }
147 152
148 private void loadAndFillForm( 153 private void loadAndFillForm(
149 final String formDataUrl, final String inputText) 154 final String formDataUrl, final String inputText)
150 throws InterruptedException, ExecutionException, TimeoutException { 155 throws InterruptedException, ExecutionException, TimeoutException {
151 startMainActivityWithURL(formDataUrl); 156 mActivityTestRule.startMainActivityWithURL(formDataUrl);
152 mHelper = new AutofillTestHelper(); 157 mHelper = new AutofillTestHelper();
153 158
154 // The TestInputMethodManagerWrapper intercepts showSoftInput so that a keyboard is never 159 // The TestInputMethodManagerWrapper intercepts showSoftInput so that a keyboard is never
155 // brought up. 160 // brought up.
156 final ContentViewCore viewCore = getActivity().getCurrentContentViewCore (); 161 final ContentViewCore viewCore =
162 mActivityTestRule.getActivity().getCurrentContentViewCore();
157 final WebContents webContents = viewCore.getWebContents(); 163 final WebContents webContents = viewCore.getWebContents();
158 final ViewGroup view = viewCore.getContainerView(); 164 final ViewGroup view = viewCore.getContainerView();
159 final TestInputMethodManagerWrapper immw = 165 final TestInputMethodManagerWrapper immw =
160 new TestInputMethodManagerWrapper(viewCore); 166 new TestInputMethodManagerWrapper(viewCore);
161 viewCore.getImeAdapterForTest().setInputMethodManagerWrapperForTest(immw ); 167 viewCore.getImeAdapterForTest().setInputMethodManagerWrapperForTest(immw );
162 168
163 // Add an Autofill profile. 169 // Add an Autofill profile.
164 AutofillProfile profile = new AutofillProfile( 170 AutofillProfile profile = new AutofillProfile(
165 "" /* guid */, ORIGIN, FIRST_NAME + " " + LAST_NAME, COMPANY_NAM E, 171 "" /* guid */, ORIGIN, FIRST_NAME + " " + LAST_NAME, COMPANY_NAM E,
166 STREET_ADDRESS_TEXTAREA, 172 STREET_ADDRESS_TEXTAREA,
167 STATE, CITY, DEPENDENT_LOCALITY, 173 STATE, CITY, DEPENDENT_LOCALITY,
168 ZIP_CODE, SORTING_CODE, COUNTRY, PHONE_NUMBER, EMAIL, 174 ZIP_CODE, SORTING_CODE, COUNTRY, PHONE_NUMBER, EMAIL,
169 LANGUAGE_CODE); 175 LANGUAGE_CODE);
170 mHelper.setProfile(profile); 176 mHelper.setProfile(profile);
171 assertEquals(1, mHelper.getNumberOfProfilesToSuggest()); 177 Assert.assertEquals(1, mHelper.getNumberOfProfilesToSuggest());
172 178
173 // Click the input field for the first name. 179 // Click the input field for the first name.
174 DOMUtils.waitForNonZeroNodeBounds(webContents, "fn"); 180 DOMUtils.waitForNonZeroNodeBounds(webContents, "fn");
175 DOMUtils.clickNode(viewCore, "fn"); 181 DOMUtils.clickNode(viewCore, "fn");
176 182
177 waitForKeyboardShowRequest(immw, 1); 183 waitForKeyboardShowRequest(immw, 1);
178 184
179 final ChromiumBaseInputConnection inputConnection = 185 final ChromiumBaseInputConnection inputConnection =
180 viewCore.getImeAdapterForTest().getInputConnectionForTest(); 186 viewCore.getImeAdapterForTest().getInputConnectionForTest();
181 inputConnection.getHandler().post(new Runnable() { 187 inputConnection.getHandler().post(new Runnable() {
182 @Override 188 @Override
183 public void run() { 189 public void run() {
184 inputConnection.setComposingText(inputText, 1); 190 inputConnection.setComposingText(inputText, 1);
185 } 191 }
186 }); 192 });
187 193
188 waitForAnchorViewAdd(view); 194 waitForAnchorViewAdd(view);
189 View anchorView = view.findViewById(R.id.dropdown_popup_window); 195 View anchorView = view.findViewById(R.id.dropdown_popup_window);
190 196
191 assertTrue(anchorView.getTag() instanceof AutofillPopup); 197 Assert.assertTrue(anchorView.getTag() instanceof AutofillPopup);
192 final AutofillPopup popup = (AutofillPopup) anchorView.getTag(); 198 final AutofillPopup popup = (AutofillPopup) anchorView.getTag();
193 199
194 waitForAutofillPopopShow(popup); 200 waitForAutofillPopopShow(popup);
195 201
196 TouchCommon.singleClickView(popup.getListView(), 10, 10); 202 TouchCommon.singleClickView(popup.getListView(), 10, 10);
197 203
198 waitForInputFieldFill(webContents); 204 waitForInputFieldFill(webContents);
199 } 205 }
200 206
201 /** 207 /**
202 * Tests that bringing up an Autofill and clicking on the first entry fills out the expected 208 * Tests that bringing up an Autofill and clicking on the first entry fills out the expected
203 * Autofill information. 209 * Autofill information.
204 */ 210 */
211 @Test
205 @MediumTest 212 @MediumTest
206 @Feature({"autofill"}) 213 @Feature({"autofill"})
207 public void testClickAutofillPopupSuggestion() 214 public void testClickAutofillPopupSuggestion()
208 throws InterruptedException, ExecutionException, TimeoutException { 215 throws InterruptedException, ExecutionException, TimeoutException {
209 loadAndFillForm(BASIC_PAGE_DATA, "J"); 216 loadAndFillForm(BASIC_PAGE_DATA, "J");
210 final ContentViewCore viewCore = getActivity().getCurrentContentViewCore (); 217 final ContentViewCore viewCore =
218 mActivityTestRule.getActivity().getCurrentContentViewCore();
211 final WebContents webContents = viewCore.getWebContents(); 219 final WebContents webContents = viewCore.getWebContents();
212 220
213 assertEquals("First name did not match", 221 Assert.assertEquals(
214 FIRST_NAME, DOMUtils.getNodeValue(webContents, "fn")); 222 "First name did not match", FIRST_NAME, DOMUtils.getNodeValue(we bContents, "fn"));
215 assertEquals("Last name did not match", 223 Assert.assertEquals(
216 LAST_NAME, DOMUtils.getNodeValue(webContents, "ln")); 224 "Last name did not match", LAST_NAME, DOMUtils.getNodeValue(webC ontents, "ln"));
217 assertEquals("Street address (textarea) did not match", 225 Assert.assertEquals("Street address (textarea) did not match", STREET_AD DRESS_TEXTAREA,
218 STREET_ADDRESS_TEXTAREA, DOMUtils.getNodeValue(webContents, "sa" )); 226 DOMUtils.getNodeValue(webContents, "sa"));
219 assertEquals("Address line 1 did not match", 227 Assert.assertEquals("Address line 1 did not match", ADDRESS_LINE1,
220 ADDRESS_LINE1, DOMUtils.getNodeValue(webContents, "a1")); 228 DOMUtils.getNodeValue(webContents, "a1"));
221 assertEquals("Address line 2 did not match", 229 Assert.assertEquals("Address line 2 did not match", ADDRESS_LINE2,
222 ADDRESS_LINE2, DOMUtils.getNodeValue(webContents, "a2")); 230 DOMUtils.getNodeValue(webContents, "a2"));
223 assertEquals("City did not match", 231 Assert.assertEquals("City did not match", CITY, DOMUtils.getNodeValue(we bContents, "ct"));
224 CITY, DOMUtils.getNodeValue(webContents, "ct")); 232 Assert.assertEquals(
225 assertEquals("Zip code did not match", 233 "Zip code did not match", ZIP_CODE, DOMUtils.getNodeValue(webCon tents, "zc"));
226 ZIP_CODE, DOMUtils.getNodeValue(webContents, "zc")); 234 Assert.assertEquals(
227 assertEquals("Country did not match", 235 "Country did not match", COUNTRY, DOMUtils.getNodeValue(webConte nts, "co"));
228 COUNTRY, DOMUtils.getNodeValue(webContents, "co")); 236 Assert.assertEquals("Email did not match", EMAIL, DOMUtils.getNodeValue( webContents, "em"));
229 assertEquals("Email did not match", 237 Assert.assertEquals("Phone number did not match", PHONE_NUMBER,
230 EMAIL, DOMUtils.getNodeValue(webContents, "em")); 238 DOMUtils.getNodeValue(webContents, "ph"));
231 assertEquals("Phone number did not match",
232 PHONE_NUMBER, DOMUtils.getNodeValue(webContents, "ph"));
233 239
234 final String profileFullName = FIRST_NAME + " " + LAST_NAME; 240 final String profileFullName = FIRST_NAME + " " + LAST_NAME;
235 final int loggedEntries = 10; 241 final int loggedEntries = 10;
236 assertEquals("Mismatched number of logged entries", 242 Assert.assertEquals("Mismatched number of logged entries", loggedEntries ,
237 loggedEntries, mAutofillLoggedEntries.size()); 243 mAutofillLoggedEntries.size());
238 assertLogged(FIRST_NAME, profileFullName); 244 assertLogged(FIRST_NAME, profileFullName);
239 assertLogged(LAST_NAME, profileFullName); 245 assertLogged(LAST_NAME, profileFullName);
240 assertLogged(STREET_ADDRESS_TEXTAREA, profileFullName); 246 assertLogged(STREET_ADDRESS_TEXTAREA, profileFullName);
241 assertLogged(ADDRESS_LINE1, profileFullName); 247 assertLogged(ADDRESS_LINE1, profileFullName);
242 assertLogged(ADDRESS_LINE2, profileFullName); 248 assertLogged(ADDRESS_LINE2, profileFullName);
243 assertLogged(CITY, profileFullName); 249 assertLogged(CITY, profileFullName);
244 assertLogged(ZIP_CODE, profileFullName); 250 assertLogged(ZIP_CODE, profileFullName);
245 assertLogged(COUNTRY, profileFullName); 251 assertLogged(COUNTRY, profileFullName);
246 assertLogged(EMAIL, profileFullName); 252 assertLogged(EMAIL, profileFullName);
247 assertLogged(PHONE_NUMBER, profileFullName); 253 assertLogged(PHONE_NUMBER, profileFullName);
248 } 254 }
249 255
250 /** 256 /**
251 * Tests that bringing up an Autofill and clicking on the partially filled f irst 257 * Tests that bringing up an Autofill and clicking on the partially filled f irst
252 * element will still fill the entire form (including the initiating element itself). 258 * element will still fill the entire form (including the initiating element itself).
253 */ 259 */
260 @Test
254 @MediumTest 261 @MediumTest
255 @Feature({"autofill"}) 262 @Feature({"autofill"})
256 public void testLoggingInitiatedElementFilled() 263 public void testLoggingInitiatedElementFilled()
257 throws InterruptedException, ExecutionException, TimeoutException { 264 throws InterruptedException, ExecutionException, TimeoutException {
258 loadAndFillForm(INITIATING_ELEMENT_FILLED, "o"); 265 loadAndFillForm(INITIATING_ELEMENT_FILLED, "o");
259 final String profileFullName = FIRST_NAME + " " + LAST_NAME; 266 final String profileFullName = FIRST_NAME + " " + LAST_NAME;
260 final int loggedEntries = 4; 267 final int loggedEntries = 4;
261 assertEquals("Mismatched number of logged entries", 268 Assert.assertEquals("Mismatched number of logged entries", loggedEntries ,
262 loggedEntries, mAutofillLoggedEntries.size()); 269 mAutofillLoggedEntries.size());
263 assertLogged(FIRST_NAME, profileFullName); 270 assertLogged(FIRST_NAME, profileFullName);
264 assertLogged(LAST_NAME, profileFullName); 271 assertLogged(LAST_NAME, profileFullName);
265 assertLogged(EMAIL, profileFullName); 272 assertLogged(EMAIL, profileFullName);
266 assertLogged(COUNTRY, profileFullName); 273 assertLogged(COUNTRY, profileFullName);
267 } 274 }
268 275
269 /** 276 /**
270 * Tests that bringing up an Autofill and clicking on the empty first elemen t 277 * Tests that bringing up an Autofill and clicking on the empty first elemen t
271 * will fill the all other elements except the previously filled email. 278 * will fill the all other elements except the previously filled email.
272 */ 279 */
280 @Test
273 @MediumTest 281 @MediumTest
274 @Feature({"autofill"}) 282 @Feature({"autofill"})
275 public void testLoggingAnotherElementFilled() 283 public void testLoggingAnotherElementFilled()
276 throws InterruptedException, ExecutionException, TimeoutException { 284 throws InterruptedException, ExecutionException, TimeoutException {
277 loadAndFillForm(ANOTHER_ELEMENT_FILLED, "J"); 285 loadAndFillForm(ANOTHER_ELEMENT_FILLED, "J");
278 final String profileFullName = FIRST_NAME + " " + LAST_NAME; 286 final String profileFullName = FIRST_NAME + " " + LAST_NAME;
279 final int loggedEntries = 3; 287 final int loggedEntries = 3;
280 assertEquals("Mismatched number of logged entries", 288 Assert.assertEquals("Mismatched number of logged entries", loggedEntries ,
281 loggedEntries, mAutofillLoggedEntries.size()); 289 mAutofillLoggedEntries.size());
282 assertLogged(FIRST_NAME, profileFullName); 290 assertLogged(FIRST_NAME, profileFullName);
283 assertLogged(LAST_NAME, profileFullName); 291 assertLogged(LAST_NAME, profileFullName);
284 assertLogged(COUNTRY, profileFullName); 292 assertLogged(COUNTRY, profileFullName);
285 // Email will not be logged since it already had some data. 293 // Email will not be logged since it already had some data.
286 } 294 }
287 295
288 /** 296 /**
289 * Tests that selecting a value not present in <option> will not be filled. 297 * Tests that selecting a value not present in <option> will not be filled.
290 */ 298 */
299 @Test
291 @MediumTest 300 @MediumTest
292 @Feature({"autofill"}) 301 @Feature({"autofill"})
293 public void testNotLoggingInvalidOption() 302 public void testNotLoggingInvalidOption()
294 throws InterruptedException, ExecutionException, TimeoutException { 303 throws InterruptedException, ExecutionException, TimeoutException {
295 loadAndFillForm(INVALID_OPTION, "o"); 304 loadAndFillForm(INVALID_OPTION, "o");
296 final String profileFullName = FIRST_NAME + " " + LAST_NAME; 305 final String profileFullName = FIRST_NAME + " " + LAST_NAME;
297 final int loggedEntries = 3; 306 final int loggedEntries = 3;
298 assertEquals("Mismatched number of logged entries", 307 Assert.assertEquals("Mismatched number of logged entries", loggedEntries ,
299 loggedEntries, mAutofillLoggedEntries.size()); 308 mAutofillLoggedEntries.size());
300 assertLogged(FIRST_NAME, profileFullName); 309 assertLogged(FIRST_NAME, profileFullName);
301 assertLogged(LAST_NAME, profileFullName); 310 assertLogged(LAST_NAME, profileFullName);
302 assertLogged(EMAIL, profileFullName); 311 assertLogged(EMAIL, profileFullName);
303 // Country will not be logged since "US" is not a valid <option>. 312 // Country will not be logged since "US" is not a valid <option>.
304 } 313 }
305 314
306 // Wait and assert helper methods ------------------------------------------ ------------------- 315 // Wait and assert helper methods ------------------------------------------ -------------------
307 316
308 private void waitForKeyboardShowRequest(final TestInputMethodManagerWrapper immw, 317 private void waitForKeyboardShowRequest(final TestInputMethodManagerWrapper immw,
309 final int count) { 318 final int count) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 }); 364 });
356 } 365 }
357 366
358 private void assertLogged(String autofilledValue, String profileFullName) { 367 private void assertLogged(String autofilledValue, String profileFullName) {
359 for (AutofillLogger.LogEntry entry : mAutofillLoggedEntries) { 368 for (AutofillLogger.LogEntry entry : mAutofillLoggedEntries) {
360 if (entry.getAutofilledValue().equals(autofilledValue) 369 if (entry.getAutofilledValue().equals(autofilledValue)
361 && entry.getProfileFullName().equals(profileFullName)) { 370 && entry.getProfileFullName().equals(profileFullName)) {
362 return; 371 return;
363 } 372 }
364 } 373 }
365 fail("Logged entry not found [" + autofilledValue + "," + profileFullNam e + "]"); 374 Assert.fail("Logged entry not found [" + autofilledValue + "," + profile FullName + "]");
366 } 375 }
367 } 376 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698