Chromium Code Reviews| Index: components/autofill/content/browser/payments/payments_client_unittest.cc |
| diff --git a/components/autofill/content/browser/payments/payments_client_unittest.cc b/components/autofill/content/browser/payments/payments_client_unittest.cc |
| index 055829e9a519480753e9af1bb22d90af18f939fd..713217721f2baee57879606d8edd8cc892fdc8f3 100644 |
| --- a/components/autofill/content/browser/payments/payments_client_unittest.cc |
| +++ b/components/autofill/content/browser/payments/payments_client_unittest.cc |
| @@ -3,9 +3,11 @@ |
| // found in the LICENSE file. |
| #include <utility> |
| +#include <vector> |
| #include "base/command_line.h" |
| #include "base/macros.h" |
| +#include "base/strings/string_piece.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "base/values.h" |
| #include "components/autofill/core/browser/autofill_test_utils.h" |
| @@ -82,7 +84,7 @@ class PaymentsClientTest : public testing::Test, public PaymentsClientDelegate { |
| void StartGettingUploadDetails() { |
| token_service_->AddAccount("example@gmail.com"); |
| identity_provider_->LogIn("example@gmail.com"); |
| - client_->GetUploadDetails("language-LOCALE"); |
| + client_->GetUploadDetails(BuildTestProfiles(), "language-LOCALE"); |
| } |
| void StartUploading() { |
| @@ -94,9 +96,14 @@ class PaymentsClientTest : public testing::Test, public PaymentsClientDelegate { |
| request_details.context_token = base::ASCIIToUTF16("context token"); |
| request_details.risk_data = "some risk data"; |
| request_details.app_locale = "language-LOCALE"; |
| + request_details.profiles = BuildTestProfiles(); |
| client_->UploadCard(request_details); |
| } |
| + const std::string& GetUploadData() { |
| + return factory_.GetFetcherByID(0)->upload_data(); |
| + } |
| + |
| void IssueOAuthToken() { |
| token_service_->IssueAllTokensForAccount( |
| "example@gmail.com", "totally_real_token", |
| @@ -135,6 +142,37 @@ class PaymentsClientTest : public testing::Test, public PaymentsClientDelegate { |
| private: |
| DISALLOW_COPY_AND_ASSIGN(PaymentsClientTest); |
| + |
| + std::vector<AutofillProfile> BuildTestProfiles() { |
| + std::vector<AutofillProfile> profiles; |
| + profiles.push_back( |
| + BuildProfile("John", "Smith", "1234 Main St.", "Miami", "FL", "32006")); |
| + profiles.push_back( |
| + BuildProfile("Pat", "Jones", "432 Oak Lane", "Lincoln", "OH", "43005")); |
| + return profiles; |
| + } |
| + |
| + AutofillProfile BuildProfile(base::StringPiece first_name, |
| + base::StringPiece last_name, |
| + base::StringPiece address_line, |
| + base::StringPiece city, |
| + base::StringPiece state, |
| + base::StringPiece zip) { |
| + AutofillProfile profile; |
| + |
| + profile.SetInfo(AutofillType(NAME_FIRST), |
| + ASCIIToUTF16(first_name), "en-US"); |
| + profile.SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16(last_name), "en-US"); |
| + profile.SetInfo(AutofillType(ADDRESS_HOME_LINE1), |
| + ASCIIToUTF16(address_line), "en-US"); |
| + profile.SetInfo(AutofillType(ADDRESS_HOME_CITY), |
| + ASCIIToUTF16(city), "en-US"); |
| + profile.SetInfo(AutofillType(ADDRESS_HOME_STATE), |
| + ASCIIToUTF16(state), "en-US"); |
| + profile.SetInfo(AutofillType(ADDRESS_HOME_ZIP), ASCIIToUTF16(zip), "en-US"); |
| + |
| + return profile; |
| + } |
| }; |
| TEST_F(PaymentsClientTest, OAuthError) { |
| @@ -163,6 +201,12 @@ TEST_F(PaymentsClientTest, GetDetailsSuccess) { |
| EXPECT_NE(nullptr, legal_message_.get()); |
| } |
| +TEST_F(PaymentsClientTest, GetDetailsRemovesRecipientNames) { |
| + StartGettingUploadDetails(); |
| + EXPECT_TRUE(GetUploadData().find(PaymentsClient::kRecipientName) == |
| + std::string::npos); |
|
Evan Stade
2016/09/22 16:16:13
nit: verify other fields are present? verify "John
|
| +} |
| + |
| TEST_F(PaymentsClientTest, UploadSuccess) { |
| StartUploading(); |
| IssueOAuthToken(); |
| @@ -170,6 +214,12 @@ TEST_F(PaymentsClientTest, UploadSuccess) { |
| EXPECT_EQ(AutofillClient::SUCCESS, result_); |
| } |
| +TEST_F(PaymentsClientTest, UploadIncludesRecipientNames) { |
| + StartUploading(); |
| + EXPECT_TRUE(GetUploadData().find(PaymentsClient::kRecipientName) != |
| + std::string::npos); |
| +} |
| + |
| TEST_F(PaymentsClientTest, GetDetailsFollowedByUploadSuccess) { |
| StartGettingUploadDetails(); |
| ReturnResponse( |