chromium/chrome/browser/ui/views/commerce/price_tracking_icon_view_interactive_uitest.cc

// Copyright 2022 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/user_action_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/commerce/shopping_service_factory.h"
#include "chrome/browser/image_fetcher/image_fetcher_service_factory.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/resource_coordinator/tab_manager.h"
#include "chrome/browser/sync/local_or_syncable_bookmark_sync_service_factory.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/commerce/commerce_ui_tab_helper.h"
#include "chrome/browser/ui/commerce/mock_commerce_ui_tab_helper.h"
#include "chrome/browser/ui/tabs/public/tab_features.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/commerce/price_tracking_bubble_dialog_view.h"
#include "chrome/browser/ui/views/commerce/price_tracking_icon_view.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/interaction/interactive_browser_test.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/bookmarks/test/bookmark_test_helpers.h"
#include "components/commerce/core/commerce_feature_list.h"
#include "components/commerce/core/mock_shopping_service.h"
#include "components/commerce/core/test_utils.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/feature_engagement/test/scoped_iph_feature_list.h"
#include "components/image_fetcher/core/mock_image_fetcher.h"
#include "components/omnibox/browser/vector_icons.h"
#include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h"
#include "components/sync_bookmarks/bookmark_sync_service.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/test/browser_test.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/interaction/interactive_test.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/interaction/element_tracker_views.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/widget/any_widget_observer.h"

namespace {
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();

const char kShoppingURL[] =;

std::unique_ptr<net::test_server::HttpResponse> BasicResponse(
    const net::test_server::HttpRequest& request) {}
}  // namespace

class PriceTrackingIconViewInteractiveTest : public InteractiveBrowserTest {};

// TODO(crbug.com/41494779): Test is failing on Mac under ChromeRefresh2023
// flags. Evaluate, fix, and remove the skip.
#if BUILDFLAG(IS_MAC)
#define MAYBE_FUEBubbleShownOnPress
#else
#define MAYBE_FUEBubbleShownOnPress
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(PriceTrackingIconViewInteractiveTest,
                       MAYBE_FUEBubbleShownOnPress) {}

// TODO(crbug.com/41494779): Test is failing on Mac under ChromeRefresh2023
// flags. Evaluate, fix, and remove the skip.
#if BUILDFLAG(IS_MAC)
#define MAYBE_PriceTrackingBubbleShownOnPress_BeforeFUEOnTrackedProduct
#else
#define MAYBE_PriceTrackingBubbleShownOnPress_BeforeFUEOnTrackedProduct
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(
    PriceTrackingIconViewInteractiveTest,
    MAYBE_PriceTrackingBubbleShownOnPress_BeforeFUEOnTrackedProduct) {}

// TODO(crbug.com/41494779): Test is failing on Mac under ChromeRefresh2023
// flags. Evaluate, fix, and remove the skip.
#if BUILDFLAG(IS_MAC)
#define MAYBE_PriceTrackingBubbleShownOnPress_AfterFUE
#else
#define MAYBE_PriceTrackingBubbleShownOnPress_AfterFUE
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(PriceTrackingIconViewInteractiveTest,
                       MAYBE_PriceTrackingBubbleShownOnPress_AfterFUE) {}

// TODO(crbug.com/41494779): Test is failing on Mac under ChromeRefresh2023
// flags. Evaluate, fix, and remove the skip.
#if BUILDFLAG(IS_MAC)
#define MAYBE_BubbleCanBeReshowOnPress
#else
#define MAYBE_BubbleCanBeReshowOnPress
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(PriceTrackingIconViewInteractiveTest,
                       MAYBE_BubbleCanBeReshowOnPress) {}

// TODO(crbug.com/41483562): fix and re-enable for CR2023.
IN_PROC_BROWSER_TEST_F(PriceTrackingIconViewInteractiveTest,
                       DISABLED_EnablePriceTrackOnPress) {}

// TODO(crbug.com/41494779): Test is failing on Mac under ChromeRefresh2023
// flags. Evaluate, fix, and remove the skip.
#if BUILDFLAG(IS_MAC)
#define MAYBE_CreateBookmarkOnPressIfNotExist
#else
#define MAYBE_CreateBookmarkOnPressIfNotExist
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(PriceTrackingIconViewInteractiveTest,
                       MAYBE_CreateBookmarkOnPressIfNotExist) {}

// TODO(crbug.com/41494779): Test is failing on Mac under ChromeRefresh2023
// flags. Evaluate, fix, and remove the skip.
#if BUILDFLAG(IS_MAC)
#define MAYBE_RecordOmniboxChipClicked
#else
#define MAYBE_RecordOmniboxChipClicked
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(PriceTrackingIconViewInteractiveTest,
                       MAYBE_RecordOmniboxChipClicked) {}

// TODO(crbug.com/41494779): Test is failing on Mac under ChromeRefresh2023
// flags. Evaluate, fix, and remove the skip.
#if BUILDFLAG(IS_MAC)
#define MAYBE_RecordOmniboxChipTracked
#else
#define MAYBE_RecordOmniboxChipTracked
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(PriceTrackingIconViewInteractiveTest,
                       MAYBE_RecordOmniboxChipTracked) {}

// TODO(crbug.com/41494779): Test is failing on Mac under ChromeRefresh2023
// flags. Evaluate, fix, and remove the skip.
#if BUILDFLAG(IS_MAC)
#define MAYBE_NoRecordOmniboxChipTracked_ForTrackedProduct
#else
#define MAYBE_NoRecordOmniboxChipTracked_ForTrackedProduct
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(PriceTrackingIconViewInteractiveTest,
                       MAYBE_NoRecordOmniboxChipTracked_ForTrackedProduct) {}

// TODO(crbug.com/41494779): Test is failing on Mac under ChromeRefresh2023
// flags. Evaluate, fix, and remove the skip.
#if BUILDFLAG(IS_MAC)
#define MAYBE_NoRecordOmniboxChipTracked_ForFUEFlow
#else
#define MAYBE_NoRecordOmniboxChipTracked_ForFUEFlow
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(PriceTrackingIconViewInteractiveTest,
                       MAYBE_NoRecordOmniboxChipTracked_ForFUEFlow) {}

IN_PROC_BROWSER_TEST_F(PriceTrackingIconViewInteractiveTest,
                       IconViewAccessibleName) {}

class PriceTrackingIconViewErrorHandelingTest
    : public PriceTrackingIconViewInteractiveTest {};

IN_PROC_BROWSER_TEST_F(PriceTrackingIconViewErrorHandelingTest,
                       IconRevertedOnFailure) {}

class PriceTrackingBubbleInteractiveTest
    : public PriceTrackingIconViewInteractiveTest {};

// TODO(crbug.com/41494779): Test is failing on Mac under ChromeRefresh2023
// flags. Evaluate, fix, and remove the skip.
#if BUILDFLAG(IS_MAC)
#define MAYBE_RecordFirstRunBubbleShown
#else
#define MAYBE_RecordFirstRunBubbleShown
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(PriceTrackingBubbleInteractiveTest,
                       MAYBE_RecordFirstRunBubbleShown) {}

// TODO(crbug.com/41494779): Test is failing on Mac under ChromeRefresh2023
// flags. Evaluate, fix, and remove the skip.
#if BUILDFLAG(IS_MAC)
#define MAYBE_RecordConfirmationShown
#else
#define MAYBE_RecordConfirmationShown
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(PriceTrackingBubbleInteractiveTest,
                       MAYBE_RecordConfirmationShown) {}

// TODO(crbug.com/41494779): Test is failing on Mac under ChromeRefresh2023
// flags. Evaluate, fix, and remove the skip.
#if BUILDFLAG(IS_MAC)
#define MAYBE_RecordConfirmationUntracked
#else
#define MAYBE_RecordConfirmationUntracked
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(PriceTrackingBubbleInteractiveTest,
                       MAYBE_RecordConfirmationUntracked) {}

IN_PROC_BROWSER_TEST_F(PriceTrackingBubbleInteractiveTest,
                       RecordEditedBookmarkFolderFromOmniboxBubble) {}

IN_PROC_BROWSER_TEST_F(PriceTrackingIconViewInteractiveTest,
                       TabDiscardDuringNavigationNoCrash) {}