diff options
author | ahutter@chromium.org <ahutter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-28 03:50:48 +0000 |
---|---|---|
committer | ahutter@chromium.org <ahutter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-28 03:50:48 +0000 |
commit | 860c5212889d3ac4dc365ea205397151746d6e6b (patch) | |
tree | 14ae8f845317cb55120c6079d745d3c05ab67cdd | |
parent | e64020a96359b82722263d4bfbf710507fd3e9c6 (diff) | |
download | chromium_src-860c5212889d3ac4dc365ea205397151746d6e6b.zip chromium_src-860c5212889d3ac4dc365ea205397151746d6e6b.tar.gz chromium_src-860c5212889d3ac4dc365ea205397151746d6e6b.tar.bz2 |
-Adds a new required action field to OnDidSave* and OnDidUpdate... in
WalletClientObserver
-Adds a new required action, REQUIRE_PHONE_NUMBER, that is sent if a
SaveToWalletRequest is missing a phone number.
-Fixes up WalletItems and FullWallet unit tests
BUG=175581
Review URL: https://chromiumcodereview.appspot.com/12335078
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185139 0039d316-1c4b-4281-b951-d872f2087c98
9 files changed, 431 insertions, 83 deletions
diff --git a/chrome/browser/autofill/wallet/full_wallet_unittest.cc b/chrome/browser/autofill/wallet/full_wallet_unittest.cc index 3dcc833..b2678b9f6 100644 --- a/chrome/browser/autofill/wallet/full_wallet_unittest.cc +++ b/chrome/browser/autofill/wallet/full_wallet_unittest.cc @@ -352,8 +352,8 @@ class FullWalletTest : public testing::Test { protected: void SetUpDictionary(const std::string& json) { scoped_ptr<Value> value(base::JSONReader::Read(json)); - DCHECK(value.get()); - DCHECK(value->IsType(Value::TYPE_DICTIONARY)); + ASSERT_TRUE(value.get()); + ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY)); dict.reset(static_cast<DictionaryValue*>(value.release())); } scoped_ptr<DictionaryValue> dict; @@ -361,32 +361,32 @@ class FullWalletTest : public testing::Test { TEST_F(FullWalletTest, CreateFullWalletMissingExpirationMonth) { SetUpDictionary(kFullWalletMissingExpirationMonth); - ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); + EXPECT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); } TEST_F(FullWalletTest, CreateFullWalletMissingExpirationYear) { SetUpDictionary(kFullWalletMissingExpirationYear); - ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); + EXPECT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); } TEST_F(FullWalletTest, CreateFullWalletMissingIin) { SetUpDictionary(kFullWalletMissingIin); - ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); + EXPECT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); } TEST_F(FullWalletTest, CreateFullWalletMissingRest) { SetUpDictionary(kFullWalletMissingRest); - ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); + EXPECT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); } TEST_F(FullWalletTest, CreateFullWalletMissingBillingAddress) { SetUpDictionary(kFullWalletMissingBillingAddress); - ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); + EXPECT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); } TEST_F(FullWalletTest, CreateFullWalletMalformedBillingAddress) { SetUpDictionary(kFullWalletMalformedBillingAddress); - ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); + EXPECT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); } TEST_F(FullWalletTest, CreateFullWalletWithRequiredActions) { @@ -405,9 +405,9 @@ TEST_F(FullWalletTest, CreateFullWalletWithRequiredActions) { scoped_ptr<Address>(), scoped_ptr<Address>(), required_actions); - ASSERT_EQ(full_wallet, *FullWallet::CreateFullWallet(*dict)); + EXPECT_EQ(full_wallet, *FullWallet::CreateFullWallet(*dict)); - DCHECK(!required_actions.empty()); + ASSERT_FALSE(required_actions.empty()); required_actions.pop_back(); FullWallet different_required_actions( -1, @@ -417,12 +417,12 @@ TEST_F(FullWalletTest, CreateFullWalletWithRequiredActions) { scoped_ptr<Address>(), scoped_ptr<Address>(), required_actions); - ASSERT_NE(full_wallet, different_required_actions); + EXPECT_NE(full_wallet, different_required_actions); } TEST_F(FullWalletTest, CreateFullWalletWithInvalidRequiredActions) { SetUpDictionary(kFullWalletWithInvalidRequiredActions); - ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); + EXPECT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); } TEST_F(FullWalletTest, CreateFullWallet) { @@ -455,7 +455,7 @@ TEST_F(FullWalletTest, CreateFullWallet) { billing_address.Pass(), shipping_address.Pass(), required_actions); - ASSERT_EQ(full_wallet, *FullWallet::CreateFullWallet(*dict)); + EXPECT_EQ(full_wallet, *FullWallet::CreateFullWallet(*dict)); } // TODO(ahutter): Add tests for GetPan and GetCvn. diff --git a/chrome/browser/autofill/wallet/required_action.cc b/chrome/browser/autofill/wallet/required_action.cc index 3557862..df0c6df 100644 --- a/chrome/browser/autofill/wallet/required_action.cc +++ b/chrome/browser/autofill/wallet/required_action.cc @@ -17,11 +17,17 @@ bool ActionAppliesToFullWallet(RequiredAction action) { action == VERIFY_CVV; } +bool ActionAppliesToSaveToWallet(RequiredAction action) { + return action == INVALID_FORM_FIELD || + action == REQUIRE_PHONE_NUMBER; +} + bool ActionAppliesToWalletItems(RequiredAction action) { return action == SETUP_WALLET || action == ACCEPT_TOS || action == GAIA_AUTH || action == INVALID_FORM_FIELD || + action == REQUIRE_PHONE_NUMBER || action == PASSIVE_GAIA_AUTH; } @@ -45,6 +51,8 @@ RequiredAction ParseRequiredActionFromString(const std::string& str) { return VERIFY_CVV; else if (str_lower == "passive_gaia_auth") return PASSIVE_GAIA_AUTH; + else if (str_lower == "require_phone_number") + return REQUIRE_PHONE_NUMBER; DLOG(ERROR) << "Failed to parse: \"" << str << "\" as a required action"; return UNKNOWN_TYPE; diff --git a/chrome/browser/autofill/wallet/required_action.h b/chrome/browser/autofill/wallet/required_action.h index bbb7a2a..0136009 100644 --- a/chrome/browser/autofill/wallet/required_action.h +++ b/chrome/browser/autofill/wallet/required_action.h @@ -25,11 +25,13 @@ enum RequiredAction { INVALID_FORM_FIELD, VERIFY_CVV, PASSIVE_GAIA_AUTH, + REQUIRE_PHONE_NUMBER, }; -// Static helper functions to determine if an RequiredAction applies to either a -// FullWallet or WalletItems. +// Static helper functions to determine if an RequiredAction applies to a +// FullWallet, WalletItems, or SaveToWallet response. bool ActionAppliesToFullWallet(RequiredAction action); +bool ActionAppliesToSaveToWallet(RequiredAction action); bool ActionAppliesToWalletItems(RequiredAction action); // Turn a string value of the parsed JSON response into an RequiredAction. diff --git a/chrome/browser/autofill/wallet/wallet_client.cc b/chrome/browser/autofill/wallet/wallet_client.cc index 49778a3..8e93e9c 100644 --- a/chrome/browser/autofill/wallet/wallet_client.cc +++ b/chrome/browser/autofill/wallet/wallet_client.cc @@ -22,20 +22,23 @@ #include "net/url_request/url_fetcher.h" #include "net/url_request/url_request_context_getter.h" +namespace autofill { +namespace wallet { + namespace { const char kJsonMimeType[] = "application/json"; const size_t kOneTimePadLength = 6; -std::string AutocheckoutStatusToString(autofill::AutocheckoutStatus status) { +std::string AutocheckoutStatusToString(AutocheckoutStatus status) { switch (status) { - case autofill::MISSING_FIELDMAPPING: + case MISSING_FIELDMAPPING: return "MISSING_FIELDMAPPING"; - case autofill::MISSING_ADVANCE: + case MISSING_ADVANCE: return "MISSING_ADVANCE"; - case autofill::CANNOT_PROCEED: + case CANNOT_PROCEED: return "CANNOT_PROCEED"; - case autofill::SUCCESS: + case SUCCESS: // SUCCESS cannot be sent to the server as it will result in a failure. NOTREACHED(); return "ERROR"; @@ -44,6 +47,30 @@ std::string AutocheckoutStatusToString(autofill::AutocheckoutStatus status) { return "NOT_POSSIBLE"; } +// Gets and parses required actions from a SaveToWallet response. Returns +// false if any unknown required actions are seen and true otherwise. +void GetRequiredActionsForSaveToWallet( + const base::DictionaryValue& dict, + std::vector<RequiredAction>* required_actions) { + const ListValue* required_action_list; + if (!dict.GetList("required_action", &required_action_list)) + return; + + for (size_t i = 0; i < required_action_list->GetSize(); ++i) { + std::string action_string; + if (required_action_list->GetString(i, &action_string)) { + RequiredAction action = ParseRequiredActionFromString(action_string); + if (!ActionAppliesToSaveToWallet(action)) { + DLOG(ERROR) << "Response from Google wallet with bad required action:" + " \"" << action_string << "\""; + required_actions->clear(); + return; + } + required_actions->push_back(action); + } + } +} + // Keys for JSON communication with the Online Wallet server. const char kAcceptedLegalDocumentKey[] = "accepted_legal_document"; const char kApiKeyKey[] = "api_key"; @@ -69,8 +96,6 @@ const char kUpgradedInstrumentIdKey[] = "upgraded_instrument_id"; } // namespace -namespace autofill { -namespace wallet { WalletClient::WalletClient(net::URLRequestContextGetter* context_getter) : context_getter_(context_getter), @@ -256,7 +281,7 @@ void WalletClient::SaveInstrumentAndAddress( } void WalletClient::SendAutocheckoutStatus( - autofill::AutocheckoutStatus status, + AutocheckoutStatus status, const GURL& source_url, const std::string& google_transaction_id, base::WeakPtr<WalletClientObserver> observer) { @@ -265,7 +290,7 @@ void WalletClient::SendAutocheckoutStatus( base::DictionaryValue request_dict; request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey()); - bool success = status == autofill::SUCCESS; + bool success = status == SUCCESS; request_dict.SetBoolean(kSuccessKey, success); request_dict.SetString(kMerchantDomainKey, source_url.GetWithEmptyPath().spec()); @@ -438,10 +463,13 @@ void WalletClient::OnURLFetchComplete( case SAVE_ADDRESS: { std::string shipping_address_id; + std::vector<RequiredAction> required_actions; + GetRequiredActionsForSaveToWallet(*response_dict, &required_actions); if (response_dict->GetString(kShippingAddressIdKey, - &shipping_address_id)) { + &shipping_address_id) || + !required_actions.empty()) { if (observer_) - observer_->OnDidSaveAddress(shipping_address_id); + observer_->OnDidSaveAddress(shipping_address_id, required_actions); } else { HandleMalformedResponse(old_request.get()); } @@ -450,9 +478,12 @@ void WalletClient::OnURLFetchComplete( case SAVE_INSTRUMENT: { std::string instrument_id; - if (response_dict->GetString(kInstrumentIdKey, &instrument_id)) { + std::vector<RequiredAction> required_actions; + GetRequiredActionsForSaveToWallet(*response_dict, &required_actions); + if (response_dict->GetString(kInstrumentIdKey, &instrument_id) || + !required_actions.empty()) { if (observer_) - observer_->OnDidSaveInstrument(instrument_id); + observer_->OnDidSaveInstrument(instrument_id, required_actions); } else { HandleMalformedResponse(old_request.get()); } @@ -465,10 +496,15 @@ void WalletClient::OnURLFetchComplete( std::string shipping_address_id; response_dict->GetString(kShippingAddressIdKey, &shipping_address_id); - if (!instrument_id.empty() && !shipping_address_id.empty()) { + std::vector<RequiredAction> required_actions; + GetRequiredActionsForSaveToWallet(*response_dict, &required_actions); + if ((!instrument_id.empty() && !shipping_address_id.empty()) || + !required_actions.empty()) { if (observer_) { - observer_->OnDidSaveInstrumentAndAddress(instrument_id, - shipping_address_id); + observer_->OnDidSaveInstrumentAndAddress( + instrument_id, + shipping_address_id, + required_actions); } } else { HandleMalformedResponse(old_request.get()); @@ -478,10 +514,12 @@ void WalletClient::OnURLFetchComplete( case UPDATE_INSTRUMENT: { std::string instrument_id; - response_dict->GetString(kInstrumentIdKey, &instrument_id); - if (!instrument_id.empty()) { + std::vector<RequiredAction> required_actions; + GetRequiredActionsForSaveToWallet(*response_dict, &required_actions); + if (response_dict->GetString(kInstrumentIdKey, &instrument_id) || + !required_actions.empty()) { if (observer_) - observer_->OnDidUpdateInstrument(instrument_id); + observer_->OnDidUpdateInstrument(instrument_id, required_actions); } else { HandleMalformedResponse(old_request.get()); } diff --git a/chrome/browser/autofill/wallet/wallet_client_observer.h b/chrome/browser/autofill/wallet/wallet_client_observer.h index c544e3e..12cdb47 100644 --- a/chrome/browser/autofill/wallet/wallet_client_observer.h +++ b/chrome/browser/autofill/wallet/wallet_client_observer.h @@ -35,25 +35,37 @@ class WalletClientObserver { virtual void OnDidGetWalletItems(scoped_ptr<WalletItems> wallet_items) = 0; // Called when a SaveAddress request finishes successfully. |address_id| can - // be used in subsequent GetFullWallet calls. - virtual void OnDidSaveAddress(const std::string& address_id) = 0; - - // Called when a SaveInstrument request finishes sucessfully. - // |instrument_id| can be used in subsequent GetFullWallet calls. - virtual void OnDidSaveInstrument(const std::string& instrument_id) = 0; + // be used in subsequent GetFullWallet calls. |required_actions| is populated + // if there was a validation error with the data being saved. + virtual void OnDidSaveAddress( + const std::string& address_id, + const std::vector<RequiredAction>& required_actions) = 0; + + // Called when a SaveInstrument request finishes sucessfully. |instrument_id| + // can be used in subsequent GetFullWallet calls. |required_actions| is + // populated if there was a validation error with the data being saved. + virtual void OnDidSaveInstrument( + const std::string& instrument_id, + const std::vector<RequiredAction>& required_actions) = 0; // Called when a SaveInstrumentAndAddress request finishes succesfully. // |instrument_id| and |address_id| can be used in subsequent - // GetFullWallet calls. + // GetFullWallet calls. |required_actions| is populated if there was a + // validation error with the data being saved. virtual void OnDidSaveInstrumentAndAddress( const std::string& instrument_id, - const std::string& address_id) = 0; + const std::string& address_id, + const std::vector<RequiredAction>& required_actions) = 0; // Called when a SendAutocheckoutStatus request finishes successfully. virtual void OnDidSendAutocheckoutStatus() = 0; // Called when an UpdateInstrument request finishes successfully. - virtual void OnDidUpdateInstrument(const std::string& instrument_id) = 0; + // |required_actions| is populated if there was a validation error with the + // data being saved. + virtual void OnDidUpdateInstrument( + const std::string& instrument_id, + const std::vector<RequiredAction>& required_actions) = 0; // TODO(ahutter): This is going to need more arguments, probably an error // code and a message for the user. diff --git a/chrome/browser/autofill/wallet/wallet_client_unittest.cc b/chrome/browser/autofill/wallet/wallet_client_unittest.cc index 68b9687..f4f1115 100644 --- a/chrome/browser/autofill/wallet/wallet_client_unittest.cc +++ b/chrome/browser/autofill/wallet/wallet_client_unittest.cc @@ -132,6 +132,25 @@ const char kSaveAddressValidResponse[] = " \"shipping_address_id\":\"shipping_address_id\"" "}"; +const char kSaveAddressWithRequiredActionsValidResponse[] = + "{" + " \"required_action\":" + " [" + " \" \\treqUIRE_PhOnE_number \\n\\r\"," + " \"INVALID_form_field\"" + " ]" + "}"; + +const char kSaveWithInvalidRequiredActionsResponse[] = + "{" + " \"required_action\":" + " [" + " \" setup_wallet\"," + " \" \\treqUIRE_PhOnE_number \\n\\r\"," + " \"INVALID_form_field\"" + " ]" + "}"; + const char kSaveInvalidResponse[] = "{" " \"garbage\":123" @@ -142,12 +161,30 @@ const char kSaveInstrumentValidResponse[] = " \"instrument_id\":\"instrument_id\"" "}"; +const char kSaveInstrumentWithRequiredActionsValidResponse[] = + "{" + " \"required_action\":" + " [" + " \" \\treqUIRE_PhOnE_number \\n\\r\"," + " \"INVALID_form_field\"" + " ]" + "}"; + const char kSaveInstrumentAndAddressValidResponse[] = "{" " \"shipping_address_id\":\"shipping_address_id\"," " \"instrument_id\":\"instrument_id\"" "}"; +const char kSaveInstrumentAndAddressWithRequiredActionsValidResponse[] = + "{" + " \"required_action\":" + " [" + " \" \\treqUIRE_PhOnE_number \\n\\r\"," + " \"INVALID_form_field\"" + " ]" + "}"; + const char kSaveInstrumentAndAddressMissingAddressResponse[] = "{" " \"instrument_id\":\"instrument_id\"" @@ -163,6 +200,15 @@ const char kUpdateInstrumentValidResponse[] = " \"instrument_id\":\"instrument_id\"" "}"; +const char kUpdateInstrumentWithRequiredActionsValidResponse[] = + "{" + " \"required_action\":" + " [" + " \" \\treqUIRE_PhOnE_number \\n\\r\"," + " \"INVALID_form_field\"" + " ]" + "}"; + const char kUpdateInstrumentMalformedResponse[] = "{" " \"cheese\":\"monkeys\"" @@ -425,13 +471,20 @@ class MockWalletClientObserver : MOCK_METHOD0(OnDidAcceptLegalDocuments, void()); MOCK_METHOD1(OnDidAuthenticateInstrument, void(bool success)); - MOCK_METHOD1(OnDidSaveAddress, void(const std::string& address_id)); - MOCK_METHOD1(OnDidSaveInstrument, void(const std::string& instrument_id)); - MOCK_METHOD2(OnDidSaveInstrumentAndAddress, + MOCK_METHOD2(OnDidSaveAddress, + void(const std::string& address_id, + const std::vector<RequiredAction>& required_actions)); + MOCK_METHOD2(OnDidSaveInstrument, void(const std::string& instrument_id, - const std::string& shipping_address_id)); + const std::vector<RequiredAction>& required_actions)); + MOCK_METHOD3(OnDidSaveInstrumentAndAddress, + void(const std::string& instrument_id, + const std::string& shipping_address_id, + const std::vector<RequiredAction>& required_actions)); MOCK_METHOD0(OnDidSendAutocheckoutStatus, void()); - MOCK_METHOD1(OnDidUpdateInstrument, void(const std::string& instrument_id)); + MOCK_METHOD2(OnDidUpdateInstrument, + void(const std::string& instrument_id, + const std::vector<RequiredAction>& required_actions)); MOCK_METHOD0(OnWalletError, void()); MOCK_METHOD0(OnMalformedResponse, void()); MOCK_METHOD1(OnNetworkError, void(int response_code)); @@ -795,7 +848,9 @@ TEST_F(WalletClientTest, GetWalletItems) { TEST_F(WalletClientTest, SaveAddressSucceeded) { MockWalletClientObserver observer; - EXPECT_CALL(observer, OnDidSaveAddress("shipping_address_id")).Times(1); + EXPECT_CALL(observer, + OnDidSaveAddress("shipping_address_id", + std::vector<RequiredAction>())).Times(1); net::TestURLFetcherFactory factory; @@ -809,6 +864,45 @@ TEST_F(WalletClientTest, SaveAddressSucceeded) { kSaveAddressValidResponse); } +TEST_F(WalletClientTest, SaveAddressWithRequiredActionsSucceeded) { + MockWalletClientObserver observer; + + std::vector<RequiredAction> required_actions; + required_actions.push_back(REQUIRE_PHONE_NUMBER); + required_actions.push_back(INVALID_FORM_FIELD); + + EXPECT_CALL(observer, + OnDidSaveAddress(std::string(), + required_actions)).Times(1); + + net::TestURLFetcherFactory factory; + + scoped_ptr<Address> address = GetTestShippingAddress(); + + WalletClient wallet_client(profile_.GetRequestContext()); + wallet_client.SaveAddress(*address, GURL(kMerchantUrl), observer.AsWeakPtr()); + VerifyAndFinishRequest(factory, + net::HTTP_OK, + kSaveAddressValidRequest, + kSaveAddressWithRequiredActionsValidResponse); +} + +TEST_F(WalletClientTest, SaveAddressFailedInvalidRequiredAction) { + MockWalletClientObserver observer; + EXPECT_CALL(observer, OnMalformedResponse()).Times(1); + + net::TestURLFetcherFactory factory; + + scoped_ptr<Address> address = GetTestShippingAddress(); + + WalletClient wallet_client(profile_.GetRequestContext()); + wallet_client.SaveAddress(*address, GURL(kMerchantUrl), observer.AsWeakPtr()); + VerifyAndFinishRequest(factory, + net::HTTP_OK, + kSaveAddressValidRequest, + kSaveWithInvalidRequiredActionsResponse); +} + TEST_F(WalletClientTest, SaveAddressFailedMalformedResponse) { MockWalletClientObserver observer; EXPECT_CALL(observer, OnMalformedResponse()).Times(1); @@ -827,7 +921,9 @@ TEST_F(WalletClientTest, SaveAddressFailedMalformedResponse) { TEST_F(WalletClientTest, SaveInstrumentSucceeded) { MockWalletClientObserver observer; - EXPECT_CALL(observer, OnDidSaveInstrument("instrument_id")).Times(1); + EXPECT_CALL(observer, + OnDidSaveInstrument("instrument_id", + std::vector<RequiredAction>())).Times(1); net::TestURLFetcherFactory factory; @@ -851,6 +947,66 @@ TEST_F(WalletClientTest, SaveInstrumentSucceeded) { kSaveInstrumentValidResponse); } +TEST_F(WalletClientTest, SaveInstrumentWithRequiredActionsSucceeded) { + MockWalletClientObserver observer; + + std::vector<RequiredAction> required_actions; + required_actions.push_back(REQUIRE_PHONE_NUMBER); + required_actions.push_back(INVALID_FORM_FIELD); + + EXPECT_CALL(observer, + OnDidSaveInstrument(std::string(), + required_actions)).Times(1); + + net::TestURLFetcherFactory factory; + + scoped_ptr<Instrument> instrument = GetTestInstrument(); + + WalletClient wallet_client(profile_.GetRequestContext()); + wallet_client.SaveInstrument(*instrument, + "obfuscated_gaia_id", + GURL(kMerchantUrl), + observer.AsWeakPtr()); + + net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); + ASSERT_TRUE(encryption_fetcher); + encryption_fetcher->set_response_code(net::HTTP_OK); + encryption_fetcher->SetResponseString("escrow_handle"); + encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); + + VerifyAndFinishRequest(factory, + net::HTTP_OK, + kSaveInstrumentValidRequest, + kSaveInstrumentWithRequiredActionsValidResponse); +} + +TEST_F(WalletClientTest, SaveInstrumentFailedInvalidRequiredActions) { + MockWalletClientObserver observer; + + EXPECT_CALL(observer, OnMalformedResponse()); + + net::TestURLFetcherFactory factory; + + scoped_ptr<Instrument> instrument = GetTestInstrument(); + + WalletClient wallet_client(profile_.GetRequestContext()); + wallet_client.SaveInstrument(*instrument, + "obfuscated_gaia_id", + GURL(kMerchantUrl), + observer.AsWeakPtr()); + + net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); + ASSERT_TRUE(encryption_fetcher); + encryption_fetcher->set_response_code(net::HTTP_OK); + encryption_fetcher->SetResponseString("escrow_handle"); + encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); + + VerifyAndFinishRequest(factory, + net::HTTP_OK, + kSaveInstrumentValidRequest, + kSaveWithInvalidRequiredActionsResponse); +} + TEST_F(WalletClientTest, SaveInstrumentEscrowDown) { MockWalletClientObserver observer; EXPECT_CALL(observer, @@ -923,8 +1079,10 @@ TEST_F(WalletClientTest, SaveInstrumentFailedMalformedResponse) { TEST_F(WalletClientTest, SaveInstrumentAndAddressSucceeded) { MockWalletClientObserver observer; EXPECT_CALL(observer, - OnDidSaveInstrumentAndAddress("instrument_id", - "shipping_address_id")).Times(1); + OnDidSaveInstrumentAndAddress( + "instrument_id", + "shipping_address_id", + std::vector<RequiredAction>())).Times(1); net::TestURLFetcherFactory factory; @@ -950,6 +1108,73 @@ TEST_F(WalletClientTest, SaveInstrumentAndAddressSucceeded) { kSaveInstrumentAndAddressValidResponse); } +TEST_F(WalletClientTest, SaveInstrumentAndAddressWithRequiredActionsSucceeded) { + MockWalletClientObserver observer; + + std::vector<RequiredAction> required_actions; + required_actions.push_back(REQUIRE_PHONE_NUMBER); + required_actions.push_back(INVALID_FORM_FIELD); + + EXPECT_CALL(observer, + OnDidSaveInstrumentAndAddress( + std::string(), + std::string(), + required_actions)).Times(1); + + net::TestURLFetcherFactory factory; + + scoped_ptr<Instrument> instrument = GetTestInstrument(); + + scoped_ptr<Address> address = GetTestShippingAddress(); + + WalletClient wallet_client(profile_.GetRequestContext()); + wallet_client.SaveInstrumentAndAddress(*instrument, + *address, + "obfuscated_gaia_id", + GURL(kMerchantUrl), + observer.AsWeakPtr()); + + net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); + ASSERT_TRUE(encryption_fetcher); + encryption_fetcher->set_response_code(net::HTTP_OK); + encryption_fetcher->SetResponseString("escrow_handle"); + encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); + VerifyAndFinishRequest( + factory, + net::HTTP_OK, + kSaveInstrumentAndAddressValidRequest, + kSaveInstrumentAndAddressWithRequiredActionsValidResponse); +} + +TEST_F(WalletClientTest, SaveInstrumentAndAddressFailedInvalidRequiredAction) { + MockWalletClientObserver observer; + EXPECT_CALL(observer, OnMalformedResponse()).Times(1); + + net::TestURLFetcherFactory factory; + + scoped_ptr<Instrument> instrument = GetTestInstrument(); + + scoped_ptr<Address> address = GetTestShippingAddress(); + + WalletClient wallet_client(profile_.GetRequestContext()); + wallet_client.SaveInstrumentAndAddress(*instrument, + *address, + "obfuscated_gaia_id", + GURL(kMerchantUrl), + observer.AsWeakPtr()); + + net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); + ASSERT_TRUE(encryption_fetcher); + encryption_fetcher->set_response_code(net::HTTP_OK); + encryption_fetcher->SetResponseString("escrow_handle"); + encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); + + VerifyAndFinishRequest(factory, + net::HTTP_OK, + kSaveInstrumentAndAddressValidRequest, + kSaveWithInvalidRequiredActionsResponse); +} + TEST_F(WalletClientTest, SaveInstrumentAndAddressEscrowDown) { MockWalletClientObserver observer; EXPECT_CALL(observer, @@ -1059,7 +1284,9 @@ TEST_F(WalletClientTest, SaveInstrumentAndAddressFailedInstrumentMissing) { TEST_F(WalletClientTest, UpdateInstrumentSucceeded) { MockWalletClientObserver observer; - EXPECT_CALL(observer, OnDidUpdateInstrument("instrument_id")).Times(1); + EXPECT_CALL(observer, + OnDidUpdateInstrument("instrument_id", + std::vector<RequiredAction>())).Times(1); net::TestURLFetcherFactory factory; @@ -1076,6 +1303,51 @@ TEST_F(WalletClientTest, UpdateInstrumentSucceeded) { kUpdateInstrumentValidResponse); } +TEST_F(WalletClientTest, UpdateInstrumentWithRequiredActionsSucceeded) { + MockWalletClientObserver observer; + + std::vector<RequiredAction> required_actions; + required_actions.push_back(REQUIRE_PHONE_NUMBER); + required_actions.push_back(INVALID_FORM_FIELD); + + EXPECT_CALL(observer, + OnDidUpdateInstrument(std::string(), + required_actions)).Times(1); + + net::TestURLFetcherFactory factory; + + scoped_ptr<Address> address = GetTestAddress(); + + WalletClient wallet_client(profile_.GetRequestContext()); + wallet_client.UpdateInstrument("instrument_id", + *address, + GURL(kMerchantUrl), + observer.AsWeakPtr()); + VerifyAndFinishRequest(factory, + net::HTTP_OK, + kUpdateInstrumentValidRequest, + kUpdateInstrumentWithRequiredActionsValidResponse); +} + +TEST_F(WalletClientTest, UpdateInstrumentFailedInvalidRequiredAction) { + MockWalletClientObserver observer; + EXPECT_CALL(observer, OnMalformedResponse()).Times(1); + + net::TestURLFetcherFactory factory; + + scoped_ptr<Address> address = GetTestAddress(); + + WalletClient wallet_client(profile_.GetRequestContext()); + wallet_client.UpdateInstrument("instrument_id", + *address, + GURL(kMerchantUrl), + observer.AsWeakPtr()); + VerifyAndFinishRequest(factory, + net::HTTP_OK, + kUpdateInstrumentValidRequest, + kSaveWithInvalidRequiredActionsResponse); +} + TEST_F(WalletClientTest, UpdateInstrumentMalformedResponse) { MockWalletClientObserver observer; EXPECT_CALL(observer, OnMalformedResponse()).Times(1); diff --git a/chrome/browser/autofill/wallet/wallet_items_unittest.cc b/chrome/browser/autofill/wallet/wallet_items_unittest.cc index e52040b..48bc333 100644 --- a/chrome/browser/autofill/wallet/wallet_items_unittest.cc +++ b/chrome/browser/autofill/wallet/wallet_items_unittest.cc @@ -354,8 +354,8 @@ class WalletItemsTest : public testing::Test { protected: void SetUpDictionary(const std::string& json) { scoped_ptr<Value> value(base::JSONReader::Read(json)); - DCHECK(value.get()); - DCHECK(value->IsType(Value::TYPE_DICTIONARY)); + ASSERT_TRUE(value.get()); + ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY)); dict.reset(static_cast<DictionaryValue*>(value.release())); } scoped_ptr<DictionaryValue> dict; @@ -363,37 +363,37 @@ class WalletItemsTest : public testing::Test { TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingStatus) { SetUpDictionary(kMaskedInstrumentMissingStatus); - ASSERT_EQ(NULL, + EXPECT_EQ(NULL, WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get()); } TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingType) { SetUpDictionary(kMaskedInstrumentMissingType); - ASSERT_EQ(NULL, + EXPECT_EQ(NULL, WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get()); } TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingLastFourDigits) { SetUpDictionary(kMaskedInstrumentMissingLastFourDigits); - ASSERT_EQ(NULL, + EXPECT_EQ(NULL, WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get()); } TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingAddress) { SetUpDictionary(kMaskedInstrumentMissingAddress); - ASSERT_EQ(NULL, + EXPECT_EQ(NULL, WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get()); } TEST_F(WalletItemsTest, CreateMaskedInstrumentMalformedAddress) { SetUpDictionary(kMaskedInstrumentMalformedAddress); - ASSERT_EQ(NULL, + EXPECT_EQ(NULL, WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get()); } TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingObjectId) { SetUpDictionary(kMaskedInstrumentMissingObjectId); - ASSERT_EQ(NULL, + EXPECT_EQ(NULL, WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get()); } @@ -420,24 +420,24 @@ TEST_F(WalletItemsTest, CreateMaskedInstrument) { address.Pass(), WalletItems::MaskedInstrument::VALID, "object_id"); - ASSERT_EQ(masked_instrument, + EXPECT_EQ(masked_instrument, *WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict)); } TEST_F(WalletItemsTest, CreateLegalDocumentMissingDocId) { SetUpDictionary(kLegalDocumentMissingDocumentId); - ASSERT_EQ(NULL, WalletItems::LegalDocument::CreateLegalDocument(*dict).get()); + EXPECT_EQ(NULL, WalletItems::LegalDocument::CreateLegalDocument(*dict).get()); } TEST_F(WalletItemsTest, CreateLegalDocumentMissingDisplayName) { SetUpDictionary(kLegalDocumentMissingDisplayName); - ASSERT_EQ(NULL, WalletItems::LegalDocument::CreateLegalDocument(*dict).get()); + EXPECT_EQ(NULL, WalletItems::LegalDocument::CreateLegalDocument(*dict).get()); } TEST_F(WalletItemsTest, CreateLegalDocument) { SetUpDictionary(kLegalDocument); WalletItems::LegalDocument expected("doc_id", "display_name"); - ASSERT_EQ(expected, + EXPECT_EQ(expected, *WalletItems::LegalDocument::CreateLegalDocument(*dict)); } @@ -463,26 +463,26 @@ TEST_F(WalletItemsTest, CreateWalletItemsWithRequiredActions) { std::string(), std::string(), std::string()); - ASSERT_EQ(expected, *WalletItems::CreateWalletItems(*dict)); + EXPECT_EQ(expected, *WalletItems::CreateWalletItems(*dict)); - DCHECK(!required_actions.empty()); + ASSERT_FALSE(required_actions.empty()); required_actions.pop_back(); WalletItems different_required_actions(required_actions, std::string(), std::string(), std::string(), std::string()); - ASSERT_NE(expected, different_required_actions); + EXPECT_NE(expected, different_required_actions); } TEST_F(WalletItemsTest, CreateWalletItemsWithInvalidRequiredActions) { SetUpDictionary(kWalletItemsWithInvalidRequiredActions); - ASSERT_EQ(NULL, WalletItems::CreateWalletItems(*dict).get()); + EXPECT_EQ(NULL, WalletItems::CreateWalletItems(*dict).get()); } TEST_F(WalletItemsTest, CreateWalletItemsMissingGoogleTransactionId) { SetUpDictionary(kWalletItemsMissingGoogleTransactionId); - ASSERT_EQ(NULL, WalletItems::CreateWalletItems(*dict).get()); + EXPECT_EQ(NULL, WalletItems::CreateWalletItems(*dict).get()); } TEST_F(WalletItemsTest, CreateWalletItems) { @@ -533,7 +533,7 @@ TEST_F(WalletItemsTest, CreateWalletItems) { "display_name")); expected.AddLegalDocument(legal_document.Pass()); - ASSERT_EQ(expected, *WalletItems::CreateWalletItems(*dict)); + EXPECT_EQ(expected, *WalletItems::CreateWalletItems(*dict)); } } // namespace wallet diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc index 81330eb..393b03f 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc @@ -954,21 +954,28 @@ void AutofillDialogControllerImpl::OnDidGetWalletItems( } void AutofillDialogControllerImpl::OnDidSaveAddress( - const std::string& address_id) { - NOTIMPLEMENTED() << " address_id=" << address_id; + const std::string& address_id, + const std::vector<wallet::RequiredAction>& required_actions) { + NOTIMPLEMENTED() << " address_id=" << address_id + << ", required_actions=" << !required_actions.empty(); WalletRequestCompleted(true); } void AutofillDialogControllerImpl::OnDidSaveInstrument( - const std::string& instrument_id) { - NOTIMPLEMENTED() << " instrument_id=" << instrument_id; + const std::string& instrument_id, + const std::vector<wallet::RequiredAction>& required_actions) { + NOTIMPLEMENTED() << " instrument_id=" << instrument_id + << ", required_actions=" << !required_actions.empty(); WalletRequestCompleted(true); } void AutofillDialogControllerImpl::OnDidSaveInstrumentAndAddress( - const std::string& instrument_id, const std::string& address_id) { + const std::string& instrument_id, + const std::string& address_id, + const std::vector<wallet::RequiredAction>& required_actions) { NOTIMPLEMENTED() << " instrument_id=" << instrument_id - << ", address_id=" << address_id; + << ", address_id=" << address_id + << ", required_actions=" << !required_actions.empty(); WalletRequestCompleted(true); } @@ -978,8 +985,10 @@ void AutofillDialogControllerImpl::OnDidSendAutocheckoutStatus() { } void AutofillDialogControllerImpl::OnDidUpdateInstrument( - const std::string& instrument_id) { - NOTIMPLEMENTED() << " instrument_id=" << instrument_id; + const std::string& instrument_id, + const std::vector<wallet::RequiredAction>& required_actions) { + NOTIMPLEMENTED() << " instrument_id=" << instrument_id + << ", required_actions=" << !required_actions.empty(); } void AutofillDialogControllerImpl::OnWalletError() { diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h index 94a013b..ec75243 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h @@ -150,13 +150,20 @@ class AutofillDialogControllerImpl : public AutofillDialogController, scoped_ptr<wallet::FullWallet> full_wallet) OVERRIDE; virtual void OnDidGetWalletItems( scoped_ptr<wallet::WalletItems> wallet_items) OVERRIDE; - virtual void OnDidSaveAddress(const std::string& address_id) OVERRIDE; - virtual void OnDidSaveInstrument(const std::string& instrument_id) OVERRIDE; + virtual void OnDidSaveAddress( + const std::string& address_id, + const std::vector<wallet::RequiredAction>& required_actions) OVERRIDE; + virtual void OnDidSaveInstrument( + const std::string& instrument_id, + const std::vector<wallet::RequiredAction>& required_actions) OVERRIDE; virtual void OnDidSaveInstrumentAndAddress( const std::string& instrument_id, - const std::string& address_id) OVERRIDE; + const std::string& address_id, + const std::vector<wallet::RequiredAction>& required_actions) OVERRIDE; virtual void OnDidSendAutocheckoutStatus() OVERRIDE; - virtual void OnDidUpdateInstrument(const std::string& instrument_id) OVERRIDE; + virtual void OnDidUpdateInstrument( + const std::string& instrument_id, + const std::vector<wallet::RequiredAction>& required_actions) OVERRIDE; virtual void OnWalletError() OVERRIDE; virtual void OnMalformedResponse() OVERRIDE; virtual void OnNetworkError(int response_code) OVERRIDE; |