| Index: webkit/tools/test_shell/test_shell_mac.mm
|
| ===================================================================
|
| --- webkit/tools/test_shell/test_shell_mac.mm (revision 7662)
|
| +++ webkit/tools/test_shell/test_shell_mac.mm (working copy)
|
| @@ -127,6 +127,151 @@
|
| DCHECK(window_map_.Get().size() == 0);
|
| }
|
|
|
| +static void SetDefaultsToLayoutTestValues(void) {
|
| + // So we can match the WebKit layout tests, we want to force a bunch of
|
| + // preferences that control appearance to match.
|
| + // (We want to do this as early as possible in application startup so
|
| + // the settings are in before any higher layers could cache values.)
|
| +
|
| + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
| +
|
| + const NSInteger kMinFontSizeCGSmoothes = 4;
|
| + const NSInteger kNoFontSmoothing = 0;
|
| + const NSInteger kBlueTintedAppearance = 1;
|
| + [defaults setInteger:kMinFontSizeCGSmoothes
|
| + forKey:@"AppleAntiAliasingThreshold"];
|
| + [defaults setInteger:kNoFontSmoothing
|
| + forKey:@"AppleFontSmoothing"];
|
| + [defaults setInteger:kBlueTintedAppearance
|
| + 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"];
|
| +
|
| + // AppKit pulls scrollbar style from NSUserDefaults. HIToolbox uses
|
| + // CFPreferences, but AnyApplication, so we set it, force it to load, and
|
| + // then reset the pref to what it was (HIToolbox will cache what it loaded).
|
| + [defaults setObject:@"DoubleMax" forKey:@"AppleScrollBarVariant"];
|
| + CFTypeRef initialValue
|
| + = CFPreferencesCopyValue(CFSTR("AppleScrollBarVariant"),
|
| + kCFPreferencesAnyApplication,
|
| + kCFPreferencesCurrentUser,
|
| + kCFPreferencesAnyHost);
|
| + CFPreferencesSetValue(CFSTR("AppleScrollBarVariant"),
|
| + CFSTR("DoubleMax"),
|
| + kCFPreferencesAnyApplication,
|
| + kCFPreferencesCurrentUser,
|
| + kCFPreferencesAnyHost);
|
| + // Make HIToolbox read from CFPreferences
|
| + ThemeScrollBarArrowStyle style;
|
| + GetThemeScrollBarArrowStyle(&style);
|
| + if (initialValue) {
|
| + // Reset the preference to what it was
|
| + CFPreferencesSetValue(CFSTR("AppleScrollBarVariant"),
|
| + initialValue,
|
| + kCFPreferencesAnyApplication,
|
| + kCFPreferencesCurrentUser,
|
| + kCFPreferencesAnyHost);
|
| + CFRelease(initialValue);
|
| + }
|
| +}
|
| +
|
| +static void ClearAnyDefaultsForLayoutTests(void) {
|
| + // Not running a test, clear the keys so the TestShell looks right to the
|
| + // running user.
|
| +
|
| + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
| +
|
| + [defaults removeObjectForKey:@"AppleAntiAliasingThreshold"];
|
| + [defaults removeObjectForKey:@"AppleFontSmoothing"];
|
| + [defaults removeObjectForKey:@"AppleAquaColorVariant"];
|
| + [defaults removeObjectForKey:@"AppleHighlightColor"];
|
| + [defaults removeObjectForKey:@"AppleOtherHighlightColor"];
|
| + [defaults removeObjectForKey:@"AppleLanguages"];
|
| + [defaults removeObjectForKey:@"AppleScrollBarVariant"];
|
| +}
|
| +
|
| +static CMProfileRef gUsersColorProfile = NULL;
|
| +
|
| +static void RestoreUsersColorProfile(void) {
|
| + // This is called from the unsafe signal handers, so doing just about anything
|
| + // isn't really safe. But since we're already gonna crash, we give it a try
|
| + // anyways... (and WebKit uses this strategy...)
|
| +
|
| + if (gUsersColorProfile) {
|
| + CGDirectDisplayID displayID = CGMainDisplayID();
|
| + CMError error = CMSetProfileByAVID((UInt32)displayID, gUsersColorProfile);
|
| + CMCloseProfile(gUsersColorProfile);
|
| + if (error) {
|
| + fprintf(stderr, "Failed to restore color profile, use System "
|
| + "Preferences -> Displays -> Color to reset. Error: %d",
|
| + (int)error);
|
| + }
|
| + gUsersColorProfile = NULL;
|
| + }
|
| +}
|
| +
|
| +static void SimpleSignalHandler(int sig) {
|
| + // Try to restore and try to go down cleanly
|
| + RestoreUsersColorProfile();
|
| + exit(128 + sig);
|
| +}
|
| +
|
| +static void CrashSignalHandler(int sig) {
|
| + // Try to restore and get out fast...
|
| + RestoreUsersColorProfile();
|
| + _exit(128 + sig);
|
| +}
|
| +
|
| +static void InstallLayoutTestColorProfile(void) {
|
| + // To make sure we get consisten colors (not dependent on the Main display),
|
| + // we force the generic rgb color profile. This cases a change the user can
|
| + // see. We use the same basic method as WebKit for trying to make sure we
|
| + // get the profile back if we go down in flames.
|
| +
|
| + // Save off the current
|
| + CGDirectDisplayID displayID = CGMainDisplayID();
|
| + CMProfileRef previousProfile;
|
| + CMError error = CMGetProfileByAVID((UInt32)displayID, &previousProfile);
|
| + if (error) {
|
| + DLOG(WARNING) << "failed to get the current color profile, "
|
| + "pixmaps won't match. Error: " << (int)error;
|
| + return;
|
| + }
|
| +
|
| + // Install the generic one
|
| + NSColorSpace *genericSpace = [NSColorSpace genericRGBColorSpace];
|
| + CMProfileRef genericProfile = (CMProfileRef)[genericSpace colorSyncProfile];
|
| + if ((error = CMSetProfileByAVID((UInt32)displayID, genericProfile))) {
|
| + DLOG(WARNING) << "failed install the generic color profile, "
|
| + "pixmaps won't match. Error: " << (int)error;
|
| + return;
|
| + }
|
| +
|
| + // Save the starting profile, and hook in as best we can to make sure when
|
| + // we exit, it's restored (use atexit() so direct calls to exit() call us).
|
| + gUsersColorProfile = previousProfile;
|
| + atexit(RestoreUsersColorProfile);
|
| + // The less scary signals...
|
| + signal(SIGINT, SimpleSignalHandler);
|
| + signal(SIGHUP, SimpleSignalHandler);
|
| + signal(SIGTERM, SimpleSignalHandler);
|
| + // And now the scary ones...
|
| + signal(SIGILL, CrashSignalHandler); // 4: illegal instruction
|
| + signal(SIGTRAP, CrashSignalHandler); // 5: trace trap
|
| + signal(SIGEMT, CrashSignalHandler); // 7: EMT instruction
|
| + signal(SIGFPE, CrashSignalHandler); // 8: floating point exception
|
| + signal(SIGBUS, CrashSignalHandler); // 10: bus error
|
| + signal(SIGSEGV, CrashSignalHandler); // 11: segmentation violation
|
| + signal(SIGSYS, CrashSignalHandler); // 12: bad argument to system call
|
| + signal(SIGPIPE, CrashSignalHandler); // 13: write on a pipe with no reader
|
| + signal(SIGXCPU, CrashSignalHandler); // 24: exceeded CPU time limit
|
| + signal(SIGXFSZ, CrashSignalHandler); // 25: exceeded file size limit
|
| +}
|
| +
|
| // static
|
| void TestShell::InitializeTestShell(bool layout_test_mode) {
|
| // This should move to a per-process platform-specific initialization function
|
| @@ -136,64 +281,13 @@
|
| window_list_ = new WindowList;
|
| layout_test_mode_ = layout_test_mode;
|
|
|
| - // So we can match the WebKit layout tests, we want to force a bunch of
|
| - // preferences that control appearance to match.
|
| - // (We want to do this as early as possible in application startup so
|
| - // the settings are in before any higher layers could cache values.)
|
| - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
| if (layout_test_mode_) {
|
| - const NSInteger kMinFontSizeCGSmoothes = 4;
|
| - const NSInteger kNoFontSmoothing = 0;
|
| - const NSInteger kBlueTintedAppearance = 1;
|
| - [defaults setInteger:kMinFontSizeCGSmoothes
|
| - forKey:@"AppleAntiAliasingThreshold"];
|
| - [defaults setInteger:kNoFontSmoothing
|
| - forKey:@"AppleFontSmoothing"];
|
| - [defaults setInteger:kBlueTintedAppearance
|
| - 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"];
|
| -
|
| - // AppKit pulls scrollbar style from NSUserDefaults. HIToolbox uses
|
| - // CFPreferences, but AnyApplication, so we set it, force it to load, and
|
| - // then reset the pref to what it was (HIToolbox will cache what it loaded).
|
| - [defaults setObject:@"DoubleMax" forKey:@"AppleScrollBarVariant"];
|
| - CFTypeRef initialValue
|
| - = CFPreferencesCopyValue(CFSTR("AppleScrollBarVariant"),
|
| - kCFPreferencesAnyApplication,
|
| - kCFPreferencesCurrentUser,
|
| - kCFPreferencesAnyHost);
|
| - CFPreferencesSetValue(CFSTR("AppleScrollBarVariant"),
|
| - CFSTR("DoubleMax"),
|
| - kCFPreferencesAnyApplication,
|
| - kCFPreferencesCurrentUser,
|
| - kCFPreferencesAnyHost);
|
| - // Make HIToolbox read from CFPreferences
|
| - ThemeScrollBarArrowStyle style;
|
| - GetThemeScrollBarArrowStyle(&style);
|
| - if (initialValue) {
|
| - // Reset the preference to what it was
|
| - CFPreferencesSetValue(CFSTR("AppleScrollBarVariant"),
|
| - initialValue,
|
| - kCFPreferencesAnyApplication,
|
| - kCFPreferencesCurrentUser,
|
| - kCFPreferencesAnyHost);
|
| - CFRelease(initialValue);
|
| - }
|
| + SetDefaultsToLayoutTestValues();
|
| + // If we could check the command line to see if we're doing pixel tests,
|
| + // then we only install the color profile in that case.
|
| + InstallLayoutTestColorProfile();
|
| } else {
|
| - // Not running a test, clear the keys so the TestShell looks right to the
|
| - // running user.
|
| - [defaults removeObjectForKey:@"AppleAntiAliasingThreshold"];
|
| - [defaults removeObjectForKey:@"AppleFontSmoothing"];
|
| - [defaults removeObjectForKey:@"AppleAquaColorVariant"];
|
| - [defaults removeObjectForKey:@"AppleHighlightColor"];
|
| - [defaults removeObjectForKey:@"AppleOtherHighlightColor"];
|
| - [defaults removeObjectForKey:@"AppleLanguages"];
|
| - [defaults removeObjectForKey:@"AppleScrollBarVariant"];
|
| + ClearAnyDefaultsForLayoutTests();
|
| }
|
|
|
| web_prefs_ = new WebPreferences;
|
|
|