Commit f8d05574 authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Fixed possible profile duplication when editing.

This was possible because the edited profile was not correctly sent
via the JNI bridge, resulting in the creation of a new profile in
native with a different GUID.

Bug: b/153139772
Change-Id: If8747b2598666e43a007fc26511812420b5e3864
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134237Reviewed-by: default avatarSandro Maggi <sandromaggi@google.com>
Reviewed-by: default avatarMarian Fechete <marianfe@google.com>
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Cr-Commit-Position: refs/heads/master@{#757400}
parent 315d119e
......@@ -33,19 +33,10 @@ public class AssistantCollectUserDataNativeDelegate implements AssistantCollectU
@Override
public void onContactInfoChanged(@Nullable AutofillContact contact) {
if (mNativeAssistantCollectUserDataDelegate != 0) {
String name = null;
String phone = null;
String email = null;
if (contact != null) {
name = contact.getPayerName();
phone = contact.getPayerPhone();
email = contact.getPayerEmail();
}
AssistantCollectUserDataNativeDelegateJni.get().onContactInfoChanged(
mNativeAssistantCollectUserDataDelegate,
AssistantCollectUserDataNativeDelegate.this, name, phone, email);
AssistantCollectUserDataNativeDelegate.this,
contact != null ? contact.getProfile() : null);
}
}
......@@ -186,8 +177,8 @@ public class AssistantCollectUserDataNativeDelegate implements AssistantCollectU
@NativeMethods
interface Natives {
void onContactInfoChanged(long nativeAssistantCollectUserDataDelegate,
AssistantCollectUserDataNativeDelegate caller, @Nullable String payerName,
@Nullable String payerPhone, @Nullable String payerEmail);
AssistantCollectUserDataNativeDelegate caller,
@Nullable PersonalDataManager.AutofillProfile contactProfile);
void onShippingAddressChanged(long nativeAssistantCollectUserDataDelegate,
AssistantCollectUserDataNativeDelegate caller,
@Nullable PersonalDataManager.AutofillProfile address);
......
......@@ -10,6 +10,7 @@ import static android.support.test.espresso.action.ViewActions.clearText;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.scrollTo;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.RootMatchers.withDecorView;
import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
......@@ -169,6 +170,68 @@ public class AutofillAssistantPersonalDataManagerTest {
assertThat(getElementValue(getWebContents(), "email"), is("johndoe@google.com"));
}
/**
* Add a contact with Autofill Assistant UI, then edit the profile multiple times (see
* b/153139772).
*/
@Test
@MediumTest
public void testCreateAndEditProfileMultipleTimes() throws Exception {
ArrayList<ActionProto> list = new ArrayList<>();
list.add(
(ActionProto) ActionProto.newBuilder()
.setCollectUserData(
CollectUserDataProto.newBuilder()
.setContactDetails(ContactDetailsProto.newBuilder()
.setContactDetailsName("contact")
.setRequestPayerName(true)
.setRequestPayerEmail(true)
.setRequestPayerPhone(false))
.setRequestTermsAndConditions(false))
.build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Address")))
.build(),
list);
runScript(script);
waitUntilViewMatchesCondition(
allOf(withId(R.id.section_title_add_button_label), withText("Add contact info")),
isCompletelyDisplayed());
onView(allOf(withId(R.id.section_title_add_button_label), withText("Add contact info")))
.perform(click());
waitUntilViewMatchesCondition(
withContentDescription("Name*"), allOf(isDisplayed(), isEnabled()));
onView(withContentDescription("Name*")).perform(typeText("John Doe"));
waitUntilViewMatchesCondition(
withContentDescription("Email*"), allOf(isDisplayed(), isEnabled()));
onView(withContentDescription("Email*")).perform(typeText("doe@google.com"));
onView(withId(org.chromium.chrome.R.id.editor_dialog_done_button)).perform(click());
waitUntilViewMatchesCondition(withText("Continue"), isEnabled());
// First edit: no changes.
onView(withText("Contact info")).perform(click());
onView(withContentDescription("Edit contact info")).perform(click());
waitUntilViewMatchesCondition(
withContentDescription("Name*"), allOf(isDisplayed(), isEnabled()));
onView(withId(org.chromium.chrome.R.id.editor_dialog_done_button)).perform(click());
// Second edit: change name from John Doe to Jane Doe.
onView(withContentDescription("Edit contact info")).perform(click());
waitUntilViewMatchesCondition(
withContentDescription("Name*"), allOf(isDisplayed(), isEnabled()));
onView(withContentDescription("Name*")).perform(clearText(), typeText("Jane Doe"));
onView(withId(org.chromium.chrome.R.id.editor_dialog_done_button)).perform(click());
// There used to be a bug where consecutive edits of the same profile would create a
// duplicate profile, which would break the following checks.
onView(withText(containsString("John Doe"))).check(doesNotExist());
onView(withText(containsString("Jane Doe"))).check(matches(isDisplayed()));
}
/**
* Catch the insert of a profile added outside of the Autofill Assistant, e.g. with the Chrome
* settings UI, and fill it into the form.
......
......@@ -38,39 +38,16 @@ AssistantCollectUserDataDelegate::~AssistantCollectUserDataDelegate() {
void AssistantCollectUserDataDelegate::OnContactInfoChanged(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
const base::android::JavaParamRef<jstring>& jpayer_name,
const base::android::JavaParamRef<jstring>& jpayer_phone,
const base::android::JavaParamRef<jstring>& jpayer_email) {
if (!jpayer_name && !jpayer_phone && !jpayer_email) {
const base::android::JavaParamRef<jobject>& jcontact_profile) {
if (!jcontact_profile) {
ui_controller_->OnContactInfoChanged(nullptr);
return;
}
std::string name = ui_controller_android_utils::SafeConvertJavaStringToNative(
env, jpayer_name);
std::string phone =
ui_controller_android_utils::SafeConvertJavaStringToNative(env,
jpayer_phone);
std::string email =
ui_controller_android_utils::SafeConvertJavaStringToNative(env,
jpayer_email);
auto contact_profile = std::make_unique<autofill::AutofillProfile>();
contact_profile->SetRawInfo(autofill::ServerFieldType::NAME_FULL,
base::UTF8ToUTF16(name));
autofill::data_util::NameParts parts =
autofill::data_util::SplitName(base::UTF8ToUTF16(name));
contact_profile->SetRawInfo(autofill::ServerFieldType::NAME_FIRST,
parts.given);
contact_profile->SetRawInfo(autofill::ServerFieldType::NAME_MIDDLE,
parts.middle);
contact_profile->SetRawInfo(autofill::ServerFieldType::NAME_LAST,
parts.family);
contact_profile->SetRawInfo(autofill::ServerFieldType::EMAIL_ADDRESS,
base::UTF8ToUTF16(email));
contact_profile->SetRawInfo(
autofill::ServerFieldType::PHONE_HOME_WHOLE_NUMBER,
base::UTF8ToUTF16(phone));
autofill::PersonalDataManagerAndroid::PopulateNativeProfileFromJava(
jcontact_profile, env, contact_profile.get());
ui_controller_->OnContactInfoChanged(std::move(contact_profile));
}
......
......@@ -18,9 +18,7 @@ class AssistantCollectUserDataDelegate {
void OnContactInfoChanged(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
const base::android::JavaParamRef<jstring>& jpayer_name,
const base::android::JavaParamRef<jstring>& jpayer_phone,
const base::android::JavaParamRef<jstring>& jpayer_email);
const base::android::JavaParamRef<jobject>& jcontact_profile);
void OnShippingAddressChanged(
JNIEnv* env,
......
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