1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "base/command_line.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "url/gurl.h"
#include "url/url_constants.h"
namespace payments {
class SitePerProcessPaymentsBrowserTest : public InProcessBrowserTest {
public:
SitePerProcessPaymentsBrowserTest() = default;
SitePerProcessPaymentsBrowserTest(const SitePerProcessPaymentsBrowserTest&) =
delete;
SitePerProcessPaymentsBrowserTest& operator=(
const SitePerProcessPaymentsBrowserTest&) = delete;
~SitePerProcessPaymentsBrowserTest() override = default;
void SetUpCommandLine(base::CommandLine* command_line) override {
// HTTPS server only serves a valid cert for localhost, so this is needed
// to load pages from other hosts without an error.
command_line->AppendSwitch(switches::kIgnoreCertificateErrors);
// Append --site-per-process flag.
content::IsolateAllSitesForTesting(command_line);
}
void SetUpOnMainThread() override {
https_server_ = std::make_unique<net::EmbeddedTestServer>(
net::EmbeddedTestServer::TYPE_HTTPS);
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(https_server_->InitializeAndListen());
content::SetupCrossSiteRedirector(https_server_.get());
https_server_->ServeFilesFromSourceDirectory(
"components/test/data/payments");
https_server_->StartAcceptingConnections();
}
std::unique_ptr<net::EmbeddedTestServer> https_server_;
};
IN_PROC_BROWSER_TEST_F(SitePerProcessPaymentsBrowserTest,
IframePaymentRequestDoesNotCrash) {
GURL url = https_server_->GetURL("a.com", "/payment_request_main.html");
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* tab =
browser()->tab_strip_model()->GetActiveWebContents();
GURL iframe_url =
https_server_->GetURL("b.com", "/payment_request_iframe.html");
EXPECT_TRUE(content::NavigateIframeToURL(tab, "test", iframe_url));
content::RenderFrameHost* iframe = content::FrameMatchingPredicate(
tab->GetPrimaryPage(),
base::BindRepeating(&content::FrameHasSourceUrl, iframe_url));
EXPECT_TRUE(content::ExecJs(iframe, "triggerPaymentRequest()"));
EXPECT_TRUE(tab->GetRenderWidgetHostView()->IsShowing());
content::RenderFrameHost* frame = ChildFrameAt(tab->GetPrimaryMainFrame(), 0);
EXPECT_TRUE(frame);
EXPECT_NE(frame->GetSiteInstance(),
tab->GetPrimaryMainFrame()->GetSiteInstance());
}
} // namespace payments
|