Commit 1ededfa5 authored by sebsg's avatar sebsg Committed by Commit bot

Also make the dropdown selection text be multiline.

BUG=637332

Review-Url: https://codereview.chromium.org/2287513002
Cr-Commit-Position: refs/heads/master@{#415286}
parent 04594344
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/spinnerItemStyle"
android:singleLine="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="inherit" />
......@@ -518,6 +518,8 @@ public class PersonalDataManager {
/**
* Gets the profiles to show in the settings page. Returns all the profiles without any
* processing.
*
* @return The list of profiles to show in the settings.
*/
public List<AutofillProfile> getProfilesForSettings() {
ThreadUtils.assertOnUiThread();
......@@ -529,10 +531,15 @@ public class PersonalDataManager {
/**
* Gets the profiles to suggest when filling a form or completing a transaction. The profiles
* will have been processed to be more relevant to the user.
*
* @param includeName Whether to include the name in the profile's label.
* @return The list of profiles to suggest to the user.
*/
public List<AutofillProfile> getProfilesToSuggest() {
public List<AutofillProfile> getProfilesToSuggest(boolean includeName) {
ThreadUtils.assertOnUiThread();
return getProfilesWithLabels(nativeGetProfileLabelsToSuggest(mPersonalDataManagerAndroid),
return getProfilesWithLabels(
nativeGetProfileLabelsToSuggest(
mPersonalDataManagerAndroid, includeName),
nativeGetProfileGUIDsToSuggest(mPersonalDataManagerAndroid));
}
......@@ -751,7 +758,8 @@ public class PersonalDataManager {
private native String[] nativeGetProfileGUIDsToSuggest(long nativePersonalDataManagerAndroid);
private native String[] nativeGetProfileLabelsForSettings(
long nativePersonalDataManagerAndroid);
private native String[] nativeGetProfileLabelsToSuggest(long nativePersonalDataManagerAndroid);
private native String[] nativeGetProfileLabelsToSuggest(long nativePersonalDataManagerAndroid,
boolean includeName);
private native AutofillProfile nativeGetProfileByGUID(long nativePersonalDataManagerAndroid,
String guid);
private native String nativeSetProfile(long nativePersonalDataManagerAndroid,
......
......@@ -133,7 +133,8 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument> {
mAddressEditor = addressEditor;
mObserverForTest = observerForTest;
List<AutofillProfile> profiles = PersonalDataManager.getInstance().getProfilesForSettings();
List<AutofillProfile> profiles = PersonalDataManager.getInstance().getProfilesToSuggest(
true /* includeName */);
mProfilesForBillingAddress = new HashMap<>();
for (int i = 0; i < profiles.size(); i++) {
AutofillProfile profile = profiles.get(i);
......
......@@ -243,7 +243,8 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
List<AutofillProfile> profiles = null;
if (requestShipping || requestPayerPhone || requestPayerEmail) {
profiles = PersonalDataManager.getInstance().getProfilesToSuggest();
profiles = PersonalDataManager.getInstance().getProfilesToSuggest(
false /* includeName */);
}
if (requestShipping) {
......
......@@ -61,7 +61,7 @@ class EditorDropdownField implements Validatable {
}
ArrayAdapter<DropdownKeyValue> adapter = new ArrayAdapter<DropdownKeyValue>(
context, android.R.layout.simple_spinner_item, dropdownKeyValues);
context, R.layout.multiline_spinner_item, dropdownKeyValues);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mDropdown = (Spinner) mLayout.findViewById(R.id.spinner);
......
......@@ -35,11 +35,12 @@ public class AutofillTestHelper {
});
}
List<AutofillProfile> getProfilesToSuggest() throws ExecutionException {
List<AutofillProfile> getProfilesToSuggest(final boolean includeName) throws
ExecutionException {
return ThreadUtils.runOnUiThreadBlocking(new Callable<List<AutofillProfile>>() {
@Override
public List<AutofillProfile> call() {
return PersonalDataManager.getInstance().getProfilesToSuggest();
return PersonalDataManager.getInstance().getProfilesToSuggest(includeName);
}
});
}
......@@ -54,7 +55,7 @@ public class AutofillTestHelper {
}
int getNumberOfProfilesToSuggest() throws ExecutionException {
return getProfilesToSuggest().size();
return getProfilesToSuggest(false).size();
}
int getNumberOfProfilesForSettings() throws ExecutionException {
......
......@@ -33,6 +33,12 @@ public class PersonalDataManagerTest extends NativeLibraryTestBase {
mHelper = new AutofillTestHelper();
}
private AutofillProfile createTestProfile() {
return new AutofillProfile("" /* guid */, "https://www.example.com" /* origin */,
"John Major", "Acme Inc.", "123 Main", "California", "Los Angeles", "", "90210", "",
"US", "555 123-4567", "jm@example.com", "");
}
@SmallTest
@Feature({"Autofill"})
public void testAddAndEditProfiles() throws InterruptedException, ExecutionException,
......@@ -104,13 +110,7 @@ public class PersonalDataManagerTest extends NativeLibraryTestBase {
@Feature({"Autofill"})
public void testAddAndDeleteProfile() throws InterruptedException, ExecutionException,
TimeoutException {
AutofillProfile profile = new AutofillProfile(
"" /* guid */, "Chrome settings" /* origin */,
"John Smith", "Acme Inc.",
"1 Main\nApt A", "CA", "San Francisco", "",
"94102", "",
"US", "4158889999", "john@acme.inc", "");
String profileOneGUID = mHelper.setProfile(profile);
String profileOneGUID = mHelper.setProfile(createTestProfile());
assertEquals(1, mHelper.getNumberOfProfilesForSettings());
mHelper.deleteProfile(profileOneGUID);
......@@ -318,7 +318,7 @@ public class PersonalDataManagerTest extends NativeLibraryTestBase {
// a bigger use count that the first profile. It should be second.
mHelper.setProfileUseStatsForTesting(guid3, 6, 5000);
List<AutofillProfile> profiles = mHelper.getProfilesToSuggest();
List<AutofillProfile> profiles = mHelper.getProfilesToSuggest(false /* includeName */);
assertEquals(3, profiles.size());
assertTrue("Profile2 should be ranked first", guid2.equals(profiles.get(0).getGUID()));
assertTrue("Profile3 should be ranked second", guid3.equals(profiles.get(1).getGUID()));
......@@ -389,10 +389,7 @@ public class PersonalDataManagerTest extends NativeLibraryTestBase {
@Feature({"Autofill"})
public void testProfileUseStatsSettingAndGetting() throws InterruptedException,
ExecutionException, TimeoutException {
String guid = mHelper.setProfile(
new AutofillProfile("" /* guid */, "https://www.example.com" /* origin */,
"Jasper Lundgren", "", "1500 Second Ave", "California", "Hollywood", "",
"90068", "", "US", "555 123-9876", "jasperl@example.com", ""));
String guid = mHelper.setProfile(createTestProfile());
// Make sure the profile does not have the specific use stats form the start.
assertTrue(1234 != mHelper.getProfileUseCountForTesting(guid));
......@@ -433,10 +430,7 @@ public class PersonalDataManagerTest extends NativeLibraryTestBase {
@Feature({"Autofill"})
public void testRecordAndLogProfileUse() throws InterruptedException, ExecutionException,
TimeoutException {
String guid = mHelper.setProfile(
new AutofillProfile("" /* guid */, "https://www.example.com" /* origin */,
"Jasper Lundgren", "", "1500 Second Ave", "California", "Hollywood", "",
"90068", "", "US", "555 123-9876", "jasperl@example.com", ""));
String guid = mHelper.setProfile(createTestProfile());
// Set specific use stats for the profile.
mHelper.setProfileUseStatsForTesting(guid, 1234, 1234);
......@@ -485,4 +479,26 @@ public class PersonalDataManagerTest extends NativeLibraryTestBase {
assertTrue(timeBeforeRecord <= mHelper.getCreditCardUseDateForTesting(guid));
assertTrue(timeAfterRecord >= mHelper.getCreditCardUseDateForTesting(guid));
}
@SmallTest
@Feature({"Autofill"})
public void testGetProfilesToSuggest_NoName() throws InterruptedException, ExecutionException,
TimeoutException {
mHelper.setProfile(createTestProfile());
List<AutofillProfile> profiles = mHelper.getProfilesToSuggest(false /* includeName */);
assertEquals("Acme Inc., 123 Main, Los Angeles, California 90210, United States",
profiles.get(0).getLabel());
}
@SmallTest
@Feature({"Autofill"})
public void testGetProfilesToSuggest_WithName() throws InterruptedException, ExecutionException,
TimeoutException {
mHelper.setProfile(createTestProfile());
List<AutofillProfile> profiles = mHelper.getProfilesToSuggest(true /* includeName */);
assertEquals("John Major, Acme Inc., 123 Main, Los Angeles, California 90210, "
+ "United States", profiles.get(0).getLabel());
}
}
......@@ -389,4 +389,13 @@ public class PaymentRequestNoShippingTest extends PaymentRequestTestBase {
"PaymentRequest.RequestedInformation", i));
}
}
/** Verifies the format of the billing address suggestions when adding a new credit card. */
@MediumTest
public void testNewCardBillingAddressFormat()
throws InterruptedException, ExecutionException, TimeoutException {
fillNewCardForm("5454-5454-5454-5454", "Bob", DECEMBER, NEXT_YEAR, FIRST_BILLING_ADDRESS);
assertTrue(getSpinnerSelectionTextInCardEditor(2).equals(
"Jon Doe, Google, 340 Main St, Los Angeles, CA 90291, United States"));
}
}
......@@ -380,6 +380,18 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeT
});
}
/** Returns the selected spinner value in the editor UI for credit cards. */
protected String getSpinnerSelectionTextInCardEditor(final int dropdownIndex)
throws ExecutionException {
return ThreadUtils.runOnUiThreadBlocking(new Callable<String>() {
@Override
public String call() {
return mUI.getCardEditorView().getDropdownFieldsForTest().get(dropdownIndex)
.getSelectedItem().toString();
}
});
}
/** Selects the spinner value in the editor UI for credit cards. */
protected void setSpinnerSelectionsInCardEditorAndWait(final int[] selections,
CallbackHelper helper) throws InterruptedException, TimeoutException {
......
......@@ -368,14 +368,16 @@ ScopedJavaLocalRef<jobjectArray>
PersonalDataManagerAndroid::GetProfileLabelsForSettings(
JNIEnv* env,
const JavaParamRef<jobject>& unused_obj) {
return GetProfileLabels(env, false, personal_data_manager_->GetProfiles());
return GetProfileLabels(env, false, false,
personal_data_manager_->GetProfiles());
}
ScopedJavaLocalRef<jobjectArray>
PersonalDataManagerAndroid::GetProfileLabelsToSuggest(
JNIEnv* env,
const JavaParamRef<jobject>& unused_obj) {
return GetProfileLabels(env, true,
const JavaParamRef<jobject>& unused_obj,
jboolean include_name) {
return GetProfileLabels(env, true, include_name,
personal_data_manager_->GetProfilesToSuggest());
}
......@@ -656,11 +658,14 @@ ScopedJavaLocalRef<jobjectArray> PersonalDataManagerAndroid::GetCreditCardGUIDs(
ScopedJavaLocalRef<jobjectArray> PersonalDataManagerAndroid::GetProfileLabels(
JNIEnv* env,
bool address_only,
bool include_name,
std::vector<AutofillProfile*> profiles) {
std::unique_ptr<std::vector<ServerFieldType>> suggested_fields;
size_t minimal_fields_shown = 2;
if (address_only) {
suggested_fields.reset(new std::vector<ServerFieldType>);
if (include_name)
suggested_fields->push_back(NAME_FULL);
suggested_fields->push_back(COMPANY_NAME);
suggested_fields->push_back(ADDRESS_HOME_LINE1);
suggested_fields->push_back(ADDRESS_HOME_LINE2);
......@@ -673,9 +678,11 @@ ScopedJavaLocalRef<jobjectArray> PersonalDataManagerAndroid::GetProfileLabels(
minimal_fields_shown = suggested_fields->size();
}
ServerFieldType excluded_field = include_name ? UNKNOWN_TYPE : NAME_FULL;
std::vector<base::string16> labels;
AutofillProfile::CreateInferredLabels(
profiles, suggested_fields.get(), NAME_FULL, minimal_fields_shown,
profiles, suggested_fields.get(), excluded_field, minimal_fields_shown,
g_browser_process->GetApplicationLocale(), &labels);
return base::android::ToJavaArrayOfStrings(env, labels);
......
......@@ -61,11 +61,13 @@ class PersonalDataManagerAndroid : public PersonalDataManagerObserver {
// Gets the labels for the profiles to suggest to the user. These labels are
// useful for distinguishing the profiles from one another.
//
// The labels never contain the full name, email address, or phone numbers.
// All other fields are included in the label.
// The labels never contain the email address, or phone numbers. The
// |include_name| argument controls whether the name is included. All other
// fields are included in the label.
base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabelsToSuggest(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& unused_obj);
const base::android::JavaParamRef<jobject>& unused_obj,
jboolean include_name);
// Returns the label of the given profile for PaymentRequest. This label does
// not contain the full name or the email address. All other fields are
......@@ -266,6 +268,7 @@ class PersonalDataManagerAndroid : public PersonalDataManagerObserver {
base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabels(
JNIEnv* env,
bool address_only,
bool include_name,
std::vector<AutofillProfile*> profiles);
// Pointer to the java counterpart.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment