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

Side by Side Diff: components/autofill/content/browser/wallet/real_pan_wallet_client_unittest.cc

Issue 1034873003: Another couple tests for RealPanWalletClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "components/autofill/core/browser/autofill_test_utils.h" 6 #include "components/autofill/core/browser/autofill_test_utils.h"
7 #include "components/autofill/core/browser/wallet/real_pan_wallet_client.h" 7 #include "components/autofill/core/browser/wallet/real_pan_wallet_client.h"
8 #include "components/autofill/core/common/autofill_switches.h" 8 #include "components/autofill/core/common/autofill_switches.h"
9 #include "content/public/test/test_browser_thread_bundle.h" 9 #include "content/public/test/test_browser_thread_bundle.h"
10 #include "google_apis/gaia/fake_identity_provider.h" 10 #include "google_apis/gaia/fake_identity_provider.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 116 }
117 117
118 TEST_F(RealPanWalletClientTest, RetryFailure) { 118 TEST_F(RealPanWalletClientTest, RetryFailure) {
119 StartUnmasking(); 119 StartUnmasking();
120 IssueOAuthToken(); 120 IssueOAuthToken();
121 ReturnResponse(net::HTTP_OK, "{ \"error\": { \"code\": \"INTERNAL\" } }"); 121 ReturnResponse(net::HTTP_OK, "{ \"error\": { \"code\": \"INTERNAL\" } }");
122 EXPECT_EQ(AutofillClient::TRY_AGAIN_FAILURE, result_); 122 EXPECT_EQ(AutofillClient::TRY_AGAIN_FAILURE, result_);
123 EXPECT_EQ("", real_pan_); 123 EXPECT_EQ("", real_pan_);
124 } 124 }
125 125
126 // TODO(estade): enable when https://codereview.chromium.org/1028313006/ 126 TEST_F(RealPanWalletClientTest, PermanentFailure) {
127 // lands.
128 TEST_F(RealPanWalletClientTest, DISABLED_PermanentFailure) {
129 StartUnmasking(); 127 StartUnmasking();
130 IssueOAuthToken(); 128 IssueOAuthToken();
131 ReturnResponse(net::HTTP_OK, 129 ReturnResponse(net::HTTP_OK,
132 "{ \"error\": { \"code\": \"ANYTHING_ELSE\" } }"); 130 "{ \"error\": { \"code\": \"ANYTHING_ELSE\" } }");
133 EXPECT_EQ(AutofillClient::PERMANENT_FAILURE, result_); 131 EXPECT_EQ(AutofillClient::PERMANENT_FAILURE, result_);
134 EXPECT_EQ("", real_pan_); 132 EXPECT_EQ("", real_pan_);
135 } 133 }
136 134
135 TEST_F(RealPanWalletClientTest, MalformedResponse) {
136 StartUnmasking();
137 IssueOAuthToken();
138 ReturnResponse(net::HTTP_OK,
139 "{ \"error_code\": \"WRONG_JSON_FORMAT\" }");
140 EXPECT_EQ(AutofillClient::PERMANENT_FAILURE, result_);
141 EXPECT_EQ("", real_pan_);
142 }
143
144 TEST_F(RealPanWalletClientTest, ReauthNeeded) {
145 {
146 StartUnmasking();
147 IssueOAuthToken();
148 ReturnResponse(net::HTTP_UNAUTHORIZED, "");
149 // No response yet.
150 EXPECT_EQ(AutofillClient::SUCCESS, result_);
151 EXPECT_EQ("", real_pan_);
152
153 // Second HTTP_UNAUTHORIZED causes permanent failure.
154 IssueOAuthToken();
155 ReturnResponse(net::HTTP_UNAUTHORIZED, "");
156 EXPECT_EQ(AutofillClient::PERMANENT_FAILURE, result_);
157 EXPECT_EQ("", real_pan_);
158 }
159
160 result_ = AutofillClient::SUCCESS;
161 real_pan_.clear();
162
163 {
164 StartUnmasking();
165 IssueOAuthToken();
166 ReturnResponse(net::HTTP_UNAUTHORIZED, "");
167 // No response yet.
168 EXPECT_EQ(AutofillClient::SUCCESS, result_);
169 EXPECT_EQ("", real_pan_);
170
171 // HTTP_OK after first HTTP_UNAUTHORIZED results in success.
172 IssueOAuthToken();
173 ReturnResponse(net::HTTP_OK, "{ \"pan\": \"1234\" }");
174 EXPECT_EQ(AutofillClient::SUCCESS, result_);
175 EXPECT_EQ("1234", real_pan_);
176 }
177 }
178
137 TEST_F(RealPanWalletClientTest, NetworkError) { 179 TEST_F(RealPanWalletClientTest, NetworkError) {
138 StartUnmasking(); 180 StartUnmasking();
139 IssueOAuthToken(); 181 IssueOAuthToken();
140 ReturnResponse(net::HTTP_REQUEST_TIMEOUT, std::string()); 182 ReturnResponse(net::HTTP_REQUEST_TIMEOUT, std::string());
141 EXPECT_EQ(AutofillClient::NETWORK_ERROR, result_); 183 EXPECT_EQ(AutofillClient::NETWORK_ERROR, result_);
142 EXPECT_EQ("", real_pan_); 184 EXPECT_EQ("", real_pan_);
143 } 185 }
144 186
145 TEST_F(RealPanWalletClientTest, OtherError) { 187 TEST_F(RealPanWalletClientTest, OtherError) {
146 StartUnmasking(); 188 StartUnmasking();
147 IssueOAuthToken(); 189 IssueOAuthToken();
148 ReturnResponse(net::HTTP_FORBIDDEN, std::string()); 190 ReturnResponse(net::HTTP_FORBIDDEN, std::string());
149 EXPECT_EQ(AutofillClient::PERMANENT_FAILURE, result_); 191 EXPECT_EQ(AutofillClient::PERMANENT_FAILURE, result_);
150 EXPECT_EQ("", real_pan_); 192 EXPECT_EQ("", real_pan_);
151 } 193 }
152 194
153 } // namespace autofill 195 } // namespace autofill
154 } // namespace wallet 196 } // namespace wallet
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698