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/child/font_warmup_win.h" | 5 #include "content/child/font_warmup_win.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/sys_byteorder.h" | 16 #include "base/sys_byteorder.h" |
17 #include "base/win/windows_version.h" | 17 #include "base/win/windows_version.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/skia/include/core/SkRefCnt.h" | |
19 #include "third_party/skia/include/core/SkString.h" | 20 #include "third_party/skia/include/core/SkString.h" |
20 #include "third_party/skia/include/core/SkTypeface.h" | 21 #include "third_party/skia/include/core/SkTypeface.h" |
21 #include "third_party/skia/include/ports/SkFontMgr.h" | 22 #include "third_party/skia/include/ports/SkFontMgr.h" |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 class TestSkTypeface : public SkTypeface { | 28 class TestSkTypeface : public SkTypeface { |
28 public: | 29 public: |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 }; | 124 }; |
124 | 125 |
125 const char* kTestFontFamily = "GDITest"; | 126 const char* kTestFontFamily = "GDITest"; |
126 const wchar_t* kTestFontFamilyW = L"GDITest"; | 127 const wchar_t* kTestFontFamilyW = L"GDITest"; |
127 const SkFontTableTag kTestFontTableTag = 0x11223344; | 128 const SkFontTableTag kTestFontTableTag = 0x11223344; |
128 const char* kTestFontData = "GDITestGDITest"; | 129 const char* kTestFontData = "GDITestGDITest"; |
129 const wchar_t* kTestFontFamilyInvalid = L"InvalidFont"; | 130 const wchar_t* kTestFontFamilyInvalid = L"InvalidFont"; |
130 | 131 |
131 class TestSkFontMgr : public SkFontMgr { | 132 class TestSkFontMgr : public SkFontMgr { |
132 public: | 133 public: |
133 TestSkFontMgr() { content::SetPreSandboxWarmupFontMgrForTesting(this); } | 134 TestSkFontMgr() { |
135 content::SetPreSandboxWarmupFontMgrForTesting(sk_ref_sp(this)); | |
136 } | |
134 ~TestSkFontMgr() override { | 137 ~TestSkFontMgr() override { |
135 content::SetPreSandboxWarmupFontMgrForTesting(nullptr); | 138 content::SetPreSandboxWarmupFontMgrForTesting(sk_sp<SkFontMgr>()); |
f(malita)
2017/01/09 15:25:34
nit: I think nullptr reads better here.
bungeman-chromium
2017/01/09 19:15:28
Done.
| |
136 } | 139 } |
137 | 140 |
138 protected: | 141 protected: |
139 int onCountFamilies() const override { return 1; } | 142 int onCountFamilies() const override { return 1; } |
140 | 143 |
141 void onGetFamilyName(int index, SkString* familyName) const override { | 144 void onGetFamilyName(int index, SkString* familyName) const override { |
142 if (index == 0) | 145 if (index == 0) |
143 *familyName = kTestFontFamily; | 146 *familyName = kTestFontFamily; |
144 } | 147 } |
145 | 148 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 DWORD data_size = static_cast<DWORD>(strlen(kTestFontData)); | 420 DWORD data_size = static_cast<DWORD>(strlen(kTestFontData)); |
418 std::vector<char> data(data_size); | 421 std::vector<char> data(data_size); |
419 DWORD size = GetFontData(hdc, kTestFontTableTag, 0, &data[0], data.size()); | 422 DWORD size = GetFontData(hdc, kTestFontTableTag, 0, &data[0], data.size()); |
420 EXPECT_EQ(size, data_size); | 423 EXPECT_EQ(size, data_size); |
421 EXPECT_EQ(memcmp(&data[0], kTestFontData, data.size()), 0); | 424 EXPECT_EQ(memcmp(&data[0], kTestFontData, data.size()), 0); |
422 EXPECT_TRUE(DeleteObject(font)); | 425 EXPECT_TRUE(DeleteObject(font)); |
423 EXPECT_TRUE(DeleteDC(hdc)); | 426 EXPECT_TRUE(DeleteDC(hdc)); |
424 } | 427 } |
425 | 428 |
426 } // namespace content | 429 } // namespace content |
OLD | NEW |