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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h" | 9 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h" |
10 #include "components/autofill/core/browser/autofill_test_utils.h" | 10 #include "components/autofill/core/browser/autofill_test_utils.h" |
11 #include "components/autofill/core/browser/credit_card.h" | 11 #include "components/autofill/core/browser/credit_card.h" |
12 #include "content/public/test/browser_test_utils.h" | 12 #include "content/public/test/browser_test_utils.h" |
13 | 13 |
14 namespace payments { | 14 namespace payments { |
15 | 15 |
16 class PaymentRequestCanMakePaymentQueryTest | 16 class PaymentRequestCanMakePaymentQueryTest |
Mathieu
2017/04/17 03:20:45
could we add a test for an invalid ssl page, expec
please use gerrit instead
2017/04/17 18:19:54
Done.
| |
17 : public PaymentRequestBrowserTestBase { | 17 : public PaymentRequestBrowserTestBase { |
18 protected: | 18 protected: |
19 PaymentRequestCanMakePaymentQueryTest() | 19 PaymentRequestCanMakePaymentQueryTest() |
20 : PaymentRequestBrowserTestBase( | 20 : PaymentRequestBrowserTestBase( |
21 "/payment_request_can_make_payment_query_test.html") {} | 21 "/payment_request_can_make_payment_query_test.html") {} |
22 | 22 |
23 void CallCanMakePayment() { | 23 void CallCanMakePayment() { |
24 ResetEventObserver(DialogEvent::CAN_MAKE_PAYMENT_CALLED); | 24 ResetEventObserver(DialogEvent::CAN_MAKE_PAYMENT_CALLED); |
25 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "buy();")); | 25 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "buy();")); |
26 WaitForObservedEvent(); | 26 WaitForObservedEvent(); |
27 } | 27 } |
28 | 28 |
29 private: | 29 private: |
30 DISALLOW_COPY_AND_ASSIGN(PaymentRequestCanMakePaymentQueryTest); | 30 DISALLOW_COPY_AND_ASSIGN(PaymentRequestCanMakePaymentQueryTest); |
31 }; | 31 }; |
32 | 32 |
33 // Visa is required, and user has a visa instrument. | 33 // Visa is required, and user has a visa instrument. |
34 IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest, | 34 IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest, |
35 CanMakePayment_Supported) { | 35 CanMakePayment_Supported) { |
36 const autofill::CreditCard card = autofill::test::GetCreditCard(); // Visa. | 36 const autofill::CreditCard card = autofill::test::GetCreditCard(); // Visa. |
37 AddCreditCard(card); | 37 AddCreditCard(card); |
38 | 38 |
39 CallCanMakePayment(); | 39 CallCanMakePayment(); |
40 | 40 |
41 ExpectBodyContains(std::vector<base::string16>{base::ASCIIToUTF16("true")}); | 41 ExpectBodyContains({"true"}); |
42 } | 42 } |
43 | 43 |
44 // Visa is required, user has a visa instrument, and user is in incognito | 44 // Visa is required, user has a visa instrument, and user is in incognito |
45 // mode. | 45 // mode. |
46 IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest, | 46 IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest, |
47 CanMakePayment_Supported_InIncognitoMode) { | 47 CanMakePayment_Supported_InIncognitoMode) { |
48 SetIncognitoForTesting(); | 48 SetIncognitoForTesting(); |
49 | 49 |
50 const autofill::CreditCard card = autofill::test::GetCreditCard(); // Visa. | 50 const autofill::CreditCard card = autofill::test::GetCreditCard(); // Visa. |
51 AddCreditCard(card); | 51 AddCreditCard(card); |
52 | 52 |
53 CallCanMakePayment(); | 53 CallCanMakePayment(); |
54 | 54 |
55 ExpectBodyContains(std::vector<base::string16>{base::ASCIIToUTF16("true")}); | 55 ExpectBodyContains({"true"}); |
56 } | 56 } |
57 | 57 |
58 // Visa is required, and user doesn't have a visa instrument. | 58 // Visa is required, and user doesn't have a visa instrument. |
59 IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest, | 59 IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest, |
60 CanMakePayment_NotSupported) { | 60 CanMakePayment_NotSupported) { |
61 const autofill::CreditCard card = autofill::test::GetCreditCard2(); // Amex. | 61 const autofill::CreditCard card = autofill::test::GetCreditCard2(); // Amex. |
62 AddCreditCard(card); | 62 AddCreditCard(card); |
63 | 63 |
64 CallCanMakePayment(); | 64 CallCanMakePayment(); |
65 | 65 |
66 ExpectBodyContains(std::vector<base::string16>{base::ASCIIToUTF16("false")}); | 66 ExpectBodyContains({"false"}); |
67 } | 67 } |
68 | 68 |
69 // Visa is required, user doesn't have a visa instrument and the user is in | 69 // Visa is required, user doesn't have a visa instrument and the user is in |
70 // incognito mode. In this case canMakePayment always returns true. | 70 // incognito mode. In this case canMakePayment always returns true. |
71 IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest, | 71 IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest, |
72 CanMakePayment_NotSupported_InIncognitoMode) { | 72 CanMakePayment_NotSupported_InIncognitoMode) { |
73 SetIncognitoForTesting(); | 73 SetIncognitoForTesting(); |
74 | 74 |
75 const autofill::CreditCard card = autofill::test::GetCreditCard2(); // Amex. | 75 const autofill::CreditCard card = autofill::test::GetCreditCard2(); // Amex. |
76 AddCreditCard(card); | 76 AddCreditCard(card); |
77 | 77 |
78 CallCanMakePayment(); | 78 CallCanMakePayment(); |
79 | 79 |
80 // Returns true because the user is in incognito mode, even though it should | 80 // Returns true because the user is in incognito mode, even though it should |
81 // return false in a normal profile. | 81 // return false in a normal profile. |
82 ExpectBodyContains(std::vector<base::string16>{base::ASCIIToUTF16("true")}); | 82 ExpectBodyContains({"true"}); |
83 } | 83 } |
84 | 84 |
85 } // namespace payments | 85 } // namespace payments |
OLD | NEW |