2008-12-10 Glenn Wilson <gwilson@google.com>
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Dec 2008 19:10:47 +0000 (19:10 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Dec 2008 19:10:47 +0000 (19:10 +0000)
        Reviewed by Adam Roben.

        Added new methods for overriding default WebPreference values
        and for resetting preferences to their defaults.
        https://bugs.webkit.org/show_bug.cgi?id=20534

        * WebView/WebPreferenceKeysPrivate.h:
        * WebView/WebPreferences.mm:
        (-[WebPreferences resetToDefaults]): new method
        (-[WebPreferences overridePreference:flag:]): new method
        * WebView/WebPreferencesPrivate.h: new method signatures

2008-12-10  Glenn Wilson  <gwilson@google.com>

        Reviewed by Adam Roben.

        Added support for overriding default preferences per-test.
        https://bugs.webkit.org/show_bug.cgi?id=20534
        Two new methods were added: resetToDefaults and overridePreference.

        * Interfaces/IWebPreferencesPrivate.idl: new method signatures
        * WebPreferenceKeysPrivate.h: added new key for internal state
        * WebPreferences.cpp: added new methods
        (WebPreferences::overridePreference): new method
        (WebPreferences::resetToDefaults): new method
        * WebPreferences.h: new method signatures

2008-12-10  Glenn Wilson  <gwilson@google.com>

        Reviewed by Adam Roben.

        Changed LayoutTestController and DumpRenderTree to allow for manual
        overriding of default preferences at test time.  Also added support for
        resetting the preferences after each test.
        https://bugs.webkit.org/show_bug.cgi?id=20534

        * DumpRenderTree/LayoutTestController.cpp: Added callback method for overriding preferences
        * DumpRenderTree/LayoutTestController.h: Added signature for callback
        * DumpRenderTree/win/DumpRenderTree.cpp: Added calls to reset preferences after each test if necessary
        * DumpRenderTree/win/LayoutTestControllerWin.cpp: Added JS override function
        * DumpRenderTree/mac/DumpRenderTree.mm: Added calls to reset preferences after each test if necessary
        * DumpRenderTree/mac/LayoutTestControllerMac.mm: Added JS override function

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@39212 268f45cc-cd09-0410-ab3c-d52691b4dbfc

22 files changed:
LayoutTests/security/override-preferences-2-expected.txt [new file with mode: 0644]
LayoutTests/security/override-preferences-2.html [new file with mode: 0644]
LayoutTests/security/override-preferences-expected.txt [new file with mode: 0644]
LayoutTests/security/override-preferences.html [new file with mode: 0644]
LayoutTests/security/override-zzz-reset-expected.txt [new file with mode: 0644]
LayoutTests/security/override-zzz-reset.html [new file with mode: 0644]
WebKit/mac/ChangeLog
WebKit/mac/WebView/WebPreferenceKeysPrivate.h
WebKit/mac/WebView/WebPreferences.mm
WebKit/mac/WebView/WebPreferencesPrivate.h
WebKit/win/ChangeLog
WebKit/win/Interfaces/IWebPreferencesPrivate.idl
WebKit/win/WebPreferenceKeysPrivate.h
WebKit/win/WebPreferences.cpp
WebKit/win/WebPreferences.h
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/LayoutTestController.cpp
WebKitTools/DumpRenderTree/LayoutTestController.h
WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm
WebKitTools/DumpRenderTree/mac/LayoutTestControllerMac.mm
WebKitTools/DumpRenderTree/win/DumpRenderTree.cpp
WebKitTools/DumpRenderTree/win/LayoutTestControllerWin.cpp

diff --git a/LayoutTests/security/override-preferences-2-expected.txt b/LayoutTests/security/override-preferences-2-expected.txt
new file mode 100644 (file)
index 0000000..abcceaa
--- /dev/null
@@ -0,0 +1,3 @@
+This test verifies that layoutTestController can have its default preferences overriden. This test verifies that the API will accept string values and also override the default font size. You should see "PASS" below.
+
+PASS
diff --git a/LayoutTests/security/override-preferences-2.html b/LayoutTests/security/override-preferences-2.html
new file mode 100644 (file)
index 0000000..23056f4
--- /dev/null
@@ -0,0 +1,18 @@
+<html>
+<script>
+    if(window.layoutTestController) {
+        layoutTestController.dumpAsText();
+        layoutTestController.overridePreference("WebKitDefaultFontSize", "24");
+    }
+</script>
+<body>
+    <p>This test verifies that layoutTestController can have its default preferences overriden.  
+    This test verifies that the API will accept string values and also override the default font size.  
+    You should see "PASS" below.</p>
+    <script>
+        var p = document.getElementsByTagName("p")[0];
+        if(!window.layoutTestController || window.getComputedStyle(p).fontSize == "24px")
+            document.write("PASS");
+    </script>
+</body>
+</html>
diff --git a/LayoutTests/security/override-preferences-expected.txt b/LayoutTests/security/override-preferences-expected.txt
new file mode 100644 (file)
index 0000000..4c348e0
--- /dev/null
@@ -0,0 +1,3 @@
+This is a test that verifies that layoutTestController can have its default preferences overridden. This test specifically checks that Javascript can be disabled, and you should see "PASS" below if viewing with a browser.
+
+PASS
diff --git a/LayoutTests/security/override-preferences.html b/LayoutTests/security/override-preferences.html
new file mode 100644 (file)
index 0000000..740a739
--- /dev/null
@@ -0,0 +1,18 @@
+<html> 
+<body> 
+<script> 
+    if(window.layoutTestController) {
+        layoutTestController.dumpAsText()
+        layoutTestController.overridePreference("WebKitJavaScriptEnabled", false);
+    }
+    
+    function loadstatus() {
+        if(window.layoutTestController)
+            document.getElementById("status").innerHTML="FAIL";
+    }
+</script> 
+<body onload="loadstatus()">
+    <p>This is a test that verifies that layoutTestController can have its default preferences overridden.  This test specifically checks that Javascript can be disabled, and you should see "PASS" below if viewing with a browser.</p>
+    <span id="status">PASS</span>
+</body>
+</html>
diff --git a/LayoutTests/security/override-zzz-reset-expected.txt b/LayoutTests/security/override-zzz-reset-expected.txt
new file mode 100644 (file)
index 0000000..dee292e
--- /dev/null
@@ -0,0 +1,3 @@
+This test verifies that the layoutTestController will reset its default preferences after every layout test. You should see "PASS" below.
+
+PASS
diff --git a/LayoutTests/security/override-zzz-reset.html b/LayoutTests/security/override-zzz-reset.html
new file mode 100644 (file)
index 0000000..cbeb1e0
--- /dev/null
@@ -0,0 +1,14 @@
+<html> 
+<body> 
+<script> 
+    if(window.layoutTestController)
+        layoutTestController.dumpAsText();
+</script> 
+<body>
+    <p>This test verifies that the layoutTestController will reset its default preferences after every layout test.  You should see "PASS" below.</p>
+    <span id="status">FAIL</span>
+    <script>
+        document.getElementById("status").innerHTML="PASS";        
+    </script>
+</body>
+</html>
index 10d907e..e9bae07 100644 (file)
@@ -1,3 +1,17 @@
+2008-12-10  Glenn Wilson  <gwilson@google.com>
+
+        Reviewed by Adam Roben.
+
+        Added new methods for overriding default WebPreference values
+        and for resetting preferences to their defaults.
+        https://bugs.webkit.org/show_bug.cgi?id=20534
+
+        * WebView/WebPreferenceKeysPrivate.h:
+        * WebView/WebPreferences.mm:
+        (-[WebPreferences resetToDefaults]): new method
+        (-[WebPreferences overridePreference:flag:]): new method
+        * WebView/WebPreferencesPrivate.h: new method signatures
+
 2008-12-10  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Darin Adler.
index 98daec0..d009e44 100644 (file)
@@ -72,6 +72,7 @@
 #define WebKitEnableFullDocumentTeardownPreferenceKey @"WebKitEnableFullDocumentTeardown"
 #define WebKitOfflineWebApplicationCacheEnabledPreferenceKey @"WebKitOfflineWebApplicationCacheEnabled"
 #define WebKitZoomsTextOnlyPreferenceKey @"WebKitZoomsTextOnly"
+#define WebKitDefaultPreferencesOverridden @"WebKitDefaultPreferencesOverridden"
 
 // These are private both because callers should be using the cover methods and because the
 // cover methods themselves are private.
index e595861..1d604f5 100644 (file)
@@ -1095,6 +1095,25 @@ static NSString *classIBCreatorID = nil;
 {
     return [self _boolValueForKey:WebKitEnableFullDocumentTeardownPreferenceKey];
 }
+
+- (void)resetToDefaults
+{
+    if (![self _boolValueForKey:WebKitDefaultPreferencesOverridden])
+        return;
+    [self init];
+
+    [self _setBoolValue:false forKey:WebKitDefaultPreferencesOverridden];
+    [self _postPreferencesChangesNotification];
+}
+
+- (void)overridePreference:(NSString *)key flag:(NSString *)preferenceFlag
+{
+    [self _setStringValue:preferenceFlag forKey:key];
+    [self _setBoolValue:true forKey:WebKitDefaultPreferencesOverridden];
+}
+
+
+
 @end
 
 @implementation WebPreferences (WebInternal)
index 99ff49c..624683e 100644 (file)
@@ -102,6 +102,15 @@ extern NSString *WebPreferencesRemovedNotification;
 - (WebTextDirectionSubmenuInclusionBehavior)textDirectionSubmenuInclusionBehavior;
 - (void)setTextDirectionSubmenuInclusionBehavior:(WebTextDirectionSubmenuInclusionBehavior)behavior;
 
+// This method is meant for overriding preferences for tests run
+// with DumpRenderTree only.
+-(void)overridePreference:(NSString *)key flag:(NSString *)flag;
+
+// This method is meant for resetting overridden preferences for tests run
+// with DumpRenderTree only.
+-(void)resetToDefaults;
+
+
 // If site-specific spoofing is enabled, some pages that do inappropriate user-agent string checks will be
 // passed a nonstandard user-agent string to get them to work correctly. This method might be removed in
 // the future when there's no more need for it.
index 5553c4c..861ec1d 100644 (file)
@@ -1,3 +1,18 @@
+2008-12-10  Glenn Wilson  <gwilson@google.com>
+
+        Reviewed by Adam Roben.
+
+        Added support for overriding default preferences per-test.
+        https://bugs.webkit.org/show_bug.cgi?id=20534
+        Two new methods were added: resetToDefaults and overridePreference.
+
+        * Interfaces/IWebPreferencesPrivate.idl: new method signatures
+        * WebPreferenceKeysPrivate.h: added new key for internal state
+        * WebPreferences.cpp: added new methods
+        (WebPreferences::overridePreference): new method
+        (WebPreferences::resetToDefaults): new method
+        * WebPreferences.h: new method signatures
+
 2008-12-08  Tor Arne Vestbø  <tavestbo@trolltech.com>
 
         Reviewed by Darin Adler and Holger Freyther.
index 62ed0be..76397e4 100644 (file)
@@ -66,4 +66,13 @@ interface IWebPreferencesPrivate : IUnknown
 
     HRESULT setLocalStorageEnabled([in] BOOL enabled);
     HRESULT localStorageEnabled([out, retval] BOOL *enabled);
+
+    // This method is meant for overriding preferences for tests run
+    // with DumpRenderTree only.
+    HRESULT overridePreference([in] BSTR key, [in] BSTR value);
+
+    // This method is meant for resetting overridden preferences for tests run
+    // with DumpRenderTree only.
+    HRESULT resetToDefaults();
+
 }
index b74fc04..b2e1296 100644 (file)
@@ -62,6 +62,7 @@
 #define WebKitUsesPageCachePreferenceKey "WebKitUsesPageCachePreferenceKey"
 #define WebKitCacheModelPreferenceKey "WebKitCacheModelPreferenceKey"
 #define WebKitLocalStorageDatabasePathPreferenceKey "WebKitLocalStorageDatabasePath"
+#define WebKitDefaultPreferencesOverridden "WebKitDefaultPreferencesOverridden"
 
 // These are private both because callers should be using the cover methods and because the
 // cover methods themselves are private.
index 5ad5cb1..3f35c4c 100644 (file)
@@ -1223,6 +1223,39 @@ HRESULT WebPreferences::zoomsTextOnly(BOOL* zoomsTextOnly)
     return S_OK;
 }
 
+HRESULT STDMETHODCALLTYPE WebPreferences::overridePreference(BSTR key, BSTR value)
+{
+    if (!SysStringLen(key) || !SysStringLen(value))
+        return E_FAIL;
+    RetainPtr<CFStringRef> keyRef(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<UniChar*>(key), SysStringLen(key)));
+    setStringValue(keyRef.get(), value);
+    setBoolValue(CFSTR(WebKitDefaultPreferencesOverridden), true);
+    return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE WebPreferences::resetToDefaults()
+{
+    if (!boolValueForKey(CFSTR(WebKitDefaultPreferencesOverridden)))
+        return S_OK;
+
+    int count = CFDictionaryGetCount(defaultSettings);
+    if (count <= 0)
+        return S_OK;
+
+    OwnArrayPtr<CFTypeRef> keys(new CFTypeRef[count]);
+    OwnArrayPtr<CFTypeRef> values(new CFTypeRef[count]);
+    CFDictionaryGetKeysAndValues(defaultSettings, keys.get(), values.get());
+
+    for (int i = 0; i < count; ++i)
+        setValueForKey(static_cast<CFStringRef>(keys[i]), values[i]);
+
+    setBoolValue(CFSTR(WebKitDefaultPreferencesOverridden), false);
+
+    postPreferencesChangesNotification();
+
+    return S_OK;
+}
+
 void WebPreferences::willAddToWebView()
 {
     ++m_numWebViews;
index 1dbcd31..dd5f60e 100644 (file)
@@ -338,6 +338,16 @@ public:
     virtual HRESULT STDMETHODCALLTYPE zoomsTextOnly( 
     /* [retval][out] */ BOOL *zoomsTextOnly);
 
+    // This method is meant for overriding preferences for tests run
+    // with DumpRenderTree only.
+    virtual HRESULT STDMETHODCALLTYPE overridePreference(
+        /* [in] */ BSTR key,
+        /* [in] */ BSTR value);
+
+    // This method is meant for resetting overridden preferences for tests run
+    // with DumpRenderTree only.
+    virtual HRESULT STDMETHODCALLTYPE resetToDefaults();
+
     // WebPreferences
 
     // This method accesses a different preference key than developerExtrasEnabled.
index 885805c..9b99b71 100644 (file)
@@ -1,6 +1,22 @@
+2008-12-10  Glenn Wilson  <gwilson@google.com>
+
+        Reviewed by Adam Roben.
+
+        Changed LayoutTestController and DumpRenderTree to allow for manual
+        overriding of default preferences at test time.  Also added support for
+        resetting the preferences after each test.
+        https://bugs.webkit.org/show_bug.cgi?id=20534
+
+        * DumpRenderTree/LayoutTestController.cpp: Added callback method for overriding preferences
+        * DumpRenderTree/LayoutTestController.h: Added signature for callback
+        * DumpRenderTree/win/DumpRenderTree.cpp: Added calls to reset preferences after each test if necessary
+        * DumpRenderTree/win/LayoutTestControllerWin.cpp: Added JS override function
+        * DumpRenderTree/mac/DumpRenderTree.mm: Added calls to reset preferences after each test if necessary
+        * DumpRenderTree/mac/LayoutTestControllerMac.mm: Added JS override function
+
 2008-12-10  Brady Eidson  <beidson@apple.com>
 
-        Reviewed by Darin
+        Reviewed by Darin Adler.
         
         Implement the new policy delegate (including navigation type and permissive mode) for DRT/win 
 
index cd55130..bf819f2 100644 (file)
@@ -348,6 +348,22 @@ static JSValueRef isCommandEnabledCallback(JSContextRef context, JSObjectRef fun
     return JSValueMakeBoolean(context, controller->isCommandEnabled(name.get()));
 }
 
+static JSValueRef overridePreferenceCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    if (argumentCount < 2)
+        return JSValueMakeUndefined(context);
+
+    JSRetainPtr<JSStringRef> key(Adopt, JSValueToStringCopy(context, arguments[0], exception));
+    ASSERT(!*exception);
+    JSRetainPtr<JSStringRef> value(Adopt, JSValueToStringCopy(context, arguments[1], exception));
+    ASSERT(!*exception);
+
+    LayoutTestController* controller = reinterpret_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
+    controller->overridePreference(key.get(), value.get());
+
+    return JSValueMakeUndefined(context);
+}
+
 static JSValueRef keepWebHistoryCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
     // Has mac implementation
@@ -802,6 +818,7 @@ JSStaticFunction* LayoutTestController::staticFunctions()
         { "isCommandEnabled", isCommandEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "keepWebHistory", keepWebHistoryCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "notifyDone", notifyDoneCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "overridePreference", overridePreferenceCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "pathToLocalResource", pathToLocalResourceCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "queueBackNavigation", queueBackNavigationCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "queueForwardNavigation", queueForwardNavigationCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
index 0d0fd5a..c37736a 100644 (file)
@@ -73,6 +73,7 @@ public:
     void setUserStyleSheetLocation(JSStringRef path);
     void setPersistentUserStyleSheetLocation(JSStringRef path);
     void clearPersistentUserStyleSheet();
+    void overridePreference(JSStringRef key, JSStringRef flag);
     int windowCount();
     
     bool elementDoesAutoCompleteForElementWithId(JSStringRef id);
index afb2b0d..c67b46c 100644 (file)
@@ -978,6 +978,7 @@ static void resetWebViewToConsistentStateBeforeTesting()
     [webView _clearMainFrameName];
 
     WebPreferences *preferences = [webView preferences];
+    [preferences resetToDefaults];
     [preferences setPrivateBrowsingEnabled:NO];
     [preferences setAuthorAndUserStylesEnabled:YES];
     [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
index c475cdc..965a4ad 100644 (file)
@@ -267,6 +267,17 @@ void LayoutTestController::setUserStyleSheetLocation(JSStringRef path)
     [[WebPreferences standardPreferences] setUserStyleSheetLocation:url];
 }
 
+void LayoutTestController::overridePreference(JSStringRef key, JSStringRef flag)
+{
+    RetainPtr<CFStringRef> keyCF(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, key));
+    NSString *keyNS = (NSString *)keyCF.get();
+
+    RetainPtr<CFStringRef> flagCF(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, flag));
+    NSString *flagNS = (NSString *)flagCF.get();
+
+    [[WebPreferences standardPreferences] overridePreference:keyNS flag:flagNS];
+}
+
 void LayoutTestController::setPersistentUserStyleSheetLocation(JSStringRef jsURL)
 {
     RetainPtr<CFStringRef> urlString(AdoptCF, JSStringCopyCFString(0, jsURL));
index c844991..605783d 100644 (file)
@@ -656,6 +656,7 @@ static void resetWebViewToConsistentStateBeforeTesting()
 
         COMPtr<IWebPreferencesPrivate> prefsPrivate(Query, preferences);
         if (prefsPrivate) {
+            prefsPrivate->resetToDefaults();
             prefsPrivate->setAuthorAndUserStylesEnabled(TRUE);
             prefsPrivate->setDeveloperExtrasEnabled(FALSE);
         }
index 45d4a2d..98af68e 100644 (file)
@@ -41,6 +41,7 @@
 #include <JavaScriptCore/Assertions.h>
 #include <JavaScriptCore/JavaScriptCore.h>
 #include <JavaScriptCore/JSRetainPtr.h>
+#include <JavaScriptCore/JSStringRefBSTR.h>
 #include <WebKit/WebKit.h>
 #include <string>
 #include <CoreFoundation/CoreFoundation.h>
@@ -658,3 +659,24 @@ bool LayoutTestController::pauseTransitionAtTimeOnElementWithId(JSStringRef prop
 {
     return false; // FIXME: Implement this on Windows
 }
+
+void LayoutTestController::overridePreference(JSStringRef key, JSStringRef flag)
+{
+    COMPtr<IWebView> webView;
+    if (FAILED(frame->webView(&webView)))
+        return;
+
+    COMPtr<IWebPreferences> preferences;
+    if (FAILED(webView->preferences(&preferences)))
+        return;
+
+    COMPtr<IWebPreferencesPrivate> prefsPrivate(Query, preferences);
+    if (!prefsPrivate)
+        return;
+
+    BSTR keyBSTR = JSStringCopyBSTR(key);
+    BSTR flagBSTR = JSStringCopyBSTR(flag);
+    prefsPrivate->overridePreference(keyBSTR, flagBSTR);
+    SysFreeString(keyBSTR);
+    SysFreeString(flagBSTR);
+}