| 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 "chrome/browser/ui/browser_commands.h" |
| 7 #include "chrome/browser/ui/views/payments/payment_request_interactive_uitest_ba
se.h" | 8 #include "chrome/browser/ui/views/payments/payment_request_interactive_uitest_ba
se.h" |
| 9 #include "chrome/test/base/ui_test_utils.h" |
| 8 #include "components/payments/payment_request.h" | 10 #include "components/payments/payment_request.h" |
| 9 #include "components/payments/payment_request_web_contents_manager.h" | 11 #include "components/payments/payment_request_web_contents_manager.h" |
| 12 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 13 #include "content/public/test/browser_test_utils.h" |
| 10 | 14 |
| 11 namespace payments { | 15 namespace payments { |
| 12 | 16 |
| 13 class PaymentRequestWebContentsManagerTest | 17 class PaymentRequestWebContentsManagerTest |
| 14 : public PaymentRequestInteractiveTestBase { | 18 : public PaymentRequestInteractiveTestBase { |
| 15 protected: | 19 protected: |
| 16 PaymentRequestWebContentsManagerTest() | 20 PaymentRequestWebContentsManagerTest() |
| 17 : PaymentRequestInteractiveTestBase( | 21 : PaymentRequestInteractiveTestBase( |
| 18 "/payment_request_multiple_requests.html") {} | 22 "/payment_request_multiple_requests.html") {} |
| 19 }; | 23 }; |
| 20 | 24 |
| 21 // If the page creates multiple PaymentRequest objects, it should not crash. | 25 // If the page creates multiple PaymentRequest objects, it should not crash. |
| 22 IN_PROC_BROWSER_TEST_F(PaymentRequestWebContentsManagerTest, MultipleRequests) { | 26 IN_PROC_BROWSER_TEST_F(PaymentRequestWebContentsManagerTest, MultipleRequests) { |
| 23 const std::vector<PaymentRequest*> payment_requests = | 27 const std::vector<PaymentRequest*> payment_requests = |
| 24 GetPaymentRequests(GetActiveWebContents()); | 28 GetPaymentRequests(GetActiveWebContents()); |
| 25 EXPECT_EQ(5U, payment_requests.size()); | 29 EXPECT_EQ(5U, payment_requests.size()); |
| 26 } | 30 } |
| 27 | 31 |
| 28 class PaymentRequestNoShippingTest : public PaymentRequestInteractiveTestBase { | 32 class PaymentRequestNoShippingTest : public PaymentRequestInteractiveTestBase { |
| 29 protected: | 33 protected: |
| 30 PaymentRequestNoShippingTest() | 34 PaymentRequestNoShippingTest() |
| 31 : PaymentRequestInteractiveTestBase( | 35 : PaymentRequestInteractiveTestBase( |
| 32 "/payment_request_no_shipping_test.html") {} | 36 "/payment_request_no_shipping_test.html") {} |
| 33 }; | 37 }; |
| 34 | 38 |
| 35 IN_PROC_BROWSER_TEST_F(PaymentRequestNoShippingTest, OpenPaymentRequestSheet) { | 39 IN_PROC_BROWSER_TEST_F(PaymentRequestNoShippingTest, OpenPaymentRequestSheet) { |
| 36 InvokePaymentRequestUI(); | 40 InvokePaymentRequestUI(); |
| 37 } | 41 } |
| 38 | 42 |
| 43 IN_PROC_BROWSER_TEST_F(PaymentRequestNoShippingTest, OpenAndNavigateTo404) { |
| 44 InvokePaymentRequestUI(); |
| 45 |
| 46 ResetEventObserver(DialogEvent::DIALOG_CLOSED); |
| 47 |
| 48 ui_test_utils::NavigateToURL(browser(), |
| 49 https_server()->GetURL("/non-existent.html")); |
| 50 |
| 51 WaitForObservedEvent(); |
| 52 } |
| 53 |
| 54 IN_PROC_BROWSER_TEST_F(PaymentRequestNoShippingTest, OpenAndNavigateToSame) { |
| 55 InvokePaymentRequestUI(); |
| 56 |
| 57 ResetEventObserver(DialogEvent::DIALOG_CLOSED); |
| 58 |
| 59 ui_test_utils::NavigateToURL( |
| 60 browser(), |
| 61 https_server()->GetURL("/payment_request_no_shipping_test.html")); |
| 62 |
| 63 WaitForObservedEvent(); |
| 64 } |
| 65 |
| 66 IN_PROC_BROWSER_TEST_F(PaymentRequestNoShippingTest, OpenAndReload) { |
| 67 InvokePaymentRequestUI(); |
| 68 |
| 69 ResetEventObserver(DialogEvent::DIALOG_CLOSED); |
| 70 |
| 71 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 72 |
| 73 WaitForObservedEvent(); |
| 74 } |
| 75 |
| 76 class PaymentRequestAbortTest : public PaymentRequestInteractiveTestBase { |
| 77 protected: |
| 78 PaymentRequestAbortTest() |
| 79 : PaymentRequestInteractiveTestBase("/payment_request_abort_test.html") {} |
| 80 }; |
| 81 |
| 82 // Testing the use of the abort() JS API. |
| 83 IN_PROC_BROWSER_TEST_F(PaymentRequestAbortTest, OpenThenAbort) { |
| 84 InvokePaymentRequestUI(); |
| 85 |
| 86 ResetEventObserver(DialogEvent::DIALOG_CLOSED); |
| 87 |
| 88 content::WebContents* web_contents = GetActiveWebContents(); |
| 89 const std::string click_buy_button_js = |
| 90 "(function() { document.getElementById('abort').click(); })();"; |
| 91 ASSERT_TRUE(content::ExecuteScript(web_contents, click_buy_button_js)); |
| 92 |
| 93 WaitForObservedEvent(); |
| 94 |
| 95 // The web-modal dialog should now be closed. |
| 96 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 97 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); |
| 98 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); |
| 99 } |
| 100 |
| 39 } // namespace payments | 101 } // namespace payments |
| OLD | NEW |