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

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

Issue 394963002: linux: Add tests for FontRenderParams on Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix embarrassingly-broken comparison Created 6 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/BUILD.gn ('k') | ui/gfx/gfx.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 "ui/gfx/font_render_params.h"
6
7 #include "base/files/file_path.h"
8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h"
10 #include "base/macros.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/gfx/test/fontconfig_util_linux.h"
13
14 namespace gfx {
15
16 namespace {
17
18 // Loads the first system font defined by fontconfig_util_linux.h with a base
19 // filename of |basename|. Case is ignored.
20 bool LoadSystemFont(const std::string& basename) {
21 for (size_t i = 0; i < kNumSystemFontsForFontconfig; ++i) {
22 base::FilePath path(gfx::kSystemFontsForFontconfig[i]);
23 if (strcasecmp(path.BaseName().value().c_str(), basename.c_str()) == 0)
24 return LoadFontIntoFontconfig(path);
25 }
26 LOG(ERROR) << "Unable to find system font named " << basename;
27 return false;
28 }
29
30 } // namespace
31
32 class FontRenderParamsTest : public testing::Test {
33 public:
34 FontRenderParamsTest() {
35 SetUpFontconfig();
36 CHECK(temp_dir_.CreateUniqueTempDir());
37 }
38
39 virtual ~FontRenderParamsTest() {
40 TearDownFontconfig();
41 }
42
43 protected:
44 base::ScopedTempDir temp_dir_;
45
46 private:
47 DISALLOW_COPY_AND_ASSIGN(FontRenderParamsTest);
48 };
49
50 TEST_F(FontRenderParamsTest, Default) {
51 // Fontconfig needs to know about at least one font to return a match.
52 ASSERT_TRUE(LoadSystemFont("arial.ttf"));
53 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(),
54 std::string(kFontconfigFileHeader) +
55 kFontconfigMatchHeader +
56 CreateFontconfigEditStanza("antialias", "bool", "true") +
57 CreateFontconfigEditStanza("autohint", "bool", "false") +
58 CreateFontconfigEditStanza("hinting", "bool", "true") +
59 CreateFontconfigEditStanza("hintstyle", "const", "hintfull") +
60 CreateFontconfigEditStanza("rgba", "const", "rgb") +
61 kFontconfigMatchFooter +
62 kFontconfigFileFooter));
63
64 FontRenderParams params = GetDefaultFontRenderParams();
65 #if defined(OS_CHROMEOS)
66 // Chrome OS uses its own defaults for everything except subpixel rendering,
67 // which comes from Fontconfig.
68 EXPECT_TRUE(params.antialiasing);
69 EXPECT_TRUE(params.autohinter);
70 EXPECT_TRUE(params.use_bitmaps);
71 EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting);
72 #else
73 // Desktop Linux gets all settings from fontconfig.
74 EXPECT_TRUE(params.antialiasing);
75 EXPECT_FALSE(params.autohinter);
76 EXPECT_TRUE(params.use_bitmaps);
77 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting);
78 #endif
79 EXPECT_FALSE(params.subpixel_positioning);
80 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB,
81 params.subpixel_rendering);
82 }
83
84 // Chrome OS ignores most Fontconfig settings.
85 #if !defined(OS_CHROMEOS)
86 TEST_F(FontRenderParamsTest, Size) {
87 // Fontconfig needs to know about at least one font to return a match.
88 ASSERT_TRUE(LoadSystemFont("arial.ttf"));
89 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(),
90 std::string(kFontconfigFileHeader) +
91 kFontconfigMatchHeader +
92 CreateFontconfigEditStanza("antialias", "bool", "true") +
93 CreateFontconfigEditStanza("hinting", "bool", "true") +
94 CreateFontconfigEditStanza("hintstyle", "const", "hintfull") +
95 CreateFontconfigEditStanza("rgba", "const", "none") +
96 kFontconfigMatchFooter +
97 kFontconfigMatchHeader +
98 CreateFontconfigTestStanza("pixelsize", "less_eq", "double", "10") +
99 CreateFontconfigEditStanza("antialias", "bool", "false") +
100 kFontconfigMatchFooter +
101 kFontconfigMatchHeader +
102 CreateFontconfigTestStanza("size", "more_eq", "double", "20") +
103 CreateFontconfigEditStanza("hintstyle", "const", "hintslight") +
104 CreateFontconfigEditStanza("rgba", "const", "rgb") +
105 kFontconfigMatchFooter +
106 kFontconfigFileFooter));
107
108 // The defaults should be used when the supplied size isn't matched by the
109 // second or third blocks.
110 int pixel_size = 12;
111 FontRenderParams params = GetCustomFontRenderParams(
112 false, NULL, &pixel_size, NULL, NULL);
113 EXPECT_TRUE(params.antialiasing);
114 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting);
115 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE,
116 params.subpixel_rendering);
117
118 pixel_size = 10;
119 params = GetCustomFontRenderParams(false, NULL, &pixel_size, NULL, NULL);
120 EXPECT_FALSE(params.antialiasing);
121 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting);
122 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE,
123 params.subpixel_rendering);
124
125 int point_size = 20;
126 params = GetCustomFontRenderParams(false, NULL, NULL, &point_size, NULL);
127 EXPECT_TRUE(params.antialiasing);
128 EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting);
129 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB,
130 params.subpixel_rendering);
131 }
132 #endif // !defined(OS_CHROMEOS)
133
134 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/BUILD.gn ('k') | ui/gfx/gfx.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698