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

Side by Side Diff: content/test/dwrite_font_fake_sender_win.h

Issue 1514183002: Revert "Create direct write font proxy classes and unit tests." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 unified diff | Download patch
« no previous file with comments | « content/content_tests.gypi ('k') | content/test/dwrite_font_fake_sender_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_TEST_DWRITE_FONT_FAKE_SENDER_WIN_H_
6 #define CONTENT_TEST_DWRITE_FONT_FAKE_SENDER_WIN_H_
7
8 #include <wrl.h>
9
10 #include <utility>
11 #include <vector>
12
13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/strings/string16.h"
16 #include "ipc/ipc_message.h"
17 #include "ipc/ipc_sender.h"
18
19 namespace content {
20
21 class FakeFontCollection;
22
23 // Creates a new FakeFontCollection, seeded with some basic data, and returns a
24 // Sender that can be used to interact with the collection.
25 IPC::Sender* CreateFakeCollectionSender();
26
27 // Helper class for describing a font object. Use FakeFontCollection instead.
28 class FakeFont {
29 public:
30 explicit FakeFont(const base::string16& name);
31
32 ~FakeFont();
33
34 FakeFont& AddFilePath(const base::string16& file_path) {
35 file_paths_.push_back(file_path);
36 return *this;
37 }
38
39 FakeFont& AddFamilyName(const base::string16& locale,
40 const base::string16& family_name) {
41 family_names_.emplace_back(locale, family_name);
42 return *this;
43 }
44
45 private:
46 friend FakeFontCollection;
47 base::string16 font_name_;
48 std::vector<base::string16> file_paths_;
49 std::vector<std::pair<base::string16, base::string16>> family_names_;
50
51 DISALLOW_ASSIGN(FakeFont);
52 };
53
54 // Implements a font collection that supports interaction through sending IPC
55 // messages from dwrite_font_proxy_messages.h.
56 // Usage:
57 // Create a new FakeFontCollection.
58 // Call AddFont() to add fonts.
59 // For each font, call methods on the font to configure the font.
60 // Note: the indices of the fonts will correspond to the order they were
61 // added. The collection will not sort or reorder fonts in any way.
62 // Call GetSender()/GetTrackingSender() to obtain an IPC::Sender.
63 // Call Send() with DWriteFontProxyMsg_* to interact with the collection.
64 // Call MessageCount()/GetMessage() to inspect the messages that were sent.
65 //
66 // The internal code flow for GetSender()/Send() is as follows:
67 // GetSender() returns a new FakeSender, pointing back to the collection.
68 // FakeSender::Send() will create a new ReplySender and call
69 // ReplySender::OnMessageReceived()
70 // ReplySender::OnMessageReceived() contains the message map, which will
71 // internally call ReplySender::On*() and ReplySender::Send()
72 // ReplySender::Send() will save the reply message, to be used later.
73 // FakeSender::Send() will retrieve the reply message and save the output.
74 class FakeFontCollection : public base::RefCounted<FakeFontCollection> {
75 public:
76 FakeFontCollection();
77
78 FakeFont& AddFont(const base::string16& font_name);
79
80 size_t MessageCount();
81
82 IPC::Message* GetMessage(size_t index);
83
84 IPC::Sender* GetSender();
85
86 // Like GetSender(), but will keep track of all sent messages for inspection.
87 IPC::Sender* GetTrackingSender();
88
89 protected:
90 // This class handles sending the reply message back to the "renderer"
91 class ReplySender : public IPC::Sender {
92 public:
93 explicit ReplySender(FakeFontCollection* collection);
94
95 ~ReplySender() override;
96
97 scoped_ptr<IPC::Message>& OnMessageReceived(const IPC::Message& msg);
98
99 bool Send(IPC::Message* msg) override;
100
101 private:
102 void OnFindFamily(const base::string16& family_name, uint32_t* index);
103
104 void OnGetFamilyCount(uint32_t* count);
105
106 void OnGetFamilyNames(
107 uint32_t family_index,
108 std::vector<std::pair<base::string16, base::string16>>* family_names);
109 void OnGetFontFiles(uint32 family_index,
110 std::vector<base::string16>* file_paths_);
111
112 private:
113 scoped_refptr<FakeFontCollection> collection_;
114 scoped_ptr<IPC::Message> reply_;
115
116 DISALLOW_COPY_AND_ASSIGN(ReplySender);
117 };
118
119 // This class can be used by the "renderer" to send messages to the "browser"
120 class FakeSender : public IPC::Sender {
121 public:
122 FakeSender(FakeFontCollection* collection, bool track_messages);
123
124 ~FakeSender() override;
125
126 bool Send(IPC::Message* message) override;
127
128 private:
129 bool track_messages_;
130 scoped_refptr<FakeFontCollection> collection_;
131
132 DISALLOW_COPY_AND_ASSIGN(FakeSender);
133 };
134
135 void OnFindFamily(const base::string16& family_name, uint32_t* index);
136
137 void OnGetFamilyCount(uint32_t* count);
138
139 void OnGetFamilyNames(
140 uint32_t family_index,
141 std::vector<std::pair<base::string16, base::string16>>* family_names);
142
143 void OnGetFontFiles(uint32 family_index,
144 std::vector<base::string16>* file_paths);
145
146 std::unique_ptr<ReplySender> GetReplySender();
147
148 private:
149 friend class base::RefCounted<FakeFontCollection>;
150 ~FakeFontCollection();
151
152 std::vector<FakeFont> fonts_;
153 std::vector<std::unique_ptr<IPC::Message>> messages_;
154
155 DISALLOW_COPY_AND_ASSIGN(FakeFontCollection);
156 };
157
158 } // namespace content
159
160 #endif // CONTENT_TEST_DWRITE_FONT_FAKE_SENDER_WIN_H_
OLDNEW
« no previous file with comments | « content/content_tests.gypi ('k') | content/test/dwrite_font_fake_sender_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698