chromium/components/page_load_metrics/browser/observers/back_forward_cache_page_load_metrics_observer_unittest.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 "components/page_load_metrics/browser/observers/back_forward_cache_page_load_metrics_observer.h"

#include "base/memory/raw_ptr.h"
#include "base/test/simple_test_tick_clock.h"
#include "components/page_load_metrics/browser/fake_page_load_metrics_observer_delegate.h"
#include "components/page_load_metrics/browser/observers/page_load_metrics_observer_content_test_harness.h"
#include "components/page_load_metrics/browser/page_load_metrics_observer.h"
#include "components/page_load_metrics/browser/page_load_tracker.h"
#include "content/public/test/mock_navigation_handle.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/mojom/ukm_interface.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"

const char kTestUrl1[] =;

Visibility;
FakePageLoadMetricsObserverDelegate;
PageLoadMetricsObserverDelegate;
HistoryNavigation;
UserPerceivedPageVisit;

class BackForwardCachePageLoadMetricsObserverTest
    : public page_load_metrics::PageLoadMetricsObserverContentTestHarness {};

TEST_F(BackForwardCachePageLoadMetricsObserverTest,
       OnRestoreFromBackForwardCache_NonAmpPageHasFalse) {}

TEST_F(BackForwardCachePageLoadMetricsObserverTest,
       OnRestoreFromBackForwardCache_AmpPageHasTrue) {}

TEST_F(BackForwardCachePageLoadMetricsObserverTest,
       OnNonBackForwardCacheNavigation_AmpPageIsUndefined) {}

// Tests that NavigationToFirstPaint are correctly logged after a BFCache
// restore, based on the BackForwardCacheRestore structs the page load
// tracker has available.
// * No logging if the restore was not in the foreground
// * No logging if the FirstPaint timestamp is after the restored page
//   backgrounded.
// * Log if the page is either still active (no background time) or the
//   timestamp for the paint is before the background time for that back forward
//   cache restore.
TEST_F(BackForwardCachePageLoadMetricsObserverTest,
       TestOnFirstPaintAfterBackForwardCacheRestoreInPage) {}

// Tests basic logging of foreground duration.
// Note that for this, and other foreground duration tests, that the logged
// foreground duration is bucketed, so even though the test sets up specific
// timings, the expected result from the logs is the bucketed result.
TEST_F(BackForwardCachePageLoadMetricsObserverTest,
       TestBasicForegroundLogging) {}

TEST_F(BackForwardCachePageLoadMetricsObserverTest,
       TestLoggingWithNoPageEndWithFirstBackgroundTime) {}

// TODO(crbug.com/40200061): Flaky under TSan.
TEST_F(BackForwardCachePageLoadMetricsObserverTest,
       TestLoggingWithNoPageEndWithNoFirstBackgroundTime) {}

// Verifies that no foreground duration is logged if the page is restored from
// BFCache while not in the foreground.
TEST_F(BackForwardCachePageLoadMetricsObserverTest,
       DoesNotLogForegroundDurationIfRestoredInBackground) {}

// Verifies that no foreground duration is logged if the page is restored from
// BFCache while not in the foreground.
TEST_F(BackForwardCachePageLoadMetricsObserverTest,
       DoesNotLogForegroundDurationIfWasHidden) {}

TEST_F(BackForwardCachePageLoadMetricsObserverTest,
       DoesNotLogForegroundDurationIfNeverEnteredBFCache) {}
TEST_F(BackForwardCachePageLoadMetricsObserverTest,
       TestPageEndWhenBackgrounding) {}

TEST_F(BackForwardCachePageLoadMetricsObserverTest, TestLogsNonCWVPageVisit) {}

TEST_F(BackForwardCachePageLoadMetricsObserverTest, TestLogsUserInitiated) {}