| 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/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 98 } |
| 99 | 99 |
| 100 void CopyChangesFromTracker() { | 100 void CopyChangesFromTracker() { |
| 101 std::vector<Change> changes; | 101 std::vector<Change> changes; |
| 102 tracker_->changes()->swap(changes); | 102 tracker_->changes()->swap(changes); |
| 103 changes_.swap(changes); | 103 changes_.swap(changes); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // The following functions are cover methods for ViewManagerService. They | 106 // The following functions are cover methods for ViewManagerService. They |
| 107 // block until the result is received. | 107 // block until the result is received. |
| 108 bool CreateNode(Id node_id) { | 108 bool CreateView(Id view_id) { |
| 109 changes_.clear(); | 109 changes_.clear(); |
| 110 ErrorCode result = ERROR_CODE_NONE; | 110 ErrorCode result = ERROR_CODE_NONE; |
| 111 view_manager_->CreateView( | 111 view_manager_->CreateView( |
| 112 node_id, | 112 view_id, |
| 113 base::Bind(&ViewManagerProxy::GotResultWithErrorCode, | 113 base::Bind(&ViewManagerProxy::GotResultWithErrorCode, |
| 114 base::Unretained(this), &result)); | 114 base::Unretained(this), |
| 115 &result)); |
| 115 RunMainLoop(); | 116 RunMainLoop(); |
| 116 return result == ERROR_CODE_NONE; | 117 return result == ERROR_CODE_NONE; |
| 117 } | 118 } |
| 118 ErrorCode CreateNodeWithErrorCode(Id node_id) { | 119 ErrorCode CreateViewWithErrorCode(Id view_id) { |
| 119 changes_.clear(); | 120 changes_.clear(); |
| 120 ErrorCode result = ERROR_CODE_NONE; | 121 ErrorCode result = ERROR_CODE_NONE; |
| 121 view_manager_->CreateView( | 122 view_manager_->CreateView( |
| 122 node_id, | 123 view_id, |
| 123 base::Bind(&ViewManagerProxy::GotResultWithErrorCode, | 124 base::Bind(&ViewManagerProxy::GotResultWithErrorCode, |
| 124 base::Unretained(this), &result)); | 125 base::Unretained(this), |
| 126 &result)); |
| 125 RunMainLoop(); | 127 RunMainLoop(); |
| 126 return result; | 128 return result; |
| 127 } | 129 } |
| 128 bool AddNode(Id parent, Id child) { | 130 bool AddView(Id parent, Id child) { |
| 129 changes_.clear(); | 131 changes_.clear(); |
| 130 bool result = false; | 132 bool result = false; |
| 131 view_manager_->AddView(parent, child, | 133 view_manager_->AddView(parent, child, |
| 132 base::Bind(&ViewManagerProxy::GotResult, | 134 base::Bind(&ViewManagerProxy::GotResult, |
| 133 base::Unretained(this), &result)); | 135 base::Unretained(this), &result)); |
| 134 RunMainLoop(); | 136 RunMainLoop(); |
| 135 return result; | 137 return result; |
| 136 } | 138 } |
| 137 bool RemoveNodeFromParent(Id node_id) { | 139 bool RemoveViewFromParent(Id view_id) { |
| 138 changes_.clear(); | 140 changes_.clear(); |
| 139 bool result = false; | 141 bool result = false; |
| 140 view_manager_->RemoveViewFromParent(node_id, | 142 view_manager_->RemoveViewFromParent( |
| 141 base::Bind(&ViewManagerProxy::GotResult, | 143 view_id, |
| 142 base::Unretained(this), &result)); | 144 base::Bind( |
| 145 &ViewManagerProxy::GotResult, base::Unretained(this), &result)); |
| 143 RunMainLoop(); | 146 RunMainLoop(); |
| 144 return result; | 147 return result; |
| 145 } | 148 } |
| 146 bool ReorderNode(Id node_id, | 149 bool ReorderView(Id view_id, Id relative_view_id, OrderDirection direction) { |
| 147 Id relative_node_id, | |
| 148 OrderDirection direction) { | |
| 149 changes_.clear(); | 150 changes_.clear(); |
| 150 bool result = false; | 151 bool result = false; |
| 151 view_manager_->ReorderView(node_id, relative_node_id, direction, | 152 view_manager_->ReorderView( |
| 152 base::Bind(&ViewManagerProxy::GotResult, | 153 view_id, |
| 153 base::Unretained(this), &result)); | 154 relative_view_id, |
| 155 direction, |
| 156 base::Bind( |
| 157 &ViewManagerProxy::GotResult, base::Unretained(this), &result)); |
| 154 RunMainLoop(); | 158 RunMainLoop(); |
| 155 return result; | 159 return result; |
| 156 } | 160 } |
| 157 void GetNodeTree(Id node_id, std::vector<TestNode>* nodes) { | 161 void GetViewTree(Id view_id, std::vector<TestView>* views) { |
| 158 changes_.clear(); | 162 changes_.clear(); |
| 159 view_manager_->GetViewTree(node_id, | 163 view_manager_->GetViewTree( |
| 160 base::Bind(&ViewManagerProxy::GotNodeTree, | 164 view_id, |
| 161 base::Unretained(this), nodes)); | 165 base::Bind( |
| 166 &ViewManagerProxy::GotViewTree, base::Unretained(this), views)); |
| 162 RunMainLoop(); | 167 RunMainLoop(); |
| 163 } | 168 } |
| 164 bool Embed(const Id node_id, const char* url) { | 169 bool Embed(const Id view_id, const char* url) { |
| 165 changes_.clear(); | 170 changes_.clear(); |
| 166 base::AutoReset<bool> auto_reset(&in_embed_, true); | 171 base::AutoReset<bool> auto_reset(&in_embed_, true); |
| 167 bool result = false; | 172 bool result = false; |
| 168 ServiceProviderPtr services; | 173 ServiceProviderPtr services; |
| 169 view_manager_->Embed(url, node_id, services.Pass(), | 174 view_manager_->Embed( |
| 170 base::Bind(&ViewManagerProxy::GotResult, | 175 url, |
| 171 base::Unretained(this), &result)); | 176 view_id, |
| 177 services.Pass(), |
| 178 base::Bind( |
| 179 &ViewManagerProxy::GotResult, base::Unretained(this), &result)); |
| 172 RunMainLoop(); | 180 RunMainLoop(); |
| 173 return result; | 181 return result; |
| 174 } | 182 } |
| 175 bool DeleteNode(Id node_id) { | 183 bool DeleteView(Id view_id) { |
| 176 changes_.clear(); | 184 changes_.clear(); |
| 177 bool result = false; | 185 bool result = false; |
| 178 view_manager_->DeleteView(node_id, | 186 view_manager_->DeleteView( |
| 179 base::Bind(&ViewManagerProxy::GotResult, | 187 view_id, |
| 180 base::Unretained(this), &result)); | 188 base::Bind( |
| 189 &ViewManagerProxy::GotResult, base::Unretained(this), &result)); |
| 181 RunMainLoop(); | 190 RunMainLoop(); |
| 182 return result; | 191 return result; |
| 183 } | 192 } |
| 184 bool SetNodeBounds(Id node_id, const gfx::Rect& bounds) { | 193 bool SetViewBounds(Id view_id, const gfx::Rect& bounds) { |
| 185 changes_.clear(); | 194 changes_.clear(); |
| 186 bool result = false; | 195 bool result = false; |
| 187 view_manager_->SetViewBounds(node_id, Rect::From(bounds), | 196 view_manager_->SetViewBounds( |
| 188 base::Bind(&ViewManagerProxy::GotResult, | 197 view_id, |
| 189 base::Unretained(this), &result)); | 198 Rect::From(bounds), |
| 199 base::Bind( |
| 200 &ViewManagerProxy::GotResult, base::Unretained(this), &result)); |
| 190 RunMainLoop(); | 201 RunMainLoop(); |
| 191 return result; | 202 return result; |
| 192 } | 203 } |
| 193 | 204 |
| 194 private: | 205 private: |
| 195 friend class TestViewManagerClientConnection; | 206 friend class TestViewManagerClientConnection; |
| 196 | 207 |
| 197 void set_router(mojo::internal::Router* router) { router_ = router; } | 208 void set_router(mojo::internal::Router* router) { router_ = router; } |
| 198 | 209 |
| 199 void set_view_manager(ViewManagerService* view_manager) { | 210 void set_view_manager(ViewManagerService* view_manager) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 main_run_loop_->Quit(); | 242 main_run_loop_->Quit(); |
| 232 } | 243 } |
| 233 | 244 |
| 234 void GotResultWithErrorCode(ErrorCode* error_code_cache, | 245 void GotResultWithErrorCode(ErrorCode* error_code_cache, |
| 235 ErrorCode error_code) { | 246 ErrorCode error_code) { |
| 236 *error_code_cache = error_code; | 247 *error_code_cache = error_code; |
| 237 DCHECK(main_run_loop_); | 248 DCHECK(main_run_loop_); |
| 238 main_run_loop_->Quit(); | 249 main_run_loop_->Quit(); |
| 239 } | 250 } |
| 240 | 251 |
| 241 void GotNodeTree(std::vector<TestNode>* nodes, Array<ViewDataPtr> results) { | 252 void GotViewTree(std::vector<TestView>* views, Array<ViewDataPtr> results) { |
| 242 ViewDatasToTestNodes(results, nodes); | 253 ViewDatasToTestViews(results, views); |
| 243 DCHECK(main_run_loop_); | 254 DCHECK(main_run_loop_); |
| 244 main_run_loop_->Quit(); | 255 main_run_loop_->Quit(); |
| 245 } | 256 } |
| 246 | 257 |
| 247 // TestChangeTracker::Delegate: | 258 // TestChangeTracker::Delegate: |
| 248 virtual void OnChangeAdded() OVERRIDE { | 259 virtual void OnChangeAdded() OVERRIDE { |
| 249 if (quit_count_ > 0 && --quit_count_ == 0) | 260 if (quit_count_ > 0 && --quit_count_ == 0) |
| 250 QuitCountReached(); | 261 QuitCountReached(); |
| 251 } | 262 } |
| 252 | 263 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 } | 305 } |
| 295 | 306 |
| 296 // ViewManagerClient: | 307 // ViewManagerClient: |
| 297 virtual void OnEmbed( | 308 virtual void OnEmbed( |
| 298 ConnectionSpecificId connection_id, | 309 ConnectionSpecificId connection_id, |
| 299 const String& creator_url, | 310 const String& creator_url, |
| 300 ViewDataPtr root, | 311 ViewDataPtr root, |
| 301 InterfaceRequest<ServiceProvider> services) OVERRIDE { | 312 InterfaceRequest<ServiceProvider> services) OVERRIDE { |
| 302 tracker_.OnEmbed(connection_id, creator_url, root.Pass()); | 313 tracker_.OnEmbed(connection_id, creator_url, root.Pass()); |
| 303 } | 314 } |
| 304 virtual void OnViewBoundsChanged(Id node_id, | 315 virtual void OnViewBoundsChanged(Id view_id, |
| 305 RectPtr old_bounds, | 316 RectPtr old_bounds, |
| 306 RectPtr new_bounds) OVERRIDE { | 317 RectPtr new_bounds) OVERRIDE { |
| 307 tracker_.OnNodeBoundsChanged(node_id, old_bounds.Pass(), new_bounds.Pass()); | 318 tracker_.OnViewBoundsChanged(view_id, old_bounds.Pass(), new_bounds.Pass()); |
| 308 } | 319 } |
| 309 virtual void OnViewHierarchyChanged(Id node, | 320 virtual void OnViewHierarchyChanged(Id view, |
| 310 Id new_parent, | 321 Id new_parent, |
| 311 Id old_parent, | 322 Id old_parent, |
| 312 Array<ViewDataPtr> nodes) OVERRIDE { | 323 Array<ViewDataPtr> views) OVERRIDE { |
| 313 tracker_.OnNodeHierarchyChanged(node, new_parent, old_parent, nodes.Pass()); | 324 tracker_.OnViewHierarchyChanged(view, new_parent, old_parent, views.Pass()); |
| 314 } | 325 } |
| 315 virtual void OnViewReordered(Id node_id, | 326 virtual void OnViewReordered(Id view_id, |
| 316 Id relative_node_id, | 327 Id relative_view_id, |
| 317 OrderDirection direction) OVERRIDE { | 328 OrderDirection direction) OVERRIDE { |
| 318 tracker_.OnNodeReordered(node_id, relative_node_id, direction); | 329 tracker_.OnViewReordered(view_id, relative_view_id, direction); |
| 319 } | 330 } |
| 320 virtual void OnViewDeleted(Id node) OVERRIDE { | 331 virtual void OnViewDeleted(Id view) OVERRIDE { tracker_.OnViewDeleted(view); } |
| 321 tracker_.OnNodeDeleted(node); | 332 virtual void OnViewInputEvent(Id view_id, |
| 322 } | |
| 323 virtual void OnViewInputEvent(Id node_id, | |
| 324 EventPtr event, | 333 EventPtr event, |
| 325 const Callback<void()>& callback) OVERRIDE { | 334 const Callback<void()>& callback) OVERRIDE { |
| 326 tracker_.OnNodeInputEvent(node_id, event.Pass()); | 335 tracker_.OnViewInputEvent(view_id, event.Pass()); |
| 327 } | 336 } |
| 328 virtual void Embed( | 337 virtual void Embed( |
| 329 const String& url, | 338 const String& url, |
| 330 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { | 339 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { |
| 331 tracker_.DelegateEmbed(url); | 340 tracker_.DelegateEmbed(url); |
| 332 } | 341 } |
| 333 virtual void DispatchOnViewInputEvent(mojo::EventPtr event) OVERRIDE { | 342 virtual void DispatchOnViewInputEvent(mojo::EventPtr event) OVERRIDE { |
| 334 } | 343 } |
| 335 | 344 |
| 336 private: | 345 private: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 BindToRequest(new TestViewManagerClientConnection, &request); | 385 BindToRequest(new TestViewManagerClientConnection, &request); |
| 377 } | 386 } |
| 378 | 387 |
| 379 private: | 388 private: |
| 380 ScopedVector<ApplicationImpl> apps_; | 389 ScopedVector<ApplicationImpl> apps_; |
| 381 | 390 |
| 382 DISALLOW_COPY_AND_ASSIGN(EmbedApplicationLoader); | 391 DISALLOW_COPY_AND_ASSIGN(EmbedApplicationLoader); |
| 383 }; | 392 }; |
| 384 | 393 |
| 385 // Creates an id used for transport from the specified parameters. | 394 // Creates an id used for transport from the specified parameters. |
| 386 Id BuildNodeId(ConnectionSpecificId connection_id, | 395 Id BuildViewId(ConnectionSpecificId connection_id, |
| 387 ConnectionSpecificId node_id) { | 396 ConnectionSpecificId view_id) { |
| 388 return (connection_id << 16) | node_id; | 397 return (connection_id << 16) | view_id; |
| 389 } | 398 } |
| 390 | 399 |
| 391 // Callback from Embed(). |result| is the result of the | 400 // Callback from Embed(). |result| is the result of the |
| 392 // Embed() call and |run_loop| the nested RunLoop. | 401 // Embed() call and |run_loop| the nested RunLoop. |
| 393 void EmbedCallback(bool* result_cache, base::RunLoop* run_loop, bool result) { | 402 void EmbedCallback(bool* result_cache, base::RunLoop* run_loop, bool result) { |
| 394 *result_cache = result; | 403 *result_cache = result; |
| 395 run_loop->Quit(); | 404 run_loop->Quit(); |
| 396 } | 405 } |
| 397 | 406 |
| 398 // Embed from an application that does not yet have a view manager connection. | 407 // Embed from an application that does not yet have a view manager connection. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 protected: | 463 protected: |
| 455 void EstablishSecondConnectionWithRoot(Id root_id) { | 464 void EstablishSecondConnectionWithRoot(Id root_id) { |
| 456 ASSERT_TRUE(connection_->Embed(root_id, kTestServiceURL)); | 465 ASSERT_TRUE(connection_->Embed(root_id, kTestServiceURL)); |
| 457 connection2_ = ViewManagerProxy::WaitForInstance(); | 466 connection2_ = ViewManagerProxy::WaitForInstance(); |
| 458 ASSERT_TRUE(connection2_ != NULL); | 467 ASSERT_TRUE(connection2_ != NULL); |
| 459 connection2_->DoRunLoopUntilChangesCount(1); | 468 connection2_->DoRunLoopUntilChangesCount(1); |
| 460 ASSERT_EQ(1u, connection2_->changes().size()); | 469 ASSERT_EQ(1u, connection2_->changes().size()); |
| 461 } | 470 } |
| 462 | 471 |
| 463 // Creates a second connection to the viewmanager. | 472 // Creates a second connection to the viewmanager. |
| 464 void EstablishSecondConnection(bool create_initial_node) { | 473 void EstablishSecondConnection(bool create_initial_view) { |
| 465 if (create_initial_node) | 474 if (create_initial_view) |
| 466 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 475 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
| 467 ASSERT_NO_FATAL_FAILURE( | 476 ASSERT_NO_FATAL_FAILURE( |
| 468 EstablishSecondConnectionWithRoot(BuildNodeId(1, 1))); | 477 EstablishSecondConnectionWithRoot(BuildViewId(1, 1))); |
| 469 const std::vector<Change>& changes(connection2_->changes()); | 478 const std::vector<Change>& changes(connection2_->changes()); |
| 470 ASSERT_EQ(1u, changes.size()); | 479 ASSERT_EQ(1u, changes.size()); |
| 471 EXPECT_EQ("OnEmbed creator=mojo:test_url", | 480 EXPECT_EQ("OnEmbed creator=mojo:test_url", |
| 472 ChangesToDescription1(changes)[0]); | 481 ChangesToDescription1(changes)[0]); |
| 473 if (create_initial_node) { | 482 if (create_initial_view) { |
| 474 EXPECT_EQ("[node=1,1 parent=null]", | 483 EXPECT_EQ("[view=1,1 parent=null]", ChangeViewDescription(changes)); |
| 475 ChangeNodeDescription(changes)); | |
| 476 } | 484 } |
| 477 } | 485 } |
| 478 | 486 |
| 479 void EstablishThirdConnection(ViewManagerProxy* owner, Id root_id) { | 487 void EstablishThirdConnection(ViewManagerProxy* owner, Id root_id) { |
| 480 ASSERT_TRUE(connection3_ == NULL); | 488 ASSERT_TRUE(connection3_ == NULL); |
| 481 ASSERT_TRUE(owner->Embed(root_id, kTestServiceURL2)); | 489 ASSERT_TRUE(owner->Embed(root_id, kTestServiceURL2)); |
| 482 connection3_ = ViewManagerProxy::WaitForInstance(); | 490 connection3_ = ViewManagerProxy::WaitForInstance(); |
| 483 ASSERT_TRUE(connection3_ != NULL); | 491 ASSERT_TRUE(connection3_ != NULL); |
| 484 connection3_->DoRunLoopUntilChangesCount(1); | 492 connection3_->DoRunLoopUntilChangesCount(1); |
| 485 ASSERT_EQ(1u, connection3_->changes().size()); | 493 ASSERT_EQ(1u, connection3_->changes().size()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 505 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); | 513 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); |
| 506 }; | 514 }; |
| 507 | 515 |
| 508 TEST_F(ViewManagerTest, SecondEmbedRoot_InitService) { | 516 TEST_F(ViewManagerTest, SecondEmbedRoot_InitService) { |
| 509 ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 1)); | 517 ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 1)); |
| 510 connection_->DoRunLoopUntilChangesCount(1); | 518 connection_->DoRunLoopUntilChangesCount(1); |
| 511 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url); | 519 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url); |
| 512 } | 520 } |
| 513 | 521 |
| 514 TEST_F(ViewManagerTest, SecondEmbedRoot_Service) { | 522 TEST_F(ViewManagerTest, SecondEmbedRoot_Service) { |
| 515 ASSERT_TRUE(connection_->Embed(BuildNodeId(0, 0), kTestServiceURL)); | 523 ASSERT_TRUE(connection_->Embed(BuildViewId(0, 0), kTestServiceURL)); |
| 516 connection_->DoRunLoopUntilChangesCount(1); | 524 connection_->DoRunLoopUntilChangesCount(1); |
| 517 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url); | 525 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url); |
| 518 } | 526 } |
| 519 | 527 |
| 520 TEST_F(ViewManagerTest, MultipleEmbedRootsBeforeWTHReady) { | 528 TEST_F(ViewManagerTest, MultipleEmbedRootsBeforeWTHReady) { |
| 521 ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 2)); | 529 ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 2)); |
| 522 connection_->DoRunLoopUntilChangesCount(2); | 530 connection_->DoRunLoopUntilChangesCount(2); |
| 523 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url); | 531 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url); |
| 524 EXPECT_EQ(kTestServiceURL, connection_->changes()[1].embed_url); | 532 EXPECT_EQ(kTestServiceURL, connection_->changes()[1].embed_url); |
| 525 } | 533 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 547 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 555 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 548 EXPECT_EQ("OnEmbed creator=mojo:test_url", | 556 EXPECT_EQ("OnEmbed creator=mojo:test_url", |
| 549 ChangesToDescription1(connection2_->changes())[0]); | 557 ChangesToDescription1(connection2_->changes())[0]); |
| 550 | 558 |
| 551 // It isn't strictly necessary that the second connection gets 2, but these | 559 // It isn't strictly necessary that the second connection gets 2, but these |
| 552 // tests are written assuming that is the case. The key thing is the | 560 // tests are written assuming that is the case. The key thing is the |
| 553 // connection ids of |connection_| and |connection2_| differ. | 561 // connection ids of |connection_| and |connection2_| differ. |
| 554 EXPECT_EQ(2, connection2_->changes()[0].connection_id); | 562 EXPECT_EQ(2, connection2_->changes()[0].connection_id); |
| 555 } | 563 } |
| 556 | 564 |
| 557 // Verifies when Embed() is invoked any child nodes are removed. | 565 // Verifies when Embed() is invoked any child views are removed. |
| 558 TEST_F(ViewManagerTest, NodesRemovedWhenEmbedding) { | 566 TEST_F(ViewManagerTest, ViewsRemovedWhenEmbedding) { |
| 559 // Two nodes 1 and 2. 2 is parented to 1. | 567 // Two views 1 and 2. 2 is parented to 1. |
| 560 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 568 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
| 561 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 569 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2))); |
| 562 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); | 570 ASSERT_TRUE(connection_->AddView(BuildViewId(1, 1), BuildViewId(1, 2))); |
| 563 | 571 |
| 564 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 572 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 565 EXPECT_EQ("[node=1,1 parent=null]", | 573 EXPECT_EQ("[view=1,1 parent=null]", |
| 566 ChangeNodeDescription(connection2_->changes())); | 574 ChangeViewDescription(connection2_->changes())); |
| 567 | 575 |
| 568 // Embed() removed node 2. | 576 // Embed() removed view 2. |
| 569 { | 577 { |
| 570 std::vector<TestNode> nodes; | 578 std::vector<TestView> views; |
| 571 connection_->GetNodeTree(BuildNodeId(1, 2), &nodes); | 579 connection_->GetViewTree(BuildViewId(1, 2), &views); |
| 572 ASSERT_EQ(1u, nodes.size()); | 580 ASSERT_EQ(1u, views.size()); |
| 573 EXPECT_EQ("node=1,2 parent=null", nodes[0].ToString()); | 581 EXPECT_EQ("view=1,2 parent=null", views[0].ToString()); |
| 574 } | 582 } |
| 575 | 583 |
| 576 // |connection2_| should not see node 2. | 584 // |connection2_| should not see view 2. |
| 577 { | 585 { |
| 578 std::vector<TestNode> nodes; | 586 std::vector<TestView> views; |
| 579 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); | 587 connection2_->GetViewTree(BuildViewId(1, 1), &views); |
| 580 ASSERT_EQ(1u, nodes.size()); | 588 ASSERT_EQ(1u, views.size()); |
| 581 EXPECT_EQ("node=1,1 parent=null", nodes[0].ToString()); | 589 EXPECT_EQ("view=1,1 parent=null", views[0].ToString()); |
| 582 } | 590 } |
| 583 { | 591 { |
| 584 std::vector<TestNode> nodes; | 592 std::vector<TestView> views; |
| 585 connection2_->GetNodeTree(BuildNodeId(1, 2), &nodes); | 593 connection2_->GetViewTree(BuildViewId(1, 2), &views); |
| 586 EXPECT_TRUE(nodes.empty()); | 594 EXPECT_TRUE(views.empty()); |
| 587 } | 595 } |
| 588 | 596 |
| 589 // Nodes 3 and 4 in connection 2. | 597 // Views 3 and 4 in connection 2. |
| 590 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 3))); | 598 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 3))); |
| 591 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 4))); | 599 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 4))); |
| 592 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(2, 3), BuildNodeId(2, 4))); | 600 ASSERT_TRUE(connection2_->AddView(BuildViewId(2, 3), BuildViewId(2, 4))); |
| 593 | 601 |
| 594 // Connection 3 rooted at 2. | 602 // Connection 3 rooted at 2. |
| 595 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(connection2_, | 603 ASSERT_NO_FATAL_FAILURE( |
| 596 BuildNodeId(2, 3))); | 604 EstablishThirdConnection(connection2_, BuildViewId(2, 3))); |
| 597 | 605 |
| 598 // Node 4 should no longer have a parent. | 606 // View 4 should no longer have a parent. |
| 599 { | 607 { |
| 600 std::vector<TestNode> nodes; | 608 std::vector<TestView> views; |
| 601 connection2_->GetNodeTree(BuildNodeId(2, 3), &nodes); | 609 connection2_->GetViewTree(BuildViewId(2, 3), &views); |
| 602 ASSERT_EQ(1u, nodes.size()); | 610 ASSERT_EQ(1u, views.size()); |
| 603 EXPECT_EQ("node=2,3 parent=null", nodes[0].ToString()); | 611 EXPECT_EQ("view=2,3 parent=null", views[0].ToString()); |
| 604 | 612 |
| 605 nodes.clear(); | 613 views.clear(); |
| 606 connection2_->GetNodeTree(BuildNodeId(2, 4), &nodes); | 614 connection2_->GetViewTree(BuildViewId(2, 4), &views); |
| 607 ASSERT_EQ(1u, nodes.size()); | 615 ASSERT_EQ(1u, views.size()); |
| 608 EXPECT_EQ("node=2,4 parent=null", nodes[0].ToString()); | 616 EXPECT_EQ("view=2,4 parent=null", views[0].ToString()); |
| 609 } | 617 } |
| 610 | 618 |
| 611 // And node 4 should not be visible to connection 3. | 619 // And view 4 should not be visible to connection 3. |
| 612 { | 620 { |
| 613 std::vector<TestNode> nodes; | 621 std::vector<TestView> views; |
| 614 connection3_->GetNodeTree(BuildNodeId(2, 3), &nodes); | 622 connection3_->GetViewTree(BuildViewId(2, 3), &views); |
| 615 ASSERT_EQ(1u, nodes.size()); | 623 ASSERT_EQ(1u, views.size()); |
| 616 EXPECT_EQ("node=2,3 parent=null", nodes[0].ToString()); | 624 EXPECT_EQ("view=2,3 parent=null", views[0].ToString()); |
| 617 } | 625 } |
| 618 } | 626 } |
| 619 | 627 |
| 620 // Verifies once Embed() has been invoked the parent connection can't see any | 628 // Verifies once Embed() has been invoked the parent connection can't see any |
| 621 // children. | 629 // children. |
| 622 TEST_F(ViewManagerTest, CantAccessChildrenOfEmbeddedNode) { | 630 TEST_F(ViewManagerTest, CantAccessChildrenOfEmbeddedView) { |
| 623 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 631 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 624 | 632 |
| 625 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); | 633 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2))); |
| 626 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2))); | 634 ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 2))); |
| 627 | 635 |
| 628 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(connection2_, | 636 ASSERT_NO_FATAL_FAILURE( |
| 629 BuildNodeId(2, 2))); | 637 EstablishThirdConnection(connection2_, BuildViewId(2, 2))); |
| 630 | 638 |
| 631 ASSERT_TRUE(connection3_->CreateNode(BuildNodeId(3, 3))); | 639 ASSERT_TRUE(connection3_->CreateView(BuildViewId(3, 3))); |
| 632 ASSERT_TRUE(connection3_->AddNode(BuildNodeId(2, 2), BuildNodeId(3, 3))); | 640 ASSERT_TRUE(connection3_->AddView(BuildViewId(2, 2), BuildViewId(3, 3))); |
| 633 | 641 |
| 634 // Even though 3 is a child of 2 connection 2 can't see 3 as it's from a | 642 // Even though 3 is a child of 2 connection 2 can't see 3 as it's from a |
| 635 // different connection. | 643 // different connection. |
| 636 { | 644 { |
| 637 std::vector<TestNode> nodes; | 645 std::vector<TestView> views; |
| 638 connection2_->GetNodeTree(BuildNodeId(2, 2), &nodes); | 646 connection2_->GetViewTree(BuildViewId(2, 2), &views); |
| 639 ASSERT_EQ(1u, nodes.size()); | 647 ASSERT_EQ(1u, views.size()); |
| 640 EXPECT_EQ("node=2,2 parent=1,1", nodes[0].ToString()); | 648 EXPECT_EQ("view=2,2 parent=1,1", views[0].ToString()); |
| 641 } | 649 } |
| 642 | 650 |
| 643 { | 651 { |
| 644 std::vector<TestNode> nodes; | 652 std::vector<TestView> views; |
| 645 connection2_->GetNodeTree(BuildNodeId(3, 3), &nodes); | 653 connection2_->GetViewTree(BuildViewId(3, 3), &views); |
| 646 EXPECT_TRUE(nodes.empty()); | 654 EXPECT_TRUE(views.empty()); |
| 647 } | 655 } |
| 648 | 656 |
| 649 // Connection 2 shouldn't be able to get node 3 at all. | 657 // Connection 2 shouldn't be able to get view 3 at all. |
| 650 { | 658 { |
| 651 std::vector<TestNode> nodes; | 659 std::vector<TestView> views; |
| 652 connection2_->GetNodeTree(BuildNodeId(3, 3), &nodes); | 660 connection2_->GetViewTree(BuildViewId(3, 3), &views); |
| 653 EXPECT_TRUE(nodes.empty()); | 661 EXPECT_TRUE(views.empty()); |
| 654 } | 662 } |
| 655 | 663 |
| 656 // Connection 1 should be able to see it all (its the root). | 664 // Connection 1 should be able to see it all (its the root). |
| 657 { | 665 { |
| 658 std::vector<TestNode> nodes; | 666 std::vector<TestView> views; |
| 659 connection_->GetNodeTree(BuildNodeId(1, 1), &nodes); | 667 connection_->GetViewTree(BuildViewId(1, 1), &views); |
| 660 ASSERT_EQ(3u, nodes.size()); | 668 ASSERT_EQ(3u, views.size()); |
| 661 EXPECT_EQ("node=1,1 parent=null", nodes[0].ToString()); | 669 EXPECT_EQ("view=1,1 parent=null", views[0].ToString()); |
| 662 EXPECT_EQ("node=2,2 parent=1,1", nodes[1].ToString()); | 670 EXPECT_EQ("view=2,2 parent=1,1", views[1].ToString()); |
| 663 EXPECT_EQ("node=3,3 parent=2,2", nodes[2].ToString()); | 671 EXPECT_EQ("view=3,3 parent=2,2", views[2].ToString()); |
| 664 } | 672 } |
| 665 } | 673 } |
| 666 | 674 |
| 667 // Verifies once Embed() has been invoked the parent can't mutate the children. | 675 // Verifies once Embed() has been invoked the parent can't mutate the children. |
| 668 TEST_F(ViewManagerTest, CantModifyChildrenOfEmbeddedNode) { | 676 TEST_F(ViewManagerTest, CantModifyChildrenOfEmbeddedView) { |
| 669 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 677 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 670 | 678 |
| 671 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); | 679 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2))); |
| 672 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2))); | 680 ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 2))); |
| 673 | 681 |
| 674 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(connection2_, | 682 ASSERT_NO_FATAL_FAILURE( |
| 675 BuildNodeId(2, 2))); | 683 EstablishThirdConnection(connection2_, BuildViewId(2, 2))); |
| 676 | 684 |
| 677 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 3))); | 685 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 3))); |
| 678 // Connection 2 shouldn't be able to add anything to the node anymore. | 686 // Connection 2 shouldn't be able to add anything to the view anymore. |
| 679 ASSERT_FALSE(connection2_->AddNode(BuildNodeId(2, 2), BuildNodeId(2, 3))); | 687 ASSERT_FALSE(connection2_->AddView(BuildViewId(2, 2), BuildViewId(2, 3))); |
| 680 | 688 |
| 681 // Create node 3 in connection 3 and add it to node 3. | 689 // Create view 3 in connection 3 and add it to view 3. |
| 682 ASSERT_TRUE(connection3_->CreateNode(BuildNodeId(3, 3))); | 690 ASSERT_TRUE(connection3_->CreateView(BuildViewId(3, 3))); |
| 683 ASSERT_TRUE(connection3_->AddNode(BuildNodeId(2, 2), BuildNodeId(3, 3))); | 691 ASSERT_TRUE(connection3_->AddView(BuildViewId(2, 2), BuildViewId(3, 3))); |
| 684 | 692 |
| 685 // Connection 2 shouldn't be able to remove node 3. | 693 // Connection 2 shouldn't be able to remove view 3. |
| 686 ASSERT_FALSE(connection2_->RemoveNodeFromParent(BuildNodeId(3, 3))); | 694 ASSERT_FALSE(connection2_->RemoveViewFromParent(BuildViewId(3, 3))); |
| 687 } | 695 } |
| 688 | 696 |
| 689 // Verifies client gets a valid id. | 697 // Verifies client gets a valid id. |
| 690 TEST_F(ViewManagerTest, CreateNode) { | 698 TEST_F(ViewManagerTest, CreateView) { |
| 691 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 699 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
| 692 EXPECT_TRUE(connection_->changes().empty()); | 700 EXPECT_TRUE(connection_->changes().empty()); |
| 693 | 701 |
| 694 // Can't create a node with the same id. | 702 // Can't create a view with the same id. |
| 695 ASSERT_EQ(ERROR_CODE_VALUE_IN_USE, | 703 ASSERT_EQ(ERROR_CODE_VALUE_IN_USE, |
| 696 connection_->CreateNodeWithErrorCode(BuildNodeId(1, 1))); | 704 connection_->CreateViewWithErrorCode(BuildViewId(1, 1))); |
| 697 EXPECT_TRUE(connection_->changes().empty()); | 705 EXPECT_TRUE(connection_->changes().empty()); |
| 698 | 706 |
| 699 // Can't create a node with a bogus connection id. | 707 // Can't create a view with a bogus connection id. |
| 700 EXPECT_EQ(ERROR_CODE_ILLEGAL_ARGUMENT, | 708 EXPECT_EQ(ERROR_CODE_ILLEGAL_ARGUMENT, |
| 701 connection_->CreateNodeWithErrorCode(BuildNodeId(2, 1))); | 709 connection_->CreateViewWithErrorCode(BuildViewId(2, 1))); |
| 702 EXPECT_TRUE(connection_->changes().empty()); | 710 EXPECT_TRUE(connection_->changes().empty()); |
| 703 } | 711 } |
| 704 | 712 |
| 705 // Verifies AddNode fails when node is already in position. | 713 // Verifies AddView fails when view is already in position. |
| 706 TEST_F(ViewManagerTest, AddNodeWithNoChange) { | 714 TEST_F(ViewManagerTest, AddViewWithNoChange) { |
| 707 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 715 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2))); |
| 708 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 716 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 3))); |
| 709 | 717 |
| 710 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 718 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 711 | 719 |
| 712 // Make 3 a child of 2. | 720 // Make 3 a child of 2. |
| 713 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3))); | 721 ASSERT_TRUE(connection_->AddView(BuildViewId(1, 2), BuildViewId(1, 3))); |
| 714 | 722 |
| 715 // Try again, this should fail. | 723 // Try again, this should fail. |
| 716 EXPECT_FALSE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3))); | 724 EXPECT_FALSE(connection_->AddView(BuildViewId(1, 2), BuildViewId(1, 3))); |
| 717 } | 725 } |
| 718 | 726 |
| 719 // Verifies AddNode fails when node is already in position. | 727 // Verifies AddView fails when view is already in position. |
| 720 TEST_F(ViewManagerTest, AddAncestorFails) { | 728 TEST_F(ViewManagerTest, AddAncestorFails) { |
| 721 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 729 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2))); |
| 722 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 730 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 3))); |
| 723 | 731 |
| 724 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 732 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 725 | 733 |
| 726 // Make 3 a child of 2. | 734 // Make 3 a child of 2. |
| 727 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3))); | 735 ASSERT_TRUE(connection_->AddView(BuildViewId(1, 2), BuildViewId(1, 3))); |
| 728 | 736 |
| 729 // Try to make 2 a child of 3, this should fail since 2 is an ancestor of 3. | 737 // Try to make 2 a child of 3, this should fail since 2 is an ancestor of 3. |
| 730 EXPECT_FALSE(connection_->AddNode(BuildNodeId(1, 3), BuildNodeId(1, 2))); | 738 EXPECT_FALSE(connection_->AddView(BuildViewId(1, 3), BuildViewId(1, 2))); |
| 731 } | 739 } |
| 732 | 740 |
| 733 // Verifies adding to root sends right notifications. | 741 // Verifies adding to root sends right notifications. |
| 734 TEST_F(ViewManagerTest, AddToRoot) { | 742 TEST_F(ViewManagerTest, AddToRoot) { |
| 735 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 21))); | 743 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 21))); |
| 736 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 744 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 3))); |
| 737 | 745 |
| 738 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 746 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 739 | 747 |
| 740 // Make 3 a child of 21. | 748 // Make 3 a child of 21. |
| 741 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 21), BuildNodeId(1, 3))); | 749 ASSERT_TRUE(connection_->AddView(BuildViewId(1, 21), BuildViewId(1, 3))); |
| 742 | 750 |
| 743 // Make 21 a child of 1. | 751 // Make 21 a child of 1. |
| 744 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 21))); | 752 ASSERT_TRUE(connection_->AddView(BuildViewId(1, 1), BuildViewId(1, 21))); |
| 745 | 753 |
| 746 // Connection 2 should not be told anything (because the node is from a | 754 // Connection 2 should not be told anything (because the view is from a |
| 747 // different connection). Create a node to ensure we got a response from | 755 // different connection). Create a view to ensure we got a response from |
| 748 // the server. | 756 // the server. |
| 749 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 100))); | 757 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 100))); |
| 750 connection2_->CopyChangesFromTracker(); | 758 connection2_->CopyChangesFromTracker(); |
| 751 EXPECT_TRUE(connection2_->changes().empty()); | 759 EXPECT_TRUE(connection2_->changes().empty()); |
| 752 } | 760 } |
| 753 | 761 |
| 754 // Verifies HierarchyChanged is correctly sent for various adds/removes. | 762 // Verifies HierarchyChanged is correctly sent for various adds/removes. |
| 755 TEST_F(ViewManagerTest, NodeHierarchyChangedNodes) { | 763 TEST_F(ViewManagerTest, ViewHierarchyChangedViews) { |
| 756 // 1,2->1,11. | 764 // 1,2->1,11. |
| 757 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 765 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2))); |
| 758 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); | 766 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11))); |
| 759 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 11))); | 767 ASSERT_TRUE(connection_->AddView(BuildViewId(1, 2), BuildViewId(1, 11))); |
| 760 | 768 |
| 761 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 769 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 762 | 770 |
| 763 // 1,1->1,2->1,11 | 771 // 1,1->1,2->1,11 |
| 764 { | 772 { |
| 765 // Client 2 should not get anything (1,2 is from another connection). | 773 // Client 2 should not get anything (1,2 is from another connection). |
| 766 connection2_->ClearChanges(); | 774 connection2_->ClearChanges(); |
| 767 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); | 775 ASSERT_TRUE(connection_->AddView(BuildViewId(1, 1), BuildViewId(1, 2))); |
| 768 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 100))); | 776 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 100))); |
| 769 connection2_->CopyChangesFromTracker(); | 777 connection2_->CopyChangesFromTracker(); |
| 770 EXPECT_TRUE(connection2_->changes().empty()); | 778 EXPECT_TRUE(connection2_->changes().empty()); |
| 771 } | 779 } |
| 772 | 780 |
| 773 // 0,1->1,1->1,2->1,11. | 781 // 0,1->1,1->1,2->1,11. |
| 774 { | 782 { |
| 775 // Again, client 2 should not get anything. | 783 // Again, client 2 should not get anything. |
| 776 connection2_->ClearChanges(); | 784 connection2_->ClearChanges(); |
| 777 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); | 785 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1))); |
| 778 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 101))); | 786 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 101))); |
| 779 connection2_->CopyChangesFromTracker(); | 787 connection2_->CopyChangesFromTracker(); |
| 780 EXPECT_TRUE(connection2_->changes().empty()); | 788 EXPECT_TRUE(connection2_->changes().empty()); |
| 781 } | 789 } |
| 782 | 790 |
| 783 // 1,1->1,2->1,11. | 791 // 1,1->1,2->1,11. |
| 784 { | 792 { |
| 785 connection2_->ClearChanges(); | 793 connection2_->ClearChanges(); |
| 786 ASSERT_TRUE(connection_->RemoveNodeFromParent(BuildNodeId(1, 1))); | 794 ASSERT_TRUE(connection_->RemoveViewFromParent(BuildViewId(1, 1))); |
| 787 EXPECT_TRUE(connection_->changes().empty()); | 795 EXPECT_TRUE(connection_->changes().empty()); |
| 788 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 102))); | 796 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 102))); |
| 789 connection2_->CopyChangesFromTracker(); | 797 connection2_->CopyChangesFromTracker(); |
| 790 EXPECT_TRUE(connection2_->changes().empty()); | 798 EXPECT_TRUE(connection2_->changes().empty()); |
| 791 } | 799 } |
| 792 | 800 |
| 793 // 1,1->1,2->1,11->1,111. | 801 // 1,1->1,2->1,11->1,111. |
| 794 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 111))); | 802 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 111))); |
| 795 { | 803 { |
| 796 connection2_->ClearChanges(); | 804 connection2_->ClearChanges(); |
| 797 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 11), BuildNodeId(1, 111))); | 805 ASSERT_TRUE(connection_->AddView(BuildViewId(1, 11), BuildViewId(1, 111))); |
| 798 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 103))); | 806 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 103))); |
| 799 connection2_->CopyChangesFromTracker(); | 807 connection2_->CopyChangesFromTracker(); |
| 800 EXPECT_TRUE(connection2_->changes().empty()); | 808 EXPECT_TRUE(connection2_->changes().empty()); |
| 801 } | 809 } |
| 802 | 810 |
| 803 // 0,1->1,1->1,2->1,11->1,111 | 811 // 0,1->1,1->1,2->1,11->1,111 |
| 804 { | 812 { |
| 805 connection2_->ClearChanges(); | 813 connection2_->ClearChanges(); |
| 806 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); | 814 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1))); |
| 807 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 104))); | 815 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 104))); |
| 808 connection2_->CopyChangesFromTracker(); | 816 connection2_->CopyChangesFromTracker(); |
| 809 EXPECT_TRUE(connection2_->changes().empty()); | 817 EXPECT_TRUE(connection2_->changes().empty()); |
| 810 } | 818 } |
| 811 } | 819 } |
| 812 | 820 |
| 813 TEST_F(ViewManagerTest, NodeHierarchyChangedAddingKnownToUnknown) { | 821 TEST_F(ViewManagerTest, ViewHierarchyChangedAddingKnownToUnknown) { |
| 814 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no | 822 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no |
| 815 // parent). | 823 // parent). |
| 816 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 824 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 817 | 825 |
| 818 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 11))); | 826 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 11))); |
| 819 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); | 827 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2))); |
| 820 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 21))); | 828 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 21))); |
| 821 | 829 |
| 822 // Set up the hierarchy. | 830 // Set up the hierarchy. |
| 823 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); | 831 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1))); |
| 824 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 11))); | 832 ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 11))); |
| 825 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(2, 2), BuildNodeId(2, 21))); | 833 ASSERT_TRUE(connection2_->AddView(BuildViewId(2, 2), BuildViewId(2, 21))); |
| 826 | 834 |
| 827 // Remove 11, should result in a hierarchy change for the root. | 835 // Remove 11, should result in a hierarchy change for the root. |
| 828 { | 836 { |
| 829 connection_->ClearChanges(); | 837 connection_->ClearChanges(); |
| 830 ASSERT_TRUE(connection2_->RemoveNodeFromParent(BuildNodeId(2, 11))); | 838 ASSERT_TRUE(connection2_->RemoveViewFromParent(BuildViewId(2, 11))); |
| 831 | 839 |
| 832 connection_->DoRunLoopUntilChangesCount(1); | 840 connection_->DoRunLoopUntilChangesCount(1); |
| 833 const Changes changes(ChangesToDescription1(connection_->changes())); | 841 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 834 ASSERT_EQ(1u, changes.size()); | 842 ASSERT_EQ(1u, changes.size()); |
| 835 EXPECT_EQ("HierarchyChanged node=2,11 new_parent=null old_parent=1,1", | 843 EXPECT_EQ("HierarchyChanged view=2,11 new_parent=null old_parent=1,1", |
| 836 changes[0]); | 844 changes[0]); |
| 837 } | 845 } |
| 838 | 846 |
| 839 // Add 2 to 1. | 847 // Add 2 to 1. |
| 840 { | 848 { |
| 841 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2))); | 849 ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 2))); |
| 842 | 850 |
| 843 connection_->DoRunLoopUntilChangesCount(1); | 851 connection_->DoRunLoopUntilChangesCount(1); |
| 844 const Changes changes(ChangesToDescription1(connection_->changes())); | 852 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 845 ASSERT_EQ(1u, changes.size()); | 853 ASSERT_EQ(1u, changes.size()); |
| 846 EXPECT_EQ("HierarchyChanged node=2,2 new_parent=1,1 old_parent=null", | 854 EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null", |
| 847 changes[0]); | 855 changes[0]); |
| 848 EXPECT_EQ("[node=2,2 parent=1,1]," | 856 EXPECT_EQ( |
| 849 "[node=2,21 parent=2,2]", | 857 "[view=2,2 parent=1,1]," |
| 850 ChangeNodeDescription(connection_->changes())); | 858 "[view=2,21 parent=2,2]", |
| 851 } | 859 ChangeViewDescription(connection_->changes())); |
| 852 } | 860 } |
| 853 | 861 } |
| 854 TEST_F(ViewManagerTest, ReorderNode) { | 862 |
| 855 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 863 TEST_F(ViewManagerTest, ReorderView) { |
| 856 | 864 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 857 Id node1_id = BuildNodeId(2, 1); | 865 |
| 858 Id node2_id = BuildNodeId(2, 2); | 866 Id view1_id = BuildViewId(2, 1); |
| 859 Id node3_id = BuildNodeId(2, 3); | 867 Id view2_id = BuildViewId(2, 2); |
| 860 Id node4_id = BuildNodeId(1, 4); // Peer to 1,1 | 868 Id view3_id = BuildViewId(2, 3); |
| 861 Id node5_id = BuildNodeId(1, 5); // Peer to 1,1 | 869 Id view4_id = BuildViewId(1, 4); // Peer to 1,1 |
| 862 Id node6_id = BuildNodeId(2, 6); // Child of 1,2. | 870 Id view5_id = BuildViewId(1, 5); // Peer to 1,1 |
| 863 Id node7_id = BuildNodeId(2, 7); // Unparented. | 871 Id view6_id = BuildViewId(2, 6); // Child of 1,2. |
| 864 Id node8_id = BuildNodeId(2, 8); // Unparented. | 872 Id view7_id = BuildViewId(2, 7); // Unparented. |
| 865 ASSERT_TRUE(connection2_->CreateNode(node1_id)); | 873 Id view8_id = BuildViewId(2, 8); // Unparented. |
| 866 ASSERT_TRUE(connection2_->CreateNode(node2_id)); | 874 ASSERT_TRUE(connection2_->CreateView(view1_id)); |
| 867 ASSERT_TRUE(connection2_->CreateNode(node3_id)); | 875 ASSERT_TRUE(connection2_->CreateView(view2_id)); |
| 868 ASSERT_TRUE(connection_->CreateNode(node4_id)); | 876 ASSERT_TRUE(connection2_->CreateView(view3_id)); |
| 869 ASSERT_TRUE(connection_->CreateNode(node5_id)); | 877 ASSERT_TRUE(connection_->CreateView(view4_id)); |
| 870 ASSERT_TRUE(connection2_->CreateNode(node6_id)); | 878 ASSERT_TRUE(connection_->CreateView(view5_id)); |
| 871 ASSERT_TRUE(connection2_->CreateNode(node7_id)); | 879 ASSERT_TRUE(connection2_->CreateView(view6_id)); |
| 872 ASSERT_TRUE(connection2_->CreateNode(node8_id)); | 880 ASSERT_TRUE(connection2_->CreateView(view7_id)); |
| 873 ASSERT_TRUE(connection2_->AddNode(node1_id, node2_id)); | 881 ASSERT_TRUE(connection2_->CreateView(view8_id)); |
| 874 ASSERT_TRUE(connection2_->AddNode(node2_id, node6_id)); | 882 ASSERT_TRUE(connection2_->AddView(view1_id, view2_id)); |
| 875 ASSERT_TRUE(connection2_->AddNode(node1_id, node3_id)); | 883 ASSERT_TRUE(connection2_->AddView(view2_id, view6_id)); |
| 876 ASSERT_TRUE(connection_->AddNode( | 884 ASSERT_TRUE(connection2_->AddView(view1_id, view3_id)); |
| 877 NodeIdToTransportId(RootNodeId()), node4_id)); | 885 ASSERT_TRUE( |
| 878 ASSERT_TRUE(connection_->AddNode( | 886 connection_->AddView(ViewIdToTransportId(RootViewId()), view4_id)); |
| 879 NodeIdToTransportId(RootNodeId()), node5_id)); | 887 ASSERT_TRUE( |
| 880 | 888 connection_->AddView(ViewIdToTransportId(RootViewId()), view5_id)); |
| 881 ASSERT_TRUE(connection_->AddNode( | 889 |
| 882 NodeIdToTransportId(RootNodeId()), node1_id)); | 890 ASSERT_TRUE( |
| 891 connection_->AddView(ViewIdToTransportId(RootViewId()), view1_id)); |
| 883 | 892 |
| 884 { | 893 { |
| 885 ASSERT_TRUE( | 894 ASSERT_TRUE( |
| 886 connection2_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_ABOVE)); | 895 connection2_->ReorderView(view2_id, view3_id, ORDER_DIRECTION_ABOVE)); |
| 887 | 896 |
| 888 connection_->DoRunLoopUntilChangesCount(1); | 897 connection_->DoRunLoopUntilChangesCount(1); |
| 889 const Changes changes(ChangesToDescription1(connection_->changes())); | 898 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 890 ASSERT_EQ(1u, changes.size()); | 899 ASSERT_EQ(1u, changes.size()); |
| 891 EXPECT_EQ("Reordered node=2,2 relative=2,3 direction=above", | 900 EXPECT_EQ("Reordered view=2,2 relative=2,3 direction=above", changes[0]); |
| 892 changes[0]); | 901 } |
| 893 } | 902 |
| 894 | 903 { |
| 895 { | 904 ASSERT_TRUE( |
| 896 ASSERT_TRUE(connection2_->ReorderNode( | 905 connection2_->ReorderView(view2_id, view3_id, ORDER_DIRECTION_BELOW)); |
| 897 node2_id, node3_id, ORDER_DIRECTION_BELOW)); | 906 |
| 898 | 907 connection_->DoRunLoopUntilChangesCount(1); |
| 899 connection_->DoRunLoopUntilChangesCount(1); | 908 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 900 const Changes changes(ChangesToDescription1(connection_->changes())); | 909 ASSERT_EQ(1u, changes.size()); |
| 901 ASSERT_EQ(1u, changes.size()); | 910 EXPECT_EQ("Reordered view=2,2 relative=2,3 direction=below", changes[0]); |
| 902 EXPECT_EQ("Reordered node=2,2 relative=2,3 direction=below", | 911 } |
| 903 changes[0]); | 912 |
| 904 } | 913 // view2 is already below view3. |
| 905 | |
| 906 // node2 is already below node3. | |
| 907 EXPECT_FALSE( | 914 EXPECT_FALSE( |
| 908 connection2_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_BELOW)); | 915 connection2_->ReorderView(view2_id, view3_id, ORDER_DIRECTION_BELOW)); |
| 909 | 916 |
| 910 // node4 & 5 are unknown to connection2_. | 917 // view4 & 5 are unknown to connection2_. |
| 911 EXPECT_FALSE(connection2_->ReorderNode( | |
| 912 node4_id, node5_id, ORDER_DIRECTION_ABOVE)); | |
| 913 | |
| 914 // node6 & node3 have different parents. | |
| 915 EXPECT_FALSE( | 918 EXPECT_FALSE( |
| 916 connection_->ReorderNode(node3_id, node6_id, ORDER_DIRECTION_ABOVE)); | 919 connection2_->ReorderView(view4_id, view5_id, ORDER_DIRECTION_ABOVE)); |
| 917 | 920 |
| 918 // Non-existent node-ids | 921 // view6 & view3 have different parents. |
| 919 EXPECT_FALSE(connection_->ReorderNode( | |
| 920 BuildNodeId(1, 27), BuildNodeId(1, 28), ORDER_DIRECTION_ABOVE)); | |
| 921 | |
| 922 // node7 & node8 are un-parented. | |
| 923 EXPECT_FALSE( | 922 EXPECT_FALSE( |
| 924 connection_->ReorderNode(node7_id, node8_id, ORDER_DIRECTION_ABOVE)); | 923 connection_->ReorderView(view3_id, view6_id, ORDER_DIRECTION_ABOVE)); |
| 925 } | 924 |
| 926 | 925 // Non-existent view-ids |
| 927 // Verifies DeleteNode works. | 926 EXPECT_FALSE(connection_->ReorderView( |
| 928 TEST_F(ViewManagerTest, DeleteNode) { | 927 BuildViewId(1, 27), BuildViewId(1, 28), ORDER_DIRECTION_ABOVE)); |
| 929 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 928 |
| 930 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); | 929 // view7 & view8 are un-parented. |
| 930 EXPECT_FALSE( |
| 931 connection_->ReorderView(view7_id, view8_id, ORDER_DIRECTION_ABOVE)); |
| 932 } |
| 933 |
| 934 // Verifies DeleteView works. |
| 935 TEST_F(ViewManagerTest, DeleteView) { |
| 936 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 937 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2))); |
| 931 | 938 |
| 932 // Make 2 a child of 1. | 939 // Make 2 a child of 1. |
| 933 { | 940 { |
| 934 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2))); | 941 ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 2))); |
| 935 connection_->DoRunLoopUntilChangesCount(1); | 942 connection_->DoRunLoopUntilChangesCount(1); |
| 936 const Changes changes(ChangesToDescription1(connection_->changes())); | 943 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 937 ASSERT_EQ(1u, changes.size()); | 944 ASSERT_EQ(1u, changes.size()); |
| 938 EXPECT_EQ("HierarchyChanged node=2,2 new_parent=1,1 old_parent=null", | 945 EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null", |
| 939 changes[0]); | 946 changes[0]); |
| 940 } | 947 } |
| 941 | 948 |
| 942 // Delete 2. | 949 // Delete 2. |
| 943 { | 950 { |
| 944 ASSERT_TRUE(connection2_->DeleteNode(BuildNodeId(2, 2))); | 951 ASSERT_TRUE(connection2_->DeleteView(BuildViewId(2, 2))); |
| 945 EXPECT_TRUE(connection2_->changes().empty()); | 952 EXPECT_TRUE(connection2_->changes().empty()); |
| 946 | 953 |
| 947 connection_->DoRunLoopUntilChangesCount(1); | 954 connection_->DoRunLoopUntilChangesCount(1); |
| 948 const Changes changes(ChangesToDescription1(connection_->changes())); | 955 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 949 ASSERT_EQ(1u, changes.size()); | 956 ASSERT_EQ(1u, changes.size()); |
| 950 EXPECT_EQ("NodeDeleted node=2,2", changes[0]); | 957 EXPECT_EQ("ViewDeleted view=2,2", changes[0]); |
| 951 } | 958 } |
| 952 } | 959 } |
| 953 | 960 |
| 954 // Verifies DeleteNode isn't allowed from a separate connection. | 961 // Verifies DeleteView isn't allowed from a separate connection. |
| 955 TEST_F(ViewManagerTest, DeleteNodeFromAnotherConnectionDisallowed) { | 962 TEST_F(ViewManagerTest, DeleteViewFromAnotherConnectionDisallowed) { |
| 956 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 963 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 957 EXPECT_FALSE(connection2_->DeleteNode(BuildNodeId(1, 1))); | 964 EXPECT_FALSE(connection2_->DeleteView(BuildViewId(1, 1))); |
| 958 } | 965 } |
| 959 | 966 |
| 960 // Verifies if a node was deleted and then reused that other clients are | 967 // Verifies if a view was deleted and then reused that other clients are |
| 961 // properly notified. | 968 // properly notified. |
| 962 TEST_F(ViewManagerTest, ReuseDeletedNodeId) { | 969 TEST_F(ViewManagerTest, ReuseDeletedViewId) { |
| 963 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 970 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 964 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); | 971 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2))); |
| 965 | 972 |
| 966 // Add 2 to 1. | 973 // Add 2 to 1. |
| 967 { | 974 { |
| 968 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2))); | 975 ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 2))); |
| 969 | 976 |
| 970 connection_->DoRunLoopUntilChangesCount(1); | 977 connection_->DoRunLoopUntilChangesCount(1); |
| 971 const Changes changes(ChangesToDescription1(connection_->changes())); | 978 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 972 EXPECT_EQ("HierarchyChanged node=2,2 new_parent=1,1 old_parent=null", | 979 EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null", |
| 973 changes[0]); | 980 changes[0]); |
| 974 EXPECT_EQ("[node=2,2 parent=1,1]", | 981 EXPECT_EQ("[view=2,2 parent=1,1]", |
| 975 ChangeNodeDescription(connection_->changes())); | 982 ChangeViewDescription(connection_->changes())); |
| 976 } | 983 } |
| 977 | 984 |
| 978 // Delete 2. | 985 // Delete 2. |
| 979 { | 986 { |
| 980 ASSERT_TRUE(connection2_->DeleteNode(BuildNodeId(2, 2))); | 987 ASSERT_TRUE(connection2_->DeleteView(BuildViewId(2, 2))); |
| 981 | 988 |
| 982 connection_->DoRunLoopUntilChangesCount(1); | 989 connection_->DoRunLoopUntilChangesCount(1); |
| 983 const Changes changes(ChangesToDescription1(connection_->changes())); | 990 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 984 ASSERT_EQ(1u, changes.size()); | 991 ASSERT_EQ(1u, changes.size()); |
| 985 EXPECT_EQ("NodeDeleted node=2,2", changes[0]); | 992 EXPECT_EQ("ViewDeleted view=2,2", changes[0]); |
| 986 } | 993 } |
| 987 | 994 |
| 988 // Create 2 again, and add it back to 1. Should get the same notification. | 995 // Create 2 again, and add it back to 1. Should get the same notification. |
| 989 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); | 996 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2))); |
| 990 { | 997 { |
| 991 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2))); | 998 ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 2))); |
| 992 | 999 |
| 993 connection_->DoRunLoopUntilChangesCount(1); | 1000 connection_->DoRunLoopUntilChangesCount(1); |
| 994 const Changes changes(ChangesToDescription1(connection_->changes())); | 1001 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 995 EXPECT_EQ("HierarchyChanged node=2,2 new_parent=1,1 old_parent=null", | 1002 EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null", |
| 996 changes[0]); | 1003 changes[0]); |
| 997 EXPECT_EQ("[node=2,2 parent=1,1]", | 1004 EXPECT_EQ("[view=2,2 parent=1,1]", |
| 998 ChangeNodeDescription(connection_->changes())); | 1005 ChangeViewDescription(connection_->changes())); |
| 999 } | 1006 } |
| 1000 } | 1007 } |
| 1001 | 1008 |
| 1002 // Assertions for GetNodeTree. | 1009 // Assertions for GetViewTree. |
| 1003 TEST_F(ViewManagerTest, GetNodeTree) { | 1010 TEST_F(ViewManagerTest, GetViewTree) { |
| 1004 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1011 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1005 | 1012 |
| 1006 // Create 11 in first connection and make it a child of 1. | 1013 // Create 11 in first connection and make it a child of 1. |
| 1007 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); | 1014 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11))); |
| 1008 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); | 1015 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1))); |
| 1009 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 11))); | 1016 ASSERT_TRUE(connection_->AddView(BuildViewId(1, 1), BuildViewId(1, 11))); |
| 1010 | 1017 |
| 1011 // Create two nodes in second connection, 2 and 3, both children of 1. | 1018 // Create two views in second connection, 2 and 3, both children of 1. |
| 1012 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); | 1019 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2))); |
| 1013 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 3))); | 1020 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 3))); |
| 1014 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2))); | 1021 ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 2))); |
| 1015 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 3))); | 1022 ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 3))); |
| 1016 | 1023 |
| 1017 // Verifies GetNodeTree() on the root. The root connection sees all. | 1024 // Verifies GetViewTree() on the root. The root connection sees all. |
| 1018 { | 1025 { |
| 1019 std::vector<TestNode> nodes; | 1026 std::vector<TestView> views; |
| 1020 connection_->GetNodeTree(BuildNodeId(0, 1), &nodes); | 1027 connection_->GetViewTree(BuildViewId(0, 1), &views); |
| 1021 ASSERT_EQ(5u, nodes.size()); | 1028 ASSERT_EQ(5u, views.size()); |
| 1022 EXPECT_EQ("node=0,1 parent=null", nodes[0].ToString()); | 1029 EXPECT_EQ("view=0,1 parent=null", views[0].ToString()); |
| 1023 EXPECT_EQ("node=1,1 parent=0,1", nodes[1].ToString()); | 1030 EXPECT_EQ("view=1,1 parent=0,1", views[1].ToString()); |
| 1024 EXPECT_EQ("node=1,11 parent=1,1", nodes[2].ToString()); | 1031 EXPECT_EQ("view=1,11 parent=1,1", views[2].ToString()); |
| 1025 EXPECT_EQ("node=2,2 parent=1,1", nodes[3].ToString()); | 1032 EXPECT_EQ("view=2,2 parent=1,1", views[3].ToString()); |
| 1026 EXPECT_EQ("node=2,3 parent=1,1", nodes[4].ToString()); | 1033 EXPECT_EQ("view=2,3 parent=1,1", views[4].ToString()); |
| 1027 } | 1034 } |
| 1028 | 1035 |
| 1029 // Verifies GetNodeTree() on the node 1,1. This does not include any children | 1036 // Verifies GetViewTree() on the view 1,1. This does not include any children |
| 1030 // as they are not from this connection. | 1037 // as they are not from this connection. |
| 1031 { | 1038 { |
| 1032 std::vector<TestNode> nodes; | 1039 std::vector<TestView> views; |
| 1033 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); | 1040 connection2_->GetViewTree(BuildViewId(1, 1), &views); |
| 1034 ASSERT_EQ(1u, nodes.size()); | 1041 ASSERT_EQ(1u, views.size()); |
| 1035 EXPECT_EQ("node=1,1 parent=null", nodes[0].ToString()); | 1042 EXPECT_EQ("view=1,1 parent=null", views[0].ToString()); |
| 1036 } | 1043 } |
| 1037 | 1044 |
| 1038 // Connection 2 shouldn't be able to get the root tree. | 1045 // Connection 2 shouldn't be able to get the root tree. |
| 1039 { | 1046 { |
| 1040 std::vector<TestNode> nodes; | 1047 std::vector<TestView> views; |
| 1041 connection2_->GetNodeTree(BuildNodeId(0, 1), &nodes); | 1048 connection2_->GetViewTree(BuildViewId(0, 1), &views); |
| 1042 ASSERT_EQ(0u, nodes.size()); | 1049 ASSERT_EQ(0u, views.size()); |
| 1043 } | 1050 } |
| 1044 } | 1051 } |
| 1045 | 1052 |
| 1046 TEST_F(ViewManagerTest, SetNodeBounds) { | 1053 TEST_F(ViewManagerTest, SetViewBounds) { |
| 1047 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1054 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
| 1048 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); | 1055 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1))); |
| 1049 | 1056 |
| 1050 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1057 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1051 | 1058 |
| 1052 ASSERT_TRUE(connection_->SetNodeBounds(BuildNodeId(1, 1), | 1059 ASSERT_TRUE( |
| 1053 gfx::Rect(0, 0, 100, 100))); | 1060 connection_->SetViewBounds(BuildViewId(1, 1), gfx::Rect(0, 0, 100, 100))); |
| 1054 | 1061 |
| 1055 connection2_->DoRunLoopUntilChangesCount(1); | 1062 connection2_->DoRunLoopUntilChangesCount(1); |
| 1056 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1063 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1057 ASSERT_EQ(1u, changes.size()); | 1064 ASSERT_EQ(1u, changes.size()); |
| 1058 EXPECT_EQ("BoundsChanged node=1,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100", | 1065 EXPECT_EQ("BoundsChanged view=1,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100", |
| 1059 changes[0]); | 1066 changes[0]); |
| 1060 | 1067 |
| 1061 // Should not be possible to change the bounds of a node created by another | 1068 // Should not be possible to change the bounds of a view created by another |
| 1062 // connection. | 1069 // connection. |
| 1063 ASSERT_FALSE(connection2_->SetNodeBounds(BuildNodeId(1, 1), | 1070 ASSERT_FALSE( |
| 1064 gfx::Rect(0, 0, 0, 0))); | 1071 connection2_->SetViewBounds(BuildViewId(1, 1), gfx::Rect(0, 0, 0, 0))); |
| 1065 } | 1072 } |
| 1066 | 1073 |
| 1067 // Verify AddNode fails when trying to manipulate nodes in other roots. | 1074 // Verify AddView fails when trying to manipulate views in other roots. |
| 1068 TEST_F(ViewManagerTest, CantMoveNodesFromOtherRoot) { | 1075 TEST_F(ViewManagerTest, CantMoveViewsFromOtherRoot) { |
| 1069 // Create 1 and 2 in the first connection. | 1076 // Create 1 and 2 in the first connection. |
| 1070 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1077 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
| 1071 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1078 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2))); |
| 1072 | 1079 |
| 1073 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1080 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1074 | 1081 |
| 1075 // Try to move 2 to be a child of 1 from connection 2. This should fail as 2 | 1082 // Try to move 2 to be a child of 1 from connection 2. This should fail as 2 |
| 1076 // should not be able to access 1. | 1083 // should not be able to access 1. |
| 1077 ASSERT_FALSE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); | 1084 ASSERT_FALSE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(1, 2))); |
| 1078 | 1085 |
| 1079 // Try to reparent 1 to the root. A connection is not allowed to reparent its | 1086 // Try to reparent 1 to the root. A connection is not allowed to reparent its |
| 1080 // roots. | 1087 // roots. |
| 1081 ASSERT_FALSE(connection2_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); | 1088 ASSERT_FALSE(connection2_->AddView(BuildViewId(0, 1), BuildViewId(1, 1))); |
| 1082 } | 1089 } |
| 1083 | 1090 |
| 1084 // Verify RemoveNodeFromParent fails for nodes that are descendants of the | 1091 // Verify RemoveViewFromParent fails for views that are descendants of the |
| 1085 // roots. | 1092 // roots. |
| 1086 TEST_F(ViewManagerTest, CantRemoveNodesInOtherRoots) { | 1093 TEST_F(ViewManagerTest, CantRemoveViewsInOtherRoots) { |
| 1087 // Create 1 and 2 in the first connection and parent both to the root. | 1094 // Create 1 and 2 in the first connection and parent both to the root. |
| 1088 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1095 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
| 1089 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1096 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2))); |
| 1090 | 1097 |
| 1091 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); | 1098 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1))); |
| 1092 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 2))); | 1099 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 2))); |
| 1093 | 1100 |
| 1094 // Establish the second connection and give it the root 1. | 1101 // Establish the second connection and give it the root 1. |
| 1095 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1102 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1096 | 1103 |
| 1097 // Connection 2 should not be able to remove node 2 or 1 from its parent. | 1104 // Connection 2 should not be able to remove view 2 or 1 from its parent. |
| 1098 ASSERT_FALSE(connection2_->RemoveNodeFromParent(BuildNodeId(1, 2))); | 1105 ASSERT_FALSE(connection2_->RemoveViewFromParent(BuildViewId(1, 2))); |
| 1099 ASSERT_FALSE(connection2_->RemoveNodeFromParent(BuildNodeId(1, 1))); | 1106 ASSERT_FALSE(connection2_->RemoveViewFromParent(BuildViewId(1, 1))); |
| 1100 | 1107 |
| 1101 // Create nodes 10 and 11 in 2. | 1108 // Create views 10 and 11 in 2. |
| 1102 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 10))); | 1109 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 10))); |
| 1103 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 11))); | 1110 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 11))); |
| 1104 | 1111 |
| 1105 // Parent 11 to 10. | 1112 // Parent 11 to 10. |
| 1106 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(2, 10), BuildNodeId(2, 11))); | 1113 ASSERT_TRUE(connection2_->AddView(BuildViewId(2, 10), BuildViewId(2, 11))); |
| 1107 // Remove 11 from 10. | 1114 // Remove 11 from 10. |
| 1108 ASSERT_TRUE(connection2_->RemoveNodeFromParent( BuildNodeId(2, 11))); | 1115 ASSERT_TRUE(connection2_->RemoveViewFromParent(BuildViewId(2, 11))); |
| 1109 | 1116 |
| 1110 // Verify nothing was actually removed. | 1117 // Verify nothing was actually removed. |
| 1111 { | 1118 { |
| 1112 std::vector<TestNode> nodes; | 1119 std::vector<TestView> views; |
| 1113 connection_->GetNodeTree(BuildNodeId(0, 1), &nodes); | 1120 connection_->GetViewTree(BuildViewId(0, 1), &views); |
| 1114 ASSERT_EQ(3u, nodes.size()); | 1121 ASSERT_EQ(3u, views.size()); |
| 1115 EXPECT_EQ("node=0,1 parent=null", nodes[0].ToString()); | 1122 EXPECT_EQ("view=0,1 parent=null", views[0].ToString()); |
| 1116 EXPECT_EQ("node=1,1 parent=0,1", nodes[1].ToString()); | 1123 EXPECT_EQ("view=1,1 parent=0,1", views[1].ToString()); |
| 1117 EXPECT_EQ("node=1,2 parent=0,1", nodes[2].ToString()); | 1124 EXPECT_EQ("view=1,2 parent=0,1", views[2].ToString()); |
| 1118 } | 1125 } |
| 1119 } | 1126 } |
| 1120 | 1127 |
| 1121 // Verify GetNodeTree fails for nodes that are not descendants of the roots. | 1128 // Verify GetViewTree fails for views that are not descendants of the roots. |
| 1122 TEST_F(ViewManagerTest, CantGetNodeTreeOfOtherRoots) { | 1129 TEST_F(ViewManagerTest, CantGetViewTreeOfOtherRoots) { |
| 1123 // Create 1 and 2 in the first connection and parent both to the root. | 1130 // Create 1 and 2 in the first connection and parent both to the root. |
| 1124 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1131 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
| 1125 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1132 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2))); |
| 1126 | 1133 |
| 1127 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); | 1134 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1))); |
| 1128 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 2))); | 1135 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 2))); |
| 1129 | 1136 |
| 1130 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1137 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1131 | 1138 |
| 1132 std::vector<TestNode> nodes; | 1139 std::vector<TestView> views; |
| 1133 | 1140 |
| 1134 // Should get nothing for the root. | 1141 // Should get nothing for the root. |
| 1135 connection2_->GetNodeTree(BuildNodeId(0, 1), &nodes); | 1142 connection2_->GetViewTree(BuildViewId(0, 1), &views); |
| 1136 ASSERT_TRUE(nodes.empty()); | 1143 ASSERT_TRUE(views.empty()); |
| 1137 | 1144 |
| 1138 // Should get nothing for node 2. | 1145 // Should get nothing for view 2. |
| 1139 connection2_->GetNodeTree(BuildNodeId(1, 2), &nodes); | 1146 connection2_->GetViewTree(BuildViewId(1, 2), &views); |
| 1140 ASSERT_TRUE(nodes.empty()); | 1147 ASSERT_TRUE(views.empty()); |
| 1141 | 1148 |
| 1142 // Should get node 1 if asked for. | 1149 // Should get view 1 if asked for. |
| 1143 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); | 1150 connection2_->GetViewTree(BuildViewId(1, 1), &views); |
| 1144 ASSERT_EQ(1u, nodes.size()); | 1151 ASSERT_EQ(1u, views.size()); |
| 1145 EXPECT_EQ("node=1,1 parent=null", nodes[0].ToString()); | 1152 EXPECT_EQ("view=1,1 parent=null", views[0].ToString()); |
| 1146 } | 1153 } |
| 1147 | 1154 |
| 1148 TEST_F(ViewManagerTest, ConnectTwice) { | 1155 TEST_F(ViewManagerTest, ConnectTwice) { |
| 1149 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1156 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
| 1150 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1157 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2))); |
| 1151 | 1158 |
| 1152 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1159 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1153 | 1160 |
| 1154 // Try to connect again to 1,1, this should fail as already connected to that | 1161 // Try to connect again to 1,1, this should fail as already connected to that |
| 1155 // root. | 1162 // root. |
| 1156 ASSERT_FALSE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL)); | 1163 ASSERT_FALSE(connection_->Embed(BuildViewId(1, 1), kTestServiceURL)); |
| 1157 | 1164 |
| 1158 // Connecting to 1,2 should succeed and end up in connection2. | 1165 // Connecting to 1,2 should succeed and end up in connection2. |
| 1159 { | 1166 { |
| 1160 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 2), kTestServiceURL)); | 1167 ASSERT_TRUE(connection_->Embed(BuildViewId(1, 2), kTestServiceURL)); |
| 1161 connection2_->DoRunLoopUntilChangesCount(1); | 1168 connection2_->DoRunLoopUntilChangesCount(1); |
| 1162 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1169 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1163 ASSERT_EQ(1u, changes.size()); | 1170 ASSERT_EQ(1u, changes.size()); |
| 1164 EXPECT_EQ("OnEmbed creator=mojo:test_url", changes[0]); | 1171 EXPECT_EQ("OnEmbed creator=mojo:test_url", changes[0]); |
| 1165 EXPECT_EQ("[node=1,2 parent=null]", | 1172 EXPECT_EQ("[view=1,2 parent=null]", |
| 1166 ChangeNodeDescription(connection2_->changes())); | 1173 ChangeViewDescription(connection2_->changes())); |
| 1167 } | 1174 } |
| 1168 } | 1175 } |
| 1169 | 1176 |
| 1170 TEST_F(ViewManagerTest, OnNodeInput) { | 1177 TEST_F(ViewManagerTest, OnViewInput) { |
| 1171 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1178 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
| 1172 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1179 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1173 | 1180 |
| 1174 // Dispatch an event to the node and verify its received. | 1181 // Dispatch an event to the view and verify its received. |
| 1175 { | 1182 { |
| 1176 EventPtr event(Event::New()); | 1183 EventPtr event(Event::New()); |
| 1177 event->action = static_cast<EventType>(1); | 1184 event->action = static_cast<EventType>(1); |
| 1178 connection_->view_manager()->DispatchOnViewInputEvent( | 1185 connection_->view_manager()->DispatchOnViewInputEvent(BuildViewId(1, 1), |
| 1179 BuildNodeId(1, 1), | 1186 event.Pass()); |
| 1180 event.Pass()); | |
| 1181 connection2_->DoRunLoopUntilChangesCount(1); | 1187 connection2_->DoRunLoopUntilChangesCount(1); |
| 1182 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1188 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1183 ASSERT_EQ(1u, changes.size()); | 1189 ASSERT_EQ(1u, changes.size()); |
| 1184 EXPECT_EQ("InputEvent node=1,1 event_action=1", changes[0]); | 1190 EXPECT_EQ("InputEvent view=1,1 event_action=1", changes[0]); |
| 1185 } | 1191 } |
| 1186 } | 1192 } |
| 1187 | 1193 |
| 1188 TEST_F(ViewManagerTest, EmbedWithSameNodeId) { | 1194 TEST_F(ViewManagerTest, EmbedWithSameViewId) { |
| 1189 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1195 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1190 | 1196 |
| 1191 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(connection_, | 1197 ASSERT_NO_FATAL_FAILURE( |
| 1192 BuildNodeId(1, 1))); | 1198 EstablishThirdConnection(connection_, BuildViewId(1, 1))); |
| 1193 | 1199 |
| 1194 // Connection2 should have been told the node was deleted. | 1200 // Connection2 should have been told the view was deleted. |
| 1195 { | 1201 { |
| 1196 connection2_->DoRunLoopUntilChangesCount(1); | 1202 connection2_->DoRunLoopUntilChangesCount(1); |
| 1197 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1203 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1198 ASSERT_EQ(1u, changes.size()); | 1204 ASSERT_EQ(1u, changes.size()); |
| 1199 EXPECT_EQ("NodeDeleted node=1,1", changes[0]); | 1205 EXPECT_EQ("ViewDeleted view=1,1", changes[0]); |
| 1200 } | 1206 } |
| 1201 | 1207 |
| 1202 // Connection2 has no root. Verify it can't see node 1,1 anymore. | 1208 // Connection2 has no root. Verify it can't see view 1,1 anymore. |
| 1203 { | 1209 { |
| 1204 std::vector<TestNode> nodes; | 1210 std::vector<TestView> views; |
| 1205 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); | 1211 connection2_->GetViewTree(BuildViewId(1, 1), &views); |
| 1206 EXPECT_TRUE(nodes.empty()); | 1212 EXPECT_TRUE(views.empty()); |
| 1207 } | 1213 } |
| 1208 } | 1214 } |
| 1209 | 1215 |
| 1210 TEST_F(ViewManagerTest, EmbedWithSameNodeId2) { | 1216 TEST_F(ViewManagerTest, EmbedWithSameViewId2) { |
| 1211 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1217 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1212 | 1218 |
| 1213 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(connection_, | 1219 ASSERT_NO_FATAL_FAILURE( |
| 1214 BuildNodeId(1, 1))); | 1220 EstablishThirdConnection(connection_, BuildViewId(1, 1))); |
| 1215 | 1221 |
| 1216 // Connection2 should have been told the node was deleted. | 1222 // Connection2 should have been told the view was deleted. |
| 1217 connection2_->DoRunLoopUntilChangesCount(1); | 1223 connection2_->DoRunLoopUntilChangesCount(1); |
| 1218 connection2_->ClearChanges(); | 1224 connection2_->ClearChanges(); |
| 1219 | 1225 |
| 1220 // Create a node in the third connection and parent it to the root. | 1226 // Create a view in the third connection and parent it to the root. |
| 1221 ASSERT_TRUE(connection3_->CreateNode(BuildNodeId(3, 1))); | 1227 ASSERT_TRUE(connection3_->CreateView(BuildViewId(3, 1))); |
| 1222 ASSERT_TRUE(connection3_->AddNode(BuildNodeId(1, 1), BuildNodeId(3, 1))); | 1228 ASSERT_TRUE(connection3_->AddView(BuildViewId(1, 1), BuildViewId(3, 1))); |
| 1223 | 1229 |
| 1224 // Connection 1 should have been told about the add (it owns the node). | 1230 // Connection 1 should have been told about the add (it owns the view). |
| 1225 { | 1231 { |
| 1226 connection_->DoRunLoopUntilChangesCount(1); | 1232 connection_->DoRunLoopUntilChangesCount(1); |
| 1227 const Changes changes(ChangesToDescription1(connection_->changes())); | 1233 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 1228 ASSERT_EQ(1u, changes.size()); | 1234 ASSERT_EQ(1u, changes.size()); |
| 1229 EXPECT_EQ("HierarchyChanged node=3,1 new_parent=1,1 old_parent=null", | 1235 EXPECT_EQ("HierarchyChanged view=3,1 new_parent=1,1 old_parent=null", |
| 1230 changes[0]); | 1236 changes[0]); |
| 1231 } | 1237 } |
| 1232 | 1238 |
| 1233 // Embed 1,1 back in connection 2. | 1239 // Embed 1,1 back in connection 2. |
| 1234 { | 1240 { |
| 1235 // 2 should be told about the new embed. | 1241 // 2 should be told about the new embed. |
| 1236 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL)); | 1242 ASSERT_TRUE(connection_->Embed(BuildViewId(1, 1), kTestServiceURL)); |
| 1237 connection2_->DoRunLoopUntilChangesCount(1); | 1243 connection2_->DoRunLoopUntilChangesCount(1); |
| 1238 const std::vector<Change>& changes(connection2_->changes()); | 1244 const std::vector<Change>& changes(connection2_->changes()); |
| 1239 ASSERT_EQ(1u, changes.size()); | 1245 ASSERT_EQ(1u, changes.size()); |
| 1240 EXPECT_EQ("OnEmbed creator=mojo:test_url", | 1246 EXPECT_EQ("OnEmbed creator=mojo:test_url", |
| 1241 ChangesToDescription1(changes)[0]); | 1247 ChangesToDescription1(changes)[0]); |
| 1242 EXPECT_EQ("[node=1,1 parent=null]", | 1248 EXPECT_EQ("[view=1,1 parent=null]", ChangeViewDescription(changes)); |
| 1243 ChangeNodeDescription(changes)); | |
| 1244 | 1249 |
| 1245 // And 3 should get a delete. | 1250 // And 3 should get a delete. |
| 1246 connection3_->DoRunLoopUntilChangesCount(1); | 1251 connection3_->DoRunLoopUntilChangesCount(1); |
| 1247 ASSERT_EQ(1u, connection3_->changes().size()); | 1252 ASSERT_EQ(1u, connection3_->changes().size()); |
| 1248 EXPECT_EQ("NodeDeleted node=1,1", | 1253 EXPECT_EQ("ViewDeleted view=1,1", |
| 1249 ChangesToDescription1(connection3_->changes())[0]); | 1254 ChangesToDescription1(connection3_->changes())[0]); |
| 1250 } | 1255 } |
| 1251 | 1256 |
| 1252 // Connection3_ has no root. Verify it can't see node 1,1 anymore. | 1257 // Connection3_ has no root. Verify it can't see view 1,1 anymore. |
| 1253 { | 1258 { |
| 1254 std::vector<TestNode> nodes; | 1259 std::vector<TestView> views; |
| 1255 connection3_->GetNodeTree(BuildNodeId(1, 1), &nodes); | 1260 connection3_->GetViewTree(BuildViewId(1, 1), &views); |
| 1256 EXPECT_TRUE(nodes.empty()); | 1261 EXPECT_TRUE(views.empty()); |
| 1257 } | 1262 } |
| 1258 | 1263 |
| 1259 // Verify 3,1 is no longer parented to 1,1. We have to do this from 1,1 as | 1264 // Verify 3,1 is no longer parented to 1,1. We have to do this from 1,1 as |
| 1260 // connection3_ can no longer see 1,1. | 1265 // connection3_ can no longer see 1,1. |
| 1261 { | 1266 { |
| 1262 std::vector<TestNode> nodes; | 1267 std::vector<TestView> views; |
| 1263 connection_->GetNodeTree(BuildNodeId(1, 1), &nodes); | 1268 connection_->GetViewTree(BuildViewId(1, 1), &views); |
| 1264 ASSERT_EQ(1u, nodes.size()); | 1269 ASSERT_EQ(1u, views.size()); |
| 1265 EXPECT_EQ("node=1,1 parent=null", nodes[0].ToString()); | 1270 EXPECT_EQ("view=1,1 parent=null", views[0].ToString()); |
| 1266 } | 1271 } |
| 1267 | 1272 |
| 1268 // Verify connection3_ can still see the node it created 3,1. | 1273 // Verify connection3_ can still see the view it created 3,1. |
| 1269 { | 1274 { |
| 1270 std::vector<TestNode> nodes; | 1275 std::vector<TestView> views; |
| 1271 connection3_->GetNodeTree(BuildNodeId(3, 1), &nodes); | 1276 connection3_->GetViewTree(BuildViewId(3, 1), &views); |
| 1272 ASSERT_EQ(1u, nodes.size()); | 1277 ASSERT_EQ(1u, views.size()); |
| 1273 EXPECT_EQ("node=3,1 parent=null", nodes[0].ToString()); | 1278 EXPECT_EQ("view=3,1 parent=null", views[0].ToString()); |
| 1274 } | 1279 } |
| 1275 } | 1280 } |
| 1276 | 1281 |
| 1277 // TODO(sky): add coverage of test that destroys connections and ensures other | 1282 // TODO(sky): add coverage of test that destroys connections and ensures other |
| 1278 // connections get deletion notification. | 1283 // connections get deletion notification. |
| 1279 | 1284 |
| 1280 // TODO(sky): need to better track changes to initial connection. For example, | 1285 // TODO(sky): need to better track changes to initial connection. For example, |
| 1281 // that SetBounsdNodes/AddNode and the like don't result in messages to the | 1286 // that SetBounsdViews/AddView and the like don't result in messages to the |
| 1282 // originating connection. | 1287 // originating connection. |
| 1283 | 1288 |
| 1284 } // namespace service | 1289 } // namespace service |
| 1285 } // namespace mojo | 1290 } // namespace mojo |
| OLD | NEW |