Title: [293502] trunk
Revision
293502
Author
[email protected]
Date
2022-04-27 02:10:04 -0700 (Wed, 27 Apr 2022)

Log Message

Add testRunner API to clear memory cache
https://bugs.webkit.org/show_bug.cgi?id=239804
rdar://92033309

Reviewed by Chris Dumez.

Source/WebCore:

* testing/Internals.cpp:
(WebCore::Internals::clearMemoryCache):
Beef up clearMemoryCache to be on par with testRunner counterpart.

Source/WebKit:

Add necessary WebKit API to implement the testRunner API.
Make use of new testRunner API in added test.

Test: http/wpt/fetch/clear-memory-cache.html

* NetworkProcess/NetworkProcess.cpp:
* UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
* UIProcess/API/C/WKWebsiteDataStoreRef.h:
* UIProcess/WebsiteData/WebsiteDataStore.cpp:

Tools:

Implement the clear memory cache testRunner API and related plumbery.

* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/TestController.cpp:
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/TestInvocation.cpp:

LayoutTests:

* http/wpt/fetch/clear-memory-cache-expected.txt: Added.
* http/wpt/fetch/clear-memory-cache.html: Added.
* http/wpt/fetch/resources/clear-memory-cache.py: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (293501 => 293502)


--- trunk/LayoutTests/ChangeLog	2022-04-27 08:21:21 UTC (rev 293501)
+++ trunk/LayoutTests/ChangeLog	2022-04-27 09:10:04 UTC (rev 293502)
@@ -1,5 +1,17 @@
 2022-04-27  Youenn Fablet  <[email protected]>
 
+        Add testRunner API to clear memory cache
+        https://bugs.webkit.org/show_bug.cgi?id=239804
+        rdar://92033309
+
+        Reviewed by Chris Dumez.
+
+        * http/wpt/fetch/clear-memory-cache-expected.txt: Added.
+        * http/wpt/fetch/clear-memory-cache.html: Added.
+        * http/wpt/fetch/resources/clear-memory-cache.py: Added.
+
+2022-04-27  Youenn Fablet  <[email protected]>
+
         Shared workers should match service worker registrations
         https://bugs.webkit.org/show_bug.cgi?id=239122
 

Added: trunk/LayoutTests/http/wpt/fetch/clear-memory-cache-expected.txt (0 => 293502)


--- trunk/LayoutTests/http/wpt/fetch/clear-memory-cache-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/clear-memory-cache-expected.txt	2022-04-27 09:10:04 UTC (rev 293502)
@@ -0,0 +1,3 @@
+
+PASS Clear memory cache between fetches
+

Added: trunk/LayoutTests/http/wpt/fetch/clear-memory-cache.html (0 => 293502)


--- trunk/LayoutTests/http/wpt/fetch/clear-memory-cache.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/clear-memory-cache.html	2022-04-27 09:10:04 UTC (rev 293502)
@@ -0,0 +1,31 @@
+<!doctype html>
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+<script>
+promise_test(async (test) => {
+    const uuid = token();
+    const url = "" + '/WebKit/fetch/resources/clear-memory-cache.py?uuid=' + uuid;
+
+    await fetch(url, { mode: 'cors', headers: [['header', 'value']] });
+
+    let response = await fetch(url, { mode: 'cors' });
+    assert_equals(await response.text(), "1");
+
+    if (window.testRunner && testRunner.clearMemoryCache)
+        testRunner.clearMemoryCache();
+
+    if (window.internals)
+        internals.clearMemoryCache();
+
+    await fetch(url, { mode: 'cors', headers: [['header', 'value']] });
+
+    response = await fetch(url, { mode: 'cors' });
+
+    if (!window.testRunner)
+        return;
+
+    assert_equals(await response.text(), "2");
+}, "Clear memory cache between fetches");
+</script>

Added: trunk/LayoutTests/http/wpt/fetch/resources/clear-memory-cache.py (0 => 293502)


--- trunk/LayoutTests/http/wpt/fetch/resources/clear-memory-cache.py	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/resources/clear-memory-cache.py	2022-04-27 09:10:04 UTC (rev 293502)
@@ -0,0 +1,23 @@
+import time
+
+
+def main(request, response):
+    headers = [("Content-Type", "text/plain")]
+    headers.append(("Access-Control-Allow-Origin", "*"))
+    headers.append(("Access-Control-Allow-Methods", "GET"))
+    headers.append(("Access-Control-Allow-Headers", "header"))
+
+    uuid = request.GET[b"uuid"]
+    count = request.server.stash.take(uuid)
+    if count is None:
+        count = 0
+
+    if request.method == "OPTIONS":
+        headers.append(("Cache-Control", "max-age=100000"))
+        request.server.stash.put(uuid, count + 1)
+        return 200, headers, ""
+
+    request.server.stash.put(uuid, count)
+
+    headers.append(("Cache-Control", "no-cache"))
+    return 200, headers, "" + str(count)

Modified: trunk/Source/WebCore/ChangeLog (293501 => 293502)


--- trunk/Source/WebCore/ChangeLog	2022-04-27 08:21:21 UTC (rev 293501)
+++ trunk/Source/WebCore/ChangeLog	2022-04-27 09:10:04 UTC (rev 293502)
@@ -1,5 +1,17 @@
 2022-04-27  Youenn Fablet  <[email protected]>
 
+        Add testRunner API to clear memory cache
+        https://bugs.webkit.org/show_bug.cgi?id=239804
+        rdar://92033309
+
+        Reviewed by Chris Dumez.
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::clearMemoryCache):
+        Beef up clearMemoryCache to be on par with testRunner counterpart.
+
+2022-04-27  Youenn Fablet  <[email protected]>
+
         Shared workers should match service worker registrations
         https://bugs.webkit.org/show_bug.cgi?id=239122
 

Modified: trunk/Source/WebCore/testing/Internals.cpp (293501 => 293502)


--- trunk/Source/WebCore/testing/Internals.cpp	2022-04-27 08:21:21 UTC (rev 293501)
+++ trunk/Source/WebCore/testing/Internals.cpp	2022-04-27 09:10:04 UTC (rev 293502)
@@ -54,6 +54,7 @@
 #include "ColorSerialization.h"
 #include "ComposedTreeIterator.h"
 #include "CookieJar.h"
+#include "CrossOriginPreflightResultCache.h"
 #include "Cursor.h"
 #include "DOMPointReadOnly.h"
 #include "DOMRect.h"
@@ -948,6 +949,7 @@
 void Internals::clearMemoryCache()
 {
     MemoryCache::singleton().evictResources();
+    CrossOriginPreflightResultCache::singleton().clear();
 }
 
 void Internals::pruneMemoryCacheToSize(unsigned size)

Modified: trunk/Source/WebKit/ChangeLog (293501 => 293502)


--- trunk/Source/WebKit/ChangeLog	2022-04-27 08:21:21 UTC (rev 293501)
+++ trunk/Source/WebKit/ChangeLog	2022-04-27 09:10:04 UTC (rev 293502)
@@ -1,5 +1,23 @@
 2022-04-27  Youenn Fablet  <[email protected]>
 
+        Add testRunner API to clear memory cache
+        https://bugs.webkit.org/show_bug.cgi?id=239804
+        rdar://92033309
+
+        Reviewed by Chris Dumez.
+
+        Add necessary WebKit API to implement the testRunner API.
+        Make use of new testRunner API in added test.
+
+        Test: http/wpt/fetch/clear-memory-cache.html
+
+        * NetworkProcess/NetworkProcess.cpp:
+        * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
+        * UIProcess/API/C/WKWebsiteDataStoreRef.h:
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+
+2022-04-27  Youenn Fablet  <[email protected]>
+
         Shared workers should match service worker registrations
         https://bugs.webkit.org/show_bug.cgi?id=239122
 

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (293501 => 293502)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2022-04-27 08:21:21 UTC (rev 293501)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2022-04-27 09:10:04 UTC (rev 293502)
@@ -67,6 +67,7 @@
 #include <WebCore/ClientOrigin.h>
 #include <WebCore/CommonAtomStrings.h>
 #include <WebCore/CookieJar.h>
+#include <WebCore/CrossOriginPreflightResultCache.h>
 #include <WebCore/DNS.h>
 #include <WebCore/DeprecatedGlobalSettings.h>
 #include <WebCore/DiagnosticLoggingClient.h>
@@ -1552,6 +1553,9 @@
     if (session)
         session->removeNetworkWebsiteData(modifiedSince, std::nullopt, [clearTasksHandler] { });
 
+    if (websiteDataTypes.contains(WebsiteDataType::MemoryCache))
+        CrossOriginPreflightResultCache::singleton().clear();
+
     if (websiteDataTypes.contains(WebsiteDataType::DiskCache) && !sessionID.isEphemeral())
         clearDiskCache(modifiedSince, [clearTasksHandler] { });
 
@@ -1642,6 +1646,9 @@
     }
 #endif
 
+    if (websiteDataTypes.contains(WebsiteDataType::MemoryCache))
+        CrossOriginPreflightResultCache::singleton().clear();
+
     if (websiteDataTypes.contains(WebsiteDataType::DiskCache) && !sessionID.isEphemeral()) {
         forEachNetworkSession([originDatas, &clearTasksHandler](auto& session) {
             clearDiskCacheEntries(session.cache(), originDatas, [clearTasksHandler] { });

Modified: trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp (293501 => 293502)


--- trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp	2022-04-27 08:21:21 UTC (rev 293501)
+++ trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp	2022-04-27 09:10:04 UTC (rev 293502)
@@ -732,6 +732,14 @@
     });
 }
 
+void WKWebsiteDataStoreRemoveMemoryCaches(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveMemoryCachesRemovalFunction callback)
+{
+    OptionSet<WebKit::WebsiteDataType> dataTypes = WebKit::WebsiteDataType::MemoryCache;
+    WebKit::toImpl(dataStoreRef)->removeData(dataTypes, -WallTime::infinity(), [context, callback] {
+        callback(context);
+    });
+}
+
 void WKWebsiteDataStoreRemoveFetchCacheForOrigin(WKWebsiteDataStoreRef dataStoreRef, WKSecurityOriginRef origin, void* context, WKWebsiteDataStoreRemoveFetchCacheRemovalFunction callback)
 {
     WebKit::WebsiteDataRecord dataRecord;

Modified: trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h (293501 => 293502)


--- trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h	2022-04-27 08:21:21 UTC (rev 293501)
+++ trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h	2022-04-27 09:10:04 UTC (rev 293502)
@@ -159,6 +159,9 @@
 WK_EXPORT void WKWebsiteDataStoreRemoveFetchCacheForOrigin(WKWebsiteDataStoreRef dataStoreRef, WKSecurityOriginRef origin, void* context, WKWebsiteDataStoreRemoveFetchCacheRemovalFunction callback);
 WK_EXPORT void WKWebsiteDataStoreRemoveAllFetchCaches(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveFetchCacheRemovalFunction callback);
 
+typedef void (*WKWebsiteDataStoreRemoveMemoryCachesRemovalFunction)(void* functionContext);
+WK_EXPORT void WKWebsiteDataStoreRemoveMemoryCaches(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveMemoryCachesRemovalFunction callback);
+
 typedef void (*WKWebsiteDataStoreRemoveITPDataForDomainFunction)(void* functionContext);
 WK_EXPORT void WKWebsiteDataStoreRemoveITPDataForDomain(WKWebsiteDataStoreRef dataStoreRef, WKStringRef origin, void* context, WKWebsiteDataStoreRemoveITPDataForDomainFunction callback);
 typedef void (*WKWebsiteDataStoreDoesStatisticsDomainIDExistInDatabaseFunction)(bool domainExistsInDatabase, void* functionContext);

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (293501 => 293502)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2022-04-27 08:21:21 UTC (rev 293501)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2022-04-27 09:10:04 UTC (rev 293502)
@@ -568,6 +568,8 @@
 {
     ProcessAccessType processAccessType = ProcessAccessType::None;
     for (auto dataType : dataTypes) {
+        if (dataTypes.contains(WebsiteDataType::MemoryCache))
+            processAccessType = ProcessAccessType::OnlyIfLaunched;
         if (WebsiteData::ownerProcess(dataType) != WebsiteDataProcessType::Network)
             continue;
         if (dataType != WebsiteDataType::Cookies || !isNonPersistentStore)

Modified: trunk/Tools/ChangeLog (293501 => 293502)


--- trunk/Tools/ChangeLog	2022-04-27 08:21:21 UTC (rev 293501)
+++ trunk/Tools/ChangeLog	2022-04-27 09:10:04 UTC (rev 293502)
@@ -1,3 +1,20 @@
+2022-04-27  Youenn Fablet  <[email protected]>
+
+        Add testRunner API to clear memory cache
+        https://bugs.webkit.org/show_bug.cgi?id=239804
+        rdar://92033309
+
+        Reviewed by Chris Dumez.
+
+        Implement the clear memory cache testRunner API and related plumbery.
+
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/TestController.cpp:
+        * WebKitTestRunner/TestController.h:
+        * WebKitTestRunner/TestInvocation.cpp:
+
 2022-04-26  Kimmo Kinnunen  <[email protected]>
 
         Remove adjustPathForRecentRenamings from VCSUtils.pm, they are not recent anymore

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (293501 => 293502)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2022-04-27 08:21:21 UTC (rev 293501)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2022-04-27 09:10:04 UTC (rev 293502)
@@ -408,6 +408,8 @@
     undefined cleanUpKeychain(DOMString attrLabel, optional DOMString applicationLabelBase64);
     boolean keyExistsInKeychain(DOMString attrLabel, DOMString applicationLabelBase64);
 
+    undefined clearMemoryCache();
+
     // Private Click Measurement
     undefined clearPrivateClickMeasurement();
     undefined clearPrivateClickMeasurementsThroughWebsiteDataRemoval();

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (293501 => 293502)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2022-04-27 08:21:21 UTC (rev 293501)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2022-04-27 09:10:04 UTC (rev 293502)
@@ -2083,6 +2083,11 @@
     postSynchronousPageMessage("DumpPrivateClickMeasurement");
 }
 
+void TestRunner::clearMemoryCache()
+{
+    postSynchronousPageMessage("ClearMemoryCache");
+}
+
 void TestRunner::clearPrivateClickMeasurement()
 {
     postSynchronousPageMessage("ClearPrivateClickMeasurement");

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (293501 => 293502)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2022-04-27 08:21:21 UTC (rev 293501)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2022-04-27 09:10:04 UTC (rev 293502)
@@ -524,6 +524,8 @@
 
     unsigned long serverTrustEvaluationCallbackCallsCount();
 
+    void clearMemoryCache();
+
     // Private Click Measurement.
     void dumpPrivateClickMeasurement();
     void clearPrivateClickMeasurement();

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (293501 => 293502)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2022-04-27 08:21:21 UTC (rev 293501)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2022-04-27 09:10:04 UTC (rev 293502)
@@ -3063,6 +3063,14 @@
     runUntil(context.done, noTimeout);
 }
 
+void TestController::clearMemoryCache()
+{
+    ClearDOMCacheCallbackContext context(*this);
+
+    WKWebsiteDataStoreRemoveMemoryCaches(websiteDataStore(), &context, clearDOMCacheCallback);
+    runUntil(context.done, noTimeout);
+}
+
 struct StorageVoidCallbackContext {
     explicit StorageVoidCallbackContext(TestController& controller)
         : testController(controller)

Modified: trunk/Tools/WebKitTestRunner/TestController.h (293501 => 293502)


--- trunk/Tools/WebKitTestRunner/TestController.h	2022-04-27 08:21:21 UTC (rev 293501)
+++ trunk/Tools/WebKitTestRunner/TestController.h	2022-04-27 09:10:04 UTC (rev 293502)
@@ -296,6 +296,7 @@
 
     void clearServiceWorkerRegistrations();
 
+    void clearMemoryCache();
     void clearDOMCache(WKStringRef origin);
     void clearDOMCaches();
     bool hasDOMCache(WKStringRef origin);

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (293501 => 293502)


--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2022-04-27 08:21:21 UTC (rev 293501)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2022-04-27 09:10:04 UTC (rev 293502)
@@ -1374,7 +1374,12 @@
         dumpPrivateClickMeasurement();
         return nullptr;
     }
-    
+
+    if (WKStringIsEqualToUTF8CString(messageName, "ClearMemoryCache")) {
+        TestController::singleton().clearMemoryCache();
+        return nullptr;
+    }
+
     if (WKStringIsEqualToUTF8CString(messageName, "ClearPrivateClickMeasurement")) {
         TestController::singleton().clearPrivateClickMeasurement();
         return nullptr;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to