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/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());