Title: [281147] trunk
Revision
281147
Author
[email protected]
Date
2021-08-17 10:30:54 -0700 (Tue, 17 Aug 2021)

Log Message

Document load events should update timing in PerformanceNavigationTiming even after its instantiation
https://bugs.webkit.org/show_bug.cgi?id=229181

Patch by Alex Christensen <[email protected]> on 2021-08-17
Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/navigation-timing/nav2_test_attributes_values-expected.txt:

Source/WebCore:

When we make a PerformanceNavigationTiming object, we copy the DocumentLoadTiming and DocumentEventTiming values.
If PerformanceNavigationTiming is accessed before the document has finished loading, we still need to update the timing values.

Covered by a newly passing WPT test, which Chrome and Firefox already pass.

* dom/Document.cpp:
(WebCore::Document::documentEventTimingFromNavigationTiming):
(WebCore::Document::setReadyState):
(WebCore::Document::finishedParsing):
* dom/Document.h:
* loader/DocumentLoadTiming.h:
(WebCore::DocumentLoadTiming::setLoadEventStart):
(WebCore::DocumentLoadTiming::setLoadEventEnd):
(WebCore::DocumentLoadTiming::markLoadEventStart): Deleted.
(WebCore::DocumentLoadTiming::markLoadEventEnd): Deleted.
* page/DOMWindow.cpp:
(WebCore::DOMWindow::dispatchLoadEvent):
* page/Performance.h:
* page/PerformanceNavigationTiming.h:

LayoutTests:

* TestExpectations:
* platform/mac-wk1/TestExpectations:
This test now always passes in WK2.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (281146 => 281147)


--- trunk/LayoutTests/ChangeLog	2021-08-17 17:25:00 UTC (rev 281146)
+++ trunk/LayoutTests/ChangeLog	2021-08-17 17:30:54 UTC (rev 281147)
@@ -1,3 +1,14 @@
+2021-08-17  Alex Christensen  <[email protected]>
+
+        Document load events should update timing in PerformanceNavigationTiming even after its instantiation
+        https://bugs.webkit.org/show_bug.cgi?id=229181
+
+        Reviewed by Chris Dumez.
+
+        * TestExpectations:
+        * platform/mac-wk1/TestExpectations:
+        This test now always passes in WK2.
+
 2021-08-17  Eric Hutchison  <[email protected]>
 
         [Star wk2 Release] performance-api/performance-observer-no-document-leak.html is a flaky crash.

Modified: trunk/LayoutTests/TestExpectations (281146 => 281147)


--- trunk/LayoutTests/TestExpectations	2021-08-17 17:25:00 UTC (rev 281146)
+++ trunk/LayoutTests/TestExpectations	2021-08-17 17:30:54 UTC (rev 281147)
@@ -1132,7 +1132,6 @@
 imported/w3c/web-platform-tests/resource-timing/crossorigin-sandwich-TAO.sub.html [ Pass Failure ]
 imported/w3c/web-platform-tests/resource-timing/crossorigin-sandwich-partial-TAO.sub.html [ Pass Failure ]
 imported/w3c/web-platform-tests/navigation-timing/secure_connection_start_non_zero.https.html [ Pass Failure ]
-imported/w3c/web-platform-tests/navigation-timing/nav2_test_attributes_values.html [ Pass Failure ]
 imported/w3c/web-platform-tests/resource-timing/TAO-match.html [ Pass Failure ]
 imported/w3c/web-platform-tests/resource-timing/iframe-failed-commit.html [ Pass Failure ]
 imported/w3c/web-platform-tests/resource-timing/fetch-cross-origin-redirect.https.html [ Pass Failure ]

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (281146 => 281147)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-08-17 17:25:00 UTC (rev 281146)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-08-17 17:30:54 UTC (rev 281147)
@@ -1,5 +1,14 @@
 2021-08-17  Alex Christensen  <[email protected]>
 
+        Document load events should update timing in PerformanceNavigationTiming even after its instantiation
+        https://bugs.webkit.org/show_bug.cgi?id=229181
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/navigation-timing/nav2_test_attributes_values-expected.txt:
+
+2021-08-17  Alex Christensen  <[email protected]>
+
         Remove unused test expectation file
 
         * web-platform-tests/resource-timing/idlharness-expected.txt: Removed.

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/navigation-timing/nav2_test_attributes_values-expected.txt (281146 => 281147)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/navigation-timing/nav2_test_attributes_values-expected.txt	2021-08-17 17:25:00 UTC (rev 281146)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/navigation-timing/nav2_test_attributes_values-expected.txt	2021-08-17 17:30:54 UTC (rev 281147)
@@ -3,5 +3,5 @@
 This test validates that the values of nav timing 2 instance's timing-related attributes are in certain order and the others are of expected values.
 
 
-FAIL Performance navigation timing instance's value is reasonable. assert_greater_than: Expected domInteractive to be greater than 0 expected a number greater than 0 but got 0
+PASS Performance navigation timing instance's value is reasonable.
 

Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (281146 => 281147)


--- trunk/LayoutTests/platform/mac-wk1/TestExpectations	2021-08-17 17:25:00 UTC (rev 281146)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations	2021-08-17 17:30:54 UTC (rev 281147)
@@ -581,6 +581,7 @@
 
 # NSURLConnection doesn't have an API to give us good timing for redirects. We do what we can with MonotonicTime::now() but this still fails sometimes.
 imported/w3c/web-platform-tests/navigation-timing/nav2_test_redirect_server.html [ Pass Failure ]
+imported/w3c/web-platform-tests/navigation-timing/nav2_test_attributes_values.html [ Pass Failure ]
 
 webkit.org/b/160101 userscripts/window-onerror-for-isolated-world-3.html [ Pass Failure ]
 

Modified: trunk/Source/WebCore/ChangeLog (281146 => 281147)


--- trunk/Source/WebCore/ChangeLog	2021-08-17 17:25:00 UTC (rev 281146)
+++ trunk/Source/WebCore/ChangeLog	2021-08-17 17:30:54 UTC (rev 281147)
@@ -1,3 +1,30 @@
+2021-08-17  Alex Christensen  <[email protected]>
+
+        Document load events should update timing in PerformanceNavigationTiming even after its instantiation
+        https://bugs.webkit.org/show_bug.cgi?id=229181
+
+        Reviewed by Chris Dumez.
+
+        When we make a PerformanceNavigationTiming object, we copy the DocumentLoadTiming and DocumentEventTiming values.
+        If PerformanceNavigationTiming is accessed before the document has finished loading, we still need to update the timing values.
+
+        Covered by a newly passing WPT test, which Chrome and Firefox already pass.
+
+        * dom/Document.cpp:
+        (WebCore::Document::documentEventTimingFromNavigationTiming):
+        (WebCore::Document::setReadyState):
+        (WebCore::Document::finishedParsing):
+        * dom/Document.h:
+        * loader/DocumentLoadTiming.h:
+        (WebCore::DocumentLoadTiming::setLoadEventStart):
+        (WebCore::DocumentLoadTiming::setLoadEventEnd):
+        (WebCore::DocumentLoadTiming::markLoadEventStart): Deleted.
+        (WebCore::DocumentLoadTiming::markLoadEventEnd): Deleted.
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::dispatchLoadEvent):
+        * page/Performance.h:
+        * page/PerformanceNavigationTiming.h:
+
 2021-08-17  Antti Koivisto  <[email protected]>
 
         Incorrect repaint when inline level box style change triggers line height change

Modified: trunk/Source/WebCore/dom/Document.cpp (281146 => 281147)


--- trunk/Source/WebCore/dom/Document.cpp	2021-08-17 17:25:00 UTC (rev 281146)
+++ trunk/Source/WebCore/dom/Document.cpp	2021-08-17 17:30:54 UTC (rev 281147)
@@ -161,6 +161,7 @@
 #include "PageTransitionEvent.h"
 #include "PaintWorkletGlobalScope.h"
 #include "Performance.h"
+#include "PerformanceNavigationTiming.h"
 #include "PlatformLocale.h"
 #include "PlatformMediaSessionManager.h"
 #include "PlatformScreen.h"
@@ -1374,6 +1375,17 @@
     return createElement(parsedName, false);
 }
 
+DocumentEventTiming* Document::documentEventTimingFromNavigationTiming()
+{
+    auto* window = domWindow();
+    if (!window)
+        return nullptr;
+    auto* navigationTiming = window->performance().navigationTiming();
+    if (!navigationTiming)
+        return nullptr;
+    return &navigationTiming->documentEventTiming();
+}
+
 void Document::setReadyState(ReadyState readyState)
 {
     if (readyState == m_readyState)
@@ -1381,16 +1393,28 @@
 
     switch (readyState) {
     case Loading:
-        if (!m_eventTiming.domLoading)
-            m_eventTiming.domLoading = MonotonicTime::now();
+        if (!m_eventTiming.domLoading) {
+            auto now = MonotonicTime::now();
+            m_eventTiming.domLoading = now;
+            if (auto* eventTiming = documentEventTimingFromNavigationTiming())
+                eventTiming->domLoading = now;
+        }
         break;
     case Complete:
-        if (!m_eventTiming.domComplete)
-            m_eventTiming.domComplete = MonotonicTime::now();
+        if (!m_eventTiming.domComplete) {
+            auto now = MonotonicTime::now();
+            m_eventTiming.domComplete = now;
+            if (auto* eventTiming = documentEventTimingFromNavigationTiming())
+                eventTiming->domComplete = now;
+        }
         FALLTHROUGH;
     case Interactive:
-        if (!m_eventTiming.domInteractive)
-            m_eventTiming.domInteractive = MonotonicTime::now();
+        if (!m_eventTiming.domInteractive) {
+            auto now = MonotonicTime::now();
+            m_eventTiming.domInteractive = now;
+            if (auto* eventTiming = documentEventTimingFromNavigationTiming())
+                eventTiming->domInteractive = now;
+        }
         break;
     }
 
@@ -6070,15 +6094,23 @@
 
     scriptRunner().documentFinishedParsing();
 
-    if (!m_eventTiming.domContentLoadedEventStart)
-        m_eventTiming.domContentLoadedEventStart = MonotonicTime::now();
+    if (!m_eventTiming.domContentLoadedEventStart) {
+        auto now = MonotonicTime::now();
+        m_eventTiming.domContentLoadedEventStart = now;
+        if (auto* eventTiming = documentEventTimingFromNavigationTiming())
+            eventTiming->domContentLoadedEventStart = now;
+    }
 
     // FIXME: Schedule a task to fire DOMContentLoaded event instead. See webkit.org/b/82931
     eventLoop().performMicrotaskCheckpoint();
     dispatchEvent(Event::create(eventNames().DOMContentLoadedEvent, Event::CanBubble::Yes, Event::IsCancelable::No));
 
-    if (!m_eventTiming.domContentLoadedEventEnd)
-        m_eventTiming.domContentLoadedEventEnd = MonotonicTime::now();
+    if (!m_eventTiming.domContentLoadedEventEnd) {
+        auto now = MonotonicTime::now();
+        m_eventTiming.domContentLoadedEventEnd = now;
+        if (auto* eventTiming = documentEventTimingFromNavigationTiming())
+            eventTiming->domContentLoadedEventEnd = now;
+    }
 
     if (RefPtr<Frame> frame = this->frame()) {
 #if ENABLE(XSLT)

Modified: trunk/Source/WebCore/dom/Document.h (281146 => 281147)


--- trunk/Source/WebCore/dom/Document.h	2021-08-17 17:25:00 UTC (rev 281146)
+++ trunk/Source/WebCore/dom/Document.h	2021-08-17 17:30:54 UTC (rev 281147)
@@ -1659,6 +1659,8 @@
     void createRenderTree();
     void detachParser();
 
+    DocumentEventTiming* documentEventTimingFromNavigationTiming();
+
     // ScriptExecutionContext
     CSSFontSelector* cssFontSelector() final { return m_fontSelector.ptr(); }
     std::unique_ptr<FontLoadRequest> fontLoadRequest(String&, bool, bool, LoadedFromOpaqueSource) final;

Modified: trunk/Source/WebCore/loader/DocumentLoadTiming.h (281146 => 281147)


--- trunk/Source/WebCore/loader/DocumentLoadTiming.h	2021-08-17 17:25:00 UTC (rev 281146)
+++ trunk/Source/WebCore/loader/DocumentLoadTiming.h	2021-08-17 17:30:54 UTC (rev 281147)
@@ -37,8 +37,8 @@
 
     void markUnloadEventStart() { m_unloadEventStart = MonotonicTime::now(); }
     void markUnloadEventEnd() { m_unloadEventEnd = MonotonicTime::now(); }
-    void markLoadEventStart() { m_loadEventStart = MonotonicTime::now(); }
-    void markLoadEventEnd() { m_loadEventEnd = MonotonicTime::now(); }
+    void setLoadEventStart(MonotonicTime time) { m_loadEventStart = time; }
+    void setLoadEventEnd(MonotonicTime time) { m_loadEventEnd = time; }
 
     void setHasSameOriginAsPreviousDocument(bool value) { m_hasSameOriginAsPreviousDocument = value; }
 

Modified: trunk/Source/WebCore/page/DOMWindow.cpp (281146 => 281147)


--- trunk/Source/WebCore/page/DOMWindow.cpp	2021-08-17 17:25:00 UTC (rev 281146)
+++ trunk/Source/WebCore/page/DOMWindow.cpp	2021-08-17 17:30:54 UTC (rev 281147)
@@ -86,6 +86,7 @@
 #include "PageConsoleClient.h"
 #include "PageTransitionEvent.h"
 #include "Performance.h"
+#include "PerformanceNavigationTiming.h"
 #include "RequestAnimationFrameCallback.h"
 #include "ResourceLoadInfo.h"
 #include "ResourceLoadObserver.h"
@@ -2259,13 +2260,21 @@
     auto protectedLoader = makeRefPtr(frame() ? frame()->loader().documentLoader() : nullptr);
     bool shouldMarkLoadEventTimes = protectedLoader && !protectedLoader->timing().loadEventStart();
 
-    if (shouldMarkLoadEventTimes)
-        protectedLoader->timing().markLoadEventStart();
+    if (shouldMarkLoadEventTimes) {
+        auto now = MonotonicTime::now();
+        protectedLoader->timing().setLoadEventStart(now);
+        if (auto* navigationTiming = performance().navigationTiming())
+            navigationTiming->documentLoadTiming().setLoadEventStart(now);
+    }
 
     dispatchEvent(Event::create(eventNames().loadEvent, Event::CanBubble::No, Event::IsCancelable::No), document());
 
-    if (shouldMarkLoadEventTimes)
-        protectedLoader->timing().markLoadEventEnd();
+    if (shouldMarkLoadEventTimes) {
+        auto now = MonotonicTime::now();
+        protectedLoader->timing().setLoadEventEnd(now);
+        if (auto* navigationTiming = performance().navigationTiming())
+            navigationTiming->documentLoadTiming().setLoadEventEnd(now);
+    }
 
     // Send a separate load event to the element that owns this frame.
     if (RefPtr ownerFrame = frame()) {

Modified: trunk/Source/WebCore/page/Performance.h (281146 => 281147)


--- trunk/Source/WebCore/page/Performance.h	2021-08-17 17:25:00 UTC (rev 281146)
+++ trunk/Source/WebCore/page/Performance.h	2021-08-17 17:30:54 UTC (rev 281147)
@@ -116,6 +116,8 @@
 
     void scheduleNavigationObservationTaskIfNeeded();
 
+    PerformanceNavigationTiming* navigationTiming() { return m_navigationTiming.get(); }
+
 private:
     Performance(ScriptExecutionContext*, MonotonicTime timeOrigin);
 

Modified: trunk/Source/WebCore/page/PerformanceNavigationTiming.h (281146 => 281147)


--- trunk/Source/WebCore/page/PerformanceNavigationTiming.h	2021-08-17 17:25:00 UTC (rev 281146)
+++ trunk/Source/WebCore/page/PerformanceNavigationTiming.h	2021-08-17 17:30:54 UTC (rev 281147)
@@ -68,6 +68,9 @@
     double startTime() const final;
     double duration() const final;
 
+    DocumentEventTiming& documentEventTiming() { return m_documentEventTiming; }
+    DocumentLoadTiming& documentLoadTiming() { return m_documentLoadTiming; }
+
 private:
     PerformanceNavigationTiming(MonotonicTime timeOrigin, CachedResource&, const DocumentLoadTiming&, const NetworkLoadMetrics&, const DocumentEventTiming&, const SecurityOrigin&, WebCore::NavigationType);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to