Unreviewed, rolling out r220268.
authorryanhaddad@apple.com <ryanhaddad@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Aug 2017 16:17:57 +0000 (16:17 +0000)
committerryanhaddad@apple.com <ryanhaddad@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Aug 2017 16:17:57 +0000 (16:17 +0000)
This change caused assertion failures on macOS and iOS Debug
WK2.

Reverted changeset:

"Resource Load Statistics: Report user interaction
immediately, but only when needed"
https://bugs.webkit.org/show_bug.cgi?id=175090
http://trac.webkit.org/changeset/220268

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220274 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/loading/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame.html
LayoutTests/http/tests/loading/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time-expected.txt [deleted file]
LayoutTests/http/tests/loading/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time.html [deleted file]
LayoutTests/platform/mac-wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/loader/ResourceLoadObserver.cpp
Source/WebCore/loader/ResourceLoadObserver.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp
Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp

index da0fb59..9894b15 100644 (file)
@@ -1,3 +1,17 @@
+2017-08-04  Ryan Haddad  <ryanhaddad@apple.com>
+
+        Unreviewed, rolling out r220268.
+
+        This change caused assertion failures on macOS and iOS Debug
+        WK2.
+
+        Reverted changeset:
+
+        "Resource Load Statistics: Report user interaction
+        immediately, but only when needed"
+        https://bugs.webkit.org/show_bug.cgi?id=175090
+        http://trac.webkit.org/changeset/220268
+
 2017-08-04  Chris Dumez  <cdumez@apple.com>
 
         Mark beacon-basic-string.html as slow.
index c3ad86c..abdd07e 100644 (file)
@@ -25,8 +25,10 @@ function finishTest() {
 }
 
 onload = function() {
-    if (internals)
+    if (internals) {
         internals.setResourceLoadStatisticsEnabled(true);
+        internals.setResourceLoadStatisticsShouldThrottleObserverNotifications(false);
+    }
 
     if (testRunner) {
         testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
diff --git a/LayoutTests/http/tests/loading/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time-expected.txt b/LayoutTests/http/tests/loading/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time-expected.txt
deleted file mode 100644 (file)
index 1360d7c..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-main frame - didStartProvisionalLoadForFrame
-main frame - didCommitLoadForFrame
-frame "testFrame" - didStartProvisionalLoadForFrame
-main frame - didFinishDocumentLoadForFrame
-frame "testFrame" - didCommitLoadForFrame
-frame "testFrame" - didFinishDocumentLoadForFrame
-frame "testFrame" - didHandleOnloadEventsForFrame
-main frame - didHandleOnloadEventsForFrame
-frame "testFrame" - didFinishLoadForFrame
-main frame - didFinishLoadForFrame
-Tests that user interaction is not reported repeatedly within a short period of time.
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-
-PASS document.location.origin is topFrameOrigin
-PASS testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin) is false
-PASS testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin) is false
-PASS testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin) is true
-PASS testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin) is false
-PASS testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin) is false
-PASS testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin) is false
-PASS testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin) is false
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
diff --git a/LayoutTests/http/tests/loading/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time.html b/LayoutTests/http/tests/loading/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time.html
deleted file mode 100644 (file)
index a1bf5df..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-<!DOCTYPE html>
-<html>
-<body>
-<script src="/js-test-resources/js-test.js"></script>
-<script src="/js-test-resources/ui-helper.js"></script>
-<script>
-    description("Tests that user interaction is not reported repeatedly within a short period of time.");
-    jsTestIsAsync = true;
-
-    const topFrameOrigin = "http://127.0.0.1:8000";
-    const subFrameOrigin = "http://localhost:8000";
-
-    function activateElement(elementId) {
-        var element = document.getElementById(elementId);
-        var centerX = element.offsetLeft + element.offsetWidth / 2;
-        var centerY = element.offsetTop + element.offsetHeight / 2;
-        UIHelper.activateAt(centerX, centerY);
-    }
-
-    function firstInteraction() {
-        if (testRunner) {
-            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-            testRunner.installStatisticsDidScanDataRecordsCallback(secondInteraction);
-
-            shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
-            shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin)");
-        }
-
-        activateElement("testFrame");
-    }
-
-    function secondInteraction() {
-        if (testRunner) {
-            testRunner.installStatisticsDidScanDataRecordsCallback(finishTest);
-
-            shouldBeTrue("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
-            shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin)");
-
-            testRunner.setStatisticsHasHadUserInteraction(topFrameOrigin, false);
-            shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
-        }
-
-        activateElement("testFrame");
-
-        if (testRunner)
-            testRunner.statisticsProcessStatisticsAndDataRecords();
-    }
-
-    function finishTest() {
-        shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
-        shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin)");
-
-        finishJSTest();
-    }
-
-    onload = function() {
-        if (internals)
-            internals.setResourceLoadStatisticsEnabled(true);
-
-        shouldBe("document.location.origin", "topFrameOrigin");
-
-        firstInteraction();
-    };
-</script>
-<iframe id="testFrame" src="http://localhost:8000/loading/resourceLoadStatistics/resources/dummy.html"></iframe>
-</body>
-</html>
\ No newline at end of file
index 78b9028..0191cff 100644 (file)
@@ -719,9 +719,8 @@ webkit.org/b/167757 workers/bomb.html [ Pass Timeout ]
 
 webkit.org/b/172397 [ Sierra Debug ] animations/needs-layout.html [ Pass ImageOnlyFailure ]
 
-# Move to general wk2 expectations once webkit.org/b/175170 is resolved.
+# Currently only tests with click, not tap.
 http/tests/loading/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame.html [ Pass ]
-http/tests/loading/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time.html [ Pass ]
 
 webkit.org/b/173861 [ Release ] http/tests/webrtc/filtering-ice-candidate-same-origin-frame.html [ Pass Timeout ]
 webkit.org/b/173861 [ Release ] http/tests/webrtc/filtering-ice-candidate-cross-origin-frame.html [ Pass Timeout ]
index 959d2ef..bf2e7d5 100644 (file)
@@ -1,3 +1,17 @@
+2017-08-04  Ryan Haddad  <ryanhaddad@apple.com>
+
+        Unreviewed, rolling out r220268.
+
+        This change caused assertion failures on macOS and iOS Debug
+        WK2.
+
+        Reverted changeset:
+
+        "Resource Load Statistics: Report user interaction
+        immediately, but only when needed"
+        https://bugs.webkit.org/show_bug.cgi?id=175090
+        http://trac.webkit.org/changeset/220268
+
 2017-08-04  Youenn Fablet  <youenn@apple.com>
 
         Remove STREAMS_API compilation guard
index 4d1479f..37b710e 100644 (file)
@@ -99,6 +99,19 @@ static bool areDomainsAssociated(Page* page, const String& firstDomain, const St
     return firstMetaDomainIdentifier == metaDomainIdentifiers.get().get(secondDomain);
 }
 
+void ResourceLoadObserver::setShouldThrottleObserverNotifications(bool shouldThrottle)
+{
+    m_shouldThrottleNotifications = shouldThrottle;
+
+    if (!m_notificationTimer.isActive())
+        return;
+
+    // If we change the notification state, we need to restart any notifications
+    // so they will be on the right schedule.
+    m_notificationTimer.stop();
+    scheduleNotificationIfNeeded();
+}
+
 void ResourceLoadObserver::setNotificationCallback(WTF::Function<void (Vector<ResourceLoadStatistics>&&)>&& notificationCallback)
 {
     ASSERT(!m_notificationCallback);
@@ -106,7 +119,7 @@ void ResourceLoadObserver::setNotificationCallback(WTF::Function<void (Vector<Re
 }
 
 ResourceLoadObserver::ResourceLoadObserver()
-    : m_notificationTimer(*this, &ResourceLoadObserver::notifyObserver)
+    : m_notificationTimer(*this, &ResourceLoadObserver::notificationTimerFired)
 {
 }
 
@@ -267,20 +280,16 @@ void ResourceLoadObserver::logUserInteractionWithReducedTimeResolution(const Doc
     if (url.isBlankURL() || url.isEmpty())
         return;
 
-    auto domain = primaryDomain(url);
+    auto& statistics = ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
     auto newTime = reduceToHourlyTimeResolution(WallTime::now());
-    auto lastReportedUserInteraction = m_lastReportedUserInteractionMap.get(domain);
-    if (newTime == lastReportedUserInteraction)
+    if (newTime == statistics.mostRecentUserInteractionTime)
         return;
 
-    m_lastReportedUserInteractionMap.set(domain, newTime);
-
-    auto& statistics = ensureResourceStatisticsForPrimaryDomain(domain);
     statistics.hadUserInteraction = true;
     statistics.lastSeen = newTime;
     statistics.mostRecentUserInteractionTime = newTime;
 
-    notifyObserver();
+    scheduleNotificationIfNeeded();
 }
 
 ResourceLoadStatistics& ResourceLoadObserver::ensureResourceStatisticsForPrimaryDomain(const String& primaryDomain)
@@ -300,13 +309,12 @@ void ResourceLoadObserver::scheduleNotificationIfNeeded()
     }
 
     if (!m_notificationTimer.isActive())
-        m_notificationTimer.startOneShot(minimumNotificationInterval);
+        m_notificationTimer.startOneShot(m_shouldThrottleNotifications ? minimumNotificationInterval : 0_s);
 }
 
-void ResourceLoadObserver::notifyObserver()
+void ResourceLoadObserver::notificationTimerFired()
 {
     ASSERT(m_notificationCallback);
-    m_notificationTimer.stop();
     m_notificationCallback(takeStatistics());
 }
 
@@ -331,10 +339,4 @@ Vector<ResourceLoadStatistics> ResourceLoadObserver::takeStatistics()
     return statistics;
 }
 
-void ResourceLoadObserver::clearState()
-{
-    m_resourceStatisticsMap.clear();
-    m_lastReportedUserInteractionMap.clear();
-}
-
 } // namespace WebCore
index dcc2946..32684bd 100644 (file)
@@ -33,7 +33,6 @@
 namespace WTF {
 class Lock;
 class WorkQueue;
-class WallTime;
 }
 
 namespace WebCore {
@@ -63,7 +62,6 @@ public:
 
     WEBCORE_EXPORT void setNotificationCallback(WTF::Function<void (Vector<ResourceLoadStatistics>&&)>&&);
 
-    WEBCORE_EXPORT void clearState();
 private:
     ResourceLoadObserver();
 
@@ -71,13 +69,13 @@ private:
     ResourceLoadStatistics& ensureResourceStatisticsForPrimaryDomain(const String&);
 
     void scheduleNotificationIfNeeded();
-    void notifyObserver();
+    void notificationTimerFired();
     Vector<ResourceLoadStatistics> takeStatistics();
 
     HashMap<String, ResourceLoadStatistics> m_resourceStatisticsMap;
-    HashMap<String, WTF::WallTime> m_lastReportedUserInteractionMap;
     WTF::Function<void (Vector<ResourceLoadStatistics>&&)> m_notificationCallback;
     Timer m_notificationTimer;
+    bool m_shouldThrottleNotifications { true };
 };
     
 } // namespace WebCore
index dbabb25..91f4d27 100644 (file)
@@ -468,6 +468,8 @@ void Internals::resetToConsistentState(Page& page)
 #if USE(LIBWEBRTC)
     WebCore::useRealRTCPeerConnectionFactory();
 #endif
+    
+    ResourceLoadObserver::shared().setShouldThrottleObserverNotifications(true);
 }
 
 Internals::Internals(Document& document)
@@ -3854,6 +3856,11 @@ void Internals::setResourceLoadStatisticsEnabled(bool enable)
     Settings::setResourceLoadStatisticsEnabled(enable);
 }
 
+void Internals::setResourceLoadStatisticsShouldThrottleObserverNotifications(bool enable)
+{
+    ResourceLoadObserver::shared().setShouldThrottleObserverNotifications(enable);
+}
+    
 String Internals::composedTreeAsText(Node& node)
 {
     if (!is<ContainerNode>(node))
index d18079b..0c0f9b6 100644 (file)
@@ -539,6 +539,7 @@ public:
 
     String resourceLoadStatisticsForOrigin(const String& origin);
     void setResourceLoadStatisticsEnabled(bool);
+    void setResourceLoadStatisticsShouldThrottleObserverNotifications(bool);
 
     bool isReadableStreamDisturbed(JSC::ExecState&, JSC::JSValue);
     JSC::JSValue cloneArrayBuffer(JSC::ExecState&, JSC::JSValue, JSC::JSValue, JSC::JSValue);
index 6d901fe..2f7a482 100644 (file)
@@ -498,6 +498,7 @@ enum EventThrottlingBehavior {
 
     DOMString resourceLoadStatisticsForOrigin(DOMString domain);
     void setResourceLoadStatisticsEnabled(boolean enable);
+    void setResourceLoadStatisticsShouldThrottleObserverNotifications(boolean enable);
 
     [MayThrowException] void setCanShowModalDialogOverride(boolean allow);
 
index 43ec5ac..792f420 100644 (file)
@@ -1,3 +1,17 @@
+2017-08-04  Ryan Haddad  <ryanhaddad@apple.com>
+
+        Unreviewed, rolling out r220268.
+
+        This change caused assertion failures on macOS and iOS Debug
+        WK2.
+
+        Reverted changeset:
+
+        "Resource Load Statistics: Report user interaction
+        immediately, but only when needed"
+        https://bugs.webkit.org/show_bug.cgi?id=175090
+        http://trac.webkit.org/changeset/220268
+
 2017-08-04  Andreas Kling  <akling@apple.com>
 
         NetworkLoad should always invoke its redirect completion handler
index 34bce00..d0826dd 100644 (file)
@@ -39,7 +39,6 @@
 #include "WebPage.h"
 #include "WebPageGroupProxy.h"
 #include <WebCore/DatabaseTracker.h>
-#include <WebCore/ResourceLoadObserver.h>
 
 using namespace WebCore;
 using namespace WebKit;
@@ -277,8 +276,3 @@ void WKBundleSetTabKeyCyclesThroughElements(WKBundleRef bundleRef, WKBundlePageR
 {
     toImpl(bundleRef)->setTabKeyCyclesThroughElements(toImpl(pageRef), enabled);
 }
-
-void WKBundleClearResourceLoadStatistics(WKBundleRef)
-{
-    ResourceLoadObserver::shared().clearState();
-}
index 9b58a9e..ce83243 100644 (file)
@@ -91,8 +91,6 @@ WK_EXPORT bool WKBundleIsProcessingUserGesture(WKBundleRef bundle);
 
 WK_EXPORT void WKBundleSetTabKeyCyclesThroughElements(WKBundleRef bundle, WKBundlePageRef page, bool enabled);
 
-WK_EXPORT void WKBundleClearResourceLoadStatistics(WKBundleRef);
-
 #ifdef __cplusplus
 }
 #endif
index 4b22c96..203fd16 100644 (file)
@@ -1,3 +1,17 @@
+2017-08-04  Ryan Haddad  <ryanhaddad@apple.com>
+
+        Unreviewed, rolling out r220268.
+
+        This change caused assertion failures on macOS and iOS Debug
+        WK2.
+
+        Reverted changeset:
+
+        "Resource Load Statistics: Report user interaction
+        immediately, but only when needed"
+        https://bugs.webkit.org/show_bug.cgi?id=175090
+        http://trac.webkit.org/changeset/220268
+
 2017-08-04  Youenn Fablet  <youenn@apple.com>
 
         Remove STREAMS_API compilation guard
index 96b0113..7a58e23 100644 (file)
@@ -367,7 +367,6 @@ void InjectedBundle::beginTesting(WKDictionaryRef settings)
     WKBundleClearAllDatabases(m_bundle);
     WKBundlePageClearApplicationCache(page()->page());
     WKBundleResetOriginAccessWhitelists(m_bundle);
-    WKBundleClearResourceLoadStatistics(m_bundle);
 
     // [WK2] REGRESSION(r128623): It made layout tests extremely slow
     // https://bugs.webkit.org/show_bug.cgi?id=96862