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

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

Issue 14904002: Load and send Wallet Risk params after user has agreed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
index 92de86c90e3730bc74b7493789179bf464aebc08..def96e32c9404bdaf6313f329ad588d56ff97e10 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
@@ -13,6 +13,7 @@
#include "chrome/test/base/testing_profile.h"
#include "components/autofill/browser/autofill_common_test.h"
#include "components/autofill/browser/autofill_metrics.h"
+#include "components/autofill/browser/risk/proto/fingerprint.pb.h"
#include "components/autofill/browser/test_personal_data_manager.h"
#include "components/autofill/browser/wallet/full_wallet.h"
#include "components/autofill/browser/wallet/instrument.h"
@@ -37,9 +38,10 @@ namespace autofill {
namespace {
const char kFakeEmail[] = "user@example.com";
+const char kFakeFingerprintEncoded[] = "CgVaAwiACA==";
const char kEditedBillingAddress[] = "123 edited billing address";
-const char* kFieldsFromPage[] = { "email", "cc-number", "billing region",
- "shipping region" };
+const char* kFieldsFromPage[] =
+ { "email", "cc-number", "billing region", "shipping region" };
const char kSettingsOrigin[] = "Chrome settings";
using content::BrowserThread;
@@ -56,6 +58,22 @@ void SetOutputValue(const DetailInputs& inputs,
}
}
+scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() {
+ base::DictionaryValue dict;
+ scoped_ptr<base::ListValue> list(new base::ListValue());
+ list->AppendString("verify_cvv");
+ dict.Set("required_action", list.release());
+ return wallet::FullWallet::CreateFullWallet(dict);
+}
+
+scoped_ptr<risk::Fingerprint> GetFakeFingerprint() {
+ scoped_ptr<risk::Fingerprint> fingerprint(new risk::Fingerprint());
+ // Add some data to the proto, else the encoded content is empty.
+ fingerprint->mutable_machine_characteristics()->mutable_screen_size()->
+ set_width(1024);
+ return fingerprint.Pass();
+}
+
class TestAutofillDialogView : public AutofillDialogView {
public:
TestAutofillDialogView() {}
@@ -222,6 +240,9 @@ class TestAutofillDialogController
void set_dialog_type(DialogType dialog_type) { dialog_type_ = dialog_type; }
+ MOCK_METHOD0(LoadRiskFingerprintData, void());
+ using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData;
+
protected:
virtual PersonalDataManager* GetManager() OVERRIDE {
return &test_manager_;
@@ -285,7 +306,7 @@ class AutofillDialogControllerTest : public testing::Test {
base::Callback<void(const FormStructure*, const std::string&)> callback =
base::Bind(&AutofillDialogControllerTest::FinishedCallback,
base::Unretained(this));
- controller_ = (new TestAutofillDialogController(
+ controller_ = (new testing::NiceMock<TestAutofillDialogController>(
test_web_contents_.get(),
form_data,
GURL(),
@@ -303,14 +324,6 @@ class AutofillDialogControllerTest : public testing::Test {
}
protected:
- static scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() {
- base::DictionaryValue dict;
- scoped_ptr<base::ListValue> list(new base::ListValue());
- list->AppendString("verify_cvv");
- dict.Set("required_action", list.release());
- return wallet::FullWallet::CreateFullWallet(dict);
- }
-
void FillCreditCardInputs() {
DetailOutputMap cc_outputs;
const DetailInputs& cc_inputs =
@@ -643,6 +656,7 @@ TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) {
AcceptLegalDocuments(_, _, _)).Times(1);
EXPECT_CALL(*controller()->GetTestingWalletClient(),
GetFullWallet(_)).Times(1);
+ EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1);
scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
@@ -650,6 +664,8 @@ TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) {
wallet_items->AddAddress(wallet::GetTestShippingAddress());
controller()->OnDidGetWalletItems(wallet_items.Pass());
controller()->OnAccept();
+ controller()->OnDidAcceptLegalDocuments();
+ controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
}
// Makes sure the default object IDs are respected.
@@ -1036,6 +1052,7 @@ TEST_F(AutofillDialogControllerTest, VerifyCvv) {
wallet_items->AddAddress(wallet::GetTestShippingAddress());
controller()->OnDidGetWalletItems(wallet_items.Pass());
controller()->OnAccept();
+ controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
EXPECT_TRUE(NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty());
EXPECT_TRUE(controller()->SectionIsActive(SECTION_SHIPPING));
@@ -1074,6 +1091,7 @@ TEST_F(AutofillDialogControllerTest, ErrorDuringSubmit) {
wallet_items->AddAddress(wallet::GetTestShippingAddress());
controller()->OnDidGetWalletItems(wallet_items.Pass());
controller()->OnAccept();
+ controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
@@ -1094,6 +1112,7 @@ TEST_F(AutofillDialogControllerTest, ChangeAccountDuringSubmit) {
wallet_items->AddAddress(wallet::GetTestShippingAddress());
controller()->OnDidGetWalletItems(wallet_items.Pass());
controller()->OnAccept();
+ controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
@@ -1114,6 +1133,7 @@ TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) {
wallet_items->AddAddress(wallet::GetTestShippingAddress());
controller()->OnDidGetWalletItems(wallet_items.Pass());
controller()->OnAccept();
+ controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv());
ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
@@ -1135,6 +1155,7 @@ TEST_F(AutofillDialogControllerTest, ChangeAccountDuringVerifyCvv) {
wallet_items->AddAddress(wallet::GetTestShippingAddress());
controller()->OnDidGetWalletItems(wallet_items.Pass());
controller()->OnAccept();
+ controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv());
ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
@@ -1404,4 +1425,49 @@ TEST_F(AutofillDialogControllerTest, SaveDetailsInChrome) {
EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
}
+TEST_F(AutofillDialogControllerTest, RiskNeverLoadsWithPendingLegalDocuments) {
+ EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0);
+
+ scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
+ wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
+ controller()->OnDidGetWalletItems(wallet_items.Pass());
+ controller()->OnAccept();
+
+ EXPECT_TRUE(controller()->GetRiskData().empty());
+}
+
+TEST_F(AutofillDialogControllerTest, RiskLoadsWithoutPendingLegalDocuments) {
+ EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1);
+
+ scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
+ wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
+ wallet_items->AddAddress(wallet::GetTestShippingAddress());
+ controller()->OnDidGetWalletItems(wallet_items.Pass());
+ controller()->OnAccept();
+
+ EXPECT_TRUE(controller()->GetRiskData().empty());
+
+ controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
+ EXPECT_EQ(kFakeFingerprintEncoded, controller()->GetRiskData());
+}
+
+TEST_F(AutofillDialogControllerTest, RiskLoadsAfterAcceptingLegalDocuments) {
+ EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0);
+
+ scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
+ wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
+ controller()->OnDidGetWalletItems(wallet_items.Pass());
+
+ testing::Mock::VerifyAndClear(controller());
+ EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1);
+
+ controller()->OnAccept();
+ EXPECT_TRUE(controller()->GetRiskData().empty());
+
+ // Simulate a risk load and verify |GetRiskData()| matches the encoded value.
+ controller()->OnDidAcceptLegalDocuments();
+ controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
+ EXPECT_EQ(kFakeFingerprintEncoded, controller()->GetRiskData());
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698