| 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" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 const autofill::CreditCard card = autofill::test::GetCreditCard2(); // Amex. | 89 const autofill::CreditCard card = autofill::test::GetCreditCard2(); // Amex. |
| 90 AddCreditCard(card); | 90 AddCreditCard(card); |
| 91 | 91 |
| 92 CallCanMakePayment(); | 92 CallCanMakePayment(); |
| 93 | 93 |
| 94 // Returns true because the user is in incognito mode, even though it should | 94 // Returns true because the user is in incognito mode, even though it should |
| 95 // return false in a normal profile. | 95 // return false in a normal profile. |
| 96 ExpectBodyContains({"true"}); | 96 ExpectBodyContains({"true"}); |
| 97 } | 97 } |
| 98 | 98 |
| 99 class PaymentRequestCanMakePaymentQueryCCTest |
| 100 : public PaymentRequestBrowserTestBase { |
| 101 protected: |
| 102 PaymentRequestCanMakePaymentQueryCCTest() |
| 103 : PaymentRequestBrowserTestBase( |
| 104 "/payment_request_can_make_payment_query_cc_test.html") {} |
| 105 |
| 106 void CallCanMakePayment(bool visa) { |
| 107 ResetEventObserver(DialogEvent::CAN_MAKE_PAYMENT_CALLED); |
| 108 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), |
| 109 visa ? "buy();" : "other_buy();")); |
| 110 WaitForObservedEvent(); |
| 111 } |
| 112 |
| 113 private: |
| 114 DISALLOW_COPY_AND_ASSIGN(PaymentRequestCanMakePaymentQueryCCTest); |
| 115 }; |
| 116 |
| 117 IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryCCTest, QueryQuota) { |
| 118 // Query "visa" payment method. |
| 119 CallCanMakePayment(/*visa=*/true); |
| 120 |
| 121 // User does not have a visa card. |
| 122 ExpectBodyContains({"false"}); |
| 123 |
| 124 // Query "mastercard" payment method. |
| 125 CallCanMakePayment(/*visa=*/false); |
| 126 |
| 127 // Query quota exceeded. |
| 128 ExpectBodyContains({"NotAllowedError"}); |
| 129 |
| 130 AddCreditCard(autofill::test::GetCreditCard()); // visa |
| 131 |
| 132 // Query "visa" payment method. |
| 133 CallCanMakePayment(/*visa=*/true); |
| 134 |
| 135 // User now has a visa card. The query is cached, but the result is always |
| 136 // fresh. |
| 137 ExpectBodyContains({"true"}); |
| 138 |
| 139 // Query "mastercard" payment method. |
| 140 CallCanMakePayment(/*visa=*/false); |
| 141 |
| 142 // Query quota exceeded. |
| 143 ExpectBodyContains({"NotAllowedError"}); |
| 144 } |
| 145 |
| 146 class PaymentRequestCanMakePaymentQueryBasicCardTest |
| 147 : public PaymentRequestBrowserTestBase { |
| 148 protected: |
| 149 PaymentRequestCanMakePaymentQueryBasicCardTest() |
| 150 : PaymentRequestBrowserTestBase("/payment_request_basic_card_test.html") { |
| 151 } |
| 152 |
| 153 void CallCanMakePayment(bool visa) { |
| 154 ResetEventObserver(DialogEvent::CAN_MAKE_PAYMENT_CALLED); |
| 155 ASSERT_TRUE(content::ExecuteScript( |
| 156 GetActiveWebContents(), |
| 157 visa ? "checkBasicVisa();" : "checkBasicCard();")); |
| 158 WaitForObservedEvent(); |
| 159 } |
| 160 |
| 161 private: |
| 162 DISALLOW_COPY_AND_ASSIGN(PaymentRequestCanMakePaymentQueryBasicCardTest); |
| 163 }; |
| 164 |
| 165 IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryBasicCardTest, |
| 166 QueryQuota) { |
| 167 // Query "basic-card" payment method with "supportedNetworks": ["visa"] in the |
| 168 // payment method specific data. |
| 169 CallCanMakePayment(/*visa=*/true); |
| 170 |
| 171 // User does not have a visa card. |
| 172 ExpectBodyContains({"false"}); |
| 173 |
| 174 // Query "basic-card" payment method without "supportedNetworks" parameter. |
| 175 CallCanMakePayment(/*visa=*/false); |
| 176 |
| 177 // Query quota exceeded. |
| 178 ExpectBodyContains({"NotAllowedError"}); |
| 179 |
| 180 AddCreditCard(autofill::test::GetCreditCard()); // visa |
| 181 |
| 182 // Query "basic-card" payment method with "supportedNetworks": ["visa"] in the |
| 183 // payment method specific data. |
| 184 CallCanMakePayment(/*visa=*/true); |
| 185 |
| 186 // User now has a visa card. The query is cached, but the result is always |
| 187 // fresh. |
| 188 ExpectBodyContains({"true"}); |
| 189 |
| 190 // Query "basic-card" payment method without "supportedNetworks" parameter. |
| 191 CallCanMakePayment(/*visa=*/false); |
| 192 |
| 193 // Query quota exceeded. |
| 194 ExpectBodyContains({"NotAllowedError"}); |
| 195 } |
| 196 |
| 99 } // namespace payments | 197 } // namespace payments |
| OLD | NEW |