chromium/chrome/browser/payments/secure_payment_confirmation_browsertest.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/payments/secure_payment_confirmation_browsertest.h"

#include <stdint.h>

#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/memory/ref_counted.h"
#include "base/path_service.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
#include "components/autofill/core/browser/test_event_waiter.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/payments/content/payment_manifest_web_data_service.h"
#include "components/payments/core/error_strings.h"
#include "components/payments/core/secure_payment_confirmation_credential.h"
#include "components/webdata_services/web_data_service_wrapper_factory.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/payments/payment_handler_host.mojom.h"

namespace payments {

void SecurePaymentConfirmationTest::SetUpCommandLine(
    base::CommandLine* command_line) {}

void SecurePaymentConfirmationTest::OnAppListReady() {}

void SecurePaymentConfirmationTest::OnErrorDisplayed() {}

void SecurePaymentConfirmationTest::OnWebDataServiceRequestDone(
    WebDataServiceBase::Handle h,
    std::unique_ptr<WDTypedResult> result) {}

void SecurePaymentConfirmationTest::ExpectEvent2Histogram(
    std::set<JourneyLogger::Event2> events,
    int count) {}

// static
std::string SecurePaymentConfirmationTest::GetWebAuthnErrorMessage() {}

namespace {

Event2;

std::string GetIconDownloadErrorMessage() {}

// Tests that show() will display the Transaction UX, if there is a matching
// credential.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationTest, Show_TransactionUX) {}

// Tests that calling show() on a platform without an authenticator will trigger
// the No Matching Credentials UX.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationTest, Show_NoAuthenticator) {}

// Tests that calling show() with no matching credentials will trigger the No
// Matching Credentials UX.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationTest,
                       Show_NoMatchingCredential) {}

// Tests that a credential with the correct credential ID but wrong RP ID will
// not match.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationTest,
                       Show_WrongCredentialRpId) {}

// Tests that a failed icon download immediately rejects the show() promise,
// without any browser UI being shown.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationTest, IconDownloadFailure) {}

class SecurePaymentConfirmationDisableDebugTest
    : public SecurePaymentConfirmationTest {};

// canMakePayment() and hasEnrolledInstrument() should return false on
// platforms without a compatible authenticator.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDisableDebugTest,
                       CanMakePayment_NoAuthenticator) {}

// canMakePayment() and hasEnrolledInstrument() should return true on
// platforms with a compatible authenticator regardless of the presence of
// payment credentials.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationTest,
                       CanMakePayment_HasAuthenticator) {}

// canMakePayment() and hasEnrolledInstrument() should return true on platforms
// with a compatible authenticator regardless of the value of the
// "prefs.can_make_payment_enabled" pref.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationTest,
                       CanMakePayment_CanMakePaymentEnabledPref) {}

#if !BUILDFLAG(IS_ANDROID)
// Intentionally do not enable the "SecurePaymentConfirmation" Blink runtime
// feature or the browser-side Finch flag.
class SecurePaymentConfirmationDisabledTest
    : public PaymentRequestPlatformBrowserTestBase {};

IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDisabledTest,
                       PaymentMethodNotSupported) {}

IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDisabledTest,
                       CannotMakePayment) {}

// Test that the feature can be disabled by the browser-side Finch flag, even if
// the Blink runtime feature is enabled.
class SecurePaymentConfirmationDisabledByFinchTest
    : public PaymentRequestPlatformBrowserTestBase {};

IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDisabledByFinchTest,
                       PaymentMethodNotSupported) {}

IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDisabledByFinchTest,
                       CannotMakePayment) {}
#endif  // !BUILDFLAG(IS_ANDROID)

// Test that Secure Payment Confirmation allows one call to show() without a
// user activation.
class SecurePaymentConfirmationActivationlessShowTest
    : public SecurePaymentConfirmationTest {};

IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationActivationlessShowTest,
                       ActivationlessShow) {}

// TODO(crbug.com/40266119): This test does not work on Android as it is
// difficult to wait for the bottom sheet to finish showing.
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_ShowAfterActivationlessShow
#else
#define MAYBE_ShowAfterActivationlessShow
#endif  // BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationActivationlessShowTest,
                       MAYBE_ShowAfterActivationlessShow) {}

}  // namespace
}  // namespace payments