Re-land the patch for https://bugs.webkit.org/show_bug.cgi?id=20534.
authordimich@chromium.org <dimich@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Aug 2009 17:42:43 +0000 (17:42 +0000)
committerdimich@chromium.org <dimich@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Aug 2009 17:42:43 +0000 (17:42 +0000)
Previously reverted since incorrect merge on landing has caused Layout Tests failures on Windows.

WebKit/mac: Added support for overriding default preferences per-test.
Originally implemented by Glenn Wilson <gwilson@chromium.org>.
Reviewed by Adam Roben.
Added new methods for overriding default WebPreference values
and for resetting preferences to their defaults.
See https://bugs.webkit.org/show_bug.cgi?id=20534

* WebView/WebPreferences.mm:
(-[WebPreferences _setPreferenceForTestWithValue:withKey:]): added.
* WebView/WebPreferencesPrivate.h: same.

WebKit/win: Added support for overriding default preferences per-test.
Originally implemented by Glenn Wilson  <gwilson@chromium.org>.
Reviewed by Adam Roben.
Added support for overriding default preferences per-test.
See https://bugs.webkit.org/show_bug.cgi?id=20534

* Interfaces/IWebPreferencesPrivate.idl: added new method setPreferenceForTest
* WebPreferences.cpp: same.
* WebPreferences.h: same.

WebKitTools: Added support for overriding default preferences per-test.
Originally implemented by Glenn Wilson  <gwilson@chromium.org>.
Reviewed by Adam Roben.
Added support for overriding default preferences per-test.
See https://bugs.webkit.org/show_bug.cgi?id=20534

* DumpRenderTree/LayoutTestController.cpp:
(overridePreferenceCallback): add wiring for layoutTestController.overridePreference.
(LayoutTestController::staticFunctions): same.
* DumpRenderTree/LayoutTestController.h: same.
* DumpRenderTree/gtk/LayoutTestControllerGtk.cpp:
(LayoutTestController::overridePreference): added empty overridePreference method.
* DumpRenderTree/mac/DumpRenderTree.mm: implemented preference override.
(resetDefaultsToConsistentValues): new method, resets preferences to same set of value before every test.
(setDefaultsToConsistentValuesForTesting): new method, sets other details of testing environment, every time  DRT starts.
(resetWebViewToConsistentStateBeforeTesting): move some preference setting from here to new resetDefaultsToConsistentValues().
* DumpRenderTree/mac/LayoutTestControllerMac.mm:
(LayoutTestController::overridePreference):
* DumpRenderTree/win/DumpRenderTree.cpp:
(resetDefaultsToConsistentValues): new method, resets preferences to same set of value before every test.
(resetWebViewToConsistentStateBeforeTesting): move some preference setting from here to new resetDefaultsToConsistentValues().
(createWebViewAndOffscreenWindow): same.
(main): same.
* DumpRenderTree/win/LayoutTestControllerWin.cpp:
(LayoutTestController::overridePreference):
* DumpRenderTree/wx/LayoutTestControllerWx.cpp:
(LayoutTestController::overridePreference):

LayoutTests: Added support for overriding default preferences per-test.
Originally implemented by Glenn Wilson  <gwilson@chromium.org>.
Reviewed by Adam Roben.
Added tests to verify that default preferences can be overridden per-test
and that overridden values are reset between each test.
See https://bugs.webkit.org/show_bug.cgi?id=20534

* fast/harness/override-preferences-2-expected.txt: Added.
* fast/harness/override-preferences-2.html: Added. Verifies overridePreverence("WebKitDefaultFontSize", "24").
* fast/harness/override-preferences-expected.txt: Added.
* fast/harness/override-preferences.html: Added. Verifies overridePreference("WebKitJavaScriptEnabled", false).
* fast/harness/override-zzz-reset-expected.txt: Added.
* fast/harness/override-zzz-reset.html: Added. Because of 'zzz' this test will run after the tests above and
verify that override of preferences does not 'spill' to the subsequent tests in a batch.
* platform/gtk/Skipped: Tests above disabled for GTK until GTK DRT implements preference override.

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

25 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/harness/override-preferences-2-expected.txt [new file with mode: 0644]
LayoutTests/fast/harness/override-preferences-2.html [new file with mode: 0644]
LayoutTests/fast/harness/override-preferences-expected.txt [new file with mode: 0644]
LayoutTests/fast/harness/override-preferences.html [new file with mode: 0644]
LayoutTests/fast/harness/override-zzz-reset-expected.txt [new file with mode: 0644]
LayoutTests/fast/harness/override-zzz-reset.html [new file with mode: 0644]
LayoutTests/platform/gtk/Skipped
LayoutTests/platform/qt/Skipped
WebKit/mac/ChangeLog
WebKit/mac/WebView/WebPreferences.mm
WebKit/mac/WebView/WebPreferencesPrivate.h
WebKit/win/ChangeLog
WebKit/win/Interfaces/IWebPreferencesPrivate.idl
WebKit/win/WebPreferences.cpp
WebKit/win/WebPreferences.h
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/LayoutTestController.cpp
WebKitTools/DumpRenderTree/LayoutTestController.h
WebKitTools/DumpRenderTree/gtk/LayoutTestControllerGtk.cpp
WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm
WebKitTools/DumpRenderTree/mac/LayoutTestControllerMac.mm
WebKitTools/DumpRenderTree/win/DumpRenderTree.cpp
WebKitTools/DumpRenderTree/win/LayoutTestControllerWin.cpp
WebKitTools/DumpRenderTree/wx/LayoutTestControllerWx.cpp

index 422c3a2..462cf31 100644 (file)
@@ -1,3 +1,22 @@
+2009-08-11  Dmitry Titov  <dimich@chromium.org>
+
+        Reviewed by Adam Roben.
+
+        Originally implemented by Glenn Wilson  <gwilson@chromium.org>.
+
+        Added tests to verify that default preferences can be overridden per-test
+        and that overridden values are reset between each test.
+        See https://bugs.webkit.org/show_bug.cgi?id=20534
+
+        * fast/harness/override-preferences-2-expected.txt: Added.
+        * fast/harness/override-preferences-2.html: Added. Verifies overridePreverence("WebKitDefaultFontSize", "24").
+        * fast/harness/override-preferences-expected.txt: Added.
+        * fast/harness/override-preferences.html: Added. Verifies overridePreference("WebKitJavaScriptEnabled", false).
+        * fast/harness/override-zzz-reset-expected.txt: Added.
+        * fast/harness/override-zzz-reset.html: Added. Because of 'zzz' this test will run after the tests above and
+        verify that override of preferences does not 'spill' to the subsequent tests in a batch.
+        * platform/gtk/Skipped: Tests above disabled for GTK until GTK DRT implements preference override.
+
 2009-08-11  Mike Fenton  <mike.fenton@torchmobile.com>
 
         Reviewed by Adam Treat.
diff --git a/LayoutTests/fast/harness/override-preferences-2-expected.txt b/LayoutTests/fast/harness/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/fast/harness/override-preferences-2.html b/LayoutTests/fast/harness/override-preferences-2.html
new file mode 100644 (file)
index 0000000..bdb7164
--- /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/fast/harness/override-preferences-expected.txt b/LayoutTests/fast/harness/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/fast/harness/override-preferences.html b/LayoutTests/fast/harness/override-preferences.html
new file mode 100644 (file)
index 0000000..523589a
--- /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/fast/harness/override-zzz-reset-expected.txt b/LayoutTests/fast/harness/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/fast/harness/override-zzz-reset.html b/LayoutTests/fast/harness/override-zzz-reset.html
new file mode 100644 (file)
index 0000000..b5ae06e
--- /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 73f2190..b723a2c 100644 (file)
@@ -5974,3 +5974,8 @@ http/tests/misc/will-send-request-returns-null-on-redirect.html
 
 # https://bugs.webkit.org/show_bug.cgi?id=28088 -- document.activeElement does not work
 editing/selection/find-in-text-control.html
+
+# Missing DRT ability to override 'standard' preferences.
+fast/harness/override-preferences.html
+fast/harness/override-preferences-2.html
+fast/harness/override-zzz-reset.html
index e3c0774..42aba88 100644 (file)
@@ -5116,3 +5116,8 @@ printing/media-queries-print.html
 fast/css/positioned-overflow-scroll.html
 fast/forms/select-popup-pagekeys.html
 fast/dom/prototype-inheritance-2.html
+
+# Missing DRT ability to override 'standard' preferences.
+fast/harness/override-preferences.html
+fast/harness/override-preferences-2.html
+fast/harness/override-zzz-reset.html
index e35709c..901ee1a 100644 (file)
@@ -1,3 +1,17 @@
+2009-08-11  Dmitry Titov  <dimich@chromium.org>
+
+        Reviewed by Adam Roben.
+
+        Originally implemented by Glenn Wilson <gwilson@chromium.org>.
+
+        Added new methods for overriding default WebPreference values
+        and for resetting preferences to their defaults.
+        See https://bugs.webkit.org/show_bug.cgi?id=20534
+
+        * WebView/WebPreferences.mm:
+        (-[WebPreferences _setPreferenceForTestWithValue:withKey:]): added.
+        * WebView/WebPreferencesPrivate.h: same.
+
 2009-08-09  Nikolas Zimmermann  <nikolas.zimmermann@torchmobile.com>
 
         Reviewed by George Staikos.
index 378b280..0b40b59 100644 (file)
@@ -1152,6 +1152,12 @@ static NSString *classIBCreatorID = nil;
 {
     ++_private->numWebViews;
 }
+
+- (void)_setPreferenceForTestWithValue:(NSString *)value forKey:(NSString *)key
+{
+    [self _setStringValue:value forKey:key];
+}
+
 @end
 
 @implementation WebPreferences (WebInternal)
index d571869..7400a77 100644 (file)
@@ -117,6 +117,10 @@ extern NSString *WebPreferencesRemovedNotification;
 - (WebTextDirectionSubmenuInclusionBehavior)textDirectionSubmenuInclusionBehavior;
 - (void)setTextDirectionSubmenuInclusionBehavior:(WebTextDirectionSubmenuInclusionBehavior)behavior;
 
+// Used to set preference specified in the test via LayoutTestController.overridePreference(..).
+// For use with DumpRenderTree only.
+- (void)_setPreferenceForTestWithValue:(NSString *)value forKey:(NSString *)key;
+
 // 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 479d81b..2ef7f8b 100644 (file)
@@ -1,3 +1,16 @@
+2009-08-11  Dmitry Titov <dimich@chromium.org>
+
+        Reviewed by Adam Roben.
+
+        Originally implemented by Glenn Wilson  <gwilson@chromium.org>.
+
+        Added support for overriding default preferences per-test.
+        See https://bugs.webkit.org/show_bug.cgi?id=20534
+
+        * Interfaces/IWebPreferencesPrivate.idl: added new method setPreferenceForTest
+        * WebPreferences.cpp: same.
+        * WebPreferences.h: same.
+
 2009-08-10  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Darin Adler.
index 562a75b..d26e4e8 100644 (file)
@@ -78,4 +78,8 @@ interface IWebPreferencesPrivate : IUnknown
 
     HRESULT isXSSAuditorEnabled([out, retval] BOOL *enabled);
     HRESULT setXSSAuditorEnabled([in] BOOL enabled);
+
+    // Used to set preference specified by a test via LayoutTestController.overridePreference(..).
+    // Used by DumpRenderTree.
+    HRESULT setPreferenceForTest([in] BSTR key, [in] BSTR value);
 }
index 8ea0319..1e15800 100644 (file)
@@ -1301,6 +1301,17 @@ HRESULT WebPreferences::zoomsTextOnly(BOOL* zoomsTextOnly)
     return S_OK;
 }
 
+HRESULT WebPreferences::setPreferenceForTest(BSTR key, BSTR value)
+{
+    if (!SysStringLen(key) || !SysStringLen(value))
+        return E_FAIL;
+    RetainPtr<CFStringRef> keyString(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<UniChar*>(key), SysStringLen(key)));
+    RetainPtr<CFStringRef> valueString(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<UniChar*>(value), SysStringLen(value)));
+    setValueForKey(keyString.get(), valueString.get());
+    postPreferencesChangesNotification();
+    return S_OK;
+}
+
 void WebPreferences::willAddToWebView()
 {
     ++m_numWebViews;
index 2f94382..0432205 100644 (file)
@@ -340,7 +340,7 @@ public:
 
     virtual HRESULT STDMETHODCALLTYPE fontSmoothingContrast( 
     /* [retval][out] */ float* contrast);
-    
+
     virtual HRESULT STDMETHODCALLTYPE setFontSmoothingContrast( 
     /* [in] */ float contrast);
 
@@ -362,6 +362,11 @@ public:
     virtual HRESULT STDMETHODCALLTYPE setXSSAuditorEnabled(
     /* [in] */ BOOL enabled);
 
+    virtual HRESULT STDMETHODCALLTYPE setPreferenceForTest(
+    /* [in] */ BSTR key,
+    /* [in] */ BSTR value);
+
+
     // WebPreferences
 
     // This method accesses a different preference key than developerExtrasEnabled.
index e401de6..534ad84 100644 (file)
@@ -1,3 +1,34 @@
+2009-08-11  Dmitry Titov  <dimich@chromium.org>
+
+        Reviewed by Adam Roben.
+
+        Originally implemented by Glenn Wilson  <gwilson@chromium.org>.
+
+        Added support for overriding default preferences per-test.
+        See https://bugs.webkit.org/show_bug.cgi?id=20534
+
+        * DumpRenderTree/LayoutTestController.cpp:
+        (overridePreferenceCallback): add wiring for layoutTestController.overridePreference.
+        (LayoutTestController::staticFunctions): same.
+        * DumpRenderTree/LayoutTestController.h: same.
+        * DumpRenderTree/gtk/LayoutTestControllerGtk.cpp:
+        (LayoutTestController::overridePreference): added empty overridePreference method.
+        * DumpRenderTree/mac/DumpRenderTree.mm: implemented preference override.
+        (resetDefaultsToConsistentValues): new method, resets preferences to same set of value before every test.
+        (setDefaultsToConsistentValuesForTesting): new method, sets other details of testing environment, every time  DRT starts.
+        (resetWebViewToConsistentStateBeforeTesting): move some preference setting from here to new resetDefaultsToConsistentValues().
+        * DumpRenderTree/mac/LayoutTestControllerMac.mm:
+        (LayoutTestController::overridePreference):
+        * DumpRenderTree/win/DumpRenderTree.cpp:
+        (resetDefaultsToConsistentValues): new method, resets preferences to same set of value before every test.
+        (resetWebViewToConsistentStateBeforeTesting): move some preference setting from here to new resetDefaultsToConsistentValues().
+        (createWebViewAndOffscreenWindow): same.
+        (main): same.
+        * DumpRenderTree/win/LayoutTestControllerWin.cpp:
+        (LayoutTestController::overridePreference):
+        * DumpRenderTree/wx/LayoutTestControllerWx.cpp:
+        (LayoutTestController::overridePreference):
+
 2009-08-11  Brian Weinstein  <bweinstein@apple.com>
 
         Reviewed by Sam Weinig.
index 2a0871f..d9c7421 100644 (file)
@@ -377,6 +377,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 = static_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
@@ -941,6 +957,7 @@ JSStaticFunction* LayoutTestController::staticFunctions()
         { "keepWebHistory", keepWebHistoryCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "notifyDone", notifyDoneCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "numberOfActiveAnimations", numberOfActiveAnimationsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "overridePreference", overridePreferenceCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "pathToLocalResource", pathToLocalResourceCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "pauseAnimationAtTimeOnElementWithId", pauseAnimationAtTimeOnElementWithIdCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "pauseTransitionAtTimeOnElementWithId", pauseTransitionAtTimeOnElementWithIdCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
index 5bc9d61..1431327 100644 (file)
@@ -53,6 +53,7 @@ public:
     bool isCommandEnabled(JSStringRef name);
     void keepWebHistory();
     void notifyDone();
+    void overridePreference(JSStringRef key, JSStringRef value);
     JSStringRef pathToLocalResource(JSContextRef, JSStringRef url);
     void queueBackNavigation(int howFarBackward);
     void queueForwardNavigation(int howFarForward);
index 009cb97..0049ae8 100644 (file)
@@ -362,3 +362,9 @@ unsigned LayoutTestController::numberOfActiveAnimations() const
 {
     return webkit_web_frame_number_of_active_animations(mainFrame);
 }
+
+void LayoutTestController::overridePreference(JSStringRef /* key */, JSStringRef /* value */)
+{
+    // FIXME: implement
+}
+
index d49248b..b4dcdba 100644 (file)
@@ -354,7 +354,8 @@ static NSString *libraryPathForDumpRenderTree()
     return [@"~/Library/Application Support/DumpRenderTree" stringByExpandingTildeInPath];
 }
 
-static void setDefaultsToConsistentValuesForTesting()
+// Called before each test.
+static void resetDefaultsToConsistentValues()
 {
     // Give some clear to undocumented defaults values
     static const int NoFontSmoothing = 0;
@@ -384,12 +385,6 @@ static void setDefaultsToConsistentValuesForTesting()
     NSString *path = libraryPathForDumpRenderTree();
     [defaults setObject:[path stringByAppendingPathComponent:@"Databases"] forKey:WebDatabaseDirectoryDefaultsKey];
     [defaults setObject:[path stringByAppendingPathComponent:@"LocalCache"] forKey:WebKitLocalCacheDefaultsKey];
-    NSURLCache *sharedCache =
-        [[NSURLCache alloc] initWithMemoryCapacity:1024 * 1024
-                                      diskCapacity:0
-                                          diskPath:[path stringByAppendingPathComponent:@"URLCache"]];
-    [NSURLCache setSharedURLCache:sharedCache];
-    [sharedCache release];
 
     WebPreferences *preferences = [WebPreferences standardPreferences];
 
@@ -411,11 +406,39 @@ static void setDefaultsToConsistentValuesForTesting()
     [preferences setCacheModel:WebCacheModelDocumentBrowser];
     [preferences setXSSAuditorEnabled:NO];
 
+    [preferences setPrivateBrowsingEnabled:NO];
+    [preferences setAuthorAndUserStylesEnabled:YES];
+    [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
+    [preferences setOfflineWebApplicationCacheEnabled:YES];
+    [preferences setDeveloperExtrasEnabled:NO];
+    [preferences setXSSAuditorEnabled:NO];
+    [preferences setLoadsImagesAutomatically:YES];
+    if (persistentUserStyleSheetLocation) {
+        [preferences setUserStyleSheetLocation:[NSURL URLWithString:(NSString *)(persistentUserStyleSheetLocation.get())]];
+        [preferences setUserStyleSheetEnabled:YES];
+    } else
+        [preferences setUserStyleSheetEnabled:NO];
+
     // The back/forward cache is causing problems due to layouts during transition from one page to another.
     // So, turn it off for now, but we might want to turn it back on some day.
     [preferences setUsesPageCache:NO];
 }
 
+// Called once on DumpRenderTree startup.
+static void setDefaultsToConsistentValuesForTesting()
+{
+    resetDefaultsToConsistentValues();
+
+    NSString *path = libraryPathForDumpRenderTree();
+    NSURLCache *sharedCache =
+        [[NSURLCache alloc] initWithMemoryCapacity:1024 * 1024
+                                      diskCapacity:0
+                                          diskPath:[path stringByAppendingPathComponent:@"URLCache"]];
+    [NSURLCache setSharedURLCache:sharedCache];
+    [sharedCache release];
+
+}
+
 static void crashHandler(int sig)
 {
     char *signalName = strsignal(sig);
@@ -1052,20 +1075,7 @@ static void resetWebViewToConsistentStateBeforeTesting()
     [webView _clearMainFrameName];
     [[webView undoManager] removeAllActions];
 
-    WebPreferences *preferences = [webView preferences];
-    [preferences setPrivateBrowsingEnabled:NO];
-    [preferences setAuthorAndUserStylesEnabled:YES];
-    [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
-    [preferences setOfflineWebApplicationCacheEnabled:YES];
-    [preferences setDeveloperExtrasEnabled:NO];
-    [preferences setXSSAuditorEnabled:NO];
-    [preferences setLoadsImagesAutomatically:YES];
-
-    if (persistentUserStyleSheetLocation) {
-        [preferences setUserStyleSheetLocation:[NSURL URLWithString:(NSString *)(persistentUserStyleSheetLocation.get())]];
-        [preferences setUserStyleSheetEnabled:YES];
-    } else
-        [preferences setUserStyleSheetEnabled:NO];
+    resetDefaultsToConsistentValues();
 
     [[mainFrame webView] setSmartInsertDeleteEnabled:YES];
     [[[mainFrame webView] inspector] setJavaScriptProfilingEnabled:NO];
index 591bb81..c4a9eee 100644 (file)
@@ -293,6 +293,17 @@ void LayoutTestController::dispatchPendingLoadRequests()
     [[mainFrame webView] _dispatchPendingLoadRequests];
 }
 
+void LayoutTestController::overridePreference(JSStringRef key, JSStringRef value)
+{
+    RetainPtr<CFStringRef> keyCF(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, key));
+    NSString *keyNS = (NSString *)keyCF.get();
+
+    RetainPtr<CFStringRef> valueCF(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, value));
+    NSString *valueNS = (NSString *)valueCF.get();
+
+    [[WebPreferences standardPreferences] _setPreferenceForTestWithValue:valueNS forKey:keyNS];
+}
+
 void LayoutTestController::setPersistentUserStyleSheetLocation(JSStringRef jsURL)
 {
     RetainPtr<CFStringRef> urlString(AdoptCF, JSStringCopyCFString(0, jsURL));
index d262826..bf5c948 100644 (file)
@@ -657,6 +657,66 @@ static bool shouldLogFrameLoadDelegates(const char* pathOrURL)
     return strstr(pathOrURL, "/loading/") || strstr(pathOrURL, "\\loading\\");
 }
 
+static void resetDefaultsToConsistentValues(IWebPreferences* preferences)
+{
+#ifdef USE_MAC_FONTS
+    static BSTR standardFamily = SysAllocString(TEXT("Times"));
+    static BSTR fixedFamily = SysAllocString(TEXT("Courier"));
+    static BSTR sansSerifFamily = SysAllocString(TEXT("Helvetica"));
+    static BSTR cursiveFamily = SysAllocString(TEXT("Apple Chancery"));
+    static BSTR fantasyFamily = SysAllocString(TEXT("Papyrus"));
+#else
+    static BSTR standardFamily = SysAllocString(TEXT("Times New Roman"));
+    static BSTR fixedFamily = SysAllocString(TEXT("Courier New"));
+    static BSTR sansSerifFamily = SysAllocString(TEXT("Arial"));
+    static BSTR cursiveFamily = SysAllocString(TEXT("Comic Sans MS")); // Not actually cursive, but it's what IE and Firefox use.
+    static BSTR fantasyFamily = SysAllocString(TEXT("Times New Roman"));
+#endif
+
+    preferences->setStandardFontFamily(standardFamily);
+    preferences->setFixedFontFamily(fixedFamily);
+    preferences->setSerifFontFamily(standardFamily);
+    preferences->setSansSerifFontFamily(sansSerifFamily);
+    preferences->setCursiveFontFamily(cursiveFamily);
+    preferences->setFantasyFontFamily(fantasyFamily);
+
+    preferences->setAutosaves(FALSE);
+    preferences->setDefaultFontSize(16);
+    preferences->setDefaultFixedFontSize(13);
+    preferences->setMinimumFontSize(1);
+    preferences->setJavaEnabled(FALSE);
+    preferences->setPlugInsEnabled(TRUE);
+    preferences->setDOMPasteAllowed(TRUE);
+    preferences->setEditableLinkBehavior(WebKitEditableLinkOnlyLiveWithShiftKey);
+    preferences->setFontSmoothing(FontSmoothingTypeStandard);
+    preferences->setUsesPageCache(FALSE);
+    preferences->setPrivateBrowsingEnabled(FALSE);
+    preferences->setJavaScriptCanOpenWindowsAutomatically(TRUE);
+    preferences->setJavaScriptEnabled(TRUE);
+    preferences->setTabsToLinks(FALSE);
+    preferences->setShouldPrintBackgrounds(TRUE);
+    preferences->setLoadsImagesAutomatically(TRUE);
+
+    if (persistentUserStyleSheetLocation) {
+        Vector<wchar_t> urlCharacters(CFStringGetLength(persistentUserStyleSheetLocation.get()));
+        CFStringGetCharacters(persistentUserStyleSheetLocation.get(), CFRangeMake(0, CFStringGetLength(persistentUserStyleSheetLocation.get())), (UniChar *)urlCharacters.data());
+        BSTR url = SysAllocStringLen(urlCharacters.data(), urlCharacters.size());
+        preferences->setUserStyleSheetLocation(url);
+        SysFreeString(url);
+        preferences->setUserStyleSheetEnabled(TRUE);
+    } else
+        preferences->setUserStyleSheetEnabled(FALSE);
+
+    COMPtr<IWebPreferencesPrivate> prefsPrivate(Query, preferences);
+    if (prefsPrivate) {
+        prefsPrivate->setAuthorAndUserStylesEnabled(TRUE);
+        prefsPrivate->setDeveloperExtrasEnabled(FALSE);
+        prefsPrivate->setShouldPaintNativeControls(FALSE); // FIXME - need to make DRT pass with Windows native controls <http://bugs.webkit.org/show_bug.cgi?id=25592>
+        prefsPrivate->setXSSAuditorEnabled(FALSE);
+        prefsPrivate->setOfflineWebApplicationCacheEnabled(FALSE);
+    }
+}
+
 static void resetWebViewToConsistentStateBeforeTesting()
 {
     COMPtr<IWebView> webView;
@@ -673,30 +733,10 @@ static void resetWebViewToConsistentStateBeforeTesting()
         webIBActions->resetPageZoom(0);
     }
 
+
     COMPtr<IWebPreferences> preferences;
-    if (SUCCEEDED(webView->preferences(&preferences))) {
-        preferences->setPrivateBrowsingEnabled(FALSE);
-        preferences->setJavaScriptCanOpenWindowsAutomatically(TRUE);
-        preferences->setLoadsImagesAutomatically(TRUE);
-
-        if (persistentUserStyleSheetLocation) {
-            Vector<wchar_t> urlCharacters(CFStringGetLength(persistentUserStyleSheetLocation.get()));
-            CFStringGetCharacters(persistentUserStyleSheetLocation.get(), CFRangeMake(0, CFStringGetLength(persistentUserStyleSheetLocation.get())), (UniChar *)urlCharacters.data());
-            BSTR url = SysAllocStringLen(urlCharacters.data(), urlCharacters.size());
-            preferences->setUserStyleSheetLocation(url);
-            SysFreeString(url);
-            preferences->setUserStyleSheetEnabled(TRUE);
-        } else
-            preferences->setUserStyleSheetEnabled(FALSE);
-
-        COMPtr<IWebPreferencesPrivate> prefsPrivate(Query, preferences);
-        if (prefsPrivate) {
-            prefsPrivate->setAuthorAndUserStylesEnabled(TRUE);
-            prefsPrivate->setDeveloperExtrasEnabled(FALSE);
-            prefsPrivate->setShouldPaintNativeControls(FALSE); // FIXME - need to make DRT pass with Windows native controls <http://bugs.webkit.org/show_bug.cgi?id=25592>
-            prefsPrivate->setXSSAuditorEnabled(FALSE);
-        }
-    }
+    if (SUCCEEDED(webView->preferences(&preferences)))
+        resetDefaultsToConsistentValues(preferences.get());
 
     COMPtr<IWebViewEditing> viewEditing;
     if (SUCCEEDED(webView->QueryInterface(&viewEditing)))
@@ -830,44 +870,6 @@ exit:
     return;
 }
 
-static void initializePreferences(IWebPreferences* preferences)
-{
-#ifdef USE_MAC_FONTS
-    BSTR standardFamily = SysAllocString(TEXT("Times"));
-    BSTR fixedFamily = SysAllocString(TEXT("Courier"));
-    BSTR sansSerifFamily = SysAllocString(TEXT("Helvetica"));
-    BSTR cursiveFamily = SysAllocString(TEXT("Apple Chancery"));
-    BSTR fantasyFamily = SysAllocString(TEXT("Papyrus"));
-#else
-    BSTR standardFamily = SysAllocString(TEXT("Times New Roman"));
-    BSTR fixedFamily = SysAllocString(TEXT("Courier New"));
-    BSTR sansSerifFamily = SysAllocString(TEXT("Arial"));
-    BSTR cursiveFamily = SysAllocString(TEXT("Comic Sans MS")); // Not actually cursive, but it's what IE and Firefox use.
-    BSTR fantasyFamily = SysAllocString(TEXT("Times New Roman"));
-#endif
-
-    preferences->setStandardFontFamily(standardFamily);
-    preferences->setFixedFontFamily(fixedFamily);
-    preferences->setSerifFontFamily(standardFamily);
-    preferences->setSansSerifFontFamily(sansSerifFamily);
-    preferences->setCursiveFontFamily(cursiveFamily);
-    preferences->setFantasyFontFamily(fantasyFamily);
-
-    preferences->setAutosaves(FALSE);
-    preferences->setJavaEnabled(FALSE);
-    preferences->setPlugInsEnabled(TRUE);
-    preferences->setDOMPasteAllowed(TRUE);
-    preferences->setEditableLinkBehavior(WebKitEditableLinkOnlyLiveWithShiftKey);
-    preferences->setFontSmoothing(FontSmoothingTypeStandard);
-    preferences->setUsesPageCache(FALSE);
-
-    SysFreeString(standardFamily);
-    SysFreeString(fixedFamily);
-    SysFreeString(sansSerifFamily);
-    SysFreeString(cursiveFamily);
-    SysFreeString(fantasyFamily);
-}
-
 static Boolean pthreadEqualCallback(const void* value1, const void* value2)
 {
     return (Boolean)pthread_equal(*(pthread_t*)value1, *(pthread_t*)value2);
@@ -1052,12 +1054,6 @@ IWebView* createWebViewAndOffscreenWindow(HWND* webViewWindow)
     if (FAILED(webView->setResourceLoadDelegate(sharedResourceLoadDelegate.get())))
         return 0;
 
-    COMPtr<IWebPreferences> preferences;
-    if (FAILED(webView->preferences(&preferences)))
-        return 0;
-
-    initializePreferences(preferences.get());
-
     openWindows().append(hostWindow);
     windowToWebViewMap().set(hostWindow, webView);
     return webView;
@@ -1125,20 +1121,6 @@ int main(int argc, char* argv[])
     sharedEditingDelegate.adoptRef(new EditingDelegate);
     sharedResourceLoadDelegate.adoptRef(new ResourceLoadDelegate);
 
-    // FIXME - need to make DRT pass with Windows native controls <http://bugs.webkit.org/show_bug.cgi?id=25592>
-    COMPtr<IWebPreferences> tmpPreferences;
-    if (FAILED(WebKitCreateInstance(CLSID_WebPreferences, 0, IID_IWebPreferences, reinterpret_cast<void**>(&tmpPreferences))))
-        return -1;
-    COMPtr<IWebPreferences> standardPreferences;
-    if (FAILED(tmpPreferences->standardPreferences(&standardPreferences)))
-        return -1;
-    COMPtr<IWebPreferencesPrivate> standardPreferencesPrivate;
-    if (FAILED(standardPreferences->QueryInterface(&standardPreferencesPrivate)))
-        return -1;
-    standardPreferencesPrivate->setShouldPaintNativeControls(FALSE);
-    standardPreferences->setJavaScriptEnabled(TRUE);
-    standardPreferences->setDefaultFontSize(16);
-    
     COMPtr<IWebView> webView(AdoptCOM, createWebViewAndOffscreenWindow(&webViewWindow));
     if (!webView)
         return -1;
index 7a80bab..a46e6cf 100644 (file)
@@ -707,6 +707,27 @@ void LayoutTestController::clearAllDatabases()
     databaseManager->deleteAllDatabases();
 }
 
+void LayoutTestController::overridePreference(JSStringRef key, JSStringRef value)
+{
+    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 valueBSTR = JSStringCopyBSTR(value);
+    prefsPrivate->setPreferenceForTest(keyBSTR, valueBSTR);
+    SysFreeString(keyBSTR);
+    SysFreeString(valueBSTR);
+}
+
 void LayoutTestController::setDatabaseQuota(unsigned long long quota)
 {
     printf("ERROR: LayoutTestController::setDatabaseQuota() not implemented\n");
index fa7e541..0877f25 100644 (file)
@@ -260,3 +260,9 @@ void LayoutTestController::waitForPolicyDelegate()
 {
     // FIXME: Implement this.
 }
+
+void LayoutTestController::overridePreference(JSStringRef /* key */, JSStringRef /* value */)
+{
+    // FIXME: implement
+}
+