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

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

Issue 19352002: Fixes vertical alignment of RenderText. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes the unit test. Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/font_list.cc ('k') | ui/gfx/render_text.cc » ('j') | no next file with comments »
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 <string> 8 #include <string>
8 #include <vector> 9 #include <vector>
9 10
10 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace { 14 namespace {
14 15
15 // Helper function for comparing fonts for equality. 16 // Helper function for comparing fonts for equality.
16 std::string FontToString(const gfx::Font& font) { 17 std::string FontToString(const gfx::Font& font) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 FontList font_list = FontList(fonts); 226 FontList font_list = FontList(fonts);
226 227
227 FontList derived = font_list.DeriveFontListWithSize(5); 228 FontList derived = font_list.DeriveFontListWithSize(5);
228 const std::vector<Font>& derived_fonts = derived.GetFonts(); 229 const std::vector<Font>& derived_fonts = derived.GetFonts();
229 230
230 EXPECT_EQ(2U, derived_fonts.size()); 231 EXPECT_EQ(2U, derived_fonts.size());
231 EXPECT_EQ("Arial|5", FontToString(derived_fonts[0])); 232 EXPECT_EQ("Arial|5", FontToString(derived_fonts[0]));
232 EXPECT_EQ("Sans serif|5", FontToString(derived_fonts[1])); 233 EXPECT_EQ("Sans serif|5", FontToString(derived_fonts[1]));
233 } 234 }
234 235
236 TEST(FontListTest, Fonts_GetHeight_GetBaseline) {
237 // If a font list has only one font, the height and baseline must be the same.
238 Font font1("Arial", 16);
239 FontList font_list1("Arial, 16px");
240 EXPECT_EQ(font1.GetHeight(), font_list1.GetHeight());
241 EXPECT_EQ(font1.GetBaseline(), font_list1.GetBaseline());
242
243 // If there are two different fonts, the font list returns the max value
244 // for ascent and descent.
245 Font font2("Symbol", 16);
246 EXPECT_NE(font1.GetBaseline(), font2.GetBaseline());
247 EXPECT_NE(font1.GetHeight() - font1.GetBaseline(),
248 font2.GetHeight() - font2.GetBaseline());
249 std::vector<Font> fonts;
250 fonts.push_back(font1);
251 fonts.push_back(font2);
252 FontList font_list_mix(fonts);
253 // ascent of FontList == max(ascent of Fonts)
msw 2013/07/19 17:30:34 nit: Capitalize 'Ascent' here and 'Descent' below.
254 EXPECT_EQ(std::max(font1.GetHeight() - font1.GetBaseline(),
255 font2.GetHeight() - font2.GetBaseline()),
256 font_list_mix.GetHeight() - font_list_mix.GetBaseline());
257 // descent of FontList == max(descent of Fonts)
258 EXPECT_EQ(std::max(font1.GetBaseline(), font2.GetBaseline()),
259 font_list_mix.GetBaseline());
260 }
261
235 } // namespace gfx 262 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/font_list.cc ('k') | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698