OLD | NEW |
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 "base/strings/utf_string_conversions.h" |
6 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h" | 6 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h" |
7 #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" |
8 #include "components/autofill/core/browser/autofill_test_utils.h" | 8 #include "components/autofill/core/browser/autofill_test_utils.h" |
9 #include "components/autofill/core/browser/personal_data_manager.h" | 9 #include "components/autofill/core/browser/personal_data_manager.h" |
10 #include "components/payments/content/payment_request.h" | 10 #include "components/payments/content/payment_request.h" |
11 #include "components/payments/content/payment_request_state.h" | 11 #include "components/payments/content/payment_request_state.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace payments { | 14 namespace payments { |
15 | 15 |
16 class PaymentMethodViewControllerTest : public PaymentRequestBrowserTestBase { | 16 class PaymentMethodViewControllerTest : public PaymentRequestBrowserTestBase { |
17 protected: | 17 protected: |
18 PaymentMethodViewControllerTest() | 18 PaymentMethodViewControllerTest() |
19 : PaymentRequestBrowserTestBase( | 19 : PaymentRequestBrowserTestBase( |
20 "/payment_request_no_shipping_test.html") {} | 20 "/payment_request_no_shipping_test.html") {} |
21 | 21 |
22 private: | 22 private: |
23 DISALLOW_COPY_AND_ASSIGN(PaymentMethodViewControllerTest); | 23 DISALLOW_COPY_AND_ASSIGN(PaymentMethodViewControllerTest); |
24 }; | 24 }; |
25 | 25 |
26 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, OneCardSelected) { | 26 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, OneCardSelected) { |
27 const autofill::CreditCard card = autofill::test::GetCreditCard(); | 27 autofill::AutofillProfile billing_profile(autofill::test::GetFullProfile()); |
| 28 PaymentRequestBrowserTestBase::AddAutofillProfile(billing_profile); |
| 29 autofill::CreditCard card = autofill::test::GetCreditCard(); |
| 30 card.set_billing_address_id(billing_profile.guid()); |
28 AddCreditCard(card); | 31 AddCreditCard(card); |
29 | 32 |
30 InvokePaymentRequestUI(); | 33 InvokePaymentRequestUI(); |
31 OpenPaymentMethodScreen(); | 34 OpenPaymentMethodScreen(); |
32 | 35 |
33 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents()).front(); | 36 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents()).front(); |
34 EXPECT_EQ(1U, request->state()->available_instruments().size()); | 37 EXPECT_EQ(1U, request->state()->available_instruments().size()); |
35 | 38 |
36 views::View* list_view = dialog_view()->GetViewByID( | 39 views::View* list_view = dialog_view()->GetViewByID( |
37 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW)); | 40 static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW)); |
38 EXPECT_TRUE(list_view); | 41 EXPECT_TRUE(list_view); |
39 EXPECT_EQ(1, list_view->child_count()); | 42 EXPECT_EQ(1, list_view->child_count()); |
40 | 43 |
41 EXPECT_EQ(request->state()->available_instruments().front().get(), | 44 EXPECT_EQ(request->state()->available_instruments().front().get(), |
42 request->state()->selected_instrument()); | 45 request->state()->selected_instrument()); |
43 views::View* checkmark_view = list_view->child_at(0)->GetViewByID( | 46 views::View* checkmark_view = list_view->child_at(0)->GetViewByID( |
44 static_cast<int>(DialogViewID::CHECKMARK_VIEW)); | 47 static_cast<int>(DialogViewID::CHECKMARK_VIEW)); |
45 EXPECT_TRUE(checkmark_view->visible()); | 48 EXPECT_TRUE(checkmark_view->visible()); |
46 } | 49 } |
47 | 50 |
48 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, | 51 IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, |
49 OneCardSelectedOutOfMany) { | 52 OneCardSelectedOutOfMany) { |
| 53 autofill::AutofillProfile billing_profile(autofill::test::GetFullProfile()); |
| 54 PaymentRequestBrowserTestBase::AddAutofillProfile(billing_profile); |
| 55 |
50 autofill::CreditCard card1 = autofill::test::GetCreditCard(); | 56 autofill::CreditCard card1 = autofill::test::GetCreditCard(); |
| 57 card1.set_billing_address_id(billing_profile.guid()); |
| 58 |
51 // Ensure that this card is the first suggestion. | 59 // Ensure that this card is the first suggestion. |
52 card1.set_use_count(5U); | 60 card1.set_use_count(5U); |
53 AddCreditCard(card1); | 61 AddCreditCard(card1); |
54 | 62 |
55 // Slightly different visa. | 63 // Slightly different visa. |
56 autofill::CreditCard card2 = autofill::test::GetCreditCard(); | 64 autofill::CreditCard card2 = autofill::test::GetCreditCard(); |
57 card2.SetNumber(base::ASCIIToUTF16("4111111111111112")); | 65 card2.SetNumber(base::ASCIIToUTF16("4111111111111112")); |
| 66 card2.set_billing_address_id(billing_profile.guid()); |
58 card2.set_use_count(1U); | 67 card2.set_use_count(1U); |
59 AddCreditCard(card2); | 68 AddCreditCard(card2); |
60 | 69 |
61 InvokePaymentRequestUI(); | 70 InvokePaymentRequestUI(); |
62 OpenPaymentMethodScreen(); | 71 OpenPaymentMethodScreen(); |
63 | 72 |
64 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents()).front(); | 73 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents()).front(); |
65 EXPECT_EQ(2U, request->state()->available_instruments().size()); | 74 EXPECT_EQ(2U, request->state()->available_instruments().size()); |
66 EXPECT_EQ(request->state()->available_instruments().front().get(), | 75 EXPECT_EQ(request->state()->available_instruments().front().get(), |
67 request->state()->selected_instrument()); | 76 request->state()->selected_instrument()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 checkmark_view2 = list_view->child_at(1)->GetViewByID( | 108 checkmark_view2 = list_view->child_at(1)->GetViewByID( |
100 static_cast<int>(DialogViewID::CHECKMARK_VIEW)); | 109 static_cast<int>(DialogViewID::CHECKMARK_VIEW)); |
101 EXPECT_FALSE(checkmark_view->visible()); | 110 EXPECT_FALSE(checkmark_view->visible()); |
102 EXPECT_TRUE(checkmark_view2->visible()); | 111 EXPECT_TRUE(checkmark_view2->visible()); |
103 | 112 |
104 EXPECT_EQ(request->state()->available_instruments().back().get(), | 113 EXPECT_EQ(request->state()->available_instruments().back().get(), |
105 request->state()->selected_instrument()); | 114 request->state()->selected_instrument()); |
106 } | 115 } |
107 | 116 |
108 } // namespace payments | 117 } // namespace payments |
OLD | NEW |