| 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/browser_commands.h" | 9 #include "chrome/browser/ui/browser_commands.h" |
| 10 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h" | 10 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 ASSERT_TRUE(content::ExecuteScript(web_contents, click_buy_button_js)); | 149 ASSERT_TRUE(content::ExecuteScript(web_contents, click_buy_button_js)); |
| 150 | 150 |
| 151 WaitForObservedEvent(); | 151 WaitForObservedEvent(); |
| 152 | 152 |
| 153 // The web-modal dialog should now be closed. | 153 // The web-modal dialog should now be closed. |
| 154 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 154 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 155 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); | 155 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); |
| 156 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); | 156 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); |
| 157 } | 157 } |
| 158 | 158 |
| 159 class PaymentRequestBasicCardTest : public PaymentRequestBrowserTestBase { |
| 160 protected: |
| 161 PaymentRequestBasicCardTest() |
| 162 : PaymentRequestBrowserTestBase("/payment_request_basic_card_test.html") { |
| 163 } |
| 164 |
| 165 void InvokePaymentRequestWithJs(const std::string& js) { |
| 166 ResetEventObserver(DialogEvent::DIALOG_OPENED); |
| 167 |
| 168 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), js)); |
| 169 |
| 170 WaitForObservedEvent(); |
| 171 } |
| 172 |
| 173 private: |
| 174 DISALLOW_COPY_AND_ASSIGN(PaymentRequestBasicCardTest); |
| 175 }; |
| 176 |
| 177 // One network is specified in 'basic-card' data, one in supportedMethods. |
| 178 IN_PROC_BROWSER_TEST_F(PaymentRequestBasicCardTest, |
| 179 BasicCard_NetworksSpecified) { |
| 180 InvokePaymentRequestWithJs("buy();"); |
| 181 |
| 182 std::vector<PaymentRequest*> requests = |
| 183 GetPaymentRequests(GetActiveWebContents()); |
| 184 EXPECT_EQ(1u, requests.size()); |
| 185 std::vector<std::string> supported_card_networks = |
| 186 requests[0]->spec()->supported_card_networks(); |
| 187 EXPECT_EQ(2u, supported_card_networks.size()); |
| 188 // The networks appear in the order in which they were specified by the |
| 189 // merchant. |
| 190 EXPECT_EQ("mastercard", supported_card_networks[0]); |
| 191 EXPECT_EQ("visa", supported_card_networks[1]); |
| 192 } |
| 193 |
| 194 // Only specifying 'basic-card' with no supportedNetworks means all networks are |
| 195 // supported. |
| 196 IN_PROC_BROWSER_TEST_F(PaymentRequestBasicCardTest, |
| 197 BasicCard_NoNetworksSpecified) { |
| 198 InvokePaymentRequestWithJs("buyBasicCard();"); |
| 199 |
| 200 std::vector<PaymentRequest*> requests = |
| 201 GetPaymentRequests(GetActiveWebContents()); |
| 202 EXPECT_EQ(1u, requests.size()); |
| 203 std::vector<std::string> supported_card_networks = |
| 204 requests[0]->spec()->supported_card_networks(); |
| 205 // The default ordering is alphabetical. |
| 206 EXPECT_EQ(8u, supported_card_networks.size()); |
| 207 EXPECT_EQ("amex", supported_card_networks[0]); |
| 208 EXPECT_EQ("diners", supported_card_networks[1]); |
| 209 EXPECT_EQ("discover", supported_card_networks[2]); |
| 210 EXPECT_EQ("jcb", supported_card_networks[3]); |
| 211 EXPECT_EQ("mastercard", supported_card_networks[4]); |
| 212 EXPECT_EQ("mir", supported_card_networks[5]); |
| 213 EXPECT_EQ("unionpay", supported_card_networks[6]); |
| 214 EXPECT_EQ("visa", supported_card_networks[7]); |
| 215 } |
| 216 |
| 217 // Specifying 'basic-card' after having explicitely included a network yields |
| 218 // the expected order when in different supportedMethods lists. |
| 219 IN_PROC_BROWSER_TEST_F(PaymentRequestBasicCardTest, |
| 220 BasicCard_NetworkThenBasicCard_DifferentList) { |
| 221 InvokePaymentRequestWithJs( |
| 222 "buyHelper([{" |
| 223 " supportedMethods: ['mastercard']," |
| 224 "}, {" |
| 225 " supportedMethods: ['basic-card']" |
| 226 "}]);"); |
| 227 |
| 228 std::vector<PaymentRequest*> requests = |
| 229 GetPaymentRequests(GetActiveWebContents()); |
| 230 EXPECT_EQ(1u, requests.size()); |
| 231 std::vector<std::string> supported_card_networks = |
| 232 requests[0]->spec()->supported_card_networks(); |
| 233 // 'mastercard' is first because it was explicitely specified first. The rest |
| 234 // is alphabetical. |
| 235 EXPECT_EQ(8u, supported_card_networks.size()); |
| 236 EXPECT_EQ("mastercard", supported_card_networks[0]); |
| 237 EXPECT_EQ("amex", supported_card_networks[1]); |
| 238 EXPECT_EQ("diners", supported_card_networks[2]); |
| 239 EXPECT_EQ("discover", supported_card_networks[3]); |
| 240 EXPECT_EQ("jcb", supported_card_networks[4]); |
| 241 EXPECT_EQ("mir", supported_card_networks[5]); |
| 242 EXPECT_EQ("unionpay", supported_card_networks[6]); |
| 243 EXPECT_EQ("visa", supported_card_networks[7]); |
| 244 } |
| 245 |
| 246 // Specifying 'basic-card' after having explicitely included a network yields |
| 247 // the expected order when in the same supportedMethods list. |
| 248 IN_PROC_BROWSER_TEST_F(PaymentRequestBasicCardTest, |
| 249 BasicCard_NetworkThenBasicCard_SameList) { |
| 250 InvokePaymentRequestWithJs( |
| 251 "buyHelper([{" |
| 252 " supportedMethods: ['visa', 'basic-card']" |
| 253 "}]);"); |
| 254 |
| 255 std::vector<PaymentRequest*> requests = |
| 256 GetPaymentRequests(GetActiveWebContents()); |
| 257 EXPECT_EQ(1u, requests.size()); |
| 258 std::vector<std::string> supported_card_networks = |
| 259 requests[0]->spec()->supported_card_networks(); |
| 260 // 'visa' is first because it was explicitely specified first. The rest |
| 261 // is alphabetical. |
| 262 EXPECT_EQ(8u, supported_card_networks.size()); |
| 263 EXPECT_EQ("visa", supported_card_networks[0]); |
| 264 EXPECT_EQ("amex", supported_card_networks[1]); |
| 265 EXPECT_EQ("diners", supported_card_networks[2]); |
| 266 EXPECT_EQ("discover", supported_card_networks[3]); |
| 267 EXPECT_EQ("jcb", supported_card_networks[4]); |
| 268 EXPECT_EQ("mastercard", supported_card_networks[5]); |
| 269 EXPECT_EQ("mir", supported_card_networks[6]); |
| 270 EXPECT_EQ("unionpay", supported_card_networks[7]); |
| 271 } |
| 272 |
| 273 // Specifying 'basic-card' with some networks after having explicitely included |
| 274 // the same networks does not yield duplicates and has the expected order. |
| 275 IN_PROC_BROWSER_TEST_F(PaymentRequestBasicCardTest, |
| 276 BasicCard_NetworkThenBasicCardWithSameNetwork) { |
| 277 InvokePaymentRequestWithJs( |
| 278 "buyHelper([{" |
| 279 " supportedMethods: ['mastercard', 'visa']" |
| 280 "}, {" |
| 281 " supportedMethods: ['basic-card']," |
| 282 " data: {" |
| 283 " supportedNetworks: ['visa', 'mastercard', 'jcb']," |
| 284 " }" |
| 285 "}]);"); |
| 286 |
| 287 std::vector<PaymentRequest*> requests = |
| 288 GetPaymentRequests(GetActiveWebContents()); |
| 289 EXPECT_EQ(1u, requests.size()); |
| 290 std::vector<std::string> supported_card_networks = |
| 291 requests[0]->spec()->supported_card_networks(); |
| 292 EXPECT_EQ(3u, supported_card_networks.size()); |
| 293 EXPECT_EQ("mastercard", supported_card_networks[0]); |
| 294 EXPECT_EQ("visa", supported_card_networks[1]); |
| 295 EXPECT_EQ("jcb", supported_card_networks[2]); |
| 296 } |
| 297 |
| 159 } // namespace payments | 298 } // namespace payments |
| OLD | NEW |