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

Side by Side Diff: components/payments/content/payment_request_state_unittest.cc

Issue 2779453002: [Payments] Return the preferred payment method name to the merchant (Closed)
Patch Set: compile fix 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
« no previous file with comments | « components/payments/content/payment_request_state.cc ('k') | 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/payments/content/payment_request_state.h" 5 #include "components/payments/content/payment_request_state.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 EXPECT_FALSE(state()->is_ready_to_pay()); 266 EXPECT_FALSE(state()->is_ready_to_pay());
267 267
268 state()->SetSelectedContactProfile(test_address()); 268 state()->SetSelectedContactProfile(test_address());
269 EXPECT_EQ(2, num_on_selected_information_changed_called()); 269 EXPECT_EQ(2, num_on_selected_information_changed_called());
270 270
271 // Ready to pay! 271 // Ready to pay!
272 EXPECT_TRUE(state()->is_ready_to_pay()); 272 EXPECT_TRUE(state()->is_ready_to_pay());
273 } 273 }
274 274
275 // Test generating a PaymentResponse. 275 // Test generating a PaymentResponse.
276 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse) { 276 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_SupportedMethod) {
277 // Default options (no shipping, no contact info). 277 // Default options (no shipping, no contact info).
278 RecreateStateWithOptions(mojom::PaymentOptions::New()); 278 RecreateStateWithOptions(mojom::PaymentOptions::New());
279 state()->SetSelectedInstrument(state()->available_instruments()[0].get()); 279 state()->SetSelectedInstrument(state()->available_instruments()[0].get());
280 EXPECT_EQ(1, num_on_selected_information_changed_called()); 280 EXPECT_EQ(1, num_on_selected_information_changed_called());
281 EXPECT_TRUE(state()->is_ready_to_pay()); 281 EXPECT_TRUE(state()->is_ready_to_pay());
282 282
283 // TODO(mathp): Currently synchronous, when async will need a RunLoop. 283 // TODO(mathp): Currently synchronous, when async will need a RunLoop.
284 // "visa" is specified directly in the supportedMethods so it is returned
285 // as the method name.
284 state()->GeneratePaymentResponse(); 286 state()->GeneratePaymentResponse();
285 EXPECT_EQ("visa", response()->method_name); 287 EXPECT_EQ("visa", response()->method_name);
286 EXPECT_EQ( 288 EXPECT_EQ(
287 "{\"billingAddress\":" 289 "{\"billingAddress\":"
288 "{\"addressLine\":[\"666 Erebus St.\",\"Apt 8\"]," 290 "{\"addressLine\":[\"666 Erebus St.\",\"Apt 8\"],"
289 "\"city\":\"Elysium\"," 291 "\"city\":\"Elysium\","
290 "\"country\":\"US\"," 292 "\"country\":\"US\","
291 "\"organization\":\"Underworld\"," 293 "\"organization\":\"Underworld\","
292 "\"phone\":\"16502111111\"," 294 "\"phone\":\"16502111111\","
293 "\"postalCode\":\"91111\"," 295 "\"postalCode\":\"91111\","
294 "\"recipient\":\"John H. Doe\"," 296 "\"recipient\":\"John H. Doe\","
295 "\"region\":\"CA\"}," 297 "\"region\":\"CA\"},"
296 "\"cardNumber\":\"4111111111111111\"," 298 "\"cardNumber\":\"4111111111111111\","
297 "\"cardSecurityCode\":\"123\"," 299 "\"cardSecurityCode\":\"123\","
298 "\"cardholderName\":\"Test User\"," 300 "\"cardholderName\":\"Test User\","
299 "\"expiryMonth\":\"11\"," 301 "\"expiryMonth\":\"11\","
300 "\"expiryYear\":\"2017\"}", 302 "\"expiryYear\":\"2017\"}",
301 response()->stringified_details); 303 response()->stringified_details);
302 } 304 }
303 305
306 // Test generating a PaymentResponse when the method is specified through
307 // "basic-card".
308 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_BasicCard) {
309 // The method data supports visa through basic-card.
310 mojom::PaymentMethodDataPtr entry = mojom::PaymentMethodData::New();
311 entry->supported_methods.push_back("basic-card");
312 entry->supported_networks.push_back(mojom::BasicCardNetwork::VISA);
313 std::vector<mojom::PaymentMethodDataPtr> method_data;
314 method_data.push_back(std::move(entry));
315 RecreateStateWithOptionsAndDetails(mojom::PaymentOptions::New(),
316 mojom::PaymentDetails::New(),
317 std::move(method_data));
318
319 EXPECT_TRUE(state()->is_ready_to_pay());
320
321 // TODO(mathp): Currently synchronous, when async will need a RunLoop.
322 // "basic-card" is specified so it is returned as the method name.
323 state()->GeneratePaymentResponse();
324 EXPECT_EQ("basic-card", response()->method_name);
325 EXPECT_EQ(
326 "{\"billingAddress\":"
327 "{\"addressLine\":[\"666 Erebus St.\",\"Apt 8\"],"
328 "\"city\":\"Elysium\","
329 "\"country\":\"US\","
330 "\"organization\":\"Underworld\","
331 "\"phone\":\"16502111111\","
332 "\"postalCode\":\"91111\","
333 "\"recipient\":\"John H. Doe\","
334 "\"region\":\"CA\"},"
335 "\"cardNumber\":\"4111111111111111\","
336 "\"cardSecurityCode\":\"123\","
337 "\"cardholderName\":\"Test User\","
338 "\"expiryMonth\":\"11\","
339 "\"expiryYear\":\"2017\"}",
340 response()->stringified_details);
341 }
342
304 } // namespace payments 343 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/content/payment_request_state.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698