| Index: content/test/dwrite_font_fake_sender_win.cc
|
| diff --git a/content/test/dwrite_font_fake_sender_win.cc b/content/test/dwrite_font_fake_sender_win.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..021f8ba832847da4467bea7cea01bb33227f0ade
|
| --- /dev/null
|
| +++ b/content/test/dwrite_font_fake_sender_win.cc
|
| @@ -0,0 +1,154 @@
|
| +// 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/test/dwrite_font_fake_sender_win.h"
|
| +
|
| +#include <shlobj.h>
|
| +
|
| +#include "content/common/dwrite_font_proxy_messages.h"
|
| +
|
| +namespace content {
|
| +
|
| +void AddFamily(FakeFontCollection* collection,
|
| + const base::string16& fontPath,
|
| + const base::string16& familyName,
|
| + const base::string16& baseFileName) {
|
| + collection->AddFont(familyName)
|
| + .AddFamilyName(L"en-us", familyName)
|
| + .AddFilePath(fontPath + L"\\" + baseFileName + L".ttf")
|
| + .AddFilePath(fontPath + L"\\" + baseFileName + L"bd.ttf")
|
| + .AddFilePath(fontPath + L"\\" + baseFileName + L"bi.ttf")
|
| + .AddFilePath(fontPath + L"\\" + baseFileName + L"i.ttf");
|
| +}
|
| +
|
| +IPC::Sender* CreateFakeCollectionSender() {
|
| + std::vector<base::char16> fontPathChars;
|
| + fontPathChars.resize(MAX_PATH);
|
| + SHGetSpecialFolderPath(NULL /* hwndOwner - reserved */, fontPathChars.data(),
|
| + CSIDL_FONTS, FALSE /* fCreate */);
|
| + base::string16 fontPath(fontPathChars.data());
|
| + FakeFontCollection* fakeCollection = new FakeFontCollection();
|
| + AddFamily(fakeCollection, fontPath, L"Arial", L"arial");
|
| + AddFamily(fakeCollection, fontPath, L"Courier New", L"cour");
|
| + AddFamily(fakeCollection, fontPath, L"Times New Roman", L"times");
|
| + return fakeCollection->GetSender();
|
| +}
|
| +
|
| +FakeFont& FakeFontCollection::AddFont(const base::string16& fontName) {
|
| + fonts_.emplace_back(fontName);
|
| + return fonts_.back();
|
| +}
|
| +
|
| +unsigned int FakeFontCollection::MessageCount() {
|
| + return messages_.size();
|
| +}
|
| +
|
| +IPC::Message* FakeFontCollection::GetMessage(unsigned int index) {
|
| + return messages_[index].get();
|
| +}
|
| +
|
| +IPC::Sender* FakeFontCollection::GetSender() {
|
| + return new FakeSender(this, false);
|
| +}
|
| +
|
| +IPC::Sender* FakeFontCollection::GetTrackingSender() {
|
| + return new FakeSender(this, true);
|
| +}
|
| +
|
| +scoped_ptr<IPC::Message>& FakeFontCollection::ReplySender::OnMessageReceived(
|
| + const IPC::Message& msg) {
|
| + reply_.reset();
|
| + bool handled = true;
|
| + IPC_BEGIN_MESSAGE_MAP(ReplySender, msg)
|
| + IPC_MESSAGE_HANDLER(DWriteFontProxyMsg_FindFamily, OnFindFamily)
|
| + IPC_MESSAGE_HANDLER(DWriteFontProxyMsg_GetFamilyCount, OnGetFamilyCount)
|
| + IPC_MESSAGE_HANDLER(DWriteFontProxyMsg_GetFamilyNames, OnGetFamilyNames)
|
| + IPC_MESSAGE_HANDLER(DWriteFontProxyMsg_GetFontFiles, OnGetFontFiles)
|
| + IPC_MESSAGE_UNHANDLED(handled = false)
|
| + IPC_END_MESSAGE_MAP()
|
| + return reply_;
|
| +}
|
| +
|
| +bool FakeFontCollection::ReplySender::Send(IPC::Message* msg) {
|
| + reply_.reset(msg);
|
| + return true;
|
| +}
|
| +
|
| +void FakeFontCollection::ReplySender::OnFindFamily(
|
| + const base::string16& familyName,
|
| + uint32* index) {
|
| + collection_->OnFindFamily(familyName, index);
|
| +}
|
| +
|
| +void FakeFontCollection::ReplySender::OnGetFamilyCount(uint32* count) {
|
| + collection_->OnGetFamilyCount(count);
|
| +}
|
| +
|
| +void FakeFontCollection::ReplySender::OnGetFamilyNames(
|
| + uint32 familyIndex,
|
| + std::vector<StringPair>* familyNames) {
|
| + collection_->OnGetFamilyNames(familyIndex, familyNames);
|
| +}
|
| +
|
| +void FakeFontCollection::ReplySender::OnGetFontFiles(
|
| + uint32 familyIndex,
|
| + std::vector<base::string16>* filePaths) {
|
| + collection_->OnGetFontFiles(familyIndex, filePaths);
|
| +}
|
| +
|
| +bool FakeFontCollection::FakeSender::Send(IPC::Message* message) {
|
| + std::unique_ptr<IPC::Message> incomingMessage;
|
| + if (trackMessages_)
|
| + collection_->messages_.emplace_back(message);
|
| + else
|
| + incomingMessage.reset(message); // Ensure message is deleted.
|
| + std::unique_ptr<ReplySender> sender = collection_->GetReplySender();
|
| + scoped_ptr<IPC::Message> reply;
|
| + reply.swap(sender->OnMessageReceived(*message));
|
| +
|
| + IPC::SyncMessage* syncMessage = reinterpret_cast<IPC::SyncMessage*>(message);
|
| + scoped_ptr<IPC::MessageReplyDeserializer> serializer(
|
| + syncMessage->GetReplyDeserializer());
|
| + serializer->SerializeOutputParameters(*(reply.get()));
|
| + return true;
|
| +}
|
| +
|
| +void FakeFontCollection::OnFindFamily(const base::string16& familyName,
|
| + uint32* index) {
|
| + for (unsigned int n = 0; n < fonts_.size(); n++) {
|
| + if (_wcsicmp(familyName.data(), fonts_[n].fontName.data()) == 0) {
|
| + *index = n;
|
| + return;
|
| + }
|
| + }
|
| + *index = UINT32_MAX;
|
| +}
|
| +
|
| +void FakeFontCollection::OnGetFamilyCount(uint32* count) {
|
| + *count = fonts_.size();
|
| +}
|
| +
|
| +void FakeFontCollection::OnGetFamilyNames(
|
| + uint32 familyIndex,
|
| + std::vector<StringPair>* familyNames) {
|
| + if (familyIndex >= fonts_.size())
|
| + return;
|
| + *familyNames = fonts_[familyIndex].familyNames;
|
| +}
|
| +
|
| +void FakeFontCollection::OnGetFontFiles(
|
| + uint32 familyIndex,
|
| + std::vector<base::string16>* filePaths) {
|
| + if (familyIndex >= fonts_.size())
|
| + return;
|
| + *filePaths = fonts_[familyIndex].filePaths;
|
| +}
|
| +
|
| +std::unique_ptr<FakeFontCollection::ReplySender>
|
| +FakeFontCollection::GetReplySender() {
|
| + return std::unique_ptr<FakeFontCollection::ReplySender>(
|
| + new FakeFontCollection::ReplySender(this));
|
| +}
|
| +
|
| +} // namespace content
|
|
|