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

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

Issue 572013002: Removing ContentViewCore dependencies from direct WebContents functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased the patch and addressed review comments. Created 6 years, 2 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.test.suitebuilder.annotation.MediumTest; 7 import android.test.suitebuilder.annotation.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.chromium.base.ThreadUtils; 12 import org.chromium.base.ThreadUtils;
13 import org.chromium.base.test.util.Feature; 13 import org.chromium.base.test.util.Feature;
14 import org.chromium.base.test.util.UrlUtils; 14 import org.chromium.base.test.util.UrlUtils;
15 import org.chromium.chrome.R; 15 import org.chromium.chrome.R;
16 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; 16 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
17 import org.chromium.chrome.shell.ChromeShellTestBase; 17 import org.chromium.chrome.shell.ChromeShellTestBase;
18 import org.chromium.content.browser.ContentViewCore; 18 import org.chromium.content.browser.ContentViewCore;
19 import org.chromium.content.browser.test.util.Criteria; 19 import org.chromium.content.browser.test.util.Criteria;
20 import org.chromium.content.browser.test.util.CriteriaHelper; 20 import org.chromium.content.browser.test.util.CriteriaHelper;
21 import org.chromium.content.browser.test.util.DOMUtils; 21 import org.chromium.content.browser.test.util.DOMUtils;
22 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper; 22 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper;
23 import org.chromium.content.browser.test.util.TouchCommon; 23 import org.chromium.content.browser.test.util.TouchCommon;
24 import org.chromium.content_public.browser.WebContents;
24 import org.chromium.ui.autofill.AutofillPopup; 25 import org.chromium.ui.autofill.AutofillPopup;
25 26
26 import java.util.ArrayList; 27 import java.util.ArrayList;
27 import java.util.List; 28 import java.util.List;
28 import java.util.concurrent.ExecutionException; 29 import java.util.concurrent.ExecutionException;
29 import java.util.concurrent.TimeoutException; 30 import java.util.concurrent.TimeoutException;
30 31
31 /** 32 /**
32 * Integration tests for the AutofillPopup. 33 * Integration tests for the AutofillPopup.
33 */ 34 */
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 private void loadAndFillForm( 135 private void loadAndFillForm(
135 final String formDataUrl, final String inputText) 136 final String formDataUrl, final String inputText)
136 throws InterruptedException, ExecutionException, TimeoutException { 137 throws InterruptedException, ExecutionException, TimeoutException {
137 launchChromeShellWithUrl(formDataUrl); 138 launchChromeShellWithUrl(formDataUrl);
138 assertTrue(waitForActiveShellToBeDoneLoading()); 139 assertTrue(waitForActiveShellToBeDoneLoading());
139 mHelper = new AutofillTestHelper(); 140 mHelper = new AutofillTestHelper();
140 141
141 // The TestInputMethodManagerWrapper intercepts showSoftInput so that a keyboard is never 142 // The TestInputMethodManagerWrapper intercepts showSoftInput so that a keyboard is never
142 // brought up. 143 // brought up.
143 final ContentViewCore viewCore = getActivity().getActiveContentViewCore( ); 144 final ContentViewCore viewCore = getActivity().getActiveContentViewCore( );
145 final WebContents webContents = viewCore.getWebContents();
144 final ViewGroup view = viewCore.getContainerView(); 146 final ViewGroup view = viewCore.getContainerView();
145 final TestInputMethodManagerWrapper immw = 147 final TestInputMethodManagerWrapper immw =
146 new TestInputMethodManagerWrapper(viewCore); 148 new TestInputMethodManagerWrapper(viewCore);
147 viewCore.getImeAdapterForTest().setInputMethodManagerWrapper(immw); 149 viewCore.getImeAdapterForTest().setInputMethodManagerWrapper(immw);
148 150
149 // Add an Autofill profile. 151 // Add an Autofill profile.
150 AutofillProfile profile = new AutofillProfile( 152 AutofillProfile profile = new AutofillProfile(
151 "" /* guid */, ORIGIN, FIRST_NAME + " " + LAST_NAME, COMPANY_NAM E, 153 "" /* guid */, ORIGIN, FIRST_NAME + " " + LAST_NAME, COMPANY_NAM E,
152 STREET_ADDRESS_TEXTAREA, 154 STREET_ADDRESS_TEXTAREA,
153 STATE, CITY, DEPENDENT_LOCALITY, 155 STATE, CITY, DEPENDENT_LOCALITY,
154 ZIP_CODE, SORTING_CODE, COUNTRY, PHONE_NUMBER, EMAIL, 156 ZIP_CODE, SORTING_CODE, COUNTRY, PHONE_NUMBER, EMAIL,
155 LANGUAGE_CODE); 157 LANGUAGE_CODE);
156 mHelper.setProfile(profile); 158 mHelper.setProfile(profile);
157 assertEquals(1, mHelper.getNumberOfProfiles()); 159 assertEquals(1, mHelper.getNumberOfProfiles());
158 160
159 // Click the input field for the first name. 161 // Click the input field for the first name.
160 assertTrue(DOMUtils.waitForNonZeroNodeBounds(viewCore, "fn")); 162 assertTrue(DOMUtils.waitForNonZeroNodeBounds(webContents, "fn"));
161 DOMUtils.clickNode(this, viewCore, "fn"); 163 DOMUtils.clickNode(this, viewCore, "fn");
162 164
163 waitForKeyboardShowRequest(immw, 1); 165 waitForKeyboardShowRequest(immw, 1);
164 166
165 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 167 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
166 @Override 168 @Override
167 public void run() { 169 public void run() {
168 viewCore.getInputConnectionForTest().setComposingText( 170 viewCore.getInputConnectionForTest().setComposingText(
169 inputText, 1); 171 inputText, 1);
170 } 172 }
171 }); 173 });
172 174
173 waitForAnchorViewAdd(view); 175 waitForAnchorViewAdd(view);
174 View anchorView = view.findViewById(R.id.dropdown_popup_window); 176 View anchorView = view.findViewById(R.id.dropdown_popup_window);
175 177
176 assertTrue(anchorView.getTag() instanceof AutofillPopup); 178 assertTrue(anchorView.getTag() instanceof AutofillPopup);
177 final AutofillPopup popup = (AutofillPopup) anchorView.getTag(); 179 final AutofillPopup popup = (AutofillPopup) anchorView.getTag();
178 180
179 waitForAutofillPopopShow(popup); 181 waitForAutofillPopopShow(popup);
180 182
181 TouchCommon touchCommon = new TouchCommon(this); 183 TouchCommon touchCommon = new TouchCommon(this);
182 touchCommon.singleClickViewRelative(popup.getListView(), 10, 10); 184 touchCommon.singleClickViewRelative(popup.getListView(), 10, 10);
183 185
184 waitForInputFieldFill(viewCore); 186 waitForInputFieldFill(webContents);
185 } 187 }
186 188
187 /** 189 /**
188 * Tests that bringing up an Autofill and clicking on the first entry fills out the expected 190 * Tests that bringing up an Autofill and clicking on the first entry fills out the expected
189 * Autofill information. 191 * Autofill information.
190 */ 192 */
191 @MediumTest 193 @MediumTest
192 @Feature({"autofill"}) 194 @Feature({"autofill"})
193 public void testClickAutofillPopupSuggestion() 195 public void testClickAutofillPopupSuggestion()
194 throws InterruptedException, ExecutionException, TimeoutException { 196 throws InterruptedException, ExecutionException, TimeoutException {
195 loadAndFillForm(BASIC_PAGE_DATA, "J"); 197 loadAndFillForm(BASIC_PAGE_DATA, "J");
196 final ContentViewCore viewCore = getActivity().getActiveContentViewCore( ); 198 final ContentViewCore viewCore = getActivity().getActiveContentViewCore( );
199 final WebContents webContents = viewCore.getWebContents();
197 200
198 assertEquals("First name did not match", 201 assertEquals("First name did not match",
199 FIRST_NAME, DOMUtils.getNodeValue(viewCore, "fn")); 202 FIRST_NAME, DOMUtils.getNodeValue(webContents, "fn"));
200 assertEquals("Last name did not match", 203 assertEquals("Last name did not match",
201 LAST_NAME, DOMUtils.getNodeValue(viewCore, "ln")); 204 LAST_NAME, DOMUtils.getNodeValue(webContents, "ln"));
202 assertEquals("Street address (textarea) did not match", 205 assertEquals("Street address (textarea) did not match",
203 STREET_ADDRESS_TEXTAREA, DOMUtils.getNodeValue(viewCore, "sa")); 206 STREET_ADDRESS_TEXTAREA, DOMUtils.getNodeValue(webContents, "sa" ));
204 assertEquals("Address line 1 did not match", 207 assertEquals("Address line 1 did not match",
205 ADDRESS_LINE1, DOMUtils.getNodeValue(viewCore, "a1")); 208 ADDRESS_LINE1, DOMUtils.getNodeValue(webContents, "a1"));
206 assertEquals("Address line 2 did not match", 209 assertEquals("Address line 2 did not match",
207 ADDRESS_LINE2, DOMUtils.getNodeValue(viewCore, "a2")); 210 ADDRESS_LINE2, DOMUtils.getNodeValue(webContents, "a2"));
208 assertEquals("City did not match", 211 assertEquals("City did not match",
209 CITY, DOMUtils.getNodeValue(viewCore, "ct")); 212 CITY, DOMUtils.getNodeValue(webContents, "ct"));
210 assertEquals("Zip code did not match", 213 assertEquals("Zip code did not match",
211 ZIP_CODE, DOMUtils.getNodeValue(viewCore, "zc")); 214 ZIP_CODE, DOMUtils.getNodeValue(webContents, "zc"));
212 assertEquals("Country did not match", 215 assertEquals("Country did not match",
213 COUNTRY, DOMUtils.getNodeValue(viewCore, "co")); 216 COUNTRY, DOMUtils.getNodeValue(webContents, "co"));
214 assertEquals("Email did not match", 217 assertEquals("Email did not match",
215 EMAIL, DOMUtils.getNodeValue(viewCore, "em")); 218 EMAIL, DOMUtils.getNodeValue(webContents, "em"));
216 assertEquals("Phone number did not match", 219 assertEquals("Phone number did not match",
217 PHONE_NUMBER, DOMUtils.getNodeValue(viewCore, "ph")); 220 PHONE_NUMBER, DOMUtils.getNodeValue(webContents, "ph"));
218 221
219 final String profileFullName = FIRST_NAME + " " + LAST_NAME; 222 final String profileFullName = FIRST_NAME + " " + LAST_NAME;
220 final int loggedEntries = 10; 223 final int loggedEntries = 10;
221 assertEquals("Mismatched number of logged entries", 224 assertEquals("Mismatched number of logged entries",
222 loggedEntries, mAutofillLoggedEntries.size()); 225 loggedEntries, mAutofillLoggedEntries.size());
223 assertLogged(FIRST_NAME, profileFullName); 226 assertLogged(FIRST_NAME, profileFullName);
224 assertLogged(LAST_NAME, profileFullName); 227 assertLogged(LAST_NAME, profileFullName);
225 assertLogged(STREET_ADDRESS_TEXTAREA, profileFullName); 228 assertLogged(STREET_ADDRESS_TEXTAREA, profileFullName);
226 assertLogged(ADDRESS_LINE1, profileFullName); 229 assertLogged(ADDRESS_LINE1, profileFullName);
227 assertLogged(ADDRESS_LINE2, profileFullName); 230 assertLogged(ADDRESS_LINE2, profileFullName);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 private void waitForAutofillPopopShow(final AutofillPopup popup) throws Inte rruptedException { 317 private void waitForAutofillPopopShow(final AutofillPopup popup) throws Inte rruptedException {
315 assertTrue("Autofill Popup anchor view was never added.", 318 assertTrue("Autofill Popup anchor view was never added.",
316 CriteriaHelper.pollForCriteria(new Criteria() { 319 CriteriaHelper.pollForCriteria(new Criteria() {
317 @Override 320 @Override
318 public boolean isSatisfied() { 321 public boolean isSatisfied() {
319 return popup.isShowing(); 322 return popup.isShowing();
320 } 323 }
321 })); 324 }));
322 } 325 }
323 326
324 private void waitForInputFieldFill(final ContentViewCore viewCore) throws In terruptedException { 327 private void waitForInputFieldFill(final WebContents webContents) throws Int erruptedException {
325 assertTrue("First name field was never filled.", 328 assertTrue("First name field was never filled.",
326 CriteriaHelper.pollForCriteria(new Criteria() { 329 CriteriaHelper.pollForCriteria(new Criteria() {
327 @Override 330 @Override
328 public boolean isSatisfied() { 331 public boolean isSatisfied() {
329 try { 332 try {
330 return TextUtils.equals(FIRST_NAME, 333 return TextUtils.equals(FIRST_NAME,
331 DOMUtils.getNodeValue(viewCore, "fn")); 334 DOMUtils.getNodeValue(webContents, "fn"));
332 } catch (InterruptedException e) { 335 } catch (InterruptedException e) {
333 return false; 336 return false;
334 } catch (TimeoutException e) { 337 } catch (TimeoutException e) {
335 return false; 338 return false;
336 } 339 }
337 340
338 } 341 }
339 })); 342 }));
340 } 343 }
341 344
342 private void assertLogged(String autofilledValue, String profileFullName) { 345 private void assertLogged(String autofilledValue, String profileFullName) {
343 for (AutofillLogger.LogEntry entry : mAutofillLoggedEntries) { 346 for (AutofillLogger.LogEntry entry : mAutofillLoggedEntries) {
344 if (entry.getAutofilledValue().equals(autofilledValue) && 347 if (entry.getAutofilledValue().equals(autofilledValue) &&
345 entry.getProfileFullName().equals(profileFullName)) { 348 entry.getProfileFullName().equals(profileFullName)) {
346 return; 349 return;
347 } 350 }
348 } 351 }
349 fail("Logged entry not found [" + autofilledValue + "," + profileFullNam e + "]"); 352 fail("Logged entry not found [" + autofilledValue + "," + profileFullNam e + "]");
350 } 353 }
351 } 354 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698