chromium/chrome/browser/ui/views/autofill/payments/iban_bubble_view_uitest.cc

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

#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/autofill/autofill_uitest_util.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/sync/test/integration/secondary_account_helper.h"
#include "chrome/browser/sync/test/integration/sync_service_impl_harness.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/ui/autofill/payments/iban_bubble_controller_impl.h"
#include "chrome/browser/ui/autofill/payments/save_iban_ui.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/autofill/payments/dialog_view_ids.h"
#include "chrome/browser/ui/views/autofill/payments/manage_saved_iban_bubble_view.h"
#include "chrome/browser/ui/views/autofill/payments/save_iban_bubble_view.h"
#include "chrome/browser/ui/views/autofill/payments/save_payment_icon_view.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/autofill/content/browser/content_autofill_driver.h"
#include "components/autofill/content/browser/test_autofill_manager_injector.h"
#include "components/autofill/core/browser/browser_autofill_manager.h"
#include "components/autofill/core/browser/form_data_importer.h"
#include "components/autofill/core/browser/form_data_importer_test_api.h"
#include "components/autofill/core/browser/metrics/payments/iban_metrics.h"
#include "components/autofill/core/browser/payments/iban_save_manager.h"
#include "components/autofill/core/browser/payments/payments_autofill_client.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/strike_databases/payments/iban_save_strike_database.h"
#include "components/autofill/core/browser/strike_databases/strike_database_integrator_base.h"
#include "components/autofill/core/browser/test_autofill_manager_waiter.h"
#include "components/autofill/core/browser/test_event_waiter.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/autofill/core/common/autofill_test_utils.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_navigation_observer.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/events/base_event_utils.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"

namespace {
const char kIbanForm[] =;
constexpr char kIbanValue[] =;
constexpr char kIbanValueWithoutWhitespaces[] =;
constexpr char kURLGetUploadDetailsRequest[] =;
constexpr char kResponseGetUploadDetailsSuccess[] =;
constexpr char kURLUploadIbanRequest[] =;
constexpr char kResponsePaymentsSuccess[] =;
constexpr char kResponsePaymentsFailure[] =;
}  // namespace

namespace autofill {

class IbanBubbleViewFullFormBrowserTest
    : public SyncTest,
      public IbanSaveManager::ObserverForTest,
      public IbanBubbleControllerImpl::ObserverForTest {};

// Tests the local save bubble. Ensures that clicking the 'No thanks' button
// successfully causes the bubble to go away, and causes a strike to be added.
IN_PROC_BROWSER_TEST_F(IbanBubbleViewFullFormBrowserTest,
                       Local_ClickingNoThanksClosesBubble) {}

// Tests the local save bubble. Ensures that clicking the [X] button
// successfully causes the bubble to go away, and causes a strike to be added.
IN_PROC_BROWSER_TEST_F(IbanBubbleViewFullFormBrowserTest,
                       Local_ClickingXIconClosesBubble) {}

// Tests overall StrikeDatabase interaction with the local save bubble. Runs an
// example of declining the prompt max times and ensuring that the
// offer-to-save bubble does not appear on the next try. Then, ensures that no
// strikes are added if the IBAN already has max strikes.
IN_PROC_BROWSER_TEST_F(IbanBubbleViewFullFormBrowserTest,
                       StrikeDatabase_Local_FullFlowTest) {}

// Tests the local save bubble. Ensures that clicking the 'Save' button
// successfully causes the bubble to go away.
IN_PROC_BROWSER_TEST_F(IbanBubbleViewFullFormBrowserTest,
                       Local_ClickingSaveClosesBubble) {}

// Tests the local save bubble. Ensures that clicking the 'Save' button
// successfully causes the bubble to go away.
IN_PROC_BROWSER_TEST_F(IbanBubbleViewFullFormBrowserTest,
                       Local_ClickingSaveClosesBubble_WithNickname) {}

// Tests the local save bubble. Ensures that clicking the [X] button will still
// see the omnibox icon.
IN_PROC_BROWSER_TEST_F(IbanBubbleViewFullFormBrowserTest,
                       Local_ClickingClosesBubbleStillShowOmnibox) {}

// Tests the local save bubble. Ensures that clicking the omnibox icon opens
// manage saved IBAN bubble with IBAN nickname.
// crbug.com/330725101: disabled because it's flaky
IN_PROC_BROWSER_TEST_F(IbanBubbleViewFullFormBrowserTest,
                       DISABLED_Local_SavedIbanHasNickname) {}

// Tests the local save bubble. Ensures that clicking the omnibox icon opens
// manage saved IBAN bubble without IBAN nickname.
// crbug.com/330725101: disabled because it's flaky
IN_PROC_BROWSER_TEST_F(IbanBubbleViewFullFormBrowserTest,
                       DISABLED_Local_SavedIbanNoNickname) {}

// Sets up Chrome with Sync-the-transport mode enabled, with the Wallet datatype
// as enabled type.
class IbanBubbleViewSyncTransportFullFormBrowserTest
    : public IbanBubbleViewFullFormBrowserTest {};

// Tests the upload save bubble. Ensures that clicking the 'Save' button
// successfully causes the bubble to go away.
IN_PROC_BROWSER_TEST_F(IbanBubbleViewSyncTransportFullFormBrowserTest,
                       Upload_ClickingSaveClosesBubble_Success) {}

// Tests the upload save bubble. Ensures that clicking the 'Save' button
// successfully causes the bubble to go away. Also, verify that a failed IBAN
// upload adds a strike to the strike database.
IN_PROC_BROWSER_TEST_F(IbanBubbleViewSyncTransportFullFormBrowserTest,
                       Upload_ClickingSaveClosesBubble_Fail) {}

// Tests the upload save bubble. Ensures that clicking the 'No thanks' button
// successfully causes the bubble to go away. Also, verify that a failed IBAN
// upload adds a strike to the strike database.
IN_PROC_BROWSER_TEST_F(IbanBubbleViewSyncTransportFullFormBrowserTest,
                       Upload_ClickingDeclineClosesBubble) {}

// Test that upload save should not be offered when the preflight call failed.
// In this case, local save should be offered.
IN_PROC_BROWSER_TEST_F(IbanBubbleViewSyncTransportFullFormBrowserTest,
                       Upload_FailedPreflightCallThenLocalSave) {}

}  // namespace autofill