Title: [269105] trunk
Revision
269105
Author
[email protected]
Date
2020-10-28 08:57:35 -0700 (Wed, 28 Oct 2020)

Log Message

[Testing] Remove requirement of adding new SPI for each preference that needs testing
https://bugs.webkit.org/show_bug.cgi?id=218267

Reviewed by Simon Fraser.

Source/WebKitLegacy/mac:

Expose a set of setters to for DumpRenderTree to use when setting preferences
by string.

* WebView/WebPreferences.mm:
(-[WebPreferences _setBoolPreferenceForTestingWithValue:forKey:]):
(-[WebPreferences _setUInt32PreferenceForTestingWithValue:forKey:]):
(-[WebPreferences _setDoublePreferenceForTestingWithValue:forKey:]):
(-[WebPreferences _setStringPreferenceForTestingWithValue:forKey:]):
* WebView/WebPreferencesPrivate.h:

Tools:

Removes the requirement for WebKitLegacy (macOS), which has already been lifted for
modern WebKit, that testing new preferences requires new WebPreferences SPI. Instead,
new testing specific SPI ([WebPreferences _set*PreferenceForTestingWithValue:forKey:])
are used to allow string based setting.

To make this work with the shared WebPreferences*.yaml names, a helper is generated to
map from the shared name to the WebKitLegacy specific name.

This still doesn't quite take us all the way to supporting any WebPreferences*.yaml name
in test headers, as is supported in WebKitTestRunner, as we still need a viable mechanism
to fully reset WebPreferences between tests. Right now, each preference must be set on
each test run, requiring the complete set of preferences to be known up front.

* DumpRenderTree/CMakeLists.txt:
* DumpRenderTree/DerivedSources-input.xcfilelist:
* DumpRenderTree/DerivedSources-output.xcfilelist:
* DumpRenderTree/DerivedSources.make:
* DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
* DumpRenderTree/Scripts/PreferencesTemplates/TestOptionsGeneratedWebKitLegacyKeyMapping.cpp.erb: Added.
* DumpRenderTree/TestOptions.cpp:
(WTR::TestOptions::supportedBoolWebPreferenceFeatures):
* DumpRenderTree/TestOptions.h:
* DumpRenderTree/mac/DumpRenderTree.mm:
(setWebPreferencesForTestOptions):
* DumpRenderTree/mac/TestRunnerMac.mm:
(TestRunner::overridePreference):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (269104 => 269105)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2020-10-28 15:28:14 UTC (rev 269104)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2020-10-28 15:57:35 UTC (rev 269105)
@@ -1,3 +1,20 @@
+2020-10-28  Sam Weinig  <[email protected]>
+
+        [Testing] Remove requirement of adding new SPI for each preference that needs testing
+        https://bugs.webkit.org/show_bug.cgi?id=218267
+
+        Reviewed by Simon Fraser.
+
+        Expose a set of setters to for DumpRenderTree to use when setting preferences
+        by string.
+
+        * WebView/WebPreferences.mm:
+        (-[WebPreferences _setBoolPreferenceForTestingWithValue:forKey:]):
+        (-[WebPreferences _setUInt32PreferenceForTestingWithValue:forKey:]):
+        (-[WebPreferences _setDoublePreferenceForTestingWithValue:forKey:]):
+        (-[WebPreferences _setStringPreferenceForTestingWithValue:forKey:]):
+        * WebView/WebPreferencesPrivate.h:
+
 2020-10-27  Tetsuharu Ohzeki  <[email protected]>
 
         Make WebCore::FocusDirection to enum class

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebPreferences.mm (269104 => 269105)


--- trunk/Source/WebKitLegacy/mac/WebView/WebPreferences.mm	2020-10-28 15:28:14 UTC (rev 269104)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebPreferences.mm	2020-10-28 15:57:35 UTC (rev 269105)
@@ -1660,26 +1660,6 @@
     [old release];
 }
 
-+ (void)_switchNetworkLoaderToNewTestingSession
-{
-#if PLATFORM(IOS_FAMILY)
-    WebThreadLock();
-#endif
-    NetworkStorageSessionMap::switchToNewTestingSession();
-}
-
-+ (void)_clearNetworkLoaderSession
-{
-    NetworkStorageSessionMap::defaultStorageSession().deleteAllCookies();
-}
-
-+ (void)_setCurrentNetworkLoaderSessionCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)policy
-{
-    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = NetworkStorageSessionMap::defaultStorageSession().cookieStorage();
-    ASSERT(cookieStorage); // Will fail when NetworkStorageSessionMap::switchToNewTestingSession() was not called beforehand.
-    CFHTTPCookieStorageSetCookieAcceptPolicy(cookieStorage.get(), policy);
-}
-
 - (BOOL)isDOMPasteAllowed
 {
     return [self _boolValueForKey:WebKitDOMPasteAllowedPreferenceKey];
@@ -1956,11 +1936,6 @@
     ++_private->numWebViews;
 }
 
-- (void)_setPreferenceForTestWithValue:(NSString *)value forKey:(NSString *)key
-{
-    [self _setStringValue:value forKey:key];
-}
-
 - (void)setFullScreenEnabled:(BOOL)flag
 {
     [self _setBoolValue:flag forKey:WebKitFullScreenEnabledPreferenceKey];
@@ -3003,6 +2978,50 @@
 
 @end
 
+@implementation WebPreferences (WebPrivateTesting)
+
++ (void)_switchNetworkLoaderToNewTestingSession
+{
+#if PLATFORM(IOS_FAMILY)
+    WebThreadLock();
+#endif
+    NetworkStorageSessionMap::switchToNewTestingSession();
+}
+
++ (void)_setCurrentNetworkLoaderSessionCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)policy
+{
+    auto cookieStorage = NetworkStorageSessionMap::defaultStorageSession().cookieStorage();
+    RELEASE_ASSERT(cookieStorage); // Will fail when NetworkStorageSessionMap::switchToNewTestingSession() was not called beforehand.
+    CFHTTPCookieStorageSetCookieAcceptPolicy(cookieStorage.get(), policy);
+}
+
++ (void)_clearNetworkLoaderSession
+{
+    NetworkStorageSessionMap::defaultStorageSession().deleteAllCookies();
+}
+
+- (void)_setBoolPreferenceForTestingWithValue:(BOOL)value forKey:(NSString *)key
+{
+    [self _setBoolValue:value forKey:key];
+}
+
+- (void)_setUInt32PreferenceForTestingWithValue:(uint32_t)value forKey:(NSString *)key
+{
+    [self _setIntegerValue:value forKey:key];
+}
+
+- (void)_setDoublePreferenceForTestingWithValue:(double)value forKey:(NSString *)key
+{
+    [self _setFloatValue:value forKey:key];
+}
+
+- (void)_setStringPreferenceForTestingWithValue:(NSString *)value forKey:(NSString *)key
+{
+    [self _setStringValue:value forKey:key];
+}
+
+@end
+
 @implementation WebPreferences (WebPrivatePreferencesConvertedToWebFeature)
 
 - (BOOL)userGesturePromisePropagationEnabled

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebPreferencesPrivate.h (269104 => 269105)


--- trunk/Source/WebKitLegacy/mac/WebView/WebPreferencesPrivate.h	2020-10-28 15:28:14 UTC (rev 269104)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebPreferencesPrivate.h	2020-10-28 15:57:35 UTC (rev 269105)
@@ -89,13 +89,6 @@
 + (void)_setInitialDefaultTextEncodingToSystemEncoding;
 + (void)_setIBCreatorID:(NSString *)string;
 
-// For DumpRenderTree use only.
-+ (void)_switchNetworkLoaderToNewTestingSession;
-+ (void)_setCurrentNetworkLoaderSessionCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)cookieAcceptPolicy;
-+ (void)_clearNetworkLoaderSession;
-// Used to set preference specified in the test via LayoutTestController.overridePreference(..).
-- (void)_setPreferenceForTestWithValue:(NSString *)value forKey:(NSString *)key;
-
 + (void)setWebKitLinkTimeVersion:(int)version;
 
 // For WebView's use only.
@@ -309,6 +302,17 @@
 - (void)_setEnabled:(BOOL)value forFeature:(WebFeature *)feature;
 @end
 
+@interface WebPreferences (WebPrivateTesting)
++ (void)_switchNetworkLoaderToNewTestingSession;
++ (void)_setCurrentNetworkLoaderSessionCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)cookieAcceptPolicy;
++ (void)_clearNetworkLoaderSession;
+
+- (void)_setBoolPreferenceForTestingWithValue:(BOOL)value forKey:(NSString *)key;
+- (void)_setUInt32PreferenceForTestingWithValue:(uint32_t)value forKey:(NSString *)key;
+- (void)_setDoublePreferenceForTestingWithValue:(double)value forKey:(NSString *)key;
+- (void)_setStringPreferenceForTestingWithValue:(NSString *)value forKey:(NSString *)key;
+@end
+
 // FIXME: If these are not used anywhere, we should remove them and only use WebFeature mechanism for the preference.
 @interface WebPreferences (WebPrivatePreferencesConvertedToWebFeature)
 @property (nonatomic) BOOL userGesturePromisePropagationEnabled;

Modified: trunk/Tools/ChangeLog (269104 => 269105)


--- trunk/Tools/ChangeLog	2020-10-28 15:28:14 UTC (rev 269104)
+++ trunk/Tools/ChangeLog	2020-10-28 15:57:35 UTC (rev 269105)
@@ -1,3 +1,37 @@
+2020-10-28  Sam Weinig  <[email protected]>
+
+        [Testing] Remove requirement of adding new SPI for each preference that needs testing
+        https://bugs.webkit.org/show_bug.cgi?id=218267
+
+        Reviewed by Simon Fraser.
+
+        Removes the requirement for WebKitLegacy (macOS), which has already been lifted for
+        modern WebKit, that testing new preferences requires new WebPreferences SPI. Instead,
+        new testing specific SPI ([WebPreferences _set*PreferenceForTestingWithValue:forKey:])
+        are used to allow string based setting.
+        
+        To make this work with the shared WebPreferences*.yaml names, a helper is generated to
+        map from the shared name to the WebKitLegacy specific name.
+
+        This still doesn't quite take us all the way to supporting any WebPreferences*.yaml name
+        in test headers, as is supported in WebKitTestRunner, as we still need a viable mechanism
+        to fully reset WebPreferences between tests. Right now, each preference must be set on
+        each test run, requiring the complete set of preferences to be known up front.
+
+        * DumpRenderTree/CMakeLists.txt:
+        * DumpRenderTree/DerivedSources-input.xcfilelist:
+        * DumpRenderTree/DerivedSources-output.xcfilelist:
+        * DumpRenderTree/DerivedSources.make:
+        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
+        * DumpRenderTree/Scripts/PreferencesTemplates/TestOptionsGeneratedWebKitLegacyKeyMapping.cpp.erb: Added.
+        * DumpRenderTree/TestOptions.cpp:
+        (WTR::TestOptions::supportedBoolWebPreferenceFeatures):
+        * DumpRenderTree/TestOptions.h:
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (setWebPreferencesForTestOptions):
+        * DumpRenderTree/mac/TestRunnerMac.mm:
+        (TestRunner::overridePreference):
+
 2020-10-28  Philippe Normand  <[email protected]>
 
         [Flatpak SDK] Update Mesa and GTK4 dependencies

Modified: trunk/Tools/DumpRenderTree/CMakeLists.txt (269104 => 269105)


--- trunk/Tools/DumpRenderTree/CMakeLists.txt	2020-10-28 15:28:14 UTC (rev 269104)
+++ trunk/Tools/DumpRenderTree/CMakeLists.txt	2020-10-28 15:57:35 UTC (rev 269105)
@@ -40,6 +40,7 @@
 )
 
 set(DumpRenderTree_WEB_PREFERENCES_TEMPLATES
+    ${DumpRenderTree_DIR}/Scripts/PreferencesTemplates/TestOptionsGeneratedWebKitLegacyKeyMapping.cpp.erb
     ${DumpRenderTree_DIR}/Scripts/PreferencesTemplates/TestOptionsGeneratedKeys.h.erb
 )
 
@@ -53,12 +54,13 @@
 set_source_files_properties(${DumpRenderTree_WEB_PREFERENCES} PROPERTIES GENERATED TRUE)
 
 add_custom_command(
-    OUTPUT ${DumpRenderTree_DERIVED_SOURCES_DIR}/TestOptionsGeneratedKeys.h
+    OUTPUT ${DumpRenderTree_DERIVED_SOURCES_DIR}/TestOptionsGeneratedWebKitLegacyKeyMapping.cpp ${DumpRenderTree_DERIVED_SOURCES_DIR}/TestOptionsGeneratedKeys.h
     DEPENDS ${DumpRenderTree_WEB_PREFERENCES_TEMPLATES} ${DumpRenderTree_WEB_PREFERENCES} WTF_CopyPreferences
-    COMMAND ${RUBY_EXECUTABLE} ${WTF_SCRIPTS_DIR}/GeneratePreferences.rb --frontend WebKitLegacy --base ${WTF_SCRIPTS_DIR}/Preferences/WebPreferences.yaml --debug ${WTF_SCRIPTS_DIR}/Preferences/WebPreferencesDebug.yaml --experimental ${WTF_SCRIPTS_DIR}/Preferences/WebPreferencesExperimental.yaml --internal ${WTF_SCRIPTS_DIR}/Preferences/WebPreferencesInternal.yaml --outputDir "${DumpRenderTree_DERIVED_SOURCES_DIR}" --template ${DumpRenderTree_DIR}/Scripts/PreferencesTemplates/TestOptionsGeneratedKeys.h.erb
+    COMMAND ${RUBY_EXECUTABLE} ${WTF_SCRIPTS_DIR}/GeneratePreferences.rb --frontend WebKitLegacy --base ${WTF_SCRIPTS_DIR}/Preferences/WebPreferences.yaml --debug ${WTF_SCRIPTS_DIR}/Preferences/WebPreferencesDebug.yaml --experimental ${WTF_SCRIPTS_DIR}/Preferences/WebPreferencesExperimental.yaml --internal ${WTF_SCRIPTS_DIR}/Preferences/WebPreferencesInternal.yaml --outputDir "${DumpRenderTree_DERIVED_SOURCES_DIR}" --template ${DumpRenderTree_DIR}/Scripts/PreferencesTemplates/TestOptionsGeneratedWebKitLegacyKeyMapping.cpp.erb --template ${DumpRenderTree_DIR}/Scripts/PreferencesTemplates/TestOptionsGeneratedKeys.h.erb
     VERBATIM)
 
 list(APPEND DumpRenderTree_SOURCES
+    ${DumpRenderTree_DERIVED_SOURCES_DIR}/TestOptionsGeneratedWebKitLegacyKeyMapping.cpp
     ${DumpRenderTree_DERIVED_SOURCES_DIR}/TestOptionsGeneratedKeys.h
 )
 

Modified: trunk/Tools/DumpRenderTree/DerivedSources-input.xcfilelist (269104 => 269105)


--- trunk/Tools/DumpRenderTree/DerivedSources-input.xcfilelist	2020-10-28 15:28:14 UTC (rev 269104)
+++ trunk/Tools/DumpRenderTree/DerivedSources-input.xcfilelist	2020-10-28 15:57:35 UTC (rev 269105)
@@ -7,6 +7,7 @@
 $(PROJECT_DIR)/../TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl
 $(PROJECT_DIR)/Bindings/CodeGeneratorDumpRenderTree.pm
 $(PROJECT_DIR)/DerivedSources.make
+$(PROJECT_DIR)/Scripts/PreferencesTemplates/TestOptionsGeneratedWebKitLegacyKeyMapping.cpp.erb
 $(PROJECT_DIR)/Scripts/PreferencesTemplates/TestOptionsGeneratedKeys.h.erb
 $(PROJECT_DIR)/Scripts/generate-derived-sources.sh
 $(WEBCORE_PRIVATE_HEADERS_DIR)/CodeGenerator.pm

Modified: trunk/Tools/DumpRenderTree/DerivedSources-output.xcfilelist (269104 => 269105)


--- trunk/Tools/DumpRenderTree/DerivedSources-output.xcfilelist	2020-10-28 15:28:14 UTC (rev 269104)
+++ trunk/Tools/DumpRenderTree/DerivedSources-output.xcfilelist	2020-10-28 15:57:35 UTC (rev 269105)
@@ -1,4 +1,5 @@
 # This file is generated by the generate-xcfilelists script.
 $(BUILT_PRODUCTS_DIR)/DerivedSources/DumpRenderTree/JSUIScriptController.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/DumpRenderTree/JSUIScriptController.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/DumpRenderTree/TestOptionsGeneratedWebKitLegacyKeyMapping.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/DumpRenderTree/TestOptionsGeneratedKeys.h

Modified: trunk/Tools/DumpRenderTree/DerivedSources.make (269104 => 269105)


--- trunk/Tools/DumpRenderTree/DerivedSources.make	2020-10-28 15:28:14 UTC (rev 269104)
+++ trunk/Tools/DumpRenderTree/DerivedSources.make	2020-10-28 15:57:35 UTC (rev 269105)
@@ -64,6 +64,7 @@
 #
 
 WEB_PREFERENCES_GENERATED_FILES = \
+    TestOptionsGeneratedWebKitLegacyKeyMapping.cpp \
     TestOptionsGeneratedKeys.h \
 #
 

Modified: trunk/Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj (269104 => 269105)


--- trunk/Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj	2020-10-28 15:28:14 UTC (rev 269104)
+++ trunk/Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj	2020-10-28 15:57:35 UTC (rev 269105)
@@ -109,6 +109,7 @@
 		5DB9AC9E0F722C3600684641 /* WebKitWeightWatcher700.ttf in Copy Font Files */ = {isa = PBXBuildFile; fileRef = 375F09770DAC3CB600C8B4E5 /* WebKitWeightWatcher700.ttf */; };
 		5DB9AC9F0F722C3600684641 /* WebKitWeightWatcher800.ttf in Copy Font Files */ = {isa = PBXBuildFile; fileRef = 375F09780DAC3CB600C8B4E5 /* WebKitWeightWatcher800.ttf */; };
 		5DB9ACA00F722C3600684641 /* WebKitWeightWatcher900.ttf in Copy Font Files */ = {isa = PBXBuildFile; fileRef = 375F09790DAC3CB600C8B4E5 /* WebKitWeightWatcher900.ttf */; };
+		7C9893DF25433F8E00354EBC /* TestOptionsGeneratedWebKitLegacyKeyMapping.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C9893DE25433C8700354EBC /* TestOptionsGeneratedWebKitLegacyKeyMapping.cpp */; };
 		7CFF9BBF2533BB240008009F /* TestFeatures.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFF9BBE2533BB240008009F /* TestFeatures.cpp */; };
 		7CFF9BC22533BC160008009F /* TestCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFF9BC12533BC160008009F /* TestCommand.cpp */; };
 		80045AEE147718E7008290A8 /* AccessibilityNotificationHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = 80045AEC147718E7008290A8 /* AccessibilityNotificationHandler.mm */; };
@@ -333,7 +334,8 @@
 		7C44697F25377A020024290A /* TestOptionsGeneratedKeys.h.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = TestOptionsGeneratedKeys.h.erb; sourceTree = "<group>"; };
 		7C44698025377A020024290A /* check-xcfilelists.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "check-xcfilelists.sh"; sourceTree = "<group>"; };
 		7C44698125377A020024290A /* generate-derived-sources.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "generate-derived-sources.sh"; sourceTree = "<group>"; };
-		7C44698525377E520024290A /* TestOptionsGeneratedKeys.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = TestOptionsGeneratedKeys.h; path = TestOptionsGeneratedKeys.h; sourceTree = "<group>"; };
+		7C44698525377E520024290A /* TestOptionsGeneratedKeys.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestOptionsGeneratedKeys.h; sourceTree = "<group>"; };
+		7C9893DE25433C8700354EBC /* TestOptionsGeneratedWebKitLegacyKeyMapping.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TestOptionsGeneratedWebKitLegacyKeyMapping.cpp; sourceTree = "<group>"; };
 		7CBBC3221DDFCF9A00786B9D /* TestOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestOptions.h; sourceTree = "<group>"; };
 		7CFF9BBD2533BB240008009F /* TestFeatures.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestFeatures.h; sourceTree = "<group>"; };
 		7CFF9BBE2533BB240008009F /* TestFeatures.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TestFeatures.cpp; sourceTree = "<group>"; };
@@ -778,6 +780,7 @@
 			isa = PBXGroup;
 			children = (
 				7C44698525377E520024290A /* TestOptionsGeneratedKeys.h */,
+				7C9893DE25433C8700354EBC /* TestOptionsGeneratedWebKitLegacyKeyMapping.cpp */,
 			);
 			name = "Derived Sources";
 			path = DerivedSources/DumpRenderTree;
@@ -1291,6 +1294,7 @@
 				7CFF9BC22533BC160008009F /* TestCommand.cpp in Sources */,
 				7CFF9BBF2533BB240008009F /* TestFeatures.cpp in Sources */,
 				A30A21F82051D8C40008FF42 /* TestOptions.cpp in Sources */,
+				7C9893DF25433F8E00354EBC /* TestOptionsGeneratedWebKitLegacyKeyMapping.cpp in Sources */,
 				BC0131DA0C9772010087317D /* TestRunner.cpp in Sources */,
 				BCA18B240C9B014B00114369 /* TestRunnerMac.mm in Sources */,
 				F4D423611DD5048200678290 /* TextInputControllerIOS.m in Sources */,

Added: trunk/Tools/DumpRenderTree/Scripts/PreferencesTemplates/TestOptionsGeneratedWebKitLegacyKeyMapping.cpp.erb (0 => 269105)


--- trunk/Tools/DumpRenderTree/Scripts/PreferencesTemplates/TestOptionsGeneratedWebKitLegacyKeyMapping.cpp.erb	                        (rev 0)
+++ trunk/Tools/DumpRenderTree/Scripts/PreferencesTemplates/TestOptionsGeneratedWebKitLegacyKeyMapping.cpp.erb	2020-10-28 15:57:35 UTC (rev 269105)
@@ -0,0 +1,48 @@
+/*
+ * <%= @warning %>
+ *
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "TestOptions.h"
+
+namespace WTR {
+
+std::string TestOptions::toWebKitLegacyPreferenceKey(const std::string& webPreferencesKey)
+{
+    static std::unordered_map<std::string, std::string> nonStandardKeys = {
+<%- for @pref in @exposedPreferences.select { |p| p.opts["webKitLegacyPreferenceKey"] } do -%>
+        { "<%= @pref.name %>", "<%= @pref.preferenceKey %>" }, \
+<%- end -%>
+    };
+
+    auto it = nonStandardKeys.find(webPreferencesKey);
+    if (it != nonStandardKeys.end())
+        return it->second;
+
+    return "WebKit" + webPreferencesKey;
+}
+
+}

Modified: trunk/Tools/DumpRenderTree/TestOptions.cpp (269104 => 269105)


--- trunk/Tools/DumpRenderTree/TestOptions.cpp	2020-10-28 15:28:14 UTC (rev 269104)
+++ trunk/Tools/DumpRenderTree/TestOptions.cpp	2020-10-28 15:57:35 UTC (rev 269105)
@@ -30,6 +30,20 @@
 
 namespace WTR {
 
+const std::vector<std::string>& TestOptions::supportedBoolWebPreferenceFeatures()
+{
+    // FIXME: Remove this once there is a viable mechanism for reseting WebPreferences between tests,
+    // at which point, we will not need to manually reset every supported preference for each test.
+
+    static std::vector<std::string> supported = [] {
+        std::vector<std::string> keys;
+        for (const auto& [key, value] : defaults().boolWebPreferenceFeatures)
+            keys.push_back(key);
+        return keys;
+    }();
+    return supported;
+}
+
 const TestFeatures& TestOptions::defaults()
 {
     static TestFeatures features;

Modified: trunk/Tools/DumpRenderTree/TestOptions.h (269104 => 269105)


--- trunk/Tools/DumpRenderTree/TestOptions.h	2020-10-28 15:28:14 UTC (rev 269104)
+++ trunk/Tools/DumpRenderTree/TestOptions.h	2020-10-28 15:57:35 UTC (rev 269105)
@@ -56,6 +56,10 @@
     const auto& uint32WebPreferenceFeatures() const { return m_features.uint32WebPreferenceFeatures; }
     const auto& stringWebPreferenceFeatures() const { return m_features.stringWebPreferenceFeatures; }
 
+    // FIXME: Remove this once there is a viable mechanism for reseting WebPreferences between tests,
+    // at which point, we will not need to manually reset every supported preference for each test.
+    static const std::vector<std::string>& supportedBoolWebPreferenceFeatures();
+
     static std::string toWebKitLegacyPreferenceKey(const std::string&);
 
 private:

Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm (269104 => 269105)


--- trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2020-10-28 15:28:14 UTC (rev 269104)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2020-10-28 15:57:35 UTC (rev 269105)
@@ -130,6 +130,11 @@
 #import <mach-o/getsect.h>
 }
 
+static RetainPtr<NSString> toNS(const std::string& string)
+{
+    return adoptNS([[NSString alloc] initWithUTF8String:string.c_str()]);
+}
+
 #if !PLATFORM(IOS_FAMILY)
 @interface DumpRenderTreeApplication : NSApplication
 @end
@@ -969,12 +974,11 @@
     [WebPreferences _setCurrentNetworkLoaderSessionCookieAcceptPolicy:NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain];
 }
 
-static bool boolWebPreferenceFeatureValue(std::string key, bool defaultValue, const WTR::TestOptions& options)
+static bool boolWebPreferenceFeatureValue(std::string key, const WTR::TestOptions& options)
 {
     auto it = options.boolWebPreferenceFeatures().find(key);
-    if (it != options.boolWebPreferenceFeatures().end())
-        return it->second;
-    return defaultValue;
+    ASSERT(it != options.boolWebPreferenceFeatures().end());
+    return it->second;
 }
 
 static void setWebPreferencesForTestOptions(WebPreferences *preferences, const WTR::TestOptions& options)
@@ -981,29 +985,10 @@
 {
     preferences.privateBrowsingEnabled = options.useEphemeralSession();
 
-    preferences.attachmentElementEnabled = boolWebPreferenceFeatureValue("AttachmentElementEnabled", false, options);
-    preferences.acceleratedDrawingEnabled = boolWebPreferenceFeatureValue("AcceleratedDrawingEnabled", false, options);
-    preferences.menuItemElementEnabled = boolWebPreferenceFeatureValue("MenuItemElementEnabled", false, options);
-    preferences.keygenElementEnabled = boolWebPreferenceFeatureValue("KeygenElementEnabled", false, options);
-    preferences.modernMediaControlsEnabled = boolWebPreferenceFeatureValue("ModernMediaControlsEnabled", true, options);
-    preferences.inspectorAdditionsEnabled = boolWebPreferenceFeatureValue("InspectorAdditionsEnabled", false, options);
-    preferences.allowCrossOriginSubresourcesToAskForCredentials = boolWebPreferenceFeatureValue("AllowCrossOriginSubresourcesToAskForCredentials", false, options);
-    preferences.colorFilterEnabled = boolWebPreferenceFeatureValue("ColorFilterEnabled", false, options);
-    preferences.selectionAcrossShadowBoundariesEnabled = boolWebPreferenceFeatureValue("SelectionAcrossShadowBoundariesEnabled", true, options);
-    preferences.webGPUEnabled = boolWebPreferenceFeatureValue("WebGPUEnabled", false, options);
-    preferences.CSSLogicalEnabled = boolWebPreferenceFeatureValue("CSSLogicalEnabled", false, options);
-    preferences.lineHeightUnitsEnabled = boolWebPreferenceFeatureValue("LineHeightUnitsEnabled", false, options);
-    preferences.adClickAttributionEnabled = boolWebPreferenceFeatureValue("AdClickAttributionEnabled", false, options);
-    preferences.resizeObserverEnabled = boolWebPreferenceFeatureValue("ResizeObserverEnabled", false, options);
-    preferences.CSSOMViewSmoothScrollingEnabled = boolWebPreferenceFeatureValue("CSSOMViewSmoothScrollingEnabled", false, options);
-    preferences.coreMathMLEnabled = boolWebPreferenceFeatureValue("CoreMathMLEnabled", false, options);
-    preferences.requestIdleCallbackEnabled = boolWebPreferenceFeatureValue("RequestIdleCallbackEnabled", false, options);
-    preferences.asyncClipboardAPIEnabled = boolWebPreferenceFeatureValue("AsyncClipboardAPIEnabled", false, options);
-    preferences.usesPageCache = boolWebPreferenceFeatureValue("UsesBackForwardCache", false, options);
-    preferences.layoutFormattingContextIntegrationEnabled = boolWebPreferenceFeatureValue("LayoutFormattingContextIntegrationEnabled", true, options);
-    preferences.aspectRatioOfImgFromWidthAndHeightEnabled = boolWebPreferenceFeatureValue("AspectRatioOfImgFromWidthAndHeightEnabled", false, options);
-    preferences.allowTopNavigationToDataURLs = boolWebPreferenceFeatureValue("AllowTopNavigationToDataURLs", true, options);
-    preferences.contactPickerAPIEnabled = boolWebPreferenceFeatureValue("ContactPickerAPIEnabled", false, options);
+    // FIXME: Remove this once there is a viable mechanism for reseting WebPreferences between tests,
+    // at which point, we will not need to manually reset every supported preference for each test.
+    for (const auto& key : options.supportedBoolWebPreferenceFeatures())
+        [preferences _setBoolPreferenceForTestingWithValue:boolWebPreferenceFeatureValue(key, options) forKey:toNS(WTR::TestOptions::toWebKitLegacyPreferenceKey(key)).get()];
 }
 
 // Called once on DumpRenderTree startup.

Modified: trunk/Tools/DumpRenderTree/mac/TestRunnerMac.mm (269104 => 269105)


--- trunk/Tools/DumpRenderTree/mac/TestRunnerMac.mm	2020-10-28 15:28:14 UTC (rev 269104)
+++ trunk/Tools/DumpRenderTree/mac/TestRunnerMac.mm	2020-10-28 15:57:35 UTC (rev 269105)
@@ -609,7 +609,7 @@
     RetainPtr<CFStringRef> valueCF = adoptCF(JSStringCopyCFString(kCFAllocatorDefault, value));
     NSString *valueNS = (__bridge NSString *)valueCF.get();
 
-    [[[mainFrame webView] preferences] _setPreferenceForTestWithValue:valueNS forKey:keyNS];
+    [[[mainFrame webView] preferences] _setStringPreferenceForTestingWithValue:valueNS forKey:keyNS];
 }
 
 void TestRunner::removeAllVisitedLinks()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to