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 70078fc9cf3eba95b80bec0e29b09a4f7fa14ba8..88137bb5673308fe5d84382b12fe5c04091bf931 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" |
@@ -179,7 +180,12 @@ class TestAutofillDialogController |
return &test_wallet_client_; |
} |
+ MOCK_METHOD0(LoadRiskFingerprintData, void()); |
+ |
void set_is_first_run(bool is_first_run) { is_first_run_ = is_first_run; } |
+ void set_fingerprint_data(const std::string& fingerprint_data) { |
+ fingerprint_data_ = fingerprint_data; |
+ } |
protected: |
virtual PersonalDataManager* GetManager() OVERRIDE { |
@@ -194,6 +200,12 @@ class TestAutofillDialogController |
return is_first_run_; |
} |
+ virtual void SerializeFingerprint(risk::Fingerprint* fingerprint, |
+ std::string* data) { |
+ // Ignore |fingerprint|, it's NULL. |
+ data->assign(fingerprint_data_); |
+ } |
+ |
private: |
// To specify our own metric logger. |
virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { |
@@ -204,6 +216,7 @@ class TestAutofillDialogController |
TestPersonalDataManager test_manager_; |
testing::NiceMock<TestWalletClient> test_wallet_client_; |
bool is_first_run_; |
+ std::string fingerprint_data_; |
DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); |
}; |
@@ -238,7 +251,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(), |
@@ -942,4 +955,60 @@ 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()); |
+ |
+ EXPECT_EQ("risky business", controller()->GetRiskData()); |
+} |
+ |
+TEST_F(AutofillDialogControllerTest, RiskLoadsWithoutPendingLegalDocuments) { |
+ EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1); |
+ controller()->set_fingerprint_data("goodbye"); |
+ |
+ scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
+ controller()->OnDidGetWalletItems(wallet_items.Pass()); |
+ // No legal Documents are present, |legal_documents_are_current_| should be |
+ // true and |LoadRiskFingerprintData()| should have been called. |
+ |
+ // |OnRiskFingerprintDataLoaded()| hasn't happened yet, |risk_data_| should be |
+ // empty still (and the default, "risky business", should be returned). |
+ EXPECT_EQ("risky business", controller()->GetRiskData()); |
+ |
+ // Now simulate a risk load success and verify that it's base64 encoded. |
+ controller()->OnDidLoadRiskFingerprintData(scoped_ptr<risk::Fingerprint>()); |
+ EXPECT_EQ("Z29vZGJ5ZQ==", controller()->GetRiskData()); |
+} |
+ |
+TEST_F(AutofillDialogControllerTest, RiskLoadsAfterAcceptingLegalDocuments) { |
+ EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0); |
+ controller()->set_fingerprint_data("hello"); |
+ |
+ scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
+ wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); |
+ controller()->OnDidGetWalletItems(wallet_items.Pass()); |
+ // |legal_documents_are_current_| should be false as there's a legal document. |
+ |
+ // If, for some reason, risk is loaded before |legal_documents_are_current_| |
+ // is true, it should not take effect (and the default should be returned). |
+ controller()->OnDidLoadRiskFingerprintData(scoped_ptr<risk::Fingerprint>()); |
+ EXPECT_EQ("risky business", controller()->GetRiskData()); |
+ |
+ testing::Mock::VerifyAndClear(controller()); |
+ EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1); |
+ |
+ controller()->OnDidAcceptLegalDocuments(); |
+ // Now |legal_documents_are_current_| should be true. |
+ |
+ // No |OnRiskFingerprintDataLoaded()| yet, |risk_data_| is still empty. |
+ EXPECT_EQ("risky business", controller()->GetRiskData()); |
+ |
+ // Now simulate a successful risk load and verify that it's base64 encoded. |
+ controller()->OnDidLoadRiskFingerprintData(scoped_ptr<risk::Fingerprint>()); |
+ EXPECT_EQ("aGVsbG8=", controller()->GetRiskData()); |
+} |
+ |
} // namespace autofill |