⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 269157 in webkit


Ignore:
Timestamp:
Oct 29, 2020, 11:18:10 AM (6 years ago)
Author:
weinig@apple.com
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):

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKitLegacy/win/ChangeLog

    r269066 r269157  
     12020-10-29  Sam Weinig  <weinig@apple.com>
     2
     3        [Testing] Remove requirement of adding new SPI for each preference that needs testing (WebKitLegacy Windows)
     4        https://bugs.webkit.org/show_bug.cgi?id=218291
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Expose a set of setters for DumpRenderTree to use when setting preferences
     9        by string, matching WebKitLegacy for cocoa platforms and modern WebKit.
     10
     11        * Interfaces/IWebPreferencesPrivate.idl:
     12        * WebPreferences.cpp:
     13        (WebPreferences::setBoolPreferenceForTesting):
     14        (WebPreferences::setUInt32PreferenceForTesting):
     15        (WebPreferences::setDoublePreferenceForTesting):
     16        (WebPreferences::setStringPreferenceForTesting):
     17        * WebPreferences.h:
     18
    1192020-10-27  Fujii Hironori  <Hironori.Fujii@sony.com>
    220
  • trunk/Source/WebKitLegacy/win/Interfaces/IWebPreferencesPrivate.idl

    r267988 r269157  
    270270    HRESULT contactPickerAPIEnabled([out, retval] BOOL* enabled);
    271271    HRESULT setContactPickerAPIEnabled([in] BOOL enabled);
    272 }
     272    HRESULT setBoolPreferenceForTesting([in] BSTR key, [in] BOOL value);
     273    HRESULT setUInt32PreferenceForTesting([in] BSTR key, [in] unsigned value);
     274    HRESULT setDoublePreferenceForTesting([in] BSTR key, [in] double value);
     275    HRESULT setStringPreferenceForTesting([in] BSTR key, [in] BSTR value);
     276}
  • trunk/Source/WebKitLegacy/win/WebPreferenceKeysPrivate.h

    r267988 r269157  
    185185#define WebKitMenuItemElementEnabledPreferenceKey "WebKitMenuItemElementEnabled"
    186186
    187 #define WebKitKeygenElementEnabledPreferenceKey "WebKitKeygenElementEnabled"
     187#define WebKitKeygenElementEnabledPreferenceKey "WebKitKeygenElementEnabledPreferenceKey"
    188188
    189189#define WebKitModernMediaControlsEnabledPreferenceKey "WebKitModernMediaControlsEnabled"
  • trunk/Source/WebKitLegacy/win/WebPreferences.cpp

    r268647 r269157  
    23292329}
    23302330
     2331HRESULT WebPreferences::setBoolPreferenceForTesting(_In_ BSTR key, _In_ BOOL value)
     2332{
     2333    if (!SysStringLen(key))
     2334        return E_FAIL;
     2335
     2336#if USE(CF)
     2337    auto keyString = String(key).createCFString();
     2338    setValueForKey(keyString.get(), value ? kCFBooleanTrue : kCFBooleanFalse);
     2339#endif
     2340
     2341    postPreferencesChangesNotification();
     2342
     2343    return S_OK;
     2344}
     2345
     2346HRESULT WebPreferences::setUInt32PreferenceForTesting(_In_ BSTR key, _In_ unsigned value)
     2347{
     2348    if (!SysStringLen(key))
     2349        return E_FAIL;
     2350
     2351#if USE(CF)
     2352    auto keyString = String(key).createCFString();
     2353    setValueForKey(keyString.get(), cfNumber(static_cast<int>(value)).get());
     2354#endif
     2355
     2356    postPreferencesChangesNotification();
     2357
     2358    return S_OK;
     2359}
     2360
     2361HRESULT WebPreferences::setDoublePreferenceForTesting(_In_ BSTR key, _In_ double value)
     2362{
     2363    if (!SysStringLen(key))
     2364        return E_FAIL;
     2365
     2366#if USE(CF)
     2367    auto keyString = String(key).createCFString();
     2368    setValueForKey(keyString.get(), cfNumber(static_cast<float>(value)).get());
     2369#endif
     2370
     2371    postPreferencesChangesNotification();
     2372
     2373    return S_OK;
     2374}
     2375
     2376HRESULT WebPreferences::setStringPreferenceForTesting(_In_ BSTR key, _In_ BSTR value)
     2377{
     2378    if (!SysStringLen(key) || !SysStringLen(value))
     2379        return E_FAIL;
     2380
     2381#if USE(CF)
     2382    auto keyString = String(key).createCFString();
     2383    auto valueString = String(value).createCFString();
     2384    setValueForKey(keyString.get(), valueString.get());
     2385#endif
     2386
     2387    postPreferencesChangesNotification();
     2388
     2389    return S_OK;
     2390}
     2391
    23312392HRESULT WebPreferences::setApplicationId(BSTR applicationId)
    23322393{
  • trunk/Source/WebKitLegacy/win/WebPreferences.h

    r267988 r269157  
    308308    virtual HRESULT STDMETHODCALLTYPE contactPickerAPIEnabled(_Out_ BOOL*);
    309309    virtual HRESULT STDMETHODCALLTYPE setContactPickerAPIEnabled(BOOL);
     310    virtual HRESULT STDMETHODCALLTYPE setBoolPreferenceForTesting(_In_ BSTR key, _In_ BOOL);
     311    virtual HRESULT STDMETHODCALLTYPE setUInt32PreferenceForTesting(_In_ BSTR key, _In_ unsigned);
     312    virtual HRESULT STDMETHODCALLTYPE setDoublePreferenceForTesting(_In_ BSTR key, _In_ double);
     313    virtual HRESULT STDMETHODCALLTYPE setStringPreferenceForTesting(_In_ BSTR key, _In_ BSTR);
    310314
    311315    // WebPreferences
  • trunk/Tools/ChangeLog

    r269132 r269157  
     12020-10-29  Sam Weinig  <weinig@apple.com>
     2
     3        [Testing] Remove requirement of adding new SPI for each preference that needs testing (WebKitLegacy Windows)
     4        https://bugs.webkit.org/show_bug.cgi?id=218291
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Adopt set*PreferenceForTesting functions to match DumpRenderTree for cocoa platforms, and
     9        make it so that only TestOptions.cpp needs to be touched to add support for new preference
     10        in tests.
     11       
     12        Also adds some helpers to convert between string types and use RetainPtr in a few more places.
     13
     14        * DumpRenderTree/win/DumpRenderTree.cpp:
     15        (toUTF8):
     16        (toBSTR):
     17        (resetWebPreferencesToConsistentValues):
     18        (boolWebPreferenceFeatureValue):
     19        (setWebPreferencesForTestOptions):
     20        (runTest):
     21
    1222020-10-28  Aakash Jain  <aakash_jain@apple.com>
    223
  • trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp

    r269111 r269157  
    233233#endif
    234234
    235 string toUTF8(BSTR bstr)
     235std::string toUTF8(BSTR bstr)
    236236{
    237237    return toUTF8(bstr, SysStringLen(bstr));
    238238}
    239239
    240 string toUTF8(const wstring& wideString)
     240std::string toUTF8(const wstring& wideString)
    241241{
    242242    return toUTF8(wideString.c_str(), wideString.length());
     243}
     244
     245static std::string toUTF8(CFStringRef input)
     246{
     247    CFIndex maximumURLLengthAsUTF8 = CFStringGetMaximumSizeForEncoding(CFStringGetLength(input), kCFStringEncodingUTF8) + 1;
     248    Vector<char> buffer(maximumURLLengthAsUTF8 + 1, 0);
     249    CFStringGetCString(input, buffer.data(), maximumURLLengthAsUTF8, kCFStringEncodingUTF8);
     250
     251    return buffer.data();
    243252}
    244253
     
    249258
    250259    return wstring(v.data(), v.size());
     260}
     261
     262static _bstr_t toBSTR(const std::string& input)
     263{
     264    return input.c_str();
     265}
     266
     267static _bstr_t toBSTR(CFStringRef input)
     268{
     269    size_t stringLength = CFStringGetLength(input);
     270    Vector<UniChar> buffer(stringLength + 1, 0);
     271    CFStringGetCharacters(input, CFRangeMake(0, stringLength), buffer.data());
     272    return reinterpret_cast<wchar_t*>(buffer.data());
    251273}
    252274
     
    885907    prefsPrivate->setFrameFlatteningEnabled(FALSE);
    886908    if (persistentUserStyleSheetLocation) {
    887         size_t stringLength = CFStringGetLength(persistentUserStyleSheetLocation.get());
    888         Vector<UniChar> urlCharacters(stringLength + 1, 0);
    889         CFStringGetCharacters(persistentUserStyleSheetLocation.get(), CFRangeMake(0, stringLength), urlCharacters.data());
    890         _bstr_t url(reinterpret_cast<wchar_t*>(urlCharacters.data()));
    891         preferences->setUserStyleSheetLocation(url);
     909        preferences->setUserStyleSheetLocation(toBSTR(persistentUserStyleSheetLocation.get()));
    892910        preferences->setUserStyleSheetEnabled(TRUE);
    893911    } else
     
    913931}
    914932
    915 static bool boolWebPreferenceFeatureValue(std::string key, bool defaultValue, const WTR::TestOptions& options)
     933static bool boolWebPreferenceFeatureValue(std::string key, const WTR::TestOptions& options)
    916934{
    917935    auto it = options.boolWebPreferenceFeatures().find(key);
    918     if (it != options.boolWebPreferenceFeatures().end())
    919         return it->second;
    920     return defaultValue;
     936    ASSERT(it != options.boolWebPreferenceFeatures().end());
     937    return it->second;
    921938}
    922939
     
    927944    preferences->setPrivateBrowsingEnabled(options.useEphemeralSession());
    928945
    929     preferences->setUsesPageCache(boolWebPreferenceFeatureValue("UsesBackForwardCache", false, options));
    930     prefsPrivate->setMenuItemElementEnabled(boolWebPreferenceFeatureValue("MenuItemElementEnabled", false, options));
    931     prefsPrivate->setKeygenElementEnabled(boolWebPreferenceFeatureValue("KeygenElementEnabled", false, options));
    932     prefsPrivate->setModernMediaControlsEnabled(boolWebPreferenceFeatureValue("ModernMediaControlsEnabled", true, options));
    933     prefsPrivate->setInspectorAdditionsEnabled(boolWebPreferenceFeatureValue("InspectorAdditionsEnabled", false, options));
    934     prefsPrivate->setRequestIdleCallbackEnabled(boolWebPreferenceFeatureValue("RequestIdleCallbackEnabled", false, options));
    935     prefsPrivate->setAsyncClipboardAPIEnabled(boolWebPreferenceFeatureValue("AsyncClipboardAPIEnabled", false, options));
    936     prefsPrivate->setContactPickerAPIEnabled(boolWebPreferenceFeatureValue("ContactPickerAPIEnabled", false, options));
    937     prefsPrivate->setAllowTopNavigationToDataURLs(boolWebPreferenceFeatureValue("AllowTopNavigationToDataURLs", true, options));
    938     prefsPrivate->setCSSOMViewSmoothScrollingEnabled(boolWebPreferenceFeatureValue("CSSOMViewSmoothScrollingEnabled", false, options));
    939     prefsPrivate->setSpatialNavigationEnabled(boolWebPreferenceFeatureValue("SpatialNavigationEnabled", false, options));
    940     preferences->setTabsToLinks(boolWebPreferenceFeatureValue("TabsToLinks", false, options));
     946    // FIXME: Remove this once there is a viable mechanism for reseting WebPreferences between tests,
     947    // at which point, we will not need to manually reset every supported preference for each test.
     948    for (const auto& key : options.supportedBoolWebPreferenceFeatures())
     949        prefsPrivate->setBoolPreferenceForTesting(toBSTR(WTR::TestOptions::toWebKitLegacyPreferenceKey(key)), boolWebPreferenceFeatureValue(key, options));
    941950}
    942951
     
    11961205    static _bstr_t methodBStr(TEXT("GET"));
    11971206
    1198     CFStringRef str = CFStringCreateWithCString(0, pathOrURL.c_str(), kCFStringEncodingWindowsLatin1);
     1207    auto str = adoptCF(CFStringCreateWithCString(0, pathOrURL.c_str(), kCFStringEncodingWindowsLatin1));
    11991208    if (!str) {
    12001209        fprintf(stderr, "Failed to parse \"%s\" as UTF-8\n", pathOrURL.c_str());
     
    12021211    }
    12031212
    1204     CFURLRef url = CFURLCreateWithString(0, str, 0);
    1205 
     1213    auto url = adoptCF(CFURLCreateWithString(0, str.get(), 0));
    12061214    if (!url)
    1207         url = CFURLCreateWithFileSystemPath(0, str, kCFURLWindowsPathStyle, false);
    1208 
    1209     CFRelease(str);
     1215        url = adoptCF(CFURLCreateWithFileSystemPath(0, str.get(), kCFURLWindowsPathStyle, false));
    12101216
    12111217    if (!url) {
     
    12141220    }
    12151221
    1216     String hostName = String(adoptCF(CFURLCopyHostName(url)).get());
    1217 
     1222    String hostName = String(adoptCF(CFURLCopyHostName(url.get())).get());
    12181223    String fallbackPath = findFontFallback(pathOrURL.c_str());
    12191224
    1220     str = CFURLGetString(url);
    1221 
    1222     CFIndex length = CFStringGetLength(str);
    1223 
    1224     Vector<UniChar> buffer(length + 1, 0);
    1225     CFStringGetCharacters(str, CFRangeMake(0, length), buffer.data());
    1226 
    1227     _bstr_t urlBStr(reinterpret_cast<wchar_t*>(buffer.data()));
    1228     ASSERT(urlBStr.length() == length);
    1229 
    1230     CFIndex maximumURLLengthAsUTF8 = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
    1231     Vector<char> testURL(maximumURLLengthAsUTF8 + 1, 0);
    1232     CFStringGetCString(str, testURL.data(), maximumURLLengthAsUTF8, kCFStringEncodingUTF8);
    1233 
    1234     CFRelease(url);
     1225    auto urlCFString = CFURLGetString(url.get());
     1226
     1227    auto urlBStr = toBSTR(urlCFString);
     1228    ASSERT(urlBStr.length() == CFStringGetLength(urlCFString));
    12351229
    12361230    auto options = testOptionsForTest(command);
     
    12381232    resetWebViewToConsistentStateBeforeTesting(options);
    12391233
    1240     ::gTestRunner = TestRunner::create(testURL.data(), command.expectedPixelHash);
     1234    ::gTestRunner = TestRunner::create(toUTF8(urlCFString), command.expectedPixelHash);
    12411235    ::gTestRunner->setCustomTimeout(command.timeout.milliseconds());
    12421236    ::gTestRunner->setDumpJSConsoleLogInStdErr(command.dumpJSConsoleLogInStdErr || options.dumpJSConsoleLogInStdErr());
Note: See TracChangeset for help on using the changeset viewer.