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

Unified Diff: content/child/dwrite_font_proxy/font_fallback_win_unittest.cc

Issue 1846433005: Implement direct write fallback proxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: content/child/dwrite_font_proxy/font_fallback_win_unittest.cc
diff --git a/content/child/dwrite_font_proxy/font_fallback_win_unittest.cc b/content/child/dwrite_font_proxy/font_fallback_win_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..765f928f1b205f0dec7df654849fcf4436da9f02
--- /dev/null
+++ b/content/child/dwrite_font_proxy/font_fallback_win_unittest.cc
@@ -0,0 +1,90 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/child/dwrite_font_proxy/font_fallback_win.h"
+
+#include <dwrite.h>
+#include <shlobj.h>
+#include <wrl.h>
+
+#include <vector>
+
+#include "base/memory/ref_counted.h"
+#include "content/child/dwrite_font_proxy/dwrite_font_proxy_win.h"
+#include "content/common/dwrite_text_analysis_source_win.h"
+#include "content/test/dwrite_font_fake_sender_win.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace mswr = Microsoft::WRL;
+
+namespace content {
+
+namespace {
+
+class FontFallbackUnitTest : public testing::Test {
+ public:
+ FontFallbackUnitTest() {
+ CreateDWriteFactory(&factory_);
+
+ std::vector<base::char16> font_path;
+ font_path.resize(MAX_PATH);
+ SHGetSpecialFolderPath(nullptr /* hwndOwner - reserved */, font_path.data(),
+ CSIDL_FONTS, FALSE /* fCreate*/);
+ base::string16 arial;
+ arial.append(font_path.data()).append(L"\\arial.ttf");
+
+ fake_collection_ = new FakeFontCollection();
+ fake_collection_->AddFont(L"Arial")
+ .AddFamilyName(L"en-us", L"Arial")
ananta 2016/04/12 23:44:39 Please split these statements up. Difficult to rea
Ilya Kulshin 2016/04/13 01:33:29 This is just using the builder pattern. I find it
+ .AddFilePath(arial);
+
+ mswr::MakeAndInitialize<DWriteFontCollectionProxy>(
+ &collection_, factory_.Get(), fake_collection_->GetSender());
+ }
+
+ void CreateDWriteFactory(IUnknown** factory) {
+ using DWriteCreateFactoryProc = decltype(DWriteCreateFactory)*;
+ HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll");
+ if (!dwrite_dll)
+ return;
+
+ DWriteCreateFactoryProc dwrite_create_factory_proc =
+ reinterpret_cast<DWriteCreateFactoryProc>(
+ GetProcAddress(dwrite_dll, "DWriteCreateFactory"));
+ if (!dwrite_create_factory_proc)
+ return;
+
+ dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED,
+ __uuidof(IDWriteFactory), factory);
+ }
+
+ scoped_refptr<FakeFontCollection> fake_collection_;
+ mswr::ComPtr<IDWriteFactory> factory_;
+ mswr::ComPtr<DWriteFontCollectionProxy> collection_;
+};
+
+TEST_F(FontFallbackUnitTest, MapCharacters) {
+ mswr::ComPtr<FontFallback> fallback;
+ mswr::MakeAndInitialize<FontFallback>(&fallback, collection_.Get(),
+ fake_collection_->GetTrackingSender());
+
+ mswr::ComPtr<IDWriteFont> font;
+ UINT32 mapped_length = 0;
+ float scale = 0.0;
+
+ mswr::ComPtr<TextAnalysisSource> text;
+ mswr::MakeAndInitialize<TextAnalysisSource>(
+ &text, L"hello", L"en-us", nullptr,
+ DWRITE_READING_DIRECTION_LEFT_TO_RIGHT);
+ fallback->MapCharacters(text.Get(), 0, 1, nullptr, nullptr,
+ DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
+ DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font,
+ &scale);
+
+ EXPECT_EQ(1, mapped_length); // The fake sender only maps one character
+ EXPECT_NE(nullptr, font.Get());
+}
+
+} // namespace
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698