| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/views/payments/payment_request_interactive_uitest_ba
se.h" |
| 6 |
| 7 #include <vector> |
| 8 |
| 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/test/base/ui_test_utils.h" |
| 12 #include "components/payments/payment_request.h" |
| 13 #include "components/payments/payment_request_web_contents_manager.h" |
| 14 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/common/content_switches.h" |
| 17 #include "content/public/test/browser_test_utils.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 |
| 20 namespace payments { |
| 21 |
| 22 PaymentRequestInteractiveTestBase::PaymentRequestInteractiveTestBase( |
| 23 const std::string& test_file_path) |
| 24 : test_file_path_(test_file_path) {} |
| 25 PaymentRequestInteractiveTestBase::~PaymentRequestInteractiveTestBase() {} |
| 26 |
| 27 void PaymentRequestInteractiveTestBase::SetUpCommandLine( |
| 28 base::CommandLine* command_line) { |
| 29 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 30 command_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); |
| 31 } |
| 32 |
| 33 void PaymentRequestInteractiveTestBase::SetUpOnMainThread() { |
| 34 https_server_.reset( |
| 35 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
| 36 ASSERT_TRUE(https_server_->InitializeAndListen()); |
| 37 https_server_->ServeFilesFromSourceDirectory("chrome/test/data/payments"); |
| 38 https_server_->StartAcceptingConnections(); |
| 39 |
| 40 GURL url = https_server()->GetURL(test_file_path_); |
| 41 ui_test_utils::NavigateToURL(browser(), url); |
| 42 } |
| 43 |
| 44 void PaymentRequestInteractiveTestBase::InvokePaymentRequestUI() { |
| 45 content::WebContents* web_contents = GetActiveWebContents(); |
| 46 static const std::string kClickBuyButtonJs = |
| 47 "(function() { document.getElementById('buy').click(); })();"; |
| 48 ASSERT_TRUE(content::ExecuteScript(web_contents, kClickBuyButtonJs)); |
| 49 |
| 50 // The web-modal dialog should be open. |
| 51 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 52 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); |
| 53 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); |
| 54 } |
| 55 |
| 56 content::WebContents* |
| 57 PaymentRequestInteractiveTestBase::GetActiveWebContents() { |
| 58 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 59 } |
| 60 |
| 61 const std::vector<PaymentRequest*> |
| 62 PaymentRequestInteractiveTestBase::GetPaymentRequests( |
| 63 content::WebContents* web_contents) { |
| 64 PaymentRequestWebContentsManager* manager = |
| 65 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents); |
| 66 if (!manager) |
| 67 return std::vector<PaymentRequest*>(); |
| 68 |
| 69 std::vector<PaymentRequest*> payment_requests_ptrs; |
| 70 for (const auto& p : manager->payment_requests_) { |
| 71 payment_requests_ptrs.push_back(p.first); |
| 72 } |
| 73 return payment_requests_ptrs; |
| 74 } |
| 75 |
| 76 } // namespace payments |
| OLD | NEW |