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

Side by Side Diff: components/autofill/content/browser/payments/payments_client_unittest.cc

Issue 2829853008: Stores server card as a full server card when upload to server succeeds. (Closed)
Patch Set: Renames AddServerCreditCard to AddFullServerCreditCard. Adds DCHECK to verify that we are in a tran… Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <utility> 5 #include <utility>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
(...skipping 16 matching lines...) Expand all
27 public: 27 public:
28 PaymentsClientTest() : result_(AutofillClient::NONE) {} 28 PaymentsClientTest() : result_(AutofillClient::NONE) {}
29 ~PaymentsClientTest() override {} 29 ~PaymentsClientTest() override {}
30 30
31 void SetUp() override { 31 void SetUp() override {
32 // Silence the warning for mismatching sync and Payments servers. 32 // Silence the warning for mismatching sync and Payments servers.
33 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 33 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
34 switches::kWalletServiceUseSandbox, "0"); 34 switches::kWalletServiceUseSandbox, "0");
35 35
36 result_ = AutofillClient::NONE; 36 result_ = AutofillClient::NONE;
37 server_id_.clear();
37 real_pan_.clear(); 38 real_pan_.clear();
38 legal_message_.reset(); 39 legal_message_.reset();
39 40
40 request_context_ = new net::TestURLRequestContextGetter( 41 request_context_ = new net::TestURLRequestContextGetter(
41 base::ThreadTaskRunnerHandle::Get()); 42 base::ThreadTaskRunnerHandle::Get());
42 token_service_.reset(new FakeOAuth2TokenService()); 43 token_service_.reset(new FakeOAuth2TokenService());
43 identity_provider_.reset(new FakeIdentityProvider(token_service_.get())); 44 identity_provider_.reset(new FakeIdentityProvider(token_service_.get()));
44 client_.reset(new PaymentsClient(request_context_.get(), this)); 45 client_.reset(new PaymentsClient(request_context_.get(), this));
45 } 46 }
46 47
(...skipping 12 matching lines...) Expand all
59 } 60 }
60 61
61 void OnDidGetUploadDetails( 62 void OnDidGetUploadDetails(
62 AutofillClient::PaymentsRpcResult result, 63 AutofillClient::PaymentsRpcResult result,
63 const base::string16& context_token, 64 const base::string16& context_token,
64 std::unique_ptr<base::DictionaryValue> legal_message) override { 65 std::unique_ptr<base::DictionaryValue> legal_message) override {
65 result_ = result; 66 result_ = result;
66 legal_message_ = std::move(legal_message); 67 legal_message_ = std::move(legal_message);
67 } 68 }
68 69
69 void OnDidUploadCard(AutofillClient::PaymentsRpcResult result) override { 70 void OnDidUploadCard(AutofillClient::PaymentsRpcResult result,
71 const std::string& server_id) override {
70 result_ = result; 72 result_ = result;
73 server_id_ = server_id;
71 } 74 }
72 75
73 protected: 76 protected:
74 void StartUnmasking() { 77 void StartUnmasking() {
75 token_service_->AddAccount("example@gmail.com"); 78 token_service_->AddAccount("example@gmail.com");
76 identity_provider_->LogIn("example@gmail.com"); 79 identity_provider_->LogIn("example@gmail.com");
77 PaymentsClient::UnmaskRequestDetails request_details; 80 PaymentsClient::UnmaskRequestDetails request_details;
78 request_details.card = test::GetMaskedServerCard(); 81 request_details.card = test::GetMaskedServerCard();
79 request_details.user_response.cvc = base::ASCIIToUTF16("123"); 82 request_details.user_response.cvc = base::ASCIIToUTF16("123");
80 request_details.risk_data = "some risk data"; 83 request_details.risk_data = "some risk data";
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 void ReturnResponse(net::HttpStatusCode response_code, 126 void ReturnResponse(net::HttpStatusCode response_code,
124 const std::string& response_body) { 127 const std::string& response_body) {
125 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); 128 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
126 ASSERT_TRUE(fetcher); 129 ASSERT_TRUE(fetcher);
127 fetcher->set_response_code(response_code); 130 fetcher->set_response_code(response_code);
128 fetcher->SetResponseString(response_body); 131 fetcher->SetResponseString(response_body);
129 fetcher->delegate()->OnURLFetchComplete(fetcher); 132 fetcher->delegate()->OnURLFetchComplete(fetcher);
130 } 133 }
131 134
132 AutofillClient::PaymentsRpcResult result_; 135 AutofillClient::PaymentsRpcResult result_;
136 std::string server_id_;
133 std::string real_pan_; 137 std::string real_pan_;
134 std::unique_ptr<base::DictionaryValue> legal_message_; 138 std::unique_ptr<base::DictionaryValue> legal_message_;
135 139
136 content::TestBrowserThreadBundle thread_bundle_; 140 content::TestBrowserThreadBundle thread_bundle_;
137 net::TestURLFetcherFactory factory_; 141 net::TestURLFetcherFactory factory_;
138 scoped_refptr<net::TestURLRequestContextGetter> request_context_; 142 scoped_refptr<net::TestURLRequestContextGetter> request_context_;
139 std::unique_ptr<FakeOAuth2TokenService> token_service_; 143 std::unique_ptr<FakeOAuth2TokenService> token_service_;
140 std::unique_ptr<FakeIdentityProvider> identity_provider_; 144 std::unique_ptr<FakeIdentityProvider> identity_provider_;
141 std::unique_ptr<PaymentsClient> client_; 145 std::unique_ptr<PaymentsClient> client_;
142 146
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // upload data. 224 // upload data.
221 EXPECT_TRUE(GetUploadData().find(PaymentsClient::kPhoneNumber) == 225 EXPECT_TRUE(GetUploadData().find(PaymentsClient::kPhoneNumber) ==
222 std::string::npos); 226 std::string::npos);
223 EXPECT_TRUE(GetUploadData().find("212") == std::string::npos); 227 EXPECT_TRUE(GetUploadData().find("212") == std::string::npos);
224 EXPECT_TRUE(GetUploadData().find("555") == std::string::npos); 228 EXPECT_TRUE(GetUploadData().find("555") == std::string::npos);
225 EXPECT_TRUE(GetUploadData().find("0162") == std::string::npos); 229 EXPECT_TRUE(GetUploadData().find("0162") == std::string::npos);
226 EXPECT_TRUE(GetUploadData().find("834") == std::string::npos); 230 EXPECT_TRUE(GetUploadData().find("834") == std::string::npos);
227 EXPECT_TRUE(GetUploadData().find("0090") == std::string::npos); 231 EXPECT_TRUE(GetUploadData().find("0090") == std::string::npos);
228 } 232 }
229 233
230 TEST_F(PaymentsClientTest, UploadSuccess) { 234 TEST_F(PaymentsClientTest, UploadSuccessWithoutServerId) {
231 StartUploading(); 235 StartUploading();
232 IssueOAuthToken(); 236 IssueOAuthToken();
233 ReturnResponse(net::HTTP_OK, "{}"); 237 ReturnResponse(net::HTTP_OK, "{}");
234 EXPECT_EQ(AutofillClient::SUCCESS, result_); 238 EXPECT_EQ(AutofillClient::SUCCESS, result_);
239 EXPECT_TRUE(server_id_.empty());
240 }
241
242 TEST_F(PaymentsClientTest, UploadSuccessWithServerId) {
243 StartUploading();
244 IssueOAuthToken();
245 ReturnResponse(net::HTTP_OK, "{ \"credit_card_id\": \"InstrumentData:1\" }");
246 EXPECT_EQ(AutofillClient::SUCCESS, result_);
247 EXPECT_EQ("InstrumentData:1", server_id_);
235 } 248 }
236 249
237 TEST_F(PaymentsClientTest, UploadIncludesNonLocationData) { 250 TEST_F(PaymentsClientTest, UploadIncludesNonLocationData) {
238 StartUploading(); 251 StartUploading();
239 252
240 // Verify that the recipient name field and test names do appear in the upload 253 // Verify that the recipient name field and test names do appear in the upload
241 // data. 254 // data.
242 EXPECT_TRUE(GetUploadData().find(PaymentsClient::kRecipientName) != 255 EXPECT_TRUE(GetUploadData().find(PaymentsClient::kRecipientName) !=
243 std::string::npos); 256 std::string::npos);
244 EXPECT_TRUE(GetUploadData().find("John") != std::string::npos); 257 EXPECT_TRUE(GetUploadData().find("John") != std::string::npos);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 TEST_F(PaymentsClientTest, OtherError) { 375 TEST_F(PaymentsClientTest, OtherError) {
363 StartUnmasking(); 376 StartUnmasking();
364 IssueOAuthToken(); 377 IssueOAuthToken();
365 ReturnResponse(net::HTTP_FORBIDDEN, std::string()); 378 ReturnResponse(net::HTTP_FORBIDDEN, std::string());
366 EXPECT_EQ(AutofillClient::PERMANENT_FAILURE, result_); 379 EXPECT_EQ(AutofillClient::PERMANENT_FAILURE, result_);
367 EXPECT_EQ("", real_pan_); 380 EXPECT_EQ("", real_pan_);
368 } 381 }
369 382
370 } // namespace autofill 383 } // namespace autofill
371 } // namespace payments 384 } // namespace payments
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/payments/cvc_unmask_view_controller.cc ('k') | components/autofill/core/browser/autofill_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698