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

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

Issue 407763003: linux: Avoid using unset Fontconfig properties. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/font_render_params_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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_render_params.h" 5 #include "ui/gfx/font_render_params.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/gfx/font.h" 12 #include "ui/gfx/font.h"
13 #include "ui/gfx/linux_font_delegate.h"
14 #include "ui/gfx/pango_util.h"
msw 2014/07/21 22:19:48 Should this (and parts of [Test|Linux]FontDelegate
Daniel Erat 2014/07/21 22:54:42 whoops, sorry for missing this the first time thro
msw 2014/07/21 23:38:30 Okay, I'm not actually worried beyond breaking any
13 #include "ui/gfx/test/fontconfig_util_linux.h" 15 #include "ui/gfx/test/fontconfig_util_linux.h"
14 16
15 namespace gfx { 17 namespace gfx {
16 18
17 namespace { 19 namespace {
18 20
21 // Implementation of LinuxFontDelegate that returns a canned FontRenderParams
22 // struct. This is used to isolate tests from the system's local configuration.
23 class TestFontDelegate : public LinuxFontDelegate {
24 public:
25 TestFontDelegate() {}
26 virtual ~TestFontDelegate() {}
27
28 void set_params(const FontRenderParams& params) { params_ = params; }
29
30 virtual FontRenderParams GetDefaultFontRenderParams() const OVERRIDE {
31 return params_;
32 }
33 virtual scoped_ptr<ScopedPangoFontDescription>
34 GetDefaultPangoFontDescription() const OVERRIDE {
35 NOTIMPLEMENTED();
36 return scoped_ptr<ScopedPangoFontDescription>();
37 }
38 virtual double GetFontDPI() const OVERRIDE {
39 NOTIMPLEMENTED();
40 return 96.0;
41 }
42
43 private:
44 FontRenderParams params_;
45
46 DISALLOW_COPY_AND_ASSIGN(TestFontDelegate);
47 };
48
19 // Loads the first system font defined by fontconfig_util_linux.h with a base 49 // Loads the first system font defined by fontconfig_util_linux.h with a base
20 // filename of |basename|. Case is ignored. 50 // filename of |basename|. Case is ignored.
21 bool LoadSystemFont(const std::string& basename) { 51 bool LoadSystemFont(const std::string& basename) {
22 for (size_t i = 0; i < kNumSystemFontsForFontconfig; ++i) { 52 for (size_t i = 0; i < kNumSystemFontsForFontconfig; ++i) {
23 base::FilePath path(gfx::kSystemFontsForFontconfig[i]); 53 base::FilePath path(gfx::kSystemFontsForFontconfig[i]);
24 if (strcasecmp(path.BaseName().value().c_str(), basename.c_str()) == 0) 54 if (strcasecmp(path.BaseName().value().c_str(), basename.c_str()) == 0)
25 return LoadFontIntoFontconfig(path); 55 return LoadFontIntoFontconfig(path);
26 } 56 }
27 LOG(ERROR) << "Unable to find system font named " << basename; 57 LOG(ERROR) << "Unable to find system font named " << basename;
28 return false; 58 return false;
29 } 59 }
30 60
31 } // namespace 61 } // namespace
32 62
33 class FontRenderParamsTest : public testing::Test { 63 class FontRenderParamsTest : public testing::Test {
34 public: 64 public:
35 FontRenderParamsTest() { 65 FontRenderParamsTest() {
36 SetUpFontconfig(); 66 SetUpFontconfig();
37 CHECK(temp_dir_.CreateUniqueTempDir()); 67 CHECK(temp_dir_.CreateUniqueTempDir());
68 orig_font_delegate_ = LinuxFontDelegate::instance();
69 LinuxFontDelegate::SetInstance(&test_font_delegate_);
38 } 70 }
39 71
40 virtual ~FontRenderParamsTest() { 72 virtual ~FontRenderParamsTest() {
73 LinuxFontDelegate::SetInstance(
74 const_cast<LinuxFontDelegate*>(orig_font_delegate_));
41 TearDownFontconfig(); 75 TearDownFontconfig();
42 } 76 }
43 77
44 protected: 78 protected:
45 base::ScopedTempDir temp_dir_; 79 base::ScopedTempDir temp_dir_;
80 const LinuxFontDelegate* orig_font_delegate_;
msw 2014/07/21 22:19:48 optional nit: original
Daniel Erat 2014/07/21 22:34:33 Done.
81 TestFontDelegate test_font_delegate_;
46 82
47 private: 83 private:
48 DISALLOW_COPY_AND_ASSIGN(FontRenderParamsTest); 84 DISALLOW_COPY_AND_ASSIGN(FontRenderParamsTest);
49 }; 85 };
50 86
51 TEST_F(FontRenderParamsTest, Default) { 87 TEST_F(FontRenderParamsTest, Default) {
52 // Fontconfig needs to know about at least one font to return a match. 88 // Fontconfig needs to know about at least one font to return a match.
53 ASSERT_TRUE(LoadSystemFont("arial.ttf")); 89 ASSERT_TRUE(LoadSystemFont("arial.ttf"));
54 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), 90 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(),
55 std::string(kFontconfigFileHeader) + 91 std::string(kFontconfigFileHeader) +
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 kFontconfigMatchHeader + 210 kFontconfigMatchHeader +
175 CreateFontconfigEditStanza("antialias", "bool", "false") + 211 CreateFontconfigEditStanza("antialias", "bool", "false") +
176 kFontconfigMatchFooter + 212 kFontconfigMatchFooter +
177 kFontconfigMatchHeader + 213 kFontconfigMatchHeader +
178 CreateFontconfigTestStanza("scalable", "eq", "bool", "true") + 214 CreateFontconfigTestStanza("scalable", "eq", "bool", "true") +
179 CreateFontconfigEditStanza("antialias", "bool", "true") + 215 CreateFontconfigEditStanza("antialias", "bool", "true") +
180 kFontconfigMatchFooter + 216 kFontconfigMatchFooter +
181 kFontconfigFileFooter)); 217 kFontconfigFileFooter));
182 218
183 // Check that we specifically ask how scalable fonts should be rendered. 219 // Check that we specifically ask how scalable fonts should be rendered.
184 FontRenderParams params = GetCustomFontRenderParams( 220 FontRenderParams params = GetCustomFontRenderParams(
msw 2014/07/21 22:19:48 nit: use GetDefaultFontRenderParams.
Daniel Erat 2014/07/21 22:34:33 i'm actually wondering if i should just delete tha
185 false, NULL, NULL, NULL, NULL, NULL); 221 false, NULL, NULL, NULL, NULL, NULL);
186 EXPECT_TRUE(params.antialiasing); 222 EXPECT_TRUE(params.antialiasing);
187 } 223 }
188 224
189 TEST_F(FontRenderParamsTest, UseBitmaps) { 225 TEST_F(FontRenderParamsTest, UseBitmaps) {
190 ASSERT_TRUE(LoadSystemFont("arial.ttf")); 226 ASSERT_TRUE(LoadSystemFont("arial.ttf"));
191 // Load a config that enables embedded bitmaps for fonts <= 10 pixels. 227 // Load a config that enables embedded bitmaps for fonts <= 10 pixels.
192 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), 228 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(),
193 std::string(kFontconfigFileHeader) + 229 std::string(kFontconfigFileHeader) +
194 kFontconfigMatchHeader + 230 kFontconfigMatchHeader +
195 CreateFontconfigEditStanza("embeddedbitmap", "bool", "false") + 231 CreateFontconfigEditStanza("embeddedbitmap", "bool", "false") +
196 kFontconfigMatchFooter + 232 kFontconfigMatchFooter +
197 kFontconfigMatchHeader + 233 kFontconfigMatchHeader +
198 CreateFontconfigTestStanza("pixelsize", "less_eq", "double", "10") + 234 CreateFontconfigTestStanza("pixelsize", "less_eq", "double", "10") +
199 CreateFontconfigEditStanza("embeddedbitmap", "bool", "true") + 235 CreateFontconfigEditStanza("embeddedbitmap", "bool", "true") +
200 kFontconfigMatchFooter + 236 kFontconfigMatchFooter +
201 kFontconfigFileFooter)); 237 kFontconfigFileFooter));
202 238
203 FontRenderParams params = GetCustomFontRenderParams( 239 FontRenderParams params = GetCustomFontRenderParams(
msw 2014/07/21 22:19:48 nit: use GetDefaultFontRenderParams.
204 false, NULL, NULL, NULL, NULL, NULL); 240 false, NULL, NULL, NULL, NULL, NULL);
205 EXPECT_FALSE(params.use_bitmaps); 241 EXPECT_FALSE(params.use_bitmaps);
206 242
207 const int pixel_size = 5; 243 const int pixel_size = 5;
208 params = GetCustomFontRenderParams( 244 params = GetCustomFontRenderParams(
209 false, NULL, &pixel_size, NULL, NULL, NULL); 245 false, NULL, &pixel_size, NULL, NULL, NULL);
210 EXPECT_TRUE(params.use_bitmaps); 246 EXPECT_TRUE(params.use_bitmaps);
211 } 247 }
212 248
249 TEST_F(FontRenderParamsTest, OnlySetConfiguredValues) {
250 // Configure the LinuxFontDelegate (which queries GtkSettings on desktop
251 // Linux) to request subpixel rendering.
252 FontRenderParams system_params;
253 system_params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB;
254 test_font_delegate_.set_params(system_params);
255
256 // Load a Fontconfig config that enables antialiasing but doesn't say anything
257 // about subpixel rendering.
258 ASSERT_TRUE(LoadSystemFont("arial.ttf"));
259 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(),
260 std::string(kFontconfigFileHeader) +
261 kFontconfigMatchHeader +
262 CreateFontconfigEditStanza("antialias", "bool", "true") +
263 kFontconfigMatchFooter +
264 kFontconfigFileFooter));
265
266 // The subpixel rendering setting from the delegate should make it through.
267 FontRenderParams params = GetCustomFontRenderParams(
msw 2014/07/21 22:19:48 nit: use GetDefaultFontRenderParams.
268 false, NULL, NULL, NULL, NULL, NULL);
269 EXPECT_EQ(system_params.subpixel_rendering, params.subpixel_rendering);
270 }
271
213 } // namespace gfx 272 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/font_render_params_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698