1 // Copyright (c) 2012 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/webkit_test_platform_support.h"
12 #include "base/files/file_path.h"
13 #include "base/file_util.h"
14 #include "base/logging.h"
15 #include "base/path_service.h"
16 #include "base/utf_string_conversions.h"
18 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(struct_name, member) \
19 offsetof(struct_name, member) + \
20 (sizeof static_cast<struct_name*>(0)->member)
21 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \
22 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont)
30 // AHEM____.TTF is copied to the directory of DumpRenderTree.exe by
32 base::FilePath base_path
;
33 PathService::Get(base::DIR_MODULE
, &base_path
);
34 base::FilePath font_path
=
35 base_path
.Append(FILE_PATH_LITERAL("/AHEM____.TTF"));
37 std::string font_buffer
;
38 if (!file_util::ReadFileToString(font_path
, &font_buffer
)) {
39 std::cerr
<< "Failed to load font " << WideToUTF8(font_path
.value())
46 ::AddFontMemResourceEx(const_cast<char*>(font_buffer
.c_str()),
51 std::cerr
<< "Failed to register Ahem font\n";
57 bool CheckLayoutTestSystemDependencies() {
58 std::list
<std::string
> errors
;
60 // This metric will be 17 when font size is "Normal".
61 // The size of drop-down menus depends on it.
62 if (::GetSystemMetrics(SM_CXVSCROLL
) != 17)
63 errors
.push_back("Must use normal size fonts (96 dpi).");
65 // ClearType must be disabled, because the rendering is unpredictable.
66 BOOL font_smoothing_enabled
;
67 ::SystemParametersInfo(SPI_GETFONTSMOOTHING
, 0, &font_smoothing_enabled
, 0);
68 int font_smoothing_type
;
69 ::SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE
, 0, &font_smoothing_type
, 0);
70 if (font_smoothing_enabled
&&
71 (font_smoothing_type
== FE_FONTSMOOTHINGCLEARTYPE
))
72 errors
.push_back("ClearType must be disabled.");
74 // Check that we're using the default system fonts.
75 OSVERSIONINFO version_info
= {0};
76 version_info
.dwOSVersionInfoSize
= sizeof(version_info
);
77 ::GetVersionEx(&version_info
);
78 bool is_vista_or_later
= (version_info
.dwMajorVersion
>= 6);
79 NONCLIENTMETRICS metrics
= {0};
80 metrics
.cbSize
= is_vista_or_later
? (sizeof NONCLIENTMETRICS
)
81 : NONCLIENTMETRICS_SIZE_PRE_VISTA
;
82 bool success
= !!::SystemParametersInfo(
83 SPI_GETNONCLIENTMETRICS
, metrics
.cbSize
, &metrics
, 0);
85 LOGFONTW
* system_fonts
[] =
86 {&metrics
.lfStatusFont
, &metrics
.lfMenuFont
, &metrics
.lfSmCaptionFont
};
87 const wchar_t* required_font
= is_vista_or_later
? L
"Segoe UI" : L
"Tahoma";
88 int required_font_size
= is_vista_or_later
? -12 : -11;
89 for (size_t i
= 0; i
< arraysize(system_fonts
); ++i
) {
90 if (system_fonts
[i
]->lfHeight
!= required_font_size
||
91 wcscmp(required_font
, system_fonts
[i
]->lfFaceName
)) {
92 errors
.push_back(is_vista_or_later
93 ? "Must use either the Aero or Basic theme."
94 : "Must use the default XP theme (Luna).");
99 for (std::list
<std::string
>::iterator it
= errors
.begin(); it
!= errors
.end();
101 std::cerr
<< *it
<< "\n";
103 return errors
.empty();
108 bool WebKitTestPlatformInitialize() {
109 return CheckLayoutTestSystemDependencies() && SetupFonts();
112 } // namespace content