chromium/chrome/browser/ui/views/payments/secure_payment_confirmation_dialog_view_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/ui/views/payments/secure_payment_confirmation_dialog_view.h"

#include <optional>

#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "cc/test/pixel_comparator.h"
#include "cc/test/pixel_test_utils.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/browser/ui/views/payments/secure_payment_confirmation_views_util.h"
#include "chrome/browser/ui/views/payments/test_secure_payment_confirmation_payment_request_delegate.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/payments/core/sizes.h"
#include "components/strings/grit/components_strings.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/test/browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features_generated.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/mojom/dialog_button.mojom.h"
#include "ui/events/base_event_utils.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/test/mock_input_event_activation_protector.h"
#include "ui/views/window/dialog_client_view.h"

namespace payments {
namespace {

const SkBitmap CreateIcon(SkColor color, int width, int height) {}

const SkBitmap CreateMaxSizeIcon(SkColor color) {}

}  // namespace

class SecurePaymentConfirmationDialogViewTest
    : public DialogBrowserTest,
      public SecurePaymentConfirmationDialogView::ObserverForTest {};

// Basic test that the view matches the model state.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       ViewMatchesModel) {}

// Test that clicking the 'Accept' button triggers the expected path and closes
// the dialog.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       AcceptButtonTest) {}

// Test that the 'Accept' button is protected against accidental inputs.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       AcceptButtonIgnoresAccidentalInputs) {}

// Test that clicking the 'Cancel' button triggers the expected path and closes
// the dialog.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       CancelButtonTest) {}

// Test that the progress bar is visible in the view when requested by the
// model.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       ProgressBarVisible) {}

// Test that the view can be updated to show the progress bar after initial
// load.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       ShowProgressBar) {}

// Check that the view updates to match model updates.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       OnModelUpdated) {}

// Test the two reasons an instrument icon is updated: The model's bitmap
// pointer changed, or the bitmap itself changed.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       InstrumentIconUpdated) {}

// Test that the web contents can be torn down whilst the dialog is visible, and
// that doing so should close the dialog.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       WebContentsClosed) {}

// TestBrowserUi-provided UI test.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       InvokeUi_default) {}

// Test that the visible instrument icon is set correctly to the default icon if
// the model does not provide one.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       DefaultInstrumentIcon) {}

// Test that the merchant label is formatted correctly based on the input
// name/origin provided in the model.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       MerchantLabelFormat) {}

// Test that an oversized instrument icon is resized down to the maximum size.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       OversizedInstrumentIcon) {}

// Test that an undersized instrument icon is resized up to the minimum size.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       UndersizedInstrumentIcon) {}

// Test that a midsized instrument icon is not resized.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       MidsizedInstrumentIcon) {}

// Test that the opt-out link is only shown when explicitly requested, and that
// clicking it causes the expected path and closes the dialog.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
                       OptOutShownWhenRequested) {}

// A variant of SecurePaymentConfirmationDialogViewTest that enables the network
// and issuer rows feature, and verifies their contents.
class SecurePaymentConfirmationDialogViewNetworkAndIssuerIconsTest
    : public SecurePaymentConfirmationDialogViewTest {};

// Variant of the main ViewMatchesModel test, which verifies that the network
// and issuer rows are shown when the flag is enabled.
IN_PROC_BROWSER_TEST_F(
    SecurePaymentConfirmationDialogViewNetworkAndIssuerIconsTest,
    ViewMatchesModel) {}

// Tests that the Network row is not shown if an icon wasn't present.
IN_PROC_BROWSER_TEST_F(
    SecurePaymentConfirmationDialogViewNetworkAndIssuerIconsTest,
    NetworkRowNotShownIfIconNotPresent) {}

// Tests that the Issuer row is not shown if an icon wasn't present.
IN_PROC_BROWSER_TEST_F(
    SecurePaymentConfirmationDialogViewNetworkAndIssuerIconsTest,
    IssuerRowNotShownIfIconNotPresent) {}

// A variant of SecurePaymentConfirmationDialogViewTest that enables the inline
// title feature, and verifies the contents.
class SecurePaymentConfirmationDialogViewInlineNetworkAndIssuerIconsTest
    : public SecurePaymentConfirmationDialogViewTest {};

// Variant of the main ViewMatchesModel test, which verifies that the title,
// description, and network/issuer icons are shown when the flag is enabled.
IN_PROC_BROWSER_TEST_F(
    SecurePaymentConfirmationDialogViewInlineNetworkAndIssuerIconsTest,
    ViewMatchesModel) {}

// Tests that the network icon is not shown if it isn't in the model.
IN_PROC_BROWSER_TEST_F(
    SecurePaymentConfirmationDialogViewInlineNetworkAndIssuerIconsTest,
    NetworkIconNotShownIfNotPresent) {}

// Tests that the issuer icon is not shown if it isn't in the model.
IN_PROC_BROWSER_TEST_F(
    SecurePaymentConfirmationDialogViewInlineNetworkAndIssuerIconsTest,
    IssuerIconNotShownIfNotPresent) {}

}  // namespace payments