diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-08 06:49:40 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-08 06:49:40 +0000 |
commit | b4f7ebaa3b1e36b1c1be4da7ebf3e1707b386df2 (patch) | |
tree | 61638275d1efe134dd4b97b33931bb86b9b23ec7 | |
parent | ae4f1625a8a4d8ea9bde7f4a107d60814b12e593 (diff) | |
download | chromium_src-b4f7ebaa3b1e36b1c1be4da7ebf3e1707b386df2.zip chromium_src-b4f7ebaa3b1e36b1c1be4da7ebf3e1707b386df2.tar.gz chromium_src-b4f7ebaa3b1e36b1c1be4da7ebf3e1707b386df2.tar.bz2 |
rAc: Pay attention to more of gaia account struct in WalletItems response
BUG=323328
Review URL: https://codereview.chromium.org/90433002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239378 0039d316-1c4b-4281-b951-d872f2087c98
10 files changed, 283 insertions, 136 deletions
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc index fe29bbe..0d70405 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc @@ -47,6 +47,7 @@ #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" #include "components/autofill/content/browser/wallet/form_field_error.h" #include "components/autofill/content/browser/wallet/full_wallet.h" +#include "components/autofill/content/browser/wallet/gaia_account.h" #include "components/autofill/content/browser/wallet/instrument.h" #include "components/autofill/content/browser/wallet/wallet_address.h" #include "components/autofill/content/browser/wallet/wallet_items.h" @@ -2353,16 +2354,18 @@ void AutofillDialogControllerImpl::OnDidGetWalletItems( wallet_items_ = wallet_items.Pass(); - if (wallet_items_) { + if (wallet_items_ && !wallet_items_->ObfuscatedGaiaId().empty()) { // Making sure the user index is in sync shouldn't be necessary, but is an // extra precaution. But if there is no active account (such as in the // PASSIVE_AUTH case), stick with the old active account. - if (!wallet_items_->obfuscated_gaia_id().empty()) - GetWalletClient()->set_user_index(wallet_items_->active_account_index()); + GetWalletClient()->set_user_index(wallet_items_->active_account_index()); + std::vector<std::string> usernames; + for (size_t i = 0; i < wallet_items_->gaia_accounts().size(); ++i) { + usernames.push_back(wallet_items_->gaia_accounts()[i]->email_address()); + } account_chooser_model_.SetWalletAccounts( - wallet_items_->gaia_accounts(), - wallet_items_->active_account_index()); + usernames, wallet_items_->active_account_index()); } ConstructLegalDocumentsText(); @@ -2580,7 +2583,7 @@ void AutofillDialogControllerImpl::LoadRiskFingerprintData() { risk_data_.clear(); uint64 obfuscated_gaia_id = 0; - bool success = base::StringToUint64(wallet_items_->obfuscated_gaia_id(), + bool success = base::StringToUint64(wallet_items_->ObfuscatedGaiaId(), &obfuscated_gaia_id); DCHECK(success); diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc index 70fb6fc..c0f938c 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc @@ -29,6 +29,7 @@ #include "chrome/test/base/testing_profile.h" #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" #include "components/autofill/content/browser/wallet/full_wallet.h" +#include "components/autofill/content/browser/wallet/gaia_account.h" #include "components/autofill/content/browser/wallet/instrument.h" #include "components/autofill/content/browser/wallet/mock_wallet_client.h" #include "components/autofill/content/browser/wallet/wallet_address.h" @@ -57,7 +58,7 @@ namespace { using testing::_; -const char kFakeEmail[] = "user@example.com"; +const char kFakeEmail[] = "user@chromium.org"; const char kFakeFingerprintEncoded[] = "CgVaAwiACA=="; const char kEditedBillingAddress[] = "123 edited billing address"; const char* kFieldsFromPage[] = @@ -102,6 +103,7 @@ void CopyInitialValues(const DetailInputs& inputs, FieldValueMap* outputs) { scoped_ptr<wallet::WalletItems> CompleteAndValidWalletItems() { scoped_ptr<wallet::WalletItems> items = wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); + items->AddAccount(wallet::GetTestGaiaAccount()); items->AddInstrument(wallet::GetTestMaskedInstrument()); items->AddAddress(wallet::GetTestShippingAddress()); return items.Pass(); diff --git a/components/autofill.gypi b/components/autofill.gypi index ab53ca1..87660f7 100644 --- a/components/autofill.gypi +++ b/components/autofill.gypi @@ -317,6 +317,8 @@ 'autofill/content/browser/wallet/form_field_error.h', 'autofill/content/browser/wallet/full_wallet.cc', 'autofill/content/browser/wallet/full_wallet.h', + 'autofill/content/browser/wallet/gaia_account.cc', + 'autofill/content/browser/wallet/gaia_account.h', 'autofill/content/browser/wallet/instrument.cc', 'autofill/content/browser/wallet/instrument.h', 'autofill/content/browser/wallet/required_action.cc', diff --git a/components/autofill/content/browser/wallet/gaia_account.cc b/components/autofill/content/browser/wallet/gaia_account.cc new file mode 100644 index 0000000..23323ce --- /dev/null +++ b/components/autofill/content/browser/wallet/gaia_account.cc @@ -0,0 +1,85 @@ +// Copyright 2013 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/content/browser/wallet/gaia_account.h" + +#include "base/logging.h" +#include "base/values.h" + +namespace autofill { + +namespace wallet { + +GaiaAccount::~GaiaAccount() {} + +// static +scoped_ptr<GaiaAccount> GaiaAccount::Create( + const base::DictionaryValue& dictionary) { + std::string email_address; + if (!dictionary.GetString("buyer_email", &email_address)) { + DLOG(ERROR) << "GAIA account: missing email address"; + return scoped_ptr<GaiaAccount>(); + } + + std::string obfuscated_id; + if (!dictionary.GetString("gaia_id", &obfuscated_id)) { + DLOG(ERROR) << "GAIA account: missing GAIA id"; + return scoped_ptr<GaiaAccount>(); + } + + int index = 0; + if (!dictionary.GetInteger("gaia_index", &index) || + index < 0) { + DLOG(ERROR) << "GAIA account: missing or bad GAIA index"; + return scoped_ptr<GaiaAccount>(); + } + + bool is_active = false; + if (!dictionary.GetBoolean("is_active", &is_active)) { + DLOG(ERROR) << "GAIA account: missing is_active"; + return scoped_ptr<GaiaAccount>(); + } + + return scoped_ptr<GaiaAccount>(new GaiaAccount(email_address, + obfuscated_id, + index, + is_active)); +} + +// static +scoped_ptr<GaiaAccount> GaiaAccount::CreateForTesting( + const std::string& email_address, + const std::string& obfuscated_id, + size_t index, + bool is_active) { + scoped_ptr<GaiaAccount> account(new GaiaAccount(email_address, + obfuscated_id, + index, + is_active)); + return account.Pass(); +} + +bool GaiaAccount::operator==(const GaiaAccount& other) const { + return email_address_ == other.email_address_ && + obfuscated_id_ == other.obfuscated_id_ && + index_ == other.index_ && + is_active_ == other.is_active_; +} + +bool GaiaAccount::operator!=(const GaiaAccount& other) const { + return !(*this == other); +} + +GaiaAccount::GaiaAccount(const std::string& email_address, + const std::string& obfuscated_id, + size_t index, + bool is_active) + : email_address_(email_address), + obfuscated_id_(obfuscated_id), + index_(index), + is_active_(is_active) {} + +} // namespace wallet + +} // namespace autofill diff --git a/components/autofill/content/browser/wallet/gaia_account.h b/components/autofill/content/browser/wallet/gaia_account.h new file mode 100644 index 0000000..2eb6e2e --- /dev/null +++ b/components/autofill/content/browser/wallet/gaia_account.h @@ -0,0 +1,59 @@ +// Copyright 2013 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_CONTENT_BROWSER_WALLET_GAIA_ACCOUNTS_H_ +#define COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_GAIA_ACCOUNTS_H_ + +#include <string> + +#include "base/memory/scoped_ptr.h" + +namespace base { +class DictionaryValue; +} + +namespace autofill { +namespace wallet { + +class GaiaAccount { + public: + ~GaiaAccount(); + + // Returns an empty scoped_ptr if input is invalid, otherwise a valid GAIA + // account. + static scoped_ptr<GaiaAccount> Create( + const base::DictionaryValue& dictionary); + + static scoped_ptr<GaiaAccount> CreateForTesting( + const std::string& email_address, + const std::string& obfuscated_id, + size_t index, + bool is_active); + + bool operator==(const GaiaAccount& other) const; + bool operator!=(const GaiaAccount& other) const; + + const std::string& email_address() const { return email_address_; } + const std::string& obfuscated_id() const { return obfuscated_id_; } + size_t index() const { return index_; } + bool is_active() const { return is_active_; } + + private: + GaiaAccount(const std::string& email_address, + const std::string& obfuscated_id, + size_t index, + bool is_active); + + std::string email_address_; + std::string obfuscated_id_; + size_t index_; + bool is_active_; + + DISALLOW_COPY_AND_ASSIGN(GaiaAccount); +}; + +} // namespace wallet +} // namespace autofill + +#endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_GAIA_ACCOUNTS_H_ diff --git a/components/autofill/content/browser/wallet/wallet_items.cc b/components/autofill/content/browser/wallet/wallet_items.cc index 84e2ec8..f947266 100644 --- a/components/autofill/content/browser/wallet/wallet_items.cc +++ b/components/autofill/content/browser/wallet/wallet_items.cc @@ -8,6 +8,7 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" +#include "components/autofill/content/browser/wallet/gaia_account.h" #include "components/autofill/core/browser/autofill_type.h" #include "components/autofill/core/browser/credit_card.h" #include "grit/component_strings.h" @@ -116,7 +117,7 @@ WalletItems::MaskedInstrument::MaskedInstrument( address_(address.Pass()), status_(status), object_id_(object_id) { - DCHECK(address_.get()); + DCHECK(address_); } WalletItems::MaskedInstrument::~MaskedInstrument() {} @@ -161,7 +162,7 @@ scoped_ptr<WalletItems::MaskedInstrument> } scoped_ptr<Address> address = Address::CreateDisplayAddress(*address_dict); - if (!address.get()) { + if (!address) { DLOG(ERROR) << "Response from Google wallet contained malformed address"; return scoped_ptr<MaskedInstrument>(); } @@ -215,14 +216,14 @@ bool WalletItems::MaskedInstrument::operator==( return false; if (expiration_year_ != other.expiration_year_) return false; - if (address_.get()) { - if (other.address_.get()) { - if (*address_.get() != *other.address_.get()) + if (address_) { + if (other.address_) { + if (*address_ != *other.address_) return false; } else { return false; } - } else if (other.address_.get()) { + } else if (other.address_) { return false; } if (status_ != other.status_) @@ -281,6 +282,13 @@ bool WalletItems::SupportsCard(const base::string16& card_number, return false; } +std::string WalletItems::ObfuscatedGaiaId() const { + if (active_account_index_ >= gaia_accounts_.size()) + return std::string(); + + return gaia_accounts_[active_account_index_]->obfuscated_id(); +} + base::string16 WalletItems::MaskedInstrument::DisplayName() const { #if defined(OS_ANDROID) // TODO(aruslan): improve this stub implementation. @@ -416,18 +424,13 @@ WalletItems::WalletItems(const std::vector<RequiredAction>& required_actions, const std::string& google_transaction_id, const std::string& default_instrument_id, const std::string& default_address_id, - const std::string& obfuscated_gaia_id, - size_t active_account_index, - AmexPermission amex_permission, - const std::vector<std::string>& gaia_accounts) + AmexPermission amex_permission) : required_actions_(required_actions), google_transaction_id_(google_transaction_id), default_instrument_id_(default_instrument_id), default_address_id_(default_address_id), - obfuscated_gaia_id_(obfuscated_gaia_id), - active_account_index_(active_account_index), - amex_permission_(amex_permission), - gaia_accounts_(gaia_accounts) {} + active_account_index_(std::numeric_limits<size_t>::max()), + amex_permission_(amex_permission) {} WalletItems::~WalletItems() {} @@ -467,9 +470,7 @@ scoped_ptr<WalletItems> if (!dictionary.GetString("default_address_id", &default_address_id)) DVLOG(1) << "Response from Google wallet missing default_address_id"; - std::string obfuscated_gaia_id; - if (!dictionary.GetString("obfuscated_gaia_id", &obfuscated_gaia_id)) - DVLOG(1) << "Response from Google wallet missing obfuscated gaia id"; + // obfuscated_gaia_id is deprecated. bool amex_disallowed = true; if (!dictionary.GetBoolean("amex_disallowed", &amex_disallowed)) @@ -477,39 +478,29 @@ scoped_ptr<WalletItems> AmexPermission amex_permission = amex_disallowed ? AMEX_DISALLOWED : AMEX_ALLOWED; - size_t active_account_index = 0; + scoped_ptr<WalletItems> wallet_items(new WalletItems(required_action, + google_transaction_id, + default_instrument_id, + default_address_id, + amex_permission)); std::vector<std::string> gaia_accounts; const base::ListValue* gaia_profiles; if (dictionary.GetList("gaia_profile", &gaia_profiles)) { for (size_t i = 0; i < gaia_profiles->GetSize(); ++i) { const base::DictionaryValue* account_dict; std::string email; - if (gaia_profiles->GetDictionary(i, &account_dict) && - account_dict->GetString("buyer_email", &email)) { - gaia_accounts.push_back(email); - - std::string gaia_id; - if (account_dict->GetString("gaia_id", &gaia_id) && - gaia_id == obfuscated_gaia_id) { - active_account_index = i; - } - } else { - DVLOG(1) << "Response from Google Wallet has malformed GAIA profile."; - } + if (!gaia_profiles->GetDictionary(i, &account_dict)) + continue; + + scoped_ptr<GaiaAccount> gaia_account( + GaiaAccount::Create(*account_dict)); + if (gaia_account) + wallet_items->AddAccount(gaia_account.Pass()); } } else { - DVLOG(1) << "Response from Google wallet missing GAIA profiles."; + DVLOG(1) << "Response from Google wallet missing GAIA accounts"; } - scoped_ptr<WalletItems> wallet_items(new WalletItems(required_action, - google_transaction_id, - default_instrument_id, - default_address_id, - obfuscated_gaia_id, - active_account_index, - amex_permission, - gaia_accounts)); - const ListValue* legal_docs; if (dictionary.GetList("required_legal_document", &legal_docs)) { for (size_t i = 0; i < legal_docs->GetSize(); ++i) { @@ -517,13 +508,10 @@ scoped_ptr<WalletItems> if (legal_docs->GetDictionary(i, &legal_doc_dict)) { scoped_ptr<LegalDocument> legal_doc( LegalDocument::CreateLegalDocument(*legal_doc_dict)); - if (legal_doc.get()) { + if (legal_doc) wallet_items->AddLegalDocument(legal_doc.Pass()); - } else { - DLOG(ERROR) << "Malformed legal document in response from " - "Google wallet"; + else return scoped_ptr<WalletItems>(); - } } } @@ -543,10 +531,8 @@ scoped_ptr<WalletItems> if (instruments->GetDictionary(i, &instrument_dict)) { scoped_ptr<MaskedInstrument> instrument( MaskedInstrument::CreateMaskedInstrument(*instrument_dict)); - if (instrument.get()) + if (instrument) wallet_items->AddInstrument(instrument.Pass()); - else - DLOG(ERROR) << "Malformed instrument in response from Google Wallet"; } } } else { @@ -560,10 +546,8 @@ scoped_ptr<WalletItems> if (addresses->GetDictionary(i, &address_dict)) { scoped_ptr<Address> address( Address::CreateAddressWithID(*address_dict)); - if (address.get()) + if (address) wallet_items->AddAddress(address.Pass()); - else - DLOG(ERROR) << "Malformed address in response from Google Wallet"; } } } else { @@ -573,21 +557,33 @@ scoped_ptr<WalletItems> return wallet_items.Pass(); } +void WalletItems::AddAccount(scoped_ptr<GaiaAccount> account) { + if (account->index() != gaia_accounts_.size()) { + DVLOG(1) << "Tried to add account out of order"; + return; + } + + if (account->is_active()) + active_account_index_ = account->index(); + + gaia_accounts_.push_back(account.release()); +} + bool WalletItems::operator==(const WalletItems& other) const { return google_transaction_id_ == other.google_transaction_id_ && default_instrument_id_ == other.default_instrument_id_ && default_address_id_ == other.default_address_id_ && required_actions_ == other.required_actions_ && - obfuscated_gaia_id_ == other.obfuscated_gaia_id_ && + // This check is technically redundant, but is useful for tests. + ObfuscatedGaiaId() == other.ObfuscatedGaiaId() && active_account_index() == other.active_account_index() && + VectorsAreEqual<GaiaAccount>(gaia_accounts(), + other.gaia_accounts()) && VectorsAreEqual<MaskedInstrument>(instruments(), other.instruments()) && VectorsAreEqual<Address>(addresses(), other.addresses()) && VectorsAreEqual<LegalDocument>(legal_documents(), - other.legal_documents()) && - gaia_accounts().size() == other.gaia_accounts().size() && - std::equal(gaia_accounts().begin(), gaia_accounts().end(), - other.gaia_accounts().begin()); + other.legal_documents()); } bool WalletItems::operator!=(const WalletItems& other) const { diff --git a/components/autofill/content/browser/wallet/wallet_items.h b/components/autofill/content/browser/wallet/wallet_items.h index eb3d526..3717088 100644 --- a/components/autofill/content/browser/wallet/wallet_items.h +++ b/components/autofill/content/browser/wallet/wallet_items.h @@ -36,6 +36,7 @@ FORWARD_DECLARE_TEST(WalletInstrumentWrapperTest, namespace wallet { +class GaiaAccount; class WalletItemsTest; enum AmexPermission { @@ -219,16 +220,17 @@ class WalletItems { bool operator==(const WalletItems& other) const; bool operator!=(const WalletItems& other) const; + void AddAccount(scoped_ptr<GaiaAccount> account); void AddInstrument(scoped_ptr<MaskedInstrument> instrument) { - DCHECK(instrument.get()); + DCHECK(instrument); instruments_.push_back(instrument.release()); } void AddAddress(scoped_ptr<Address> address) { - DCHECK(address.get()); + DCHECK(address); addresses_.push_back(address.release()); } void AddLegalDocument(scoped_ptr<LegalDocument> legal_document) { - DCHECK(legal_document.get()); + DCHECK(legal_document); legal_documents_.push_back(legal_document.release()); } @@ -244,6 +246,9 @@ class WalletItems { bool SupportsCard(const base::string16& card_number, base::string16* message) const; + const std::vector<GaiaAccount*>& gaia_accounts() const { + return gaia_accounts_.get(); + } const std::vector<RequiredAction>& required_actions() const { return required_actions_; } @@ -258,11 +263,10 @@ class WalletItems { } const std::vector<Address*>& addresses() const { return addresses_.get(); } const std::string& default_address_id() const { return default_address_id_; } - const std::string& obfuscated_gaia_id() const { return obfuscated_gaia_id_; } + // Returns the GAIA id of the active account, or an empty string if no account + // is active. + std::string ObfuscatedGaiaId() const; size_t active_account_index() const { return active_account_index_; } - const std::vector<std::string>& gaia_accounts() const { - return gaia_accounts_; - } const std::vector<LegalDocument*>& legal_documents() const { return legal_documents_.get(); } @@ -273,9 +277,7 @@ class WalletItems { const std::vector<RequiredAction>&, const std::string&, const std::string&, - AmexPermission, - const std::vector<std::string>&, - size_t); + AmexPermission); friend scoped_ptr<WalletItems> GetTestWalletItemsWithDefaultIds( RequiredAction action); FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems); @@ -286,10 +288,7 @@ class WalletItems { const std::string& google_transaction_id, const std::string& default_instrument_id, const std::string& default_address_id, - const std::string& obfuscated_gaia_id, - size_t active_account_index, - AmexPermission amex_permission, - const std::vector<std::string>& gaia_accounts); + AmexPermission amex_permission); // Actions that must be completed by the user before a FullWallet can be // issued to them by the Online Wallet service. @@ -304,14 +303,13 @@ class WalletItems { // The id of the user's default address. std::string default_address_id_; - // The externalized Gaia id of the user. TODO(estade): we can remove this - // if |gaia_accounts_| is made to hold more metadata about the accounts. - std::string obfuscated_gaia_id_; - // The index into |gaia_accounts_| of the account for which this object // holds data. size_t active_account_index_; + // The complete set of logged in GAIA accounts. + ScopedVector<GaiaAccount> gaia_accounts_; + // The user's backing instruments. ScopedVector<MaskedInstrument> instruments_; @@ -324,11 +322,6 @@ class WalletItems { // Whether Google Wallet allows American Express card for this merchant. AmexPermission amex_permission_; - // The complete set of logged in GAIA accounts. This just stores email - // addresses. The actual response has more metadata which we currently - // ignore. - std::vector<std::string> gaia_accounts_; - DISALLOW_COPY_AND_ASSIGN(WalletItems); }; diff --git a/components/autofill/content/browser/wallet/wallet_items_unittest.cc b/components/autofill/content/browser/wallet/wallet_items_unittest.cc index 7002630..02217be 100644 --- a/components/autofill/content/browser/wallet/wallet_items_unittest.cc +++ b/components/autofill/content/browser/wallet/wallet_items_unittest.cc @@ -7,6 +7,7 @@ #include "base/memory/scoped_ptr.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" +#include "components/autofill/content/browser/wallet/gaia_account.h" #include "components/autofill/content/browser/wallet/required_action.h" #include "components/autofill/content/browser/wallet/wallet_items.h" #include "testing/gtest/include/gtest/gtest.h" @@ -199,7 +200,6 @@ const char kLegalDocumentMissingDisplayName[] = const char kWalletItemsWithRequiredActions[] = "{" - " \"obfuscated_gaia_id\":\"\"," " \"required_action\":" " [" " \" setup_wallet\"," @@ -215,7 +215,6 @@ const char kWalletItemsWithRequiredActions[] = const char kWalletItemsWithInvalidRequiredActions[] = "{" - " \"obfuscated_gaia_id\":\"\"," " \"required_action\":" " [" " \"verify_CVV\"," @@ -278,7 +277,6 @@ const char kWalletItemsMissingGoogleTransactionId[] = " }" " ]," " \"default_address_id\":\"default_address_id\"," - " \"obfuscated_gaia_id\":\"obfuscated_gaia_id\"," " \"amex_disallowed\":true," " \"required_legal_document\":" " [" @@ -345,7 +343,7 @@ const char kWalletItems[] = " }" " ]," " \"default_address_id\":\"default_address_id\"," - " \"obfuscated_gaia_id\":\"obfuscated_gaia_id\"," + " \"obfuscated_gaia_id\":\"ignore_this_value\"," " \"amex_disallowed\":true," " \"gaia_profile\":" " [" @@ -512,10 +510,7 @@ TEST_F(WalletItemsTest, CreateWalletItemsWithRequiredActions) { std::string(), std::string(), std::string(), - std::string(), - 0, - AMEX_DISALLOWED, - std::vector<std::string>()); + AMEX_DISALLOWED); EXPECT_EQ(expected, *WalletItems::CreateWalletItems(*dict)); ASSERT_FALSE(required_actions.empty()); @@ -524,10 +519,7 @@ TEST_F(WalletItemsTest, CreateWalletItemsWithRequiredActions) { std::string(), std::string(), std::string(), - std::string(), - 0, - AMEX_DISALLOWED, - std::vector<std::string>()); + AMEX_DISALLOWED); EXPECT_NE(expected, different_required_actions); } @@ -554,17 +546,25 @@ TEST_F(WalletItemsTest, CreateWalletItemsMissingAmexDisallowed) { TEST_F(WalletItemsTest, CreateWalletItems) { SetUpDictionary(std::string(kWalletItems) + std::string(kCloseJson)); std::vector<RequiredAction> required_actions; - std::vector<std::string> users; - users.push_back("user@chromium.org"); - users.push_back("user2@chromium.org"); WalletItems expected(required_actions, "google_transaction_id", "default_instrument_id", "default_address_id", - "obfuscated_gaia_id", - 1, - AMEX_DISALLOWED, - users); + AMEX_DISALLOWED); + + scoped_ptr<GaiaAccount> user1(GaiaAccount::CreateForTesting( + "user@chromium.org", + "123456789", + 0, + true)); + expected.AddAccount(user1.Pass()); + scoped_ptr<GaiaAccount> user2(GaiaAccount::CreateForTesting( + "user2@chromium.org", + "obfuscated_gaia_id", + 1, + false)); + expected.AddAccount(user2.Pass()); + EXPECT_EQ("123456789", expected.ObfuscatedGaiaId()); scoped_ptr<Address> billing_address(new Address("US", ASCIIToUTF16("name"), diff --git a/components/autofill/content/browser/wallet/wallet_test_util.cc b/components/autofill/content/browser/wallet/wallet_test_util.cc index 13d0622..e33a72a 100644 --- a/components/autofill/content/browser/wallet/wallet_test_util.cc +++ b/components/autofill/content/browser/wallet/wallet_test_util.cc @@ -12,6 +12,7 @@ #include "base/strings/utf_string_conversions.h" #include "base/values.h" #include "components/autofill/content/browser/wallet/full_wallet.h" +#include "components/autofill/content/browser/wallet/gaia_account.h" #include "components/autofill/content/browser/wallet/instrument.h" #include "components/autofill/content/browser/wallet/required_action.h" #include "components/autofill/content/browser/wallet/wallet_address.h" @@ -64,6 +65,11 @@ GetTestMaskedInstrumentWithIdAndAddress( WalletItems::MaskedInstrument::VALID); } +scoped_ptr<GaiaAccount> GetTestGaiaAccount() { + return scoped_ptr<GaiaAccount>(GaiaAccount::CreateForTesting( + "user@chromium.org", "obfuscated_id", 0, true)); +} + scoped_ptr<Address> GetTestAddress() { return scoped_ptr<Address>(new Address("US", ASCIIToUTF16("recipient_name"), @@ -235,33 +241,28 @@ scoped_ptr<WalletItems> GetTestWalletItems( const std::vector<RequiredAction>& required_actions, const std::string& default_instrument_id, const std::string& default_address_id, - AmexPermission amex_permission, - const std::vector<std::string>& users, - size_t user_index) { + AmexPermission amex_permission) { return scoped_ptr<WalletItems>( new wallet::WalletItems(required_actions, "google_transaction_id", default_instrument_id, default_address_id, - "obfuscated_gaia_id", - user_index, - amex_permission, - users)); + amex_permission)); } scoped_ptr<WalletItems> GetTestWalletItemsWithRequiredAction( RequiredAction action) { std::vector<RequiredAction> required_actions(1, action); - std::vector<std::string> users; + scoped_ptr<WalletItems> items = + GetTestWalletItems(required_actions, + "default_instrument_id", + "default_address_id", + AMEX_ALLOWED); + if (action != GAIA_AUTH) - users.push_back("user@example.com"); - - return GetTestWalletItems(required_actions, - "default_instrument_id", - "default_address_id", - AMEX_ALLOWED, - users, - 0); + items->AddAccount(GetTestGaiaAccount()); + + return items.Pass(); } scoped_ptr<WalletItems> GetTestWalletItems(AmexPermission amex_permission) { @@ -270,28 +271,32 @@ scoped_ptr<WalletItems> GetTestWalletItems(AmexPermission amex_permission) { amex_permission); } - scoped_ptr<WalletItems> GetTestWalletItemsWithUsers( - const std::vector<std::string>& users, size_t user_index) { - return GetTestWalletItems(std::vector<RequiredAction>(), - "default_instrument_id", - "default_address_id", - AMEX_ALLOWED, - users, - user_index); + const std::vector<std::string>& users, size_t active_index) { + scoped_ptr<WalletItems> items = + GetTestWalletItems(std::vector<RequiredAction>(), + "default_instrument_id", + "default_address_id", + AMEX_ALLOWED); + for (size_t i = 0; i < users.size(); ++i) { + scoped_ptr<GaiaAccount> account(GaiaAccount::CreateForTesting( + users[i], "obfuscated_id", i, i == active_index)); + items->AddAccount(account.Pass()); + } + return items.Pass(); } scoped_ptr<WalletItems> GetTestWalletItemsWithDefaultIds( const std::string& default_instrument_id, const std::string& default_address_id, AmexPermission amex_permission) { - std::vector<std::string> users(1, "user@example.com"); - return GetTestWalletItems(std::vector<RequiredAction>(), - default_instrument_id, - default_address_id, - amex_permission, - users, - 0); + scoped_ptr<WalletItems> items = + GetTestWalletItems(std::vector<RequiredAction>(), + default_instrument_id, + default_address_id, + amex_permission); + items->AddAccount(GetTestGaiaAccount()); + return items.Pass(); } } // namespace wallet diff --git a/components/autofill/content/browser/wallet/wallet_test_util.h b/components/autofill/content/browser/wallet/wallet_test_util.h index 12ca6b5..934bd1c 100644 --- a/components/autofill/content/browser/wallet/wallet_test_util.h +++ b/components/autofill/content/browser/wallet/wallet_test_util.h @@ -15,8 +15,10 @@ namespace wallet { class Address; class FullWallet; +class GaiaAccount; class Instrument; +scoped_ptr<GaiaAccount> GetTestGaiaAccount(); scoped_ptr<Address> GetTestAddress(); scoped_ptr<Address> GetTestMinimalAddress(); scoped_ptr<FullWallet> GetTestFullWallet(); |