Truly independent web browser
LibWeb: Implement Paint Timing
Andreas Kling54ea6ab0d5c3
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txtindex 9e06a068bf2..6c21ffe3f89 100644--- a/Libraries/LibWeb/CMakeLists.txt+++ b/Libraries/LibWeb/CMakeLists.txt@@ -775,6 +775,8 @@ set(SOURCESPage/PageCursor.cppPage/RenderingStats.cppPage/ScreenWakeLockHandle.cpp+ PaintTiming/PaintTiming.cpp+ PaintTiming/PerformancePaintTiming.cppPainting/Blending.cppPainting/BoxModelMetrics.cppPainting/BoxViews.cppdiff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.hindex f7391c240cf..2464778afd6 100644--- a/Libraries/LibWeb/DOM/Document.h+++ b/Libraries/LibWeb/DOM/Document.h@@ -57,6 +57,7 @@#include <LibWeb/Infra/SerializedURL.h>#include <LibWeb/InvalidateDisplayList.h>#include <LibWeb/Layout/LayoutRustFFI.h>+#include <LibWeb/PaintTiming/DocumentPaintTimingState.h>#include <LibWeb/Painting/DisplayListRecording.h>#include <LibWeb/Painting/FlexboxInspectorOverlay.h>#include <LibWeb/Painting/Forward.h>@@ -636,6 +637,9 @@ public:// Whether the last layout committed a box whose `content-visibility` is `auto`.bool has_boxes_with_auto_content_visibility() const;Compositing::AccumulatedVisualContextTree visual_context_tree() const;++ PaintTiming::DocumentPaintTimingState& paint_timing_state() { return m_paint_timing_state; }+Compositing::ScrollStateSnapshot const& scroll_state_snapshot() const;GC::Ref<NodeList> get_elements_by_name(Utf16View);@@ -2167,6 +2171,8 @@ private:GC::Ptr<CSS::VisualViewport> m_visual_viewport;+ PaintTiming::DocumentPaintTimingState m_paint_timing_state;+// NOTE: Not in the spec per se, but Document must be able to access all IntersectionObservers whose root is in the document.GC::WeakHashSet<IntersectionObserver::IntersectionObserver> m_intersection_observers;diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.hindex 334ae517fb8..8ca3bcb842e 100644--- a/Libraries/LibWeb/Forward.h+++ b/Libraries/LibWeb/Forward.h@@ -977,6 +977,12 @@ class Notification;}+namespace Web::PaintTiming {++class PerformancePaintTiming;++}+namespace Web::Painting {class BoxViewRepaintAccess;diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cppindex 453b3743ba8..bb5afe067e9 100644--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp@@ -45,6 +45,7 @@#include <LibWeb/Page/EventHandler.h>#include <LibWeb/Page/Page.h>#include <LibWeb/Page/RenderingStats.h>+#include <LibWeb/PaintTiming/PaintTiming.h>#include <LibWeb/Painting/BoxViews.h>#include <LibWeb/Painting/DocumentPaintState.h>#include <LibWeb/Platform/EventLoopPlugin.h>@@ -1235,7 +1236,14 @@ void EventLoop::update_the_rendering_after_style_and_layout(Vector<GC::Root<DOM:// FIXME: 20. For each doc of docs, record rendering time for doc given unsafeStyleAndLayoutStartTime.- // FIXME: 21. For each doc of docs, mark paint timing for doc.+ // 21. For each doc of docs, mark paint timing for doc.+ for (auto& document : docs) {+ // AD-HOC: Script that ran earlier in this rendering update may have detached document from its navigable, as+ // in step 16. Nothing is rendered for it anymore.+ if (!document->navigable() || document->navigable()->active_document().ptr() != document.ptr())+ continue;+ PaintTiming::mark_paint_timing(*document);+ }// AD-HOC: Flush dirty canvas contexts in documents' pages after callbacks// have had a chance to update them, and before painting snapshots the frame.diff --git a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cppindex df71f102ec2..191117318d6 100644--- a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp+++ b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp@@ -67,6 +67,7 @@#include <LibWeb/NavigationTiming/PerformanceNavigationTiming.h>#include <LibWeb/Page/Page.h>#include <LibWeb/Page/RenderingStats.h>+#include <LibWeb/PaintTiming/PerformancePaintTiming.h>#include <LibWeb/Painting/PaintingRustBridge.h>#include <LibWeb/PerformanceTimeline/EntryTypes.h>#include <LibWeb/PerformanceTimeline/EventNames.h>@@ -108,29 +109,20 @@ WindowOrWorkerGlobalScopeMixin::~WindowOrWorkerGlobalScopeMixin() = default;void WindowOrWorkerGlobalScopeMixin::initialize(){-#define __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(entry_type, cpp_class) \- m_performance_entry_buffer_map.set(entry_type, \- PerformanceTimeline::PerformanceEntryTuple { \- .performance_entry_buffer = {}, \- .max_buffer_size = cpp_class::max_buffer_size(), \- .available_from_timeline = cpp_class::available_from_timeline(), \- .dropped_entries_count = 0, \- });+ bool global_is_window = is<HTML::Window>(this_impl());++#define __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(entry_type, cpp_class, globals) \+ if (HighResolutionTime::is_supported_for_global(HighResolutionTime::SupportedPerformanceEntryTypeGlobals::globals, global_is_window)) { \+ m_performance_entry_buffer_map.set(entry_type, \+ PerformanceTimeline::PerformanceEntryTuple { \+ .performance_entry_buffer = {}, \+ .max_buffer_size = cpp_class::max_buffer_size(), \+ .available_from_timeline = cpp_class::available_from_timeline(), \+ .dropped_entries_count = 0, \+ }); \+ }ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES#undef __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES-- if (is<HTML::Window>(this_impl())) {-#define __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(entry_type, cpp_class) \- m_performance_entry_buffer_map.set(entry_type, \- PerformanceTimeline::PerformanceEntryTuple { \- .performance_entry_buffer = {}, \- .max_buffer_size = cpp_class::max_buffer_size(), \- .available_from_timeline = cpp_class::available_from_timeline(), \- .dropped_entries_count = 0, \- });- ENUMERATE_WINDOW_SUPPORTED_PERFORMANCE_ENTRY_TYPES-#undef __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES- }}void WindowOrWorkerGlobalScopeMixin::visit_edges(JS::Cell::Visitor& visitor)diff --git a/Libraries/LibWeb/HighResolutionTime/SupportedPerformanceTypes.h b/Libraries/LibWeb/HighResolutionTime/SupportedPerformanceTypes.hindex 1cfdfcb6d2e..40bc423b7bb 100644--- a/Libraries/LibWeb/HighResolutionTime/SupportedPerformanceTypes.h+++ b/Libraries/LibWeb/HighResolutionTime/SupportedPerformanceTypes.h@@ -8,19 +8,23 @@namespace Web::HighResolutionTime {-// Please keep these in alphabetical order based on the entry type :^)-#define ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES_BEFORE_NAVIGATION \- __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(PerformanceTimeline::EntryTypes::mark, UserTiming::PerformanceMark) \- __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(PerformanceTimeline::EntryTypes::measure, UserTiming::PerformanceMeasure)--#define ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES_AFTER_NAVIGATION \- __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(PerformanceTimeline::EntryTypes::resource, ResourceTiming::PerformanceResourceTiming)+// The global objects an entry type is supported for.+enum class SupportedPerformanceEntryTypeGlobals {+ WindowAndWorker,+ WindowOnly,+};-#define ENUMERATE_WINDOW_SUPPORTED_PERFORMANCE_ENTRY_TYPES \- __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(PerformanceTimeline::EntryTypes::navigation, NavigationTiming::PerformanceNavigationTiming)+inline bool is_supported_for_global(SupportedPerformanceEntryTypeGlobals globals, bool global_is_window)+{+ return globals == SupportedPerformanceEntryTypeGlobals::WindowAndWorker || global_is_window;+}-#define ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES \- ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES_BEFORE_NAVIGATION \- ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES_AFTER_NAVIGATION+// Please keep these in alphabetical order based on the entry type :^)+#define ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES \+ __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(PerformanceTimeline::EntryTypes::mark, UserTiming::PerformanceMark, WindowAndWorker) \+ __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(PerformanceTimeline::EntryTypes::measure, UserTiming::PerformanceMeasure, WindowAndWorker) \+ __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(PerformanceTimeline::EntryTypes::navigation, NavigationTiming::PerformanceNavigationTiming, WindowOnly) \+ __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(PerformanceTimeline::EntryTypes::paint, PaintTiming::PerformancePaintTiming, WindowOnly) \+ __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(PerformanceTimeline::EntryTypes::resource, ResourceTiming::PerformanceResourceTiming, WindowAndWorker)}diff --git a/Libraries/LibWeb/PaintTiming/DocumentPaintTimingState.h b/Libraries/LibWeb/PaintTiming/DocumentPaintTimingState.hnew file mode 100644index 00000000000..c49d4d29511--- /dev/null+++ b/Libraries/LibWeb/PaintTiming/DocumentPaintTimingState.h@@ -0,0 +1,20 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <AK/HashTable.h>+#include <AK/Utf16String.h>++namespace Web::PaintTiming {++struct DocumentPaintTimingState {+ // https://w3c.github.io/paint-timing/#set-of-previously-reported-paints+ // Each Document has a set of previously reported paints, which is an ordered set of strings, initially empty.+ OrderedHashTable<Utf16String> set_of_previously_reported_paints;+};++}diff --git a/Libraries/LibWeb/PaintTiming/PaintTiming.cpp b/Libraries/LibWeb/PaintTiming/PaintTiming.cppnew file mode 100644index 00000000000..dc8129b36aa--- /dev/null+++ b/Libraries/LibWeb/PaintTiming/PaintTiming.cpp@@ -0,0 +1,463 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <AK/NeverDestroyed.h>+#include <LibWeb/CSS/ComputedValues.h>+#include <LibWeb/CSS/FontComputer.h>+#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>+#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>+#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>+#include <LibWeb/CSS/StyleValues/StyleValueList.h>+#include <LibWeb/DOM/Document.h>+#include <LibWeb/DOM/Element.h>+#include <LibWeb/HTML/HTMLCanvasElement.h>+#include <LibWeb/HTML/HTMLInputElement.h>+#include <LibWeb/HTML/HTMLVideoElement.h>+#include <LibWeb/HTML/LocalNavigable.h>+#include <LibWeb/HTML/Scripting/Environments.h>+#include <LibWeb/HTML/Window.h>+#include <LibWeb/HighResolutionTime/TimeOrigin.h>+#include <LibWeb/Layout/Box.h>+#include <LibWeb/Layout/TextNode.h>+#include <LibWeb/Layout/Viewport.h>+#include <LibWeb/PaintTiming/PaintTiming.h>+#include <LibWeb/PaintTiming/PerformancePaintTiming.h>+#include <LibWeb/Painting/BoxViews.h>++namespace Web::PaintTiming {++static Utf16String const& first_paint_name()+{+ static NeverDestroyed<Utf16String> name { "first-paint"_utf16 };+ return *name;+}++static Utf16String const& first_contentful_paint_name()+{+ static NeverDestroyed<Utf16String> name { "first-contentful-paint"_utf16 };+ return *name;+}++// https://w3c.github.io/paint-timing/#non-empty+static bool is_non_empty(Utf16View const& string)+{+ // A DOMString is non-empty if it contains at least one character excluding document white space characters.+ for (auto code_unit : string) {+ if (code_unit != ' ' && code_unit != '\t' && code_unit != '\n' && code_unit != '\r' && code_unit != '\f')+ return true;+ }+ return false;+}++static RefPtr<CSS::StyleValue const> style_value_of(CSS::ComputedValuesFFI::ComputedStyleValueHandle const& handle)+{+ if (!handle.pointer)+ return nullptr;+ return CSS::StyleValue::adopt_rust_style_value_data(CSS::StyleValueFFI::rust_style_value_retain(static_cast<CSS::StyleValueFFI::StyleValueData const*>(handle.pointer)));+}++static bool is_zero_length_or_percentage(CSS::StyleValue const& value)+{+ if (value.is_length())+ return value.as_length().raw_value() == 0;+ if (value.is_percentage())+ return value.as_percentage().raw_value() == 0;+ return false;+}++// Whether the used background-size of the given background layer has a zero width or height.+static bool background_size_is_empty(Layout::NodeWithStyle const& node, size_t layer_index)+{+ auto background_size = style_value_of(node.style_group<CSS::ComputedValues::BackgroundValues>().background_size);+ if (!background_size)+ return false;+ if (background_size->is_value_list()) {+ auto const& list = background_size->as_value_list();+ if (list.size() == 0)+ return false;+ background_size = list.value_at(layer_index, true);+ }+ if (!background_size->is_background_size())+ return false;+ auto const& size = background_size->as_background_size();+ return is_zero_length_or_percentage(size.size_x()) || is_zero_length_or_percentage(size.size_y());+}++// https://w3c.github.io/paint-timing/#contentful-image+static bool is_contentful_image(Layout::NodeWithStyle::ImageObserver const* observer)+{+ // A CSS image img is a contentful image when all of the following apply:+ // - img is url valued.+ // - img is available.+ // NB: Only url-valued images have an observer, which holds the decoded image data once it is available.+ return observer && observer->decoded_image_data();+}++static bool svg_has_rendered_descendants(Layout::Node const& svg_box)+{+ bool has_rendered_descendants = false;+ svg_box.for_each_in_inclusive_subtree([&](Layout::Node const& node) {+ if (&node == &svg_box)+ return TraversalDecision::Continue;+ switch (node.kind()) {+ case Layout::RustFFI::NodeKind::SVGGeometryBox:+ case Layout::RustFFI::NodeKind::SVGImageBox:+ case Layout::RustFFI::NodeKind::SVGTextBox:+ case Layout::RustFFI::NodeKind::SVGTextPathBox:+ case Layout::RustFFI::NodeKind::SVGForeignObjectBox:+ has_rendered_descendants = true;+ return TraversalDecision::Break;+ default:+ return TraversalDecision::Continue;+ }+ });+ return has_rendered_descendants;+}++// https://w3c.github.io/paint-timing/#contentful+// NB: This answers the question for the box of an element, or for a text node's box, which stands for the element+// the text node is a child of. Generated content has boxes of its own, so a pseudo-element's content is found+// the same way as an element's.+static bool is_contentful(Layout::Node const& node)+{+ // An element target is contentful when one or more of the following apply:++ // - target has a text node child, representing non-empty text, and the node's used opacity is greater than zero.+ // NB: The opacity of the text node's ancestors is checked as part of whether it is paintable.+ if (auto const* text_node = as_if<Layout::TextNode>(node)) {+ if (auto const* dom_text = text_node->dom_text())+ return is_non_empty(dom_text->data().utf16_view());+ // NB: Generated text has no DOM node, so its rendered text is looked at instead.+ auto rendered_text = text_node->rendered_text_for_dom();+ return is_non_empty(rendered_text.utf16_view());+ }++ auto const* node_with_style = as_if<Layout::NodeWithStyle>(node);+ if (!node_with_style)+ return false;++ auto const* dom_node = node.dom_node();++ switch (node.kind()) {+ // - target is a replaced element representing an available image.+ case Layout::RustFFI::NodeKind::ImageBox:+ case Layout::RustFFI::NodeKind::SVGImageBox: {+ auto const* image_provider = as<Layout::Box>(node).image_provider_if_any();+ if (image_provider && image_provider->is_image_available())+ return true;+ break;+ }+ // - target is a canvas with its context mode set to any value other than none.+ case Layout::RustFFI::NodeKind::CanvasBox:+ if (auto const* canvas = as_if<HTML::HTMLCanvasElement>(dom_node); canvas && !canvas->context().has<Empty>())+ return true;+ break;+ // - target is a video element that represents its poster frame or the first video frame and the frame is+ // available.+ case Layout::RustFFI::NodeKind::VideoBox:+ if (auto const* video = as_if<HTML::HTMLVideoElement>(dom_node)) {+ auto representation = video->current_representation();+ if (representation == HTML::HTMLVideoElement::Representation::PosterFrame && video->poster_frame().has_value())+ return true;+ if (representation == HTML::HTMLVideoElement::Representation::VideoFrame || representation == HTML::HTMLVideoElement::Representation::FirstVideoFrame)+ return true;+ }+ break;+ // - target is an svg element with rendered descendants.+ case Layout::RustFFI::NodeKind::SVGSVGBox:+ if (svg_has_rendered_descendants(node))+ return true;+ break;+ // - target is an input element with a non-empty value attribute.+ // NB: The value is what the control renders, which the value attribute only provides the default for.+ case Layout::RustFFI::NodeKind::TextInputBox:+ if (auto const* input = as_if<HTML::HTMLInputElement>(dom_node)) {+ auto value = input->value();+ if (is_non_empty(value.utf16_view()))+ return true;+ }+ break;+ default:+ break;+ }++ // - target has a background-image which is a contentful image, and its used background-size has non-zero width+ // and height values.+ auto background_layer_count = node_with_style->background_images().size();+ for (size_t layer_index = 0; layer_index < background_layer_count; ++layer_index) {+ if (is_contentful_image(node_with_style->background_image_observer(layer_index)) && !background_size_is_empty(*node_with_style, layer_index))+ return true;+ }++ // - target has a border-image-source which is a contentful image, and its used border-image-width has non-zero+ // value.+ // FIXME: Check the used border-image-width.+ if (is_contentful_image(node_with_style->border_image_source_observer()))+ return true;++ // - target is an originating element for a paintable pseudo-element that represents a contentful image or+ // non-empty text.+ // NB: The boxes of a pseudo-element's generated content are checked like those of any element.++ return false;+}++// AD-HOC: Whether the box paints something other than the default background, which is what first paint is about.+static bool paints_non_default_content(Layout::Node const& node)+{+ if (is_contentful(node))+ return true;++ auto const* node_with_style = as_if<Layout::NodeWithStyle>(node);+ if (!node_with_style)+ return false;++ // NB: The enclosing box of a paintable iframe counts towards first paint.+ if (node.kind() == Layout::RustFFI::NodeKind::NavigableContainerViewport)+ return true;++ if (node_with_style->background_color().alpha() > 0)+ return true;++ for (auto const& background_image : node_with_style->background_images()) {+ if (background_image)+ return true;+ }++ auto border_is_painted = [](CSS::BorderData const& border) {+ return border.width > 0 && border.line_style != CSS::LineStyle::None && border.line_style != CSS::LineStyle::Hidden && border.color.alpha() > 0;+ };+ return border_is_painted(node_with_style->border_left()) || border_is_painted(node_with_style->border_top()) || border_is_painted(node_with_style->border_right()) || border_is_painted(node_with_style->border_bottom());+}++static CSSPixelRect client_rect_of_box(Layout::Node const& node, Layout::RustFFI::FfiRectToViewportTransform const& rect_to_viewport_transform)+{+ if (!node.is_text_node())+ return Painting::bounding_client_rect(node, rect_to_viewport_transform);++ // NB: The client rect of a text box is the union of the rects of its fragments.+ CSSPixelRect united_rect;+ Layout::RustFFI::layout_script_text_range_rects(+ node.document_host(), Layout::Node::slot_id(&node),+ to_underlying(Painting::SelectionState::Full), 0, 0, 0, NumericLimits<size_t>::max(),+ rect_to_viewport_transform, &united_rect, [](void* context, CSSPixelRect rect) {+ auto& united_rect = *static_cast<CSSPixelRect*>(context);+ if (rect.is_empty())+ return;+ united_rect = united_rect.is_empty() ? rect : united_rect.united(rect);+ });+ return united_rect;+}++// NB: This answers whether boxes of the document are paintable, from the state the document has after layout.+class PaintableChecker {+public:+ explicit PaintableChecker(DOM::Document& document)+ : m_read(document)+ {+ auto navigable = document.navigable();+ if (!navigable)+ return;+ m_viewport = document.layout_node(m_read);+ if (!m_viewport || !Painting::has_committed_box(*m_viewport)) {+ m_viewport = nullptr;+ return;+ }++ // NB: The scrolling area is in the coordinate space of the document, while client rects are relative to the+ // viewport, so client rects are offset by the viewport's scroll offset before they are compared with it.+ m_scrolling_area = Painting::scrollable_overflow_rect(*m_viewport);+ m_scroll_offset = navigable->viewport_scroll_offset();++ document.update_paint_and_hit_testing_properties_if_needed();+ m_rect_to_viewport_transform = Painting::rect_to_viewport_transform(document, document.visual_context_tree());+ }++ Layout::Viewport const* viewport() const { return m_scrolling_area.has_value() ? m_viewport : nullptr; }++ // https://w3c.github.io/paint-timing/#paintable+ bool is_paintable(Layout::Node const& node) const+ {+ if (!viewport())+ return false;++ // An element el is paintable when all of the following apply:+ // - el is being rendered.+ // NB: Only boxes are looked at.++ // - el's used visibility is visible.+ auto const* node_with_style = as_if<Layout::NodeWithStyle>(node);+ if (!node_with_style)+ node_with_style = as_if<Layout::NodeWithStyle>(node.parent_ptr());+ if (!node_with_style || node_with_style->visibility() != CSS::Visibility::Visible)+ return false;++ // - el and all of its ancestors' used opacity is greater than zero.+ // NB: The subtrees of boxes with an opacity of zero are not looked at.++ // - el's paintable bounding rect intersects with the scrolling area of the document.+ // https://w3c.github.io/paint-timing/#paintable-bounding-rect+ // 1. Let boundingRect be the result of running the getBoundingClientRect() on target.+ auto bounding_rect = client_rect_of_box(node, m_rect_to_viewport_transform).translated(m_scroll_offset);++ // 2. Clip boundingRect with the document's scrolling area.+ // 3. Return boundingRect.+ // NB: The clipped rect is not empty only if the rect intersects with the scrolling area.+ return bounding_rect.intersects(*m_scrolling_area);+ }++private:+ Layout::ForcedReadScope m_read;+ Layout::Viewport const* m_viewport { nullptr };+ Optional<CSSPixelRect> m_scrolling_area;+ CSSPixelPoint m_scroll_offset;+ Layout::RustFFI::FfiRectToViewportTransform m_rect_to_viewport_transform { Painting::identity_rect_to_viewport_transform() };+};++struct PaintedContent {+ bool has_non_default_content { false };+ bool has_contentful_content { false };+};++// NB: This finds whether the document has an element that is both paintable and contentful, and whether it paints+// anything other than the default background, from the boxes it has after layout. Only boxes are looked at, so+// elements that are not being rendered are skipped, and a box with an opacity of zero hides its whole subtree.+static PaintedContent find_painted_content(PaintableChecker const& checker, PaintedContent const& already_found)+{+ PaintedContent result = already_found;++ auto const* viewport = checker.viewport();+ if (!viewport)+ return result;++ viewport->for_each_in_inclusive_subtree([&](Layout::Node const& node) {+ if (auto const* node_with_style = as_if<Layout::NodeWithStyle>(node); node_with_style && node_with_style->opacity() <= 0)+ return TraversalDecision::SkipChildrenAndContinue;++ if (!result.has_non_default_content && paints_non_default_content(node) && checker.is_paintable(node))+ result.has_non_default_content = true;++ if (is_contentful(node) && checker.is_paintable(node)) {+ result.has_non_default_content = true;+ result.has_contentful_content = true;+ return TraversalDecision::Break;+ }++ // NB: The rendered descendants of an svg element make the svg element contentful, so they are not looked+ // at by themselves.+ if (node.kind() == Layout::RustFFI::NodeKind::SVGSVGBox)+ return TraversalDecision::SkipChildrenAndContinue;++ return TraversalDecision::Continue;+ });++ return result;+}++// https://w3c.github.io/paint-timing/#mark-paint-timing+void mark_paint_timing(DOM::Document& document)+{+ // 1. If the document's browsing context is not paint-timing eligible, return.+ // NB: We configure every nested browsing context to report paint timing, so every browsing context is eligible.+ if (!document.browsing_context())+ return;++ auto& reported_paints = document.paint_timing_state().set_of_previously_reported_paints;++ // OPTIMIZATION: Nothing below reports anything once first paint and first contentful paint have been reported.+ if (reported_paints.contains(first_paint_name()) && reported_paints.contains(first_contentful_paint_name()))+ return;++ // AD-HOC: Nothing is painted for a document whose initial paint is deferred until its fonts load.+ if (document.font_computer().should_defer_initial_paint())+ return;++ PaintableChecker checker { document };++ // 2. Let paintTimingInfo be a new paint timing info, whose rendering update end time is the current high+ // resolution time given document's relevant global object.+ PaintTimingInfo paint_timing_info {+ .rendering_update_end_time = HighResolutionTime::current_high_resolution_time(HTML::relevant_global_object(document)),+ .implementation_defined_presentation_time = {},+ };++ // FIXME: 3. Let paintedImages be a new ordered set+ // FIXME: 4. Let paintedTextNodes be a new ordered set+ // FIXME: 5. For each record in doc's images pending rendering list:+ // 1. If record's request is available and ready to be painted, then run the following steps:+ // 1. Append record to paintedImages.+ // 2. Remove record from doc's images pending rendering list.+ // FIXME: 6. For each Element element in doc's descendants:+ // 1. If element is contained in doc's set of elements with rendered text, continue.+ // 2. If element's set of owned text nodes is empty, continue.+ // 3. Append element to doc's set of elements with rendered text.+ // 4. Append element to paintedTextNodes.++ // 7. Let reportedPaints be the document's set of previously reported paints.+ // FIXME: 8. Let frameTimingInfo be document's current frame timing info.+ // FIXME: 9. Set document's current frame timing info to null.++ // 10. Let flushPaintTimings be the following steps:+ auto flush_paint_timings = [&] {+ // NB: The boxes are looked at once for both first paint and first contentful paint.+ PaintedContent already_found {+ .has_non_default_content = reported_paints.contains(first_paint_name()),+ .has_contentful_content = reported_paints.contains(first_contentful_paint_name()),+ };+ auto painted_content = find_painted_content(checker, already_found);++ // 1. If reportedPaints does not contain "first-paint", and the user agent is configured to mark first paint,+ // then report paint timing given document, "first-paint", and paintTimingInfo.+ // NOTE: First paint excludes the default background paint, but includes non-default background paint.+ if (!reported_paints.contains(first_paint_name()) && painted_content.has_non_default_content)+ report_paint_timing(document, first_paint_name(), paint_timing_info);++ // 2. If document should report first contentful paint, then:+ // https://w3c.github.io/paint-timing/#should-report-first-contentful-paint+ // 1. If document's set of previously reported paints contains "first-contentful-paint", then return false.+ // 2. If document contains at least one element that is both paintable and contentful, then return true.+ // 3. Otherwise, return false.+ if (!reported_paints.contains(first_contentful_paint_name()) && painted_content.has_contentful_content) {+ // 1. Report paint timing given document, "first-contentful-paint", and paintTimingInfo.+ report_paint_timing(document, first_contentful_paint_name(), paint_timing_info);+ }++ // FIXME: 3. Report largest contentful paint given document, paintTimingInfo, paintedImages and+ // paintedTextNodes.++ // FIXME: 4. Report element timing given document, paintTimingInfo, paintedImages and paintedTextNodes.+ // FIXME: 5. If frameTimingInfo is not null, then queue a long animation frame entry given document,+ // frameTimingInfo, and paintTimingInfo.+ };++ // 11. If the user-agent does not support implementation-defined presentation times, call flushPaintTimings and+ // return.+ // NB: The frame is presented by another process, which does not report back when it was presented.+ flush_paint_timings();+}++// https://w3c.github.io/paint-timing/#report-paint-timing+void report_paint_timing(DOM::Document& document, Utf16String const& paint_type, PaintTimingInfo const& paint_timing_info)+{+ // 1. Create a new PerformancePaintTiming object newEntry with document's relevant realm and set its attributes as+ // follows:+ // 1. Set newEntry's name attribute to paintType.+ // 2. Set newEntry's entryType attribute to "paint".+ // 3. Set newEntry's startTime attribute to the default paint timestamp given paintTimingInfo.+ // 4. Set newEntry's duration attribute to 0.+ // 2. Set newEntry's paint timing info to paintTimingInfo.+ auto new_entry = PerformancePaintTiming::create(paint_type, paint_timing_info);++ // 3. Queue newEntry in document's relevant realm.+ auto& window = HTML::relevant_window(document);+ window.queue_performance_entry(new_entry);+ window.add_performance_entry(new_entry);++ // 4. Append paintType to document's set of previously reported paints.+ document.paint_timing_state().set_of_previously_reported_paints.set(paint_type);+}++}diff --git a/Libraries/LibWeb/PaintTiming/PaintTiming.h b/Libraries/LibWeb/PaintTiming/PaintTiming.hnew file mode 100644index 00000000000..6db0f9deff6--- /dev/null+++ b/Libraries/LibWeb/PaintTiming/PaintTiming.h@@ -0,0 +1,21 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <AK/Utf16String.h>+#include <LibWeb/Forward.h>+#include <LibWeb/PaintTiming/PaintTimingMixin.h>++namespace Web::PaintTiming {++// https://w3c.github.io/paint-timing/#mark-paint-timing+void mark_paint_timing(DOM::Document&);++// https://w3c.github.io/paint-timing/#report-paint-timing+void report_paint_timing(DOM::Document&, Utf16String const& paint_type, PaintTimingInfo const&);++}diff --git a/Libraries/LibWeb/PaintTiming/PaintTimingMixin.h b/Libraries/LibWeb/PaintTiming/PaintTimingMixin.hnew file mode 100644index 00000000000..6f6251fd66a--- /dev/null+++ b/Libraries/LibWeb/PaintTiming/PaintTimingMixin.h@@ -0,0 +1,63 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <AK/Optional.h>+#include <LibWebCommon/HighResolutionTime/DOMHighResTimeStamp.h>++namespace Web::PaintTiming {++// https://w3c.github.io/paint-timing/#paint-timing-info+struct PaintTimingInfo {+ // https://w3c.github.io/paint-timing/#paint-timing-info-rendering-update-end-time+ HighResolutionTime::DOMHighResTimeStamp rendering_update_end_time { 0 };++ // https://w3c.github.io/paint-timing/#paint-timing-info-implementation-defined-presentation-time+ Optional<HighResolutionTime::DOMHighResTimeStamp> implementation_defined_presentation_time;+};++// https://w3c.github.io/paint-timing/#default-paint-timestamp+inline HighResolutionTime::DOMHighResTimeStamp default_paint_timestamp(PaintTimingInfo const& paint_timing_info)+{+ // To get the default paint timestamp for a paint timing info paintTimingInfo, return paintTimingInfo's+ // implementation-defined presentation time if it is non-null, otherwise paintTimingInfo's rendering update end time.+ return paint_timing_info.implementation_defined_presentation_time.value_or(paint_timing_info.rendering_update_end_time);+}++// https://w3c.github.io/paint-timing/#sec-PaintTimingMixin+class PaintTimingMixin {+public:+ // https://w3c.github.io/paint-timing/#dom-painttimingmixin-painttime+ HighResolutionTime::DOMHighResTimeStamp paint_time() const+ {+ // The paintTime attribute's getter step is to return this's paint timing info's rendering update end time.+ return m_paint_timing_info.rendering_update_end_time;+ }++ // https://w3c.github.io/paint-timing/#dom-painttimingmixin-presentationtime+ Optional<HighResolutionTime::DOMHighResTimeStamp> presentation_time() const+ {+ // The presentationTime attribute's getter step, if exists, is to return this's paint timing info's+ // implementation-defined presentation time.+ return m_paint_timing_info.implementation_defined_presentation_time;+ }++ PaintTimingInfo const& paint_timing_info() const { return m_paint_timing_info; }++protected:+ explicit PaintTimingMixin(PaintTimingInfo paint_timing_info)+ : m_paint_timing_info(paint_timing_info)+ {+ }++private:+ // https://w3c.github.io/paint-timing/#painttimingmixin-paint-timing-info+ // NB: Every object that includes this mixin is created with a paint timing info, so it is never null here.+ PaintTimingInfo m_paint_timing_info;+};++}diff --git a/Libraries/LibWeb/PaintTiming/PaintTimingMixin.idl b/Libraries/LibWeb/PaintTiming/PaintTimingMixin.idlnew file mode 100644index 00000000000..0eb854bbb07--- /dev/null+++ b/Libraries/LibWeb/PaintTiming/PaintTimingMixin.idl@@ -0,0 +1,6 @@+// https://w3c.github.io/paint-timing/#sec-PaintTimingMixin+[Exposed=Window]+interface mixin PaintTimingMixin {+ readonly attribute DOMHighResTimeStamp paintTime;+ readonly attribute DOMHighResTimeStamp? presentationTime;+};diff --git a/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.cpp b/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.cppnew file mode 100644index 00000000000..d1771e23c9e--- /dev/null+++ b/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.cpp@@ -0,0 +1,40 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <LibGC/Heap.h>+#include <LibWeb/PaintTiming/PerformancePaintTiming.h>+#include <LibWeb/PerformanceTimeline/EntryTypes.h>++namespace Web::PaintTiming {++GC_DEFINE_ALLOCATOR(PerformancePaintTiming);++// https://w3c.github.io/paint-timing/#report-paint-timing+PerformancePaintTiming::PerformancePaintTiming(Utf16String const& paint_type, PaintTimingInfo paint_timing_info)+ // 1. Set newEntry's name attribute to paintType.+ // 3. Set newEntry's startTime attribute to the default paint timestamp given paintTimingInfo.+ // 4. Set newEntry's duration attribute to 0.+ : PerformanceTimeline::PerformanceEntry(paint_type, default_paint_timestamp(paint_timing_info), 0)+ // 2. Set newEntry's paint timing info to paintTimingInfo.+ , PaintTimingMixin(paint_timing_info)+{+}++PerformancePaintTiming::~PerformancePaintTiming() = default;++GC::Ref<PerformancePaintTiming> PerformancePaintTiming::create(Utf16String const& paint_type, PaintTimingInfo paint_timing_info)+{+ return GC::Heap::the().allocate<PerformancePaintTiming>(paint_type, paint_timing_info);+}++// https://w3c.github.io/paint-timing/#sec-PerformancePaintTiming+Utf16FlyString const& PerformancePaintTiming::entry_type() const+{+ // The entryType attribute's getter must return "paint".+ return PerformanceTimeline::EntryTypes::paint;+}++}diff --git a/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.h b/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.hnew file mode 100644index 00000000000..2dc84b4e730--- /dev/null+++ b/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.h@@ -0,0 +1,44 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <LibWeb/PaintTiming/PaintTimingMixin.h>+#include <LibWeb/PerformanceTimeline/PerformanceEntry.h>++namespace Web::PaintTiming {++// https://w3c.github.io/paint-timing/#sec-PerformancePaintTiming+class PerformancePaintTiming final+ : public PerformanceTimeline::PerformanceEntry+ , public PaintTimingMixin {+ WEB_WRAPPABLE(PerformancePaintTiming, PerformanceTimeline::PerformanceEntry);+ GC_DECLARE_ALLOCATOR(PerformancePaintTiming);++public:+ virtual ~PerformancePaintTiming() override;++ static GC::Ref<PerformancePaintTiming> create(Utf16String const& paint_type, PaintTimingInfo);++ // NOTE: These three functions are answered by the registry for the given entry type.+ // https://w3c.github.io/timing-entrytypes-registry/#registry++ // https://w3c.github.io/timing-entrytypes-registry/#dfn-availablefromtimeline+ static PerformanceTimeline::AvailableFromTimeline available_from_timeline() { return PerformanceTimeline::AvailableFromTimeline::Yes; }++ // https://w3c.github.io/timing-entrytypes-registry/#dfn-maxbuffersize+ static Optional<u64> max_buffer_size() { return 2; }++ // https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry+ virtual PerformanceTimeline::ShouldAddEntry should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&> = {}) const override { return PerformanceTimeline::ShouldAddEntry::Yes; }++ virtual Utf16FlyString const& entry_type() const override;++private:+ PerformancePaintTiming(Utf16String const& paint_type, PaintTimingInfo);+};++}diff --git a/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.idl b/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.idlnew file mode 100644index 00000000000..a7fd236515e--- /dev/null+++ b/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.idl@@ -0,0 +1,6 @@+// https://w3c.github.io/paint-timing/#sec-PerformancePaintTiming+[Exposed=Window]+interface PerformancePaintTiming : PerformanceEntry {+ [Default] object toJSON();+};+PerformancePaintTiming includes PaintTimingMixin;diff --git a/Libraries/LibWeb/PerformanceTimeline/PerformanceObserver.cpp b/Libraries/LibWeb/PerformanceTimeline/PerformanceObserver.cppindex ac574ac4c09..7177e9c0204 100644--- a/Libraries/LibWeb/PerformanceTimeline/PerformanceObserver.cpp+++ b/Libraries/LibWeb/PerformanceTimeline/PerformanceObserver.cpp@@ -46,21 +46,12 @@ static GC::Ref<JS::Object> create_supported_entry_types_array(JS::Object& relevaauto& vm = realm.vm();GC::RootVector<JS::Value> supported_entry_types;-#define __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(entry_type, cpp_class) \- supported_entry_types.append(JS::PrimitiveString::create(vm, entry_type));- ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES_BEFORE_NAVIGATION-#undef __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES+ bool global_is_window = HTML::window_from_global_object(relevant_global_object);- if (HTML::window_from_global_object(relevant_global_object)) {-#define __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(entry_type, cpp_class) \- supported_entry_types.append(JS::PrimitiveString::create(vm, entry_type));- ENUMERATE_WINDOW_SUPPORTED_PERFORMANCE_ENTRY_TYPES-#undef __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES- }--#define __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(entry_type, cpp_class) \- supported_entry_types.append(JS::PrimitiveString::create(vm, entry_type));- ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES_AFTER_NAVIGATION+#define __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(entry_type, cpp_class, globals) \+ if (HighResolutionTime::is_supported_for_global(HighResolutionTime::SupportedPerformanceEntryTypeGlobals::globals, global_is_window)) \+ supported_entry_types.append(JS::PrimitiveString::create(vm, entry_type));+ ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES#undef __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPESauto supported_entry_types_array = JS::Array::create_from(realm, supported_entry_types);@@ -68,6 +59,19 @@ static GC::Ref<JS::Object> create_supported_entry_types_array(JS::Object& relevareturn supported_entry_types_array;}+static bool is_supported_entry_type(HTML::WindowOrWorkerGlobalScopeMixin const& relevant_global, Utf16FlyString const& type)+{+ bool global_is_window = is<HTML::Window>(relevant_global.this_impl());++#define __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(entry_type, cpp_class, globals) \+ if (type == entry_type) \+ return HighResolutionTime::is_supported_for_global(HighResolutionTime::SupportedPerformanceEntryTypeGlobals::globals, global_is_window);+ ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES+#undef __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES++ return false;+}+GC::Ref<PerformanceObserver> PerformanceObserver::create(GC::Ptr<WebIDL::CallbackType> callback, HTML::WindowOrWorkerGlobalScopeMixin& relevant_global){return GC::Heap::the().allocate<PerformanceObserver>(callback, relevant_global);@@ -149,19 +153,8 @@ WebIDL::ExceptionOr<void> PerformanceObserver::observe(PerformanceObserverInit o// The user agent SHOULD notify developers if entry types is modified. For example, a console warning listing removed// types might be appropriate.entry_types.remove_all_matching([&relevant_global](Utf16FlyString const& type) {-#define __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(entry_type, cpp_class) \- if (type == entry_type) \- return false;- ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES-#undef __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES-- if (is<HTML::Window>(relevant_global.this_impl())) {-#define __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(entry_type, cpp_class) \- if (type == entry_type) \- return false;- ENUMERATE_WINDOW_SUPPORTED_PERFORMANCE_ENTRY_TYPES-#undef __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES- }+ if (is_supported_entry_type(relevant_global, type))+ return false;dbgln("Potential FIXME: Removing unsupported PerformanceEntry type '{}' from list of observed types in PerformanceObserver::observe()", type);return true;@@ -195,21 +188,7 @@ WebIDL::ExceptionOr<void> PerformanceObserver::observe(PerformanceObserverInit o// The user agent SHOULD notify developers when this happens, for instance via a console warning.VERIFY(observer_options.type.has_value());auto& type = observer_options.type.value();- bool recognized_type = false;--#define __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(entry_type, cpp_class) \- if (!recognized_type && type == entry_type) \- recognized_type = true;- ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES-#undef __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES-- if (is<HTML::Window>(relevant_global.this_impl())) {-#define __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES(entry_type, cpp_class) \- if (!recognized_type && type == entry_type) \- recognized_type = true;- ENUMERATE_WINDOW_SUPPORTED_PERFORMANCE_ENTRY_TYPES-#undef __ENUMERATE_SUPPORTED_PERFORMANCE_ENTRY_TYPES- }+ bool recognized_type = is_supported_entry_type(relevant_global, type);if (!recognized_type) {dbgln("Potential FIXME: Returning from PerformanceObserver::observe() as we don't support the PerformanceEntry type '{}'", type);diff --git a/Libraries/LibWeb/idl_files.cmake b/Libraries/LibWeb/idl_files.cmakeindex f1e2ddadc7c..521ca1559d7 100644--- a/Libraries/LibWeb/idl_files.cmake+++ b/Libraries/LibWeb/idl_files.cmake@@ -431,6 +431,8 @@ libweb_js_bindings(NavigationTiming/PerformanceNavigation)libweb_js_bindings(NavigationTiming/PerformanceNavigationTiming)libweb_js_bindings(NavigationTiming/PerformanceTiming)libweb_js_bindings(NotificationsAPI/Notification)+libweb_js_bindings(PaintTiming/PaintTimingMixin)+libweb_js_bindings(PaintTiming/PerformancePaintTiming)libweb_js_bindings(PerformanceTimeline/PerformanceEntry)libweb_js_bindings(PerformanceTimeline/PerformanceObserver)libweb_js_bindings(PerformanceTimeline/PerformanceObserverEntryList)diff --git a/Tests/LibWeb/Text/expected/PerformanceObserver/PerformanceObserver-supportedEntryTypes.txt b/Tests/LibWeb/Text/expected/PerformanceObserver/PerformanceObserver-supportedEntryTypes.txtindex 742b6ac4624..2e076adc411 100644--- a/Tests/LibWeb/Text/expected/PerformanceObserver/PerformanceObserver-supportedEntryTypes.txt+++ b/Tests/LibWeb/Text/expected/PerformanceObserver/PerformanceObserver-supportedEntryTypes.txt@@ -1,4 +1,4 @@-PerformanceObserver.supportedEntryTypes: mark,measure,navigation,resource+PerformanceObserver.supportedEntryTypes: mark,measure,navigation,paint,resourcePerformanceObserver.supportedEntryTypes instanceof Array: trueObject.isFrozen(PerformanceObserver.supportedEntryTypes): truePerformanceObserver.supportedEntryTypes === PerformanceObserver.supportedEntryTypes: truediff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txtindex 57124ba7c41..49e8936f760 100644--- a/Tests/LibWeb/Text/expected/all-window-properties.txt+++ b/Tests/LibWeb/Text/expected/all-window-properties.txt@@ -367,6 +367,7 @@ PerformanceNavigationPerformanceNavigationTimingPerformanceObserverPerformanceObserverEntryList+PerformancePaintTimingPerformanceResourceTimingPerformanceServerTimingPerformanceTimingdiff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/buffered-flag.window.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/buffered-flag.window.txtnew file mode 100644index 00000000000..3755e29e8b1--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/buffered-flag.window.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass PerformanceObserver with buffered flag sees previous FCP entry.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-after-scroll.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-after-scroll.txtnew file mode 100644index 00000000000..1a7badc6efd--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-after-scroll.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint is reported even though a scroll event was dispatched before it.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-background-size.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-background-size.txtnew file mode 100644index 00000000000..6b0b2f5d8aa--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-background-size.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint fires due to background size.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-bg-image-set.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-bg-image-set.txtnew file mode 100644index 00000000000..bb66d782631--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-bg-image-set.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint fires due to background image in image-set.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-bg-image-two-steps.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-bg-image-two-steps.txtnew file mode 100644index 00000000000..e8e5fd3ac31--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-bg-image-two-steps.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint fires for background image only when visible.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-canvas-context.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-canvas-context.txtnew file mode 100644index 00000000000..52e24ba4d78--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-canvas-context.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Canvas should count as contentful when context is created\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-gradient.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-gradient.txtnew file mode 100644index 00000000000..1710a84b68d--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-gradient.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Gradients should not count as contentful\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-ignore-from-subframe.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-ignore-from-subframe.txtnew file mode 100644index 00000000000..7f135a601e5--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-ignore-from-subframe.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Parent frame should not fire own paint-timing events for subframes.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-invisible-text.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-invisible-text.txtnew file mode 100644index 00000000000..c1d00626f0b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-invisible-text.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint fires due to pseudo-element becoming visible.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-opacity-descendant.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-opacity-descendant.txtnew file mode 100644index 00000000000..2306d6e2dff--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-opacity-descendant.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint fires due to its ancestor getting positive opacity.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-opacity.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-opacity.txtnew file mode 100644index 00000000000..901dd0fc93b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-opacity.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint fires due to opacity-revealed element.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-out-of-bounds-translate.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-out-of-bounds-translate.txtnew file mode 100644index 00000000000..53cd5a5ba52--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-out-of-bounds-translate.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint fires due to transform-based intersection with document.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-out-of-bounds.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-out-of-bounds.txtnew file mode 100644index 00000000000..d081a255ffe--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-out-of-bounds.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint fires due to intersection with document.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-display.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-display.txtnew file mode 100644index 00000000000..bcf6e4dfd21--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-display.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint fires due to pseudo-element text.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-image.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-image.txtnew file mode 100644index 00000000000..d5c4256dfe4--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-image.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint fires due to pseudo-element image.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-opacity.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-opacity.txtnew file mode 100644index 00000000000..67419a3cf7a--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-opacity.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint fires due to pseudo-element getting positive opacity.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-text.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-text.txtnew file mode 100644index 00000000000..bcf6e4dfd21--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-text.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint fires due to pseudo-element text.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-visibility.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-visibility.txtnew file mode 100644index 00000000000..c1d00626f0b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-visibility.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint fires due to pseudo-element becoming visible.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-svg.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-svg.txtnew file mode 100644index 00000000000..32ca40f99ac--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-svg.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint fires when SVG becomes contentful.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-text-input.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-text-input.txtnew file mode 100644index 00000000000..65d80147b92--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-text-input.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Text input should become contentful when its value is non-empty\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-typographic-pseudo.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-typographic-pseudo.txtnew file mode 100644index 00000000000..a746bb0ffd9--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-typographic-pseudo.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail First contentful paint fires only when some of the text is visible, considering ::first-letter.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-video-poster.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-video-poster.txtnew file mode 100644index 00000000000..5f6cd439261--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-video-poster.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Video should become contentful when poster is loaded\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-whitespace.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-whitespace.txtnew file mode 100644index 00000000000..364ec15fef6--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-whitespace.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Whitespace should not count as contentful.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-with-rtl.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-with-rtl.txtnew file mode 100644index 00000000000..19b3c7d0d43--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/fcp-with-rtl.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass FCP should fire when coordinates are negative, if within document scrollable area\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/first-contentful-canvas-none.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/first-contentful-canvas-none.txtnew file mode 100644index 00000000000..2a239df8b65--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/first-contentful-canvas-none.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First contentful paint should not fire for canvas type none\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/input-text.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/input-text.txtnew file mode 100644index 00000000000..c02d3f59099--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/input-text.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Text from a form control triggers First Contentful Paint.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/replaced-content-image.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/replaced-content-image.txtnew file mode 100644index 00000000000..006bebd1583--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/replaced-content-image.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Replaced content image triggers First Contentful Paint.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/svg-in-iframe.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/svg-in-iframe.txtnew file mode 100644index 00000000000..dcf42159b2c--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/fcp-only/svg-in-iframe.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass SVG in an iframe does not trigger FCP in the main frame\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/first-paint-only/iframe-in-invisible-ancestor.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/first-paint-only/iframe-in-invisible-ancestor.txtnew file mode 100644index 00000000000..b352fee8327--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/first-paint-only/iframe-in-invisible-ancestor.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass First paint is not reported for an iframe inside an invisible ancestor.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/supported-paint-type.window.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/supported-paint-type.window.txtnew file mode 100644index 00000000000..d27486e1c60--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/supported-paint-type.window.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass supportedEntryTypes contains 'paint'.+Pass 'paint' entries should be observable.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/with-paint-timing-mixin/paint-timing-mixin-to-json.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/with-paint-timing-mixin/paint-timing-mixin-to-json.txtnew file mode 100644index 00000000000..73eb0e6be32--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/with-paint-timing-mixin/paint-timing-mixin-to-json.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Paint timing entries should serialize paintTime and presentationTime with toJSON\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/paint-timing/with-paint-timing-mixin/paint-timing-mixin.txt b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/with-paint-timing-mixin/paint-timing-mixin.txtnew file mode 100644index 00000000000..9311eb192b5--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/paint-timing/with-paint-timing-mixin/paint-timing-mixin.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Paint timing entries should expose paintTime and presentationTime\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/buffered-flag.window.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/buffered-flag.window.htmlnew file mode 100644index 00000000000..9f5d5390fcc--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/buffered-flag.window.html@@ -0,0 +1,8 @@+<!doctype html>+<meta charset=utf-8>++<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>++<div id=log></div>+<script src="../../paint-timing/fcp-only/buffered-flag.window.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/buffered-flag.window.js b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/buffered-flag.window.jsnew file mode 100644index 00000000000..5910b6881fb--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/buffered-flag.window.js@@ -0,0 +1,24 @@+setup({"hide_test_state": true});+async_test(t => {+ assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");+ // First observer creates a second one in the callback to ensure the entry has been dispatched+ // by the time the second observer begins observing.+ new PerformanceObserver(entries => {+ const entry_seen = entries.getEntriesByName('first-contentful-paint').length > 0;+ // Abort if we have not yet received the entry.+ if (!entry_seen)+ return;++ // Second observer requires 'buffered: true' to see the entry.+ new PerformanceObserver(t.step_func_done(list => {+ const fcp = list.getEntriesByName('first-contentful-paint');+ assert_equals(fcp.length, 1, 'Should have an fcp entry');+ const entry = fcp[0];+ assert_equals(entry.entryType, 'paint');+ })).observe({'type': 'paint', buffered: true});+ }).observe({'entryTypes': ['paint']});+ // Trigger the first contentful paint entry.+ const img = document.createElement("img");+ img.src = "../resources/circles.png";+ document.body.appendChild(img);+}, "PerformanceObserver with buffered flag sees previous FCP entry.");diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-after-scroll.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-after-scroll.htmlnew file mode 100644index 00000000000..0fbe5b0e286--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-after-scroll.html@@ -0,0 +1,56 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP is reported after a scroll event</title>+<style>+ #scroller {+ width: 100px;+ height: 50px;+ overflow: scroll;+ scrollbar-width: none;+ }++ #scroller > div {+ height: 500px;+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="scroller"><div></div></div>+<div id="main"></div>+<script>+ setup({"hide_test_state": true});++ // Bounded wait, so that a missing entry fails the assert below instead of+ // timing out the whole file.+ async function waitForFirstContentfulPaint(maxFrames) {+ for (let i = 0; i < maxFrames; ++i) {+ if (performance.getEntriesByName('first-contentful-paint').length) {+ return true;+ }+ await waitForAnimationFrames(1);+ }+ return performance.getEntriesByName('first-contentful-paint').length > 0;+ }++ promise_test(async t => {+ assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");+ await new Promise(r => window.addEventListener('load', r));+ await assertNoFirstContentfulPaint(t);++ const scroller = document.getElementById('scroller');+ const scrolled = new Promise(resolve =>+ scroller.addEventListener('scroll', resolve, {once: true}));+ scroller.scrollTop = 100;+ await scrolled;+ await assertNoFirstContentfulPaint(t);++ document.getElementById('main').textContent = 'Contentful text';+ assert_true(await waitForFirstContentfulPaint(30),+ 'first-contentful-paint should be reported after a scroll event');+ }, 'First contentful paint is reported even though a scroll event was dispatched before it.');+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-background-size.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-background-size.htmlnew file mode 100644index 00000000000..deffbd98033--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-background-size.html@@ -0,0 +1,38 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP due to background size</title>+<style>+ #main {+ position: relative;+ width: 100px;+ height: 100px;+ background-image: url(../resources/circles.png);+ background-size: 0 0;+ }++ /* contentful class is defined in test_fcp script. */+ #main.contentful {+ background-size: 100% 100%;+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main"></div>+<script>+ // Load the image into memory first to make sure it's decoded.+ function load_image() {+ const img = document.createElement("img");+ img.src = "../resources/circles.png";++ return new Promise(resolve => {+ img.onload = async () => resolve();+ });+ }++ test_fcp("First contentful paint fires due to background size.", load_image);+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-bg-image-set.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-bg-image-set.htmlnew file mode 100644index 00000000000..02c4cac3bdb--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-bg-image-set.html@@ -0,0 +1,36 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP due to background image in image-set</title>+<style>+ #main {+ width: 100px;+ height: 100px;+ }++ /* contentful class is defined in test_fcp script. */+ #main.contentful {+ background-image: -webkit-image-set(url(../resources/circles.png) 1x);+ background-image: image-set(url(../resources/circles.png) 1x);+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main"></div>+<script>+ // Load the image into memory first to make sure it's decoded.+ function load_image() {+ const img = document.createElement("img");+ img.src = "../resources/circles.png";++ return new Promise(resolve => {+ img.onload = async () => resolve();+ });+ }++ test_fcp("First contentful paint fires due to background image in image-set.", load_image);+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-bg-image-two-steps.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-bg-image-two-steps.htmlnew file mode 100644index 00000000000..d55c100d568--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-bg-image-two-steps.html@@ -0,0 +1,44 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP should fire for background image only when visible</title>+<style>+ #main {+ width: 100px;+ height: 100px;+ }++ /* contentful and preFCP classes are defined in test_fcp script. */+ #main.preFCP {+ visibility: hidden;+ }++ #main.contentful, #main.preFCP {+ background-image: url(../resources/circles.png);+ }++ #main.contentful {+ visibility: visible;+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main"></div>+<script>+ // Load the image into memory first to make sure it's decoded.+ function load_image() {+ const img = document.createElement("img");+ img.src = "../resources/circles.png";++ return new Promise(resolve => {+ img.onload = async () => resolve();+ });+ }++ test_fcp("First contentful paint fires for background image only when visible.", load_image);+</script>+</body>++</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-canvas-context.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-canvas-context.htmlnew file mode 100644index 00000000000..d8e31a4adab--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-canvas-context.html@@ -0,0 +1,24 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP when canvas context is created</title>+</head>+<body>+<script src="../resources/utils.js"></script>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<canvas id="canvas" width="50" height="50"></canvas>+<script>+ setup({"hide_test_state": true});+ promise_test(async t => {+ assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");+ await new Promise(r => window.addEventListener('load', r));+ await assertNoFirstContentfulPaint(t);+ const canvas = document.getElementById('canvas');+ const context = canvas.getContext('2d');+ context.fillRect(0, 0, 100, 100);+ await assertFirstContentfulPaint(t);+ }, 'Canvas should count as contentful when context is created');+</script>+</body>++</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-gradient.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-gradient.htmlnew file mode 100644index 00000000000..9d66a9c8149--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-gradient.html@@ -0,0 +1,27 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP should not fire with gradient-only backgrounds</title>+<style>+ #main {+ width: 100px;+ height: 100px;+ background-image: linear-gradient(to bottom, orange, blue);+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main"></div>+<script>+ setup({"hide_test_state": true});+ promise_test(async t => {+ assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");+ await new Promise(r => window.addEventListener('load', r));+ await assertNoFirstContentfulPaint(t);+ }, 'Gradients should not count as contentful');+</script>+</body>++</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-ignore-from-subframe.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-ignore-from-subframe.htmlnew file mode 100644index 00000000000..e294647ef6d--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-ignore-from-subframe.html@@ -0,0 +1,27 @@+<!DOCTYPE html>+<head>+ <title>+ Performance Paint Timing Test: Paints in the iframe should be reported in the iframe+ and not in the top document+ </title>+</head>+<body>+<script src="../resources/utils.js"></script>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script>+setup({"hide_test_state": true});+promise_test(async t => {+ assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");+ const iframe = document.createElement('iframe');+ iframe.src = '../resources/subframe-painting.html';+ document.body.appendChild(iframe);+ await new Promise(resolve => window.addEventListener('message', e => {+ if (e.data.entryType == "paint" && e.data.name == "first-contentful-paint")+ resolve()+ }));+ await assertNoFirstContentfulPaint(t);+}, 'Parent frame should not fire own paint-timing events for subframes.');+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-invisible-text.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-invisible-text.htmlnew file mode 100644index 00000000000..7d6e524a76d--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-invisible-text.html@@ -0,0 +1,30 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP should still fire for invisible text</title>+<style>+ #main {+ position: relative;+ width: 100px;+ height: 100px;+ visibility: hidden;+ color: rgba(0, 0, 0, 0);+ }++ /* contentful class is defined in test_fcp script. */+ #main.contentful {+ visibility: visible;+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main">+ INVISIBLE+</div>+<script>+ test_fcp("First contentful paint fires due to pseudo-element becoming visible.")+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-opacity-descendant.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-opacity-descendant.htmlnew file mode 100644index 00000000000..d9511de66af--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-opacity-descendant.html@@ -0,0 +1,34 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP due to ancestor opacity</title>+<style>+ #main {+ width: 100px;+ height: 100px;+ left: 0px;+ position: relative;+ top: 0;+ opacity: 0;+ }++ #child {+ opacity: 1;+ }++ #main.contentful {+ opacity: 0.5;+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main">+ <div id="child">Text</div>+</div>+<script>+ test_fcp("First contentful paint fires due to its ancestor getting positive opacity.");+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-opacity.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-opacity.htmlnew file mode 100644index 00000000000..d48c5b44fd3--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-opacity.html@@ -0,0 +1,30 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP due to opacity</title>+<style>+ #main {+ width: 100px;+ height: 100px;+ left: 0px;+ position: relative;+ top: 0;+ background-image: url(../resources/circles.png);+ opacity: 0;+ }++ /* contentful class is defined in test_fcp script. */+ #main.contentful {+ opacity: 0.1;+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main"></div>+<script>+ test_fcp("First contentful paint fires due to opacity-revealed element.");+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-out-of-bounds-translate.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-out-of-bounds-translate.htmlnew file mode 100644index 00000000000..bc6c88b6fec--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-out-of-bounds-translate.html@@ -0,0 +1,30 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP due to transform-based intersection with document</title>+<style>+ #main {+ width: 100px;+ height: 100px;+ left: 0px;+ transform: translate(-1000px);+ position: relative;+ top: 0;+ background-image: url(../resources/circles.png);+ }++ /* contentful class is defined in test_fcp script. */+ #main.contentful {+ transform: none;+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main"></div>+<script>+ test_fcp("First contentful paint fires due to transform-based intersection with document.")+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-out-of-bounds.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-out-of-bounds.htmlnew file mode 100644index 00000000000..4ae7a29f0e3--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-out-of-bounds.html@@ -0,0 +1,39 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP due to intersection with document</title>+<style>+ #main {+ width: 100px;+ height: 100px;+ left: -1000px;+ position: relative;+ top: 0;+ background-image: url(../resources/circles.png);+ }++ /* contentful class is defined in test_fcp script. */+ #main.contentful {+ left: 0px;+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main"></div>+<script>+ // Load the image into memory first to make sure it's decoded.+ function load_image() {+ const img = document.createElement("img");+ img.src = "../resources/circles.png";++ return new Promise(resolve => {+ img.onload = async () => resolve();+ });+ }++ test_fcp("First contentful paint fires due to intersection with document.", load_image)+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-display.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-display.htmlnew file mode 100644index 00000000000..603dbc02269--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-display.html@@ -0,0 +1,32 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP due to pseudo-element text</title>+<style>+ #main {+ position: relative;+ width: 100px;+ height: 100px;+ }++ #main:after {+ content: "TEXT";+ display: none;+ }++ /* contentful class is defined in test_fcp script. */+ #main.contentful:after {+ display: block;+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main">+</div>+<script>+ test_fcp("First contentful paint fires due to pseudo-element text.")+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-image.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-image.htmlnew file mode 100644index 00000000000..94ed2cdb743--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-image.html@@ -0,0 +1,38 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP due to pseudo-element image</title>+<style>+ #main {+ position: relative;+ width: 100px;+ height: 100px;+ }++ /* contentful class is defined in test_fcp script. */+ #main.contentful:after {+ content: url(../resources/circles.png);+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main">+</div>+<script>+ // Load the image into memory first to make sure it's decoded.+ function load_image() {+ const img = document.createElement("img");+ img.src = "../resources/circles.png";++ return new Promise(resolve => {+ img.onload = async () => resolve();+ });+ }++ test_fcp("First contentful paint fires due to pseudo-element image.", load_image)+</script>+</body>++</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-opacity.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-opacity.htmlnew file mode 100644index 00000000000..d8395c75c13--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-opacity.html@@ -0,0 +1,32 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP due to pseudo-element getting positive opacity</title>+<style>+ #main {+ position: relative;+ width: 100px;+ height: 100px;+ }++ #main:after {+ content: "TEXT";+ opacity: 0;+ }++ /* contentful class is defined in test_fcp script. */+ #main.contentful:after {+ opacity: 0.5;+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main">+</div>+<script>+ test_fcp("First contentful paint fires due to pseudo-element getting positive opacity.")+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-text.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-text.htmlnew file mode 100644index 00000000000..1df1fd164c1--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-text.html@@ -0,0 +1,28 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP due to pseudo-element text</title>+<style>+ #main {+ position: relative;+ width: 100px;+ height: 100px;+ }++ /* contentful class is defined in test_fcp script. */+ #main.contentful:after {+ content: "TEXT"+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main">+</div>+<script>+ test_fcp("First contentful paint fires due to pseudo-element text.")+</script>+</body>++</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-visibility.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-visibility.htmlnew file mode 100644index 00000000000..f3b665c6ab9--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-pseudo-element-visibility.html@@ -0,0 +1,32 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP due to pseudo-element becoming visible</title>+<style>+ #main {+ position: relative;+ width: 100px;+ height: 100px;+ }++ #main:after {+ content: "TEXT";+ visibility: hidden;+ }++ /* contentful class is defined in test_fcp script. */+ #main.contentful:after {+ visibility: visible;+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main">+</div>+<script>+ test_fcp("First contentful paint fires due to pseudo-element becoming visible.")+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-svg.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-svg.htmlnew file mode 100644index 00000000000..b45691c37c9--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-svg.html@@ -0,0 +1,40 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP with SVG</title>+<style>+ #main {+ width: 100px;+ height: 100px;+ left: 0px;+ position: relative;+ }++ #circle {+ display: none;+ }++ /* contentful class is defined in test_fcp script. */+ #main.contentful #circle {+ display: block;+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main">+ <svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg"+ xmlns:xlink="http://www.w3.org/1999/xlink">+ <defs>+ <circle id="myCircle" cx="5" cy="5" r="4" stroke="blue"/>+ </defs>+ <use id="circle" href="#myCircle" fill="green" />+ </svg>+</div>+<script>+ test_fcp("First contentful paint fires when SVG becomes contentful.")+</script>+</body>++</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-text-input.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-text-input.htmlnew file mode 100644index 00000000000..1cc4637d37e--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-text-input.html@@ -0,0 +1,24 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP due for non-empty text input</title>+</head>+<body>+<script src="../resources/utils.js"></script>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<input id="input" type="text" />+<script>+ setup({"hide_test_state": true});+ promise_test(async t => {+ assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");+ await new Promise(r => window.addEventListener('load', r));+ await assertNoFirstContentfulPaint(t);+ const input = document.getElementById('input');+ input.setAttribute('value', ' ');+ await assertNoFirstContentfulPaint(t);+ input.setAttribute('value', 'value');+ await assertFirstContentfulPaint(t);+ }, 'Text input should become contentful when its value is non-empty');+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-typographic-pseudo.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-typographic-pseudo.htmlnew file mode 100644index 00000000000..85d235be8a8--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-typographic-pseudo.html@@ -0,0 +1,32 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP should not fire when all text is hidden due to typographic pseudo-elements</title>+<style>+ #main {+ position: relative;+ width: 100px;+ height: 100px;+ }++ #main *::first-letter {+ opacity: 0;+ }++ /* contentful class is defined in test_fcp script. */+ #main.contentful *::first-letter {+ opacity: 1;+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main">+ <div>A</div>+</div>+<script>+ test_fcp("First contentful paint fires only when some of the text is visible, considering ::first-letter.")+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-video-poster.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-video-poster.htmlnew file mode 100644index 00000000000..0649bedcb86--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-video-poster.html@@ -0,0 +1,28 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP due to loaded video poster</title>+</head>+<body>+<script src="../resources/utils.js"></script>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<video id="video" width="50" height="50"></video>+<script>+ setup({"hide_test_state": true});+ promise_test(async t => {+ assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");+ await new Promise(r => window.addEventListener('load', r));+ await assertNoFirstContentfulPaint(t);+ const video = document.getElementById('video');+ const src = '../resources/circles.png';+ const image = new Image();+ image.src = src;+ video.setAttribute('poster', src);+ await new Promise(resolve => {+ image.onload = async () => resolve();+ })+ await assertFirstContentfulPaint(t);+ }, 'Video should become contentful when poster is loaded');+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-whitespace.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-whitespace.htmlnew file mode 100644index 00000000000..70f25c3288e--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-whitespace.html@@ -0,0 +1,27 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: Whitespace should not count as contentful</title>+<style>+ #text {+ display: none;+ }++ /* contentful class is defined in test_fcp script. */+ #main.contentful #text{+ display: block;+ }+</style>+</head>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<div id="main">+ <div id="whitespace"> </div>+ <div id="text">TEXT</div>+</div>+<script>+ test_fcp("Whitespace should not count as contentful.")+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-with-rtl.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-with-rtl.htmlnew file mode 100644index 00000000000..e6072bd4158--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/fcp-with-rtl.html@@ -0,0 +1,31 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing Test: FCP due to direction change</title>+<style>+ #text {+ right: -100px;+ position: absolute;+ }++ body {+ direction: rtl;+ }+</style>+</head>+<body>+<script src="../resources/utils.js"></script>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<div id="text">TEXT</div>+<script>+ setup({"hide_test_state": true});+ promise_test(async t => {+ assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");+ await new Promise(r => window.addEventListener('load', r));+ await assertNoFirstContentfulPaint(t);+ document.body.style.direction = 'ltr'+ await assertFirstContentfulPaint(t);+ }, 'FCP should fire when coordinates are negative, if within document scrollable area');+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/first-contentful-canvas-none.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/first-contentful-canvas-none.htmlnew file mode 100644index 00000000000..142eca5c6e7--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/first-contentful-canvas-none.html@@ -0,0 +1,23 @@+<!DOCTYPE html>++<head>+ <title>Performance Paint Timing Test: FCP due to canvas</title>+</head>++<body>+ <script src="../../resources/testharness.js"></script>+ <script src="../../resources/testharnessreport.js"></script>+ <script src="../resources/utils.js"></script>+ <canvas id="canvas" width="200" height="200"></canvas>++ <script>+ setup({"hide_test_state": true});+ promise_test(async t => {+ assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");+ await new Promise(r => window.addEventListener('load', r));+ await assertNoFirstContentfulPaint(t);+ }, 'First contentful paint should not fire for canvas type none');+ </script>+</body>++</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/input-text.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/input-text.htmlnew file mode 100644index 00000000000..6a9e97d1a1e--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/input-text.html@@ -0,0 +1,20 @@+<!DOCTYPE html>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<form>+ <input type="text" id='myInput'>+</form>+<script>+setup({"hide_test_state": true});+promise_test(async t => {+ const onload = new Promise(r => window.addEventListener('load', r));+ await onload;+ return assertNoFirstContentfulPaint(t).then(() => {+ document.getElementById('myInput').value = 'default text';+ return assertFirstContentfulPaint(t);+ });+}, 'Text from a form control triggers First Contentful Paint.');+</script>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/replaced-content-image.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/replaced-content-image.htmlnew file mode 100644index 00000000000..624bc8df9ed--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/replaced-content-image.html@@ -0,0 +1,20 @@+<!DOCTYPE html>+<body>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<style>+ img {+ content: url(../resources/circle.svg);+ }+</style>+<img>+<script>+setup({"hide_test_state": true});+promise_test(async t => {+ const onload = new Promise(r => window.addEventListener('load', r));+ await onload;+ return assertFirstContentfulPaint(t);+}, 'Replaced content image triggers First Contentful Paint.');+</script>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/svg-in-iframe.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/svg-in-iframe.htmlnew file mode 100644index 00000000000..057feea4515--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/fcp-only/svg-in-iframe.html@@ -0,0 +1,14 @@+<!DOCTYPE html>+<title>Performance Paint Timing Test: SVG in iframe does not trigger FCP</title>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<iframe src="../resources/svg.html"></iframe>+<script>+ promise_test(async (t) => {+ await new Promise(resolve => {+ window.addEventListener("message", resolve);+ });+ return assertNoFirstContentfulPaint(t);+ }, "SVG in an iframe does not trigger FCP in the main frame");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/first-paint-only/iframe-in-invisible-ancestor.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/first-paint-only/iframe-in-invisible-ancestor.htmlnew file mode 100644index 00000000000..a25a6378e98--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/first-paint-only/iframe-in-invisible-ancestor.html@@ -0,0 +1,32 @@+<!DOCTYPE HTML>+<meta charset=utf-8>+<title>Paint Timing: First paint is not reported for an iframe inside an invisible ancestor</title>+<link rel="author" title="Shubham Gupta" href="mailto:[email protected]">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/utils.js"></script>+<style>+ #invisible {+ opacity: 0;+ }++ iframe {+ border: 0;+ height: 100px;+ width: 100px;+ }+</style>+<div id="invisible"><iframe src="../resources/subframe-painting.html"></iframe></div>++<script>+ setup({"hide_test_state": true});++ promise_test(async t => {+ assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");++ await waitForAnimationFrames(10);+ assert_equals(performance.getEntriesByName('first-paint').length, 0,+ 'First paint should not be reported for an iframe in an invisible ancestor.');+ await assertNoFirstContentfulPaint(t);+ }, 'First paint is not reported for an iframe inside an invisible ancestor.');+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/resources/circle.svg b/Tests/LibWeb/Text/input/wpt-import/paint-timing/resources/circle.svgnew file mode 100644index 00000000000..6b5fdbe8e06--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/resources/circle.svg@@ -0,0 +1,3 @@+<svg xmlns="http://www.w3.org/2000/svg" version="1.1">+ <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="none" />+</svg>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/resources/circles.png b/Tests/LibWeb/Text/input/wpt-import/paint-timing/resources/circles.pngnew file mode 100644index 00000000000..708682a207bBinary files /dev/null and b/Tests/LibWeb/Text/input/wpt-import/paint-timing/resources/circles.png differdiff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/resources/subframe-painting.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/resources/subframe-painting.htmlnew file mode 100644index 00000000000..00fd39bcb81--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/resources/subframe-painting.html@@ -0,0 +1,24 @@+<!DOCTYPE html>+<body>+<div id="image"></div>+<script>+ const img = document.createElement('IMG');+ img.src = 'circles.png';++ var observer = new PerformanceObserver(function(list, obj) {+ var paintEntries = list.getEntries();+ for (let i = 0; i < paintEntries.length; i++) {+ // postMessage doesn't allow sending the entry object over directly+ var dataToSend = {+ "entryType": paintEntries[i]["entryType"],+ "name": paintEntries[i]["name"]+ };+ parent.postMessage(dataToSend, '*');+ }+ });++ observer.observe({"type": "paint"});+ document.getElementById('image').appendChild(img);+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/resources/svg.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/resources/svg.htmlnew file mode 100644index 00000000000..94185eab346--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/resources/svg.html@@ -0,0 +1,20 @@+<!DOCTYPE html>+<div id="main">+ <svg viewBox="0 0 10 10">+ <defs>+ <circle id="myCircle" cx="5" cy="5" r="4" stroke="blue" />+ </defs>+ <use id="circle" href="#myCircle" fill="green" />+ </svg>+</div>+<script>+ const observer = new PerformanceObserver(list => {+ const fcp = list.getEntriesByName("first-contentful-paint");+ if (!fcp.length)+ return;++ // Message the parent when FCP has been reached.+ parent.postMessage("GotFCP", '*');+ });+ observer.observe({ type: "paint", buffered: true });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/resources/utils.js b/Tests/LibWeb/Text/input/wpt-import/paint-timing/resources/utils.jsnew file mode 100644index 00000000000..d25e3256515--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/resources/utils.js@@ -0,0 +1,99 @@+function waitForAnimationFrames(count) {+ return new Promise(resolve => {+ if (count-- <= 0) {+ resolve();+ } else {+ requestAnimationFrame(() => {+ waitForAnimationFrames(count).then(resolve);+ });+ }+ });+}++function assertFirstPaint() {+ return new Promise(resolve => {+ const observer = new PerformanceObserver(list => {+ let entries = list.getEntries();+ assert_equals(entries.length, 1, 'Expected exactly one first-paint entry');+ assert_equals(entries[0].entryType, 'paint', 'Expected entryType to be "paint"');+ assert_equals(entries[0].name, 'first-paint', 'Expected name to be "first-paint');+ observer.disconnect();+ resolve();+ });+ observer.observe({type: 'paint', buffered: true});+ });+}++// Asserts that there is currently no FCP reported. Pass t to add some wait, in case CSS is loaded+// and FCP is incorrectly fired afterwards.+async function assertNoFirstContentfulPaint(t) {+ await waitForAnimationFrames(3);+ assert_equals(performance.getEntriesByName('first-contentful-paint').length, 0, 'First contentful paint marked too early. ');+}++// Function that is resolved once FCP is reported, using PerformanceObserver. It rejects after a long+// wait time so that failing tests don't timeout.+async function assertFirstContentfulPaint(t) {+ return new Promise(resolve => {+ function checkFCP() {+ const entries = performance.getEntriesByName('first-contentful-paint');+ if (entries.length === 1) {+ resolve(entries[0]);+ } else {+ t.step_timeout(checkFCP, 0);+ }+ }+ t.step(checkFCP);+ });+}++async function test_fcp(label, before_assert_fcp_func) {+ setup({"hide_test_state": true});+ const style = document.createElement('style');+ document.head.appendChild(style);+ await promise_test(async t => {+ assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");+ const main = document.getElementById('main');+ await new Promise(r => window.addEventListener('load', r));+ await assertNoFirstContentfulPaint(t);+ main.className = 'preFCP';+ await assertNoFirstContentfulPaint(t);+ const time_before_fcp_func = performance.now();+ if (before_assert_fcp_func) {+ await before_assert_fcp_func();+ }+ main.className = 'contentful';+ const entry = await assertFirstContentfulPaint(t);+ if ("paintTime" in entry) {+ if ("presentationTime" in entry && entry.presentationTime !== null) {+ assert_greater_than(entry.presentationTime, entry.paintTime);+ assert_equals(entry.startTime, entry.presentationTime);+ } else {+ assert_equals(entry.startTime, entry.paintTime);+ }+ }+ }, label);+}++function assertPaintTimingEntries(t, timeout) {+ function testEntries() {+ const bufferedEntries = performance.getEntriesByType('paint');+ if (bufferedEntries.length < 2) {+ t.step_timeout(function() {+ testEntries();+ }, timeout);+ return;+ }+ t.step(function() {+ assert_equals(bufferedEntries.length, 2, "FP and FCP.");+ assert_equals(bufferedEntries[0].entryType, "paint");+ assert_equals(bufferedEntries[0].name, "first-paint");+ assert_equals(bufferedEntries[1].entryType, "paint");+ assert_equals(bufferedEntries[1].name, "first-contentful-paint");+ t.done();+ });+ }+ t.step(function() {+ testEntries();+ });+}diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/supported-paint-type.window.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/supported-paint-type.window.htmlnew file mode 100644index 00000000000..9939328c7a3--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/supported-paint-type.window.html@@ -0,0 +1,8 @@+<!doctype html>+<meta charset=utf-8>++<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>++<div id=log></div>+<script src="../paint-timing/supported-paint-type.window.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/supported-paint-type.window.js b/Tests/LibWeb/Text/input/wpt-import/paint-timing/supported-paint-type.window.jsnew file mode 100644index 00000000000..518faff5cfb--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/supported-paint-type.window.js@@ -0,0 +1,22 @@+test(() => {+ assert_implements(typeof PerformanceObserver.supportedEntryTypes !== "undefined", 'supportedEntryTypes is not supported');+ assert_true(PerformanceObserver.supportedEntryTypes.includes("paint"),+ "There should be an entry 'paint' in PerformanceObserver.supportedEntryTypes");+}, "supportedEntryTypes contains 'paint'.");++const entryType = 'paint';+promise_test(async() => {+ assert_implements(typeof PerformanceObserver.supportedEntryTypes !== "undefined", 'supportedEntryTypes is not supported');+ assert_implements(typeof PerformanceObserver.supportedEntryTypes.includes(entryType), `supportedEntryTypes does not include '${entryType}'`);+ await new Promise((resolve) => {+ new PerformanceObserver(function (list, observer) {+ observer.disconnect();+ resolve();+ }).observe({entryTypes: [entryType]});++ // Force the PerformanceEntry.+ // Use `self` for Workers.+ if (self.document)+ document.head.parentNode.appendChild(document.createTextNode('foo'));+ })+}, `'${entryType}' entries should be observable.`)diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/with-paint-timing-mixin/paint-timing-mixin-to-json.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/with-paint-timing-mixin/paint-timing-mixin-to-json.htmlnew file mode 100644index 00000000000..4d4b9a026c5--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/with-paint-timing-mixin/paint-timing-mixin-to-json.html@@ -0,0 +1,56 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing: Check that paintTime/presentationTime are serialized properly with toJSON</title>+</head>+<body>+<script src="../resources/utils.js"></script>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script>+ setup({"hide_test_state": true});+ promise_test(async t => {+ assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");+ assert_implements("paintTime" in window.PerformancePaintTiming.prototype, "Paint Timing doesn't expose `paintTime`");+ await new Promise(r => window.addEventListener('load', r));+ await assertNoFirstContentfulPaint(t);+ const img = document.createElement('img');+ img.src = '../resources/circles.png';+ document.body.append(img);+ const reference_time = performance.now();+ const performance_entry_promise = new Promise(resolve => {+ new PerformanceObserver(entries => {+ const [entry] = entries.getEntriesByName("first-contentful-paint");+ if (entry)+ resolve(entry);+ }).observe({type: "paint"});+ });+ const entry = await performance_entry_promise;+ assert_greater_than(entry.paintTime, reference_time);+ if ("presentationTime" in entry && entry.presentationTime !== null) {+ assert_greater_than(entry.presentationTime, entry.paintTime);+ assert_equals(entry.presentationTime, entry.startTime);+ } else {+ assert_equals(entry.paintTime, entry.startTime);+ }++ const json = entry.toJSON();+ assert_equals(typeof json, 'object');+ // Check that basic PerformanceEntry attributes are serialized.+ assert_equals(json.name, entry.name,+ 'PerformanceEventTiming "name" attribute does not match its toJSON value');+ // Check that the PaintTimingMixin attributes are serialized.+ assert_equals(json.paintTime, entry.paintTime,+ 'PerformanceEventTiming "paintTime" attribute does not match its toJSON value');+ assert_equals(json.presentationTime, entry.presentationTime,+ 'PerformanceEventTiming "presentationTime" attribute does not match its toJSON value');+ if ("presentationTime" in entry && entry.presentationTime !== null) {+ assert_greater_than(json.presentationTime, json.paintTime);+ assert_equals(json.presentationTime, json.startTime);+ } else {+ assert_equals(json.paintTime, json.startTime);+ }++}, "Paint timing entries should serialize paintTime and presentationTime with toJSON");+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/paint-timing/with-paint-timing-mixin/paint-timing-mixin.html b/Tests/LibWeb/Text/input/wpt-import/paint-timing/with-paint-timing-mixin/paint-timing-mixin.htmlnew file mode 100644index 00000000000..9cc204eecf2--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/paint-timing/with-paint-timing-mixin/paint-timing-mixin.html@@ -0,0 +1,38 @@+<!DOCTYPE html>+<head>+<title>Performance Paint Timing: Check that paintTime/presentationTime are available</title>+</head>+<body>+<script src="../resources/utils.js"></script>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script>+ setup({"hide_test_state": true});+ promise_test(async t => {+ assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");+ assert_implements("paintTime" in window.PerformancePaintTiming.prototype, "Paint Timing doesn't expose `paintTime`");+ await new Promise(r => window.addEventListener('load', r));+ await assertNoFirstContentfulPaint(t);+ const img = document.createElement('img');+ img.src = '../resources/circles.png';+ document.body.append(img);+ const reference_time = performance.now();+ const performance_entry_promise = new Promise(resolve => {+ new PerformanceObserver(entries => {+ const [entry] = entries.getEntriesByName("first-contentful-paint");+ if (entry)+ resolve(entry);+ }).observe({type: "paint"});+ });+ const entry = await performance_entry_promise;+ assert_greater_than(entry.paintTime, reference_time);+ if ("presentationTime" in entry && entry.presentationTime !== null) {+ assert_greater_than(entry.presentationTime, entry.paintTime);+ assert_equals(entry.presentationTime, entry.startTime);+ } else {+ assert_equals(entry.paintTime, entry.startTime);+ }+}, "Paint timing entries should expose paintTime and presentationTime");+</script>+</body>+</html>