chromium/components/page_load_metrics/browser/observers/core/uma_page_load_metrics_observer_unittest.cc

// Copyright 2015 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/core/uma_page_load_metrics_observer.h"

#include <memory>

#include "base/test/metrics/histogram_tester.h"
#include "base/test/power_monitor_test.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_trace_processor.h"
#include "base/time/time.h"
#include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
#include "components/page_load_metrics/browser/observers/core/largest_contentful_paint_handler.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_memory_tracker.h"
#include "components/page_load_metrics/browser/page_load_metrics_util.h"
#include "components/page_load_metrics/browser/page_load_tracker.h"
#include "components/page_load_metrics/common/test/page_load_metrics_test_util.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/preloading_test_util.h"
#include "content/public/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/input/web_mouse_event.h"

NavigationSimulator;
RenderFrameHost;
RenderFrameHostTester;
LargestContentTextOrImage;
UserInteractionLatenciesPtr;
UserInteractionLatencies;
UserInteractionLatency;
UserInteractionType;

namespace {

const char kDefaultTestUrl[] =;
const char kDefaultTestUrlAnchor[] =;
const char kDefaultTestUrl2[] =;

const char kHistogramFirstContentfulPaintDataScheme[] =;
const char kHistogramFirstContentfulPaintFileScheme[] =;

}  // namespace

class UmaPageLoadMetricsObserverTest
    : public page_load_metrics::PageLoadMetricsObserverContentTestHarness,
      public testing::WithParamInterface<bool>,
      public content::WebContentsObserver {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(UmaPageLoadMetricsObserverTest, NoMetrics) {}

TEST_P(UmaPageLoadMetricsObserverTest,
       SameDocumentNoTriggerUntilTrueNavCommit) {}

TEST_P(UmaPageLoadMetricsObserverTest, SingleMetricAfterCommit) {}

TEST_P(UmaPageLoadMetricsObserverTest, MultipleMetricsAfterCommits) {}

TEST_P(UmaPageLoadMetricsObserverTest,
       PaintMetricsAreNotRecordedForDataScheme) {}

TEST_P(UmaPageLoadMetricsObserverTest,
       PaintMetricsAreNotRecordedForFileScheme) {}

TEST_P(UmaPageLoadMetricsObserverTest, BackgroundDifferentHistogram) {}

TEST_F(UmaPageLoadMetricsObserverTest,
       RelevantBackgroundMetricsAreRecordedForHttpsScheme) {}

TEST_P(UmaPageLoadMetricsObserverTest, OnlyBackgroundLaterEvents) {}

TEST_P(UmaPageLoadMetricsObserverTest, DontBackgroundQuickerLoad) {}

TEST_P(UmaPageLoadMetricsObserverTest, FailedProvisionalLoad) {}

TEST_P(UmaPageLoadMetricsObserverTest, Reload) {}

TEST_P(UmaPageLoadMetricsObserverTest, ForwardBack) {}

TEST_P(UmaPageLoadMetricsObserverTest, NavigationTiming) {}

TEST_P(UmaPageLoadMetricsObserverTest, NewNavigation) {}

TEST_P(UmaPageLoadMetricsObserverTest, BytesAndResourcesCounted) {}

TEST_P(UmaPageLoadMetricsObserverTest, CpuUsageCounted) {}

TEST_P(UmaPageLoadMetricsObserverTest, LargestImageLoading) {}

TEST_P(UmaPageLoadMetricsObserverTest, LargestImageLoadingSmallerThanText) {}

TEST_P(UmaPageLoadMetricsObserverTest,
       LargestContentfulPaintAllFrames_OnlySubframeProvided) {}

TEST_P(UmaPageLoadMetricsObserverTest,
       LargestContentfulPaintAllFrames_SubframeImageLoading) {}

TEST_P(UmaPageLoadMetricsObserverTest,
       LargestContentfulPaintAllFrames_OnlyMainFrameProvided) {}

// This is to test whether LargestContentfulPaintAllFrames could merge
// candidates from different frames correctly. The merging will substitutes the
// existing candidate if a larger candidate from subframe is provided.
TEST_P(UmaPageLoadMetricsObserverTest,
       LargestContentfulPaintAllFrames_MergeFromFramesBySize_SubframeLarger) {}

// This is to test whether LargestContentfulPaintAllFrames could merge
// candidates from different frames correctly. The merging will substitutes the
// existing candidate if a larger candidate from main frame is provided.
TEST_P(UmaPageLoadMetricsObserverTest,
       LargestContentfulPaintAllFrames_MergeFromFramesBySize_MainFrameLarger) {}

// This tests a trade-off we have made - aggregating all subframe candidates,
// which makes LCP unable to substitute the subframe candidate with a smaller
// candidate. This test provides two subframe candidates, the later larger than
// the first one.
TEST_P(UmaPageLoadMetricsObserverTest,
       LargestContentfulPaintAllFrames_SubframesCandidateOnlyGetLarger_Larger) {}

// This tests a trade-off we have made - aggregating all subframe candidates,
// which makes LCP unable to substitute the subframe candidate with a smaller
// candidate. This test provides two subframe candidates, the later smaller than
// the first one.
TEST_P(
    UmaPageLoadMetricsObserverTest,
    LargestContentfulPaintAllFrames_SubframesCandidateOnlyGetLarger_Smaller) {}

TEST_P(UmaPageLoadMetricsObserverTest, LargestContentfulPaint_NoTextOrImage) {}

TEST_P(UmaPageLoadMetricsObserverTest, LargestContentfulPaint_OnlyText) {}

TEST_P(UmaPageLoadMetricsObserverTest, LargestContentfulPaint_OnlyImage) {}

TEST_P(UmaPageLoadMetricsObserverTest,
       LargestContentfulPaint_ImageLargerThanText) {}

TEST_P(UmaPageLoadMetricsObserverTest,
       LargestContentfulPaint_TextLargerThanImage) {}

TEST_P(UmaPageLoadMetricsObserverTest, NormalizedResponsivenessMetrics) {}

TEST_P(UmaPageLoadMetricsObserverTest, FirstInputDelayAndTimestamp) {}

TEST_P(UmaPageLoadMetricsObserverTest,
       FirstInputDelayAndTimestampBackgrounded) {}

TEST_P(UmaPageLoadMetricsObserverTest, NavigationToBackNavigationWithGesture) {}

TEST_P(UmaPageLoadMetricsObserverTest,
       BrowserNavigationToBackNavigationWithGesture) {}

TEST_P(UmaPageLoadMetricsObserverTest,
       NavigationToBackNavigationWithoutGesture) {}

TEST_P(UmaPageLoadMetricsObserverTest,
       AbortedNavigationToBackNavigationWithGesture) {}

TEST_P(UmaPageLoadMetricsObserverTest, MainFrame_MaxMemoryBytesRecorded) {}

TEST_P(UmaPageLoadMetricsObserverTest, SingleSubFrame_MaxMemoryBytesRecorded) {}

TEST_P(UmaPageLoadMetricsObserverTest, MultiSubFrames_MaxMemoryBytesRecorded) {}

TEST_P(UmaPageLoadMetricsObserverTest,
       CrossSiteSubframeLargestContentfulPaint_SubframeLarger) {}

TEST_P(UmaPageLoadMetricsObserverTest,
       CrossSiteSubframeLargestContentfulPaint_SubframeSmaller) {}

TEST_P(UmaPageLoadMetricsObserverTest,
       CrossSiteSubframeLargestContentfulPaint_MultiSubframes) {}

// The following tests are ensure that Page Load metrics are recorded in a
// trace. Currently enabled only for platforms where USE_PERFETTO_CLIENT_LIBRARY
// is true (Android, Linux) as test infra (TestTraceProcessor) requires it.
TEST_F(UmaPageLoadMetricsObserverTest, TestTracingFirstContentfulPaint) {}

TEST_F(UmaPageLoadMetricsObserverTest, TestTracingLargestContentfulPaint) {}

TEST_F(UmaPageLoadMetricsObserverTest, TestTracingLoadEventStart) {}

TEST_F(UmaPageLoadMetricsObserverTest, TestTracingDomContentLoadedEventStart) {}

TEST_P(UmaPageLoadMetricsObserverTest, LCPSpeculationRulesPrerender) {}