Commit bd3fc9de authored by Danyao Wang's avatar Danyao Wang Committed by Commit Bot

[Web Payments] Allow skip-the-sheet w/o user gesture for SPC trial.

Allow origins enrolled in the Secure Payment Confirmation trial to use
skip-the-sheet flow to trigger secure modal.

Bug: 1122028
Change-Id: I8d9e41ad6ac3b8851e72fa5416562d85a8b14f43
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2378446Reviewed-by: default avatarSahel Sharify <sahel@chromium.org>
Commit-Queue: Danyao Wang <danyao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802078}
parent fc1b3bfe
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/test/payments/payment_request_platform_browsertest_base.h" #include "chrome/test/payments/payment_request_platform_browsertest_base.h"
#include "components/payments/core/features.h" #include "components/payments/core/features.h"
#include "components/payments/core/journey_logger.h" #include "components/payments/core/journey_logger.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -89,6 +91,88 @@ IN_PROC_BROWSER_TEST_F(PaymentHandlerJustInTimeInstallationTest, ...@@ -89,6 +91,88 @@ IN_PROC_BROWSER_TEST_F(PaymentHandlerJustInTimeInstallationTest,
"\"https://henrypay.com/webpay\" is not supported.\n\n\n\n\n"); "\"https://henrypay.com/webpay\" is not supported.\n\n\n\n\n");
} }
using PaymentHandlerSkipSheetTest = PaymentHandlerJustInTimeInstallationTest;
IN_PROC_BROWSER_TEST_F(PaymentHandlerSkipSheetTest, SkipWithUserGesture) {
base::HistogramTester histogram_tester;
ResetEventWaiterForSingleEvent(TestEvent::kPaymentCompleted);
EXPECT_TRUE(
content::ExecJs(GetActiveWebContents(),
"testPaymentMethods([ "
" {supportedMethods: 'https://kylepay.com/webpay'}])"));
WaitForObservedEvent();
ExpectBodyContains("kylepay.com/webpay");
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events");
ASSERT_EQ(1U, buckets.size());
EXPECT_TRUE(buckets[0].min & JourneyLogger::EVENT_SKIPPED_SHOW);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SHOWN);
EXPECT_TRUE(buckets[0].min & JourneyLogger::EVENT_AVAILABLE_METHOD_OTHER);
EXPECT_TRUE(buckets[0].min & JourneyLogger::EVENT_SELECTED_OTHER);
}
IN_PROC_BROWSER_TEST_F(PaymentHandlerSkipSheetTest, NoSkipWithoutUserGesture) {
// When shipping is not requested, kylepay.com cannot leverage skip-the-sheet
// for being the only payment app that can fulfill all delegation requests. So
// if there is no user gesture, the request should stop at the payment sheet
// waiting for user action.
base::HistogramTester histogram_tester;
ResetEventWaiterForSingleEvent(TestEvent::kAppListReady);
EXPECT_TRUE(
content::ExecJs(GetActiveWebContents(),
"testPaymentMethods([ "
" {supportedMethods: 'https://kylepay.com/webpay'}])",
content::EXECUTE_SCRIPT_NO_USER_GESTURE));
WaitForObservedEvent();
EXPECT_TRUE(content::ExecJs(GetActiveWebContents(), "abort()"));
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events");
ASSERT_EQ(1U, buckets.size());
// TODO(crbug.com/1122198): EVENT_SHOWN is not always logged on Android.
#if !defined(OS_ANDROID)
EXPECT_TRUE(buckets[0].min & JourneyLogger::EVENT_SHOWN);
#endif
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SKIPPED_SHOW);
EXPECT_TRUE(buckets[0].min & JourneyLogger::EVENT_AVAILABLE_METHOD_OTHER);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SELECTED_OTHER);
}
class SecurePaymentConfirmationSkipSheetTest
: public PaymentHandlerJustInTimeInstallationTest {
protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
PaymentHandlerJustInTimeInstallationTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(
switches::kEnableExperimentalWebPlatformFeatures);
}
};
// TODO(crbug.com/825270): Remove this special case user gesture exception is
// removed.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationSkipSheetTest,
SkipWithoutUserGesture) {
base::HistogramTester histogram_tester;
ResetEventWaiterForSingleEvent(TestEvent::kPaymentCompleted);
EXPECT_TRUE(
content::ExecJs(GetActiveWebContents(),
"testPaymentMethods([ "
" {supportedMethods: 'https://kylepay.com/webpay'}])",
content::EXECUTE_SCRIPT_NO_USER_GESTURE));
WaitForObservedEvent();
ExpectBodyContains("kylepay.com/webpay");
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events");
ASSERT_EQ(1U, buckets.size());
EXPECT_TRUE(buckets[0].min & JourneyLogger::EVENT_SKIPPED_SHOW);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SHOWN);
EXPECT_TRUE(buckets[0].min & JourneyLogger::EVENT_AVAILABLE_METHOD_OTHER);
EXPECT_TRUE(buckets[0].min & JourneyLogger::EVENT_SELECTED_OTHER);
}
class AlwaysAllowJustInTimePaymentAppTest class AlwaysAllowJustInTimePaymentAppTest
: public PaymentHandlerJustInTimeInstallationTest, : public PaymentHandlerJustInTimeInstallationTest,
public testing::WithParamInterface<bool> { public testing::WithParamInterface<bool> {
......
...@@ -809,6 +809,15 @@ ScriptPromise PaymentRequest::show(ScriptState* script_state, ...@@ -809,6 +809,15 @@ ScriptPromise PaymentRequest::show(ScriptState* script_state,
WebFeature::kPaymentRequestShowWithoutGesture); WebFeature::kPaymentRequestShowWithoutGesture);
} }
// TODO(crbug.com/825270): Pretend that a user gesture is provided to allow
// origins that are part of the Secure Payment Confirmation Origin Trial to
// use skip-the-sheet flow as a hack for secure modal window
// (crbug.com/1122028). Remove this after user gesture delegation ships.
if (RuntimeEnabledFeatures::SecurePaymentConfirmationEnabled(
GetExecutionContext())) {
is_user_gesture = true;
}
// TODO(crbug.com/779126): add support for handling payment requests in // TODO(crbug.com/779126): add support for handling payment requests in
// immersive mode. // immersive mode.
if (GetFrame()->GetDocument()->GetSettings()->GetImmersiveModeEnabled()) { if (GetFrame()->GetDocument()->GetSettings()->GetImmersiveModeEnabled()) {
......
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