- add sources.
[platform/framework/web/crosswalk.git] / src / content / shell / app / webkit_test_platform_support_mac.mm
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/command_line.h"
6 #include "base/logging.h"
7 #include "base/mac/bundle_locations.h"
8 #include "base/path_service.h"
9 #include "content/public/common/content_switches.h"
10 #include "content/shell/app/webkit_test_platform_support.h"
11
12 #include <AppKit/AppKit.h>
13 #include <Foundation/Foundation.h>
14
15 namespace content {
16
17 namespace {
18
19 void SetDefaultsToLayoutTestValues(void) {
20   // So we can match the WebKit layout tests, we want to force a bunch of
21   // preferences that control appearance to match.
22   // (We want to do this as early as possible in application startup so
23   // the settings are in before any higher layers could cache values.)
24
25   NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
26   // Do not set text-rendering prefs (AppleFontSmoothing,
27   // AppleAntiAliasingThreshold) here: Skia picks the right settings for this
28   // in layout test mode, see FontSkia.cpp in WebKit and
29   // SkFontHost_mac_coretext.cpp in skia.
30   const NSInteger kBlueTintedAppearance = 1;
31   [defaults setInteger:kBlueTintedAppearance
32                 forKey:@"AppleAquaColorVariant"];
33   [defaults setObject:@"0.709800 0.835300 1.000000"
34                forKey:@"AppleHighlightColor"];
35   [defaults setObject:@"0.500000 0.500000 0.500000"
36                forKey:@"AppleOtherHighlightColor"];
37   [defaults setObject:[NSArray arrayWithObject:@"en"]
38                forKey:@"AppleLanguages"];
39   [defaults setBool:NO
40              forKey:@"AppleScrollAnimationEnabled"];
41   [defaults setObject:@"Always"
42                forKey:@"AppleShowScrollBars"];
43 }
44
45 }  // namespace
46
47 bool CheckLayoutSystemDeps() {
48   return true;
49 }
50
51 bool WebKitTestPlatformInitialize() {
52
53   SetDefaultsToLayoutTestValues();
54
55   // Load font files in the resource folder.
56   static const char* const fontFileNames[] = {
57       "AHEM____.TTF",
58       "WebKitWeightWatcher100.ttf",
59       "WebKitWeightWatcher200.ttf",
60       "WebKitWeightWatcher300.ttf",
61       "WebKitWeightWatcher400.ttf",
62       "WebKitWeightWatcher500.ttf",
63       "WebKitWeightWatcher600.ttf",
64       "WebKitWeightWatcher700.ttf",
65       "WebKitWeightWatcher800.ttf",
66       "WebKitWeightWatcher900.ttf",
67   };
68
69   // mainBundle is Content Shell Helper.app.  Go two levels up to find
70   // Content Shell.app. Due to DumpRenderTree injecting the font files into
71   // its direct dependents, it's not easily possible to put the ttf files into
72   // the helper's resource directory instead of the outer bundle's resource
73   // directory.
74   NSString* bundle = [base::mac::FrameworkBundle() bundlePath];
75   bundle = [bundle stringByAppendingPathComponent:@"../.."];
76   NSURL* resources_directory = [[NSBundle bundleWithPath:bundle] resourceURL];
77
78   NSMutableArray* font_urls = [NSMutableArray array];
79   for (unsigned i = 0; i < arraysize(fontFileNames); ++i) {
80     NSURL* font_url = [resources_directory
81         URLByAppendingPathComponent:[NSString
82             stringWithUTF8String:fontFileNames[i]]];
83     [font_urls addObject:[font_url absoluteURL]];
84   }
85
86   CFArrayRef errors = 0;
87   if (!CTFontManagerRegisterFontsForURLs((CFArrayRef)font_urls,
88                                          kCTFontManagerScopeProcess,
89                                          &errors)) {
90     DLOG(FATAL) << "Fail to activate fonts.";
91     CFRelease(errors);
92   }
93
94   // Add <app bundle's parent dir>/plugins to the plugin path so we can load
95   // test plugins.
96   base::FilePath plugins_dir;
97   PathService::Get(base::DIR_EXE, &plugins_dir);
98   plugins_dir = plugins_dir.AppendASCII("../../../plugins");
99   CommandLine& command_line = *CommandLine::ForCurrentProcess();
100   command_line.AppendSwitchPath(switches::kExtraPluginDir, plugins_dir);
101
102   return true;
103 }
104
105 }  // namespace