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

Side by Side Diff: content/child/dwrite_font_proxy/font_fallback_win_unittest.cc

Issue 1906633003: Implement fallback cache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blinkfontfallback
Patch Set: Add some checks and comments Created 4 years, 8 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/child/dwrite_font_proxy/font_fallback_win.h" 5 #include "content/child/dwrite_font_proxy/font_fallback_win.h"
6 6
7 #include <dwrite.h> 7 #include <dwrite.h>
8 #include <shlobj.h> 8 #include <shlobj.h>
9 #include <wrl.h> 9 #include <wrl.h>
10 10
(...skipping 17 matching lines...) Expand all
28 CreateDWriteFactory(&factory_); 28 CreateDWriteFactory(&factory_);
29 29
30 factory_->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE, 30 factory_->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE,
31 L"en-us", true /* ignoreUserOverride */, 31 L"en-us", true /* ignoreUserOverride */,
32 &number_substitution_); 32 &number_substitution_);
33 33
34 std::vector<base::char16> font_path; 34 std::vector<base::char16> font_path;
35 font_path.resize(MAX_PATH); 35 font_path.resize(MAX_PATH);
36 SHGetSpecialFolderPath(nullptr /* hwndOwner - reserved */, font_path.data(), 36 SHGetSpecialFolderPath(nullptr /* hwndOwner - reserved */, font_path.data(),
37 CSIDL_FONTS, FALSE /* fCreate*/); 37 CSIDL_FONTS, FALSE /* fCreate*/);
38 base::string16 arial_path; 38 base::string16 segoe_path;
39 arial_path.append(font_path.data()).append(L"\\arial.ttf"); 39 segoe_path.append(font_path.data()).append(L"\\seguisym.ttf");
40 40
41 fake_collection_ = new FakeFontCollection(); 41 fake_collection_ = new FakeFontCollection();
42 fake_collection_->AddFont(L"Arial") 42 fake_collection_->AddFont(L"Segoe UI Symbol")
43 .AddFamilyName(L"en-us", L"Arial") 43 .AddFamilyName(L"en-us", L"Segoe UI Symbol")
44 .AddFilePath(arial_path); 44 .AddFilePath(segoe_path);
45 45
46 mswr::MakeAndInitialize<DWriteFontCollectionProxy>( 46 mswr::MakeAndInitialize<DWriteFontCollectionProxy>(
47 &collection_, factory_.Get(), fake_collection_->GetSender()); 47 &collection_, factory_.Get(), fake_collection_->GetSender());
48 } 48 }
49 49
50 void CreateDWriteFactory(IUnknown** factory) { 50 void CreateDWriteFactory(IUnknown** factory) {
51 using DWriteCreateFactoryProc = decltype(DWriteCreateFactory)*; 51 using DWriteCreateFactoryProc = decltype(DWriteCreateFactory)*;
52 HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll"); 52 HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll");
53 if (!dwrite_dll) 53 if (!dwrite_dll)
54 return; 54 return;
(...skipping 10 matching lines...) Expand all
65 65
66 scoped_refptr<FakeFontCollection> fake_collection_; 66 scoped_refptr<FakeFontCollection> fake_collection_;
67 mswr::ComPtr<IDWriteFactory> factory_; 67 mswr::ComPtr<IDWriteFactory> factory_;
68 mswr::ComPtr<DWriteFontCollectionProxy> collection_; 68 mswr::ComPtr<DWriteFontCollectionProxy> collection_;
69 mswr::ComPtr<IDWriteNumberSubstitution> number_substitution_; 69 mswr::ComPtr<IDWriteNumberSubstitution> number_substitution_;
70 }; 70 };
71 71
72 TEST_F(FontFallbackUnitTest, MapCharacters) { 72 TEST_F(FontFallbackUnitTest, MapCharacters) {
73 mswr::ComPtr<FontFallback> fallback; 73 mswr::ComPtr<FontFallback> fallback;
74 mswr::MakeAndInitialize<FontFallback>(&fallback, collection_.Get(), 74 mswr::MakeAndInitialize<FontFallback>(&fallback, collection_.Get(),
75 fake_collection_->GetTrackingSender()); 75 fake_collection_->GetSender());
76 76
77 mswr::ComPtr<IDWriteFont> font; 77 mswr::ComPtr<IDWriteFont> font;
78 UINT32 mapped_length = 0; 78 UINT32 mapped_length = 0;
79 float scale = 0.0; 79 float scale = 0.0;
80 80
81 mswr::ComPtr<TextAnalysisSource> text; 81 mswr::ComPtr<TextAnalysisSource> text;
82 mswr::MakeAndInitialize<TextAnalysisSource>( 82 mswr::MakeAndInitialize<TextAnalysisSource>(
83 &text, L"hello", L"en-us", number_substitution_.Get(), 83 &text, L"hello", L"en-us", number_substitution_.Get(),
84 DWRITE_READING_DIRECTION_LEFT_TO_RIGHT); 84 DWRITE_READING_DIRECTION_LEFT_TO_RIGHT);
85 fallback->MapCharacters(text.Get(), 0, 1, nullptr, nullptr, 85 fallback->MapCharacters(text.Get(), 0, 5, nullptr, nullptr,
86 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, 86 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
87 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font, 87 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font,
88 &scale); 88 &scale);
89 89
90 EXPECT_EQ(1u, mapped_length); // The fake sender only maps one character 90 EXPECT_EQ(1u, mapped_length); // The fake sender only maps one character
91 EXPECT_NE(nullptr, font.Get()); 91 EXPECT_NE(nullptr, font.Get());
92 } 92 }
93 93
94 TEST_F(FontFallbackUnitTest, DuplicateCallsShouldNotRepeatIPC) {
95 mswr::ComPtr<FontFallback> fallback;
96 mswr::MakeAndInitialize<FontFallback>(&fallback, collection_.Get(),
97 fake_collection_->GetTrackingSender());
98
99 mswr::ComPtr<IDWriteFont> font;
100 UINT32 mapped_length = 0;
101 float scale = 0.0;
102
103 mswr::ComPtr<TextAnalysisSource> text;
104 mswr::MakeAndInitialize<TextAnalysisSource>(
105 &text, L"hello", L"en-us", number_substitution_.Get(),
106 DWRITE_READING_DIRECTION_LEFT_TO_RIGHT);
107 fallback->MapCharacters(text.Get(), 0, 5, nullptr, nullptr,
108 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
109 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font,
110 &scale);
111 mapped_length = 0;
112 fallback->MapCharacters(text.Get(), 0, 5, nullptr, nullptr,
113 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
114 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font,
115 &scale);
116
117 EXPECT_EQ(1u, fake_collection_->MessageCount());
118 EXPECT_EQ(5u, mapped_length);
119 }
120
121 TEST_F(FontFallbackUnitTest, DifferentFamilyShouldNotReuseCache) {
122 mswr::ComPtr<FontFallback> fallback;
123 mswr::MakeAndInitialize<FontFallback>(&fallback, collection_.Get(),
124 fake_collection_->GetTrackingSender());
125
126 mswr::ComPtr<IDWriteFont> font;
127 UINT32 mapped_length = 0;
128 float scale = 0.0;
129
130 mswr::ComPtr<TextAnalysisSource> text;
131 mswr::MakeAndInitialize<TextAnalysisSource>(
132 &text, L"hello", L"en-us", number_substitution_.Get(),
133 DWRITE_READING_DIRECTION_LEFT_TO_RIGHT);
134 fallback->MapCharacters(text.Get(), 0, 5, nullptr, L"font1",
135 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
136 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font,
137 &scale);
138 fallback->MapCharacters(text.Get(), 0, 5, nullptr, L"font2",
139 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
140 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font,
141 &scale);
142
143 EXPECT_EQ(2u, fake_collection_->MessageCount());
144 }
145
146 TEST_F(FontFallbackUnitTest, CacheMissShouldRepeatIPC) {
147 mswr::ComPtr<FontFallback> fallback;
148 mswr::MakeAndInitialize<FontFallback>(&fallback, collection_.Get(),
149 fake_collection_->GetTrackingSender());
150
151 mswr::ComPtr<IDWriteFont> font;
152 UINT32 mapped_length = 0;
153 float scale = 0.0;
154
155 mswr::ComPtr<TextAnalysisSource> text;
156 mswr::MakeAndInitialize<TextAnalysisSource>(
157 &text, L"hello", L"en-us", number_substitution_.Get(),
158 DWRITE_READING_DIRECTION_LEFT_TO_RIGHT);
159 mswr::ComPtr<TextAnalysisSource> unmappable_text;
160 mswr::MakeAndInitialize<TextAnalysisSource>(
161 &unmappable_text, L"\uffff", L"en-us", number_substitution_.Get(),
162 DWRITE_READING_DIRECTION_LEFT_TO_RIGHT);
163 fallback->MapCharacters(text.Get(), 0, 5, nullptr, nullptr,
164 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
165 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font,
166 &scale);
167 fallback->MapCharacters(unmappable_text.Get(), 0, 1, nullptr, nullptr,
168 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
169 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font,
170 &scale);
171
172 EXPECT_EQ(2u, fake_collection_->MessageCount());
173 }
174
175 TEST_F(FontFallbackUnitTest, SurrogatePairCacheHit) {
176 mswr::ComPtr<FontFallback> fallback;
177 mswr::MakeAndInitialize<FontFallback>(&fallback, collection_.Get(),
178 fake_collection_->GetTrackingSender());
179
180 mswr::ComPtr<IDWriteFont> font;
181 UINT32 mapped_length = 0;
182 float scale = 0.0;
183
184 mswr::ComPtr<TextAnalysisSource> text;
185 mswr::MakeAndInitialize<TextAnalysisSource>(
186 &text, L"hello", L"en-us", number_substitution_.Get(),
187 DWRITE_READING_DIRECTION_LEFT_TO_RIGHT);
188 mswr::ComPtr<TextAnalysisSource> surrogate_pair_text;
189 mswr::MakeAndInitialize<TextAnalysisSource>(
190 &surrogate_pair_text, L"\U0001d300", L"en-us", number_substitution_.Get(),
191 DWRITE_READING_DIRECTION_LEFT_TO_RIGHT);
192 fallback->MapCharacters(text.Get(), 0, 5, nullptr, nullptr,
193 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
194 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font,
195 &scale);
196 fallback->MapCharacters(surrogate_pair_text.Get(), 0, 2, nullptr, nullptr,
197 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
198 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font,
199 &scale);
200
201 EXPECT_EQ(1u, fake_collection_->MessageCount());
202 EXPECT_EQ(2u, mapped_length);
203 }
204
94 } // namespace 205 } // namespace
95 } // namespace content 206 } // namespace content
OLDNEW
« no previous file with comments | « content/child/dwrite_font_proxy/font_fallback_win.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698