Changeset 106005 in webkit


Ignore:
Timestamp:
Jan 26, 2012 9:10:28 AM (12 years ago)
Author:
caio.oliveira@openbossa.org
Message:

Implement overridePreference for boolean preferences in WebKitTestRunner
https://bugs.webkit.org/show_bug.cgi?id=77033

Reviewed by Alexey Proskuryakov.

Source/WebKit2:

Implement a way to WebKitTestRunner override preferences for the pages
loaded. Follows the same approach taken by
overrideXSSAuditorEnabledForTestRunner() from r66551, but generalizing to many
preferences.

Preferences are stored in the UI process using WebPreferencesStore, and when
there's a change, this data is sent to Web process, triggering
WebPage::preferencesDidChange(), which take a WebPreferencesStore and apply it's
data to the WebCore::Settings object.

The overridePreference() is executed on the Web process, and set the preferences
without communicating to the UI process. The overriden preferences are stored in
a static map and WebPreferencesStore query this map before returning the values
of each preference. This static map is used only on the Web process.

To clear the overrides we need to clear the map. Since WTR only sets preferences
when resetting the page, we hook the clearing at WebPage::preferencesDidChange().
A WKPreferences private function was exposed to WTR force the update, in case
there's no effective change at UI process (all the properties remains the same).

This clearing could be improved by creating a proper message instead of hooking
at WebPage::preferencesDidChange().

  • Shared/WebPreferencesStore.cpp:

(WebKit::WebPreferencesStore::decode):
(WebKit::WebPreferencesStore::overrideBoolValueForKey):
(WebKit::WebPreferencesStore::removeTestRunnerOverrides):
(WebKit::WebPreferencesStore::getBoolValueForKey):

  • Shared/WebPreferencesStore.h:
  • UIProcess/API/C/WKPreferences.cpp:

(WKPreferencesResetTestRunnerOverrides):

  • UIProcess/API/C/WKPreferencesPrivate.h:
  • UIProcess/WebPreferences.h:

(WebKit::WebPreferences::forceUpdate):

  • WebProcess/InjectedBundle/API/c/WKBundle.cpp:

(WKBundleOverrideBoolPreferenceForTestRunner):

  • WebProcess/InjectedBundle/API/c/WKBundlePrivate.h:
  • WebProcess/InjectedBundle/InjectedBundle.cpp:

(WebKit::InjectedBundle::overrideBoolPreferenceForTestRunner):
(WebKit::InjectedBundle::overrideXSSAuditorEnabledForTestRunner):

  • WebProcess/InjectedBundle/InjectedBundle.h:

Tools:

For now overridePreference supports boolean values.

  • WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl:
  • WebKitTestRunner/InjectedBundle/LayoutTestController.cpp:

(WTR::LayoutTestController::setXSSAuditorEnabled):
(WTR::LayoutTestController::overridePreference):

  • WebKitTestRunner/InjectedBundle/LayoutTestController.h:
  • WebKitTestRunner/TestController.cpp:

(WTR::TestController::resetStateToConsistentValues): Reset the overrides
explicitly and properly disable the use of PageCache when resetting the
state. Tests that use PageCache can now enable it via overridePreference.

LayoutTests:

  • platform/wk2/Skipped:
Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r106002 r106005  
     12012-01-26  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
     2
     3        Implement overridePreference for boolean preferences in WebKitTestRunner
     4        https://bugs.webkit.org/show_bug.cgi?id=77033
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        * platform/wk2/Skipped:
     9
    1102012-01-26  Balazs Kelemen  <kbalazs@webkit.org>
    211
  • trunk/LayoutTests/platform/wk2/Skipped

    r105988 r106005  
    193193fast/canvas/webgl/framebuffer-object-attachment.html
    194194fast/canvas/webgl/gl-vertex-attrib-zero-issues.html
    195 fast/events/pagehide-timeout.html
    196195fast/canvas/webgl/gl-getshadersource.html
    197196fast/canvas/webgl/tex-sub-image-2d-bad-args.html
     
    288287fast/canvas/webgl/webgl-array-invalid-ranges.html
    289288fast/canvas/webgl/webgl-specific.html
    290 fast/dom/Geolocation/no-page-cache.html
    291 fast/dom/Window/timer-resume-on-navigation-back.html
    292 fast/events/onunload-back-to-page-cache.html
    293 fast/events/pageshow-pagehide-on-back-cached-with-frames.html
    294 fast/events/pageshow-pagehide-on-back-cached.html
    295 fast/events/tab-focus-anchor.html
    296 fast/frames/frame-crash-with-page-cache.html
    297289fast/harness/override-preferences-2.html
    298 fast/harness/override-preferences.html
    299 fast/harness/page-cache-crash-on-data-urls.html
    300 fast/harness/use-page-cache.html
    301 fast/history/timed-refresh-in-cached-frame.html
    302290fast/images/animated-gif-restored-from-bfcache.html
    303 fast/loader/frames-with-unload-handlers-in-page-cache.html
    304 fast/loader/input-element-page-cache-crash.html
    305 fast/loader/scroll-position-restored-on-back.html
    306 fast/loader/stateobjects/popstate-fires-with-page-cache.html
    307 fast/loader/unschedule-relayout-after-unload.html
    308 fast/parser/noscript-with-javascript-disabled.html
    309 fast/parser/noscript-with-javascript-enabled.html
    310291fast/repaint/no-caret-repaint-in-non-content-editable-element.html
    311292fast/text/zero-font-size.html
    312293fast/text/international/locale-sensitive-fonts.html
    313 http/tests/appcache/disabled.html
    314 css3/filters/custom-filter-shader-cache.html
    315 css3/filters/effect-blur.html
    316 css3/filters/effect-brightness.html
    317 css3/filters/effect-contrast.html
    318 css3/filters/effect-custom-combined-missing.html
    319 css3/filters/effect-custom-parameters.html
    320 css3/filters/effect-drop-shadow.html
    321 css3/filters/effect-grayscale.html
    322 css3/filters/effect-hue-rotate.html
    323 css3/filters/effect-invert.html
    324 css3/filters/effect-opacity.html
    325 css3/filters/effect-saturate.html
    326 css3/filters/effect-sepia.html
    327 css3/filters/missing-custom-filter-shader.html
    328 css3/filters/effect-custom.html
    329 css3/filters/effect-custom-disabled.html
    330294css3/filters/effect-combined.html
    331295css3/filters/filter-repaint.html
  • trunk/Source/WebKit2/ChangeLog

    r106000 r106005  
     12012-01-26  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
     2
     3        Implement overridePreference for boolean preferences in WebKitTestRunner
     4        https://bugs.webkit.org/show_bug.cgi?id=77033
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        Implement a way to WebKitTestRunner override preferences for the pages
     9        loaded. Follows the same approach taken by
     10        overrideXSSAuditorEnabledForTestRunner() from r66551, but generalizing to many
     11        preferences.
     12
     13        Preferences are stored in the UI process using WebPreferencesStore, and when
     14        there's a change, this data is sent to Web process, triggering
     15        WebPage::preferencesDidChange(), which take a WebPreferencesStore and apply it's
     16        data to the WebCore::Settings object.
     17
     18        The overridePreference() is executed on the Web process, and set the preferences
     19        without communicating to the UI process. The overriden preferences are stored in
     20        a static map and WebPreferencesStore query this map before returning the values
     21        of each preference. This static map is used only on the Web process.
     22
     23        To clear the overrides we need to clear the map. Since WTR only sets preferences
     24        when resetting the page, we hook the clearing at WebPage::preferencesDidChange().
     25        A WKPreferences private function was exposed to WTR force the update, in case
     26        there's no effective change at UI process (all the properties remains the same).
     27
     28        This clearing could be improved by creating a proper message instead of hooking
     29        at WebPage::preferencesDidChange().
     30
     31        * Shared/WebPreferencesStore.cpp:
     32        (WebKit::WebPreferencesStore::decode):
     33        (WebKit::WebPreferencesStore::overrideBoolValueForKey):
     34        (WebKit::WebPreferencesStore::removeTestRunnerOverrides):
     35        (WebKit::WebPreferencesStore::getBoolValueForKey):
     36        * Shared/WebPreferencesStore.h:
     37        * UIProcess/API/C/WKPreferences.cpp:
     38        (WKPreferencesResetTestRunnerOverrides):
     39        * UIProcess/API/C/WKPreferencesPrivate.h:
     40        * UIProcess/WebPreferences.h:
     41        (WebKit::WebPreferences::forceUpdate):
     42        * WebProcess/InjectedBundle/API/c/WKBundle.cpp:
     43        (WKBundleOverrideBoolPreferenceForTestRunner):
     44        * WebProcess/InjectedBundle/API/c/WKBundlePrivate.h:
     45        * WebProcess/InjectedBundle/InjectedBundle.cpp:
     46        (WebKit::InjectedBundle::overrideBoolPreferenceForTestRunner):
     47        (WebKit::InjectedBundle::overrideXSSAuditorEnabledForTestRunner):
     48        * WebProcess/InjectedBundle/InjectedBundle.h:
     49
    1502012-01-26  Carlos Garcia Campos  <cgarcia@igalia.com>
    251
  • trunk/Source/WebKit2/Shared/WebPreferencesStore.cpp

    r95901 r106005  
    4949
    5050
    51 static bool hasXSSAuditorEnabledTestRunnerOverride;
    52 static bool xssAuditorEnabledTestRunnerOverride;
     51static HashMap<String, bool> boolTestRunnerOverridesMap;
    5352
    5453WebPreferencesStore::WebPreferencesStore()
     
    7473    if (!decoder->decode(result.m_doubleValues))
    7574        return false;
    76 
    77     if (hasXSSAuditorEnabledTestRunnerOverride)
    78         result.m_boolValues.set(WebPreferencesKey::xssAuditorEnabledKey(), xssAuditorEnabledTestRunnerOverride);
    79 
    8075    return true;
    8176}
    8277
    83 void WebPreferencesStore::overrideXSSAuditorEnabledForTestRunner(bool enabled)
    84 {
    85     hasXSSAuditorEnabledTestRunnerOverride = true;
    86     xssAuditorEnabledTestRunnerOverride = enabled;
     78void WebPreferencesStore::overrideBoolValueForKey(const String& key, bool value)
     79{
     80    boolTestRunnerOverridesMap.set(key, value);
    8781}
    8882
    8983void WebPreferencesStore::removeTestRunnerOverrides()
    9084{
    91     hasXSSAuditorEnabledTestRunnerOverride = false;
     85    boolTestRunnerOverridesMap.clear();
    9286}
    9387
     
    186180bool WebPreferencesStore::getBoolValueForKey(const String& key) const
    187181{
     182    // FIXME: Extend overriding to other key types used from LayoutTestController.
     183    HashMap<String, bool>::const_iterator it = boolTestRunnerOverridesMap.find(key);
     184    if (it != boolTestRunnerOverridesMap.end())
     185        return it->second;
    188186    return valueForKey(m_boolValues, key);
    189187}
  • trunk/Source/WebKit2/Shared/WebPreferencesStore.h

    r105571 r106005  
    215215    double getDoubleValueForKey(const String& key) const;
    216216
    217     static void overrideXSSAuditorEnabledForTestRunner(bool);
     217    // For WebKitTestRunner usage.
     218    static void overrideBoolValueForKey(const String& key, bool value);
    218219    static void removeTestRunnerOverrides();
    219220
  • trunk/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp

    r105485 r106005  
    732732    return toImpl(preferencesRef)->notificationsEnabled();
    733733}
     734
     735void WKPreferencesResetTestRunnerOverrides(WKPreferencesRef preferencesRef)
     736{
     737    // Currently we reset the overrides on the web process when preferencesDidChange() is called. Since WTR preferences
     738    // are usually always the same (in the UI process), they are not sent to web process, not triggering the reset.
     739    toImpl(preferencesRef)->forceUpdate();
     740}
  • trunk/Source/WebKit2/UIProcess/API/C/WKPreferencesPrivate.h

    r105485 r106005  
    161161WK_EXPORT bool WKPreferencesGetApplicationChromeModeEnabled(WKPreferencesRef preferencesRef);
    162162
     163WK_EXPORT void WKPreferencesResetTestRunnerOverrides(WKPreferencesRef preferencesRef);
     164
    163165#ifdef __cplusplus
    164166}
  • trunk/Source/WebKit2/UIProcess/WebPreferences.h

    r95901 r106005  
    7070#undef DECLARE_PREFERENCE_GETTER_AND_SETTERS
    7171
     72    // Exposed for WebKitTestRunner use only.
     73    void forceUpdate() { update(); }
     74
    7275private:
    7376    WebPreferences();
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.cpp

    r105988 r106005  
    127127}
    128128
    129 void WKBundleOverrideXSSAuditorEnabledForTestRunner(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, bool enabled)
    130 {
    131     toImpl(bundleRef)->overrideXSSAuditorEnabledForTestRunner(toImpl(pageGroupRef), enabled);
     129void WKBundleOverrideBoolPreferenceForTestRunner(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, WKStringRef preference, bool enabled)
     130{
     131    toImpl(bundleRef)->overrideBoolPreferenceForTestRunner(toImpl(pageGroupRef), toImpl(preference)->string(), enabled);
    132132}
    133133
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h

    r105988 r106005  
    6565
    6666// Will make WebProcess ignore this preference until a preferences change notification, only for WebKitTestRunner use.
    67 WK_EXPORT void WKBundleOverrideXSSAuditorEnabledForTestRunner(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled);
     67WK_EXPORT void WKBundleOverrideBoolPreferenceForTestRunner(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, WKStringRef preference, bool enabled);
     68
    6869WK_EXPORT void WKBundleSetAllowUniversalAccessFromFileURLs(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled);
    6970WK_EXPORT void WKBundleSetAllowFileAccessFromFileURLs(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled);
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp

    r105988 r106005  
    3232#include "InjectedBundleScriptWorld.h"
    3333#include "InjectedBundleUserMessageCoders.h"
     34#include "LayerTreeHost.h"
    3435#include "WKAPICast.h"
    3536#include "WKBundleAPICast.h"
     
    118119}
    119120
     121void InjectedBundle::overrideBoolPreferenceForTestRunner(WebPageGroupProxy* pageGroup, const String& preference, bool enabled)
     122{
     123    const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
     124
     125    // FIXME: Need an explicit way to set "WebKitTabToLinksPreferenceKey" directly in WebPage.
     126
     127    // Map the names used in LayoutTests with the names used in WebCore::Settings and WebPreferencesStore.
     128#define FOR_EACH_OVERRIDE_BOOL_PREFERENCE(macro) \
     129    macro(WebKitAcceleratedCompositingEnabled, AcceleratedCompositingEnabled, acceleratedCompositingEnabled) \
     130    macro(WebKitCSSCustomFilterEnabled, CSSCustomFilterEnabled, cssCustomFilterEnabled) \
     131    macro(WebKitJavaEnabled, JavaEnabled, javaEnabled) \
     132    macro(WebKitJavaScriptEnabled, ScriptEnabled, javaScriptEnabled) \
     133    macro(WebKitLoadSiteIconsKey, LoadsSiteIconsIgnoringImageLoadingSetting, loadsSiteIconsIgnoringImageLoadingPreference) \
     134    macro(WebKitOfflineWebApplicationCacheEnabled, OfflineWebApplicationCacheEnabled, offlineWebApplicationCacheEnabled) \
     135    macro(WebKitPageCacheSupportsPluginsPreferenceKey, PageCacheSupportsPlugins, pageCacheSupportsPlugins) \
     136    macro(WebKitPluginsEnabled, PluginsEnabled, pluginsEnabled) \
     137    macro(WebKitUsesPageCachePreferenceKey, UsesPageCache, usesPageCache) \
     138    macro(WebKitWebAudioEnabled, WebAudioEnabled, webAudioEnabled) \
     139    macro(WebKitWebGLEnabled, WebGLEnabled, webGLEnabled) \
     140    macro(WebKitXSSAuditorEnabled, XSSAuditorEnabled, xssAuditorEnabled)
     141
     142    if (preference == "WebKitAcceleratedCompositingEnabled")
     143        enabled = enabled && LayerTreeHost::supportsAcceleratedCompositing();
     144
     145#define OVERRIDE_PREFERENCE_AND_SET_IN_EXISTING_PAGES(TestRunnerName, SettingsName, WebPreferencesName) \
     146    if (preference == #TestRunnerName) { \
     147        WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::WebPreferencesName##Key(), enabled); \
     148        for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter) \
     149            (*iter)->settings()->set##SettingsName(enabled); \
     150        return; \
     151    }
     152
     153    FOR_EACH_OVERRIDE_BOOL_PREFERENCE(OVERRIDE_PREFERENCE_AND_SET_IN_EXISTING_PAGES)
     154
     155#if ENABLE(WEB_SOCKETS)
     156    OVERRIDE_PREFERENCE_AND_SET_IN_EXISTING_PAGES("WebKitHixie76WebSocketProtocolEnabled", UseHixie76WebSocketProtocol, hixie76WebSocketProtocolEnabled)
     157#endif
     158
     159#undef OVERRIDE_PREFERENCE_AND_SET_IN_EXISTING_PAGES
     160#undef FOR_EACH_OVERRIDE_BOOL_PREFERENCE
     161}
     162
    120163void InjectedBundle::overrideXSSAuditorEnabledForTestRunner(WebPageGroupProxy* pageGroup, bool enabled)
    121164{
    122165    // Override the preference for all future pages.
    123     WebPreferencesStore::overrideXSSAuditorEnabledForTestRunner(enabled);
     166    WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::xssAuditorEnabledKey(), enabled);
    124167
    125168    // Change the setting for existing ones.
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h

    r105988 r106005  
    9898    void removeAllVisitedLinks();
    9999    void activateMacFontAscentHack();
     100    void overrideBoolPreferenceForTestRunner(WebPageGroupProxy*, const String& preference, bool enabled);
    100101    void overrideXSSAuditorEnabledForTestRunner(WebPageGroupProxy* pageGroup, bool enabled);
    101102    void setAllowUniversalAccessFromFileURLs(WebPageGroupProxy*, bool);
  • trunk/Tools/ChangeLog

    r106004 r106005  
     12012-01-26  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
     2
     3        Implement overridePreference for boolean preferences in WebKitTestRunner
     4        https://bugs.webkit.org/show_bug.cgi?id=77033
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        For now overridePreference supports boolean values.
     9
     10        * WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl:
     11        * WebKitTestRunner/InjectedBundle/LayoutTestController.cpp:
     12        (WTR::LayoutTestController::setXSSAuditorEnabled):
     13        (WTR::LayoutTestController::overridePreference):
     14        * WebKitTestRunner/InjectedBundle/LayoutTestController.h:
     15        * WebKitTestRunner/TestController.cpp:
     16        (WTR::TestController::resetStateToConsistentValues): Reset the overrides
     17        explicitly and properly disable the use of PageCache when resetting the
     18        state. Tests that use PageCache can now enable it via overridePreference.
     19
    1202012-01-26  Alexander Færøy  <alexander.faeroy@nokia.com>
    221
  • trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl

    r105988 r106005  
    134134
    135135        void setWindowIsKey(in boolean isKey);
    136        
     136
     137        // FIXME: handle non-boolean preferences.
     138        void overridePreference(in DOMString preference, in boolean value);
     139
    137140        readonly attribute DOMString platformName;
    138141    };
  • trunk/Tools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp

    r105988 r106005  
    351351void LayoutTestController::setXSSAuditorEnabled(bool enabled)
    352352{
    353     WKBundleOverrideXSSAuditorEnabledForTestRunner(InjectedBundle::shared().bundle(), InjectedBundle::shared().pageGroup(), true);
     353    WKRetainPtr<WKStringRef> key(AdoptWK, WKStringCreateWithUTF8CString("WebKitXSSAuditorEnabled"));
     354    WKBundleOverrideBoolPreferenceForTestRunner(InjectedBundle::shared().bundle(), InjectedBundle::shared().pageGroup(), key.get(), enabled);
    354355}
    355356
     
    614615}
    615616
     617void LayoutTestController::overridePreference(JSStringRef preference, bool value)
     618{
     619    WKBundleOverrideBoolPreferenceForTestRunner(InjectedBundle::shared().bundle(), InjectedBundle::shared().pageGroup(), toWK(preference).get(), value);
     620}
     621
    616622} // namespace WTR
  • trunk/Tools/WebKitTestRunner/InjectedBundle/LayoutTestController.h

    r105988 r106005  
    193193    void callSetBackingScaleFactorCallback();
    194194
     195    void overridePreference(JSStringRef preference, bool value);
     196
    195197    JSRetainPtr<JSStringRef> platformName();
    196198   
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r104910 r106005  
    416416    // Reset preferences
    417417    WKPreferencesRef preferences = WKPageGroupGetPreferences(m_pageGroup.get());
     418    WKPreferencesResetTestRunnerOverrides(preferences);
    418419    WKPreferencesSetOfflineWebApplicationCacheEnabled(preferences, true);
    419420    WKPreferencesSetFontSmoothingLevel(preferences, kWKFontSmoothingLevelNoSubpixelAntiAliasing);
     
    428429    WKPreferencesSetFullScreenEnabled(preferences, true);
    429430#endif
     431    WKPreferencesSetPageCacheEnabled(preferences, false);
    430432
    431433// [Qt][WK2]REGRESSION(r104881):It broke hundreds of tests
Note: See TracChangeset for help on using the changeset viewer.