Commit fe543d96 authored by Alfonso Garza's avatar Alfonso Garza Committed by Commit Bot

[AF] Refactor CardNameFixFlowViewDelegateMobile for cross-platform use.

This change updates CardNameFixFlow to follow the same pattern as
CardUnmaskPrompt and the next CL will add the iOS part.
https://chromium-review.googlesource.com/c/chromium/src/+/1757210

Also adds tests for CardNameFixFlowControllerImpl as the delegate
was previously untested.

Bug: 993849
Change-Id: I79de0c7128882bc8ba73b3dac2a2bcb93c3e572a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1817208
Commit-Queue: Alfonso Garza <alfonsogarza@google.com>
Auto-Submit: Alfonso Garza <alfonsogarza@google.com>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700891}
parent a4ab722e
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
#include "chrome/android/chrome_jni_headers/AutofillNameFixFlowBridge_jni.h" #include "chrome/android/chrome_jni_headers/AutofillNameFixFlowBridge_jni.h"
#include "chrome/browser/android/resource_mapper.h" #include "chrome/browser/android/resource_mapper.h"
#include "components/autofill/core/browser/ui/payments/card_name_fix_flow_view_delegate_mobile.h" #include "components/autofill/core/browser/ui/payments/card_name_fix_flow_controller.h"
#include "components/autofill/core/browser/ui/payments/card_name_fix_flow_view.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "ui/android/view_android.h" #include "ui/android/view_android.h"
#include "ui/android/window_android.h" #include "ui/android/window_android.h"
...@@ -17,13 +18,22 @@ using base::android::ScopedJavaLocalRef; ...@@ -17,13 +18,22 @@ using base::android::ScopedJavaLocalRef;
namespace autofill { namespace autofill {
CardNameFixFlowViewAndroid::CardNameFixFlowViewAndroid( CardNameFixFlowViewAndroid::CardNameFixFlowViewAndroid(
std::unique_ptr<CardNameFixFlowViewDelegateMobile> delegate, CardNameFixFlowController* controller,
content::WebContents* web_contents) content::WebContents* web_contents)
: delegate_(std::move(delegate)), web_contents_(web_contents) {} : controller_(controller), web_contents_(web_contents) {}
CardNameFixFlowViewAndroid::~CardNameFixFlowViewAndroid() { void CardNameFixFlowViewAndroid::OnUserAccept(
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env,
Java_AutofillNameFixFlowBridge_dismiss(env, java_object_); const JavaParamRef<jobject>& obj,
const JavaParamRef<jstring>& name) {
controller_->OnNameAccepted(
base::android::ConvertJavaStringToUTF16(env, name));
}
void CardNameFixFlowViewAndroid::PromptDismissed(
JNIEnv* env,
const JavaParamRef<jobject>& obj) {
delete this;
} }
void CardNameFixFlowViewAndroid::Show() { void CardNameFixFlowViewAndroid::Show() {
...@@ -31,38 +41,33 @@ void CardNameFixFlowViewAndroid::Show() { ...@@ -31,38 +41,33 @@ void CardNameFixFlowViewAndroid::Show() {
ui::ViewAndroid* view_android = web_contents_->GetNativeView(); ui::ViewAndroid* view_android = web_contents_->GetNativeView();
ScopedJavaLocalRef<jstring> dialog_title = ScopedJavaLocalRef<jstring> dialog_title =
base::android::ConvertUTF16ToJavaString(env, delegate_->GetTitleText()); base::android::ConvertUTF16ToJavaString(env, controller_->GetTitleText());
ScopedJavaLocalRef<jstring> inferred_name = ScopedJavaLocalRef<jstring> inferred_name =
base::android::ConvertUTF16ToJavaString( base::android::ConvertUTF16ToJavaString(
env, delegate_->GetInferredCardHolderName()); env, controller_->GetInferredCardholderName());
ScopedJavaLocalRef<jstring> confirm = base::android::ConvertUTF16ToJavaString( ScopedJavaLocalRef<jstring> confirm = base::android::ConvertUTF16ToJavaString(
env, delegate_->GetSaveButtonLabel()); env, controller_->GetSaveButtonLabel());
java_object_.Reset(Java_AutofillNameFixFlowBridge_create( java_object_.Reset(Java_AutofillNameFixFlowBridge_create(
env, reinterpret_cast<intptr_t>(this), dialog_title, inferred_name, env, reinterpret_cast<intptr_t>(this), dialog_title, inferred_name,
confirm, ResourceMapper::MapFromChromiumId(delegate_->GetIconId()), confirm, ResourceMapper::MapFromChromiumId(controller_->GetIconId()),
view_android->GetWindowAndroid()->GetJavaObject())); view_android->GetWindowAndroid()->GetJavaObject()));
Java_AutofillNameFixFlowBridge_show( Java_AutofillNameFixFlowBridge_show(
env, java_object_, view_android->GetWindowAndroid()->GetJavaObject()); env, java_object_, view_android->GetWindowAndroid()->GetJavaObject());
delegate_->Shown();
} }
void CardNameFixFlowViewAndroid::OnUserAccept( void CardNameFixFlowViewAndroid::ControllerGone() {
JNIEnv* env, controller_ = nullptr;
const JavaParamRef<jobject>& obj, JNIEnv* env = base::android::AttachCurrentThread();
const JavaParamRef<jstring>& name) {
delegate_->Accept(base::android::ConvertJavaStringToUTF16(env, name));
Java_AutofillNameFixFlowBridge_dismiss(env, java_object_); Java_AutofillNameFixFlowBridge_dismiss(env, java_object_);
} }
void CardNameFixFlowViewAndroid::PromptDismissed( CardNameFixFlowViewAndroid::~CardNameFixFlowViewAndroid() {
JNIEnv* env, if (controller_)
const JavaParamRef<jobject>& obj) { controller_->OnConfirmNameDialogClosed();
delegate_->Dismissed();
delete this;
} }
} // namespace autofill } // namespace autofill
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/android/scoped_java_ref.h" #include "base/android/scoped_java_ref.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "components/autofill/core/browser/ui/payments/card_name_fix_flow_view.h"
namespace content { namespace content {
class WebContents; class WebContents;
...@@ -18,31 +19,31 @@ class WebContents; ...@@ -18,31 +19,31 @@ class WebContents;
namespace autofill { namespace autofill {
class CardNameFixFlowViewDelegateMobile; class CardNameFixFlowController;
// This class is responsible for its destruction. Destruction is achieved by
// calling delete when the prompt is dismissed. class CardNameFixFlowViewAndroid : public CardNameFixFlowView {
class CardNameFixFlowViewAndroid {
public: public:
CardNameFixFlowViewAndroid( // |controller| must outlive |this|.
std::unique_ptr<CardNameFixFlowViewDelegateMobile> delegate, CardNameFixFlowViewAndroid(CardNameFixFlowController* controller,
content::WebContents* web_contents); content::WebContents* web_contents);
~CardNameFixFlowViewAndroid();
void OnUserAccept(JNIEnv* env, void OnUserAccept(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jstring>& name); const base::android::JavaParamRef<jstring>& name);
void PromptDismissed(JNIEnv* env, void PromptDismissed(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj); const base::android::JavaParamRef<jobject>& obj);
void Show(); // CardNameFixFlowView implementation.
void Show() override;
void ControllerGone() override;
private: private:
~CardNameFixFlowViewAndroid() override;
// The corresponding java object. // The corresponding java object.
base::android::ScopedJavaGlobalRef<jobject> java_object_; base::android::ScopedJavaGlobalRef<jobject> java_object_;
std::unique_ptr<CardNameFixFlowViewDelegateMobile> delegate_; CardNameFixFlowController* controller_;
content::WebContents* web_contents_; content::WebContents* web_contents_;
DISALLOW_COPY_AND_ASSIGN(CardNameFixFlowViewAndroid); DISALLOW_COPY_AND_ASSIGN(CardNameFixFlowViewAndroid);
......
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
#include "components/autofill/core/browser/payments/autofill_save_card_infobar_delegate_mobile.h" #include "components/autofill/core/browser/payments/autofill_save_card_infobar_delegate_mobile.h"
#include "components/autofill/core/browser/payments/autofill_save_card_infobar_mobile.h" #include "components/autofill/core/browser/payments/autofill_save_card_infobar_mobile.h"
#include "components/autofill/core/browser/ui/payments/card_expiration_date_fix_flow_view_delegate_mobile.h" #include "components/autofill/core/browser/ui/payments/card_expiration_date_fix_flow_view_delegate_mobile.h"
#include "components/autofill/core/browser/ui/payments/card_name_fix_flow_view_delegate_mobile.h" #include "components/autofill/core/browser/ui/payments/card_name_fix_flow_view.h"
#include "components/infobars/core/infobar.h" #include "components/infobars/core/infobar.h"
#include "ui/android/window_android.h" #include "ui/android/window_android.h"
#else // !OS_ANDROID #else // !OS_ANDROID
...@@ -334,18 +334,12 @@ void ChromeAutofillClient::ConfirmSaveCreditCardLocally( ...@@ -334,18 +334,12 @@ void ChromeAutofillClient::ConfirmSaveCreditCardLocally(
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
void ChromeAutofillClient::ConfirmAccountNameFixFlow( void ChromeAutofillClient::ConfirmAccountNameFixFlow(
base::OnceCallback<void(const base::string16&)> callback) { base::OnceCallback<void(const base::string16&)> callback) {
std::unique_ptr<CardNameFixFlowViewDelegateMobile>
card_name_fix_flow_view_delegate_mobile =
std::make_unique<CardNameFixFlowViewDelegateMobile>(
GetAccountHolderName(),
/*upload_save_card_callback=*/std::move(callback));
// Destruction is handled by the fix flow dialog by explicitly calling delete
// when the prompt is dismissed.
CardNameFixFlowViewAndroid* card_name_fix_flow_view_android = CardNameFixFlowViewAndroid* card_name_fix_flow_view_android =
new CardNameFixFlowViewAndroid( new CardNameFixFlowViewAndroid(&card_name_fix_flow_controller_,
std::move(card_name_fix_flow_view_delegate_mobile), web_contents()); web_contents());
card_name_fix_flow_view_android->Show(); card_name_fix_flow_controller_.Show(
card_name_fix_flow_view_android, GetAccountHolderName(),
/*upload_save_card_callback=*/std::move(callback));
} }
void ChromeAutofillClient::ConfirmExpirationDateFixFlow( void ChromeAutofillClient::ConfirmExpirationDateFixFlow(
......
...@@ -23,11 +23,13 @@ ...@@ -23,11 +23,13 @@
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h" #include "content/public/browser/web_contents_user_data.h"
#if !defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "components/autofill/core/browser/ui/payments/card_name_fix_flow_controller_impl.h"
#else // !OS_ANDROID
#include "chrome/browser/ui/autofill/payments/manage_migration_ui_controller.h" #include "chrome/browser/ui/autofill/payments/manage_migration_ui_controller.h"
#include "chrome/browser/ui/autofill/payments/save_card_bubble_controller.h" #include "chrome/browser/ui/autofill/payments/save_card_bubble_controller.h"
#include "components/zoom/zoom_observer.h" #include "components/zoom/zoom_observer.h"
#endif // !defined(OS_ANDROID) #endif
namespace content { namespace content {
class WebContents; class WebContents;
...@@ -166,6 +168,9 @@ class ChromeAutofillClient ...@@ -166,6 +168,9 @@ class ChromeAutofillClient
base::WeakPtr<AutofillPopupControllerImpl> popup_controller_; base::WeakPtr<AutofillPopupControllerImpl> popup_controller_;
CardUnmaskPromptControllerImpl unmask_controller_; CardUnmaskPromptControllerImpl unmask_controller_;
std::unique_ptr<LogManager> log_manager_; std::unique_ptr<LogManager> log_manager_;
#if defined(OS_ANDROID)
CardNameFixFlowControllerImpl card_name_fix_flow_controller_;
#endif
WEB_CONTENTS_USER_DATA_KEY_DECL(); WEB_CONTENTS_USER_DATA_KEY_DECL();
......
...@@ -295,8 +295,10 @@ jumbo_static_library("browser") { ...@@ -295,8 +295,10 @@ jumbo_static_library("browser") {
"ui/mobile_label_formatter.h", "ui/mobile_label_formatter.h",
"ui/payments/card_expiration_date_fix_flow_view_delegate_mobile.cc", "ui/payments/card_expiration_date_fix_flow_view_delegate_mobile.cc",
"ui/payments/card_expiration_date_fix_flow_view_delegate_mobile.h", "ui/payments/card_expiration_date_fix_flow_view_delegate_mobile.h",
"ui/payments/card_name_fix_flow_view_delegate_mobile.cc", "ui/payments/card_name_fix_flow_controller.h",
"ui/payments/card_name_fix_flow_view_delegate_mobile.h", "ui/payments/card_name_fix_flow_controller_impl.cc",
"ui/payments/card_name_fix_flow_controller_impl.h",
"ui/payments/card_name_fix_flow_view.h",
] ]
} }
...@@ -601,6 +603,7 @@ source_set("unit_tests") { ...@@ -601,6 +603,7 @@ source_set("unit_tests") {
sources += [ sources += [
"autofill_assistant_unittest.cc", "autofill_assistant_unittest.cc",
"ui/mobile_label_formatter_unittest.cc", "ui/mobile_label_formatter_unittest.cc",
"ui/payments/card_name_fix_flow_controller_impl_unittest.cc",
] ]
} }
......
// Copyright 2019 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.
#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_UI_PAYMENTS_CARD_NAME_FIX_FLOW_CONTROLLER_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_UI_PAYMENTS_CARD_NAME_FIX_FLOW_CONTROLLER_H_
#include "base/strings/string16.h"
namespace autofill {
// Enables the user to accept or deny cardholder name fix flow prompt.
// Only used on mobile.
class CardNameFixFlowController {
public:
virtual ~CardNameFixFlowController() {}
// Interaction.
virtual void OnConfirmNameDialogClosed() = 0;
virtual void OnNameAccepted(const base::string16& name) = 0;
virtual void OnDismissed() = 0;
// State.
virtual int GetIconId() const = 0;
virtual base::string16 GetInferredCardholderName() const = 0;
virtual base::string16 GetSaveButtonLabel() const = 0;
virtual base::string16 GetTitleText() const = 0;
};
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_UI_PAYMENTS_CARD_NAME_FIX_FLOW_CONTROLLER_H_
// Copyright 2018 The Chromium Authors. All rights reserved. // Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "components/autofill/core/browser/ui/payments/card_name_fix_flow_view_delegate_mobile.h" #include "components/autofill/core/browser/ui/payments/card_name_fix_flow_controller_impl.h"
#include <utility> #include <utility>
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "build/branding_buildflags.h" #include "build/branding_buildflags.h"
#include "components/autofill/core/browser/autofill_metrics.h"
#include "components/autofill/core/browser/ui/payments/card_name_fix_flow_view.h"
#include "components/grit/components_scaled_resources.h" #include "components/grit/components_scaled_resources.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
namespace autofill { namespace autofill {
CardNameFixFlowViewDelegateMobile::CardNameFixFlowViewDelegateMobile( CardNameFixFlowControllerImpl::CardNameFixFlowControllerImpl() {}
const base::string16& inferred_cardholder_name,
base::OnceCallback<void(const base::string16&)> upload_save_card_callback) CardNameFixFlowControllerImpl::~CardNameFixFlowControllerImpl() {
: inferred_cardholder_name_(inferred_cardholder_name), if (card_name_fix_flow_view_)
upload_save_card_callback_(std::move(upload_save_card_callback)), card_name_fix_flow_view_->ControllerGone();
shown_(false),
had_user_interaction_(false) {
DCHECK(!upload_save_card_callback_.is_null());
AutofillMetrics::LogSaveCardCardholderNamePrefilled(
!inferred_cardholder_name_.empty());
}
CardNameFixFlowViewDelegateMobile::~CardNameFixFlowViewDelegateMobile() { if (shown_ && !had_user_interaction_) {
if (shown_ && !had_user_interaction_)
AutofillMetrics::LogCardholderNameFixFlowPromptEvent( AutofillMetrics::LogCardholderNameFixFlowPromptEvent(
AutofillMetrics:: AutofillMetrics::
CARDHOLDER_NAME_FIX_FLOW_PROMPT_CLOSED_WITHOUT_INTERACTION); CARDHOLDER_NAME_FIX_FLOW_PROMPT_CLOSED_WITHOUT_INTERACTION);
}
} }
int CardNameFixFlowViewDelegateMobile::GetIconId() const { void CardNameFixFlowControllerImpl::Show(
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) CardNameFixFlowView* card_name_fix_flow_view,
return IDR_AUTOFILL_GOOGLE_PAY_WITH_DIVIDER; const base::string16& inferred_cardholder_name,
#else base::OnceCallback<void(const base::string16&)> name_accepted_callback) {
return 0; DCHECK(!name_accepted_callback.is_null());
#endif DCHECK(card_name_fix_flow_view);
}
base::string16 CardNameFixFlowViewDelegateMobile::GetTitleText() const { if (card_name_fix_flow_view_)
return l10n_util::GetStringUTF16( card_name_fix_flow_view_->ControllerGone();
IDS_AUTOFILL_SAVE_CARD_CARDHOLDER_NAME_FIX_FLOW_HEADER); card_name_fix_flow_view_ = card_name_fix_flow_view;
}
base::string16 CardNameFixFlowViewDelegateMobile::GetInferredCardHolderName() name_accepted_callback_ = std::move(name_accepted_callback);
const {
return inferred_cardholder_name_; inferred_cardholder_name_ = inferred_cardholder_name;
AutofillMetrics::LogSaveCardCardholderNamePrefilled(
!inferred_cardholder_name_.empty());
card_name_fix_flow_view_->Show();
AutofillMetrics::LogCardholderNameFixFlowPromptEvent(
AutofillMetrics::CARDHOLDER_NAME_FIX_FLOW_PROMPT_SHOWN);
shown_ = true;
} }
base::string16 CardNameFixFlowViewDelegateMobile::GetSaveButtonLabel() const { void CardNameFixFlowControllerImpl::OnConfirmNameDialogClosed() {
return l10n_util::GetStringUTF16( card_name_fix_flow_view_ = nullptr;
IDS_AUTOFILL_FIX_FLOW_PROMPT_SAVE_CARD_LABEL);
} }
void CardNameFixFlowViewDelegateMobile::Accept(const base::string16& name) { void CardNameFixFlowControllerImpl::OnNameAccepted(const base::string16& name) {
std::move(upload_save_card_callback_).Run(name);
AutofillMetrics::LogCardholderNameFixFlowPromptEvent( AutofillMetrics::LogCardholderNameFixFlowPromptEvent(
AutofillMetrics::CARDHOLDER_NAME_FIX_FLOW_PROMPT_ACCEPTED); AutofillMetrics::CARDHOLDER_NAME_FIX_FLOW_PROMPT_ACCEPTED);
had_user_interaction_ = true; had_user_interaction_ = true;
AutofillMetrics::LogSaveCardCardholderNameWasEdited( AutofillMetrics::LogSaveCardCardholderNameWasEdited(
inferred_cardholder_name_ != name); inferred_cardholder_name_ != name);
base::string16 trimmed_name;
base::TrimWhitespace(name, base::TRIM_ALL, &trimmed_name);
std::move(name_accepted_callback_).Run(trimmed_name);
} }
void CardNameFixFlowViewDelegateMobile::Dismissed() { void CardNameFixFlowControllerImpl::OnDismissed() {
AutofillMetrics::LogCardholderNameFixFlowPromptEvent( AutofillMetrics::LogCardholderNameFixFlowPromptEvent(
AutofillMetrics::CARDHOLDER_NAME_FIX_FLOW_PROMPT_DISMISSED); AutofillMetrics::CARDHOLDER_NAME_FIX_FLOW_PROMPT_DISMISSED);
had_user_interaction_ = true; had_user_interaction_ = true;
} }
void CardNameFixFlowViewDelegateMobile::Shown() { int CardNameFixFlowControllerImpl::GetIconId() const {
AutofillMetrics::LogCardholderNameFixFlowPromptEvent( #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
AutofillMetrics::CARDHOLDER_NAME_FIX_FLOW_PROMPT_SHOWN); return IDR_AUTOFILL_GOOGLE_PAY_WITH_DIVIDER;
shown_ = true; #else
return 0;
#endif
}
base::string16 CardNameFixFlowControllerImpl::GetInferredCardholderName()
const {
return inferred_cardholder_name_;
}
base::string16 CardNameFixFlowControllerImpl::GetSaveButtonLabel() const {
return l10n_util::GetStringUTF16(
IDS_AUTOFILL_FIX_FLOW_PROMPT_SAVE_CARD_LABEL);
}
base::string16 CardNameFixFlowControllerImpl::GetTitleText() const {
return l10n_util::GetStringUTF16(
IDS_AUTOFILL_SAVE_CARD_CARDHOLDER_NAME_FIX_FLOW_HEADER);
} }
} // namespace autofill } // namespace autofill
// Copyright 2019 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.
#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_UI_PAYMENTS_CARD_NAME_FIX_FLOW_CONTROLLER_IMPL_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_UI_PAYMENTS_CARD_NAME_FIX_FLOW_CONTROLLER_IMPL_H_
#include <string>
#include "base/callback.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "components/autofill/core/browser/ui/payments/card_name_fix_flow_controller.h"
namespace autofill {
class CardNameFixFlowView;
class CardNameFixFlowControllerImpl : public CardNameFixFlowController {
public:
CardNameFixFlowControllerImpl();
~CardNameFixFlowControllerImpl() override;
void Show(CardNameFixFlowView* card_name_fix_flow_view,
const base::string16& inferred_cardholder_name,
base::OnceCallback<void(const base::string16&)> name_callback);
// CardNameFixFlowController implementation.
void OnConfirmNameDialogClosed() override;
void OnNameAccepted(const base::string16& name) override;
void OnDismissed() override;
int GetIconId() const override;
base::string16 GetInferredCardholderName() const override;
base::string16 GetSaveButtonLabel() const override;
base::string16 GetTitleText() const override;
private:
// Inferred cardholder name from Gaia account.
base::string16 inferred_cardholder_name_;
// View that displays the fix flow prompt.
CardNameFixFlowView* card_name_fix_flow_view_ = nullptr;
// The callback to call once user confirms their name through the fix flow.
base::OnceCallback<void(const base::string16&)> name_accepted_callback_;
// Whether the prompt was shown to the user.
bool shown_ = false;
// Whether the user explicitly accepted or dismissed this prompt.
bool had_user_interaction_ = false;
DISALLOW_COPY_AND_ASSIGN(CardNameFixFlowControllerImpl);
};
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_UI_PAYMENTS_CARD_NAME_FIX_FLOW_CONTROLLER_IMPL_H_
// Copyright 2019 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.
#include "components/autofill/core/browser/ui/payments/card_name_fix_flow_controller_impl.h"
#include <stddef.h>
#include <memory>
#include "base/bind.h"
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "components/autofill/core/browser/autofill_metrics.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/ui/payments/card_name_fix_flow_view.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace autofill {
class TestCardNameFixFlowView : public CardNameFixFlowView {
public:
void Show() override {}
void ControllerGone() override {}
};
class CardNameFixFlowControllerImplGenericTest {
public:
CardNameFixFlowControllerImplGenericTest() {}
void ShowPromptWithInferredName() {
inferred_name_ = base::ASCIIToUTF16("John Doe");
ShowPrompt();
}
void ShowPromptWithoutInferredName() {
inferred_name_ = base::ASCIIToUTF16("");
ShowPrompt();
}
void AcceptWithInferredName() { controller_->OnNameAccepted(inferred_name_); }
void AcceptWithEditedName() {
controller_->OnNameAccepted(base::ASCIIToUTF16("Edited Name"));
}
protected:
std::unique_ptr<TestCardNameFixFlowView> test_card_name_fix_flow_view_;
std::unique_ptr<CardNameFixFlowControllerImpl> controller_;
base::string16 inferred_name_;
base::string16 accepted_name_;
base::WeakPtrFactory<CardNameFixFlowControllerImplGenericTest>
weak_ptr_factory_{this};
private:
void OnNameAccepted(const base::string16& name) { accepted_name_ = name; }
void ShowPrompt() {
controller_->Show(
test_card_name_fix_flow_view_.get(), inferred_name_,
base::BindOnce(
&CardNameFixFlowControllerImplGenericTest::OnNameAccepted,
weak_ptr_factory_.GetWeakPtr()));
}
DISALLOW_COPY_AND_ASSIGN(CardNameFixFlowControllerImplGenericTest);
};
class CardNameFixFlowControllerImplTest
: public CardNameFixFlowControllerImplGenericTest,
public testing::Test {
public:
CardNameFixFlowControllerImplTest() {}
~CardNameFixFlowControllerImplTest() override {}
void SetUp() override {
test_card_name_fix_flow_view_.reset(new TestCardNameFixFlowView());
controller_.reset(new CardNameFixFlowControllerImpl());
}
private:
DISALLOW_COPY_AND_ASSIGN(CardNameFixFlowControllerImplTest);
};
TEST_F(CardNameFixFlowControllerImplTest, LogShown) {
base::HistogramTester histogram_tester;
ShowPromptWithInferredName();
histogram_tester.ExpectUniqueSample(
"Autofill.CardholderNameFixFlowPrompt.Events",
AutofillMetrics::CARDHOLDER_NAME_FIX_FLOW_PROMPT_SHOWN, 1);
}
TEST_F(CardNameFixFlowControllerImplTest, LogPrefilled) {
base::HistogramTester histogram_tester;
ShowPromptWithInferredName();
histogram_tester.ExpectBucketCount("Autofill.SaveCardCardholderNamePrefilled",
true, 1);
}
TEST_F(CardNameFixFlowControllerImplTest, LogNotPrefilled) {
base::HistogramTester histogram_tester;
ShowPromptWithoutInferredName();
histogram_tester.ExpectBucketCount("Autofill.SaveCardCardholderNamePrefilled",
false, 1);
}
TEST_F(CardNameFixFlowControllerImplTest, LogAccepted) {
base::HistogramTester histogram_tester;
ShowPromptWithInferredName();
AcceptWithInferredName();
histogram_tester.ExpectBucketCount(
"Autofill.CardholderNameFixFlowPrompt.Events",
AutofillMetrics::CARDHOLDER_NAME_FIX_FLOW_PROMPT_ACCEPTED, 1);
}
TEST_F(CardNameFixFlowControllerImplTest, LogUserAcceptedInferredName) {
base::HistogramTester histogram_tester;
ShowPromptWithInferredName();
AcceptWithInferredName();
histogram_tester.ExpectBucketCount("Autofill.SaveCardCardholderNameWasEdited",
false, 1);
}
TEST_F(CardNameFixFlowControllerImplTest, LogUserAcceptedEditedName) {
base::HistogramTester histogram_tester;
ShowPromptWithInferredName();
AcceptWithEditedName();
histogram_tester.ExpectBucketCount("Autofill.SaveCardCardholderNameWasEdited",
true, 1);
}
TEST_F(CardNameFixFlowControllerImplTest, LogDismissed) {
base::HistogramTester histogram_tester;
controller_->OnDismissed();
histogram_tester.ExpectBucketCount(
"Autofill.CardholderNameFixFlowPrompt.Events",
AutofillMetrics::CARDHOLDER_NAME_FIX_FLOW_PROMPT_DISMISSED, 1);
}
} // namespace autofill
// Copyright 2019 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.
#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_UI_PAYMENTS_CARD_NAME_FIX_FLOW_VIEW_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_UI_PAYMENTS_CARD_NAME_FIX_FLOW_VIEW_H_
#include "base/macros.h"
#include "base/strings/string16.h"
namespace autofill {
// The cross-platform UI interface which prompts the user to confirm their name.
// This object is responsible for its own lifetime.
class CardNameFixFlowView {
public:
virtual void Show() = 0;
virtual void ControllerGone() = 0;
protected:
virtual ~CardNameFixFlowView() = default;
};
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_UI_PAYMENTS_CARD_NAME_FIX_FLOW_VIEW_H_
// Copyright 2018 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.
#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_UI_PAYMENTS_CARD_NAME_FIX_FLOW_VIEW_DELEGATE_MOBILE_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_UI_PAYMENTS_CARD_NAME_FIX_FLOW_VIEW_DELEGATE_MOBILE_H_
#include <memory>
#include "base/callback.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "components/autofill/core/browser/autofill_metrics.h"
namespace autofill {
// Enables the user to accept or deny cardholder name fix flow prompt.
// Only used on mobile.
class CardNameFixFlowViewDelegateMobile {
public:
CardNameFixFlowViewDelegateMobile(
const base::string16& inferred_cardholder_name,
base::OnceCallback<void(const base::string16&)>
upload_save_card_callback);
~CardNameFixFlowViewDelegateMobile();
int GetIconId() const;
base::string16 GetTitleText() const;
base::string16 GetInferredCardHolderName() const;
base::string16 GetSaveButtonLabel() const;
void Accept(const base::string16& name);
void Dismissed();
void Shown();
private:
// Inferred cardholder name from Gaia account.
base::string16 inferred_cardholder_name_;
// The callback to save the credit card to Google Payments once user accepts
// fix flow.
base::OnceCallback<void(const base::string16&)> upload_save_card_callback_;
// Whether the prompt was shown to the user.
bool shown_;
// Did the user ever explicitly accept or dismiss this prompt?
bool had_user_interaction_;
DISALLOW_COPY_AND_ASSIGN(CardNameFixFlowViewDelegateMobile);
};
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_UI_PAYMENTS_CARD_NAME_FIX_FLOW_VIEW_DELEGATE_MOBILE_H_
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