| 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" |
| 11 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 11 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "components/autofill/core/browser/autofill_profile.h" |
| 14 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 15 #include "components/autofill/core/browser/credit_card.h" |
| 13 #include "components/payments/content/payment_request.h" | 16 #include "components/payments/content/payment_request.h" |
| 14 #include "components/payments/content/payment_request_web_contents_manager.h" | 17 #include "components/payments/content/payment_request_web_contents_manager.h" |
| 15 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 18 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 16 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 17 | 20 |
| 18 namespace payments { | 21 namespace payments { |
| 19 | 22 |
| 20 class PaymentRequestWebContentsManagerTest | 23 class PaymentRequestWebContentsManagerTest |
| 21 : public PaymentRequestBrowserTestBase { | 24 : public PaymentRequestBrowserTestBase { |
| 22 protected: | 25 protected: |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 IN_PROC_BROWSER_TEST_F(PaymentRequestNoShippingTest, OpenAndReload) { | 89 IN_PROC_BROWSER_TEST_F(PaymentRequestNoShippingTest, OpenAndReload) { |
| 87 InvokePaymentRequestUI(); | 90 InvokePaymentRequestUI(); |
| 88 | 91 |
| 89 ResetEventObserver(DialogEvent::DIALOG_CLOSED); | 92 ResetEventObserver(DialogEvent::DIALOG_CLOSED); |
| 90 | 93 |
| 91 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | 94 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 92 | 95 |
| 93 WaitForObservedEvent(); | 96 WaitForObservedEvent(); |
| 94 } | 97 } |
| 95 | 98 |
| 99 IN_PROC_BROWSER_TEST_F(PaymentRequestNoShippingTest, PayWithVisa) { |
| 100 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile(); |
| 101 AddAutofillProfile(billing_address); |
| 102 autofill::CreditCard card = autofill::test::GetCreditCard(); |
| 103 card.set_billing_address_id(billing_address.guid()); |
| 104 AddCreditCard(card); // Visa. |
| 105 |
| 106 InvokePaymentRequestUI(); |
| 107 |
| 108 ResetEventObserver(DialogEvent::DIALOG_CLOSED); |
| 109 |
| 110 ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON); |
| 111 |
| 112 WaitForObservedEvent(); |
| 113 |
| 114 // The actual structure of the card response is unit-tested. |
| 115 ExpectBodyContains(std::vector<base::string16>{ |
| 116 card.GetRawInfo(autofill::CREDIT_CARD_NUMBER), |
| 117 card.GetRawInfo(autofill::CREDIT_CARD_NAME_FULL), |
| 118 card.GetRawInfo(autofill::CREDIT_CARD_EXP_MONTH), |
| 119 card.GetRawInfo(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR)}); |
| 120 ExpectBodyContains(std::vector<base::string16>{ |
| 121 billing_address.GetRawInfo(autofill::NAME_FIRST), |
| 122 billing_address.GetRawInfo(autofill::NAME_LAST), |
| 123 billing_address.GetRawInfo(autofill::ADDRESS_HOME_LINE1), |
| 124 billing_address.GetRawInfo(autofill::ADDRESS_HOME_LINE2), |
| 125 billing_address.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY), |
| 126 billing_address.GetRawInfo(autofill::ADDRESS_HOME_ZIP), |
| 127 billing_address.GetRawInfo(autofill::ADDRESS_HOME_CITY), |
| 128 billing_address.GetRawInfo(autofill::ADDRESS_HOME_STATE)}); |
| 129 } |
| 130 |
| 96 class PaymentRequestAbortTest : public PaymentRequestBrowserTestBase { | 131 class PaymentRequestAbortTest : public PaymentRequestBrowserTestBase { |
| 97 protected: | 132 protected: |
| 98 PaymentRequestAbortTest() | 133 PaymentRequestAbortTest() |
| 99 : PaymentRequestBrowserTestBase("/payment_request_abort_test.html") {} | 134 : PaymentRequestBrowserTestBase("/payment_request_abort_test.html") {} |
| 100 | 135 |
| 101 private: | 136 private: |
| 102 DISALLOW_COPY_AND_ASSIGN(PaymentRequestAbortTest); | 137 DISALLOW_COPY_AND_ASSIGN(PaymentRequestAbortTest); |
| 103 }; | 138 }; |
| 104 | 139 |
| 105 // Testing the use of the abort() JS API. | 140 // Testing the use of the abort() JS API. |
| 106 IN_PROC_BROWSER_TEST_F(PaymentRequestAbortTest, OpenThenAbort) { | 141 IN_PROC_BROWSER_TEST_F(PaymentRequestAbortTest, OpenThenAbort) { |
| 107 InvokePaymentRequestUI(); | 142 InvokePaymentRequestUI(); |
| 108 | 143 |
| 109 ResetEventObserver(DialogEvent::DIALOG_CLOSED); | 144 ResetEventObserver(DialogEvent::DIALOG_CLOSED); |
| 110 | 145 |
| 111 content::WebContents* web_contents = GetActiveWebContents(); | 146 content::WebContents* web_contents = GetActiveWebContents(); |
| 112 const std::string click_buy_button_js = | 147 const std::string click_buy_button_js = |
| 113 "(function() { document.getElementById('abort').click(); })();"; | 148 "(function() { document.getElementById('abort').click(); })();"; |
| 114 ASSERT_TRUE(content::ExecuteScript(web_contents, click_buy_button_js)); | 149 ASSERT_TRUE(content::ExecuteScript(web_contents, click_buy_button_js)); |
| 115 | 150 |
| 116 WaitForObservedEvent(); | 151 WaitForObservedEvent(); |
| 117 | 152 |
| 118 // The web-modal dialog should now be closed. | 153 // The web-modal dialog should now be closed. |
| 119 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 154 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 120 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); | 155 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); |
| 121 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); | 156 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); |
| 122 } | 157 } |
| 123 | 158 |
| 124 } // namespace payments | 159 } // namespace payments |
| OLD | NEW |