chromium/content/browser/renderer_host/back_forward_cache_metrics_browsertest.cc

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

#include "content/browser/renderer_host/back_forward_cache_metrics.h"

#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/browser/renderer_host/back_forward_cache_impl.h"
#include "content/browser/renderer_host/navigation_controller_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/content_navigation_policy.h"
#include "content/public/browser/browser_thread.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/back_forward_cache_util.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/shell/browser/shell.h"
#include "content/test/content_browser_test_utils_internal.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "net/dns/mock_host_resolver.h"
#include "services/device/public/cpp/test/scoped_geolocation_overrider.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/scheduler/web_scheduler_tracked_feature.h"
#include "third_party/blink/public/mojom/frame/back_forward_cache_controller.mojom-test-utils.h"

Bucket;
ElementsAre;

namespace content {

namespace {

ukm::SourceId ToSourceId(int64_t navigation_id) {}

// Some features are present in almost all page loads (especially the ones
// which are related to the document finishing loading).
// We ignore them to make tests easier to read and write.

blink::scheduler::WebSchedulerTrackedFeatures GetFeaturesToIgnore() {}

UkmMetrics;
UkmEntry;

enum BackForwardCacheStatus {};
}  // namespace

class BackForwardCacheMetricsBrowserTestBase : public ContentBrowserTest,
                                               public WebContentsObserver {};

class BackForwardCacheMetricsBrowserTest
    : public BackForwardCacheMetricsBrowserTestBase,
      public testing::WithParamInterface<BackForwardCacheStatus> {};

IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest, UKM) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest, CloneAndGoBack) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest,
                       FlushRecordsNotRestoredReasons) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest,
                       WebViewFlushRecordsExtendedNotRestoredReasons) {}

// Confirms that UKMs are not recorded on reloading.
IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest, Reload) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest,
                       SameDocumentNavigationAndGoBackImmediately) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest,
                       GoBackToSameDocumentNavigationEntry) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest,
                       GoBackToSameDocumentNavigationEntry2) {}

namespace {

std::vector<ukm::SourceId> GetMetricsSourceIds(
    ukm::TestAutoSetUkmRecorder* recorder) {}

}  // namespace

IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest, Features_MainFrame) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest,
                       Features_MainFrame_CrossOriginNavigation) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest,
                       Features_SameOriginSubframes) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest,
                       Features_SameOriginSubframes_CrossOriginNavigation) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest,
                       Features_CrossOriginSubframes) {}

// TODO(crbug.com/40290702): Shared workers are not available on Android.
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_SharedWorker
#else
#define MAYBE_SharedWorker
#endif
IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest, MAYBE_SharedWorker) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest, Geolocation) {}

class RecordBackForwardCacheMetricsWithoutEnabling
    : public BackForwardCacheMetricsBrowserTestBase {};

IN_PROC_BROWSER_TEST_F(RecordBackForwardCacheMetricsWithoutEnabling,
                       ReloadsAndHistoryNavigations) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest,
                       RecordReloadsAfterHistoryNavigation) {}

IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsBrowserTest,
                       RestoreNavigationToNextPaint) {}

class BackForwardCacheMetricsPrerenderingBrowserTest
    : public BackForwardCacheMetricsBrowserTest {};

// Tests that activating a prerender works correctly when navigated
// back.
IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsPrerenderingBrowserTest,
                       MainFrameNavigation) {}

class BackForwardCacheMetricsFencedFrameBrowserTest
    : public BackForwardCacheMetricsBrowserTest {};

// Tests that fenced frame navigation doesn't have BackForwardCacheMetrics.
IN_PROC_BROWSER_TEST_P(BackForwardCacheMetricsFencedFrameBrowserTest,
                       FenceFrameNavigation) {}

INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

}  // namespace content