| OLD | NEW |
| 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 "mojo/converters/geometry/geometry_type_converters.h" | 9 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 10 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 10 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 // Provides common setup for animation tests. Creates the following views: | 249 // Provides common setup for animation tests. Creates the following views: |
| 250 // 0,1 (the root, provided by view manager) | 250 // 0,1 (the root, provided by view manager) |
| 251 // 1,1 the second connection is embedded here (view owned by wm_connection()). | 251 // 1,1 the second connection is embedded here (view owned by wm_connection()). |
| 252 // 2,1 bounds=1,2 11x22 | 252 // 2,1 bounds=1,2 11x22 |
| 253 // 2,2 bounds=2,3 6x7 | 253 // 2,2 bounds=2,3 6x7 |
| 254 // 2,3 bounds=3,4 6x7 | 254 // 2,3 bounds=3,4 6x7 |
| 255 // CloneAndAnimate() is invoked for 2,2. | 255 // CloneAndAnimate() is invoked for 2,2. |
| 256 void SetUpAnimate1(ViewManagerServiceTest* test, ViewId* embed_view_id) { | 256 void SetUpAnimate1(ViewManagerServiceTest* test, ViewId* embed_view_id) { |
| 257 *embed_view_id = ViewId(test->wm_connection()->id(), 1); | 257 *embed_view_id = ViewId(test->wm_connection()->id(), 1); |
| 258 EXPECT_EQ(ERROR_CODE_NONE, test->wm_connection()->CreateView(*embed_view_id)); | 258 EXPECT_EQ(ERROR_CODE_NONE, test->wm_connection()->CreateView(*embed_view_id)); |
| 259 EXPECT_TRUE(test->wm_connection()->SetViewVisibility(*embed_view_id, true)); |
| 259 EXPECT_TRUE(test->wm_connection()->AddView(*(test->wm_connection()->root()), | 260 EXPECT_TRUE(test->wm_connection()->AddView(*(test->wm_connection()->root()), |
| 260 *embed_view_id)); | 261 *embed_view_id)); |
| 261 EXPECT_TRUE(test->wm_connection()->Embed( | 262 EXPECT_TRUE(test->wm_connection()->Embed( |
| 262 std::string(), *embed_view_id, InterfaceRequest<ServiceProvider>())); | 263 std::string(), *embed_view_id, InterfaceRequest<ServiceProvider>())); |
| 263 ViewManagerServiceImpl* connection1 = | 264 ViewManagerServiceImpl* connection1 = |
| 264 test->connection_manager()->GetConnectionWithRoot(*embed_view_id); | 265 test->connection_manager()->GetConnectionWithRoot(*embed_view_id); |
| 265 ASSERT_TRUE(connection1 != nullptr); | 266 ASSERT_TRUE(connection1 != nullptr); |
| 266 ASSERT_NE(connection1, test->wm_connection()); | 267 ASSERT_NE(connection1, test->wm_connection()); |
| 267 | 268 |
| 268 const ViewId child1(connection1->id(), 1); | 269 const ViewId child1(connection1->id(), 1); |
| 269 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1)); | 270 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1)); |
| 270 const ViewId child2(connection1->id(), 2); | 271 const ViewId child2(connection1->id(), 2); |
| 271 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2)); | 272 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2)); |
| 272 const ViewId child3(connection1->id(), 3); | 273 const ViewId child3(connection1->id(), 3); |
| 273 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3)); | 274 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3)); |
| 274 | 275 |
| 275 ServerView* v1 = connection1->GetView(child1); | 276 ServerView* v1 = connection1->GetView(child1); |
| 277 v1->SetVisible(true); |
| 276 v1->SetBounds(gfx::Rect(1, 2, 11, 22)); | 278 v1->SetBounds(gfx::Rect(1, 2, 11, 22)); |
| 277 ServerView* v2 = connection1->GetView(child2); | 279 ServerView* v2 = connection1->GetView(child2); |
| 280 v2->SetVisible(true); |
| 278 v2->SetBounds(gfx::Rect(2, 3, 6, 7)); | 281 v2->SetBounds(gfx::Rect(2, 3, 6, 7)); |
| 279 ServerView* v3 = connection1->GetView(child3); | 282 ServerView* v3 = connection1->GetView(child3); |
| 283 v3->SetVisible(true); |
| 280 v3->SetBounds(gfx::Rect(3, 4, 6, 7)); | 284 v3->SetBounds(gfx::Rect(3, 4, 6, 7)); |
| 281 | 285 |
| 282 EXPECT_TRUE(connection1->AddView(*embed_view_id, child1)); | 286 EXPECT_TRUE(connection1->AddView(*embed_view_id, child1)); |
| 283 EXPECT_TRUE(connection1->AddView(child1, child2)); | 287 EXPECT_TRUE(connection1->AddView(child1, child2)); |
| 284 EXPECT_TRUE(connection1->AddView(child2, child3)); | 288 EXPECT_TRUE(connection1->AddView(child2, child3)); |
| 285 | 289 |
| 286 TestViewManagerClient* connection1_client = test->last_view_manager_client(); | 290 TestViewManagerClient* connection1_client = test->last_view_manager_client(); |
| 287 connection1_client->tracker()->changes()->clear(); | 291 connection1_client->tracker()->changes()->clear(); |
| 288 test->wm_client()->tracker()->changes()->clear(); | 292 test->wm_client()->tracker()->changes()->clear(); |
| 289 EXPECT_TRUE(test->connection_manager()->CloneAndAnimate(child2)); | 293 EXPECT_TRUE(test->connection_manager()->CloneAndAnimate(child2)); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId()); | 386 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId()); |
| 383 EXPECT_EQ(2u, cloned_view->parent()->GetChildren().size()); | 387 EXPECT_EQ(2u, cloned_view->parent()->GetChildren().size()); |
| 384 EXPECT_TRUE(cloned_view->parent()->GetChildren()[1] == cloned_view); | 388 EXPECT_TRUE(cloned_view->parent()->GetChildren()[1] == cloned_view); |
| 385 } | 389 } |
| 386 | 390 |
| 387 // Clone and animate on a tree with more depth. Basically that of | 391 // Clone and animate on a tree with more depth. Basically that of |
| 388 // SetUpAnimate1() but cloning 2,1. | 392 // SetUpAnimate1() but cloning 2,1. |
| 389 TEST_F(ViewManagerServiceTest, CloneAndAnimateLargerDepth) { | 393 TEST_F(ViewManagerServiceTest, CloneAndAnimateLargerDepth) { |
| 390 const ViewId embed_view_id(wm_connection()->id(), 1); | 394 const ViewId embed_view_id(wm_connection()->id(), 1); |
| 391 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id)); | 395 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id)); |
| 396 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true)); |
| 392 EXPECT_TRUE( | 397 EXPECT_TRUE( |
| 393 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id)); | 398 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id)); |
| 394 EXPECT_TRUE(wm_connection()->Embed(std::string(), embed_view_id, | 399 EXPECT_TRUE(wm_connection()->Embed(std::string(), embed_view_id, |
| 395 InterfaceRequest<ServiceProvider>())); | 400 InterfaceRequest<ServiceProvider>())); |
| 396 ViewManagerServiceImpl* connection1 = | 401 ViewManagerServiceImpl* connection1 = |
| 397 connection_manager()->GetConnectionWithRoot(embed_view_id); | 402 connection_manager()->GetConnectionWithRoot(embed_view_id); |
| 398 ASSERT_TRUE(connection1 != nullptr); | 403 ASSERT_TRUE(connection1 != nullptr); |
| 399 ASSERT_NE(connection1, wm_connection()); | 404 ASSERT_NE(connection1, wm_connection()); |
| 400 | 405 |
| 401 const ViewId child1(connection1->id(), 1); | 406 const ViewId child1(connection1->id(), 1); |
| 402 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1)); | 407 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1)); |
| 403 const ViewId child2(connection1->id(), 2); | 408 const ViewId child2(connection1->id(), 2); |
| 404 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2)); | 409 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2)); |
| 405 const ViewId child3(connection1->id(), 3); | 410 const ViewId child3(connection1->id(), 3); |
| 406 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3)); | 411 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3)); |
| 407 | 412 |
| 408 ServerView* v1 = connection1->GetView(child1); | 413 ServerView* v1 = connection1->GetView(child1); |
| 414 v1->SetVisible(true); |
| 415 connection1->GetView(child2)->SetVisible(true); |
| 416 connection1->GetView(child3)->SetVisible(true); |
| 409 | 417 |
| 410 EXPECT_TRUE(connection1->AddView(embed_view_id, child1)); | 418 EXPECT_TRUE(connection1->AddView(embed_view_id, child1)); |
| 411 EXPECT_TRUE(connection1->AddView(child1, child2)); | 419 EXPECT_TRUE(connection1->AddView(child1, child2)); |
| 412 EXPECT_TRUE(connection1->AddView(child2, child3)); | 420 EXPECT_TRUE(connection1->AddView(child2, child3)); |
| 413 | 421 |
| 414 TestViewManagerClient* connection1_client = last_view_manager_client(); | 422 TestViewManagerClient* connection1_client = last_view_manager_client(); |
| 415 connection1_client->tracker()->changes()->clear(); | 423 connection1_client->tracker()->changes()->clear(); |
| 416 wm_client()->tracker()->changes()->clear(); | 424 wm_client()->tracker()->changes()->clear(); |
| 417 EXPECT_TRUE(connection_manager()->CloneAndAnimate(child1)); | 425 EXPECT_TRUE(connection_manager()->CloneAndAnimate(child1)); |
| 418 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); | 426 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); |
| 419 EXPECT_TRUE(wm_client()->tracker()->changes()->empty()); | 427 EXPECT_TRUE(wm_client()->tracker()->changes()->empty()); |
| 420 | 428 |
| 421 // We cloned v1. The cloned view ends up as a sibling of it. | 429 // We cloned v1. The cloned view ends up as a sibling of it. |
| 422 const ServerView* cloned_view = GetFirstCloned(v1->parent()); | 430 const ServerView* cloned_view = GetFirstCloned(v1->parent()); |
| 423 ASSERT_TRUE(cloned_view); | 431 ASSERT_TRUE(cloned_view); |
| 424 // |cloned_view| should have a child and its child should have a child. | 432 // |cloned_view| should have a child and its child should have a child. |
| 425 ASSERT_EQ(1u, cloned_view->GetChildren().size()); | 433 ASSERT_EQ(1u, cloned_view->GetChildren().size()); |
| 426 const ServerView* cloned_view_child = cloned_view->GetChildren()[0]; | 434 const ServerView* cloned_view_child = cloned_view->GetChildren()[0]; |
| 427 EXPECT_EQ(1u, cloned_view_child->GetChildren().size()); | 435 EXPECT_EQ(1u, cloned_view_child->GetChildren().size()); |
| 428 EXPECT_TRUE(cloned_view_child->id() == ClonedViewId()); | 436 EXPECT_TRUE(cloned_view_child->id() == ClonedViewId()); |
| 429 } | 437 } |
| 430 | 438 |
| 431 } // namespace service | 439 } // namespace service |
| 432 } // namespace mojo | 440 } // namespace mojo |
| OLD | NEW |