Commit 324bb1f7 authored by Danyao Wang's avatar Danyao Wang Committed by Commit Bot

[Payment Handler] Add browsertest for AlwaysAllowJIT feature.

The feature was landed a while ago. This CL adds missing browsertests.

Bug: 922683
Change-Id: I798bcea5acee34c55c887464509684827a05b6eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2103442Reviewed-by: default avatarSahel Sharify <sahel@chromium.org>
Commit-Queue: Danyao Wang <danyao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751150}
parent e400052d
...@@ -2,7 +2,12 @@ ...@@ -2,7 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.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/journey_logger.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace payments { namespace payments {
...@@ -60,4 +65,82 @@ IN_PROC_BROWSER_TEST_F(PaymentHandlerJustInTimeInstallationTest, ...@@ -60,4 +65,82 @@ IN_PROC_BROWSER_TEST_F(PaymentHandlerJustInTimeInstallationTest,
ExpectBodyContains("kylepay.com/webpay"); ExpectBodyContains("kylepay.com/webpay");
} }
class AlwaysAllowJustInTimePaymentAppTest
: public PaymentHandlerJustInTimeInstallationTest,
public testing::WithParamInterface<bool> {
protected:
AlwaysAllowJustInTimePaymentAppTest() {
scoped_feature_list_.InitWithFeatureState(
features::kAlwaysAllowJustInTimePaymentApp, GetParam());
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_P(AlwaysAllowJustInTimePaymentAppTest,
HybridRequest_NoCreditCard) {
base::HistogramTester histogram_tester;
ResetEventWaiterForSingleEvent(GetParam() ? TestEvent::kPaymentCompleted
: TestEvent::kShowAppsReady);
EXPECT_TRUE(
content::ExecJs(GetActiveWebContents(),
"testPaymentMethods([ "
" {supportedMethods: 'basic-card'}, "
" {supportedMethods: 'https://kylepay.com/webpay'}])"));
WaitForObservedEvent();
if (GetParam()) {
// If AlwaysAllowJIT is enabled, kylepay should be installed just-in-time
// and used for testing.
ExpectBodyContains("kylepay.com/webpay");
} else {
// With AlwaysJIT disabled, the request is expected to stop at the payment
// sheet waiting for user action.
EXPECT_TRUE(content::ExecJs(GetActiveWebContents(), "abort()"));
}
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events");
ASSERT_EQ(1U, buckets.size());
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_AVAILABLE_METHOD_BASIC_CARD);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_AVAILABLE_METHOD_GOOGLE);
EXPECT_EQ(GetParam(),
(buckets[0].min & JourneyLogger::EVENT_AVAILABLE_METHOD_OTHER) > 0);
}
IN_PROC_BROWSER_TEST_P(AlwaysAllowJustInTimePaymentAppTest,
HybridRequest_HasCompleteCreditCard) {
CreateAndAddCreditCardForProfile(CreateAndAddAutofillProfile());
base::HistogramTester histogram_tester;
ResetEventWaiterForSingleEvent(TestEvent::kShowAppsReady);
EXPECT_TRUE(
content::ExecJs(GetActiveWebContents(),
"testPaymentMethods([ "
" {supportedMethods: 'basic-card'}, "
" {supportedMethods: 'https://kylepay.com/webpay'}])"));
WaitForObservedEvent();
// Regardless whether AlwaysJIT is disabled, beceause there is a complete
// basic card, the request is expected to stop at the payment sheet waiting
// for user action.
EXPECT_TRUE(content::ExecJs(GetActiveWebContents(), "abort()"));
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events");
ASSERT_EQ(1U, buckets.size());
EXPECT_TRUE(buckets[0].min &
JourneyLogger::EVENT_AVAILABLE_METHOD_BASIC_CARD);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_AVAILABLE_METHOD_GOOGLE);
EXPECT_EQ(GetParam(),
(buckets[0].min & JourneyLogger::EVENT_AVAILABLE_METHOD_OTHER) > 0);
}
INSTANTIATE_TEST_SUITE_P(All,
AlwaysAllowJustInTimePaymentAppTest,
::testing::Values(true, false));
} // namespace payments } // namespace payments
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
/* global PaymentRequest:false */ /* global PaymentRequest:false */
var request = null;
var showPromise = null;
/** /**
* Helper function that launches the PaymentRequest UI with the specified * Helper function that launches the PaymentRequest UI with the specified
* payment methods. * payment methods.
...@@ -15,7 +18,7 @@ ...@@ -15,7 +18,7 @@
* @param {boolean} requestShippingContact: Whether or not shipping address and * @param {boolean} requestShippingContact: Whether or not shipping address and
* payer's contact information are required. * payer's contact information are required.
*/ */
function testPaymentMethods(methods, requestShippingContact = false) { async function testPaymentMethods(methods, requestShippingContact = false) {
const shippingOptions = requestShippingContact const shippingOptions = requestShippingContact
? [{ ? [{
id: 'freeShippingOption', id: 'freeShippingOption',
...@@ -25,7 +28,7 @@ function testPaymentMethods(methods, requestShippingContact = false) { ...@@ -25,7 +28,7 @@ function testPaymentMethods(methods, requestShippingContact = false) {
}] }]
: []; : [];
try { try {
new PaymentRequest( request = new PaymentRequest(
methods, methods,
{total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}, {total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}},
shippingOptions}, shippingOptions},
...@@ -34,27 +37,27 @@ function testPaymentMethods(methods, requestShippingContact = false) { ...@@ -34,27 +37,27 @@ function testPaymentMethods(methods, requestShippingContact = false) {
requestPayerEmail: requestShippingContact, requestPayerEmail: requestShippingContact,
requestPayerName: requestShippingContact, requestPayerName: requestShippingContact,
requestPayerPhone: requestShippingContact, requestPayerPhone: requestShippingContact,
})
.show()
.then(function(resp) {
resp.complete('success')
.then(function() {
print(
resp.methodName + '<br>' +
JSON.stringify(resp.details, undefined, 2));
})
.catch(function(error) {
print(error.message);
});
})
.catch(function(error) {
print(error.message);
}); });
showPromise = request.show();
const resp = await showPromise;
await resp.complete('success');
const json = JSON.stringify(resp.details, undefined, 2);
print(`${resp.methodName}<br>${json}`);
} catch (error) { } catch (error) {
print(error.message); print(error.message);
} }
} }
/**
* Aborts the PaymentRequest initiated by testPaymentMethods().
*/
async function abort() { // eslint-disable-line no-unused-vars
await request.abort();
return await showPromise.catch((e) => {
return e.name == 'AbortError';
});
}
/** /**
* Launches the PaymentRequest UI with Bob Pay and credit cards as payment * Launches the PaymentRequest UI with Bob Pay and credit cards as payment
* methods. * methods.
......
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