chromium/chrome/browser/history_clusters/history_clusters_metrics_browsertest.cc

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

#include <memory>

#include "base/base64.h"
#include "base/run_loop.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/history/history_test_utils.h"
#include "chrome/browser/history_clusters/history_clusters_metrics_logger.h"
#include "chrome/browser/history_clusters/history_clusters_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/webui/history/history_ui.h"
#include "chrome/browser/ui/webui/history_clusters/history_clusters_handler.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/history_clusters/core/features.h"
#include "components/history_clusters/core/url_constants.h"
#include "components/ukm/test_ukm_recorder.h"
#include "components/variations/active_field_trials.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_source.h"
#include "ui/webui/resources/cr_components/history_clusters/history_clusters.mojom.h"

namespace history_clusters {

namespace {

enum class UiTab {};

void ValidateHistoryClustersUKMEntry(const ukm::mojom::UkmEntry* entry,
                                     HistoryClustersInitialState init_state,
                                     int num_queries,
                                     int num_toggles_to_basic_history) {}

}  // namespace

class HistoryClustersMetricsBrowserTest : public InProcessBrowserTest {};

IN_PROC_BROWSER_TEST_F(HistoryClustersMetricsBrowserTest,
                       NoUKMEventOnOtherPages) {}

// Flaky on Win, Linux and Mac. http://crbug.com/1282122
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || \
    BUILDFLAG(IS_MAC)
#define MAYBE_DirectNavigationNoInteraction
#else
#define MAYBE_DirectNavigationNoInteraction
#endif
IN_PROC_BROWSER_TEST_F(HistoryClustersMetricsBrowserTest,
                       MAYBE_DirectNavigationNoInteraction) {}

// TODO(crbug.com/40812616): Flaky on Linux, Windows and Mac.
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN) || \
    BUILDFLAG(IS_MAC)
#define MAYBE_DirectNavigationWithQuery
#else
#define MAYBE_DirectNavigationWithQuery
#endif
IN_PROC_BROWSER_TEST_F(HistoryClustersMetricsBrowserTest,
                       MAYBE_DirectNavigationWithQuery) {}

// Disabled on Windows, ChromeOS, and Linux due to flakes: crbug.com/1263465.
// Disabled on Mac due to flakes: crbug.com/1288805.
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || \
    BUILDFLAG(IS_MAC)
#define MAYBE_DirectNavigationWithToggleToBasic
#else
#define MAYBE_DirectNavigationWithToggleToBasic
#endif
IN_PROC_BROWSER_TEST_F(HistoryClustersMetricsBrowserTest,
                       MAYBE_DirectNavigationWithToggleToBasic) {}

IN_PROC_BROWSER_TEST_F(
    HistoryClustersMetricsBrowserTest,
    DISABLED_DirectNavigationWithToggleToBasicAndToggleBack) {}

// Assumed to be flaky since the above tests are flaky.
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN) || \
    BUILDFLAG(IS_MAC)
#define MAYBE_IndirectNavigation
#else
#define MAYBE_IndirectNavigation
#endif
IN_PROC_BROWSER_TEST_F(HistoryClustersMetricsBrowserTest,
                       MAYBE_IndirectNavigation) {}

}  // namespace history_clusters