#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <algorithm>
#include <memory>
#include <string>
#include <vector>
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/json/json_string_value_serializer.h"
#include "base/strings/strcat.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/scoped_run_loop_timeout.h"
#include "base/test/trace_event_analyzer.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "cc/base/switches.h"
#include "chrome/browser/page_load_metrics/integration_tests/metric_integration_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/page_load_metrics/browser/page_load_metrics_test_waiter.h"
#include "components/paint_preview/buildflags/buildflags.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/common/content_switches.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/hit_test_region_observer.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/performance/largest_contentful_paint_type.h"
#if defined(USE_AURA)
#include "ui/aura/window.h"
#endif
#include "ui/events/test/event_generator.h"
#if BUILDFLAG(ENABLE_PAINT_PREVIEW)
#include "components/paint_preview/browser/paint_preview_client.h"
#endif
Query;
TraceAnalyzer;
TraceEvent;
TraceEventVector;
PageLoad;
namespace {
void ValidateTraceEventHasCorrectCandidateSize(int expected_size,
const TraceEvent& event) { … }
void ValidateTraceEventBreakdownTimings(const TraceEvent& event,
double lcp_time) { … }
int GetCandidateIndex(const TraceEvent& event) { … }
bool compare_candidate_index(const TraceEvent* lhs, const TraceEvent* rhs) { … }
}
IN_PROC_BROWSER_TEST_F(MetricIntegrationTest, LargestContentfulPaint) { … }
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
#define MAYBE_LargestContentfulPaint_SubframeInput …
#else
#define MAYBE_LargestContentfulPaint_SubframeInput …
#endif
IN_PROC_BROWSER_TEST_F(MetricIntegrationTest,
MAYBE_LargestContentfulPaint_SubframeInput) { … }
#if BUILDFLAG(ENABLE_PAINT_PREVIEW)
IN_PROC_BROWSER_TEST_F(MetricIntegrationTest,
LargestContentfulPaintPaintPreview) { … }
#endif
class LCPLazyLoadingImageTest : public MetricIntegrationTest { … };
IN_PROC_BROWSER_TEST_F(LCPLazyLoadingImageTest,
LargestContentfulPaint_EventLazyLoadingImage_Enabled) { … }
IN_PROC_BROWSER_TEST_F(LCPLazyLoadingImageTest,
LargestContentfulPaint_EventLazyLoadingImage_Unset) { … }
IN_PROC_BROWSER_TEST_F(
LCPLazyLoadingImageTest,
DISABLED_LargestContentfulPaint_EventLazyLoadingImage_Video) { … }
class PageViewportInLCPTest : public MetricIntegrationTest { … };
IN_PROC_BROWSER_TEST_F(PageViewportInLCPTest, FullSizeImageInIframe) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_IsAnimatedLCPTest …
#else
#define MAYBE_IsAnimatedLCPTest …
#endif
class MAYBE_IsAnimatedLCPTest : public MetricIntegrationTest { … };
IN_PROC_BROWSER_TEST_F(MAYBE_IsAnimatedLCPTest,
LargestContentfulPaint_IsAnimated) { … }
IN_PROC_BROWSER_TEST_F(MAYBE_IsAnimatedLCPTest,
LargestContentfulPaint_IsNotAnimated) { … }
IN_PROC_BROWSER_TEST_F(
MAYBE_IsAnimatedLCPTest,
LargestContentfulPaint_AnimatedImageWithLargerTextFirst) { … }
IN_PROC_BROWSER_TEST_F(MAYBE_IsAnimatedLCPTest,
DISABLED_LargestContentfulPaint_IsVideo) { … }
class LargestContentfulPaintTypeTest : public MetricIntegrationTest { … };
IN_PROC_BROWSER_TEST_F(LargestContentfulPaintTypeTest, ImageType_PNG) { … }
IN_PROC_BROWSER_TEST_F(LargestContentfulPaintTypeTest, ImageType_JPG) { … }
IN_PROC_BROWSER_TEST_F(LargestContentfulPaintTypeTest, ImageType_WebP) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_ImageType_GIF …
#else
#define MAYBE_ImageType_GIF …
#endif
IN_PROC_BROWSER_TEST_F(LargestContentfulPaintTypeTest, MAYBE_ImageType_GIF) { … }
IN_PROC_BROWSER_TEST_F(LargestContentfulPaintTypeTest, ImageType_AVIF) { … }
IN_PROC_BROWSER_TEST_F(LargestContentfulPaintTypeTest, ImageType_SVG) { … }
IN_PROC_BROWSER_TEST_F(LargestContentfulPaintTypeTest, TextType) { … }
IN_PROC_BROWSER_TEST_F(LargestContentfulPaintTypeTest,
LargeTextAndImage_TextType) { … }
IN_PROC_BROWSER_TEST_F(LargestContentfulPaintTypeTest,
ImageAndLargeText_TextType) { … }
IN_PROC_BROWSER_TEST_F(LargestContentfulPaintTypeTest,
TextAndLargeImage_ImageType) { … }
IN_PROC_BROWSER_TEST_F(LargestContentfulPaintTypeTest,
LargeImageAndText_ImageType) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_DataURIType …
#else
#define MAYBE_DataURIType …
#endif
IN_PROC_BROWSER_TEST_F(LargestContentfulPaintTypeTest, MAYBE_DataURIType) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_DataURIType_SVG …
#else
#define MAYBE_DataURIType_SVG …
#endif
IN_PROC_BROWSER_TEST_F(LargestContentfulPaintTypeTest, MAYBE_DataURIType_SVG) { … }
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
#define MAYBE_DataURIType_Video …
#else
#define MAYBE_DataURIType_Video …
#endif
IN_PROC_BROWSER_TEST_F(LargestContentfulPaintTypeTest,
MAYBE_DataURIType_Video) { … }
IN_PROC_BROWSER_TEST_F(MetricIntegrationTest, LCPBreakdownTimings) { … }
class LcpBreakdownTimingsTest : public MetricIntegrationTest { … };
IN_PROC_BROWSER_TEST_F(LcpBreakdownTimingsTest, Subframe) { … }
IN_PROC_BROWSER_TEST_F(LcpBreakdownTimingsTest, DISABLED_CrossSiteSubframe) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_MemCacheServedImage …
#else
#define MAYBE_MemCacheServedImage …
#endif
IN_PROC_BROWSER_TEST_F(LcpBreakdownTimingsTest, MAYBE_MemCacheServedImage) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_PreloadedImage …
#else
#define MAYBE_PreloadedImage …
#endif
IN_PROC_BROWSER_TEST_F(LcpBreakdownTimingsTest, MAYBE_PreloadedImage) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
#define MAYBE_PreloadedCacheableImage …
#else
#define MAYBE_PreloadedCacheableImage …
#endif
IN_PROC_BROWSER_TEST_F(LcpBreakdownTimingsTest, MAYBE_PreloadedCacheableImage) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_MAC)
#define MAYBE_NativeLazyLoadingImage …
#else
#define MAYBE_NativeLazyLoadingImage …
#endif
IN_PROC_BROWSER_TEST_F(LcpBreakdownTimingsTest, MAYBE_NativeLazyLoadingImage) { … }
IN_PROC_BROWSER_TEST_F(LcpBreakdownTimingsTest,
DISABLED_ManualLazyLoadingImage) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_CssBackgroundImage …
#else
#define MAYBE_CssBackgroundImage …
#endif
IN_PROC_BROWSER_TEST_F(LcpBreakdownTimingsTest, MAYBE_CssBackgroundImage) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
#define MAYBE_WrittenAsInnerHtmlImage …
#else
#define MAYBE_WrittenAsInnerHtmlImage …
#endif
IN_PROC_BROWSER_TEST_F(LcpBreakdownTimingsTest, MAYBE_WrittenAsInnerHtmlImage) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_MAC)
#define MAYBE_WrittenAsOuterHtmlImage …
#else
#define MAYBE_WrittenAsOuterHtmlImage …
#endif
IN_PROC_BROWSER_TEST_F(LcpBreakdownTimingsTest, MAYBE_WrittenAsOuterHtmlImage) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS) || defined(ADDRESS_SANITIZER)
#define MAYBE_DocumentWrittenImage …
#else
#define MAYBE_DocumentWrittenImage …
#endif
IN_PROC_BROWSER_TEST_F(LcpBreakdownTimingsTest, MAYBE_DocumentWrittenImage) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS) || defined(ADDRESS_SANITIZER)
#define MAYBE_SrcSetImage …
#else
#define MAYBE_SrcSetImage …
#endif
IN_PROC_BROWSER_TEST_F(LcpBreakdownTimingsTest, MAYBE_SrcSetImage) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_MAC)
#define MAYBE_DomMethodAddedImage …
#else
#define MAYBE_DomMethodAddedImage …
#endif
IN_PROC_BROWSER_TEST_F(LcpBreakdownTimingsTest, MAYBE_DomMethodAddedImage) { … }
IN_PROC_BROWSER_TEST_F(MetricIntegrationTest,
LCPBreakdownTimings_ImageAndLargerText) { … }
IN_PROC_BROWSER_TEST_F(MetricIntegrationTest,
LCPBreakdownTimings_ImageAndLargerImage) { … }
IN_PROC_BROWSER_TEST_F(MetricIntegrationTest,
DISABLED_LCPBreakdownTimings_DetachedWindow) { … }
IN_PROC_BROWSER_TEST_F(MetricIntegrationTest,
LCPBreakdownTimings_NoLcpForBrokenImage) { … }
IN_PROC_BROWSER_TEST_F(MetricIntegrationTest,
LcpSameOriginImage_CrossOriginTypeNotSet) { … }
IN_PROC_BROWSER_TEST_F(MetricIntegrationTest,
LcpCrossOriginImage_CrossOriginTypeIsSet) { … }