Roll WebRTC 9189:9205, Libjingle 9186:9198
[chromium-blink-merge.git] / content / shell / app / blink_test_platform_support_win.cc
bloba7e6becaa489d089756bb9d6f745b97e479ba4c6
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"
7 #include <windows.h>
8 #include <iostream>
9 #include <list>
10 #include <string>
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)
26 namespace content {
28 namespace {
30 bool SetupFonts() {
31 // Load Ahem font.
32 // AHEM____.TTF is copied to the directory of DumpRenderTree.exe by
33 // WebKit.gyp.
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.
44 // GDI registration.
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())
48 << "\n";
49 return false;
52 DWORD num_fonts = 1;
53 HANDLE font_handle =
54 ::AddFontMemResourceEx(const_cast<char*>(font_buffer.c_str()),
55 font_buffer.length(),
57 &num_fonts);
58 if (!font_handle) {
59 std::cerr << "Failed to register Ahem font\n";
60 return false;
63 // DirectWrite sandbox registration.
64 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
65 command_line.AppendSwitchASCII(switches::kRegisterFontFiles,
66 base::WideToUTF8(font_path.value()));
68 return true;
71 } // namespace
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);
91 CHECK(success);
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).");
102 break;
106 for (std::list<std::string>::iterator it = errors.begin(); it != errors.end();
107 ++it) {
108 std::cerr << *it << "\n";
110 return errors.empty();
113 bool BlinkTestPlatformInitialize() {
114 return SetupFonts();
117 } // namespace content