Commit 52701ed1 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

Test double launching Payment Handler

Change:
* Add an ability for Android browser test to click the close button
on the opened payment handler UI.
* Test launching payment handler twice to prevent crbug.com/1131874 from
happening again.

Bug: 1131874

Change-Id: Id43def5f2d2be4a40e34eda1219942dabd70485e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2434769
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811847}
parent bdd90f05
......@@ -631,10 +631,10 @@ public class PaymentRequestImpl
}
/**
* Click the security icon of the Expandable Payment Handler for testing purpose; return false
* Clicks the security icon of the Expandable Payment Handler for testing purpose; return false
* if failed.
*
* @return The WebContents of the Expandable Payment Handler.
* @return Whether the click is successful.
*/
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
public static boolean clickPaymentHandlerSecurityIconForTest() {
......@@ -647,6 +647,23 @@ public class PaymentRequestImpl
return mPaymentUIsManager.clickPaymentHandlerSecurityIconForTest();
}
/**
* Simulates a click on the close button of the Payment Handler for testing purpose; return
* false if failed.
*
* @return Whether the click is successful.
*/
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
public static boolean clickPaymentHandlerCloseButtonForTest() {
if (sShowingPaymentRequest == null) return false;
return sShowingPaymentRequest.clickPaymentHandlerCloseButtonForTestInternal();
}
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
private boolean clickPaymentHandlerCloseButtonForTestInternal() {
return mPaymentUIsManager.clickPaymentHandlerCloseButtonForTest();
}
/**
* Confirms payment in minimal UI. Used only in test.
*
......
......@@ -166,4 +166,9 @@ public class PaymentHandlerCoordinator {
public void clickSecurityIconForTest() {
mToolbarCoordinator.clickSecurityIconForTest();
}
@VisibleForTesting
public void clickCloseButtonForTest() {
mToolbarCoordinator.clickCloseButtonForTest();
}
}
......@@ -102,12 +102,18 @@ public class PaymentHandlerToolbarCoordinator implements PaymentHandlerToolbarMe
return mToolbarView.getView();
}
/** @return The security icon of the PaymentHandlerToolbar. */
/** Simulates a click on the security icon of the payment handler toolbar. */
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
public void clickSecurityIconForTest() {
mToolbarView.mSecurityIconView.performClick();
}
/** Simulates a click on the close button of the payment handler toolbar. */
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
public void clickCloseButtonForTest() {
mToolbarView.mCloseButton.performClick();
}
// Implement PaymentHandlerToolbarMediatorDelegate.
@Override
@ConnectionSecurityLevel
......
......@@ -972,6 +972,13 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
return true;
}
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
public boolean clickPaymentHandlerCloseButtonForTest() {
if (mPaymentHandlerUi == null) return false;
mPaymentHandlerUi.clickCloseButtonForTest();
return true;
}
/** Provide PaymentInformation to the PaymentRequest UI. */
public void providePaymentInformationToPaymentRequestUI() {
// Do not display service worker payment apps summary in single line so as to display its
......
......@@ -22,6 +22,7 @@ source_set("browsertests") {
"payment_handler_enforce_full_delegation_browsertest.cc",
"payment_handler_exploit_browsertest.cc",
"payment_handler_just_in_time_installation_browsertest.cc",
"payment_handler_ui_browsertest.cc",
"payment_handler_uninstall_browsertest.cc",
"payment_request_app_store_billing_browsertest.cc",
"payment_request_can_make_payment_browsertest.cc",
......
// Copyright 2020 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/test/payments/payment_request_platform_browsertest_base.h"
#include "content/public/test/browser_test.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
namespace payments {
namespace {
class PaymentHandlerUiBrowserTest
: public PaymentRequestPlatformBrowserTestBase {};
// Make sure a page can open the Payment UI multiple times.
IN_PROC_BROWSER_TEST_F(PaymentHandlerUiBrowserTest,
OpenPaymentTwiceShouldBeSuccessful) {
NavigateTo("/maxpay.com/merchant.html");
std::string expected = "success";
EXPECT_EQ(expected, content::EvalJs(GetActiveWebContents(), "install()"));
EXPECT_EQ("app_is_ready",
content::EvalJs(
GetActiveWebContents(),
"launchAndWaitUntilReady('./payment_handler_window.html')"));
EXPECT_TRUE(test_controller()->ClickPaymentHandlerCloseButton());
EXPECT_EQ("User closed the Payment Request UI.",
content::EvalJs(GetActiveWebContents(), "getResult()"));
// The second time should be successful.
EXPECT_EQ("app_is_ready",
content::EvalJs(
GetActiveWebContents(),
"launchAndWaitUntilReady('./payment_handler_window.html')"));
EXPECT_TRUE(test_controller()->ClickPaymentHandlerCloseButton());
EXPECT_EQ("User closed the Payment Request UI.",
content::EvalJs(GetActiveWebContents(), "getResult()"));
}
} // namespace
} // namespace payments
......@@ -229,6 +229,11 @@ public class PaymentRequestTestBridge {
return PaymentRequestImpl.clickPaymentHandlerSecurityIconForTest();
}
@CalledByNative
private static boolean clickPaymentHandlerCloseButtonForTest() {
return PaymentRequestImpl.clickPaymentHandlerCloseButtonForTest();
}
@CalledByNative
private static boolean confirmMinimalUIForTest() {
return PaymentRequestImpl.confirmMinimalUIForTest();
......
......@@ -43,6 +43,12 @@ bool ClickPaymentHandlerSecurityIconForTest() {
env);
}
bool ClickPaymentHandlerCloseButtonForTest() {
JNIEnv* env = base::android::AttachCurrentThread();
return Java_PaymentRequestTestBridge_clickPaymentHandlerCloseButtonForTest(
env);
}
bool ConfirmMinimalUIForTest() {
return Java_PaymentRequestTestBridge_confirmMinimalUIForTest(
base::android::AttachCurrentThread());
......
......@@ -29,15 +29,20 @@ void SetUseDelegateOnPaymentRequestForTesting(
bool skip_ui_for_basic_card,
const std::string& twa_package_name);
// Get the WebContents of the Expandable Payment Handler for testing purpose, or
// null if nonexistent. To guarantee a non-null return, this function should be
// called only if: 1) PaymentRequest UI is opening. 2)
// Gets the WebContents of the Expandable Payment Handler for testing purpose,
// or null if nonexistent. To guarantee a non-null return, this function should
// be called only if: 1) PaymentRequest UI is opening. 2)
// ScrollToExpandPaymentHandler feature is enabled. 3) PaymentHandler is
// opening.
content::WebContents* GetPaymentHandlerWebContentsForTest();
// Simulates a click on the security icon of the Payment Handler UI. Returns
// true on success.
bool ClickPaymentHandlerSecurityIconForTest();
// Click the close button on the Payment Handler UI. Returns true on success.
bool ClickPaymentHandlerCloseButtonForTest();
// Confirms payment in minimal UI. Returns true on success.
bool ConfirmMinimalUIForTest();
......
......@@ -73,18 +73,22 @@ class PaymentRequestTestController {
void SetTwaPaymentApp(const std::string& method_name,
const std::string& response);
// Get the WebContents of the Payment Handler for testing purpose, or null if
// Gets the WebContents of the Payment Handler for testing purpose, or null if
// nonexistent. To guarantee a non-null return, this function should be called
// only if: 1) PaymentRequest UI is opening. 2) ScrollToExpandPaymentHandler
// feature is enabled (on Android). 3) PaymentHandler is opening.
content::WebContents* GetPaymentHandlerWebContents();
#if defined(OS_ANDROID)
// Click the security icon on the Expandable Payment Handler toolbar for
// testing purpose. return whether it's succeeded.
// Clicks the security icon on the Expandable Payment Handler toolbar for
// testing purpose. Return whether it's succeeded.
bool ClickPaymentHandlerSecurityIcon();
#endif
// Clicks the close button on the Payment Handler toolbar for testing purpose.
// Return whether it's succeeded.
bool ClickPaymentHandlerCloseButton();
// Confirms payment in a browser payment sheet, be it either PAYMENT_REQUEST
// or SECURE_PAYMENT_CONFIRMATION type. Returns true if the dialog was
// available.
......
......@@ -24,6 +24,10 @@ bool PaymentRequestTestController::ClickPaymentHandlerSecurityIcon() {
return ClickPaymentHandlerSecurityIconForTest();
}
bool PaymentRequestTestController::ClickPaymentHandlerCloseButton() {
return ClickPaymentHandlerCloseButtonForTest();
}
bool PaymentRequestTestController::ConfirmPayment() {
NOTIMPLEMENTED();
return false;
......
......@@ -155,6 +155,18 @@ bool PaymentRequestTestController::ConfirmPayment() {
return true;
}
bool PaymentRequestTestController::ClickPaymentHandlerCloseButton() {
if (!delegate_)
return false;
PaymentRequestDialog* dialog = delegate_->GetDialogForTesting();
if (!dialog)
return false;
dialog->CloseDialog();
return true;
}
bool PaymentRequestTestController::ConfirmMinimalUI() {
// Desktop does not have a minimal UI.
return true;
......
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