Commit 36531cae authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Payment Handler] Exploit test both with and without scroll-to-expand.

This patch runs the exploit test both with and without Scroll-to-Expand
payment handler feature. Since SmokeTest was failing due to an issue in
Chrome Custom Tab, which is not being used with Scroll-to-Expand payment
handler, this configuration can run the SmokeTest, thus increasing code
coverage overall.

Bug: 998737
Change-Id: I8ced750c67d08a93f0733c85ec07884d3c6989c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2042293Reviewed-by: default avatarLiquan (Max) Gu <maxlg@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739452}
parent 353f2dc5
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/macros.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/test/base/chrome_test_utils.h"
#include "chrome/test/payments/payment_request_test_controller.h"
......@@ -18,6 +18,7 @@
#include "url/origin.h"
#if defined(OS_ANDROID)
#include "chrome/browser/flags/android/chrome_feature_list.h"
#include "chrome/test/base/android/android_browser_test.h"
#else
#include "chrome/test/base/in_process_browser_test.h"
......@@ -28,12 +29,10 @@ namespace {
class PaymentHandlerExploitTest : public PlatformBrowserTest,
public content::ServiceWorkerHostInterceptor {
public:
protected:
PaymentHandlerExploitTest()
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {}
~PaymentHandlerExploitTest() override {}
content::WebContents* GetActiveWebContents() {
return chrome_test_utils::GetActiveWebContents(this);
}
......@@ -46,6 +45,39 @@ class PaymentHandlerExploitTest : public PlatformBrowserTest,
return https_server_.GetURL(relative_path);
}
void SmokeTest() {
std::string expected = "success";
EXPECT_EQ(expected, content::EvalJs(GetActiveWebContents(), "install()"));
EXPECT_EQ(expected, content::EvalJs(GetActiveWebContents(), "launch()"));
}
void TestThatRendererCannotOpenCrossOriginWindow() {
std::string expected = "success";
EXPECT_EQ(expected, content::EvalJs(GetActiveWebContents(), "install()"));
GURL service_worker_scope = GetTestServerUrl("/");
int service_worker_process_id = -1;
EXPECT_EQ(blink::ServiceWorkerStatusCode::kOk,
InterceptServiceWorkerHostWithScope(
GetActiveWebContents()->GetBrowserContext(),
service_worker_scope, &service_worker_process_id));
content::RenderProcessHostWatcher crash_observer(
content::RenderProcessHost::FromID(service_worker_process_id),
content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
GURL cross_origin_url("https://127.0.0.1:80");
EXPECT_FALSE(url::IsSameOriginWith(cross_origin_url, service_worker_scope));
set_payment_handler_window_url(cross_origin_url);
EXPECT_TRUE(content::ExecJs(GetActiveWebContents(), "launch()"));
crash_observer.Wait();
EXPECT_FALSE(crash_observer.did_exit_normally());
}
base::test::ScopedFeatureList features_;
private:
// PlatformBrowserTest:
void SetUpOnMainThread() override {
......@@ -67,48 +99,57 @@ class PaymentHandlerExploitTest : public PlatformBrowserTest,
GURL payment_handler_window_url_;
net::EmbeddedTestServer https_server_;
PaymentRequestTestController test_controller_;
};
DISALLOW_COPY_AND_ASSIGN(PaymentHandlerExploitTest);
class DefaultPaymentHandlerExploitTest : public PaymentHandlerExploitTest {
public:
DefaultPaymentHandlerExploitTest() {
#if defined(OS_ANDROID)
// Scroll-to-Expand payment handler feature is available only on Android.
features_.InitAndDisableFeature(
chrome::android::kScrollToExpandPaymentHandler);
#endif // defined(OS_ANDROID)
}
};
// Unable to launch a payment handler window on Android through browser test.
// https://crbug.com/998737
// Android browsertests are not able to open a Chrome Custom Tab for the payment
// handler window due to an ActivityNotFoundException: "No Activity found to
// handle Intent." https://crbug.com/998737
#if defined(OS_ANDROID)
#define MAYBE_SmokeTest DISABLED_SmokeTest
#else
#define MAYBE_SmokeTest SmokeTest
#endif
IN_PROC_BROWSER_TEST_F(PaymentHandlerExploitTest, MAYBE_SmokeTest) {
std::string expected = "success";
EXPECT_EQ(expected, content::EvalJs(GetActiveWebContents(), "install()"));
EXPECT_EQ(expected, content::EvalJs(GetActiveWebContents(), "launch()"));
#endif // defined(OS_ANDROID)
IN_PROC_BROWSER_TEST_F(DefaultPaymentHandlerExploitTest, MAYBE_SmokeTest) {
SmokeTest();
}
IN_PROC_BROWSER_TEST_F(PaymentHandlerExploitTest,
IN_PROC_BROWSER_TEST_F(DefaultPaymentHandlerExploitTest,
RendererCannotOpenCrossOriginWindow) {
std::string expected = "success";
EXPECT_EQ(expected, content::EvalJs(GetActiveWebContents(), "install()"));
GURL service_worker_scope = GetTestServerUrl("/");
int service_worker_process_id = -1;
EXPECT_EQ(blink::ServiceWorkerStatusCode::kOk,
InterceptServiceWorkerHostWithScope(
GetActiveWebContents()->GetBrowserContext(),
service_worker_scope, &service_worker_process_id));
content::RenderProcessHostWatcher crash_observer(
content::RenderProcessHost::FromID(service_worker_process_id),
content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
TestThatRendererCannotOpenCrossOriginWindow();
}
GURL cross_origin_url("https://127.0.0.1:80");
EXPECT_FALSE(url::IsSameOriginWith(cross_origin_url, service_worker_scope));
set_payment_handler_window_url(cross_origin_url);
#if defined(OS_ANDROID)
// Same tests as above, but with Scroll-to-Expand payment handler feature
// enabled. This feature is only available on Android.
class ScrollToExpandPaymentHandlerExploitTest
: public PaymentHandlerExploitTest {
public:
ScrollToExpandPaymentHandlerExploitTest() {
features_.InitAndEnableFeature(
chrome::android::kScrollToExpandPaymentHandler);
}
};
EXPECT_TRUE(content::ExecJs(GetActiveWebContents(), "launch()"));
IN_PROC_BROWSER_TEST_F(ScrollToExpandPaymentHandlerExploitTest, SmokeTest) {
SmokeTest();
}
crash_observer.Wait();
EXPECT_FALSE(crash_observer.did_exit_normally());
IN_PROC_BROWSER_TEST_F(ScrollToExpandPaymentHandlerExploitTest,
RendererCannotOpenCrossOriginWindow) {
TestThatRendererCannotOpenCrossOriginWindow();
}
#endif // defined(OS_ANDROID)
} // namespace
} // namespace payments
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment