[Mac] Rationalize user defaults override code
authorap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Oct 2013 17:47:46 +0000 (17:47 +0000)
committerap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Oct 2013 17:47:46 +0000 (17:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=123436

Reviewed by Dan Bernstein.

* DumpRenderTree/mac/DumpRenderTree.mm:
(resetWebPreferencesToConsistentValues): Renamed from resetDefaultsToConsistentValues,
because this function only resets WebPreferences now.
(setDefaultsToConsistentValuesForTesting): Moved code for setting the defaults
here, because tests never change them, and they only need to be set once, not
before each test. Removed long obsolete workaround for HIToolbox preferences.
Don't call resetWebPreferencesToConsistentValues, because it will be called before
the first test anyway.
(main): Don't set AppleMagnifiedMode here, moved that to setDefaultsToConsistentValuesForTesting.
(resetWebViewToConsistentStateBeforeTesting): Moved TestRunner::setSerializeHTTPLoads
and setlocale calls out of resetWebPreferencesToConsistentValues().
Added AppleAquaAntiAliasingChanged notification that we had in WK2, because it's
also needed in WK1.

* WebKitTestRunner/InjectedBundle/mac/InjectedBundleMac.mm:
(WTR::InjectedBundle::platformInitialize): Use literal syntax for defaults
dictionary.

* WebKitTestRunner/mac/main.mm:
(setDefaultsToConsistentValuesForTesting): Factored out of main(), and changed to
use NSArgumentDomain for everything.

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

Tools/ChangeLog
Tools/DumpRenderTree/mac/DumpRenderTree.mm
Tools/WebKitTestRunner/InjectedBundle/mac/InjectedBundleMac.mm
Tools/WebKitTestRunner/mac/main.mm

index 7119a3b..b3d1e72 100644 (file)
@@ -1,3 +1,32 @@
+2013-10-29  Alexey Proskuryakov  <ap@apple.com>
+
+        [Mac] Rationalize user defaults override code
+        https://bugs.webkit.org/show_bug.cgi?id=123436
+
+        Reviewed by Dan Bernstein.
+
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (resetWebPreferencesToConsistentValues): Renamed from resetDefaultsToConsistentValues,
+        because this function only resets WebPreferences now.
+        (setDefaultsToConsistentValuesForTesting): Moved code for setting the defaults
+        here, because tests never change them, and they only need to be set once, not
+        before each test. Removed long obsolete workaround for HIToolbox preferences.
+        Don't call resetWebPreferencesToConsistentValues, because it will be called before
+        the first test anyway.
+        (main): Don't set AppleMagnifiedMode here, moved that to setDefaultsToConsistentValuesForTesting.
+        (resetWebViewToConsistentStateBeforeTesting): Moved TestRunner::setSerializeHTTPLoads
+        and setlocale calls out of resetWebPreferencesToConsistentValues().
+        Added AppleAquaAntiAliasingChanged notification that we had in WK2, because it's
+        also needed in WK1.
+
+        * WebKitTestRunner/InjectedBundle/mac/InjectedBundleMac.mm:
+        (WTR::InjectedBundle::platformInitialize): Use literal syntax for defaults
+        dictionary.
+
+        * WebKitTestRunner/mac/main.mm:
+        (setDefaultsToConsistentValuesForTesting): Factored out of main(), and changed to
+        use NSArgumentDomain for everything.
+
 2013-10-29  Philippe Normand  <pnormand@igalia.com>
 
         [GTK] enable media-stream in build-webkit
index 705c306..570b2ee 100644 (file)
@@ -597,60 +597,8 @@ static NSString *libraryPathForDumpRenderTree()
 }
 
 // Called before each test.
-static void resetDefaultsToConsistentValues()
+static void resetWebPreferencesToConsistentValues()
 {
-    static const int NoFontSmoothing = 0;
-    static const int BlueTintedAppearance = 1;
-
-    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
-    [defaults setInteger:4 forKey:@"AppleAntiAliasingThreshold"]; // smallest font size to CG should perform antialiasing on
-    [defaults setInteger:NoFontSmoothing forKey:@"AppleFontSmoothing"];
-    [defaults setInteger:BlueTintedAppearance forKey:@"AppleAquaColorVariant"];
-    [defaults setObject:@"0.709800 0.835300 1.000000" forKey:@"AppleHighlightColor"];
-    [defaults setObject:@"0.500000 0.500000 0.500000" forKey:@"AppleOtherHighlightColor"];
-    [defaults setObject:[NSArray arrayWithObject:@"en"] forKey:@"AppleLanguages"];
-    [defaults setBool:YES forKey:WebKitEnableFullDocumentTeardownPreferenceKey];
-    [defaults setBool:YES forKey:WebKitFullScreenEnabledPreferenceKey];
-    [defaults setBool:YES forKey:@"UseWebKitWebInspector"];
-
-    [defaults setObject:[NSDictionary dictionaryWithObjectsAndKeys:
-        @"notational", @"notationl",
-        @"message", @"mesage",
-        @"would", @"wouldn",
-        @"welcome", @"wellcome",
-        @"hello\nworld", @"hellolfworld",
-        nil] forKey:@"NSTestCorrectionDictionary"];
-
-    // Scrollbars are drawn either using AppKit (which uses NSUserDefaults) or using HIToolbox (which uses CFPreferences / kCFPreferencesAnyApplication / kCFPreferencesCurrentUser / kCFPreferencesAnyHost)
-    [defaults setObject:@"DoubleMax" forKey:@"AppleScrollBarVariant"];
-    RetainPtr<CFTypeRef> initialValue = CFPreferencesCopyValue(CFSTR("AppleScrollBarVariant"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
-    CFPreferencesSetValue(CFSTR("AppleScrollBarVariant"), CFSTR("DoubleMax"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
-#ifndef __LP64__
-    // See <rdar://problem/6347388>.
-    ThemeScrollBarArrowStyle style;
-    GetThemeScrollBarArrowStyle(&style); // Force HIToolbox to read from CFPreferences
-#endif
-
-
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
-    [defaults setBool:NO forKey:@"NSScrollAnimationEnabled"];
-#else
-    [defaults setBool:NO forKey:@"AppleScrollAnimationEnabled"];
-#endif
-
-    [defaults setBool:NO forKey:@"NSOverlayScrollersEnabled"];
-    [defaults setObject:@"Always" forKey:@"AppleShowScrollBars"];
-
-    if (initialValue)
-        CFPreferencesSetValue(CFSTR("AppleScrollBarVariant"), initialValue.get(), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
-
-    NSString *path = libraryPathForDumpRenderTree();
-    [defaults setObject:[path stringByAppendingPathComponent:@"Databases"] forKey:WebDatabaseDirectoryDefaultsKey];
-    [defaults setObject:[path stringByAppendingPathComponent:@"LocalStorage"] forKey:WebStorageDirectoryDefaultsKey];
-    [defaults setObject:[path stringByAppendingPathComponent:@"LocalCache"] forKey:WebKitLocalCacheDefaultsKey];
-
-    [defaults setBool:NO forKey:@"WebKitKerningAndLigaturesEnabledByDefault"];
-
     WebPreferences *preferences = [WebPreferences standardPreferences];
 
     [preferences setAllowUniversalAccessFromFileURLs:YES];
@@ -723,10 +671,6 @@ static void resetDefaultsToConsistentValues()
     [preferences setScreenFontSubstitutionEnabled:YES];
 
     [WebPreferences _setCurrentNetworkLoaderSessionCookieAcceptPolicy:NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain];
-    
-    TestRunner::setSerializeHTTPLoads(false);
-
-    setlocale(LC_ALL, "");
 }
 
 // Called once on DumpRenderTree startup.
@@ -735,13 +679,49 @@ static void setDefaultsToConsistentValuesForTesting()
     // FIXME: We'd like to start with a clean state for every test, but this function can't be used more than once yet.
     [WebPreferences _switchNetworkLoaderToNewTestingSession];
 
-    resetDefaultsToConsistentValues();
+    static const int NoFontSmoothing = 0;
+    static const int BlueTintedAppearance = 1;
+
+    NSString *libraryPath = libraryPathForDumpRenderTree();
+
+    NSDictionary *dict = @{
+        @"AppleMagnifiedMode": @YES,
+        @"AppleAntiAliasingThreshold": @4,
+        @"AppleFontSmoothing": @(NoFontSmoothing),
+        @"AppleAquaColorVariant": @(BlueTintedAppearance),
+        @"AppleHighlightColor": @"0.709800 0.835300 1.000000",
+        @"AppleOtherHighlightColor":@"0.500000 0.500000 0.500000",
+        @"AppleLanguages": @[ @"en" ],
+        WebKitEnableFullDocumentTeardownPreferenceKey: @YES,
+        WebKitFullScreenEnabledPreferenceKey: @YES,
+        @"UseWebKitWebInspector": @YES,
+        @"NSTestCorrectionDictionary": @{
+            @"notationl": @"notational",
+            @"mesage": @"message",
+            @"wouldn": @"would",
+            @"wellcome": @"welcome",
+            @"hellolfworld": @"hello\nworld"
+        },
+        @"WebKitKerningAndLigaturesEnabledByDefault": @NO,
+        @"AppleScrollBarVariant": @"DoubleMax",
+        @"NSScrollAnimationEnabled": @NO,
+        @"NSOverlayScrollersEnabled": @NO,
+        @"AppleShowScrollBars": @"Always",
+        WebDatabaseDirectoryDefaultsKey: [libraryPath stringByAppendingPathComponent:@"Databases"],
+        WebStorageDirectoryDefaultsKey: [libraryPath stringByAppendingPathComponent:@"LocalStorage"],
+        WebKitLocalCacheDefaultsKey: [libraryPath stringByAppendingPathComponent:@"LocalCache"]
+    };
+
+    [[NSUserDefaults standardUserDefaults] setVolatileDomain:dict forName:NSArgumentDomain];
+
+    // Underlying frameworks have already read AppleAntiAliasingThreshold default before we changed it.
+    // A distributed notification is delivered to all applications, but it should be harmless, and it's the only way to update all underlying frameworks anyway.
+    [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"AppleAquaAntiAliasingChanged" object:nil userInfo:nil deliverImmediately:YES];
 
-    NSString *path = libraryPathForDumpRenderTree();
     NSURLCache *sharedCache =
         [[NSURLCache alloc] initWithMemoryCapacity:1024 * 1024
                                       diskCapacity:0
-                                          diskPath:[path stringByAppendingPathComponent:@"URLCache"]];
+                                          diskPath:[libraryPath stringByAppendingPathComponent:@"URLCache"]];
     [NSURLCache setSharedURLCache:sharedCache];
     [sharedCache release];
 }
@@ -950,11 +930,7 @@ int main(int argc, const char *argv[])
 {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     [DumpRenderTreeApplication sharedApplication]; // Force AppKit to init itself
-    
-    NSDictionary *defaults = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"AppleMagnifiedMode", nil];
-    [[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
-    [defaults release];
-    
+
     dumpRenderTree(argc, argv);
     [WebCoreStatistics garbageCollectJavaScriptObjects];
     [WebCoreStatistics emptyCache]; // Otherwise SVGImages trigger false positives for Frame/Node counts
@@ -1305,7 +1281,11 @@ static void resetWebViewToConsistentStateBeforeTesting()
     [[webView window] setAutodisplay:NO];
     [webView setTracksRepaints:NO];
     
-    resetDefaultsToConsistentValues();
+    resetWebPreferencesToConsistentValues();
+
+    TestRunner::setSerializeHTTPLoads(false);
+
+    setlocale(LC_ALL, "");
 
     if (gTestRunner) {
         WebCoreTestSupport::resetInternalsObject([mainFrame globalContext]);
index e6fc1bb..3da67d4 100644 (file)
@@ -42,22 +42,21 @@ void InjectedBundle::platformInitialize(WKTypeRef)
     static const int NoFontSmoothing = 0;
     static const int BlueTintedAppearance = 1;
 
-    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
-        [NSNumber numberWithInteger:4], @"AppleAntiAliasingThreshold",
-        [NSNumber numberWithInteger:NoFontSmoothing], @"AppleFontSmoothing",
-        [NSNumber numberWithInteger:BlueTintedAppearance], @"AppleAquaColorVariant",
-        @"0.709800 0.835300 1.000000", @"AppleHighlightColor",
-        @"0.500000 0.500000 0.500000", @"AppleOtherHighlightColor",
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
-        [NSNumber numberWithBool:NO], @"NSScrollAnimationEnabled",
-#else
-        [NSNumber numberWithBool:NO], @"AppleScrollAnimationEnabled",
-#endif
-        [NSNumber numberWithBool:NO], @"NSOverlayScrollersEnabled",
-        @"Always", @"AppleShowScrollBars",
-        [NSArray arrayWithObject:@"en"], @"AppleLanguages",
-        [NSDictionary dictionaryWithObjectsAndKeys:@"notational", @"notationl", nil], @"NSTestCorrectionDictionary",
-        nil];
+    NSDictionary *dict = @{
+        @"AppleAntiAliasingThreshold": @4,
+        @"AppleFontSmoothing": @(NoFontSmoothing),
+        @"AppleAquaColorVariant": @(BlueTintedAppearance),
+        @"AppleHighlightColor": @"0.709800 0.835300 1.000000",
+        @"AppleOtherHighlightColor": @"0.500000 0.500000 0.500000",
+        @"NSScrollAnimationEnabled": @NO,
+        @"NSOverlayScrollersEnabled": @NO,
+        @"AppleShowScrollBars": @"Always",
+        @"AppleLanguages": @[ @"en" ],
+        // FIXME: Why does this dictionary not match the one in DumpRenderTree?
+        @"NSTestCorrectionDictionary": @{
+            @"notationl": @"notational"
+        }
+    };
 
     [[NSUserDefaults standardUserDefaults] setVolatileDomain:dict forName:NSArgumentDomain];
 
index f2296d4..a52993c 100644 (file)
 
 #import "TestController.h"
 
+static void setDefaultsToConsistentValuesForTesting()
+{
+    NSDictionary *dict = @{
+        @"AppleMagnifiedMode": @YES,
+        @"WebKitKerningAndLigaturesEnabledByDefault": @NO,
+        // FIXME: This is likely insufficient, as tests change (and don't reset) these settings via Internals.
+        @"WebAutomaticQuoteSubstitutionEnabled": @NO,
+        @"WebAutomaticDashSubstitutionEnabled": @NO
+    };
+
+    [[NSUserDefaults standardUserDefaults] setVolatileDomain:dict forName:NSArgumentDomain];
+}
+
 int main(int argc, const char* argv[])
 {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     [NSApplication sharedApplication];
-    [[NSUserDefaults standardUserDefaults] setVolatileDomain:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:@"WebKitKerningAndLigaturesEnabledByDefault"] forName:NSArgumentDomain];
-    
-    NSDictionary *defaults = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"AppleMagnifiedMode", nil];
-    [[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
-    [defaults release];
-
-    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebAutomaticQuoteSubstitutionEnabled"];
-    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebAutomaticDashSubstitutionEnabled"];
+    setDefaultsToConsistentValuesForTesting();
 
     {
         WTR::TestController controller(argc, argv);