Title: [269157] trunk
Revision
269157
Author
wei...@apple.com
Date
2020-10-29 11:18:10 -0700 (Thu, 29 Oct 2020)

Log Message

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

Reviewed by Brent Fulgham.

Source/WebKitLegacy/win:

Expose a set of setters for DumpRenderTree to use when setting preferences
by string, matching WebKitLegacy for cocoa platforms and modern WebKit.

* Interfaces/IWebPreferencesPrivate.idl:
* WebPreferences.cpp:
(WebPreferences::setBoolPreferenceForTesting):
(WebPreferences::setUInt32PreferenceForTesting):
(WebPreferences::setDoublePreferenceForTesting):
(WebPreferences::setStringPreferenceForTesting):
* WebPreferences.h:

Tools:

Adopt set*PreferenceForTesting functions to match DumpRenderTree for cocoa platforms, and
make it so that only TestOptions.cpp needs to be touched to add support for new preference
in tests.

Also adds some helpers to convert between string types and use RetainPtr in a few more places.

* DumpRenderTree/win/DumpRenderTree.cpp:
(toUTF8):
(toBSTR):
(resetWebPreferencesToConsistentValues):
(boolWebPreferenceFeatureValue):
(setWebPreferencesForTestOptions):
(runTest):

Modified Paths

Diff

Modified: trunk/Source/WebKitLegacy/win/ChangeLog (269156 => 269157)


--- trunk/Source/WebKitLegacy/win/ChangeLog	2020-10-29 18:10:27 UTC (rev 269156)
+++ trunk/Source/WebKitLegacy/win/ChangeLog	2020-10-29 18:18:10 UTC (rev 269157)
@@ -1,3 +1,21 @@
+2020-10-29  Sam Weinig  <wei...@apple.com>
+
+        [Testing] Remove requirement of adding new SPI for each preference that needs testing (WebKitLegacy Windows)
+        https://bugs.webkit.org/show_bug.cgi?id=218291
+
+        Reviewed by Brent Fulgham.
+
+        Expose a set of setters for DumpRenderTree to use when setting preferences
+        by string, matching WebKitLegacy for cocoa platforms and modern WebKit.
+
+        * Interfaces/IWebPreferencesPrivate.idl:
+        * WebPreferences.cpp:
+        (WebPreferences::setBoolPreferenceForTesting):
+        (WebPreferences::setUInt32PreferenceForTesting):
+        (WebPreferences::setDoublePreferenceForTesting):
+        (WebPreferences::setStringPreferenceForTesting):
+        * WebPreferences.h:
+
 2020-10-27  Fujii Hironori  <hironori.fu...@sony.com>
 
         [WinCairo][WK1] Implement WebView::layerTreeAsString

Modified: trunk/Source/WebKitLegacy/win/Interfaces/IWebPreferencesPrivate.idl (269156 => 269157)


--- trunk/Source/WebKitLegacy/win/Interfaces/IWebPreferencesPrivate.idl	2020-10-29 18:10:27 UTC (rev 269156)
+++ trunk/Source/WebKitLegacy/win/Interfaces/IWebPreferencesPrivate.idl	2020-10-29 18:18:10 UTC (rev 269157)
@@ -269,4 +269,8 @@
     HRESULT setModernUnprefixedWebAudioEnabled([in] BOOL enabled);
     HRESULT contactPickerAPIEnabled([out, retval] BOOL* enabled);
     HRESULT setContactPickerAPIEnabled([in] BOOL enabled);
+    HRESULT setBoolPreferenceForTesting([in] BSTR key, [in] BOOL value);
+    HRESULT setUInt32PreferenceForTesting([in] BSTR key, [in] unsigned value);
+    HRESULT setDoublePreferenceForTesting([in] BSTR key, [in] double value);
+    HRESULT setStringPreferenceForTesting([in] BSTR key, [in] BSTR value);
 }

Modified: trunk/Source/WebKitLegacy/win/WebPreferenceKeysPrivate.h (269156 => 269157)


--- trunk/Source/WebKitLegacy/win/WebPreferenceKeysPrivate.h	2020-10-29 18:10:27 UTC (rev 269156)
+++ trunk/Source/WebKitLegacy/win/WebPreferenceKeysPrivate.h	2020-10-29 18:18:10 UTC (rev 269157)
@@ -184,7 +184,7 @@
 
 #define WebKitMenuItemElementEnabledPreferenceKey "WebKitMenuItemElementEnabled"
 
-#define WebKitKeygenElementEnabledPreferenceKey "WebKitKeygenElementEnabled"
+#define WebKitKeygenElementEnabledPreferenceKey "WebKitKeygenElementEnabledPreferenceKey"
 
 #define WebKitModernMediaControlsEnabledPreferenceKey "WebKitModernMediaControlsEnabled"
 

Modified: trunk/Source/WebKitLegacy/win/WebPreferences.cpp (269156 => 269157)


--- trunk/Source/WebKitLegacy/win/WebPreferences.cpp	2020-10-29 18:10:27 UTC (rev 269156)
+++ trunk/Source/WebKitLegacy/win/WebPreferences.cpp	2020-10-29 18:18:10 UTC (rev 269157)
@@ -2328,6 +2328,67 @@
     return S_OK;
 }
 
+HRESULT WebPreferences::setBoolPreferenceForTesting(_In_ BSTR key, _In_ BOOL value)
+{
+    if (!SysStringLen(key))
+        return E_FAIL;
+
+#if USE(CF)
+    auto keyString = String(key).createCFString();
+    setValueForKey(keyString.get(), value ? kCFBooleanTrue : kCFBooleanFalse);
+#endif
+
+    postPreferencesChangesNotification();
+
+    return S_OK;
+}
+
+HRESULT WebPreferences::setUInt32PreferenceForTesting(_In_ BSTR key, _In_ unsigned value)
+{
+    if (!SysStringLen(key))
+        return E_FAIL;
+
+#if USE(CF)
+    auto keyString = String(key).createCFString();
+    setValueForKey(keyString.get(), cfNumber(static_cast<int>(value)).get());
+#endif
+
+    postPreferencesChangesNotification();
+
+    return S_OK;
+}
+
+HRESULT WebPreferences::setDoublePreferenceForTesting(_In_ BSTR key, _In_ double value)
+{
+    if (!SysStringLen(key))
+        return E_FAIL;
+
+#if USE(CF)
+    auto keyString = String(key).createCFString();
+    setValueForKey(keyString.get(), cfNumber(static_cast<float>(value)).get());
+#endif
+
+    postPreferencesChangesNotification();
+
+    return S_OK;
+}
+
+HRESULT WebPreferences::setStringPreferenceForTesting(_In_ BSTR key, _In_ BSTR value)
+{
+    if (!SysStringLen(key) || !SysStringLen(value))
+        return E_FAIL;
+
+#if USE(CF)
+    auto keyString = String(key).createCFString();
+    auto valueString = String(value).createCFString();
+    setValueForKey(keyString.get(), valueString.get());
+#endif
+
+    postPreferencesChangesNotification();
+
+    return S_OK;
+}
+
 HRESULT WebPreferences::setApplicationId(BSTR applicationId)
 {
 #if USE(CF)

Modified: trunk/Source/WebKitLegacy/win/WebPreferences.h (269156 => 269157)


--- trunk/Source/WebKitLegacy/win/WebPreferences.h	2020-10-29 18:10:27 UTC (rev 269156)
+++ trunk/Source/WebKitLegacy/win/WebPreferences.h	2020-10-29 18:18:10 UTC (rev 269157)
@@ -307,6 +307,10 @@
     virtual HRESULT STDMETHODCALLTYPE setModernUnprefixedWebAudioEnabled(BOOL);
     virtual HRESULT STDMETHODCALLTYPE contactPickerAPIEnabled(_Out_ BOOL*);
     virtual HRESULT STDMETHODCALLTYPE setContactPickerAPIEnabled(BOOL);
+    virtual HRESULT STDMETHODCALLTYPE setBoolPreferenceForTesting(_In_ BSTR key, _In_ BOOL);
+    virtual HRESULT STDMETHODCALLTYPE setUInt32PreferenceForTesting(_In_ BSTR key, _In_ unsigned);
+    virtual HRESULT STDMETHODCALLTYPE setDoublePreferenceForTesting(_In_ BSTR key, _In_ double);
+    virtual HRESULT STDMETHODCALLTYPE setStringPreferenceForTesting(_In_ BSTR key, _In_ BSTR);
 
     // WebPreferences
 

Modified: trunk/Tools/ChangeLog (269156 => 269157)


--- trunk/Tools/ChangeLog	2020-10-29 18:10:27 UTC (rev 269156)
+++ trunk/Tools/ChangeLog	2020-10-29 18:18:10 UTC (rev 269157)
@@ -1,3 +1,24 @@
+2020-10-29  Sam Weinig  <wei...@apple.com>
+
+        [Testing] Remove requirement of adding new SPI for each preference that needs testing (WebKitLegacy Windows)
+        https://bugs.webkit.org/show_bug.cgi?id=218291
+
+        Reviewed by Brent Fulgham.
+
+        Adopt set*PreferenceForTesting functions to match DumpRenderTree for cocoa platforms, and
+        make it so that only TestOptions.cpp needs to be touched to add support for new preference
+        in tests.
+        
+        Also adds some helpers to convert between string types and use RetainPtr in a few more places.
+
+        * DumpRenderTree/win/DumpRenderTree.cpp:
+        (toUTF8):
+        (toBSTR):
+        (resetWebPreferencesToConsistentValues):
+        (boolWebPreferenceFeatureValue):
+        (setWebPreferencesForTestOptions):
+        (runTest):
+
 2020-10-28  Aakash Jain  <aakash_j...@apple.com>
 
         [build.webkit.org] loadConfig unittest fail depending on locally installed version of buildbot

Modified: trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp (269156 => 269157)


--- trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp	2020-10-29 18:10:27 UTC (rev 269156)
+++ trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp	2020-10-29 18:18:10 UTC (rev 269157)
@@ -232,16 +232,25 @@
 }
 #endif
 
-string toUTF8(BSTR bstr)
+std::string toUTF8(BSTR bstr)
 {
     return toUTF8(bstr, SysStringLen(bstr));
 }
 
-string toUTF8(const wstring& wideString)
+std::string toUTF8(const wstring& wideString)
 {
     return toUTF8(wideString.c_str(), wideString.length());
 }
 
+static std::string toUTF8(CFStringRef input)
+{
+    CFIndex maximumURLLengthAsUTF8 = CFStringGetMaximumSizeForEncoding(CFStringGetLength(input), kCFStringEncodingUTF8) + 1;
+    Vector<char> buffer(maximumURLLengthAsUTF8 + 1, 0);
+    CFStringGetCString(input, buffer.data(), maximumURLLengthAsUTF8, kCFStringEncodingUTF8);
+
+    return buffer.data();
+}
+
 wstring cfStringRefToWString(CFStringRef cfStr)
 {
     Vector<wchar_t> v(CFStringGetLength(cfStr));
@@ -250,6 +259,19 @@
     return wstring(v.data(), v.size());
 }
 
+static _bstr_t toBSTR(const std::string& input)
+{
+    return input.c_str();
+}
+
+static _bstr_t toBSTR(CFStringRef input)
+{
+    size_t stringLength = CFStringGetLength(input);
+    Vector<UniChar> buffer(stringLength + 1, 0);
+    CFStringGetCharacters(input, CFRangeMake(0, stringLength), buffer.data());
+    return reinterpret_cast<wchar_t*>(buffer.data());
+}
+
 static LRESULT CALLBACK DumpRenderTreeWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
     switch (msg) {
@@ -884,11 +906,7 @@
     prefsPrivate->setLoadsSiteIconsIgnoringImageLoadingPreference(FALSE);
     prefsPrivate->setFrameFlatteningEnabled(FALSE);
     if (persistentUserStyleSheetLocation) {
-        size_t stringLength = CFStringGetLength(persistentUserStyleSheetLocation.get());
-        Vector<UniChar> urlCharacters(stringLength + 1, 0);
-        CFStringGetCharacters(persistentUserStyleSheetLocation.get(), CFRangeMake(0, stringLength), urlCharacters.data());
-        _bstr_t url(reinterpret_cast<wchar_t*>(urlCharacters.data()));
-        preferences->setUserStyleSheetLocation(url);
+        preferences->setUserStyleSheetLocation(toBSTR(persistentUserStyleSheetLocation.get()));
         preferences->setUserStyleSheetEnabled(TRUE);
     } else
         preferences->setUserStyleSheetEnabled(FALSE);
@@ -912,12 +930,11 @@
     setAlwaysAcceptCookies(false);
 }
 
-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(IWebPreferences* preferences, const WTR::TestOptions& options)
@@ -926,18 +943,10 @@
 
     preferences->setPrivateBrowsingEnabled(options.useEphemeralSession());
 
-    preferences->setUsesPageCache(boolWebPreferenceFeatureValue("UsesBackForwardCache", false, options));
-    prefsPrivate->setMenuItemElementEnabled(boolWebPreferenceFeatureValue("MenuItemElementEnabled", false, options));
-    prefsPrivate->setKeygenElementEnabled(boolWebPreferenceFeatureValue("KeygenElementEnabled", false, options));
-    prefsPrivate->setModernMediaControlsEnabled(boolWebPreferenceFeatureValue("ModernMediaControlsEnabled", true, options));
-    prefsPrivate->setInspectorAdditionsEnabled(boolWebPreferenceFeatureValue("InspectorAdditionsEnabled", false, options));
-    prefsPrivate->setRequestIdleCallbackEnabled(boolWebPreferenceFeatureValue("RequestIdleCallbackEnabled", false, options));
-    prefsPrivate->setAsyncClipboardAPIEnabled(boolWebPreferenceFeatureValue("AsyncClipboardAPIEnabled", false, options));
-    prefsPrivate->setContactPickerAPIEnabled(boolWebPreferenceFeatureValue("ContactPickerAPIEnabled", false, options));
-    prefsPrivate->setAllowTopNavigationToDataURLs(boolWebPreferenceFeatureValue("AllowTopNavigationToDataURLs", true, options));
-    prefsPrivate->setCSSOMViewSmoothScrollingEnabled(boolWebPreferenceFeatureValue("CSSOMViewSmoothScrollingEnabled", false, options));
-    prefsPrivate->setSpatialNavigationEnabled(boolWebPreferenceFeatureValue("SpatialNavigationEnabled", false, options));
-    preferences->setTabsToLinks(boolWebPreferenceFeatureValue("TabsToLinks", 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())
+        prefsPrivate->setBoolPreferenceForTesting(toBSTR(WTR::TestOptions::toWebKitLegacyPreferenceKey(key)), boolWebPreferenceFeatureValue(key, options));
 }
 
 static String applicationId()
@@ -1195,49 +1204,34 @@
 
     static _bstr_t methodBStr(TEXT("GET"));
 
-    CFStringRef str = CFStringCreateWithCString(0, pathOrURL.c_str(), kCFStringEncodingWindowsLatin1);
+    auto str = adoptCF(CFStringCreateWithCString(0, pathOrURL.c_str(), kCFStringEncodingWindowsLatin1));
     if (!str) {
         fprintf(stderr, "Failed to parse \"%s\" as UTF-8\n", pathOrURL.c_str());
         return;
     }
 
-    CFURLRef url = "" str, 0);
-
+    auto url = "" str.get(), 0));
     if (!url)
-        url = "" str, kCFURLWindowsPathStyle, false);
+        url = "" str.get(), kCFURLWindowsPathStyle, false));
 
-    CFRelease(str);
-
     if (!url) {
         fprintf(stderr, "Failed to parse \"%s\" as a URL\n", pathOrURL.c_str());
         return;
     }
 
-    String hostName = String(adoptCF(CFURLCopyHostName(url)).get());
-
+    String hostName = String(adoptCF(CFURLCopyHostName(url.get())).get());
     String fallbackPath = findFontFallback(pathOrURL.c_str());
 
-    str = CFURLGetString(url);
+    auto urlCFString = CFURLGetString(url.get());
 
-    CFIndex length = CFStringGetLength(str);
+    auto urlBStr = toBSTR(urlCFString);
+    ASSERT(urlBStr.length() == CFStringGetLength(urlCFString));
 
-    Vector<UniChar> buffer(length + 1, 0);
-    CFStringGetCharacters(str, CFRangeMake(0, length), buffer.data());
-
-    _bstr_t urlBStr(reinterpret_cast<wchar_t*>(buffer.data()));
-    ASSERT(urlBStr.length() == length);
-
-    CFIndex maximumURLLengthAsUTF8 = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
-    Vector<char> testURL(maximumURLLengthAsUTF8 + 1, 0);
-    CFStringGetCString(str, testURL.data(), maximumURLLengthAsUTF8, kCFStringEncodingUTF8);
-
-    CFRelease(url);
-
     auto options = testOptionsForTest(command);
 
     resetWebViewToConsistentStateBeforeTesting(options);
 
-    ::gTestRunner = TestRunner::create(testURL.data(), command.expectedPixelHash);
+    ::gTestRunner = TestRunner::create(toUTF8(urlCFString), command.expectedPixelHash);
     ::gTestRunner->setCustomTimeout(command.timeout.milliseconds());
     ::gTestRunner->setDumpJSConsoleLogInStdErr(command.dumpJSConsoleLogInStdErr || options.dumpJSConsoleLogInStdErr());
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to