| Index: content/browser/renderer_host/dwrite_font_proxy_message_filter_win_unittest.cc
|
| diff --git a/content/browser/renderer_host/dwrite_font_proxy_message_filter_win_unittest.cc b/content/browser/renderer_host/dwrite_font_proxy_message_filter_win_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..09c96c673e2b7faa5f2f53b2b127e0e90078ec45
|
| --- /dev/null
|
| +++ b/content/browser/renderer_host/dwrite_font_proxy_message_filter_win_unittest.cc
|
| @@ -0,0 +1,133 @@
|
| +// Copyright 2015 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/browser/renderer_host/dwrite_font_proxy_message_filter_win.h"
|
| +
|
| +#include <dwrite.h>
|
| +
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/test/test_simple_task_runner.h"
|
| +#include "base/thread_task_runner_handle.h"
|
| +#include "content/common/dwrite_font_proxy_messages.h"
|
| +#include "ipc/ipc_message_macros.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace mswr = Microsoft::WRL;
|
| +
|
| +namespace content {
|
| +
|
| +bool RunTasksSynchronously(BrowserThread::ID thread,
|
| + const tracked_objects::Location& location,
|
| + const base::Closure& task,
|
| + const base::Closure& reply) {
|
| + task.Run();
|
| + reply.Run();
|
| + return true;
|
| +}
|
| +
|
| +class FilterWithFakeSender : public DWriteFontProxyMessageFilter {
|
| + public:
|
| + FilterWithFakeSender()
|
| + : DWriteFontProxyMessageFilter(&RunTasksSynchronously) {}
|
| + bool Send(IPC::Message* msg) override {
|
| + EXPECT_EQ(nullptr, replyMessage_.get());
|
| + replyMessage_.reset(msg);
|
| + return true;
|
| + }
|
| +
|
| + IPC::Message* GetReply() { return replyMessage_.get(); }
|
| +
|
| + void ResetReply() { replyMessage_.reset(nullptr); }
|
| +
|
| + private:
|
| + scoped_ptr<IPC::Message> replyMessage_;
|
| +};
|
| +
|
| +class DWriteFontProxyMessageFilterUnitTest : public testing::Test {
|
| + public:
|
| + DWriteFontProxyMessageFilterUnitTest() {
|
| + filter_ = new FilterWithFakeSender();
|
| + }
|
| +
|
| + void Send(IPC::SyncMessage* message) {
|
| + std::unique_ptr<IPC::SyncMessage> deleter(message);
|
| + scoped_ptr<IPC::MessageReplyDeserializer> serializer(
|
| + message->GetReplyDeserializer());
|
| + filter_->OnMessageReceived(*message);
|
| + ASSERT_NE(nullptr, filter_->GetReply());
|
| + serializer->SerializeOutputParameters(*(filter_->GetReply()));
|
| + }
|
| +
|
| + scoped_refptr<FilterWithFakeSender> filter_;
|
| +};
|
| +
|
| +TEST_F(DWriteFontProxyMessageFilterUnitTest, GetFamilyCount) {
|
| + uint32 familyCount = 0;
|
| + Send(new DWriteFontProxyMsg_GetFamilyCount(&familyCount));
|
| + EXPECT_NE(0u, familyCount); // Assume there's some fonts on the test system.
|
| +}
|
| +
|
| +TEST_F(DWriteFontProxyMessageFilterUnitTest, FindFamily) {
|
| + uint32 arialIndex = 0;
|
| + Send(new DWriteFontProxyMsg_FindFamily(L"Arial", &arialIndex));
|
| + EXPECT_NE(UINT_MAX, arialIndex);
|
| +
|
| + filter_->ResetReply();
|
| + uint32 timesIndex = 0;
|
| + Send(new DWriteFontProxyMsg_FindFamily(L"Times New Roman", ×Index));
|
| + EXPECT_NE(UINT_MAX, timesIndex);
|
| + EXPECT_NE(arialIndex, timesIndex);
|
| +
|
| + filter_->ResetReply();
|
| + uint32 unknownIndex = 0;
|
| + Send(new DWriteFontProxyMsg_FindFamily(L"Not a font family", &unknownIndex));
|
| + EXPECT_EQ(UINT_MAX, unknownIndex);
|
| +}
|
| +
|
| +TEST_F(DWriteFontProxyMessageFilterUnitTest, GetFamilyNames) {
|
| + uint32 arialIndex = 0;
|
| + Send(new DWriteFontProxyMsg_FindFamily(L"Arial", &arialIndex));
|
| + filter_->ResetReply();
|
| +
|
| + std::vector<StringPair> names;
|
| + Send(new DWriteFontProxyMsg_GetFamilyNames(arialIndex, &names));
|
| +
|
| + EXPECT_LT(0u, names.size());
|
| + for (auto& pair : names) {
|
| + EXPECT_STRNE(L"", pair.first.c_str());
|
| + EXPECT_STRNE(L"", pair.second.c_str());
|
| + }
|
| +}
|
| +
|
| +TEST_F(DWriteFontProxyMessageFilterUnitTest, GetFamilyNamesIndexOutOfBounds) {
|
| + std::vector<StringPair> names;
|
| + uint32 invalidIndex = 1000000;
|
| + Send(new DWriteFontProxyMsg_GetFamilyNames(invalidIndex, &names));
|
| +
|
| + EXPECT_EQ(0u, names.size());
|
| +}
|
| +
|
| +TEST_F(DWriteFontProxyMessageFilterUnitTest, GetFontFiles) {
|
| + uint32 arialIndex = 0;
|
| + Send(new DWriteFontProxyMsg_FindFamily(L"Arial", &arialIndex));
|
| + filter_->ResetReply();
|
| +
|
| + std::vector<base::string16> files;
|
| + Send(new DWriteFontProxyMsg_GetFontFiles(arialIndex, &files));
|
| +
|
| + EXPECT_LT(0u, files.size());
|
| + for (base::string16& file : files) {
|
| + EXPECT_STRNE(L"", file.c_str());
|
| + }
|
| +}
|
| +
|
| +TEST_F(DWriteFontProxyMessageFilterUnitTest, GetFontFilesIndexOutOfBounds) {
|
| + std::vector<base::string16> files;
|
| + uint32 invalidIndex = 1000000;
|
| + Send(new DWriteFontProxyMsg_GetFontFiles(invalidIndex, &files));
|
| +
|
| + EXPECT_EQ(0u, files.size());
|
| +}
|
| +
|
| +} // namespace content
|
|
|