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

Side by Side Diff: chrome/browser/ui/views/payments/payment_method_view_controller_interactive_uitest.cc

Issue 2711973002: [Web Payments] Implement the credit card selection UI functionality. (Closed)
Patch Set: Rebase Created 3 years, 10 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
OLDNEW
(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/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 PersonalDataLoadedObserverMock personal_data_observer_;
22
23 private:
24 DISALLOW_COPY_AND_ASSIGN(PaymentMethodViewControllerTest);
25 };
26
27 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, TestEmptyEditor) {
Mathieu 2017/02/24 22:51:24 EmptyList? Also I would rename Test from the test
anthonyvd 2017/02/24 23:26:28 Done here and below.
28 InvokePaymentRequestUI();
29 OpenPaymentMethodScreen();
30
31 views::View* list_view = dialog_view()->GetViewByID(
32 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW));
33 EXPECT_TRUE(list_view);
34 EXPECT_FALSE(list_view->has_children());
35 }
36
37 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, TestOneCardSelected) {
38 autofill::PersonalDataManager* personal_data_manager = GetDataManager();
39 personal_data_manager->AddObserver(&personal_data_observer_);
40
41 autofill::CreditCard card = autofill::test::GetCreditCard();
42 personal_data_manager->AddCreditCard(card);
Mathieu 2017/02/24 22:51:24 I think I would move the Add call just before data
anthonyvd 2017/02/24 23:26:28 Done.
43
44 base::RunLoop data_loop;
45 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
46 .WillOnce(QuitMessageLoop(&data_loop));
47 data_loop.Run();
48
49 InvokePaymentRequestUI();
50 OpenPaymentMethodScreen();
51
52 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents())[0];
53 EXPECT_EQ(1U, request->credit_cards().size());
54
55 views::View* list_view = dialog_view()->GetViewByID(
56 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW));
57 EXPECT_TRUE(list_view);
58 EXPECT_EQ(1, list_view->child_count());
59
60 EXPECT_EQ(card, *request->selected_credit_card());
61 views::View* checkmark_view = list_view->child_at(0)->GetViewByID(
62 static_cast<int>(DialogViewID::PAYMENT_METHOD_ITEM_CHECKMARK_VIEW));
63 EXPECT_TRUE(checkmark_view->visible());
64 }
65
66 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest,
67 TestOneCardSelectedOutOfMany) {
68 autofill::PersonalDataManager* personal_data_manager = GetDataManager();
69 personal_data_manager->AddObserver(&personal_data_observer_);
70
71 autofill::CreditCard card1 = autofill::test::GetCreditCard();
72 autofill::CreditCard card2 = autofill::test::GetCreditCard2();
73 personal_data_manager->AddCreditCard(card1);
74
75 base::RunLoop card1_loop;
76 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
77 .WillOnce(QuitMessageLoop(&card1_loop));
78 card1_loop.Run();
79
80 personal_data_manager->AddCreditCard(card2);
81
82 base::RunLoop card2_loop;
83 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
84 .WillOnce(QuitMessageLoop(&card2_loop));
85 card2_loop.Run();
86
87 InvokePaymentRequestUI();
88 OpenPaymentMethodScreen();
89
90 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents())[0];
91 EXPECT_EQ(2U, request->credit_cards().size());
92 EXPECT_EQ(card1, *request->selected_credit_card());
93
94 views::View* list_view = dialog_view()->GetViewByID(
95 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW));
96 EXPECT_TRUE(list_view);
97 EXPECT_EQ(2, list_view->child_count());
98
99 EXPECT_EQ(card1, *request->selected_credit_card());
100 views::View* checkmark_view = list_view->child_at(0)->GetViewByID(
101 static_cast<int>(DialogViewID::PAYMENT_METHOD_ITEM_CHECKMARK_VIEW));
102 EXPECT_TRUE(checkmark_view->visible());
103
104 views::View* checkmark_view2 = list_view->child_at(1)->GetViewByID(
105 static_cast<int>(DialogViewID::PAYMENT_METHOD_ITEM_CHECKMARK_VIEW));
106 EXPECT_FALSE(checkmark_view2->visible());
107
108 // Simulate selecting the second card.
109 ClickOnDialogViewAndWait(list_view->child_at(1));
110
111 EXPECT_EQ(card2, *request->selected_credit_card());
112 EXPECT_FALSE(checkmark_view->visible());
113 EXPECT_TRUE(checkmark_view2->visible());
114
115 // Clicking on the second card again should not modify any state.
116 ClickOnDialogViewAndWait(list_view->child_at(1));
117
118 EXPECT_EQ(card2, *request->selected_credit_card());
119 EXPECT_FALSE(checkmark_view->visible());
120 EXPECT_TRUE(checkmark_view2->visible());
121 }
122
123 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698