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

Side by Side Diff: components/view_manager/view_tree_unittest.cc

Issue 1314953002: Rename ViewManagerService,ViewManagerClient -> ViewTree,ViewTreeClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 3 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/view_manager/view_tree_impl.cc ('k') | mandoline/tab/frame.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/view_manager/client_connection.h" 9 #include "components/view_manager/client_connection.h"
10 #include "components/view_manager/connection_manager.h" 10 #include "components/view_manager/connection_manager.h"
11 #include "components/view_manager/connection_manager_delegate.h" 11 #include "components/view_manager/connection_manager_delegate.h"
12 #include "components/view_manager/display_manager.h" 12 #include "components/view_manager/display_manager.h"
13 #include "components/view_manager/display_manager_factory.h" 13 #include "components/view_manager/display_manager_factory.h"
14 #include "components/view_manager/ids.h" 14 #include "components/view_manager/ids.h"
15 #include "components/view_manager/public/cpp/types.h" 15 #include "components/view_manager/public/cpp/types.h"
16 #include "components/view_manager/public/cpp/util.h" 16 #include "components/view_manager/public/cpp/util.h"
17 #include "components/view_manager/public/interfaces/view_manager.mojom.h" 17 #include "components/view_manager/public/interfaces/view_tree.mojom.h"
18 #include "components/view_manager/server_view.h" 18 #include "components/view_manager/server_view.h"
19 #include "components/view_manager/surfaces/surfaces_state.h" 19 #include "components/view_manager/surfaces/surfaces_state.h"
20 #include "components/view_manager/test_change_tracker.h" 20 #include "components/view_manager/test_change_tracker.h"
21 #include "components/view_manager/view_manager_root_connection.h" 21 #include "components/view_manager/view_manager_root_connection.h"
22 #include "components/view_manager/view_manager_service_impl.h" 22 #include "components/view_manager/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; 29 using mojo::ERROR_CODE_NONE;
30 using mojo::InterfaceRequest; 30 using mojo::InterfaceRequest;
31 using mojo::ServiceProvider; 31 using mojo::ServiceProvider;
32 using mojo::ServiceProviderPtr; 32 using mojo::ServiceProviderPtr;
33 using mojo::String; 33 using mojo::String;
34 using mojo::ViewDataPtr; 34 using mojo::ViewDataPtr;
35 35
36 namespace view_manager { 36 namespace view_manager {
37 namespace { 37 namespace {
38 38
39 // ----------------------------------------------------------------------------- 39 // -----------------------------------------------------------------------------
40 40
41 // ViewManagerClient implementation that logs all calls to a TestChangeTracker. 41 // ViewTreeClient implementation that logs all calls to a TestChangeTracker.
42 // TODO(sky): refactor so both this and ViewManagerServiceAppTest share code. 42 // TODO(sky): refactor so both this and ViewTreeAppTest share code.
43 class TestViewManagerClient : public mojo::ViewManagerClient { 43 class TestViewTreeClient : public mojo::ViewTreeClient {
44 public: 44 public:
45 TestViewManagerClient() {} 45 TestViewTreeClient() {}
46 ~TestViewManagerClient() override {} 46 ~TestViewTreeClient() override {}
47 47
48 TestChangeTracker* tracker() { return &tracker_; } 48 TestChangeTracker* tracker() { return &tracker_; }
49 49
50 private: 50 private:
51 // ViewManagerClient: 51 // ViewTreeClient:
52 void OnEmbed(uint16_t connection_id, 52 void OnEmbed(uint16_t connection_id,
53 ViewDataPtr root, 53 ViewDataPtr root,
54 mojo::ViewManagerServicePtr view_manager_service, 54 mojo::ViewTreePtr tree,
55 mojo::Id focused_view_id) override { 55 mojo::Id focused_view_id) override {
56 // TODO(sky): add test coverage of |focused_view_id|. 56 // TODO(sky): add test coverage of |focused_view_id|.
57 tracker_.OnEmbed(connection_id, root.Pass()); 57 tracker_.OnEmbed(connection_id, root.Pass());
58 } 58 }
59 void OnEmbedForDescendant( 59 void OnEmbedForDescendant(
60 uint32_t view, 60 uint32_t view,
61 mojo::URLRequestPtr request, 61 mojo::URLRequestPtr request,
62 const OnEmbedForDescendantCallback& callback) override {} 62 const OnEmbedForDescendantCallback& callback) override {}
63 void OnEmbeddedAppDisconnected(uint32_t view) override { 63 void OnEmbeddedAppDisconnected(uint32_t view) override {
64 tracker_.OnEmbeddedAppDisconnected(view); 64 tracker_.OnEmbeddedAppDisconnected(view);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 mojo::EventPtr event, 102 mojo::EventPtr event,
103 const mojo::Callback<void()>& callback) override { 103 const mojo::Callback<void()>& callback) override {
104 tracker_.OnViewInputEvent(view, event.Pass()); 104 tracker_.OnViewInputEvent(view, event.Pass());
105 } 105 }
106 void OnViewFocused(uint32_t focused_view_id) override { 106 void OnViewFocused(uint32_t focused_view_id) override {
107 tracker_.OnViewFocused(focused_view_id); 107 tracker_.OnViewFocused(focused_view_id);
108 } 108 }
109 109
110 TestChangeTracker tracker_; 110 TestChangeTracker tracker_;
111 111
112 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClient); 112 DISALLOW_COPY_AND_ASSIGN(TestViewTreeClient);
113 }; 113 };
114 114
115 // ----------------------------------------------------------------------------- 115 // -----------------------------------------------------------------------------
116 116
117 // ClientConnection implementation that vends TestViewManagerClient. 117 // ClientConnection implementation that vends TestViewTreeClient.
118 class TestClientConnection : public ClientConnection { 118 class TestClientConnection : public ClientConnection {
119 public: 119 public:
120 explicit TestClientConnection(scoped_ptr<ViewManagerServiceImpl> service_impl) 120 explicit TestClientConnection(scoped_ptr<ViewTreeImpl> service_impl)
121 : ClientConnection(service_impl.Pass(), &client_) {} 121 : ClientConnection(service_impl.Pass(), &client_) {}
122 122
123 TestViewManagerClient* client() { return &client_; } 123 TestViewTreeClient* client() { return &client_; }
124 124
125 private: 125 private:
126 ~TestClientConnection() override {} 126 ~TestClientConnection() override {}
127 127
128 TestViewManagerClient client_; 128 TestViewTreeClient client_;
129 129
130 DISALLOW_COPY_AND_ASSIGN(TestClientConnection); 130 DISALLOW_COPY_AND_ASSIGN(TestClientConnection);
131 }; 131 };
132 132
133 // ----------------------------------------------------------------------------- 133 // -----------------------------------------------------------------------------
134 134
135 // Empty implementation of ConnectionManagerDelegate. 135 // Empty implementation of ConnectionManagerDelegate.
136 class TestConnectionManagerDelegate : public ConnectionManagerDelegate { 136 class TestConnectionManagerDelegate : public ConnectionManagerDelegate {
137 public: 137 public:
138 TestConnectionManagerDelegate() : last_connection_(nullptr) {} 138 TestConnectionManagerDelegate() : last_connection_(nullptr) {}
139 ~TestConnectionManagerDelegate() override {} 139 ~TestConnectionManagerDelegate() override {}
140 140
141 TestViewManagerClient* last_client() { 141 TestViewTreeClient* last_client() {
142 return last_connection_ ? last_connection_->client() : nullptr; 142 return last_connection_ ? last_connection_->client() : nullptr;
143 } 143 }
144 144
145 TestClientConnection* last_connection() { return last_connection_; } 145 TestClientConnection* last_connection() { return last_connection_; }
146 146
147 private: 147 private:
148 // ConnectionManagerDelegate: 148 // ConnectionManagerDelegate:
149 void OnNoMoreRootConnections() override {} 149 void OnNoMoreRootConnections() override {}
150 150
151 ClientConnection* CreateClientConnectionForEmbedAtView( 151 ClientConnection* CreateClientConnectionForEmbedAtView(
152 ConnectionManager* connection_manager, 152 ConnectionManager* connection_manager,
153 mojo::InterfaceRequest<mojo::ViewManagerService> service_request, 153 mojo::InterfaceRequest<mojo::ViewTree> service_request,
154 mojo::ConnectionSpecificId creator_id, 154 mojo::ConnectionSpecificId creator_id,
155 mojo::URLRequestPtr request, 155 mojo::URLRequestPtr request,
156 const ViewId& root_id) override { 156 const ViewId& root_id) override {
157 scoped_ptr<ViewManagerServiceImpl> service( 157 scoped_ptr<ViewTreeImpl> service(
158 new ViewManagerServiceImpl(connection_manager, creator_id, root_id)); 158 new ViewTreeImpl(connection_manager, creator_id, root_id));
159 last_connection_ = new TestClientConnection(service.Pass()); 159 last_connection_ = new TestClientConnection(service.Pass());
160 return last_connection_; 160 return last_connection_;
161 } 161 }
162 ClientConnection* CreateClientConnectionForEmbedAtView( 162 ClientConnection* CreateClientConnectionForEmbedAtView(
163 ConnectionManager* connection_manager, 163 ConnectionManager* connection_manager,
164 mojo::InterfaceRequest<mojo::ViewManagerService> service_request, 164 mojo::InterfaceRequest<mojo::ViewTree> service_request,
165 mojo::ConnectionSpecificId creator_id, 165 mojo::ConnectionSpecificId creator_id,
166 const ViewId& root_id, 166 const ViewId& root_id,
167 mojo::ViewManagerClientPtr client) override { 167 mojo::ViewTreeClientPtr client) override {
168 // Used by ConnectionManager::AddRoot. 168 // Used by ConnectionManager::AddRoot.
169 scoped_ptr<ViewManagerServiceImpl> service( 169 scoped_ptr<ViewTreeImpl> service(
170 new ViewManagerServiceImpl(connection_manager, creator_id, root_id)); 170 new ViewTreeImpl(connection_manager, creator_id, root_id));
171 last_connection_ = new TestClientConnection(service.Pass()); 171 last_connection_ = new TestClientConnection(service.Pass());
172 return last_connection_; 172 return last_connection_;
173 } 173 }
174 174
175 TestClientConnection* last_connection_; 175 TestClientConnection* last_connection_;
176 176
177 DISALLOW_COPY_AND_ASSIGN(TestConnectionManagerDelegate); 177 DISALLOW_COPY_AND_ASSIGN(TestConnectionManagerDelegate);
178 }; 178 };
179 179
180 // ----------------------------------------------------------------------------- 180 // -----------------------------------------------------------------------------
181 181
182 class TestViewManagerRootConnection : public ViewManagerRootConnection { 182 class TestViewManagerRootConnection : public ViewManagerRootConnection {
183 public: 183 public:
184 TestViewManagerRootConnection(scoped_ptr<ViewManagerRootImpl> root, 184 TestViewManagerRootConnection(scoped_ptr<ViewManagerRootImpl> root,
185 ConnectionManager* manager) 185 ConnectionManager* manager)
186 : ViewManagerRootConnection(root.Pass(), manager) {} 186 : ViewManagerRootConnection(root.Pass(), manager) {}
187 ~TestViewManagerRootConnection() override {} 187 ~TestViewManagerRootConnection() override {}
188 188
189 private: 189 private:
190 // ViewManagerRootDelegate: 190 // ViewManagerRootDelegate:
191 void OnDisplayInitialized() override { 191 void OnDisplayInitialized() override {
192 connection_manager()->AddRoot(this); 192 connection_manager()->AddRoot(this);
193 set_view_manager_service(connection_manager()->EmbedAtView( 193 set_view_tree(connection_manager()->EmbedAtView(
194 kInvalidConnectionId, 194 kInvalidConnectionId,
195 view_manager_root()->root_view()->id(), 195 view_manager_root()->root_view()->id(),
196 mojo::ViewManagerClientPtr())); 196 mojo::ViewTreeClientPtr()));
197 } 197 }
198 DISALLOW_COPY_AND_ASSIGN(TestViewManagerRootConnection); 198 DISALLOW_COPY_AND_ASSIGN(TestViewManagerRootConnection);
199 }; 199 };
200 200
201 // ----------------------------------------------------------------------------- 201 // -----------------------------------------------------------------------------
202 // Empty implementation of DisplayManager. 202 // Empty implementation of DisplayManager.
203 class TestDisplayManager : public DisplayManager { 203 class TestDisplayManager : public DisplayManager {
204 public: 204 public:
205 TestDisplayManager() {} 205 TestDisplayManager() {}
206 ~TestDisplayManager() override {} 206 ~TestDisplayManager() override {}
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 event->pointer_data->pointer_id = 1u; 264 event->pointer_data->pointer_id = 1u;
265 event->pointer_data->x = x; 265 event->pointer_data->x = x;
266 event->pointer_data->y = y; 266 event->pointer_data->y = y;
267 return event.Pass(); 267 return event.Pass();
268 } 268 }
269 269
270 } // namespace 270 } // namespace
271 271
272 // ----------------------------------------------------------------------------- 272 // -----------------------------------------------------------------------------
273 273
274 class ViewManagerServiceTest : public testing::Test { 274 class ViewTreeTest : public testing::Test {
275 public: 275 public:
276 ViewManagerServiceTest() : wm_client_(nullptr) {} 276 ViewTreeTest() : wm_client_(nullptr) {}
277 ~ViewManagerServiceTest() override {} 277 ~ViewTreeTest() override {}
278 278
279 // ViewManagerServiceImpl for the window manager. 279 // ViewTreeImpl for the window manager.
280 ViewManagerServiceImpl* wm_connection() { 280 ViewTreeImpl* wm_connection() {
281 return connection_manager_->GetConnection(1); 281 return connection_manager_->GetConnection(1);
282 } 282 }
283 283
284 TestViewManagerClient* last_view_manager_client() { 284 TestViewTreeClient* last_view_tree_client() {
285 return delegate_.last_client(); 285 return delegate_.last_client();
286 } 286 }
287 287
288 TestClientConnection* last_client_connection() { 288 TestClientConnection* last_client_connection() {
289 return delegate_.last_connection(); 289 return delegate_.last_connection();
290 } 290 }
291 291
292 ConnectionManager* connection_manager() { return connection_manager_.get(); } 292 ConnectionManager* connection_manager() { return connection_manager_.get(); }
293 293
294 TestViewManagerClient* wm_client() { return wm_client_; } 294 TestViewTreeClient* wm_client() { return wm_client_; }
295 295
296 TestViewManagerRootConnection* root_connection() { return root_connection_; } 296 TestViewManagerRootConnection* root_connection() { return root_connection_; }
297 297
298 protected: 298 protected:
299 // testing::Test: 299 // testing::Test:
300 void SetUp() override { 300 void SetUp() override {
301 DisplayManager::set_factory_for_testing(&display_manager_factory_); 301 DisplayManager::set_factory_for_testing(&display_manager_factory_);
302 // TODO(fsamuel): This is probably broken. We need a root. 302 // TODO(fsamuel): This is probably broken. We need a root.
303 connection_manager_.reset(new ConnectionManager(&delegate_)); 303 connection_manager_.reset(new ConnectionManager(&delegate_));
304 ViewManagerRootImpl* root = new ViewManagerRootImpl( 304 ViewManagerRootImpl* root = new ViewManagerRootImpl(
305 connection_manager_.get(), true /* is_headless */, nullptr, 305 connection_manager_.get(), true /* is_headless */, nullptr,
306 scoped_refptr<gles2::GpuState>(), 306 scoped_refptr<gles2::GpuState>(),
307 scoped_refptr<surfaces::SurfacesState>()); 307 scoped_refptr<surfaces::SurfacesState>());
308 // TODO(fsamuel): This is way too magical. We need to find a better way to 308 // TODO(fsamuel): This is way too magical. We need to find a better way to
309 // manage lifetime. 309 // manage lifetime.
310 root_connection_ = new TestViewManagerRootConnection( 310 root_connection_ = new TestViewManagerRootConnection(
311 make_scoped_ptr(root), connection_manager_.get()); 311 make_scoped_ptr(root), connection_manager_.get());
312 root->Init(root_connection_); 312 root->Init(root_connection_);
313 wm_client_ = delegate_.last_client(); 313 wm_client_ = delegate_.last_client();
314 } 314 }
315 315
316 private: 316 private:
317 // TestViewManagerClient that is used for the WM connection. 317 // TestViewTreeClient that is used for the WM connection.
318 TestViewManagerClient* wm_client_; 318 TestViewTreeClient* wm_client_;
319 TestDisplayManagerFactory display_manager_factory_; 319 TestDisplayManagerFactory display_manager_factory_;
320 TestConnectionManagerDelegate delegate_; 320 TestConnectionManagerDelegate delegate_;
321 TestViewManagerRootConnection* root_connection_; 321 TestViewManagerRootConnection* root_connection_;
322 scoped_ptr<ConnectionManager> connection_manager_; 322 scoped_ptr<ConnectionManager> connection_manager_;
323 base::MessageLoop message_loop_; 323 base::MessageLoop message_loop_;
324 324
325 DISALLOW_COPY_AND_ASSIGN(ViewManagerServiceTest); 325 DISALLOW_COPY_AND_ASSIGN(ViewTreeTest);
326 }; 326 };
327 327
328 namespace { 328 namespace {
329 329
330 const ServerView* GetFirstCloned(const ServerView* view) { 330 const ServerView* GetFirstCloned(const ServerView* view) {
331 for (const ServerView* child : view->GetChildren()) { 331 for (const ServerView* child : view->GetChildren()) {
332 if (child->id() == ClonedViewId()) 332 if (child->id() == ClonedViewId())
333 return child; 333 return child;
334 } 334 }
335 return nullptr; 335 return nullptr;
336 } 336 }
337 337
338 // Provides common setup for animation tests. Creates the following views: 338 // Provides common setup for animation tests. Creates the following views:
339 // 0,1 (the root, provided by view manager) 339 // 0,1 (the root, provided by view manager)
340 // 1,1 the second connection is embedded here (view owned by wm_connection()). 340 // 1,1 the second connection is embedded here (view owned by wm_connection()).
341 // 2,1 bounds=1,2 11x22 341 // 2,1 bounds=1,2 11x22
342 // 2,2 bounds=2,3 6x7 342 // 2,2 bounds=2,3 6x7
343 // 2,3 bounds=3,4 6x7 343 // 2,3 bounds=3,4 6x7
344 // CloneAndAnimate() is invoked for 2,2. 344 // CloneAndAnimate() is invoked for 2,2.
345 void SetUpAnimate1(ViewManagerServiceTest* test, ViewId* embed_view_id) { 345 void SetUpAnimate1(ViewTreeTest* test, ViewId* embed_view_id) {
346 *embed_view_id = ViewId(test->wm_connection()->id(), 1); 346 *embed_view_id = ViewId(test->wm_connection()->id(), 1);
347 EXPECT_EQ(ERROR_CODE_NONE, test->wm_connection()->CreateView(*embed_view_id)); 347 EXPECT_EQ(ERROR_CODE_NONE, test->wm_connection()->CreateView(*embed_view_id));
348 EXPECT_TRUE(test->wm_connection()->SetViewVisibility(*embed_view_id, true)); 348 EXPECT_TRUE(test->wm_connection()->SetViewVisibility(*embed_view_id, true));
349 EXPECT_TRUE(test->wm_connection()->AddView(*(test->wm_connection()->root()), 349 EXPECT_TRUE(test->wm_connection()->AddView(*(test->wm_connection()->root()),
350 *embed_view_id)); 350 *embed_view_id));
351 mojo::URLRequestPtr request(mojo::URLRequest::New()); 351 mojo::URLRequestPtr request(mojo::URLRequest::New());
352 test->wm_connection()->EmbedAllowingReembed(*embed_view_id, request.Pass(), 352 test->wm_connection()->EmbedAllowingReembed(*embed_view_id, request.Pass(),
353 mojo::Callback<void(bool)>()); 353 mojo::Callback<void(bool)>());
354 ViewManagerServiceImpl* connection1 = 354 ViewTreeImpl* connection1 =
355 test->connection_manager()->GetConnectionWithRoot(*embed_view_id); 355 test->connection_manager()->GetConnectionWithRoot(*embed_view_id);
356 ASSERT_TRUE(connection1 != nullptr); 356 ASSERT_TRUE(connection1 != nullptr);
357 ASSERT_NE(connection1, test->wm_connection()); 357 ASSERT_NE(connection1, test->wm_connection());
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->CreateView(child1));
361 const ViewId child2(connection1->id(), 2); 361 const ViewId child2(connection1->id(), 2);
362 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2)); 362 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2));
363 const ViewId child3(connection1->id(), 3); 363 const ViewId child3(connection1->id(), 3);
364 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3)); 364 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3));
365 365
366 ServerView* v1 = connection1->GetView(child1); 366 ServerView* v1 = connection1->GetView(child1);
367 v1->SetVisible(true); 367 v1->SetVisible(true);
368 v1->SetBounds(gfx::Rect(1, 2, 11, 22)); 368 v1->SetBounds(gfx::Rect(1, 2, 11, 22));
369 ServerView* v2 = connection1->GetView(child2); 369 ServerView* v2 = connection1->GetView(child2);
370 v2->SetVisible(true); 370 v2->SetVisible(true);
371 v2->SetBounds(gfx::Rect(2, 3, 6, 7)); 371 v2->SetBounds(gfx::Rect(2, 3, 6, 7));
372 ServerView* v3 = connection1->GetView(child3); 372 ServerView* v3 = connection1->GetView(child3);
373 v3->SetVisible(true); 373 v3->SetVisible(true);
374 v3->SetBounds(gfx::Rect(3, 4, 6, 7)); 374 v3->SetBounds(gfx::Rect(3, 4, 6, 7));
375 375
376 EXPECT_TRUE(connection1->AddView(*embed_view_id, child1)); 376 EXPECT_TRUE(connection1->AddView(*embed_view_id, child1));
377 EXPECT_TRUE(connection1->AddView(child1, child2)); 377 EXPECT_TRUE(connection1->AddView(child1, child2));
378 EXPECT_TRUE(connection1->AddView(child2, child3)); 378 EXPECT_TRUE(connection1->AddView(child2, child3));
379 379
380 TestViewManagerClient* connection1_client = test->last_view_manager_client(); 380 TestViewTreeClient* connection1_client = test->last_view_tree_client();
381 connection1_client->tracker()->changes()->clear(); 381 connection1_client->tracker()->changes()->clear();
382 test->wm_client()->tracker()->changes()->clear(); 382 test->wm_client()->tracker()->changes()->clear();
383 EXPECT_TRUE(test->connection_manager()->CloneAndAnimate(child2)); 383 EXPECT_TRUE(test->connection_manager()->CloneAndAnimate(child2));
384 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); 384 EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
385 EXPECT_TRUE(test->wm_client()->tracker()->changes()->empty()); 385 EXPECT_TRUE(test->wm_client()->tracker()->changes()->empty());
386 386
387 // We cloned v2. The cloned view ends up as a sibling of it. 387 // We cloned v2. The cloned view ends up as a sibling of it.
388 const ServerView* cloned_view = GetFirstCloned(connection1->GetView(child1)); 388 const ServerView* cloned_view = GetFirstCloned(connection1->GetView(child1));
389 ASSERT_TRUE(cloned_view); 389 ASSERT_TRUE(cloned_view);
390 // |cloned_view| should have one and only one cloned child (corresponds to 390 // |cloned_view| should have one and only one cloned child (corresponds to
391 // |child3|). 391 // |child3|).
392 ASSERT_EQ(1u, cloned_view->GetChildren().size()); 392 ASSERT_EQ(1u, cloned_view->GetChildren().size());
393 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId()); 393 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
394 394
395 // Cloned views should match the bounds of the view they were cloned from. 395 // Cloned views should match the bounds of the view they were cloned from.
396 EXPECT_EQ(v2->bounds(), cloned_view->bounds()); 396 EXPECT_EQ(v2->bounds(), cloned_view->bounds());
397 EXPECT_EQ(v3->bounds(), cloned_view->GetChildren()[0]->bounds()); 397 EXPECT_EQ(v3->bounds(), cloned_view->GetChildren()[0]->bounds());
398 398
399 // Cloned views are owned by the ConnectionManager and shouldn't be returned 399 // Cloned views are owned by the ConnectionManager and shouldn't be returned
400 // from ViewManagerServiceImpl::GetView. 400 // from ViewTreeImpl::GetView.
401 EXPECT_TRUE(connection1->GetView(ClonedViewId()) == nullptr); 401 EXPECT_TRUE(connection1->GetView(ClonedViewId()) == nullptr);
402 EXPECT_TRUE(test->wm_connection()->GetView(ClonedViewId()) == nullptr); 402 EXPECT_TRUE(test->wm_connection()->GetView(ClonedViewId()) == nullptr);
403 } 403 }
404 404
405 } // namespace 405 } // namespace
406 406
407 // Verifies ViewManagerService::GetViewTree() doesn't return cloned views. 407 // Verifies ViewTree::GetViewTree() doesn't return cloned views.
408 TEST_F(ViewManagerServiceTest, ConnectionsCantSeeClonedViews) { 408 TEST_F(ViewTreeTest, ConnectionsCantSeeClonedViews) {
409 ViewId embed_view_id; 409 ViewId embed_view_id;
410 EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id)); 410 EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
411 411
412 ViewManagerServiceImpl* connection1 = 412 ViewTreeImpl* connection1 =
413 connection_manager()->GetConnectionWithRoot(embed_view_id); 413 connection_manager()->GetConnectionWithRoot(embed_view_id);
414 414
415 const ViewId child1(connection1->id(), 1); 415 const ViewId child1(connection1->id(), 1);
416 const ViewId child2(connection1->id(), 2); 416 const ViewId child2(connection1->id(), 2);
417 const ViewId child3(connection1->id(), 3); 417 const ViewId child3(connection1->id(), 3);
418 418
419 // Verify the root doesn't see any cloned views. 419 // Verify the root doesn't see any cloned views.
420 std::vector<const ServerView*> views( 420 std::vector<const ServerView*> views(
421 wm_connection()->GetViewTree(*wm_connection()->root())); 421 wm_connection()->GetViewTree(*wm_connection()->root()));
422 ASSERT_EQ(5u, views.size()); 422 ASSERT_EQ(5u, views.size());
423 ASSERT_TRUE(views[0]->id() == *wm_connection()->root()); 423 ASSERT_TRUE(views[0]->id() == *wm_connection()->root());
424 ASSERT_TRUE(views[1]->id() == embed_view_id); 424 ASSERT_TRUE(views[1]->id() == embed_view_id);
425 ASSERT_TRUE(views[2]->id() == child1); 425 ASSERT_TRUE(views[2]->id() == child1);
426 ASSERT_TRUE(views[3]->id() == child2); 426 ASSERT_TRUE(views[3]->id() == child2);
427 ASSERT_TRUE(views[4]->id() == child3); 427 ASSERT_TRUE(views[4]->id() == child3);
428 428
429 // Verify connection1 doesn't see any cloned views. 429 // Verify connection1 doesn't see any cloned views.
430 std::vector<const ServerView*> v1_views( 430 std::vector<const ServerView*> v1_views(
431 connection1->GetViewTree(embed_view_id)); 431 connection1->GetViewTree(embed_view_id));
432 ASSERT_EQ(4u, v1_views.size()); 432 ASSERT_EQ(4u, v1_views.size());
433 ASSERT_TRUE(v1_views[0]->id() == embed_view_id); 433 ASSERT_TRUE(v1_views[0]->id() == embed_view_id);
434 ASSERT_TRUE(v1_views[1]->id() == child1); 434 ASSERT_TRUE(v1_views[1]->id() == child1);
435 ASSERT_TRUE(v1_views[2]->id() == child2); 435 ASSERT_TRUE(v1_views[2]->id() == child2);
436 ASSERT_TRUE(v1_views[3]->id() == child3); 436 ASSERT_TRUE(v1_views[3]->id() == child3);
437 } 437 }
438 438
439 TEST_F(ViewManagerServiceTest, ClonedViewsPromotedOnConnectionClose) { 439 TEST_F(ViewTreeTest, ClonedViewsPromotedOnConnectionClose) {
440 ViewId embed_view_id; 440 ViewId embed_view_id;
441 EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id)); 441 EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
442 442
443 // Destroy connection1, which should force the cloned view to become a child 443 // Destroy connection1, which should force the cloned view to become a child
444 // of where it was embedded (the embedded view still exists). 444 // of where it was embedded (the embedded view still exists).
445 connection_manager()->OnConnectionError(last_client_connection()); 445 connection_manager()->OnConnectionError(last_client_connection());
446 446
447 ServerView* embed_view = wm_connection()->GetView(embed_view_id); 447 ServerView* embed_view = wm_connection()->GetView(embed_view_id);
448 ASSERT_TRUE(embed_view != nullptr); 448 ASSERT_TRUE(embed_view != nullptr);
449 const ServerView* cloned_view = GetFirstCloned(embed_view); 449 const ServerView* cloned_view = GetFirstCloned(embed_view);
450 ASSERT_TRUE(cloned_view); 450 ASSERT_TRUE(cloned_view);
451 ASSERT_EQ(1u, cloned_view->GetChildren().size()); 451 ASSERT_EQ(1u, cloned_view->GetChildren().size());
452 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId()); 452 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
453 453
454 // Because the cloned view changed parents its bounds should have changed. 454 // Because the cloned view changed parents its bounds should have changed.
455 EXPECT_EQ(gfx::Rect(3, 5, 6, 7), cloned_view->bounds()); 455 EXPECT_EQ(gfx::Rect(3, 5, 6, 7), cloned_view->bounds());
456 // The bounds of the cloned child should not have changed though. 456 // The bounds of the cloned child should not have changed though.
457 EXPECT_EQ(gfx::Rect(3, 4, 6, 7), cloned_view->GetChildren()[0]->bounds()); 457 EXPECT_EQ(gfx::Rect(3, 4, 6, 7), cloned_view->GetChildren()[0]->bounds());
458 } 458 }
459 459
460 TEST_F(ViewManagerServiceTest, ClonedViewsPromotedOnHide) { 460 TEST_F(ViewTreeTest, ClonedViewsPromotedOnHide) {
461 ViewId embed_view_id; 461 ViewId embed_view_id;
462 EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id)); 462 EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
463 463
464 ViewManagerServiceImpl* connection1 = 464 ViewTreeImpl* connection1 =
465 connection_manager()->GetConnectionWithRoot(embed_view_id); 465 connection_manager()->GetConnectionWithRoot(embed_view_id);
466 466
467 // Hide the parent of the cloned view, which should force the cloned view to 467 // Hide the parent of the cloned view, which should force the cloned view to
468 // become a sibling of the parent. 468 // become a sibling of the parent.
469 const ServerView* view_to_hide = 469 const ServerView* view_to_hide =
470 connection1->GetView(ViewId(connection1->id(), 1)); 470 connection1->GetView(ViewId(connection1->id(), 1));
471 ASSERT_TRUE(connection1->SetViewVisibility(view_to_hide->id(), false)); 471 ASSERT_TRUE(connection1->SetViewVisibility(view_to_hide->id(), false));
472 472
473 const ServerView* cloned_view = GetFirstCloned(view_to_hide->parent()); 473 const ServerView* cloned_view = GetFirstCloned(view_to_hide->parent());
474 ASSERT_TRUE(cloned_view); 474 ASSERT_TRUE(cloned_view);
475 ASSERT_EQ(1u, cloned_view->GetChildren().size()); 475 ASSERT_EQ(1u, cloned_view->GetChildren().size());
476 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId()); 476 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
477 EXPECT_EQ(2u, cloned_view->parent()->GetChildren().size()); 477 EXPECT_EQ(2u, cloned_view->parent()->GetChildren().size());
478 EXPECT_TRUE(cloned_view->parent()->GetChildren()[1] == cloned_view); 478 EXPECT_TRUE(cloned_view->parent()->GetChildren()[1] == cloned_view);
479 } 479 }
480 480
481 // Clone and animate on a tree with more depth. Basically that of 481 // Clone and animate on a tree with more depth. Basically that of
482 // SetUpAnimate1() but cloning 2,1. 482 // SetUpAnimate1() but cloning 2,1.
483 TEST_F(ViewManagerServiceTest, CloneAndAnimateLargerDepth) { 483 TEST_F(ViewTreeTest, CloneAndAnimateLargerDepth) {
484 const ViewId embed_view_id(wm_connection()->id(), 1); 484 const ViewId embed_view_id(wm_connection()->id(), 1);
485 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id)); 485 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id));
486 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true)); 486 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true));
487 EXPECT_TRUE( 487 EXPECT_TRUE(
488 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id)); 488 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id));
489 mojo::URLRequestPtr request(mojo::URLRequest::New()); 489 mojo::URLRequestPtr request(mojo::URLRequest::New());
490 wm_connection()->EmbedAllowingReembed(embed_view_id, request.Pass(), 490 wm_connection()->EmbedAllowingReembed(embed_view_id, request.Pass(),
491 mojo::Callback<void(bool)>()); 491 mojo::Callback<void(bool)>());
492 ViewManagerServiceImpl* connection1 = 492 ViewTreeImpl* connection1 =
493 connection_manager()->GetConnectionWithRoot(embed_view_id); 493 connection_manager()->GetConnectionWithRoot(embed_view_id);
494 ASSERT_TRUE(connection1 != nullptr); 494 ASSERT_TRUE(connection1 != nullptr);
495 ASSERT_NE(connection1, wm_connection()); 495 ASSERT_NE(connection1, wm_connection());
496 496
497 const ViewId child1(connection1->id(), 1); 497 const ViewId child1(connection1->id(), 1);
498 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1)); 498 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1));
499 const ViewId child2(connection1->id(), 2); 499 const ViewId child2(connection1->id(), 2);
500 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2)); 500 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2));
501 const ViewId child3(connection1->id(), 3); 501 const ViewId child3(connection1->id(), 3);
502 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3)); 502 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3));
503 503
504 ServerView* v1 = connection1->GetView(child1); 504 ServerView* v1 = connection1->GetView(child1);
505 v1->SetVisible(true); 505 v1->SetVisible(true);
506 connection1->GetView(child2)->SetVisible(true); 506 connection1->GetView(child2)->SetVisible(true);
507 connection1->GetView(child3)->SetVisible(true); 507 connection1->GetView(child3)->SetVisible(true);
508 508
509 EXPECT_TRUE(connection1->AddView(embed_view_id, child1)); 509 EXPECT_TRUE(connection1->AddView(embed_view_id, child1));
510 EXPECT_TRUE(connection1->AddView(child1, child2)); 510 EXPECT_TRUE(connection1->AddView(child1, child2));
511 EXPECT_TRUE(connection1->AddView(child2, child3)); 511 EXPECT_TRUE(connection1->AddView(child2, child3));
512 512
513 TestViewManagerClient* connection1_client = last_view_manager_client(); 513 TestViewTreeClient* connection1_client = last_view_tree_client();
514 connection1_client->tracker()->changes()->clear(); 514 connection1_client->tracker()->changes()->clear();
515 wm_client()->tracker()->changes()->clear(); 515 wm_client()->tracker()->changes()->clear();
516 EXPECT_TRUE(connection_manager()->CloneAndAnimate(child1)); 516 EXPECT_TRUE(connection_manager()->CloneAndAnimate(child1));
517 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); 517 EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
518 EXPECT_TRUE(wm_client()->tracker()->changes()->empty()); 518 EXPECT_TRUE(wm_client()->tracker()->changes()->empty());
519 519
520 // We cloned v1. The cloned view ends up as a sibling of it. 520 // We cloned v1. The cloned view ends up as a sibling of it.
521 const ServerView* cloned_view = GetFirstCloned(v1->parent()); 521 const ServerView* cloned_view = GetFirstCloned(v1->parent());
522 ASSERT_TRUE(cloned_view); 522 ASSERT_TRUE(cloned_view);
523 // |cloned_view| should have a child and its child should have a child. 523 // |cloned_view| should have a child and its child should have a child.
524 ASSERT_EQ(1u, cloned_view->GetChildren().size()); 524 ASSERT_EQ(1u, cloned_view->GetChildren().size());
525 const ServerView* cloned_view_child = cloned_view->GetChildren()[0]; 525 const ServerView* cloned_view_child = cloned_view->GetChildren()[0];
526 EXPECT_EQ(1u, cloned_view_child->GetChildren().size()); 526 EXPECT_EQ(1u, cloned_view_child->GetChildren().size());
527 EXPECT_TRUE(cloned_view_child->id() == ClonedViewId()); 527 EXPECT_TRUE(cloned_view_child->id() == ClonedViewId());
528 } 528 }
529 529
530 // Verifies focus correctly changes on pointer events. 530 // Verifies focus correctly changes on pointer events.
531 TEST_F(ViewManagerServiceTest, FocusOnPointer) { 531 TEST_F(ViewTreeTest, FocusOnPointer) {
532 const ViewId embed_view_id(wm_connection()->id(), 1); 532 const ViewId embed_view_id(wm_connection()->id(), 1);
533 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id)); 533 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id));
534 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true)); 534 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true));
535 EXPECT_TRUE( 535 EXPECT_TRUE(
536 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id)); 536 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id));
537 root_connection()->view_manager_root()->root_view()-> 537 root_connection()->view_manager_root()->root_view()->
538 SetBounds(gfx::Rect(0, 0, 100, 100)); 538 SetBounds(gfx::Rect(0, 0, 100, 100));
539 mojo::URLRequestPtr request(mojo::URLRequest::New()); 539 mojo::URLRequestPtr request(mojo::URLRequest::New());
540 wm_connection()->EmbedAllowingReembed(embed_view_id, request.Pass(), 540 wm_connection()->EmbedAllowingReembed(embed_view_id, request.Pass(),
541 mojo::Callback<void(bool)>()); 541 mojo::Callback<void(bool)>());
542 ViewManagerServiceImpl* connection1 = 542 ViewTreeImpl* connection1 =
543 connection_manager()->GetConnectionWithRoot(embed_view_id); 543 connection_manager()->GetConnectionWithRoot(embed_view_id);
544 ASSERT_TRUE(connection1 != nullptr); 544 ASSERT_TRUE(connection1 != nullptr);
545 ASSERT_NE(connection1, wm_connection()); 545 ASSERT_NE(connection1, wm_connection());
546 546
547 connection_manager() 547 connection_manager()
548 ->GetView(embed_view_id) 548 ->GetView(embed_view_id)
549 ->SetBounds(gfx::Rect(0, 0, 50, 50)); 549 ->SetBounds(gfx::Rect(0, 0, 50, 50));
550 550
551 const ViewId child1(connection1->id(), 1); 551 const ViewId child1(connection1->id(), 1);
552 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1)); 552 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1));
553 EXPECT_TRUE(connection1->AddView(embed_view_id, child1)); 553 EXPECT_TRUE(connection1->AddView(embed_view_id, child1));
554 ServerView* v1 = connection1->GetView(child1); 554 ServerView* v1 = connection1->GetView(child1);
555 v1->SetVisible(true); 555 v1->SetVisible(true);
556 v1->SetBounds(gfx::Rect(20, 20, 20, 20)); 556 v1->SetBounds(gfx::Rect(20, 20, 20, 20));
557 557
558 TestViewManagerClient* connection1_client = last_view_manager_client(); 558 TestViewTreeClient* connection1_client = last_view_tree_client();
559 connection1_client->tracker()->changes()->clear(); 559 connection1_client->tracker()->changes()->clear();
560 wm_client()->tracker()->changes()->clear(); 560 wm_client()->tracker()->changes()->clear();
561 561
562 connection_manager()->OnEvent(root_connection()->view_manager_root(), 562 connection_manager()->OnEvent(root_connection()->view_manager_root(),
563 CreatePointerDownEvent(21, 22)); 563 CreatePointerDownEvent(21, 22));
564 // Focus should go to child1. This results in notifying both the window 564 // Focus should go to child1. This results in notifying both the window
565 // manager and client connection being notified. 565 // manager and client connection being notified.
566 EXPECT_EQ(v1, connection_manager()->GetFocusedView()); 566 EXPECT_EQ(v1, connection_manager()->GetFocusedView());
567 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u); 567 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u);
568 EXPECT_EQ("Focused id=2,1", 568 EXPECT_EQ("Focused id=2,1",
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 CreatePointerDownEvent(61, 22)); 603 CreatePointerDownEvent(61, 22));
604 EXPECT_EQ(root_connection()->view_manager_root()->root_view(), 604 EXPECT_EQ(root_connection()->view_manager_root()->root_view(),
605 connection_manager()->GetFocusedView()); 605 connection_manager()->GetFocusedView());
606 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u); 606 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u);
607 EXPECT_EQ("InputEvent view=0,2 event_action=4", 607 EXPECT_EQ("InputEvent view=0,2 event_action=4",
608 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); 608 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
609 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); 609 EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
610 } 610 }
611 611
612 } // namespace view_manager 612 } // namespace view_manager
OLDNEW
« no previous file with comments | « components/view_manager/view_tree_impl.cc ('k') | mandoline/tab/frame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698