TestController should clear all fetch caches when resetting its state
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Oct 2017 02:14:55 +0000 (02:14 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Oct 2017 02:14:55 +0000 (02:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=178486

Patch by Youenn Fablet <youenn@apple.com> on 2017-10-18
Reviewed by Chris Dumez.

Tools:

Adding clearDOMCaches test runner method.
Using that method when resetting state.

* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::clearDOMCaches):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):

LayoutTests:

* http/tests/cache-storage/cache-clearing-all.https.html:

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

LayoutTests/ChangeLog
LayoutTests/http/tests/cache-storage/cache-clearing-all.https.html
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestController.h
Tools/WebKitTestRunner/TestInvocation.cpp

index d7efc81..ab79988 100644 (file)
@@ -1,3 +1,12 @@
+2017-10-18  Youenn Fablet  <youenn@apple.com>
+
+        TestController should clear all fetch caches when resetting its state
+        https://bugs.webkit.org/show_bug.cgi?id=178486
+
+        Reviewed by Chris Dumez.
+
+        * http/tests/cache-storage/cache-clearing-all.https.html:
+
 2017-10-18  Dean Jackson  <dino@apple.com>
 
         Some older hardware can't actually use renderbuffers at the size they advertise
index f9a14eb..84d6734 100644 (file)
@@ -22,7 +22,7 @@ promise_test(async (test) => {
 
     if (!window.testRunner)
         return Promise.reject("test runner needed");
-    testRunner.clearDOMCache();
+    testRunner.clearDOMCaches();
 
     var keys = await self.caches.keys();
     assert_equals(keys.length, 0, "keys should be empty");
index 7a1a9b7..2b6f47d 100644 (file)
@@ -1,3 +1,20 @@
+2017-10-18  Youenn Fablet  <youenn@apple.com>
+
+        TestController should clear all fetch caches when resetting its state
+        https://bugs.webkit.org/show_bug.cgi?id=178486
+
+        Reviewed by Chris Dumez.
+
+        Adding clearDOMCaches test runner method.
+        Using that method when resetting state.
+
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::clearDOMCaches):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
+
 2017-10-18  Chelsea Pugh  <cpugh@apple.com>
 
         [iOS] Use new class name from UIKit when checking UITextSuggestion type
index d178fec..2ddc0be 100644 (file)
@@ -57,6 +57,7 @@ interface TestRunner {
     void dumpDOMAsWebArchive();
     void dumpPolicyDelegateCallbacks();
 
+    void clearDOMCaches();
     void clearDOMCache(DOMString origin);
     boolean hasDOMCache(DOMString origin);
     unsigned long domCacheSize(DOMString origin);
index 07239dd..028f82e 100644 (file)
@@ -1834,6 +1834,12 @@ void TestRunner::clearDOMCache(JSStringRef origin)
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
 }
 
+void TestRunner::clearDOMCaches()
+{
+    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("ClearDOMCaches"));
+    WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr);
+}
+
 bool TestRunner::hasDOMCache(JSStringRef origin)
 {
     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("HasDOMCache"));
index 9ff81b6..56a1097 100644 (file)
@@ -164,6 +164,7 @@ public:
     JSValueRef originsWithApplicationCache();
 
     void clearDOMCache(JSStringRef origin);
+    void clearDOMCaches();
     bool hasDOMCache(JSStringRef origin);
     uint64_t domCacheSize(JSStringRef origin);
 
index c221581..fb20495 100644 (file)
@@ -783,6 +783,8 @@ bool TestController::resetStateToConsistentValues(const TestOptions& options)
 
     WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKContextGetWebsiteDataStore(platformContext()));
 
+    clearDOMCaches();
+
     // FIXME: This function should also ensure that there is only one page open.
 
     // Reset the EventSender for each test.
@@ -2322,12 +2324,21 @@ void TestController::clearDOMCache(WKStringRef origin)
     auto websiteDataStore = WKContextGetWebsiteDataStore(platformContext());
     ClearDOMCacheCallbackContext context(*this);
 
-    if (WKStringIsEmpty(origin))
-        WKWebsiteDataStoreRemoveAllFetchCaches(websiteDataStore, &context, clearDOMCacheCallback);
-    else {
-        auto cacheOrigin = adoptWK(WKSecurityOriginCreateFromString(origin));
-        WKWebsiteDataStoreRemoveFetchCacheForOrigin(websiteDataStore, cacheOrigin.get(), &context, clearDOMCacheCallback);
-    }
+    auto cacheOrigin = adoptWK(WKSecurityOriginCreateFromString(origin));
+    WKWebsiteDataStoreRemoveFetchCacheForOrigin(websiteDataStore, cacheOrigin.get(), &context, clearDOMCacheCallback);
+
+    if (!context.done)
+        runUntil(context.done, m_currentInvocation->shortTimeout());
+#endif
+}
+
+void TestController::clearDOMCaches()
+{
+#if PLATFORM(COCOA) && WK_API_ENABLED
+    auto websiteDataStore = WKContextGetWebsiteDataStore(platformContext());
+    ClearDOMCacheCallbackContext context(*this);
+
+    WKWebsiteDataStoreRemoveAllFetchCaches(websiteDataStore, &context, clearDOMCacheCallback);
     if (!context.done)
         runUntil(context.done, m_currentInvocation->shortTimeout());
 #endif
index b46b6b1..b1817d7 100644 (file)
@@ -191,6 +191,7 @@ public:
     void removeAllSessionCredentials();
 
     void clearDOMCache(WKStringRef origin);
+    void clearDOMCaches();
     bool hasDOMCache(WKStringRef origin);
     uint64_t domCacheSize(WKStringRef origin);
 
index cd35a97..d1000dc 100644 (file)
@@ -1210,6 +1210,11 @@ WKRetainPtr<WKTypeRef> TestInvocation::didReceiveSynchronousMessageFromInjectedB
         return nullptr;
     }
 
+    if (WKStringIsEqualToUTF8CString(messageName, "ClearDOMCaches")) {
+        TestController::singleton().clearDOMCaches();
+        return nullptr;
+    }
+
     if (WKStringIsEqualToUTF8CString(messageName, "HasDOMCache")) {
         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
         WKStringRef origin = static_cast<WKStringRef>(messageBody);