chromium/chrome/browser/page_load_metrics/observers/back_forward_cache_page_load_metrics_observer_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 <memory>

#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/page_load_metrics/integration_tests/metric_integration_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
#include "components/page_load_metrics/browser/observers/back_forward_cache_page_load_metrics_observer.h"
#include "components/page_load_metrics/browser/observers/core/uma_page_load_metrics_observer.h"
#include "components/page_load_metrics/browser/page_load_metrics_test_waiter.h"
#include "components/page_load_metrics/browser/page_load_metrics_util.h"
#include "components/page_load_metrics/common/test/page_load_metrics_test_util.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/metrics/public/cpp/ukm_builders.h"

namespace {

UkmEntry;
PageEndReason;

class BackForwardCachePageLoadMetricsObserverBrowserTest
    : public MetricIntegrationTest {};

}  // namespace

// TODO(crbug.com/334416161): Re-enble this test.
#if BUILDFLAG(IS_WIN)
#define MAYBE_FirstPaintAfterBackForwardCacheRestore
#else
#define MAYBE_FirstPaintAfterBackForwardCacheRestore
#endif
IN_PROC_BROWSER_TEST_F(BackForwardCachePageLoadMetricsObserverBrowserTest,
                       MAYBE_FirstPaintAfterBackForwardCacheRestore) {}

IN_PROC_BROWSER_TEST_F(BackForwardCachePageLoadMetricsObserverBrowserTest,
                       FirstPaintAfterBackForwardCacheRestoreBackground) {}

// TODO(https://crbug.com/40799125): Test is flaky on Windows and Mac.
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
#define MAYBE_FirstInputDelayAfterBackForwardCacheRestoreBackground
#else
#define MAYBE_FirstInputDelayAfterBackForwardCacheRestoreBackground
#endif
IN_PROC_BROWSER_TEST_F(
    BackForwardCachePageLoadMetricsObserverBrowserTest,
    MAYBE_FirstInputDelayAfterBackForwardCacheRestoreBackground) {}

IN_PROC_BROWSER_TEST_F(BackForwardCachePageLoadMetricsObserverBrowserTest,
                       IsAmpPageAfterBackForwardCacheRestore) {}

// TODO(crbug.com/334416161): Re-enble this test.
#if BUILDFLAG(IS_WIN)
#define MAYBE_CumulativeLayoutShiftAfterBackForwardCacheRestore
#else
#define MAYBE_CumulativeLayoutShiftAfterBackForwardCacheRestore
#endif
IN_PROC_BROWSER_TEST_F(
    BackForwardCachePageLoadMetricsObserverBrowserTest,
    MAYBE_CumulativeLayoutShiftAfterBackForwardCacheRestore) {}

// TODO(crbug.com/40752530): Disabled for being flaky.
IN_PROC_BROWSER_TEST_F(
    BackForwardCachePageLoadMetricsObserverBrowserTest,
    DISABLED_RequestAnimationFramesAfterBackForwardCacheRestore) {}

// TODO(crbug.com/334416161): Re-enble this test.
#if BUILDFLAG(IS_WIN)
#define MAYBE_LayoutShiftNormalization_AfterBackForwardCacheRestore
#else
#define MAYBE_LayoutShiftNormalization_AfterBackForwardCacheRestore
#endif
IN_PROC_BROWSER_TEST_F(
    BackForwardCachePageLoadMetricsObserverBrowserTest,
    MAYBE_LayoutShiftNormalization_AfterBackForwardCacheRestore) {}

// Verifies that the app resumes HistoryNavigation logging for a page if the
// page restores from the bf-cache after the app has backgrounded and
// re-foregrounded.
IN_PROC_BROWSER_TEST_F(
    BackForwardCachePageLoadMetricsObserverBrowserTest,
    ResumesLoggingAfterRestoringFromCacheAfterBackgrounding) {}

// TODO(crbug.com/40937315): Test is flaky on MSAN.
// TODO(https://crbug.com/40799125): Test is flaky on Windows and Mac.
#if defined(MEMORY_SANITIZER) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
#define MAYBE_ResponsivenessMetricsNormalizationWithSendingAllLatencies
#else
#define MAYBE_ResponsivenessMetricsNormalizationWithSendingAllLatencies
#endif
IN_PROC_BROWSER_TEST_F(
    BackForwardCachePageLoadMetricsObserverBrowserTest,
    MAYBE_ResponsivenessMetricsNormalizationWithSendingAllLatencies) {}