chromium/components/page_load_metrics/browser/metrics_web_contents_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/metrics_web_contents_observer.h"

#include <memory>

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/process/kill.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "base/timer/mock_timer.h"
#include "components/page_load_metrics/browser/metrics_lifecycle_observer.h"
#include "components/page_load_metrics/browser/page_load_metrics_test_content_browser_client.h"
#include "components/page_load_metrics/browser/page_load_tracker.h"
#include "components/page_load_metrics/browser/test_metrics_web_contents_observer_embedder.h"
#include "components/page_load_metrics/common/page_load_metrics.mojom.h"
#include "content/public/browser/back_forward_cache.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_features.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/render_frame_host_test_support.h"
#include "content/public/test/test_renderer_host.h"
#include "net/base/net_errors.h"
#include "net/cert/cert_status_flags.h"
#include "services/network/public/mojom/fetch_api.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/utility/utility.h"
#include "third_party/blink/public/common/performance/performance_timeline_constants.h"
#include "third_party/blink/public/common/use_counter/use_counter_feature.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom.h"
#include "third_party/blink/public/mojom/use_counter/use_counter_feature.mojom-shared.h"
#include "url/url_constants.h"

NavigationSimulator;

namespace page_load_metrics {

namespace {

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

void PopulatePageLoadTiming(mojom::PageLoadTiming* timing) {}

blink::mojom::ResourceLoadInfoPtr CreateResourceLoadInfo(
    const GURL& url,
    network::mojom::RequestDestination request_destination) {}

}  //  namespace

class MetricsWebContentsObserverTest
    : public content::RenderViewHostTestHarness {};

TEST_F(MetricsWebContentsObserverTest, SuccessfulMainFrameNavigation) {}

TEST_F(MetricsWebContentsObserverTest,
       DISABLED_MainFrameNavigationInternalAbort) {}

TEST_F(MetricsWebContentsObserverTest, SubFrame) {}

TEST_F(MetricsWebContentsObserverTest, SameDocumentNoTrigger) {}

TEST_F(MetricsWebContentsObserverTest, DontLogNewTabPage) {}

TEST_F(MetricsWebContentsObserverTest, DontLogIrrelevantNavigation) {}

TEST_F(MetricsWebContentsObserverTest, EmptyTimingError) {}

TEST_F(MetricsWebContentsObserverTest, NullNavigationStartError) {}

TEST_F(MetricsWebContentsObserverTest, TimingOrderError) {}

TEST_F(MetricsWebContentsObserverTest, BadIPC) {}

TEST_F(MetricsWebContentsObserverTest, ObservePartialNavigation) {}

TEST_F(MetricsWebContentsObserverTest, StopObservingOnCommit) {}

TEST_F(MetricsWebContentsObserverTest, StopObservingOnStart) {}

// We buffer cross frame timings in order to provide a consistent view of
// timing data to observers. See crbug.com/722860 for more.
TEST_F(MetricsWebContentsObserverTest, OutOfOrderCrossFrameTiming) {}

// We buffer cross-frame paint updates to account for paint timings from
// different frames arriving out of order.
TEST_F(MetricsWebContentsObserverTest, OutOfOrderCrossFrameTiming2) {}

TEST_F(MetricsWebContentsObserverTest, FlushBufferOnAppBackground) {}

TEST_F(MetricsWebContentsObserverTest,
       FirstInputDelayMissingFirstInputTimestamp) {}

TEST_F(MetricsWebContentsObserverTest,
       FirstInputTimestampMissingFirstInputDelay) {}

// Main frame delivers an input notification. Subsequently, a subframe delivers
// an input notification, where the input occurred first. Verify that
// FirstInputDelay and FirstInputTimestamp come from the subframe.
TEST_F(MetricsWebContentsObserverTest,
       FirstInputDelayAndTimingSubframeFirstDeliveredSecond) {}

// A subframe delivers an input notification. Subsequently, the mainframe
// delivers an input notification, where the input occurred first. Verify that
// FirstInputDelay and FirstInputTimestamp come from the main frame.
TEST_F(MetricsWebContentsObserverTest,
       FirstInputDelayAndTimingMainframeFirstDeliveredSecond) {}

TEST_F(MetricsWebContentsObserverTest, DispatchDelayedMetricsOnPageClose) {}

// Make sure the dispatch of CPU occurs immediately.
TEST_F(MetricsWebContentsObserverTest, DispatchCpuMetricsImmediately) {}

TEST_F(MetricsWebContentsObserverTest, OnLoadedResource_MainFrame) {}

TEST_F(MetricsWebContentsObserverTest, OnLoadedResource_Subresource) {}

TEST_F(MetricsWebContentsObserverTest,
       OnLoadedResource_ResourceFromOtherRFHIgnored) {}

TEST_F(MetricsWebContentsObserverTest,
       OnLoadedResource_IgnoreNonHttpOrHttpsScheme) {}

TEST_F(MetricsWebContentsObserverTest, RecordFeatureUsage) {}

TEST_F(MetricsWebContentsObserverTest, RecordFeatureUsageNoObserver) {}

TEST_F(MetricsWebContentsObserverTest, CustomUserTiming) {}

class MetricsWebContentsObserverBackForwardCacheTest
    : public MetricsWebContentsObserverTest,
      public content::WebContentsDelegate {};

TEST_F(MetricsWebContentsObserverBackForwardCacheTest,
       RecordFeatureUsageWithBackForwardCache) {}

// Checks OnEnterBackForwardCache is called appropriately with back-forward
// cache enabled.
TEST_F(MetricsWebContentsObserverBackForwardCacheTest, EnterBackForwardCache) {}

// TODO(hajimehoshi): Detect the document eviction so that PageLoadTracker in
// the cache is destroyed. This would call PageLoadMetricsObserver::OnComplete.
// This test can be implemented after a PageLoadMetricsObserver's
// OnEnterBackForwardCache returns CONTINUE_OBSERVING.

class MetricsWebContentsObserverBackForwardCacheDisabledTest
    : public MetricsWebContentsObserverTest {};

// Checks OnEnterBackForwardCache is NOT called without back-forward cache
// enabled.
TEST_F(MetricsWebContentsObserverBackForwardCacheDisabledTest,
       EnterBackForwardCacheNotCalled) {}

class MetricsWebContentsObserverNonPrimaryPageTest
    : public MetricsWebContentsObserverBackForwardCacheTest {};

TEST_F(MetricsWebContentsObserverNonPrimaryPageTest, MemoryUpdates) {}

}  // namespace page_load_metrics