OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/browser/renderer_host/dwrite_font_proxy_message_filter_win.h" | 5 #include "content/browser/renderer_host/dwrite_font_proxy_message_filter_win.h" |
6 | 6 |
7 #include <dwrite.h> | 7 #include <dwrite.h> |
| 8 #include <dwrite_2.h> |
8 | 9 |
9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
11 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
12 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/win/windows_version.h" |
13 #include "content/common/dwrite_font_proxy_messages.h" | 15 #include "content/common/dwrite_font_proxy_messages.h" |
14 #include "content/public/test/test_browser_thread_bundle.h" | 16 #include "content/public/test/test_browser_thread_bundle.h" |
15 #include "ipc/ipc_message_macros.h" | 17 #include "ipc/ipc_message_macros.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "ui/gfx/win/direct_write.h" | 19 #include "ui/gfx/win/direct_write.h" |
18 | 20 |
19 namespace mswr = Microsoft::WRL; | 21 namespace mswr = Microsoft::WRL; |
20 | 22 |
21 namespace content { | 23 namespace content { |
22 | 24 |
(...skipping 26 matching lines...) Expand all Loading... |
49 void Send(IPC::SyncMessage* message) { | 51 void Send(IPC::SyncMessage* message) { |
50 std::unique_ptr<IPC::SyncMessage> deleter(message); | 52 std::unique_ptr<IPC::SyncMessage> deleter(message); |
51 std::unique_ptr<IPC::MessageReplyDeserializer> serializer( | 53 std::unique_ptr<IPC::MessageReplyDeserializer> serializer( |
52 message->GetReplyDeserializer()); | 54 message->GetReplyDeserializer()); |
53 filter_->OnMessageReceived(*message); | 55 filter_->OnMessageReceived(*message); |
54 base::RunLoop().RunUntilIdle(); | 56 base::RunLoop().RunUntilIdle(); |
55 ASSERT_NE(nullptr, filter_->GetReply()); | 57 ASSERT_NE(nullptr, filter_->GetReply()); |
56 serializer->SerializeOutputParameters(*(filter_->GetReply())); | 58 serializer->SerializeOutputParameters(*(filter_->GetReply())); |
57 } | 59 } |
58 | 60 |
| 61 bool IsDWrite2Available() { |
| 62 mswr::ComPtr<IDWriteFactory> factory; |
| 63 gfx::win::CreateDWriteFactory(&factory); |
| 64 mswr::ComPtr<IDWriteFactory2> factory2; |
| 65 factory.As<IDWriteFactory2>(&factory2); |
| 66 |
| 67 if (!factory2.Get()) { |
| 68 // IDWriteFactory2 is expected to not be available before Win8.1 |
| 69 EXPECT_LT(base::win::GetVersion(), base::win::VERSION_WIN8_1); |
| 70 } |
| 71 return factory2.Get(); |
| 72 } |
| 73 |
59 scoped_refptr<FilterWithFakeSender> filter_; | 74 scoped_refptr<FilterWithFakeSender> filter_; |
60 content::TestBrowserThreadBundle thread_bundle_; | 75 content::TestBrowserThreadBundle thread_bundle_; |
61 }; | 76 }; |
62 | 77 |
63 TEST_F(DWriteFontProxyMessageFilterUnitTest, GetFamilyCount) { | 78 TEST_F(DWriteFontProxyMessageFilterUnitTest, GetFamilyCount) { |
64 if (!gfx::win::ShouldUseDirectWrite()) | 79 if (!gfx::win::ShouldUseDirectWrite()) |
65 return; | 80 return; |
66 UINT32 family_count = 0; | 81 UINT32 family_count = 0; |
67 Send(new DWriteFontProxyMsg_GetFamilyCount(&family_count)); | 82 Send(new DWriteFontProxyMsg_GetFamilyCount(&family_count)); |
68 EXPECT_NE(0u, family_count); // Assume there's some fonts on the test system. | 83 EXPECT_NE(0u, family_count); // Assume there's some fonts on the test system. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 TEST_F(DWriteFontProxyMessageFilterUnitTest, GetFontFilesIndexOutOfBounds) { | 148 TEST_F(DWriteFontProxyMessageFilterUnitTest, GetFontFilesIndexOutOfBounds) { |
134 if (!gfx::win::ShouldUseDirectWrite()) | 149 if (!gfx::win::ShouldUseDirectWrite()) |
135 return; | 150 return; |
136 std::vector<base::string16> files; | 151 std::vector<base::string16> files; |
137 UINT32 invalid_index = 1000000; | 152 UINT32 invalid_index = 1000000; |
138 Send(new DWriteFontProxyMsg_GetFontFiles(invalid_index, &files)); | 153 Send(new DWriteFontProxyMsg_GetFontFiles(invalid_index, &files)); |
139 | 154 |
140 EXPECT_EQ(0u, files.size()); | 155 EXPECT_EQ(0u, files.size()); |
141 } | 156 } |
142 | 157 |
| 158 TEST_F(DWriteFontProxyMessageFilterUnitTest, MapCharacter) { |
| 159 if (!gfx::win::ShouldUseDirectWrite() || !IsDWrite2Available()) |
| 160 return; |
| 161 |
| 162 DWriteFontStyle font_style; |
| 163 font_style.font_weight = DWRITE_FONT_WEIGHT_NORMAL; |
| 164 font_style.font_slant = DWRITE_FONT_STYLE_NORMAL; |
| 165 font_style.font_stretch = DWRITE_FONT_STRETCH_NORMAL; |
| 166 |
| 167 MapCharactersResult result; |
| 168 Send(new DWriteFontProxyMsg_MapCharacters( |
| 169 L"abc", font_style, L"", DWRITE_READING_DIRECTION_LEFT_TO_RIGHT, L"", |
| 170 &result)); |
| 171 |
| 172 EXPECT_NE(UINT32_MAX, result.family_index); |
| 173 EXPECT_STRNE(L"", result.family_name.c_str()); |
| 174 EXPECT_EQ(3u, result.mapped_length); |
| 175 EXPECT_NE(0.0, result.scale); |
| 176 EXPECT_NE(0, result.font_style.font_weight); |
| 177 EXPECT_EQ(DWRITE_FONT_STYLE_NORMAL, result.font_style.font_slant); |
| 178 EXPECT_NE(0, result.font_style.font_stretch); |
| 179 } |
| 180 |
| 181 TEST_F(DWriteFontProxyMessageFilterUnitTest, MapCharacterInvalidCharacter) { |
| 182 if (!gfx::win::ShouldUseDirectWrite() || !IsDWrite2Available()) |
| 183 return; |
| 184 |
| 185 DWriteFontStyle font_style; |
| 186 font_style.font_weight = DWRITE_FONT_WEIGHT_NORMAL; |
| 187 font_style.font_slant = DWRITE_FONT_STYLE_NORMAL; |
| 188 font_style.font_stretch = DWRITE_FONT_STRETCH_NORMAL; |
| 189 |
| 190 MapCharactersResult result; |
| 191 Send(new DWriteFontProxyMsg_MapCharacters( |
| 192 L"\ufffe\uffffabc", font_style, L"en-us", |
| 193 DWRITE_READING_DIRECTION_LEFT_TO_RIGHT, L"", &result)); |
| 194 |
| 195 EXPECT_EQ(UINT32_MAX, result.family_index); |
| 196 EXPECT_STREQ(L"", result.family_name.c_str()); |
| 197 EXPECT_EQ(2u, result.mapped_length); |
| 198 } |
| 199 |
| 200 TEST_F(DWriteFontProxyMessageFilterUnitTest, MapCharacterInvalidAfterValid) { |
| 201 if (!gfx::win::ShouldUseDirectWrite() || !IsDWrite2Available()) |
| 202 return; |
| 203 |
| 204 DWriteFontStyle font_style; |
| 205 font_style.font_weight = DWRITE_FONT_WEIGHT_NORMAL; |
| 206 font_style.font_slant = DWRITE_FONT_STYLE_NORMAL; |
| 207 font_style.font_stretch = DWRITE_FONT_STRETCH_NORMAL; |
| 208 |
| 209 MapCharactersResult result; |
| 210 Send(new DWriteFontProxyMsg_MapCharacters( |
| 211 L"abc\ufffe\uffff", font_style, L"en-us", |
| 212 DWRITE_READING_DIRECTION_LEFT_TO_RIGHT, L"", &result)); |
| 213 |
| 214 EXPECT_NE(UINT32_MAX, result.family_index); |
| 215 EXPECT_STRNE(L"", result.family_name.c_str()); |
| 216 EXPECT_EQ(3u, result.mapped_length); |
| 217 EXPECT_NE(0.0, result.scale); |
| 218 EXPECT_NE(0, result.font_style.font_weight); |
| 219 EXPECT_EQ(DWRITE_FONT_STYLE_NORMAL, result.font_style.font_slant); |
| 220 EXPECT_NE(0, result.font_style.font_stretch); |
| 221 } |
| 222 |
143 } // namespace | 223 } // namespace |
144 | 224 |
145 } // namespace content | 225 } // namespace content |
OLD | NEW |