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.
5 #include "content/shell/app/blink_test_platform_support.h"
12 #include "base/command_line.h"
13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h"
15 #include "base/logging.h"
16 #include "base/path_service.h"
17 #include "base/strings/utf_string_conversions.h"
18 #include "content/shell/common/shell_switches.h"
20 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(struct_name, member) \
21 offsetof(struct_name, member) + \
22 (sizeof static_cast<struct_name*>(0)->member)
23 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \
24 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont)
32 // AHEM____.TTF is copied to the directory of DumpRenderTree.exe by
34 base::FilePath base_path
;
35 PathService::Get(base::DIR_MODULE
, &base_path
);
36 base::FilePath font_path
=
37 base_path
.Append(FILE_PATH_LITERAL("/AHEM____.TTF"));
39 // We do two registrations:
40 // 1. For GDI font rendering via ::AddFontMemResourceEx.
41 // 2. For DirectWrite rendering by appending a command line flag that tells
42 // the sandbox policy/warmup to grant access to the given path.
45 std::string font_buffer
;
46 if (!base::ReadFileToString(font_path
, &font_buffer
)) {
47 std::cerr
<< "Failed to load font " << base::WideToUTF8(font_path
.value())
54 ::AddFontMemResourceEx(const_cast<char*>(font_buffer
.c_str()),
59 std::cerr
<< "Failed to register Ahem font\n";
63 // DirectWrite sandbox registration.
64 base::CommandLine
& command_line
= *base::CommandLine::ForCurrentProcess();
65 command_line
.AppendSwitchASCII(switches::kRegisterFontFiles
,
66 base::WideToUTF8(font_path
.value()));
73 bool CheckLayoutSystemDeps() {
74 std::list
<std::string
> errors
;
76 // This metric will be 17 when font size is "Normal".
77 // The size of drop-down menus depends on it.
78 if (::GetSystemMetrics(SM_CXVSCROLL
) != 17)
79 errors
.push_back("Must use normal size fonts (96 dpi).");
81 // Check that we're using the default system fonts.
82 OSVERSIONINFO version_info
= {0};
83 version_info
.dwOSVersionInfoSize
= sizeof(version_info
);
84 ::GetVersionEx(&version_info
);
85 bool is_vista_or_later
= (version_info
.dwMajorVersion
>= 6);
86 NONCLIENTMETRICS metrics
= {0};
87 metrics
.cbSize
= is_vista_or_later
? sizeof(NONCLIENTMETRICS
)
88 : NONCLIENTMETRICS_SIZE_PRE_VISTA
;
89 bool success
= !!::SystemParametersInfo(
90 SPI_GETNONCLIENTMETRICS
, metrics
.cbSize
, &metrics
, 0);
92 LOGFONTW
* system_fonts
[] =
93 {&metrics
.lfStatusFont
, &metrics
.lfMenuFont
, &metrics
.lfSmCaptionFont
};
94 const wchar_t* required_font
= is_vista_or_later
? L
"Segoe UI" : L
"Tahoma";
95 int required_font_size
= is_vista_or_later
? -12 : -11;
96 for (size_t i
= 0; i
< arraysize(system_fonts
); ++i
) {
97 if (system_fonts
[i
]->lfHeight
!= required_font_size
||
98 wcscmp(required_font
, system_fonts
[i
]->lfFaceName
)) {
99 errors
.push_back(is_vista_or_later
100 ? "Must use either the Aero or Basic theme."
101 : "Must use the default XP theme (Luna).");
106 for (std::list
<std::string
>::iterator it
= errors
.begin(); it
!= errors
.end();
108 std::cerr
<< *it
<< "\n";
110 return errors
.empty();
113 bool BlinkTestPlatformInitialize() {
117 } // namespace content