| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <list> |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h" |
| 9 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| 10 #include "components/autofill/core/browser/autofill_profile.h" |
| 11 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace payments { |
| 15 |
| 16 class PaymentRequestOrderSummaryViewControllerTest |
| 17 : public PaymentRequestBrowserTestBase { |
| 18 protected: |
| 19 PaymentRequestOrderSummaryViewControllerTest() |
| 20 : PaymentRequestBrowserTestBase( |
| 21 "/payment_request_dynamic_shipping_test.html") {} |
| 22 |
| 23 private: |
| 24 DISALLOW_COPY_AND_ASSIGN(PaymentRequestOrderSummaryViewControllerTest); |
| 25 }; |
| 26 |
| 27 IN_PROC_BROWSER_TEST_F(PaymentRequestOrderSummaryViewControllerTest, |
| 28 OrderSummaryReflectsShippingOption) { |
| 29 // In MI state, shipping is $5.00. |
| 30 autofill::AutofillProfile michigan = autofill::test::GetFullProfile2(); |
| 31 michigan.set_use_count(100U); |
| 32 AddAutofillProfile(michigan); |
| 33 // In CA state, there is free shipping. |
| 34 autofill::AutofillProfile california = autofill::test::GetFullProfile(); |
| 35 california.set_use_count(50U); |
| 36 AddAutofillProfile(california); |
| 37 |
| 38 InvokePaymentRequestUI(); |
| 39 |
| 40 OpenOrderSummaryScreen(); |
| 41 |
| 42 // No address is selected. |
| 43 // Verify the expected amounts are shown ('Total', 'Pending Shipping Price' |
| 44 // and 'Subtotal', respectively). |
| 45 EXPECT_EQ(base::ASCIIToUTF16("USD $5.00"), |
| 46 GetStyledLabelText(DialogViewID::ORDER_SUMMARY_TOTAL_AMOUNT_LABEL)); |
| 47 EXPECT_EQ(base::ASCIIToUTF16("$0.00"), |
| 48 GetStyledLabelText(DialogViewID::ORDER_SUMMARY_LINE_ITEM_1)); |
| 49 EXPECT_EQ(base::ASCIIToUTF16("$5.00"), |
| 50 GetStyledLabelText(DialogViewID::ORDER_SUMMARY_LINE_ITEM_2)); |
| 51 |
| 52 // Go to the shipping address screen and select the first address (MI state). |
| 53 ClickOnBackArrow(); |
| 54 OpenShippingSectionScreen(); |
| 55 ResetEventObserverForSequence(std::list<DialogEvent>{ |
| 56 DialogEvent::BACK_NAVIGATION, DialogEvent::SPEC_DONE_UPDATING}); |
| 57 ClickOnChildInListViewAndWait( |
| 58 /* child_index=*/0, /*total_num_children=*/2, |
| 59 DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW); |
| 60 |
| 61 // Michigan address is selected and has standard shipping. |
| 62 std::vector<base::string16> shipping_address_labels = |
| 63 GetThreeLineLabelValues(DialogViewID::PAYMENT_SHEET_SHIPPING_SECTION); |
| 64 EXPECT_EQ(base::ASCIIToUTF16("Jane A. Smith"), shipping_address_labels[0]); |
| 65 EXPECT_EQ( |
| 66 base::ASCIIToUTF16("ACME, 123 Main Street, Unit 1, Greensdale, MI 48838"), |
| 67 shipping_address_labels[1]); |
| 68 EXPECT_EQ(base::ASCIIToUTF16("13105557889"), shipping_address_labels[2]); |
| 69 std::vector<base::string16> shipping_option_labels = |
| 70 GetShippingOptionLabelValues( |
| 71 DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION); |
| 72 EXPECT_EQ(base::ASCIIToUTF16("Standard shipping in US"), |
| 73 shipping_option_labels[0]); |
| 74 EXPECT_EQ(base::ASCIIToUTF16("$5.00"), shipping_option_labels[1]); |
| 75 |
| 76 // Go back to Order Summary screen to see updated totals. |
| 77 OpenOrderSummaryScreen(); |
| 78 |
| 79 // Verify the expected amounts are shown ('Total', 'Standard shipping in US' |
| 80 // and 'Subtotal', respectively). |
| 81 EXPECT_EQ(base::ASCIIToUTF16("USD $10.00"), |
| 82 GetStyledLabelText(DialogViewID::ORDER_SUMMARY_TOTAL_AMOUNT_LABEL)); |
| 83 EXPECT_EQ(base::ASCIIToUTF16("$5.00"), |
| 84 GetStyledLabelText(DialogViewID::ORDER_SUMMARY_LINE_ITEM_1)); |
| 85 EXPECT_EQ(base::ASCIIToUTF16("$5.00"), |
| 86 GetStyledLabelText(DialogViewID::ORDER_SUMMARY_LINE_ITEM_2)); |
| 87 |
| 88 // Go to the shipping address screen and select the second address (CA state). |
| 89 ClickOnBackArrow(); |
| 90 OpenShippingSectionScreen(); |
| 91 ResetEventObserverForSequence(std::list<DialogEvent>{ |
| 92 DialogEvent::BACK_NAVIGATION, DialogEvent::SPEC_DONE_UPDATING}); |
| 93 ClickOnChildInListViewAndWait( |
| 94 /* child_index=*/1, /*total_num_children=*/2, |
| 95 DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW); |
| 96 |
| 97 // California address is selected and has free shipping. |
| 98 shipping_address_labels = |
| 99 GetThreeLineLabelValues(DialogViewID::PAYMENT_SHEET_SHIPPING_SECTION); |
| 100 EXPECT_EQ(base::ASCIIToUTF16("John H. Doe"), shipping_address_labels[0]); |
| 101 EXPECT_EQ(base::ASCIIToUTF16( |
| 102 "Underworld, 666 Erebus St., Apt 8, Elysium, CA 91111"), |
| 103 shipping_address_labels[1]); |
| 104 EXPECT_EQ(base::ASCIIToUTF16("16502111111"), shipping_address_labels[2]); |
| 105 shipping_option_labels = GetShippingOptionLabelValues( |
| 106 DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION); |
| 107 EXPECT_EQ(base::ASCIIToUTF16("Free shipping in California"), |
| 108 shipping_option_labels[0]); |
| 109 EXPECT_EQ(base::ASCIIToUTF16("$0.00"), shipping_option_labels[1]); |
| 110 |
| 111 // Go back to Order Summary screen to see updated totals. |
| 112 OpenOrderSummaryScreen(); |
| 113 |
| 114 // Verify the expected amounts are shown ('Total', |
| 115 // 'Free shipping in California' and 'Subtotal', respectively). |
| 116 EXPECT_EQ(base::ASCIIToUTF16("USD $5.00"), |
| 117 GetStyledLabelText(DialogViewID::ORDER_SUMMARY_TOTAL_AMOUNT_LABEL)); |
| 118 EXPECT_EQ(base::ASCIIToUTF16("$0.00"), |
| 119 GetStyledLabelText(DialogViewID::ORDER_SUMMARY_LINE_ITEM_1)); |
| 120 EXPECT_EQ(base::ASCIIToUTF16("$5.00"), |
| 121 GetStyledLabelText(DialogViewID::ORDER_SUMMARY_LINE_ITEM_2)); |
| 122 } |
| 123 |
| 124 } // namespace payments |
| OLD | NEW |