| 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.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.ChromeActivity; |
| 16 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; | 17 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
| 17 import org.chromium.chrome.shell.ChromeShellTestBase; | 18 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| 18 import org.chromium.content.browser.ContentViewCore; | 19 import org.chromium.content.browser.ContentViewCore; |
| 19 import org.chromium.content.browser.test.util.Criteria; | 20 import org.chromium.content.browser.test.util.Criteria; |
| 20 import org.chromium.content.browser.test.util.CriteriaHelper; | 21 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 21 import org.chromium.content.browser.test.util.DOMUtils; | 22 import org.chromium.content.browser.test.util.DOMUtils; |
| 22 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper; | 23 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper; |
| 23 import org.chromium.content.browser.test.util.TouchCommon; | 24 import org.chromium.content.browser.test.util.TouchCommon; |
| 24 import org.chromium.content_public.browser.WebContents; | 25 import org.chromium.content_public.browser.WebContents; |
| 25 import org.chromium.ui.autofill.AutofillPopup; | 26 import org.chromium.ui.autofill.AutofillPopup; |
| 26 | 27 |
| 27 import java.util.ArrayList; | 28 import java.util.ArrayList; |
| 28 import java.util.List; | 29 import java.util.List; |
| 29 import java.util.concurrent.ExecutionException; | 30 import java.util.concurrent.ExecutionException; |
| 30 import java.util.concurrent.TimeoutException; | 31 import java.util.concurrent.TimeoutException; |
| 31 | 32 |
| 32 /** | 33 /** |
| 33 * Integration tests for the AutofillPopup. | 34 * Integration tests for the AutofillPopup. |
| 34 */ | 35 */ |
| 35 public class AutofillPopupTest extends ChromeShellTestBase { | 36 public class AutofillPopupTest extends ChromeActivityTestCaseBase<ChromeActivity
> { |
| 36 | 37 |
| 37 private static final String FIRST_NAME = "John"; | 38 private static final String FIRST_NAME = "John"; |
| 38 private static final String LAST_NAME = "Smith"; | 39 private static final String LAST_NAME = "Smith"; |
| 39 private static final String COMPANY_NAME = "Acme Inc."; | 40 private static final String COMPANY_NAME = "Acme Inc."; |
| 40 private static final String ADDRESS_LINE1 = "1 Main"; | 41 private static final String ADDRESS_LINE1 = "1 Main"; |
| 41 private static final String ADDRESS_LINE2 = "Apt A"; | 42 private static final String ADDRESS_LINE2 = "Apt A"; |
| 42 private static final String STREET_ADDRESS_TEXTAREA = ADDRESS_LINE1 + "\n" +
ADDRESS_LINE2; | 43 private static final String STREET_ADDRESS_TEXTAREA = ADDRESS_LINE1 + "\n" +
ADDRESS_LINE2; |
| 43 private static final String CITY = "San Francisco"; | 44 private static final String CITY = "San Francisco"; |
| 44 private static final String DEPENDENT_LOCALITY = ""; | 45 private static final String DEPENDENT_LOCALITY = ""; |
| 45 private static final String STATE = "CA"; | 46 private static final String STATE = "CA"; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 + "<select id=\"co\" autocomplete=\"country\"><br>" | 112 + "<select id=\"co\" autocomplete=\"country\"><br>" |
| 112 + "<option value=\"GB\">Great Britain</option>" | 113 + "<option value=\"GB\">Great Britain</option>" |
| 113 + "<option value=\"BR\">Brazil</option>" | 114 + "<option value=\"BR\">Brazil</option>" |
| 114 + "</select>" | 115 + "</select>" |
| 115 + "<input type=\"submit\" />" | 116 + "<input type=\"submit\" />" |
| 116 + "</form></body></html>"); | 117 + "</form></body></html>"); |
| 117 | 118 |
| 118 private AutofillTestHelper mHelper; | 119 private AutofillTestHelper mHelper; |
| 119 private List<AutofillLogger.LogEntry> mAutofillLoggedEntries; | 120 private List<AutofillLogger.LogEntry> mAutofillLoggedEntries; |
| 120 | 121 |
| 122 public AutofillPopupTest() { |
| 123 super(ChromeActivity.class); |
| 124 } |
| 125 |
| 126 @Override |
| 127 public void startMainActivity() throws InterruptedException { |
| 128 // Don't launch activity automatically. |
| 129 } |
| 130 |
| 121 @Override | 131 @Override |
| 122 public void setUp() throws Exception { | 132 public void setUp() throws Exception { |
| 123 super.setUp(); | 133 super.setUp(); |
| 124 clearAppData(); | |
| 125 mAutofillLoggedEntries = new ArrayList<AutofillLogger.LogEntry>(); | 134 mAutofillLoggedEntries = new ArrayList<AutofillLogger.LogEntry>(); |
| 126 AutofillLogger.setLogger( | 135 AutofillLogger.setLogger( |
| 127 new AutofillLogger.Logger() { | 136 new AutofillLogger.Logger() { |
| 128 @Override | 137 @Override |
| 129 public void didFillField(AutofillLogger.LogEntry logEntry) { | 138 public void didFillField(AutofillLogger.LogEntry logEntry) { |
| 130 mAutofillLoggedEntries.add(logEntry); | 139 mAutofillLoggedEntries.add(logEntry); |
| 131 } | 140 } |
| 132 } | 141 } |
| 133 ); | 142 ); |
| 134 } | 143 } |
| 135 | 144 |
| 136 private void loadAndFillForm( | 145 private void loadAndFillForm( |
| 137 final String formDataUrl, final String inputText) | 146 final String formDataUrl, final String inputText) |
| 138 throws InterruptedException, ExecutionException, TimeoutException { | 147 throws InterruptedException, ExecutionException, TimeoutException { |
| 139 launchChromeShellWithUrl(formDataUrl); | 148 startMainActivityWithURL(formDataUrl); |
| 140 assertTrue(waitForActiveShellToBeDoneLoading()); | |
| 141 mHelper = new AutofillTestHelper(); | 149 mHelper = new AutofillTestHelper(); |
| 142 | 150 |
| 143 // The TestInputMethodManagerWrapper intercepts showSoftInput so that a
keyboard is never | 151 // The TestInputMethodManagerWrapper intercepts showSoftInput so that a
keyboard is never |
| 144 // brought up. | 152 // brought up. |
| 145 final ContentViewCore viewCore = getActivity().getActiveContentViewCore(
); | 153 final ContentViewCore viewCore = getActivity().getCurrentContentViewCore
(); |
| 146 final WebContents webContents = viewCore.getWebContents(); | 154 final WebContents webContents = viewCore.getWebContents(); |
| 147 final ViewGroup view = viewCore.getContainerView(); | 155 final ViewGroup view = viewCore.getContainerView(); |
| 148 final TestInputMethodManagerWrapper immw = | 156 final TestInputMethodManagerWrapper immw = |
| 149 new TestInputMethodManagerWrapper(viewCore); | 157 new TestInputMethodManagerWrapper(viewCore); |
| 150 viewCore.getImeAdapterForTest().setInputMethodManagerWrapper(immw); | 158 viewCore.getImeAdapterForTest().setInputMethodManagerWrapper(immw); |
| 151 | 159 |
| 152 // Add an Autofill profile. | 160 // Add an Autofill profile. |
| 153 AutofillProfile profile = new AutofillProfile( | 161 AutofillProfile profile = new AutofillProfile( |
| 154 "" /* guid */, ORIGIN, FIRST_NAME + " " + LAST_NAME, COMPANY_NAM
E, | 162 "" /* guid */, ORIGIN, FIRST_NAME + " " + LAST_NAME, COMPANY_NAM
E, |
| 155 STREET_ADDRESS_TEXTAREA, | 163 STREET_ADDRESS_TEXTAREA, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 196 |
| 189 /** | 197 /** |
| 190 * Tests that bringing up an Autofill and clicking on the first entry fills
out the expected | 198 * Tests that bringing up an Autofill and clicking on the first entry fills
out the expected |
| 191 * Autofill information. | 199 * Autofill information. |
| 192 */ | 200 */ |
| 193 @MediumTest | 201 @MediumTest |
| 194 @Feature({"autofill"}) | 202 @Feature({"autofill"}) |
| 195 public void testClickAutofillPopupSuggestion() | 203 public void testClickAutofillPopupSuggestion() |
| 196 throws InterruptedException, ExecutionException, TimeoutException { | 204 throws InterruptedException, ExecutionException, TimeoutException { |
| 197 loadAndFillForm(BASIC_PAGE_DATA, "J"); | 205 loadAndFillForm(BASIC_PAGE_DATA, "J"); |
| 198 final ContentViewCore viewCore = getActivity().getActiveContentViewCore(
); | 206 final ContentViewCore viewCore = getActivity().getCurrentContentViewCore
(); |
| 199 final WebContents webContents = viewCore.getWebContents(); | 207 final WebContents webContents = viewCore.getWebContents(); |
| 200 | 208 |
| 201 assertEquals("First name did not match", | 209 assertEquals("First name did not match", |
| 202 FIRST_NAME, DOMUtils.getNodeValue(webContents, "fn")); | 210 FIRST_NAME, DOMUtils.getNodeValue(webContents, "fn")); |
| 203 assertEquals("Last name did not match", | 211 assertEquals("Last name did not match", |
| 204 LAST_NAME, DOMUtils.getNodeValue(webContents, "ln")); | 212 LAST_NAME, DOMUtils.getNodeValue(webContents, "ln")); |
| 205 assertEquals("Street address (textarea) did not match", | 213 assertEquals("Street address (textarea) did not match", |
| 206 STREET_ADDRESS_TEXTAREA, DOMUtils.getNodeValue(webContents, "sa"
)); | 214 STREET_ADDRESS_TEXTAREA, DOMUtils.getNodeValue(webContents, "sa"
)); |
| 207 assertEquals("Address line 1 did not match", | 215 assertEquals("Address line 1 did not match", |
| 208 ADDRESS_LINE1, DOMUtils.getNodeValue(webContents, "a1")); | 216 ADDRESS_LINE1, DOMUtils.getNodeValue(webContents, "a1")); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 private void assertLogged(String autofilledValue, String profileFullName) { | 353 private void assertLogged(String autofilledValue, String profileFullName) { |
| 346 for (AutofillLogger.LogEntry entry : mAutofillLoggedEntries) { | 354 for (AutofillLogger.LogEntry entry : mAutofillLoggedEntries) { |
| 347 if (entry.getAutofilledValue().equals(autofilledValue) | 355 if (entry.getAutofilledValue().equals(autofilledValue) |
| 348 && entry.getProfileFullName().equals(profileFullName)) { | 356 && entry.getProfileFullName().equals(profileFullName)) { |
| 349 return; | 357 return; |
| 350 } | 358 } |
| 351 } | 359 } |
| 352 fail("Logged entry not found [" + autofilledValue + "," + profileFullNam
e + "]"); | 360 fail("Logged entry not found [" + autofilledValue + "," + profileFullNam
e + "]"); |
| 353 } | 361 } |
| 354 } | 362 } |
| OLD | NEW |