Title: [295321] branches/safari-613-branch
Revision
295321
Author
alanc...@apple.com
Date
2022-06-06 19:30:29 -0700 (Mon, 06 Jun 2022)

Log Message

Cherry-pick bf09fd4a06a7. rdar://problem/92033309

    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.

    Canonical link: https://commits.webkit.org/250033@main
    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293502 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-613-branch/LayoutTests/ChangeLog (295320 => 295321)


--- branches/safari-613-branch/LayoutTests/ChangeLog	2022-06-07 02:30:22 UTC (rev 295320)
+++ branches/safari-613-branch/LayoutTests/ChangeLog	2022-06-07 02:30:29 UTC (rev 295321)
@@ -1,3 +1,15 @@
+2022-04-27  Youenn Fablet  <you...@apple.com>
+
+        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-28  Patrick Griffis  <pgrif...@igalia.com>
 
         CSP: Fix mixing strict-dynamic and unsafe-inline policies

Added: branches/safari-613-branch/LayoutTests/http/wpt/fetch/clear-memory-cache-expected.txt (0 => 295321)


--- branches/safari-613-branch/LayoutTests/http/wpt/fetch/clear-memory-cache-expected.txt	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/http/wpt/fetch/clear-memory-cache-expected.txt	2022-06-07 02:30:29 UTC (rev 295321)
@@ -0,0 +1,3 @@
+
+PASS Clear memory cache between fetches
+

Added: branches/safari-613-branch/LayoutTests/http/wpt/fetch/clear-memory-cache.html (0 => 295321)


--- branches/safari-613-branch/LayoutTests/http/wpt/fetch/clear-memory-cache.html	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/http/wpt/fetch/clear-memory-cache.html	2022-06-07 02:30:29 UTC (rev 295321)
@@ -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: branches/safari-613-branch/LayoutTests/http/wpt/fetch/resources/clear-memory-cache.py (0 => 295321)


--- branches/safari-613-branch/LayoutTests/http/wpt/fetch/resources/clear-memory-cache.py	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/http/wpt/fetch/resources/clear-memory-cache.py	2022-06-07 02:30:29 UTC (rev 295321)
@@ -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: branches/safari-613-branch/Source/WebCore/ChangeLog (295320 => 295321)


--- branches/safari-613-branch/Source/WebCore/ChangeLog	2022-06-07 02:30:22 UTC (rev 295320)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog	2022-06-07 02:30:29 UTC (rev 295321)
@@ -1,3 +1,15 @@
+2022-04-27  Youenn Fablet  <you...@apple.com>
+
+        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-28  Alex Christensen  <achristen...@webkit.org>
 
         Use more smart pointers in Element.cpp

Modified: branches/safari-613-branch/Source/WebCore/testing/Internals.cpp (295320 => 295321)


--- branches/safari-613-branch/Source/WebCore/testing/Internals.cpp	2022-06-07 02:30:22 UTC (rev 295320)
+++ branches/safari-613-branch/Source/WebCore/testing/Internals.cpp	2022-06-07 02:30:29 UTC (rev 295321)
@@ -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"
@@ -932,6 +933,7 @@
 void Internals::clearMemoryCache()
 {
     MemoryCache::singleton().evictResources();
+    CrossOriginPreflightResultCache::singleton().clear();
 }
 
 void Internals::pruneMemoryCacheToSize(unsigned size)

Modified: branches/safari-613-branch/Source/WebKit/ChangeLog (295320 => 295321)


--- branches/safari-613-branch/Source/WebKit/ChangeLog	2022-06-07 02:30:22 UTC (rev 295320)
+++ branches/safari-613-branch/Source/WebKit/ChangeLog	2022-06-07 02:30:29 UTC (rev 295321)
@@ -1,3 +1,21 @@
+2022-04-27  Youenn Fablet  <you...@apple.com>
+
+        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-03-17  Kate Cheney  <katherine_che...@apple.com>
 
         Calls to print can result in unresponsive print modal

Modified: branches/safari-613-branch/Source/WebKit/NetworkProcess/NetworkProcess.cpp (295320 => 295321)


--- branches/safari-613-branch/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2022-06-07 02:30:22 UTC (rev 295320)
+++ branches/safari-613-branch/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2022-06-07 02:30:29 UTC (rev 295321)
@@ -67,6 +67,7 @@
 #include "WebsiteDataType.h"
 #include <WebCore/ClientOrigin.h>
 #include <WebCore/CookieJar.h>
+#include <WebCore/CrossOriginPreflightResultCache.h>
 #include <WebCore/DNS.h>
 #include <WebCore/DeprecatedGlobalSettings.h>
 #include <WebCore/DiagnosticLoggingClient.h>
@@ -1560,6 +1561,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] { });
 
@@ -1644,6 +1648,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: branches/safari-613-branch/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp (295320 => 295321)


--- branches/safari-613-branch/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp	2022-06-07 02:30:22 UTC (rev 295320)
+++ branches/safari-613-branch/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp	2022-06-07 02:30:29 UTC (rev 295321)
@@ -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: branches/safari-613-branch/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h (295320 => 295321)


--- branches/safari-613-branch/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h	2022-06-07 02:30:22 UTC (rev 295320)
+++ branches/safari-613-branch/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h	2022-06-07 02:30:29 UTC (rev 295321)
@@ -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: branches/safari-613-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (295320 => 295321)


--- branches/safari-613-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2022-06-07 02:30:22 UTC (rev 295320)
+++ branches/safari-613-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2022-06-07 02:30:29 UTC (rev 295321)
@@ -535,6 +535,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: branches/safari-613-branch/Tools/ChangeLog (295320 => 295321)


--- branches/safari-613-branch/Tools/ChangeLog	2022-06-07 02:30:22 UTC (rev 295320)
+++ branches/safari-613-branch/Tools/ChangeLog	2022-06-07 02:30:29 UTC (rev 295321)
@@ -1,3 +1,20 @@
+2022-04-27  Youenn Fablet  <you...@apple.com>
+
+        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-03-17  Kate Cheney  <katherine_che...@apple.com>
 
         Calls to print can result in unresponsive print modal

Modified: branches/safari-613-branch/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (295320 => 295321)


--- branches/safari-613-branch/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2022-06-07 02:30:22 UTC (rev 295320)
+++ branches/safari-613-branch/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2022-06-07 02:30:29 UTC (rev 295321)
@@ -406,6 +406,8 @@
     undefined cleanUpKeychain(DOMString attrLabel, optional DOMString applicationLabelBase64);
     boolean keyExistsInKeychain(DOMString attrLabel, DOMString applicationLabelBase64);
 
+    undefined clearMemoryCache();
+
     // Private Click Measurement
     undefined clearPrivateClickMeasurement();
     undefined clearPrivateClickMeasurementsThroughWebsiteDataRemoval();

Modified: branches/safari-613-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (295320 => 295321)


--- branches/safari-613-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2022-06-07 02:30:22 UTC (rev 295320)
+++ branches/safari-613-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2022-06-07 02:30:29 UTC (rev 295321)
@@ -2065,6 +2065,11 @@
     postSynchronousPageMessage("DumpPrivateClickMeasurement");
 }
 
+void TestRunner::clearMemoryCache()
+{
+    postSynchronousPageMessage("ClearMemoryCache");
+}
+
 void TestRunner::clearPrivateClickMeasurement()
 {
     postSynchronousPageMessage("ClearPrivateClickMeasurement");

Modified: branches/safari-613-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (295320 => 295321)


--- branches/safari-613-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2022-06-07 02:30:22 UTC (rev 295320)
+++ branches/safari-613-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2022-06-07 02:30:29 UTC (rev 295321)
@@ -522,6 +522,8 @@
 
     unsigned long serverTrustEvaluationCallbackCallsCount();
 
+    void clearMemoryCache();
+
     // Private Click Measurement.
     void dumpPrivateClickMeasurement();
     void clearPrivateClickMeasurement();

Modified: branches/safari-613-branch/Tools/WebKitTestRunner/TestController.cpp (295320 => 295321)


--- branches/safari-613-branch/Tools/WebKitTestRunner/TestController.cpp	2022-06-07 02:30:22 UTC (rev 295320)
+++ branches/safari-613-branch/Tools/WebKitTestRunner/TestController.cpp	2022-06-07 02:30:29 UTC (rev 295321)
@@ -2993,6 +2993,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: branches/safari-613-branch/Tools/WebKitTestRunner/TestController.h (295320 => 295321)


--- branches/safari-613-branch/Tools/WebKitTestRunner/TestController.h	2022-06-07 02:30:22 UTC (rev 295320)
+++ branches/safari-613-branch/Tools/WebKitTestRunner/TestController.h	2022-06-07 02:30:29 UTC (rev 295321)
@@ -294,6 +294,7 @@
 
     void clearServiceWorkerRegistrations();
 
+    void clearMemoryCache();
     void clearDOMCache(WKStringRef origin);
     void clearDOMCaches();
     bool hasDOMCache(WKStringRef origin);

Modified: branches/safari-613-branch/Tools/WebKitTestRunner/TestInvocation.cpp (295320 => 295321)


--- branches/safari-613-branch/Tools/WebKitTestRunner/TestInvocation.cpp	2022-06-07 02:30:22 UTC (rev 295320)
+++ branches/safari-613-branch/Tools/WebKitTestRunner/TestInvocation.cpp	2022-06-07 02:30:29 UTC (rev 295321)
@@ -1360,7 +1360,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
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to