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

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

Issue 1406153004: components/mus/public/interfaces View => Window (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Yet another rebase Created 5 years, 2 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/view_tree_impl.cc ('k') | components/mus/ws/window_manager_access_policy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "components/mus/public/cpp/types.h" 9 #include "components/mus/public/cpp/types.h"
10 #include "components/mus/public/cpp/util.h" 10 #include "components/mus/public/cpp/util.h"
11 #include "components/mus/public/interfaces/view_tree.mojom.h" 11 #include "components/mus/public/interfaces/window_tree.mojom.h"
12 #include "components/mus/surfaces/surfaces_state.h" 12 #include "components/mus/surfaces/surfaces_state.h"
13 #include "components/mus/ws/client_connection.h" 13 #include "components/mus/ws/client_connection.h"
14 #include "components/mus/ws/connection_manager.h" 14 #include "components/mus/ws/connection_manager.h"
15 #include "components/mus/ws/connection_manager_delegate.h" 15 #include "components/mus/ws/connection_manager_delegate.h"
16 #include "components/mus/ws/display_manager.h" 16 #include "components/mus/ws/display_manager.h"
17 #include "components/mus/ws/display_manager_factory.h" 17 #include "components/mus/ws/display_manager_factory.h"
18 #include "components/mus/ws/ids.h" 18 #include "components/mus/ws/ids.h"
19 #include "components/mus/ws/server_view.h" 19 #include "components/mus/ws/server_view.h"
20 #include "components/mus/ws/test_change_tracker.h" 20 #include "components/mus/ws/test_change_tracker.h"
21 #include "components/mus/ws/view_tree_host_connection.h" 21 #include "components/mus/ws/view_tree_host_connection.h"
22 #include "components/mus/ws/view_tree_impl.h" 22 #include "components/mus/ws/view_tree_impl.h"
23 #include "mojo/application/public/interfaces/service_provider.mojom.h" 23 #include "mojo/application/public/interfaces/service_provider.mojom.h"
24 #include "mojo/converters/geometry/geometry_type_converters.h" 24 #include "mojo/converters/geometry/geometry_type_converters.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/gfx/geometry/rect.h" 26 #include "ui/gfx/geometry/rect.h"
27 27
28 using mojo::Array; 28 using mojo::Array;
29 using mojo::ERROR_CODE_NONE;
30 using mojo::InterfaceRequest; 29 using mojo::InterfaceRequest;
31 using mojo::ServiceProvider; 30 using mojo::ServiceProvider;
32 using mojo::ServiceProviderPtr; 31 using mojo::ServiceProviderPtr;
33 using mojo::String; 32 using mojo::String;
34 using mojo::ViewDataPtr; 33 using mus::mojom::ERROR_CODE_NONE;
34 using mus::mojom::WindowDataPtr;
35 35
36 namespace mus { 36 namespace mus {
37 namespace { 37 namespace {
38 38
39 // ----------------------------------------------------------------------------- 39 // -----------------------------------------------------------------------------
40 40
41 // ViewTreeClient implementation that logs all calls to a TestChangeTracker. 41 // WindowTreeClient implementation that logs all calls to a TestChangeTracker.
42 // TODO(sky): refactor so both this and ViewTreeAppTest share code. 42 // TODO(sky): refactor so both this and ViewTreeAppTest share code.
43 class TestViewTreeClient : public mojo::ViewTreeClient { 43 class TestWindowTreeClient : public mus::mojom::WindowTreeClient {
44 public: 44 public:
45 TestViewTreeClient() {} 45 TestWindowTreeClient() {}
46 ~TestViewTreeClient() override {} 46 ~TestWindowTreeClient() override {}
47 47
48 TestChangeTracker* tracker() { return &tracker_; } 48 TestChangeTracker* tracker() { return &tracker_; }
49 49
50 private: 50 private:
51 // ViewTreeClient: 51 // WindowTreeClient:
52 void OnEmbed(uint16_t connection_id, 52 void OnEmbed(uint16_t connection_id,
53 ViewDataPtr root, 53 WindowDataPtr root,
54 mojo::ViewTreePtr tree, 54 mus::mojom::WindowTreePtr tree,
55 Id focused_view_id, 55 Id focused_view_id,
56 uint32_t access_policy) override { 56 uint32_t access_policy) override {
57 // TODO(sky): add test coverage of |focused_view_id|. 57 // TODO(sky): add test coverage of |focused_view_id|.
58 tracker_.OnEmbed(connection_id, root.Pass()); 58 tracker_.OnEmbed(connection_id, root.Pass());
59 } 59 }
60 void OnEmbeddedAppDisconnected(uint32_t view) override { 60 void OnEmbeddedAppDisconnected(uint32_t view) override {
61 tracker_.OnEmbeddedAppDisconnected(view); 61 tracker_.OnEmbeddedAppDisconnected(view);
62 } 62 }
63 void OnUnembed() override { tracker_.OnUnembed(); } 63 void OnUnembed() override { tracker_.OnUnembed(); }
64 void OnWindowBoundsChanged(uint32_t view, 64 void OnWindowBoundsChanged(uint32_t view,
65 mojo::RectPtr old_bounds, 65 mojo::RectPtr old_bounds,
66 mojo::RectPtr new_bounds) override { 66 mojo::RectPtr new_bounds) override {
67 tracker_.OnWindowBoundsChanged(view, old_bounds.Pass(), new_bounds.Pass()); 67 tracker_.OnWindowBoundsChanged(view, old_bounds.Pass(), new_bounds.Pass());
68 } 68 }
69 void OnClientAreaChanged(uint32_t window_id, 69 void OnClientAreaChanged(uint32_t window_id,
70 mojo::RectPtr old_client_area, 70 mojo::RectPtr old_client_area,
71 mojo::RectPtr new_client_area) override { 71 mojo::RectPtr new_client_area) override {
72 } 72 }
73 void OnWindowViewportMetricsChanged( 73 void OnWindowViewportMetricsChanged(
74 mojo::ViewportMetricsPtr old_metrics, 74 mojom::ViewportMetricsPtr old_metrics,
75 mojo::ViewportMetricsPtr new_metrics) override { 75 mojom::ViewportMetricsPtr new_metrics) override {
76 tracker_.OnWindowViewportMetricsChanged(old_metrics.Pass(), 76 tracker_.OnWindowViewportMetricsChanged(old_metrics.Pass(),
77 new_metrics.Pass()); 77 new_metrics.Pass());
78 } 78 }
79 void OnWindowHierarchyChanged(uint32_t view, 79 void OnWindowHierarchyChanged(uint32_t view,
80 uint32_t new_parent, 80 uint32_t new_parent,
81 uint32_t old_parent, 81 uint32_t old_parent,
82 Array<ViewDataPtr> views) override { 82 Array<WindowDataPtr> views) override {
83 tracker_.OnWindowHierarchyChanged(view, new_parent, old_parent, 83 tracker_.OnWindowHierarchyChanged(view, new_parent, old_parent,
84 views.Pass()); 84 views.Pass());
85 } 85 }
86 void OnWindowReordered(uint32_t view_id, 86 void OnWindowReordered(uint32_t view_id,
87 uint32_t relative_view_id, 87 uint32_t relative_view_id,
88 mojo::OrderDirection direction) override { 88 mojom::OrderDirection direction) override {
89 tracker_.OnWindowReordered(view_id, relative_view_id, direction); 89 tracker_.OnWindowReordered(view_id, relative_view_id, direction);
90 } 90 }
91 void OnWindowDeleted(uint32_t view) override { 91 void OnWindowDeleted(uint32_t view) override {
92 tracker_.OnWindowDeleted(view); 92 tracker_.OnWindowDeleted(view);
93 } 93 }
94 void OnWindowVisibilityChanged(uint32_t view, bool visible) override { 94 void OnWindowVisibilityChanged(uint32_t view, bool visible) override {
95 tracker_.OnWindowVisibilityChanged(view, visible); 95 tracker_.OnWindowVisibilityChanged(view, visible);
96 } 96 }
97 void OnWindowDrawnStateChanged(uint32_t view, bool drawn) override { 97 void OnWindowDrawnStateChanged(uint32_t view, bool drawn) override {
98 tracker_.OnWindowDrawnStateChanged(view, drawn); 98 tracker_.OnWindowDrawnStateChanged(view, drawn);
99 } 99 }
100 void OnWindowSharedPropertyChanged(uint32_t view, 100 void OnWindowSharedPropertyChanged(uint32_t view,
101 const String& name, 101 const String& name,
102 Array<uint8_t> new_data) override { 102 Array<uint8_t> new_data) override {
103 tracker_.OnWindowSharedPropertyChanged(view, name, new_data.Pass()); 103 tracker_.OnWindowSharedPropertyChanged(view, name, new_data.Pass());
104 } 104 }
105 void OnWindowInputEvent(uint32_t view, 105 void OnWindowInputEvent(uint32_t view,
106 mojo::EventPtr event, 106 mojo::EventPtr event,
107 const mojo::Callback<void()>& callback) override { 107 const mojo::Callback<void()>& callback) override {
108 tracker_.OnWindowInputEvent(view, event.Pass()); 108 tracker_.OnWindowInputEvent(view, event.Pass());
109 } 109 }
110 void OnWindowFocused(uint32_t focused_view_id) override { 110 void OnWindowFocused(uint32_t focused_view_id) override {
111 tracker_.OnWindowFocused(focused_view_id); 111 tracker_.OnWindowFocused(focused_view_id);
112 } 112 }
113 113
114 TestChangeTracker tracker_; 114 TestChangeTracker tracker_;
115 115
116 DISALLOW_COPY_AND_ASSIGN(TestViewTreeClient); 116 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeClient);
117 }; 117 };
118 118
119 // ----------------------------------------------------------------------------- 119 // -----------------------------------------------------------------------------
120 120
121 // ClientConnection implementation that vends TestViewTreeClient. 121 // ClientConnection implementation that vends TestWindowTreeClient.
122 class TestClientConnection : public ClientConnection { 122 class TestClientConnection : public ClientConnection {
123 public: 123 public:
124 explicit TestClientConnection(scoped_ptr<ViewTreeImpl> service_impl) 124 explicit TestClientConnection(scoped_ptr<ViewTreeImpl> service_impl)
125 : ClientConnection(service_impl.Pass(), &client_) {} 125 : ClientConnection(service_impl.Pass(), &client_) {}
126 126
127 TestViewTreeClient* client() { return &client_; } 127 TestWindowTreeClient* client() { return &client_; }
128 128
129 private: 129 private:
130 ~TestClientConnection() override {} 130 ~TestClientConnection() override {}
131 131
132 TestViewTreeClient client_; 132 TestWindowTreeClient client_;
133 133
134 DISALLOW_COPY_AND_ASSIGN(TestClientConnection); 134 DISALLOW_COPY_AND_ASSIGN(TestClientConnection);
135 }; 135 };
136 136
137 // ----------------------------------------------------------------------------- 137 // -----------------------------------------------------------------------------
138 138
139 // Empty implementation of ConnectionManagerDelegate. 139 // Empty implementation of ConnectionManagerDelegate.
140 class TestConnectionManagerDelegate : public ConnectionManagerDelegate { 140 class TestConnectionManagerDelegate : public ConnectionManagerDelegate {
141 public: 141 public:
142 TestConnectionManagerDelegate() : last_connection_(nullptr) {} 142 TestConnectionManagerDelegate() : last_connection_(nullptr) {}
143 ~TestConnectionManagerDelegate() override {} 143 ~TestConnectionManagerDelegate() override {}
144 144
145 TestViewTreeClient* last_client() { 145 TestWindowTreeClient* last_client() {
146 return last_connection_ ? last_connection_->client() : nullptr; 146 return last_connection_ ? last_connection_->client() : nullptr;
147 } 147 }
148 148
149 TestClientConnection* last_connection() { return last_connection_; } 149 TestClientConnection* last_connection() { return last_connection_; }
150 150
151 private: 151 private:
152 // ConnectionManagerDelegate: 152 // ConnectionManagerDelegate:
153 void OnNoMoreRootConnections() override {} 153 void OnNoMoreRootConnections() override {}
154 154
155 ClientConnection* CreateClientConnectionForEmbedAtView( 155 ClientConnection* CreateClientConnectionForEmbedAtView(
156 ConnectionManager* connection_manager, 156 ConnectionManager* connection_manager,
157 mojo::InterfaceRequest<mojo::ViewTree> service_request, 157 mojo::InterfaceRequest<mus::mojom::WindowTree> service_request,
158 ConnectionSpecificId creator_id, 158 ConnectionSpecificId creator_id,
159 mojo::URLRequestPtr request, 159 mojo::URLRequestPtr request,
160 const ViewId& root_id, 160 const ViewId& root_id,
161 uint32_t policy_bitmask) override { 161 uint32_t policy_bitmask) override {
162 scoped_ptr<ViewTreeImpl> service(new ViewTreeImpl( 162 scoped_ptr<ViewTreeImpl> service(new ViewTreeImpl(
163 connection_manager, creator_id, root_id, policy_bitmask)); 163 connection_manager, creator_id, root_id, policy_bitmask));
164 last_connection_ = new TestClientConnection(service.Pass()); 164 last_connection_ = new TestClientConnection(service.Pass());
165 return last_connection_; 165 return last_connection_;
166 } 166 }
167 ClientConnection* CreateClientConnectionForEmbedAtView( 167 ClientConnection* CreateClientConnectionForEmbedAtView(
168 ConnectionManager* connection_manager, 168 ConnectionManager* connection_manager,
169 mojo::InterfaceRequest<mojo::ViewTree> service_request, 169 mojo::InterfaceRequest<mus::mojom::WindowTree> service_request,
170 ConnectionSpecificId creator_id, 170 ConnectionSpecificId creator_id,
171 const ViewId& root_id, 171 const ViewId& root_id,
172 uint32_t policy_bitmask, 172 uint32_t policy_bitmask,
173 mojo::ViewTreeClientPtr client) override { 173 mus::mojom::WindowTreeClientPtr client) override {
174 // Used by ConnectionManager::AddRoot. 174 // Used by ConnectionManager::AddRoot.
175 scoped_ptr<ViewTreeImpl> service(new ViewTreeImpl( 175 scoped_ptr<ViewTreeImpl> service(new ViewTreeImpl(
176 connection_manager, creator_id, root_id, policy_bitmask)); 176 connection_manager, creator_id, root_id, policy_bitmask));
177 last_connection_ = new TestClientConnection(service.Pass()); 177 last_connection_ = new TestClientConnection(service.Pass());
178 return last_connection_; 178 return last_connection_;
179 } 179 }
180 180
181 TestClientConnection* last_connection_; 181 TestClientConnection* last_connection_;
182 182
183 DISALLOW_COPY_AND_ASSIGN(TestConnectionManagerDelegate); 183 DISALLOW_COPY_AND_ASSIGN(TestConnectionManagerDelegate);
184 }; 184 };
185 185
186 // ----------------------------------------------------------------------------- 186 // -----------------------------------------------------------------------------
187 187
188 class TestViewTreeHostConnection : public ViewTreeHostConnection { 188 class TestViewTreeHostConnection : public ViewTreeHostConnection {
189 public: 189 public:
190 TestViewTreeHostConnection(scoped_ptr<ViewTreeHostImpl> host_impl, 190 TestViewTreeHostConnection(scoped_ptr<ViewTreeHostImpl> host_impl,
191 ConnectionManager* manager) 191 ConnectionManager* manager)
192 : ViewTreeHostConnection(host_impl.Pass(), manager) {} 192 : ViewTreeHostConnection(host_impl.Pass(), manager) {}
193 ~TestViewTreeHostConnection() override {} 193 ~TestViewTreeHostConnection() override {}
194 194
195 private: 195 private:
196 // ViewTreeHostDelegate: 196 // WindowTreeHostDelegate:
197 void OnDisplayInitialized() override { 197 void OnDisplayInitialized() override {
198 connection_manager()->AddHost(this); 198 connection_manager()->AddHost(this);
199 set_view_tree(connection_manager()->EmbedAtView( 199 set_view_tree(connection_manager()->EmbedAtView(
200 kInvalidConnectionId, view_tree_host()->root_view()->id(), 200 kInvalidConnectionId, view_tree_host()->root_view()->id(),
201 mojo::ViewTree::ACCESS_POLICY_EMBED_ROOT, mojo::ViewTreeClientPtr())); 201 mus::mojom::WindowTree::ACCESS_POLICY_EMBED_ROOT,
202 mus::mojom::WindowTreeClientPtr()));
202 } 203 }
203 DISALLOW_COPY_AND_ASSIGN(TestViewTreeHostConnection); 204 DISALLOW_COPY_AND_ASSIGN(TestViewTreeHostConnection);
204 }; 205 };
205 206
206 // ----------------------------------------------------------------------------- 207 // -----------------------------------------------------------------------------
207 // Empty implementation of DisplayManager. 208 // Empty implementation of DisplayManager.
208 class TestDisplayManager : public DisplayManager { 209 class TestDisplayManager : public DisplayManager {
209 public: 210 public:
210 TestDisplayManager() {} 211 TestDisplayManager() {}
211 ~TestDisplayManager() override {} 212 ~TestDisplayManager() override {}
212 213
213 // DisplayManager: 214 // DisplayManager:
214 void Init(DisplayManagerDelegate* delegate) override { 215 void Init(DisplayManagerDelegate* delegate) override {
215 // It is necessary to tell the delegate about the ViewportMetrics to make 216 // It is necessary to tell the delegate about the ViewportMetrics to make
216 // sure that the ViewTreeHostConnection is correctly initialized (and a 217 // sure that the ViewTreeHostConnection is correctly initialized (and a
217 // root-view is created). 218 // root-view is created).
218 mojo::ViewportMetrics metrics; 219 mojom::ViewportMetrics metrics;
219 metrics.size_in_pixels = mojo::Size::From(gfx::Size(400, 300)); 220 metrics.size_in_pixels = mojo::Size::From(gfx::Size(400, 300));
220 metrics.device_pixel_ratio = 1.f; 221 metrics.device_pixel_ratio = 1.f;
221 delegate->OnViewportMetricsChanged(mojo::ViewportMetrics(), metrics); 222 delegate->OnViewportMetricsChanged(mojom::ViewportMetrics(), metrics);
222 } 223 }
223 void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override { 224 void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override {
224 } 225 }
225 void SetViewportSize(const gfx::Size& size) override {} 226 void SetViewportSize(const gfx::Size& size) override {}
226 void SetTitle(const base::string16& title) override {} 227 void SetTitle(const base::string16& title) override {}
227 const mojo::ViewportMetrics& GetViewportMetrics() override { 228 const mojom::ViewportMetrics& GetViewportMetrics() override {
228 return display_metrices_; 229 return display_metrices_;
229 } 230 }
230 void UpdateTextInputState(const ui::TextInputState& state) override {} 231 void UpdateTextInputState(const ui::TextInputState& state) override {}
231 void SetImeVisibility(bool visible) override {} 232 void SetImeVisibility(bool visible) override {}
232 233
233 private: 234 private:
234 mojo::ViewportMetrics display_metrices_; 235 mojom::ViewportMetrics display_metrices_;
235 236
236 DISALLOW_COPY_AND_ASSIGN(TestDisplayManager); 237 DISALLOW_COPY_AND_ASSIGN(TestDisplayManager);
237 }; 238 };
238 239
239 // Factory that dispenses TestDisplayManagers. 240 // Factory that dispenses TestDisplayManagers.
240 class TestDisplayManagerFactory : public DisplayManagerFactory { 241 class TestDisplayManagerFactory : public DisplayManagerFactory {
241 public: 242 public:
242 TestDisplayManagerFactory() {} 243 TestDisplayManagerFactory() {}
243 ~TestDisplayManagerFactory() {} 244 ~TestDisplayManagerFactory() {}
244 DisplayManager* CreateDisplayManager( 245 DisplayManager* CreateDisplayManager(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 class ViewTreeTest : public testing::Test { 282 class ViewTreeTest : public testing::Test {
282 public: 283 public:
283 ViewTreeTest() : wm_client_(nullptr) {} 284 ViewTreeTest() : wm_client_(nullptr) {}
284 ~ViewTreeTest() override {} 285 ~ViewTreeTest() override {}
285 286
286 // ViewTreeImpl for the window manager. 287 // ViewTreeImpl for the window manager.
287 ViewTreeImpl* wm_connection() { 288 ViewTreeImpl* wm_connection() {
288 return connection_manager_->GetConnection(1); 289 return connection_manager_->GetConnection(1);
289 } 290 }
290 291
291 TestViewTreeClient* last_view_tree_client() { 292 TestWindowTreeClient* last_window_tree_client() {
292 return delegate_.last_client(); 293 return delegate_.last_client();
293 } 294 }
294 295
295 TestClientConnection* last_client_connection() { 296 TestClientConnection* last_client_connection() {
296 return delegate_.last_connection(); 297 return delegate_.last_connection();
297 } 298 }
298 299
299 ConnectionManager* connection_manager() { return connection_manager_.get(); } 300 ConnectionManager* connection_manager() { return connection_manager_.get(); }
300 301
301 TestViewTreeClient* wm_client() { return wm_client_; } 302 TestWindowTreeClient* wm_client() { return wm_client_; }
302 303
303 TestViewTreeHostConnection* host_connection() { return host_connection_; } 304 TestViewTreeHostConnection* host_connection() { return host_connection_; }
304 DisplayManagerDelegate* display_manager_delegate() { 305 DisplayManagerDelegate* display_manager_delegate() {
305 return host_connection()->view_tree_host(); 306 return host_connection()->view_tree_host();
306 } 307 }
307 308
308 protected: 309 protected:
309 // testing::Test: 310 // testing::Test:
310 void SetUp() override { 311 void SetUp() override {
311 DisplayManager::set_factory_for_testing(&display_manager_factory_); 312 DisplayManager::set_factory_for_testing(&display_manager_factory_);
312 // TODO(fsamuel): This is probably broken. We need a root. 313 // TODO(fsamuel): This is probably broken. We need a root.
313 connection_manager_.reset( 314 connection_manager_.reset(
314 new ConnectionManager(&delegate_, scoped_refptr<SurfacesState>())); 315 new ConnectionManager(&delegate_, scoped_refptr<SurfacesState>()));
315 ViewTreeHostImpl* host = new ViewTreeHostImpl( 316 ViewTreeHostImpl* host = new ViewTreeHostImpl(
316 mojo::ViewTreeHostClientPtr(), connection_manager_.get(), 317 mus::mojom::WindowTreeHostClientPtr(), connection_manager_.get(),
317 nullptr, scoped_refptr<GpuState>(), 318 nullptr, scoped_refptr<GpuState>(), scoped_refptr<SurfacesState>());
318 scoped_refptr<SurfacesState>());
319 // TODO(fsamuel): This is way too magical. We need to find a better way to 319 // TODO(fsamuel): This is way too magical. We need to find a better way to
320 // manage lifetime. 320 // manage lifetime.
321 host_connection_ = new TestViewTreeHostConnection( 321 host_connection_ = new TestViewTreeHostConnection(
322 make_scoped_ptr(host), connection_manager_.get()); 322 make_scoped_ptr(host), connection_manager_.get());
323 host->Init(host_connection_); 323 host->Init(host_connection_);
324 wm_client_ = delegate_.last_client(); 324 wm_client_ = delegate_.last_client();
325 } 325 }
326 326
327 private: 327 private:
328 // TestViewTreeClient that is used for the WM connection. 328 // TestWindowTreeClient that is used for the WM connection.
329 TestViewTreeClient* wm_client_; 329 TestWindowTreeClient* wm_client_;
330 TestDisplayManagerFactory display_manager_factory_; 330 TestDisplayManagerFactory display_manager_factory_;
331 TestConnectionManagerDelegate delegate_; 331 TestConnectionManagerDelegate delegate_;
332 TestViewTreeHostConnection* host_connection_; 332 TestViewTreeHostConnection* host_connection_;
333 scoped_ptr<ConnectionManager> connection_manager_; 333 scoped_ptr<ConnectionManager> connection_manager_;
334 base::MessageLoop message_loop_; 334 base::MessageLoop message_loop_;
335 335
336 DISALLOW_COPY_AND_ASSIGN(ViewTreeTest); 336 DISALLOW_COPY_AND_ASSIGN(ViewTreeTest);
337 }; 337 };
338 338
339 // Verifies focus correctly changes on pointer events. 339 // Verifies focus correctly changes on pointer events.
340 TEST_F(ViewTreeTest, FocusOnPointer) { 340 TEST_F(ViewTreeTest, FocusOnPointer) {
341 const ViewId embed_view_id(wm_connection()->id(), 1); 341 const ViewId embed_view_id(wm_connection()->id(), 1);
342 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id)); 342 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->NewWindow(embed_view_id));
343 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true)); 343 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_view_id, true));
344 EXPECT_TRUE( 344 EXPECT_TRUE(
345 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id)); 345 wm_connection()->AddWindow(*(wm_connection()->root()), embed_view_id));
346 host_connection()->view_tree_host()->root_view()->SetBounds( 346 host_connection()->view_tree_host()->root_view()->SetBounds(
347 gfx::Rect(0, 0, 100, 100)); 347 gfx::Rect(0, 0, 100, 100));
348 mojo::URLRequestPtr request(mojo::URLRequest::New()); 348 mojo::URLRequestPtr request(mojo::URLRequest::New());
349 wm_connection()->Embed(embed_view_id, request.Pass()); 349 wm_connection()->Embed(embed_view_id, request.Pass());
350 ViewTreeImpl* connection1 = 350 ViewTreeImpl* connection1 =
351 connection_manager()->GetConnectionWithRoot(embed_view_id); 351 connection_manager()->GetConnectionWithRoot(embed_view_id);
352 ASSERT_TRUE(connection1 != nullptr); 352 ASSERT_TRUE(connection1 != nullptr);
353 ASSERT_NE(connection1, wm_connection()); 353 ASSERT_NE(connection1, wm_connection());
354 354
355 connection_manager() 355 connection_manager()
356 ->GetView(embed_view_id) 356 ->GetView(embed_view_id)
357 ->SetBounds(gfx::Rect(0, 0, 50, 50)); 357 ->SetBounds(gfx::Rect(0, 0, 50, 50));
358 358
359 const ViewId child1(connection1->id(), 1); 359 const ViewId child1(connection1->id(), 1);
360 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1)); 360 EXPECT_EQ(ERROR_CODE_NONE, connection1->NewWindow(child1));
361 EXPECT_TRUE(connection1->AddView(embed_view_id, child1)); 361 EXPECT_TRUE(connection1->AddWindow(embed_view_id, child1));
362 ServerView* v1 = connection1->GetView(child1); 362 ServerView* v1 = connection1->GetView(child1);
363 v1->SetVisible(true); 363 v1->SetVisible(true);
364 v1->SetBounds(gfx::Rect(20, 20, 20, 20)); 364 v1->SetBounds(gfx::Rect(20, 20, 20, 20));
365 365
366 TestViewTreeClient* connection1_client = last_view_tree_client(); 366 TestWindowTreeClient* connection1_client = last_window_tree_client();
367 connection1_client->tracker()->changes()->clear(); 367 connection1_client->tracker()->changes()->clear();
368 wm_client()->tracker()->changes()->clear(); 368 wm_client()->tracker()->changes()->clear();
369 369
370 display_manager_delegate()->OnEvent(CreatePointerDownEvent(21, 22)); 370 display_manager_delegate()->OnEvent(CreatePointerDownEvent(21, 22));
371 // Focus should go to child1. This result in notifying both the window 371 // Focus should go to child1. This result in notifying both the window
372 // manager and client connection being notified. 372 // manager and client connection being notified.
373 EXPECT_EQ(v1, connection1->GetHost()->GetFocusedView()); 373 EXPECT_EQ(v1, connection1->GetHost()->GetFocusedView());
374 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u); 374 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u);
375 EXPECT_EQ("Focused id=2,1", 375 EXPECT_EQ("Focused id=2,1",
376 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); 376 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
(...skipping 30 matching lines...) Expand all
407 EXPECT_EQ(host_connection()->view_tree_host()->root_view(), 407 EXPECT_EQ(host_connection()->view_tree_host()->root_view(),
408 host_connection()->view_tree_host()->GetFocusedView()); 408 host_connection()->view_tree_host()->GetFocusedView());
409 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u); 409 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u);
410 EXPECT_EQ("InputEvent view=0,2 event_action=4", 410 EXPECT_EQ("InputEvent view=0,2 event_action=4",
411 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); 411 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
412 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); 412 EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
413 } 413 }
414 414
415 TEST_F(ViewTreeTest, BasicInputEventTarget) { 415 TEST_F(ViewTreeTest, BasicInputEventTarget) {
416 const ViewId embed_view_id(wm_connection()->id(), 1); 416 const ViewId embed_view_id(wm_connection()->id(), 1);
417 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id)); 417 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->NewWindow(embed_view_id));
418 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true)); 418 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_view_id, true));
419 EXPECT_TRUE( 419 EXPECT_TRUE(
420 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id)); 420 wm_connection()->AddWindow(*(wm_connection()->root()), embed_view_id));
421 host_connection()->view_tree_host()->root_view()->SetBounds( 421 host_connection()->view_tree_host()->root_view()->SetBounds(
422 gfx::Rect(0, 0, 100, 100)); 422 gfx::Rect(0, 0, 100, 100));
423 mojo::URLRequestPtr request(mojo::URLRequest::New()); 423 mojo::URLRequestPtr request(mojo::URLRequest::New());
424 wm_connection()->Embed(embed_view_id, request.Pass()); 424 wm_connection()->Embed(embed_view_id, request.Pass());
425 ViewTreeImpl* connection1 = 425 ViewTreeImpl* connection1 =
426 connection_manager()->GetConnectionWithRoot(embed_view_id); 426 connection_manager()->GetConnectionWithRoot(embed_view_id);
427 ASSERT_TRUE(connection1 != nullptr); 427 ASSERT_TRUE(connection1 != nullptr);
428 ASSERT_NE(connection1, wm_connection()); 428 ASSERT_NE(connection1, wm_connection());
429 429
430 connection_manager() 430 connection_manager()
431 ->GetView(embed_view_id) 431 ->GetView(embed_view_id)
432 ->SetBounds(gfx::Rect(0, 0, 50, 50)); 432 ->SetBounds(gfx::Rect(0, 0, 50, 50));
433 433
434 const ViewId child1(connection1->id(), 1); 434 const ViewId child1(connection1->id(), 1);
435 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1)); 435 EXPECT_EQ(ERROR_CODE_NONE, connection1->NewWindow(child1));
436 EXPECT_TRUE(connection1->AddView(embed_view_id, child1)); 436 EXPECT_TRUE(connection1->AddWindow(embed_view_id, child1));
437 ServerView* v1 = connection1->GetView(child1); 437 ServerView* v1 = connection1->GetView(child1);
438 v1->SetVisible(true); 438 v1->SetVisible(true);
439 v1->SetBounds(gfx::Rect(20, 20, 20, 20)); 439 v1->SetBounds(gfx::Rect(20, 20, 20, 20));
440 440
441 TestViewTreeClient* embed_connection = last_view_tree_client(); 441 TestWindowTreeClient* embed_connection = last_window_tree_client();
442 embed_connection->tracker()->changes()->clear(); 442 embed_connection->tracker()->changes()->clear();
443 wm_client()->tracker()->changes()->clear(); 443 wm_client()->tracker()->changes()->clear();
444 444
445 // Send an event to |v1|. |embed_connection| should get the event, not 445 // Send an event to |v1|. |embed_connection| should get the event, not
446 // |wm_client|, since |v1| lives inside an embedded view. 446 // |wm_client|, since |v1| lives inside an embedded view.
447 display_manager_delegate()->OnEvent(CreatePointerDownEvent(21, 22)); 447 display_manager_delegate()->OnEvent(CreatePointerDownEvent(21, 22));
448 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); 448 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size());
449 EXPECT_EQ("Focused id=2,1", 449 EXPECT_EQ("Focused id=2,1",
450 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); 450 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
451 ASSERT_EQ(2u, embed_connection->tracker()->changes()->size()); 451 ASSERT_EQ(2u, embed_connection->tracker()->changes()->size());
452 EXPECT_EQ("Focused id=2,1", 452 EXPECT_EQ("Focused id=2,1",
453 ChangesToDescription1(*embed_connection->tracker()->changes())[0]); 453 ChangesToDescription1(*embed_connection->tracker()->changes())[0]);
454 EXPECT_EQ("InputEvent view=2,1 event_action=4", 454 EXPECT_EQ("InputEvent view=2,1 event_action=4",
455 ChangesToDescription1(*embed_connection->tracker()->changes())[1]); 455 ChangesToDescription1(*embed_connection->tracker()->changes())[1]);
456 } 456 }
457 457
458 } // namespace mus 458 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/view_tree_impl.cc ('k') | components/mus/ws/window_manager_access_policy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698