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

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

Issue 2715213005: [Payments] Add the pay button, and control its enabled state (Closed)
Patch Set: addressed comments Created 3 years, 9 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
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 "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 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" 6 #include "chrome/browser/ui/views/payments/payment_request_interactive_uitest_ba se.h"
7 #include "components/autofill/core/browser/autofill_test_utils.h" 7 #include "components/autofill/core/browser/autofill_test_utils.h"
8 #include "components/autofill/core/browser/personal_data_manager.h" 8 #include "components/autofill/core/browser/personal_data_manager.h"
9 #include "components/payments/content/payment_request.h" 9 #include "components/payments/content/payment_request.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 15 matching lines...) Expand all
26 InvokePaymentRequestUI(); 26 InvokePaymentRequestUI();
27 OpenPaymentMethodScreen(); 27 OpenPaymentMethodScreen();
28 28
29 views::View* list_view = dialog_view()->GetViewByID( 29 views::View* list_view = dialog_view()->GetViewByID(
30 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW)); 30 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW));
31 EXPECT_TRUE(list_view); 31 EXPECT_TRUE(list_view);
32 EXPECT_FALSE(list_view->has_children()); 32 EXPECT_FALSE(list_view->has_children());
33 } 33 }
34 34
35 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, OneCardSelected) { 35 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, OneCardSelected) {
36 autofill::PersonalDataManager* personal_data_manager = GetDataManager(); 36 const autofill::CreditCard card = autofill::test::GetCreditCard();
37 37 AddCreditCard(card);
38 PersonalDataLoadedObserverMock personal_data_observer;
39 personal_data_manager->AddObserver(&personal_data_observer);
40 base::RunLoop data_loop;
41 EXPECT_CALL(personal_data_observer, OnPersonalDataChanged())
42 .WillOnce(QuitMessageLoop(&data_loop));
43 autofill::CreditCard card = autofill::test::GetCreditCard();
44 personal_data_manager->AddCreditCard(card);
45 data_loop.Run();
46 38
47 InvokePaymentRequestUI(); 39 InvokePaymentRequestUI();
48 OpenPaymentMethodScreen(); 40 OpenPaymentMethodScreen();
49 41
50 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents())[0]; 42 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents())[0];
51 EXPECT_EQ(1U, request->credit_cards().size()); 43 EXPECT_EQ(1U, request->credit_cards().size());
52 44
53 views::View* list_view = dialog_view()->GetViewByID( 45 views::View* list_view = dialog_view()->GetViewByID(
54 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW)); 46 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW));
55 EXPECT_TRUE(list_view); 47 EXPECT_TRUE(list_view);
56 EXPECT_EQ(1, list_view->child_count()); 48 EXPECT_EQ(1, list_view->child_count());
57 49
58 EXPECT_EQ(card, *request->selected_credit_card()); 50 EXPECT_EQ(card, *request->selected_credit_card());
59 views::View* checkmark_view = list_view->child_at(0)->GetViewByID( 51 views::View* checkmark_view = list_view->child_at(0)->GetViewByID(
60 static_cast<int>(DialogViewID::PAYMENT_METHOD_ITEM_CHECKMARK_VIEW)); 52 static_cast<int>(DialogViewID::PAYMENT_METHOD_ITEM_CHECKMARK_VIEW));
61 EXPECT_TRUE(checkmark_view->visible()); 53 EXPECT_TRUE(checkmark_view->visible());
62 } 54 }
63 55
64 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, 56 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest,
65 OneCardSelectedOutOfMany) { 57 OneCardSelectedOutOfMany) {
66 autofill::PersonalDataManager* personal_data_manager = GetDataManager();
67
68 PersonalDataLoadedObserverMock personal_data_observer1;
69 personal_data_manager->AddObserver(&personal_data_observer1);
70 base::RunLoop card1_loop;
71 EXPECT_CALL(personal_data_observer1, OnPersonalDataChanged())
72 .WillOnce(QuitMessageLoop(&card1_loop));
73 autofill::CreditCard card1 = autofill::test::GetCreditCard(); 58 autofill::CreditCard card1 = autofill::test::GetCreditCard();
74 // Ensure that this card is the first suggestion. 59 // Ensure that this card is the first suggestion.
75 card1.set_use_count(5U); 60 card1.set_use_count(5U);
76 personal_data_manager->AddCreditCard(card1); 61 AddCreditCard(card1);
77 card1_loop.Run();
78 personal_data_manager->RemoveObserver(&personal_data_observer1);
79 62
80 EXPECT_EQ(1U, personal_data_manager->GetCreditCardsToSuggest().size());
81
82 PersonalDataLoadedObserverMock personal_data_observer2;
83 personal_data_manager->AddObserver(&personal_data_observer2);
84 base::RunLoop card2_loop;
85 EXPECT_CALL(personal_data_observer2, OnPersonalDataChanged())
86 .WillOnce(QuitMessageLoop(&card2_loop));
87 autofill::CreditCard card2 = autofill::test::GetCreditCard2(); 63 autofill::CreditCard card2 = autofill::test::GetCreditCard2();
88 card2.set_use_count(1U); 64 card2.set_use_count(1U);
89 personal_data_manager->AddCreditCard(card2); 65 AddCreditCard(card2);
90 card2_loop.Run();
91 personal_data_manager->RemoveObserver(&personal_data_observer2);
92 66
93 InvokePaymentRequestUI(); 67 InvokePaymentRequestUI();
94 OpenPaymentMethodScreen(); 68 OpenPaymentMethodScreen();
95 69
96 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents())[0]; 70 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents())[0];
97 EXPECT_EQ(2U, request->credit_cards().size()); 71 EXPECT_EQ(2U, request->credit_cards().size());
98 EXPECT_EQ(card1, *request->selected_credit_card()); 72 EXPECT_EQ(card1, *request->selected_credit_card());
99 73
100 views::View* list_view = dialog_view()->GetViewByID( 74 views::View* list_view = dialog_view()->GetViewByID(
101 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW)); 75 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW));
(...skipping 18 matching lines...) Expand all
120 94
121 // Clicking on the second card again should not modify any state. 95 // Clicking on the second card again should not modify any state.
122 ClickOnDialogViewAndWait(list_view->child_at(1)); 96 ClickOnDialogViewAndWait(list_view->child_at(1));
123 97
124 EXPECT_EQ(card2, *request->selected_credit_card()); 98 EXPECT_EQ(card2, *request->selected_credit_card());
125 EXPECT_FALSE(checkmark_view->visible()); 99 EXPECT_FALSE(checkmark_view->visible());
126 EXPECT_TRUE(checkmark_view2->visible()); 100 EXPECT_TRUE(checkmark_view2->visible());
127 } 101 }
128 102
129 } // namespace payments 103 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698