#include "chrome/browser/page_load_metrics/observers/core/ukm_page_load_metrics_observer.h"
#include <memory>
#include <optional>
#include "base/memory/raw_ptr.h"
#include "base/metrics/metrics_hashes.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
#include "base/test/test_trace_processor.h"
#include "base/test/trace_event_analyzer.h"
#include "base/time/time.h"
#include "base/trace_event/traced_value.h"
#include "build/build_config.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/history_tab_helper.h"
#include "chrome/browser/history_clusters/history_clusters_service_factory.h"
#include "chrome/browser/history_clusters/history_clusters_tab_helper.h"
#include "chrome/browser/page_load_metrics/observers/page_load_metrics_observer_test_harness.h"
#include "chrome/browser/performance_manager/test_support/test_user_performance_tuning_manager_environment.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/search_test_utils.h"
#include "chrome/test/base/testing_profile.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/test/bookmark_test_helpers.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/browser/history_types.h"
#include "components/history/core/test/history_service_test_util.h"
#include "components/history_clusters/core/history_clusters_service.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/ntp_tiles/custom_links_store.h"
#include "components/page_load_metrics/browser/observers/core/largest_contentful_paint_handler.h"
#include "components/page_load_metrics/browser/page_load_metrics_observer.h"
#include "components/page_load_metrics/browser/page_load_tracker.h"
#include "components/page_load_metrics/common/page_load_metrics.mojom.h"
#include "components/page_load_metrics/common/page_visit_final_status.h"
#include "components/page_load_metrics/common/test/page_load_metrics_test_util.h"
#include "components/performance_manager/public/features.h"
#include "components/performance_manager/public/user_tuning/prefs.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/testing_pref_service.h"
#include "components/search_engines/template_url_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/mock_navigation_handle.h"
#include "content/public/test/navigation_simulator.h"
#include "net/base/ip_endpoint.h"
#include "net/nqe/effective_connection_type.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_source.h"
#include "services/network/public/cpp/network_quality_tracker.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/performance/largest_contentful_paint_type.h"
#include "third_party/metrics_proto/system_profile.pb.h"
#include "third_party/perfetto/include/perfetto/tracing/track.h"
NavigationSimulator;
RenderFrameHost;
RenderFrameHostTester;
PageVisitFinalStatus;
AnyNumber;
Mock;
Return;
UserInteractionLatenciesPtr;
UserInteractionLatencies;
UserInteractionLatency;
UserInteractionType;
namespace {
GeneratedNavigation;
LargestContentState;
LargestContentTextOrImage;
PageLoad;
PageLoad_Internal;
UserPerceivedPageVisit;
const char kTestUrl1[] = …;
const char kTestUrl2[] = …;
const char kSubframeTestUrl[] = …;
class MockNetworkQualityProvider : public network::NetworkQualityTracker { … };
}
class UkmPageLoadMetricsObserverTest
: public page_load_metrics::PageLoadMetricsObserverTestHarness { … };
class UkmPageLoadMetricsObserverWithMockTimeTest
: public UkmPageLoadMetricsObserverTest { … };
TEST_F(UkmPageLoadMetricsObserverTest, NoMetrics) { … }
TEST_F(UkmPageLoadMetricsObserverTest, Basic) { … }
TEST_F(UkmPageLoadMetricsObserverTest, FailedProvisionalLoad) { … }
TEST_F(UkmPageLoadMetricsObserverTest, LargestImagePaint) { … }
TEST_F(UkmPageLoadMetricsObserverTest, LargestImagePaintCrossOrigin) { … }
TEST_F(UkmPageLoadMetricsObserverTest, LargestImagePaintVideo) { … }
TEST_F(UkmPageLoadMetricsObserverTest, LargestImagePaintAnimated) { … }
TEST_F(UkmPageLoadMetricsObserverTest, LargestImagePaintFromSubframeMerged) { … }
TEST_F(UkmPageLoadMetricsObserverTest, LargestImagePaintFromMainFrameMerged) { … }
TEST_F(UkmPageLoadMetricsObserverTest, LargestImageLoading) { … }
TEST_F(UkmPageLoadMetricsObserverTest, LargestImageLoadingSmallerThanText) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
LargestImagePaint_DiscardBackgroundResult) { … }
TEST_F(UkmPageLoadMetricsObserverTest, AbortNeverForegrounded) { … }
TEST_F(UkmPageLoadMetricsObserverTest, FCPPlusPlus_DiscardBackgroundResult) { … }
TEST_F(UkmPageLoadMetricsObserverTest, FCPPlusPlus_ReportLastCandidate) { … }
TEST_F(UkmPageLoadMetricsObserverTest, LargestTextPaint) { … }
TEST_F(UkmPageLoadMetricsObserverTest, LargestContentfulPaint_Trace) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
LargestContentfulPaint_Trace_InvalidateCandidate) { … }
TEST_F(UkmPageLoadMetricsObserverTest, LargestContentfulPaint_OnlyText) { … }
TEST_F(UkmPageLoadMetricsObserverTest, LargestContentfulPaint_OnlyImage) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
LargestContentfulPaint_ImageLargerThanText) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
LargestContentfulPaintAllFrames_OnlySubframe) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
LargestContentfulPaintAllFrames_SubframeImageLoading) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
LargestContentfulPaintAllFrames_OnlyMainFrame) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
LargestContentfulPaintAllFrames_CrossSiteSubFrame) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
LargestContentfulPaintAllFrames_MergeFrameCandidateBySize) { … }
TEST_F(UkmPageLoadMetricsObserverTest, NormalizedUserInteractionLatencies) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
NormalizedUserInteractionLatenciesRecordOnHidden) { … }
TEST_F(UkmPageLoadMetricsObserverTest, FirstInputDelayAndTimestamp) { … }
TEST_F(UkmPageLoadMetricsObserverTest, FirstScrollDelayAndTimestamp) { … }
TEST_F(UkmPageLoadMetricsObserverTest, MultiplePageLoads) { … }
TEST_F(UkmPageLoadMetricsObserverTest, NetworkQualityEstimates) { … }
TEST_F(UkmPageLoadMetricsObserverTest, PageTransitionReload) { … }
TEST_F(UkmPageLoadMetricsObserverTest, PageSizeMetrics) { … }
TEST_F(UkmPageLoadMetricsObserverTest, JSSizeMetrics) { … }
TEST_F(UkmPageLoadMetricsObserverTest, JSMaxSizeMetrics) { … }
TEST_F(UkmPageLoadMetricsObserverTest, ImageMediaSizeMetrics) { … }
TEST_F(UkmPageLoadMetricsObserverTest, CpuTimeMetrics) { … }
TEST_F(UkmPageLoadMetricsObserverTest, LayoutInstability) { … }
TEST_F(UkmPageLoadMetricsObserverTest, SoftNavigationCount) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
ExperimentalLayoutInstabilityRecordOnHidden) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
ExperimentalLayoutInstabilityRecordOnPageOpenBackground) { … }
TEST_F(UkmPageLoadMetricsObserverWithMockTimeTest,
LargestContentfulPaintRecordOnHidden) { … }
TEST_F(UkmPageLoadMetricsObserverWithMockTimeTest,
LargestContentfulPaintRecordOnPageOpenBackground) { … }
TEST_F(UkmPageLoadMetricsObserverTest, SiteInstanceRenderProcessAssignment) { … }
TEST_F(UkmPageLoadMetricsObserverTest, MHTMLNotTrackedOfflinePreview) { … }
TEST_F(UkmPageLoadMetricsObserverTest, LayoutInstabilitySubframeAggregation) { … }
TEST_F(UkmPageLoadMetricsObserverTest, ThirdPartyCookieBlockingDisabled) { … }
TEST_F(UkmPageLoadMetricsObserverTest, ThirdPartyCookieBlockingEnabled) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
ThirdPartyCookieBlockingDisabledForSite) { … }
TEST_F(UkmPageLoadMetricsObserverTest, NotSearchOrHomePage) { … }
TEST_F(UkmPageLoadMetricsObserverTest, HomePageReported) { … }
TEST_F(UkmPageLoadMetricsObserverTest, DefaultSearchReported) { … }
TEST_F(UkmPageLoadMetricsObserverTest, NavigationIsScopedSearchLikeNavigation) { … }
TEST_F(UkmPageLoadMetricsObserverTest, NoLargestContentfulPaint) { … }
TEST_F(UkmPageLoadMetricsObserverTest, FCPHiddenWhileFlushing) { … }
TEST_F(UkmPageLoadMetricsObserverTest, LCPHiddenWhileFlushing) { … }
TEST_F(UkmPageLoadMetricsObserverTest, AppEnterBackground) { … }
TEST_F(UkmPageLoadMetricsObserverTest, IsExistingBookmark) { … }
TEST_F(UkmPageLoadMetricsObserverTest, IsNewBookmark) { … }
#if !BUILDFLAG(IS_ANDROID)
TEST_F(UkmPageLoadMetricsObserverTest, IsNTPCustomLink) { … }
#endif
TEST_F(UkmPageLoadMetricsObserverTest, DurationSinceLastVisitSeconds) { … }
TEST_F(UkmPageLoadMetricsObserverTest, NavigationTimestamp) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
DurationSinceLastVisitSecondsHistoryServiceLosesRace) { … }
class TestOfflinePreviewsUkmPageLoadMetricsObserver
: public UkmPageLoadMetricsObserver { … };
class OfflinePreviewsUKMPageLoadMetricsObserverTest
: public UkmPageLoadMetricsObserverTest { … };
TEST_F(OfflinePreviewsUKMPageLoadMetricsObserverTest, OfflinePreviewReported) { … }
TEST_F(UkmPageLoadMetricsObserverTest, NavigationTiming) { … }
TEST_F(UkmPageLoadMetricsObserverTest, CLSNeverForegroundedNoReport) { … }
class CLSUkmPageLoadMetricsObserverTest
: public UkmPageLoadMetricsObserverTest { … };
void CLSUkmPageLoadMetricsObserverTest::SimulateShiftDelta(
float delta,
content::RenderFrameHost* frame) { … }
RenderFrameHost* CLSUkmPageLoadMetricsObserverTest::NavigateSubframe() { … }
void CLSUkmPageLoadMetricsObserverTest::VerifyUKMBuckets(
int total,
int before_input_or_scroll) { … }
void CLSUkmPageLoadMetricsObserverTest::InitPageLoadTimingWithInputOrScroll(
page_load_metrics::mojom::PageLoadTiming& timing,
base::TimeDelta timestamp) { … }
void CLSUkmPageLoadMetricsObserverTest::RunBeforeInputOrScrollCase(
bool input_in_subframe) { … }
TEST_F(CLSUkmPageLoadMetricsObserverTest, BeforeInputOrScroll_Main) { … }
TEST_F(CLSUkmPageLoadMetricsObserverTest, BeforeInputOrScroll_Sub) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
TestLogsBrowserInitiatedNavigationAsUserInitiated) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
TestLogsUserInitiatedRendererNavigationAsUserInitiated) { … }
TEST_F(UkmPageLoadMetricsObserverTest,
TestLogsRendererInitiatedRendererNavigationAsUserInitiated) { … }
TEST_F(UkmPageLoadMetricsObserverTest, TestWasDiscarded) { … }
#if !BUILDFLAG(IS_ANDROID)
TEST_F(UkmPageLoadMetricsObserverTest, TestRefreshRateThrottled) { … }
#endif
class TracingWebContentsObserver : public content::WebContentsObserver { … };
TEST_F(UkmPageLoadMetricsObserverTest, TestTracingUserTimingMetrics) { … }