Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(806)

Side by Side Diff: ui/gfx/font_list_unittest.cc

Issue 844083002: Get all font unittests running with DirectWrite on Windows 7+ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix presubmit Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/gfx/platform_font_win.cc » ('j') | ui/gfx/platform_font_win_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/font_list.h" 5 #include "ui/gfx/font_list.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 TEST(FontListTest, Fonts_GetHeight_GetBaseline) { 259 TEST(FontListTest, Fonts_GetHeight_GetBaseline) {
260 // If a font list has only one font, the height and baseline must be the same. 260 // If a font list has only one font, the height and baseline must be the same.
261 Font font1("Arial", 16); 261 Font font1("Arial", 16);
262 ASSERT_EQ("arial", 262 ASSERT_EQ("arial",
263 base::StringToLowerASCII(font1.GetActualFontNameForTesting())); 263 base::StringToLowerASCII(font1.GetActualFontNameForTesting()));
264 FontList font_list1("Arial, 16px"); 264 FontList font_list1("Arial, 16px");
265 EXPECT_EQ(font1.GetHeight(), font_list1.GetHeight()); 265 EXPECT_EQ(font1.GetHeight(), font_list1.GetHeight());
266 EXPECT_EQ(font1.GetBaseline(), font_list1.GetBaseline()); 266 EXPECT_EQ(font1.GetBaseline(), font_list1.GetBaseline());
267 267
268 // If there are two different fonts, the font list returns the max value 268 // If there are two different fonts, the font list returns the max value
269 // for ascent and descent. 269 // for the baseline (ascent) and height.
270 Font font2("Symbol", 16); 270 Font font2("Symbol", 16);
271 ASSERT_EQ("symbol", 271 ASSERT_EQ("symbol",
272 base::StringToLowerASCII(font2.GetActualFontNameForTesting())); 272 base::StringToLowerASCII(font2.GetActualFontNameForTesting()));
273 EXPECT_NE(font1.GetBaseline(), font2.GetBaseline()); 273 EXPECT_NE(font1.GetBaseline(), font2.GetBaseline());
274 EXPECT_NE(font1.GetHeight() - font1.GetBaseline(), 274 EXPECT_NE(font1.GetHeight(), font2.GetHeight());
275 font2.GetHeight() - font2.GetBaseline());
276 std::vector<Font> fonts; 275 std::vector<Font> fonts;
277 fonts.push_back(font1); 276 fonts.push_back(font1);
278 fonts.push_back(font2); 277 fonts.push_back(font2);
279 FontList font_list_mix(fonts); 278 FontList font_list_mix(fonts);
279 // descent of FontList == max(descent of Fonts)
msw 2015/01/10 01:50:15 The baseline is actually the ascent, not descent.
ananta 2015/01/10 02:05:49 Done.
280 EXPECT_EQ(std::max(font1.GetBaseline(), font2.GetBaseline()),
281 font_list_mix.GetBaseline());
282 // FIXME
283 // The height of the font list should be the max height of the fonts in it.
msw 2015/01/10 01:50:15 Oh darn, my earlier advice was wrong. I remember w
ananta 2015/01/10 02:05:49 Done.
284 // This is not the case for Mac and should be fixed.
285 #if defined(OS_MACOSX)
280 // ascent of FontList == max(ascent of Fonts) 286 // ascent of FontList == max(ascent of Fonts)
281 EXPECT_EQ(std::max(font1.GetHeight() - font1.GetBaseline(), 287 EXPECT_EQ(std::max(font1.GetHeight() - font1.GetBaseline(),
282 font2.GetHeight() - font2.GetBaseline()), 288 font2.GetHeight() - font2.GetBaseline()),
283 font_list_mix.GetHeight() - font_list_mix.GetBaseline()); 289 font_list_mix.GetHeight() - font_list_mix.GetBaseline());
284 // descent of FontList == max(descent of Fonts) 290 #else
285 EXPECT_EQ(std::max(font1.GetBaseline(), font2.GetBaseline()), 291 // Height of FontList == max(Height of Fonts)
286 font_list_mix.GetBaseline()); 292 EXPECT_EQ(std::max(font1.GetHeight(), font2.GetHeight()),
293 font_list_mix.GetHeight());
294 #endif
287 } 295 }
288 296
289 TEST(FontListTest, Fonts_DeriveWithHeightUpperBound) { 297 TEST(FontListTest, Fonts_DeriveWithHeightUpperBound) {
290 std::vector<Font> fonts; 298 std::vector<Font> fonts;
291 299
292 fonts.push_back(gfx::Font("Arial", 18)); 300 fonts.push_back(gfx::Font("Arial", 18));
293 fonts.push_back(gfx::Font("Sans serif", 18)); 301 fonts.push_back(gfx::Font("Sans serif", 18));
294 fonts.push_back(gfx::Font("Symbol", 18)); 302 fonts.push_back(gfx::Font("Symbol", 18));
295 FontList font_list = FontList(fonts); 303 FontList font_list = FontList(fonts);
296 304
297 // A smaller upper bound should derive a font list with a smaller height. 305 // A smaller upper bound should derive a font list with a smaller height.
298 const int height_1 = font_list.GetHeight() - 5; 306 const int height_1 = font_list.GetHeight() - 5;
299 FontList derived_1 = font_list.DeriveWithHeightUpperBound(height_1); 307 FontList derived_1 = font_list.DeriveWithHeightUpperBound(height_1);
300 EXPECT_LE(derived_1.GetHeight(), height_1); 308 EXPECT_LE(derived_1.GetHeight(), height_1);
301 EXPECT_LT(derived_1.GetHeight(), font_list.GetHeight()); 309 EXPECT_LT(derived_1.GetHeight(), font_list.GetHeight());
302 EXPECT_LT(derived_1.GetFontSize(), font_list.GetFontSize()); 310 EXPECT_LT(derived_1.GetFontSize(), font_list.GetFontSize());
303 311
304 // A larger upper bound should not change the height of the font list. 312 // A larger upper bound should not change the height of the font list.
305 const int height_2 = font_list.GetHeight() + 5; 313 const int height_2 = font_list.GetHeight() + 5;
306 FontList derived_2 = font_list.DeriveWithHeightUpperBound(height_2); 314 FontList derived_2 = font_list.DeriveWithHeightUpperBound(height_2);
307 EXPECT_LE(derived_2.GetHeight(), height_2); 315 EXPECT_LE(derived_2.GetHeight(), height_2);
308 EXPECT_EQ(font_list.GetHeight(), derived_2.GetHeight()); 316 EXPECT_EQ(font_list.GetHeight(), derived_2.GetHeight());
309 EXPECT_EQ(font_list.GetFontSize(), derived_2.GetFontSize()); 317 EXPECT_EQ(font_list.GetFontSize(), derived_2.GetFontSize());
310 } 318 }
311 319
312 } // namespace gfx 320 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/platform_font_win.cc » ('j') | ui/gfx/platform_font_win_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698