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

Side by Side Diff: components/mus/ws/test_utils.cc

Issue 1757403002: More user id tracking for mus: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tweaks Created 4 years, 9 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 unified diff | Download patch
« no previous file with comments | « components/mus/ws/test_utils.h ('k') | components/mus/ws/user_id.h » ('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 2016 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 #include "components/mus/ws/test_utils.h"
6
7 #include "cc/output/copy_output_request.h"
8 #include "components/mus/surfaces/surfaces_state.h"
9 #include "components/mus/ws/window_manager_factory_service.h"
10 #include "components/mus/ws/window_tree_host_connection.h"
11 #include "mojo/converters/geometry/geometry_type_converters.h"
12
13 namespace mus {
14 namespace ws {
15 namespace test {
16 namespace {
17
18 // -----------------------------------------------------------------------------
19 // Empty implementation of DisplayManager.
20 class TestDisplayManager : public DisplayManager {
21 public:
22 explicit TestDisplayManager(int32_t* cursor_id_storage)
23 : cursor_id_storage_(cursor_id_storage) {
24 display_metrics_.size_in_pixels = mojo::Size::From(gfx::Size(400, 300));
25 display_metrics_.device_pixel_ratio = 1.f;
26 }
27 ~TestDisplayManager() override {}
28
29 // DisplayManager:
30 void Init(DisplayManagerDelegate* delegate) override {
31 // It is necessary to tell the delegate about the ViewportMetrics to make
32 // sure that the WindowTreeHostConnection is correctly initialized (and a
33 // root-window is created).
34 delegate->OnViewportMetricsChanged(mojom::ViewportMetrics(),
35 display_metrics_);
36 }
37 void SchedulePaint(const ServerWindow* window,
38 const gfx::Rect& bounds) override {}
39 void SetViewportSize(const gfx::Size& size) override {}
40 void SetTitle(const base::string16& title) override {}
41 void SetCapture() override {}
42 void ReleaseCapture() override {}
43 void SetCursorById(int32_t cursor) override { *cursor_id_storage_ = cursor; }
44 mojom::Rotation GetRotation() override { return mojom::Rotation::VALUE_0; }
45 const mojom::ViewportMetrics& GetViewportMetrics() override {
46 return display_metrics_;
47 }
48 void UpdateTextInputState(const ui::TextInputState& state) override {}
49 void SetImeVisibility(bool visible) override {}
50 bool IsFramePending() const override { return false; }
51 void RequestCopyOfOutput(
52 scoped_ptr<cc::CopyOutputRequest> output_request) override {}
53
54 private:
55 mojom::ViewportMetrics display_metrics_;
56
57 int32_t* cursor_id_storage_;
58
59 DISALLOW_COPY_AND_ASSIGN(TestDisplayManager);
60 };
61
62 } // namespace
63
64 // WindowManagerFactoryRegistryTestApi ----------------------------------------
65
66 WindowManagerFactoryRegistryTestApi::WindowManagerFactoryRegistryTestApi(
67 WindowManagerFactoryRegistry* registry)
68 : registry_(registry) {}
69
70 WindowManagerFactoryRegistryTestApi::~WindowManagerFactoryRegistryTestApi() {}
71
72 void WindowManagerFactoryRegistryTestApi::AddService(
73 UserId user_id,
74 mojom::WindowManagerFactory* factory) {
75 scoped_ptr<WindowManagerFactoryService> service_ptr(
76 new WindowManagerFactoryService(registry_, user_id));
77 WindowManagerFactoryService* service = service_ptr.get();
78 registry_->AddServiceImpl(std::move(service_ptr));
79 service->SetWindowManagerFactoryImpl(factory);
80 }
81
82 // TestDisplayManagerFactory -------------------------------------------------
83
84 TestDisplayManagerFactory::TestDisplayManagerFactory(int32_t* cursor_id_storage)
85 : cursor_id_storage_(cursor_id_storage) {}
86
87 TestDisplayManagerFactory::~TestDisplayManagerFactory() {}
88
89 DisplayManager* TestDisplayManagerFactory::CreateDisplayManager(
90 mojo::Connector* connector,
91 const scoped_refptr<GpuState>& gpu_state,
92 const scoped_refptr<mus::SurfacesState>& surfaces_state) {
93 return new TestDisplayManager(cursor_id_storage_);
94 }
95
96 // WindowTreeTestApi ---------------------------------------------------------
97
98 WindowTreeTestApi::WindowTreeTestApi(WindowTreeImpl* tree) : tree_(tree) {}
99 WindowTreeTestApi::~WindowTreeTestApi() {}
100
101 // WindowTreeHostTestApi -----------------------------------------------------
102
103 WindowTreeHostTestApi::WindowTreeHostTestApi(WindowTreeHostImpl* tree_host)
104 : tree_host_(tree_host) {}
105 WindowTreeHostTestApi::~WindowTreeHostTestApi() {}
106
107 // TestWindowTreeClient -------------------------------------------------------
108
109 TestWindowTreeClient::TestWindowTreeClient()
110 : binding_(this), record_on_change_completed_(false) {}
111 TestWindowTreeClient::~TestWindowTreeClient() {}
112
113 void TestWindowTreeClient::Bind(
114 mojo::InterfaceRequest<mojom::WindowTreeClient> request) {
115 binding_.Bind(std::move(request));
116 }
117
118 void TestWindowTreeClient::OnEmbed(uint16_t connection_id,
119 mojom::WindowDataPtr root,
120 mus::mojom::WindowTreePtr tree,
121 Id focused_window_id,
122 uint32_t access_policy) {
123 // TODO(sky): add test coverage of |focused_window_id|.
124 tracker_.OnEmbed(connection_id, std::move(root));
125 }
126
127 void TestWindowTreeClient::OnEmbeddedAppDisconnected(uint32_t window) {
128 tracker_.OnEmbeddedAppDisconnected(window);
129 }
130
131 void TestWindowTreeClient::OnUnembed(Id window_id) {
132 tracker_.OnUnembed(window_id);
133 }
134
135 void TestWindowTreeClient::OnLostCapture(Id window_id) {}
136
137 void TestWindowTreeClient::OnTopLevelCreated(uint32_t change_id,
138 mojom::WindowDataPtr data) {
139 tracker_.OnTopLevelCreated(change_id, std::move(data));
140 }
141
142 void TestWindowTreeClient::OnWindowBoundsChanged(uint32_t window,
143 mojo::RectPtr old_bounds,
144 mojo::RectPtr new_bounds) {
145 tracker_.OnWindowBoundsChanged(window, std::move(old_bounds),
146 std::move(new_bounds));
147 }
148
149 void TestWindowTreeClient::OnClientAreaChanged(
150 uint32_t window_id,
151 mojo::InsetsPtr new_client_area,
152 mojo::Array<mojo::RectPtr> new_additional_client_areas) {}
153
154 void TestWindowTreeClient::OnTransientWindowAdded(
155 uint32_t window_id,
156 uint32_t transient_window_id) {}
157
158 void TestWindowTreeClient::OnTransientWindowRemoved(
159 uint32_t window_id,
160 uint32_t transient_window_id) {}
161
162 void TestWindowTreeClient::OnWindowViewportMetricsChanged(
163 mojo::Array<uint32_t> window_ids,
164 mojom::ViewportMetricsPtr old_metrics,
165 mojom::ViewportMetricsPtr new_metrics) {
166 tracker_.OnWindowViewportMetricsChanged(std::move(old_metrics),
167 std::move(new_metrics));
168 }
169
170 void TestWindowTreeClient::OnWindowHierarchyChanged(
171 uint32_t window,
172 uint32_t new_parent,
173 uint32_t old_parent,
174 mojo::Array<mojom::WindowDataPtr> windows) {
175 tracker_.OnWindowHierarchyChanged(window, new_parent, old_parent,
176 std::move(windows));
177 }
178
179 void TestWindowTreeClient::OnWindowReordered(uint32_t window_id,
180 uint32_t relative_window_id,
181 mojom::OrderDirection direction) {
182 tracker_.OnWindowReordered(window_id, relative_window_id, direction);
183 }
184
185 void TestWindowTreeClient::OnWindowDeleted(uint32_t window) {
186 tracker_.OnWindowDeleted(window);
187 }
188
189 void TestWindowTreeClient::OnWindowVisibilityChanged(uint32_t window,
190 bool visible) {
191 tracker_.OnWindowVisibilityChanged(window, visible);
192 }
193
194 void TestWindowTreeClient::OnWindowDrawnStateChanged(uint32_t window,
195 bool drawn) {
196 tracker_.OnWindowDrawnStateChanged(window, drawn);
197 }
198
199 void TestWindowTreeClient::OnWindowSharedPropertyChanged(
200 uint32_t window,
201 const mojo::String& name,
202 mojo::Array<uint8_t> new_data) {
203 tracker_.OnWindowSharedPropertyChanged(window, name, std::move(new_data));
204 }
205
206 void TestWindowTreeClient::OnWindowInputEvent(uint32_t event_id,
207 uint32_t window,
208 mojom::EventPtr event) {
209 tracker_.OnWindowInputEvent(window, std::move(event));
210 }
211
212 void TestWindowTreeClient::OnWindowFocused(uint32_t focused_window_id) {
213 tracker_.OnWindowFocused(focused_window_id);
214 }
215
216 void TestWindowTreeClient::OnWindowPredefinedCursorChanged(
217 uint32_t window_id,
218 mojom::Cursor cursor_id) {
219 tracker_.OnWindowPredefinedCursorChanged(window_id, cursor_id);
220 }
221
222 void TestWindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) {
223 if (record_on_change_completed_)
224 tracker_.OnChangeCompleted(change_id, success);
225 }
226
227 void TestWindowTreeClient::RequestClose(uint32_t window_id) {}
228
229 void TestWindowTreeClient::GetWindowManager(
230 mojo::AssociatedInterfaceRequest<mojom::WindowManager> internal) {}
231
232 // TestClientConnection --------------------------------------------------------
233
234 TestClientConnection::TestClientConnection() : ClientConnection(&client_) {}
235 TestClientConnection::~TestClientConnection() {}
236
237 mojom::WindowManager* TestClientConnection::GetWindowManager() {
238 NOTREACHED();
239 return nullptr;
240 }
241 void TestClientConnection::SetIncomingMethodCallProcessingPaused(bool paused) {
242 is_paused_ = paused;
243 }
244
245 // TestConnectionManagerDelegate ----------------------------------------------
246
247 TestConnectionManagerDelegate::TestConnectionManagerDelegate() {}
248 TestConnectionManagerDelegate::~TestConnectionManagerDelegate() {}
249
250 void TestConnectionManagerDelegate::OnNoMoreRootConnections() {
251 got_on_no_more_connections_ = true;
252 }
253
254 scoped_ptr<ClientConnection>
255 TestConnectionManagerDelegate::CreateClientConnectionForEmbedAtWindow(
256 ws::ConnectionManager* connection_manager,
257 ws::WindowTreeImpl* tree,
258 mojom::WindowTreeRequest tree_request,
259 mojom::WindowTreeClientPtr client) {
260 scoped_ptr<TestClientConnection> connection(new TestClientConnection);
261 last_connection_ = connection.get();
262 return std::move(connection);
263 }
264
265 void TestConnectionManagerDelegate::CreateDefaultWindowTreeHosts() {
266 DCHECK(num_tree_hosts_to_create_);
267 DCHECK(connection_manager_);
268
269 for (int i = 0; i < num_tree_hosts_to_create_; ++i) {
270 // WindowTreeHostImpl manages its own lifetime.
271 WindowTreeHostImpl* host_impl = new WindowTreeHostImpl(
272 connection_manager_, nullptr, scoped_refptr<GpuState>(),
273 scoped_refptr<mus::SurfacesState>());
274 host_impl->Init(nullptr);
275 }
276 }
277
278 } // namespace test
279 } // namespace ws
280 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/test_utils.h ('k') | components/mus/ws/user_id.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698