Title: [261758] trunk/Tools
Revision
261758
Author
[email protected]
Date
2020-05-15 13:50:18 -0700 (Fri, 15 May 2020)

Log Message

Make sure we use current data store in WKTR's TestController
https://bugs.webkit.org/show_bug.cgi?id=211920

Reviewed by Alex Christensen.

Make sure we use current data store in WKTR's TestController. Currently, a lot of code
uses defaultDataStore(), even though the test may be using another data store (e.g. an
ephemeral one). I suspect this is contributing to test flakiness.

We now also make sure that TestController::websiteDataStore() returns the actual store
that will be used by the test when resetPreferencesToConsistentValues() is called.
Previously, it would not since it would get the store from the m_mainView and m_mainView
would only get initialized after calling resetPreferencesToConsistentValues(). To support
this, we now initialize a m_websiteDataStore member in platformInitializeDataStore(),
which gets called right before resetPreferencesToConsistentValues(). When
platformCreateWebView() gets called right after resetPreferencesToConsistentValues(),
it now simply relies on m_websiteDataStore instead of creating the data store at this
point.

* WebKitTestRunner/TestController.cpp:
(WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle):
(WTR::TestController::clearServiceWorkerRegistrations):
(WTR::TestController::clearDOMCache):
(WTR::TestController::clearDOMCaches):
(WTR::TestController::hasDOMCache):
(WTR::TestController::domCacheSize):
(WTR::TestController::clearStatisticsDataForDomain):
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::invoke):
(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (261757 => 261758)


--- trunk/Tools/ChangeLog	2020-05-15 20:42:09 UTC (rev 261757)
+++ trunk/Tools/ChangeLog	2020-05-15 20:50:18 UTC (rev 261758)
@@ -1,3 +1,36 @@
+2020-05-15  Chris Dumez  <[email protected]>
+
+        Make sure we use current data store in WKTR's TestController
+        https://bugs.webkit.org/show_bug.cgi?id=211920
+
+        Reviewed by Alex Christensen.
+
+        Make sure we use current data store in WKTR's TestController. Currently, a lot of code
+        uses defaultDataStore(), even though the test may be using another data store (e.g. an
+        ephemeral one). I suspect this is contributing to test flakiness.
+
+        We now also make sure that TestController::websiteDataStore() returns the actual store
+        that will be used by the test when resetPreferencesToConsistentValues() is called.
+        Previously, it would not since it would get the store from the m_mainView and m_mainView
+        would only get initialized after calling resetPreferencesToConsistentValues(). To support
+        this, we now initialize a m_websiteDataStore member in platformInitializeDataStore(),
+        which gets called right before resetPreferencesToConsistentValues(). When
+        platformCreateWebView() gets called right after resetPreferencesToConsistentValues(),
+        it now simply relies on m_websiteDataStore instead of creating the data store at this
+        point.
+
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle):
+        (WTR::TestController::clearServiceWorkerRegistrations):
+        (WTR::TestController::clearDOMCache):
+        (WTR::TestController::clearDOMCaches):
+        (WTR::TestController::hasDOMCache):
+        (WTR::TestController::domCacheSize):
+        (WTR::TestController::clearStatisticsDataForDomain):
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::invoke):
+        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
+
 2020-05-15  Diego Pino Garcia  <[email protected]>
 
         [buildbot] Increase blocksize of file transfer in UploadTestResults step

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (261757 => 261758)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2020-05-15 20:42:09 UTC (rev 261757)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2020-05-15 20:50:18 UTC (rev 261758)
@@ -556,7 +556,7 @@
 
 WKWebsiteDataStoreRef TestController::websiteDataStore()
 {
-    return WKPageConfigurationGetWebsiteDataStore(adoptWK(WKPageCopyPageConfiguration(m_mainWebView->page())).get());
+    return m_websiteDataStore.get();
 }
 
 WKRetainPtr<WKPageConfigurationRef> TestController::generatePageConfiguration(const TestOptions& options)
@@ -650,6 +650,7 @@
 #endif
 
     auto configuration = generatePageConfiguration(options);
+    platformInitializeDataStore(configuration.get(), options);
 
     // Some preferences (notably mock scroll bars setting) currently cannot be re-applied to an existing view, so we need to set them now.
     // FIXME: Migrate these preferences to WKContextConfigurationRef.
@@ -941,7 +942,7 @@
     WKPreferencesSetBeaconAPIEnabled(preferences, true);
     WKPreferencesSetDirectoryUploadEnabled(preferences, true);
 
-    WKHTTPCookieStoreDeleteAllCookies(WKWebsiteDataStoreGetHTTPCookieStore(TestController::defaultWebsiteDataStore()), nullptr, nullptr);
+    WKHTTPCookieStoreDeleteAllCookies(WKWebsiteDataStoreGetHTTPCookieStore(websiteDataStore()), nullptr, nullptr);
 
     WKPreferencesSetMockCaptureDevicesEnabled(preferences, true);
     
@@ -1028,7 +1029,6 @@
     WKContextResetServiceWorkerFetchTimeoutForTesting(TestController::singleton().context());
 
     WKWebsiteDataStoreClearAllDeviceOrientationPermissions(websiteDataStore());
-    WKWebsiteDataStoreClearAllDeviceOrientationPermissions(TestController::defaultWebsiteDataStore());
 
     clearIndexedDatabases();
     clearLocalStorage();
@@ -2233,7 +2233,7 @@
 
     auto setHTTPCookieAcceptPolicy = [&] (WKHTTPCookieAcceptPolicy policy, CompletionHandler<void(WKTypeRef)>&& completionHandler) {
         auto context = new CompletionHandler<void(WKTypeRef)>(WTFMove(completionHandler));
-        WKHTTPCookieStoreSetHTTPCookieAcceptPolicy(WKWebsiteDataStoreGetHTTPCookieStore(TestController::defaultWebsiteDataStore()), policy, context, [] (void* context) {
+        WKHTTPCookieStoreSetHTTPCookieAcceptPolicy(WKWebsiteDataStoreGetHTTPCookieStore(websiteDataStore()), policy, context, [] (void* context) {
             auto completionHandlerPointer = static_cast<CompletionHandler<void(WKTypeRef)>*>(context);
             (*completionHandlerPointer)(nullptr);
             delete completionHandlerPointer;
@@ -3116,6 +3116,11 @@
 {
 }
 
+void TestController::platformInitializeDataStore(WKPageConfigurationRef configuration, const TestOptions&)
+{
+    m_websiteDataStore = WKPageConfigurationGetWebsiteDataStore(configuration);
+}
+
 void TestController::platformCreateWebView(WKPageConfigurationRef configuration, const TestOptions& options)
 {
     m_mainWebView = makeUnique<PlatformWebView>(configuration, options);
@@ -3217,7 +3222,7 @@
 {
     ClearServiceWorkerRegistrationsCallbackContext context(*this);
 
-    WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(TestController::defaultWebsiteDataStore(), &context, clearServiceWorkerRegistrationsCallback);
+    WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(websiteDataStore(), &context, clearServiceWorkerRegistrationsCallback);
     runUntil(context.done, noTimeout);
 }
 
@@ -3243,7 +3248,7 @@
     ClearDOMCacheCallbackContext context(*this);
 
     auto cacheOrigin = adoptWK(WKSecurityOriginCreateFromString(origin));
-    WKWebsiteDataStoreRemoveFetchCacheForOrigin(TestController::defaultWebsiteDataStore(), cacheOrigin.get(), &context, clearDOMCacheCallback);
+    WKWebsiteDataStoreRemoveFetchCacheForOrigin(websiteDataStore(), cacheOrigin.get(), &context, clearDOMCacheCallback);
     runUntil(context.done, noTimeout);
 }
 
@@ -3251,7 +3256,7 @@
 {
     ClearDOMCacheCallbackContext context(*this);
 
-    WKWebsiteDataStoreRemoveAllFetchCaches(TestController::defaultWebsiteDataStore(), &context, clearDOMCacheCallback);
+    WKWebsiteDataStoreRemoveAllFetchCaches(websiteDataStore(), &context, clearDOMCacheCallback);
     runUntil(context.done, noTimeout);
 }
 
@@ -3335,7 +3340,7 @@
 bool TestController::hasDOMCache(WKStringRef origin)
 {
     FetchCacheOriginsCallbackContext context(*this, origin);
-    WKWebsiteDataStoreGetFetchCacheOrigins(TestController::defaultWebsiteDataStore(), &context, fetchCacheOriginsCallback);
+    WKWebsiteDataStoreGetFetchCacheOrigins(websiteDataStore(), &context, fetchCacheOriginsCallback);
     runUntil(context.done, noTimeout);
     return context.result;
 }
@@ -3363,7 +3368,7 @@
 uint64_t TestController::domCacheSize(WKStringRef origin)
 {
     FetchCacheSizeForOriginCallbackContext context(*this);
-    WKWebsiteDataStoreGetFetchCacheSizeForOrigin(TestController::defaultWebsiteDataStore(), origin, &context, fetchCacheSizeForOriginCallback);
+    WKWebsiteDataStoreGetFetchCacheSizeForOrigin(websiteDataStore(), origin, &context, fetchCacheSizeForOriginCallback);
     runUntil(context.done, noTimeout);
     return context.result;
 }
@@ -3420,7 +3425,7 @@
 {
     ResourceStatisticsCallbackContext context(*this);
 
-    WKWebsiteDataStoreRemoveITPDataForDomain(TestController::defaultWebsiteDataStore(), domain, &context, resourceStatisticsVoidResultCallback);
+    WKWebsiteDataStoreRemoveITPDataForDomain(websiteDataStore(), domain, &context, resourceStatisticsVoidResultCallback);
     runUntil(context.done, noTimeout);
 }
 

Modified: trunk/Tools/WebKitTestRunner/TestController.h (261757 => 261758)


--- trunk/Tools/WebKitTestRunner/TestController.h	2020-05-15 20:42:09 UTC (rev 261757)
+++ trunk/Tools/WebKitTestRunner/TestController.h	2020-05-15 20:50:18 UTC (rev 261758)
@@ -371,6 +371,7 @@
     bool handleControlCommand(const char* command);
 
     void platformInitialize();
+    void platformInitializeDataStore(WKPageConfigurationRef, const TestOptions&);
     void platformDestroy();
     WKContextRef platformAdjustContext(WKContextRef, WKContextConfigurationRef);
     void platformInitializeContext();
@@ -623,6 +624,7 @@
 #endif
 
     std::unique_ptr<EventSenderProxy> m_eventSenderProxy;
+    WKRetainPtr<WKWebsiteDataStoreRef> m_websiteDataStore;
 
     WorkQueueManager m_workQueueManager;
 

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (261757 => 261758)


--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2020-05-15 20:42:09 UTC (rev 261757)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2020-05-15 20:50:18 UTC (rev 261758)
@@ -164,7 +164,7 @@
 
     TestController::singleton().setShouldLogHistoryClientCallbacks(shouldLogHistoryClientCallbacks());
 
-    WKHTTPCookieStoreSetHTTPCookieAcceptPolicy(WKWebsiteDataStoreGetHTTPCookieStore(TestController::defaultWebsiteDataStore()), kWKHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain, nullptr, nullptr);
+    WKHTTPCookieStoreSetHTTPCookieAcceptPolicy(WKWebsiteDataStoreGetHTTPCookieStore(TestController::singleton().websiteDataStore()), kWKHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain, nullptr, nullptr);
 
     // FIXME: We should clear out visited links here.
 
@@ -1082,7 +1082,7 @@
     if (WKStringIsEqualToUTF8CString(messageName, "SetCacheModel")) {
         ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
         uint64_t model = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody));
-        WKWebsiteDataStoreSetCacheModelSynchronouslyForTesting(TestController::defaultWebsiteDataStore(), model);
+        WKWebsiteDataStoreSetCacheModelSynchronouslyForTesting(TestController::singleton().websiteDataStore(), model);
         return nullptr;
     }
 
@@ -1139,7 +1139,7 @@
     }
     
     if (WKStringIsEqualToUTF8CString(messageName, "DeleteAllIndexedDatabases")) {
-        WKWebsiteDataStoreRemoveAllIndexedDatabases(TestController::defaultWebsiteDataStore(), nullptr, { });
+        WKWebsiteDataStoreRemoveAllIndexedDatabases(TestController::singleton().websiteDataStore(), nullptr, { });
         return nullptr;
     }
 

Modified: trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm (261757 => 261758)


--- trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm	2020-05-15 20:42:09 UTC (rev 261757)
+++ trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm	2020-05-15 20:50:18 UTC (rev 261758)
@@ -131,6 +131,21 @@
 #endif
 }
 
+void TestController::platformInitializeDataStore(WKPageConfigurationRef, const TestOptions& options)
+{
+    if (options.useEphemeralSession || options.standaloneWebApplicationURL.length()) {
+        auto websiteDataStoreConfig = options.useEphemeralSession ? [[[_WKWebsiteDataStoreConfiguration alloc] initNonPersistentConfiguration] autorelease] : [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease];
+        if (!options.useEphemeralSession)
+            configureWebsiteDataStoreTemporaryDirectories((WKWebsiteDataStoreConfigurationRef)websiteDataStoreConfig);
+        if (options.standaloneWebApplicationURL.length())
+            [websiteDataStoreConfig setStandaloneApplicationURL:[NSURL URLWithString:[NSString stringWithUTF8String:options.standaloneWebApplicationURL.c_str()]]];
+        auto *websiteDataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfig] autorelease];
+        [websiteDataStore _setResourceLoadStatisticsEnabled:YES];
+        m_websiteDataStore = (__bridge WKWebsiteDataStoreRef)websiteDataStore;
+    } else
+        m_websiteDataStore = (__bridge WKWebsiteDataStoreRef)globalWebViewConfiguration.websiteDataStore;
+}
+
 void TestController::platformCreateWebView(WKPageConfigurationRef, const TestOptions& options)
 {
     RetainPtr<WKWebViewConfiguration> copiedConfiguration = adoptNS([globalWebViewConfiguration copy]);
@@ -157,16 +172,7 @@
     if (options.enableEditableImages)
         [copiedConfiguration _setEditableImagesEnabled:YES];
 
-    if (options.useEphemeralSession || options.standaloneWebApplicationURL.length()) {
-        auto websiteDataStoreConfig = options.useEphemeralSession ? [[[_WKWebsiteDataStoreConfiguration alloc] initNonPersistentConfiguration] autorelease] : [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease];
-        if (!options.useEphemeralSession)
-            configureWebsiteDataStoreTemporaryDirectories((WKWebsiteDataStoreConfigurationRef)websiteDataStoreConfig);
-        if (options.standaloneWebApplicationURL.length())
-            [websiteDataStoreConfig setStandaloneApplicationURL:[NSURL URLWithString:[NSString stringWithUTF8String:options.standaloneWebApplicationURL.c_str()]]];
-        auto websiteDataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfig] autorelease];
-        [websiteDataStore _setResourceLoadStatisticsEnabled:YES];
-        [copiedConfiguration setWebsiteDataStore:websiteDataStore];
-    }
+    [copiedConfiguration setWebsiteDataStore:(WKWebsiteDataStore *)websiteDataStore()];
 
     [copiedConfiguration _setAllowTopNavigationToDataURLs:options.allowTopNavigationToDataURLs];
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to