summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-08 14:57:31 +0000
committerthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-08 14:57:31 +0000
commita900521d67701e7bd232bfe04e9381129a9a6f38 (patch)
treeefcec8fa6402dc03bb8aa9539928683d90f3fbd5 /webkit
parent6f4f66fab5503a2503a57ab2424297d24b6018a5 (diff)
downloadchromium_src-a900521d67701e7bd232bfe04e9381129a9a6f38.zip
chromium_src-a900521d67701e7bd232bfe04e9381129a9a6f38.tar.gz
chromium_src-a900521d67701e7bd232bfe04e9381129a9a6f38.tar.bz2
- moved the defaults/prefs handling for settings during layout tests into
functions so it's a little easier to follow. - added color sync profile mgmt during layout tests so more images will match. - added signal handlers (like webkit) to do our best to get the color profile reset if we crash. Review URL: http://codereview.chromium.org/17244 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7729 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/tools/test_shell/test_shell_mac.mm206
1 files changed, 150 insertions, 56 deletions
diff --git a/webkit/tools/test_shell/test_shell_mac.mm b/webkit/tools/test_shell/test_shell_mac.mm
index c15a51c..7aedd413 100644
--- a/webkit/tools/test_shell/test_shell_mac.mm
+++ b/webkit/tools/test_shell/test_shell_mac.mm
@@ -127,73 +127,167 @@ void TestShell::PlatformShutdown() {
DCHECK(window_map_.Get().size() == 0);
}
-// static
-void TestShell::InitializeTestShell(bool layout_test_mode) {
- // This should move to a per-process platform-specific initialization function
- // when one exists.
- [NSApplication sharedApplication];
-
- window_list_ = new WindowList;
- layout_test_mode_ = layout_test_mode;
-
+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];
- 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);
+
+ 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"),
- CFSTR("DoubleMax"),
+ initialValue,
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);
+ 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
+ // when one exists.
+ [NSApplication sharedApplication];
+
+ window_list_ = new WindowList;
+ layout_test_mode_ = layout_test_mode;
+
+ if (layout_test_mode_) {
+ 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;