| 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 "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | |
| 6 #include "chrome/browser/ui/views/payments/payment_request_interactive_uitest_ba
se.h" | |
| 7 #include "components/autofill/core/browser/autofill_test_utils.h" | |
| 8 #include "components/autofill/core/browser/personal_data_manager.h" | |
| 9 #include "components/payments/content/payment_request.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace payments { | |
| 13 | |
| 14 class PaymentMethodViewControllerTest | |
| 15 : public PaymentRequestInteractiveTestBase { | |
| 16 protected: | |
| 17 PaymentMethodViewControllerTest() | |
| 18 : PaymentRequestInteractiveTestBase( | |
| 19 "/payment_request_no_shipping_test.html") {} | |
| 20 | |
| 21 private: | |
| 22 DISALLOW_COPY_AND_ASSIGN(PaymentMethodViewControllerTest); | |
| 23 }; | |
| 24 | |
| 25 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, EmptyList) { | |
| 26 InvokePaymentRequestUI(); | |
| 27 OpenPaymentMethodScreen(); | |
| 28 | |
| 29 views::View* list_view = dialog_view()->GetViewByID( | |
| 30 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW)); | |
| 31 EXPECT_TRUE(list_view); | |
| 32 EXPECT_FALSE(list_view->has_children()); | |
| 33 } | |
| 34 | |
| 35 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, OneCardSelected) { | |
| 36 const autofill::CreditCard card = autofill::test::GetCreditCard(); | |
| 37 AddCreditCard(card); | |
| 38 | |
| 39 InvokePaymentRequestUI(); | |
| 40 OpenPaymentMethodScreen(); | |
| 41 | |
| 42 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents())[0]; | |
| 43 EXPECT_EQ(1U, request->credit_cards().size()); | |
| 44 | |
| 45 views::View* list_view = dialog_view()->GetViewByID( | |
| 46 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW)); | |
| 47 EXPECT_TRUE(list_view); | |
| 48 EXPECT_EQ(1, list_view->child_count()); | |
| 49 | |
| 50 EXPECT_EQ(card, *request->selected_credit_card()); | |
| 51 views::View* checkmark_view = list_view->child_at(0)->GetViewByID( | |
| 52 static_cast<int>(DialogViewID::CHECKMARK_VIEW)); | |
| 53 EXPECT_TRUE(checkmark_view->visible()); | |
| 54 } | |
| 55 | |
| 56 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, | |
| 57 OneCardSelectedOutOfMany) { | |
| 58 autofill::CreditCard card1 = autofill::test::GetCreditCard(); | |
| 59 // Ensure that this card is the first suggestion. | |
| 60 card1.set_use_count(5U); | |
| 61 AddCreditCard(card1); | |
| 62 | |
| 63 autofill::CreditCard card2 = autofill::test::GetCreditCard2(); | |
| 64 card2.set_use_count(1U); | |
| 65 AddCreditCard(card2); | |
| 66 | |
| 67 InvokePaymentRequestUI(); | |
| 68 OpenPaymentMethodScreen(); | |
| 69 | |
| 70 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents())[0]; | |
| 71 EXPECT_EQ(2U, request->credit_cards().size()); | |
| 72 EXPECT_EQ(card1, *request->selected_credit_card()); | |
| 73 | |
| 74 views::View* list_view = dialog_view()->GetViewByID( | |
| 75 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW)); | |
| 76 EXPECT_TRUE(list_view); | |
| 77 EXPECT_EQ(2, list_view->child_count()); | |
| 78 | |
| 79 EXPECT_EQ(card1, *request->selected_credit_card()); | |
| 80 views::View* checkmark_view = list_view->child_at(0)->GetViewByID( | |
| 81 static_cast<int>(DialogViewID::CHECKMARK_VIEW)); | |
| 82 EXPECT_TRUE(checkmark_view->visible()); | |
| 83 | |
| 84 views::View* checkmark_view2 = list_view->child_at(1)->GetViewByID( | |
| 85 static_cast<int>(DialogViewID::CHECKMARK_VIEW)); | |
| 86 EXPECT_FALSE(checkmark_view2->visible()); | |
| 87 | |
| 88 // Simulate selecting the second card. | |
| 89 ClickOnDialogViewAndWait(list_view->child_at(1)); | |
| 90 | |
| 91 EXPECT_EQ(card2, *request->selected_credit_card()); | |
| 92 EXPECT_FALSE(checkmark_view->visible()); | |
| 93 EXPECT_TRUE(checkmark_view2->visible()); | |
| 94 | |
| 95 // Clicking on the second card again should not modify any state. | |
| 96 ClickOnDialogViewAndWait(list_view->child_at(1)); | |
| 97 | |
| 98 EXPECT_EQ(card2, *request->selected_credit_card()); | |
| 99 EXPECT_FALSE(checkmark_view->visible()); | |
| 100 EXPECT_TRUE(checkmark_view2->visible()); | |
| 101 } | |
| 102 | |
| 103 } // namespace payments | |
| OLD | NEW |