Wrap Pepper CDM Content Settings code in defined(ENABLE_PEPPER_CDMS).
[chromium-blink-merge.git] / content / shell / webkit_test_platform_support_win.cc
blobdf9faf2e497611137f296357e2cbf6c08496cd22
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"
7 #include <iostream>
8 #include <list>
9 #include <string>
10 #include <windows.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/strings/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)
24 namespace content {
26 namespace {
28 bool SetupFonts() {
29 // Load Ahem font.
30 // AHEM____.TTF is copied to the directory of DumpRenderTree.exe by
31 // WebKit.gyp.
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())
40 << "\n";
41 return false;
44 DWORD num_fonts = 1;
45 HANDLE font_handle =
46 ::AddFontMemResourceEx(const_cast<char*>(font_buffer.c_str()),
47 font_buffer.length(),
49 &num_fonts);
50 if (!font_handle) {
51 std::cerr << "Failed to register Ahem font\n";
52 return false;
54 return true;
57 } // namespace
59 bool CheckLayoutSystemDeps() {
60 std::list<std::string> errors;
62 // This metric will be 17 when font size is "Normal".
63 // The size of drop-down menus depends on it.
64 if (::GetSystemMetrics(SM_CXVSCROLL) != 17)
65 errors.push_back("Must use normal size fonts (96 dpi).");
67 // ClearType must be disabled, because the rendering is unpredictable.
68 BOOL font_smoothing_enabled;
69 ::SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &font_smoothing_enabled, 0);
70 int font_smoothing_type;
71 ::SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &font_smoothing_type, 0);
72 if (font_smoothing_enabled &&
73 (font_smoothing_type == FE_FONTSMOOTHINGCLEARTYPE))
74 errors.push_back("ClearType must be disabled.");
76 // Check that we're using the default system fonts.
77 OSVERSIONINFO version_info = {0};
78 version_info.dwOSVersionInfoSize = sizeof(version_info);
79 ::GetVersionEx(&version_info);
80 bool is_vista_or_later = (version_info.dwMajorVersion >= 6);
81 NONCLIENTMETRICS metrics = {0};
82 metrics.cbSize = is_vista_or_later ? (sizeof NONCLIENTMETRICS)
83 : NONCLIENTMETRICS_SIZE_PRE_VISTA;
84 bool success = !!::SystemParametersInfo(
85 SPI_GETNONCLIENTMETRICS, metrics.cbSize, &metrics, 0);
86 CHECK(success);
87 LOGFONTW* system_fonts[] =
88 {&metrics.lfStatusFont, &metrics.lfMenuFont, &metrics.lfSmCaptionFont};
89 const wchar_t* required_font = is_vista_or_later ? L"Segoe UI" : L"Tahoma";
90 int required_font_size = is_vista_or_later ? -12 : -11;
91 for (size_t i = 0; i < arraysize(system_fonts); ++i) {
92 if (system_fonts[i]->lfHeight != required_font_size ||
93 wcscmp(required_font, system_fonts[i]->lfFaceName)) {
94 errors.push_back(is_vista_or_later
95 ? "Must use either the Aero or Basic theme."
96 : "Must use the default XP theme (Luna).");
97 break;
101 for (std::list<std::string>::iterator it = errors.begin(); it != errors.end();
102 ++it) {
103 std::cerr << *it << "\n";
105 return errors.empty();
108 bool WebKitTestPlatformInitialize() {
109 return SetupFonts();
112 } // namespace content