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

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

Issue 2757523002: [Payments] Use PaymentInstrument/AutofillPaymentInstrument throughout. (Closed)
Patch Set: addressed nits 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 "base/strings/utf_string_conversions.h"
5 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h" 6 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h"
6 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 7 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
7 #include "components/autofill/core/browser/autofill_test_utils.h" 8 #include "components/autofill/core/browser/autofill_test_utils.h"
8 #include "components/autofill/core/browser/personal_data_manager.h" 9 #include "components/autofill/core/browser/personal_data_manager.h"
9 #include "components/payments/content/payment_request.h" 10 #include "components/payments/content/payment_request.h"
10 #include "components/payments/content/payment_request_state.h" 11 #include "components/payments/content/payment_request_state.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace payments { 14 namespace payments {
14 15
(...skipping 17 matching lines...) Expand all
32 EXPECT_FALSE(list_view->has_children()); 33 EXPECT_FALSE(list_view->has_children());
33 } 34 }
34 35
35 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, OneCardSelected) { 36 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, OneCardSelected) {
36 const autofill::CreditCard card = autofill::test::GetCreditCard(); 37 const autofill::CreditCard card = autofill::test::GetCreditCard();
37 AddCreditCard(card); 38 AddCreditCard(card);
38 39
39 InvokePaymentRequestUI(); 40 InvokePaymentRequestUI();
40 OpenPaymentMethodScreen(); 41 OpenPaymentMethodScreen();
41 42
42 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents())[0]; 43 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents()).front();
43 EXPECT_EQ(1U, request->state()->credit_cards().size()); 44 EXPECT_EQ(1U, request->state()->available_instruments().size());
44 45
45 views::View* list_view = dialog_view()->GetViewByID( 46 views::View* list_view = dialog_view()->GetViewByID(
46 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW)); 47 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW));
47 EXPECT_TRUE(list_view); 48 EXPECT_TRUE(list_view);
48 EXPECT_EQ(1, list_view->child_count()); 49 EXPECT_EQ(1, list_view->child_count());
49 50
50 EXPECT_EQ(card, *request->state()->selected_credit_card()); 51 EXPECT_EQ(request->state()->available_instruments().front().get(),
52 request->state()->selected_instrument());
51 views::View* checkmark_view = list_view->child_at(0)->GetViewByID( 53 views::View* checkmark_view = list_view->child_at(0)->GetViewByID(
52 static_cast<int>(DialogViewID::CHECKMARK_VIEW)); 54 static_cast<int>(DialogViewID::CHECKMARK_VIEW));
53 EXPECT_TRUE(checkmark_view->visible()); 55 EXPECT_TRUE(checkmark_view->visible());
54 } 56 }
55 57
56 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, 58 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest,
57 OneCardSelectedOutOfMany) { 59 OneCardSelectedOutOfMany) {
58 autofill::CreditCard card1 = autofill::test::GetCreditCard(); 60 autofill::CreditCard card1 = autofill::test::GetCreditCard();
59 // Ensure that this card is the first suggestion. 61 // Ensure that this card is the first suggestion.
60 card1.set_use_count(5U); 62 card1.set_use_count(5U);
61 AddCreditCard(card1); 63 AddCreditCard(card1);
62 64
63 autofill::CreditCard card2 = autofill::test::GetCreditCard2(); 65 // Slightly different visa.
66 autofill::CreditCard card2 = autofill::test::GetCreditCard();
67 card2.SetNumber(base::ASCIIToUTF16("4111111111111112"));
64 card2.set_use_count(1U); 68 card2.set_use_count(1U);
65 AddCreditCard(card2); 69 AddCreditCard(card2);
66 70
67 InvokePaymentRequestUI(); 71 InvokePaymentRequestUI();
68 OpenPaymentMethodScreen(); 72 OpenPaymentMethodScreen();
69 73
70 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents())[0]; 74 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents()).front();
71 EXPECT_EQ(2U, request->state()->credit_cards().size()); 75 EXPECT_EQ(2U, request->state()->available_instruments().size());
72 EXPECT_EQ(card1, *request->state()->selected_credit_card()); 76 EXPECT_EQ(request->state()->available_instruments().front().get(),
77 request->state()->selected_instrument());
73 78
74 views::View* list_view = dialog_view()->GetViewByID( 79 views::View* list_view = dialog_view()->GetViewByID(
75 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW)); 80 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW));
76 EXPECT_TRUE(list_view); 81 EXPECT_TRUE(list_view);
77 EXPECT_EQ(2, list_view->child_count()); 82 EXPECT_EQ(2, list_view->child_count());
78 83
79 EXPECT_EQ(card1, *request->state()->selected_credit_card()); 84 EXPECT_EQ(request->state()->available_instruments().front().get(),
85 request->state()->selected_instrument());
80 views::View* checkmark_view = list_view->child_at(0)->GetViewByID( 86 views::View* checkmark_view = list_view->child_at(0)->GetViewByID(
81 static_cast<int>(DialogViewID::CHECKMARK_VIEW)); 87 static_cast<int>(DialogViewID::CHECKMARK_VIEW));
82 EXPECT_TRUE(checkmark_view->visible()); 88 EXPECT_TRUE(checkmark_view->visible());
83 89
84 views::View* checkmark_view2 = list_view->child_at(1)->GetViewByID( 90 views::View* checkmark_view2 = list_view->child_at(1)->GetViewByID(
85 static_cast<int>(DialogViewID::CHECKMARK_VIEW)); 91 static_cast<int>(DialogViewID::CHECKMARK_VIEW));
86 EXPECT_FALSE(checkmark_view2->visible()); 92 EXPECT_FALSE(checkmark_view2->visible());
87 93
88 // Simulate selecting the second card. 94 // Simulate selecting the second card.
89 ClickOnDialogViewAndWait(list_view->child_at(1)); 95 ClickOnDialogViewAndWait(list_view->child_at(1));
90 96
91 EXPECT_EQ(card2, *request->state()->selected_credit_card()); 97 EXPECT_EQ(request->state()->available_instruments().back().get(),
98 request->state()->selected_instrument());
92 EXPECT_FALSE(checkmark_view->visible()); 99 EXPECT_FALSE(checkmark_view->visible());
93 EXPECT_TRUE(checkmark_view2->visible()); 100 EXPECT_TRUE(checkmark_view2->visible());
94 101
95 // Clicking on the second card again should not modify any state. 102 // Clicking on the second card again should not modify any state.
96 ClickOnDialogViewAndWait(list_view->child_at(1)); 103 ClickOnDialogViewAndWait(list_view->child_at(1));
97 104
98 EXPECT_EQ(card2, *request->state()->selected_credit_card()); 105 EXPECT_EQ(request->state()->available_instruments().back().get(),
106 request->state()->selected_instrument());
99 EXPECT_FALSE(checkmark_view->visible()); 107 EXPECT_FALSE(checkmark_view->visible());
100 EXPECT_TRUE(checkmark_view2->visible()); 108 EXPECT_TRUE(checkmark_view2->visible());
101 } 109 }
102 110
103 } // namespace payments 111 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698