Unreviewed, rolling out r241620.
[WebKit-https.git] / Tools / WebKitTestRunner / cocoa / TestControllerCocoa.mm
index e81dbfc..fe3bd6e 100644 (file)
@@ -31,6 +31,7 @@
 #import "StringFunctions.h"
 #import "TestInvocation.h"
 #import "TestRunnerWKWebView.h"
+#import "TestWebsiteDataStoreDelegate.h"
 #import <Foundation/Foundation.h>
 #import <Security/SecItem.h>
 #import <WebKit/WKContextConfigurationRef.h>
@@ -55,6 +56,10 @@ namespace WTR {
 
 static WKWebViewConfiguration *globalWebViewConfiguration;
 
+#if WK_API_ENABLED
+static TestWebsiteDataStoreDelegate *globalWebsiteDataStoreDelegateClient;
+#endif
+
 void initializeWebViewConfiguration(const char* libraryPath, WKStringRef injectedBundlePath, WKContextRef context, WKContextConfigurationRef contextConfiguration)
 {
 #if WK_API_ENABLED
@@ -69,7 +74,6 @@ void initializeWebViewConfiguration(const char* libraryPath, WKStringRef injecte
     WKCookieManagerSetStorageAccessAPIEnabled(WKContextGetCookieManager(context), true);
 
     WKWebsiteDataStore* poolWebsiteDataStore = (__bridge WKWebsiteDataStore *)WKContextGetWebsiteDataStore((__bridge WKContextRef)globalWebViewConfiguration.processPool);
-    [poolWebsiteDataStore _setCacheStoragePerOriginQuota: 400 * 1024];
     if (libraryPath) {
         String cacheStorageDirectory = String(libraryPath) + '/' + "CacheStorage";
         [poolWebsiteDataStore _setCacheStorageDirectory: cacheStorageDirectory];
@@ -81,6 +85,12 @@ void initializeWebViewConfiguration(const char* libraryPath, WKStringRef injecte
     [globalWebViewConfiguration.websiteDataStore _setResourceLoadStatisticsEnabled:YES];
     [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetShouldSubmitTelemetry:NO];
 
+#if WK_API_ENABLED
+    [globalWebsiteDataStoreDelegateClient release];
+    globalWebsiteDataStoreDelegateClient = [[TestWebsiteDataStoreDelegate alloc] init];
+    [globalWebViewConfiguration.websiteDataStore set_delegate:globalWebsiteDataStoreDelegateClient];
+#endif
+
 #if PLATFORM(IOS_FAMILY)
     globalWebViewConfiguration.allowsInlineMediaPlayback = YES;
     globalWebViewConfiguration._inlineMediaPlaybackRequiresPlaysInlineAttribute = NO;
@@ -154,10 +164,16 @@ void TestController::platformCreateWebView(WKPageConfigurationRef, const TestOpt
 #endif
 
     if (options.enableAttachmentElement)
-        [copiedConfiguration _setAttachmentElementEnabled: YES];
+        [copiedConfiguration _setAttachmentElementEnabled:YES];
 
     if (options.enableColorFilter)
-        [copiedConfiguration _setColorFilterEnabled: YES];
+        [copiedConfiguration _setColorFilterEnabled:YES];
+
+    if (options.enableEditableImages)
+        [copiedConfiguration _setEditableImagesEnabled:YES];
+
+    if (options.enableUndoManagerAPI)
+        [copiedConfiguration _setUndoManagerAPIEnabled:YES];
 
     if (options.applicationManifest.length()) {
         auto manifestPath = [NSString stringWithUTF8String:options.applicationManifest.c_str()];
@@ -169,6 +185,9 @@ void TestController::platformCreateWebView(WKPageConfigurationRef, const TestOpt
 
     if (options.punchOutWhiteBackgroundsInDarkMode)
         m_mainWebView->setDrawsBackground(false);
+
+    if (options.editable)
+        m_mainWebView->setEditable(true);
 #else
     m_mainWebView = std::make_unique<PlatformWebView>(globalWebViewConfiguration, options);
 #endif
@@ -203,17 +222,6 @@ void TestController::platformRunUntil(bool& done, WTF::Seconds timeout)
         [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:endDate];
 }
 
-ClassMethodSwizzler::ClassMethodSwizzler(Class cls, SEL originalSelector, IMP implementation)
-    : m_method(class_getClassMethod(objc_getMetaClass(NSStringFromClass(cls).UTF8String), originalSelector))
-    , m_originalImplementation(method_setImplementation(m_method, implementation))
-{
-}
-
-ClassMethodSwizzler::~ClassMethodSwizzler()
-{
-    method_setImplementation(m_method, m_originalImplementation);
-}
-    
 static NSCalendar *swizzledCalendar()
 {
     return [NSCalendar calendarWithIdentifier:TestController::singleton().getOverriddenCalendarIdentifier().get()];
@@ -230,8 +238,8 @@ void TestController::setDefaultCalendarType(NSString *identifier)
     if (!m_calendarSwizzler)
         m_calendarSwizzler = std::make_unique<ClassMethodSwizzler>([NSCalendar class], @selector(currentCalendar), reinterpret_cast<IMP>(swizzledCalendar));
 }
-    
-void TestController::cocoaResetStateToConsistentValues(const TestOptions& options)
+
+void TestController::resetContentExtensions()
 {
 #if WK_API_ENABLED
     __block bool doneRemoving = false;
@@ -241,19 +249,30 @@ void TestController::cocoaResetStateToConsistentValues(const TestOptions& option
     platformRunUntil(doneRemoving, noTimeout);
     [[_WKUserContentExtensionStore defaultStore] _removeAllContentExtensions];
 
+    if (auto* webView = mainWebView()) {
+        TestRunnerWKWebView *platformView = webView->platformView();
+        [platformView.configuration.userContentController _removeAllUserContentFilters];
+    }
+#endif
+}
 
+void TestController::cocoaResetStateToConsistentValues(const TestOptions& options)
+{
+#if WK_API_ENABLED
     m_calendarSwizzler = nullptr;
     m_overriddenCalendarIdentifier = nil;
     
     if (auto* webView = mainWebView()) {
         TestRunnerWKWebView *platformView = webView->platformView();
-        [platformView.configuration.userContentController _removeAllUserContentFilters];
         platformView._viewScale = 1;
+        platformView._minimumEffectiveDeviceWidth = 0;
 
         // Toggle on before the test, and toggle off after the test.
         if (options.shouldShowSpellCheckingDots)
             [platformView toggleContinuousSpellChecking:nil];
     }
+
+    [globalWebsiteDataStoreDelegateClient setAllowRaisingQuota: false];
 #endif
 }
 
@@ -387,23 +406,29 @@ bool TestController::keyExistsInKeychain(const String& attrLabel, const String&
     return false;
 }
 
-#if PLATFORM(MAC)
-void TestController::toggleCapsLock()
+void TestController::allowCacheStorageQuotaIncrease()
 {
-    m_capsLockOn = !m_capsLockOn;
-    NSEvent *fakeEvent = [NSEvent keyEventWithType:NSEventTypeFlagsChanged
-        location:NSZeroPoint
-        modifierFlags:m_capsLockOn ? NSEventModifierFlagCapsLock : 0
-        timestamp:0
-        windowNumber:[mainWebView()->platformWindow() windowNumber]
-        context:nullptr
-        characters:@""
-        charactersIgnoringModifiers:@""
-        isARepeat:NO
-        keyCode:57];
-    
-    [mainWebView()->platformWindow() sendEvent:fakeEvent];
+#if WK_API_ENABLED
+    [globalWebsiteDataStoreDelegateClient setAllowRaisingQuota: true];
+#endif
+}
+
+bool TestController::canDoServerTrustEvaluationInNetworkProcess() const
+{
+#if HAVE(CFNETWORK_NSURLSESSION_STRICTRUSTEVALUATE)
+    return true;
+#else
+    return false;
+#endif
 }
+
+bool TestController::isDoingMediaCapture() const
+{
+#if WK_API_ENABLED
+    return m_mainWebView->platformView()._mediaCaptureState != _WKMediaCaptureStateNone;
+#else
+    return false;
 #endif
+}
 
 } // namespace WTR