| Index: chrome/browser/ui/views/payments/payment_request_interactive_uitest_base.cc
|
| diff --git a/chrome/browser/ui/views/payments/payment_request_interactive_uitest_base.cc b/chrome/browser/ui/views/payments/payment_request_interactive_uitest_base.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e13163a52152dd4a42b5ad0d7f22d941d182b6bb
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/views/payments/payment_request_interactive_uitest_base.cc
|
| @@ -0,0 +1,76 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ui/views/payments/payment_request_interactive_uitest_base.h"
|
| +
|
| +#include <vector>
|
| +
|
| +#include "chrome/browser/ui/browser.h"
|
| +#include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| +#include "chrome/test/base/ui_test_utils.h"
|
| +#include "components/payments/payment_request.h"
|
| +#include "components/payments/payment_request_web_contents_manager.h"
|
| +#include "components/web_modal/web_contents_modal_dialog_manager.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +#include "content/public/common/content_switches.h"
|
| +#include "content/public/test/browser_test_utils.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace payments {
|
| +
|
| +PaymentRequestInteractiveTestBase::PaymentRequestInteractiveTestBase(
|
| + const std::string& test_file_path)
|
| + : test_file_path_(test_file_path) {}
|
| +PaymentRequestInteractiveTestBase::~PaymentRequestInteractiveTestBase() {}
|
| +
|
| +void PaymentRequestInteractiveTestBase::SetUpCommandLine(
|
| + base::CommandLine* command_line) {
|
| + InProcessBrowserTest::SetUpCommandLine(command_line);
|
| + command_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures);
|
| +}
|
| +
|
| +void PaymentRequestInteractiveTestBase::SetUpOnMainThread() {
|
| + https_server_.reset(
|
| + new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS));
|
| + ASSERT_TRUE(https_server_->InitializeAndListen());
|
| + https_server_->ServeFilesFromSourceDirectory("chrome/test/data/payments");
|
| + https_server_->StartAcceptingConnections();
|
| +
|
| + GURL url = https_server()->GetURL(test_file_path_);
|
| + ui_test_utils::NavigateToURL(browser(), url);
|
| +}
|
| +
|
| +void PaymentRequestInteractiveTestBase::InvokePaymentRequestUI() {
|
| + content::WebContents* web_contents = GetActiveWebContents();
|
| + static const std::string kClickBuyButtonJs =
|
| + "(function() { document.getElementById('buy').click(); })();";
|
| + ASSERT_TRUE(content::ExecuteScript(web_contents, kClickBuyButtonJs));
|
| +
|
| + // The web-modal dialog should be open.
|
| + web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager =
|
| + web_modal::WebContentsModalDialogManager::FromWebContents(web_contents);
|
| + EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive());
|
| +}
|
| +
|
| +content::WebContents*
|
| +PaymentRequestInteractiveTestBase::GetActiveWebContents() {
|
| + return browser()->tab_strip_model()->GetActiveWebContents();
|
| +}
|
| +
|
| +const std::vector<PaymentRequest*>
|
| +PaymentRequestInteractiveTestBase::GetPaymentRequests(
|
| + content::WebContents* web_contents) {
|
| + PaymentRequestWebContentsManager* manager =
|
| + PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents);
|
| + if (!manager)
|
| + return std::vector<PaymentRequest*>();
|
| +
|
| + std::vector<PaymentRequest*> payment_requests_ptrs;
|
| + for (const auto& p : manager->payment_requests_) {
|
| + payment_requests_ptrs.push_back(p.first);
|
| + }
|
| + return payment_requests_ptrs;
|
| +}
|
| +
|
| +} // namespace payments
|
|
|