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

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

Issue 2860563002: [Payments] Make AutofillPaymentInstrumentTest use test objects (Closed)
Patch Set: Addressed comment Created 3 years, 7 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 | components/payments/core/autofill_payment_instrument_unittest.cc » ('j') | 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 void OnShippingAddressSelected(mojom::PaymentAddressPtr address) override { 48 void OnShippingAddressSelected(mojom::PaymentAddressPtr address) override {
49 selected_shipping_address_ = std::move(address); 49 selected_shipping_address_ = std::move(address);
50 } 50 }
51 51
52 void RecreateStateWithOptionsAndDetails( 52 void RecreateStateWithOptionsAndDetails(
53 mojom::PaymentOptionsPtr options, 53 mojom::PaymentOptionsPtr options,
54 mojom::PaymentDetailsPtr details, 54 mojom::PaymentDetailsPtr details,
55 std::vector<mojom::PaymentMethodDataPtr> method_data) { 55 std::vector<mojom::PaymentMethodDataPtr> method_data) {
56 // The spec will be based on the |options| and |details| passed in. 56 // The spec will be based on the |options| and |details| passed in.
57 spec_ = base::MakeUnique<PaymentRequestSpec>( 57 spec_ = base::MakeUnique<PaymentRequestSpec>(
58 std::move(options), std::move(details), std::move(method_data), nullptr, 58 std::move(options), std::move(details), std::move(method_data),
59 "en-US"); 59 /*observer=*/nullptr, "en-US");
60 state_ = base::MakeUnique<PaymentRequestState>( 60 state_ = base::MakeUnique<PaymentRequestState>(
61 spec_.get(), this, "en-US", &test_personal_data_manager_, 61 spec_.get(), this, "en-US", &test_personal_data_manager_,
62 &test_payment_request_delegate_); 62 &test_payment_request_delegate_);
63 state_->AddObserver(this); 63 state_->AddObserver(this);
64 } 64 }
65 65
66 // Convenience method to create a PaymentRequestState with default details 66 // Convenience method to create a PaymentRequestState with default details
67 // (one shipping option) and method data (only supports visa). 67 // (one shipping option) and method data (only supports visa).
68 void RecreateStateWithOptions(mojom::PaymentOptionsPtr options) { 68 void RecreateStateWithOptions(mojom::PaymentOptionsPtr options) {
69 RecreateStateWithOptionsAndDetails( 69 RecreateStateWithOptionsAndDetails(
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 EXPECT_TRUE(state()->is_ready_to_pay()); 268 EXPECT_TRUE(state()->is_ready_to_pay());
269 } 269 }
270 270
271 TEST_F(PaymentRequestStateTest, SelectedShippingAddressMessage_Normalized) { 271 TEST_F(PaymentRequestStateTest, SelectedShippingAddressMessage_Normalized) {
272 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New(); 272 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New();
273 options->request_shipping = true; 273 options->request_shipping = true;
274 RecreateStateWithOptions(std::move(options)); 274 RecreateStateWithOptions(std::move(options));
275 275
276 // Make the normalization not be instantaneous. 276 // Make the normalization not be instantaneous.
277 test_payment_request_delegate() 277 test_payment_request_delegate()
278 ->GetTestAddressNormalizer() 278 ->test_address_normalizer()
279 ->DelayNormalization(); 279 ->DelayNormalization();
280 280
281 EXPECT_EQ(0, num_on_selected_information_changed_called()); 281 EXPECT_EQ(0, num_on_selected_information_changed_called());
282 282
283 // Select an address, nothing should happen until the normalization is 283 // Select an address, nothing should happen until the normalization is
284 // completed and the merchant has validated the address. 284 // completed and the merchant has validated the address.
285 state()->SetSelectedShippingProfile(test_address()); 285 state()->SetSelectedShippingProfile(test_address());
286 EXPECT_EQ(1, num_on_selected_information_changed_called()); 286 EXPECT_EQ(1, num_on_selected_information_changed_called());
287 EXPECT_FALSE(state()->is_ready_to_pay()); 287 EXPECT_FALSE(state()->is_ready_to_pay());
288 288
289 // Complete the normalization. 289 // Complete the normalization.
290 test_payment_request_delegate() 290 test_payment_request_delegate()
291 ->GetTestAddressNormalizer() 291 ->test_address_normalizer()
292 ->CompleteAddressNormalization(); 292 ->CompleteAddressNormalization();
293 EXPECT_EQ(1, num_on_selected_information_changed_called()); 293 EXPECT_EQ(1, num_on_selected_information_changed_called());
294 EXPECT_FALSE(state()->is_ready_to_pay()); 294 EXPECT_FALSE(state()->is_ready_to_pay());
295 295
296 // Simulate that the merchant has validated the shipping address change. 296 // Simulate that the merchant has validated the shipping address change.
297 spec()->UpdateWith(CreateDefaultDetails()); 297 spec()->UpdateWith(CreateDefaultDetails());
298 EXPECT_EQ(2, num_on_selected_information_changed_called()); 298 EXPECT_EQ(2, num_on_selected_information_changed_called());
299 EXPECT_TRUE(state()->is_ready_to_pay()); 299 EXPECT_TRUE(state()->is_ready_to_pay());
300 300
301 // Check that all the expected values were set for the shipping address. 301 // Check that all the expected values were set for the shipping address.
302 EXPECT_EQ("US", selected_shipping_address()->country); 302 EXPECT_EQ("US", selected_shipping_address()->country);
303 EXPECT_EQ("666 Erebus St.", selected_shipping_address()->address_line[0]); 303 EXPECT_EQ("666 Erebus St.", selected_shipping_address()->address_line[0]);
304 EXPECT_EQ("Apt 8", selected_shipping_address()->address_line[1]); 304 EXPECT_EQ("Apt 8", selected_shipping_address()->address_line[1]);
305 EXPECT_EQ("CA", selected_shipping_address()->region); 305 EXPECT_EQ("CA", selected_shipping_address()->region);
306 EXPECT_EQ("Elysium", selected_shipping_address()->city); 306 EXPECT_EQ("Elysium", selected_shipping_address()->city);
307 EXPECT_EQ("", selected_shipping_address()->dependent_locality); 307 EXPECT_EQ("", selected_shipping_address()->dependent_locality);
308 EXPECT_EQ("91111", selected_shipping_address()->postal_code); 308 EXPECT_EQ("91111", selected_shipping_address()->postal_code);
309 EXPECT_EQ("", selected_shipping_address()->sorting_code); 309 EXPECT_EQ("", selected_shipping_address()->sorting_code);
310 EXPECT_EQ("", selected_shipping_address()->language_code); 310 EXPECT_EQ("", selected_shipping_address()->language_code);
311 EXPECT_EQ("Underworld", selected_shipping_address()->organization); 311 EXPECT_EQ("Underworld", selected_shipping_address()->organization);
312 EXPECT_EQ("John H. Doe", selected_shipping_address()->recipient); 312 EXPECT_EQ("John H. Doe", selected_shipping_address()->recipient);
313 EXPECT_EQ("16502111111", selected_shipping_address()->phone); 313 EXPECT_EQ("16502111111", selected_shipping_address()->phone);
314 } 314 }
315 315
316 } // namespace payments 316 } // namespace payments
OLDNEW
« no previous file with comments | « no previous file | components/payments/core/autofill_payment_instrument_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698