Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: webkit/tools/test_shell/test_shell_mac.mm

Issue 17244: - moved the defaults/prefs handling for settings during layout tests into... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <ApplicationServices/ApplicationServices.h> 5 #include <ApplicationServices/ApplicationServices.h>
6 #import <Cocoa/Cocoa.h> 6 #import <Cocoa/Cocoa.h>
7 #include <sys/stat.h> 7 #include <sys/stat.h>
8 8
9 #include "webkit/tools/test_shell/test_shell.h" 9 #include "webkit/tools/test_shell/test_shell.h"
10 10
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 for (WindowList::iterator it = TestShell::windowList()->begin(); 120 for (WindowList::iterator it = TestShell::windowList()->begin();
121 it != TestShell::windowList()->end(); 121 it != TestShell::windowList()->end();
122 ++it) { 122 ++it) {
123 DestroyAssociatedShell(*it); 123 DestroyAssociatedShell(*it);
124 [*it release]; 124 [*it release];
125 } 125 }
126 // assert if we have anything left over, that would be bad. 126 // assert if we have anything left over, that would be bad.
127 DCHECK(window_map_.Get().size() == 0); 127 DCHECK(window_map_.Get().size() == 0);
128 } 128 }
129 129
130 static void SetDefaultsToLayoutTestValues(void) {
131 // So we can match the WebKit layout tests, we want to force a bunch of
132 // preferences that control appearance to match.
133 // (We want to do this as early as possible in application startup so
134 // the settings are in before any higher layers could cache values.)
135
136 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
137
138 const NSInteger kMinFontSizeCGSmoothes = 4;
139 const NSInteger kNoFontSmoothing = 0;
140 const NSInteger kBlueTintedAppearance = 1;
141 [defaults setInteger:kMinFontSizeCGSmoothes
142 forKey:@"AppleAntiAliasingThreshold"];
143 [defaults setInteger:kNoFontSmoothing
144 forKey:@"AppleFontSmoothing"];
145 [defaults setInteger:kBlueTintedAppearance
146 forKey:@"AppleAquaColorVariant"];
147 [defaults setObject:@"0.709800 0.835300 1.000000"
148 forKey:@"AppleHighlightColor"];
149 [defaults setObject:@"0.500000 0.500000 0.500000"
150 forKey:@"AppleOtherHighlightColor"];
151 [defaults setObject:[NSArray arrayWithObject:@"en"]
152 forKey:@"AppleLanguages"];
153
154 // AppKit pulls scrollbar style from NSUserDefaults. HIToolbox uses
155 // CFPreferences, but AnyApplication, so we set it, force it to load, and
156 // then reset the pref to what it was (HIToolbox will cache what it loaded).
157 [defaults setObject:@"DoubleMax" forKey:@"AppleScrollBarVariant"];
158 CFTypeRef initialValue
159 = CFPreferencesCopyValue(CFSTR("AppleScrollBarVariant"),
160 kCFPreferencesAnyApplication,
161 kCFPreferencesCurrentUser,
162 kCFPreferencesAnyHost);
163 CFPreferencesSetValue(CFSTR("AppleScrollBarVariant"),
164 CFSTR("DoubleMax"),
165 kCFPreferencesAnyApplication,
166 kCFPreferencesCurrentUser,
167 kCFPreferencesAnyHost);
168 // Make HIToolbox read from CFPreferences
169 ThemeScrollBarArrowStyle style;
170 GetThemeScrollBarArrowStyle(&style);
171 if (initialValue) {
172 // Reset the preference to what it was
173 CFPreferencesSetValue(CFSTR("AppleScrollBarVariant"),
174 initialValue,
175 kCFPreferencesAnyApplication,
176 kCFPreferencesCurrentUser,
177 kCFPreferencesAnyHost);
178 CFRelease(initialValue);
179 }
180 }
181
182 static void ClearAnyDefaultsForLayoutTests(void) {
183 // Not running a test, clear the keys so the TestShell looks right to the
184 // running user.
185
186 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
187
188 [defaults removeObjectForKey:@"AppleAntiAliasingThreshold"];
189 [defaults removeObjectForKey:@"AppleFontSmoothing"];
190 [defaults removeObjectForKey:@"AppleAquaColorVariant"];
191 [defaults removeObjectForKey:@"AppleHighlightColor"];
192 [defaults removeObjectForKey:@"AppleOtherHighlightColor"];
193 [defaults removeObjectForKey:@"AppleLanguages"];
194 [defaults removeObjectForKey:@"AppleScrollBarVariant"];
195 }
196
197 static CMProfileRef gUsersColorProfile = NULL;
198
199 static void RestoreUsersColorProfile(void) {
200 // This is called from the unsafe signal handers, so doing just about anything
201 // isn't really safe. But since we're already gonna crash, we give it a try
202 // anyways... (and WebKit uses this strategy...)
203
204 if (gUsersColorProfile) {
205 CGDirectDisplayID displayID = CGMainDisplayID();
206 CMError error = CMSetProfileByAVID((UInt32)displayID, gUsersColorProfile);
207 CMCloseProfile(gUsersColorProfile);
208 if (error) {
209 fprintf(stderr, "Failed to restore color profile, use System "
210 "Preferences -> Displays -> Color to reset. Error: %d",
211 (int)error);
212 }
213 gUsersColorProfile = NULL;
214 }
215 }
216
217 static void SimpleSignalHandler(int sig) {
218 // Try to restore and try to go down cleanly
219 RestoreUsersColorProfile();
220 exit(128 + sig);
221 }
222
223 static void CrashSignalHandler(int sig) {
224 // Try to restore and get out fast...
225 RestoreUsersColorProfile();
226 _exit(128 + sig);
227 }
228
229 static void InstallLayoutTestColorProfile(void) {
230 // To make sure we get consisten colors (not dependent on the Main display),
231 // we force the generic rgb color profile. This cases a change the user can
232 // see. We use the same basic method as WebKit for trying to make sure we
233 // get the profile back if we go down in flames.
234
235 // Save off the current
236 CGDirectDisplayID displayID = CGMainDisplayID();
237 CMProfileRef previousProfile;
238 CMError error = CMGetProfileByAVID((UInt32)displayID, &previousProfile);
239 if (error) {
240 DLOG(WARNING) << "failed to get the current color profile, "
241 "pixmaps won't match. Error: " << (int)error;
242 return;
243 }
244
245 // Install the generic one
246 NSColorSpace *genericSpace = [NSColorSpace genericRGBColorSpace];
247 CMProfileRef genericProfile = (CMProfileRef)[genericSpace colorSyncProfile];
248 if ((error = CMSetProfileByAVID((UInt32)displayID, genericProfile))) {
249 DLOG(WARNING) << "failed install the generic color profile, "
250 "pixmaps won't match. Error: " << (int)error;
251 return;
252 }
253
254 // Save the starting profile, and hook in as best we can to make sure when
255 // we exit, it's restored (use atexit() so direct calls to exit() call us).
256 gUsersColorProfile = previousProfile;
257 atexit(RestoreUsersColorProfile);
258 // The less scary signals...
259 signal(SIGINT, SimpleSignalHandler);
260 signal(SIGHUP, SimpleSignalHandler);
261 signal(SIGTERM, SimpleSignalHandler);
262 // And now the scary ones...
263 signal(SIGILL, CrashSignalHandler); // 4: illegal instruction
264 signal(SIGTRAP, CrashSignalHandler); // 5: trace trap
265 signal(SIGEMT, CrashSignalHandler); // 7: EMT instruction
266 signal(SIGFPE, CrashSignalHandler); // 8: floating point exception
267 signal(SIGBUS, CrashSignalHandler); // 10: bus error
268 signal(SIGSEGV, CrashSignalHandler); // 11: segmentation violation
269 signal(SIGSYS, CrashSignalHandler); // 12: bad argument to system call
270 signal(SIGPIPE, CrashSignalHandler); // 13: write on a pipe with no reader
271 signal(SIGXCPU, CrashSignalHandler); // 24: exceeded CPU time limit
272 signal(SIGXFSZ, CrashSignalHandler); // 25: exceeded file size limit
273 }
274
130 // static 275 // static
131 void TestShell::InitializeTestShell(bool layout_test_mode) { 276 void TestShell::InitializeTestShell(bool layout_test_mode) {
132 // This should move to a per-process platform-specific initialization function 277 // This should move to a per-process platform-specific initialization function
133 // when one exists. 278 // when one exists.
134 [NSApplication sharedApplication]; 279 [NSApplication sharedApplication];
135 280
136 window_list_ = new WindowList; 281 window_list_ = new WindowList;
137 layout_test_mode_ = layout_test_mode; 282 layout_test_mode_ = layout_test_mode;
138 283
139 // So we can match the WebKit layout tests, we want to force a bunch of
140 // preferences that control appearance to match.
141 // (We want to do this as early as possible in application startup so
142 // the settings are in before any higher layers could cache values.)
143 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
144 if (layout_test_mode_) { 284 if (layout_test_mode_) {
145 const NSInteger kMinFontSizeCGSmoothes = 4; 285 SetDefaultsToLayoutTestValues();
146 const NSInteger kNoFontSmoothing = 0; 286 // If we could check the command line to see if we're doing pixel tests,
147 const NSInteger kBlueTintedAppearance = 1; 287 // then we only install the color profile in that case.
148 [defaults setInteger:kMinFontSizeCGSmoothes 288 InstallLayoutTestColorProfile();
149 forKey:@"AppleAntiAliasingThreshold"];
150 [defaults setInteger:kNoFontSmoothing
151 forKey:@"AppleFontSmoothing"];
152 [defaults setInteger:kBlueTintedAppearance
153 forKey:@"AppleAquaColorVariant"];
154 [defaults setObject:@"0.709800 0.835300 1.000000"
155 forKey:@"AppleHighlightColor"];
156 [defaults setObject:@"0.500000 0.500000 0.500000"
157 forKey:@"AppleOtherHighlightColor"];
158 [defaults setObject:[NSArray arrayWithObject:@"en"]
159 forKey:@"AppleLanguages"];
160
161 // AppKit pulls scrollbar style from NSUserDefaults. HIToolbox uses
162 // CFPreferences, but AnyApplication, so we set it, force it to load, and
163 // then reset the pref to what it was (HIToolbox will cache what it loaded).
164 [defaults setObject:@"DoubleMax" forKey:@"AppleScrollBarVariant"];
165 CFTypeRef initialValue
166 = CFPreferencesCopyValue(CFSTR("AppleScrollBarVariant"),
167 kCFPreferencesAnyApplication,
168 kCFPreferencesCurrentUser,
169 kCFPreferencesAnyHost);
170 CFPreferencesSetValue(CFSTR("AppleScrollBarVariant"),
171 CFSTR("DoubleMax"),
172 kCFPreferencesAnyApplication,
173 kCFPreferencesCurrentUser,
174 kCFPreferencesAnyHost);
175 // Make HIToolbox read from CFPreferences
176 ThemeScrollBarArrowStyle style;
177 GetThemeScrollBarArrowStyle(&style);
178 if (initialValue) {
179 // Reset the preference to what it was
180 CFPreferencesSetValue(CFSTR("AppleScrollBarVariant"),
181 initialValue,
182 kCFPreferencesAnyApplication,
183 kCFPreferencesCurrentUser,
184 kCFPreferencesAnyHost);
185 CFRelease(initialValue);
186 }
187 } else { 289 } else {
188 // Not running a test, clear the keys so the TestShell looks right to the 290 ClearAnyDefaultsForLayoutTests();
189 // running user.
190 [defaults removeObjectForKey:@"AppleAntiAliasingThreshold"];
191 [defaults removeObjectForKey:@"AppleFontSmoothing"];
192 [defaults removeObjectForKey:@"AppleAquaColorVariant"];
193 [defaults removeObjectForKey:@"AppleHighlightColor"];
194 [defaults removeObjectForKey:@"AppleOtherHighlightColor"];
195 [defaults removeObjectForKey:@"AppleLanguages"];
196 [defaults removeObjectForKey:@"AppleScrollBarVariant"];
197 } 291 }
198 292
199 web_prefs_ = new WebPreferences; 293 web_prefs_ = new WebPreferences;
200 294
201 ResetWebPreferences(); 295 ResetWebPreferences();
202 296
203 // Load the Ahem font, which is used by layout tests. 297 // Load the Ahem font, which is used by layout tests.
204 const char* ahem_path_c; 298 const char* ahem_path_c;
205 FilePath ahem_path; // Ensure ahem_path_c storage is not freed too soon. 299 FilePath ahem_path; // Ensure ahem_path_c storage is not freed too soon.
206 if (mac_util::AmIBundled()) { 300 if (mac_util::AmIBundled()) {
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 return false; 848 return false;
755 } 849 }
756 850
757 void DidLoadPlugin(const std::string& filename) { 851 void DidLoadPlugin(const std::string& filename) {
758 } 852 }
759 853
760 void DidUnloadPlugin(const std::string& filename) { 854 void DidUnloadPlugin(const std::string& filename) {
761 } 855 }
762 856
763 } // namespace webkit_glue 857 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698