webkit_test_platform_support_win.cc revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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 "content/shell/app/webkit_test_platform_support.h" 6 7#include <windows.h> 8#include <iostream> 9#include <list> 10#include <string> 11 12#include "base/file_util.h" 13#include "base/files/file_path.h" 14#include "base/logging.h" 15#include "base/path_service.h" 16#include "base/strings/utf_string_conversions.h" 17 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) 23 24namespace content { 25 26namespace { 27 28bool 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")); 36 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; 42 } 43 44 DWORD num_fonts = 1; 45 HANDLE font_handle = 46 ::AddFontMemResourceEx(const_cast<char*>(font_buffer.c_str()), 47 font_buffer.length(), 48 0, 49 &num_fonts); 50 if (!font_handle) { 51 std::cerr << "Failed to register Ahem font\n"; 52 return false; 53 } 54 return true; 55} 56 57} // namespace 58 59bool CheckLayoutSystemDeps() { 60 std::list<std::string> errors; 61 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)."); 66 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."); 75 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; 98 } 99 } 100 101 for (std::list<std::string>::iterator it = errors.begin(); it != errors.end(); 102 ++it) { 103 std::cerr << *it << "\n"; 104 } 105 return errors.empty(); 106} 107 108bool WebKitTestPlatformInitialize() { 109 return SetupFonts(); 110} 111 112} // namespace content 113