| 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/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 NodeIdToString(node_id).c_str(), | 55 NodeIdToString(node_id).c_str(), |
| 56 NodeIdToString(parent_id).c_str(), | 56 NodeIdToString(parent_id).c_str(), |
| 57 NodeIdToString(view_id).c_str()); | 57 NodeIdToString(view_id).c_str()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 TransportNodeId parent_id; | 60 TransportNodeId parent_id; |
| 61 TransportNodeId node_id; | 61 TransportNodeId node_id; |
| 62 TransportNodeId view_id; | 62 TransportNodeId view_id; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 // Callback that results in a vector of INodes. The INodes are converted to | 65 void INodesToTestNodes(const mojo::Array<INode>& data, |
| 66 // TestNodes. | 66 std::vector<TestNode>* test_nodes) { |
| 67 void INodesCallback(std::vector<TestNode>* test_nodes, | |
| 68 const mojo::Array<INode>& data) { | |
| 69 for (size_t i = 0; i < data.size(); ++i) { | 67 for (size_t i = 0; i < data.size(); ++i) { |
| 70 TestNode node; | 68 TestNode node; |
| 71 node.parent_id = data[i].parent_id(); | 69 node.parent_id = data[i].parent_id(); |
| 72 node.node_id = data[i].node_id(); | 70 node.node_id = data[i].node_id(); |
| 73 node.view_id = data[i].view_id(); | 71 node.view_id = data[i].view_id(); |
| 74 test_nodes->push_back(node); | 72 test_nodes->push_back(node); |
| 75 } | 73 } |
| 74 } |
| 75 |
| 76 // Callback that results in a vector of INodes. The INodes are converted to |
| 77 // TestNodes. |
| 78 void INodesCallback(std::vector<TestNode>* test_nodes, |
| 79 const mojo::Array<INode>& data) { |
| 80 INodesToTestNodes(data, test_nodes); |
| 76 current_run_loop->Quit(); | 81 current_run_loop->Quit(); |
| 77 } | 82 } |
| 78 | 83 |
| 79 // Creates an id used for transport from the specified parameters. | 84 // Creates an id used for transport from the specified parameters. |
| 80 TransportNodeId CreateNodeId(TransportConnectionId connection_id, | 85 TransportNodeId CreateNodeId(TransportConnectionId connection_id, |
| 81 TransportConnectionSpecificNodeId node_id) { | 86 TransportConnectionSpecificNodeId node_id) { |
| 82 return (connection_id << 16) | node_id; | 87 return (connection_id << 16) | node_id; |
| 83 } | 88 } |
| 84 | 89 |
| 85 // Creates an id used for transport from the specified parameters. | 90 // Creates an id used for transport from the specified parameters. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 ViewManagerClientImpl() | 178 ViewManagerClientImpl() |
| 174 : id_(0), | 179 : id_(0), |
| 175 next_server_change_id_(0), | 180 next_server_change_id_(0), |
| 176 quit_count_(0) {} | 181 quit_count_(0) {} |
| 177 | 182 |
| 178 TransportConnectionId id() const { return id_; } | 183 TransportConnectionId id() const { return id_; } |
| 179 | 184 |
| 180 TransportChangeId next_server_change_id() const { | 185 TransportChangeId next_server_change_id() const { |
| 181 return next_server_change_id_; | 186 return next_server_change_id_; |
| 182 } | 187 } |
| 188 const std::vector<TestNode>& initial_nodes() const { |
| 189 return initial_nodes_; |
| 190 } |
| 191 const std::vector<TestNode>& hierarchy_changed_nodes() const { |
| 192 return hierarchy_changed_nodes_; |
| 193 } |
| 183 | 194 |
| 184 Changes GetAndClearChanges() { | 195 Changes GetAndClearChanges() { |
| 185 Changes changes; | 196 Changes changes; |
| 186 changes.swap(changes_); | 197 changes.swap(changes_); |
| 187 return changes; | 198 return changes; |
| 188 } | 199 } |
| 189 | 200 |
| 190 void WaitForId() { | 201 void WaitForId() { |
| 191 if (id_ == 0) | 202 if (id_ == 0) |
| 192 DoRunLoop(); | 203 DoRunLoop(); |
| 193 } | 204 } |
| 194 | 205 |
| 195 void DoRunLoopUntilChangesCount(size_t count) { | 206 void DoRunLoopUntilChangesCount(size_t count) { |
| 196 if (changes_.size() >= count) | 207 if (changes_.size() >= count) |
| 197 return; | 208 return; |
| 198 quit_count_ = count - changes_.size(); | 209 quit_count_ = count - changes_.size(); |
| 199 DoRunLoop(); | 210 DoRunLoop(); |
| 200 } | 211 } |
| 201 | 212 |
| 202 private: | 213 private: |
| 203 // IViewManagerClient overrides: | 214 // IViewManagerClient overrides: |
| 204 virtual void OnConnectionEstablished( | 215 virtual void OnConnectionEstablished( |
| 205 TransportConnectionId connection_id, | 216 TransportConnectionId connection_id, |
| 206 TransportChangeId next_server_change_id) OVERRIDE { | 217 TransportChangeId next_server_change_id, |
| 218 const mojo::Array<INode>& nodes) OVERRIDE { |
| 207 id_ = connection_id; | 219 id_ = connection_id; |
| 208 next_server_change_id_ = next_server_change_id; | 220 next_server_change_id_ = next_server_change_id; |
| 221 INodesToTestNodes(nodes, &initial_nodes_); |
| 209 if (current_run_loop) | 222 if (current_run_loop) |
| 210 current_run_loop->Quit(); | 223 current_run_loop->Quit(); |
| 211 } | 224 } |
| 225 virtual void OnServerChangeIdAdvanced( |
| 226 uint32_t next_server_change_id) OVERRIDE { |
| 227 changes_.push_back( |
| 228 base::StringPrintf( |
| 229 "ServerChangeIdAdvanced %d", |
| 230 static_cast<int>(next_server_change_id))); |
| 231 QuitIfNecessary(); |
| 232 } |
| 212 virtual void OnNodeHierarchyChanged( | 233 virtual void OnNodeHierarchyChanged( |
| 213 TransportNodeId node, | 234 TransportNodeId node, |
| 214 TransportNodeId new_parent, | 235 TransportNodeId new_parent, |
| 215 TransportNodeId old_parent, | 236 TransportNodeId old_parent, |
| 216 TransportChangeId server_change_id) OVERRIDE { | 237 TransportChangeId server_change_id, |
| 238 const mojo::Array<INode>& nodes) OVERRIDE { |
| 217 changes_.push_back( | 239 changes_.push_back( |
| 218 base::StringPrintf( | 240 base::StringPrintf( |
| 219 "HierarchyChanged change_id=%d node=%s new_parent=%s old_parent=%s", | 241 "HierarchyChanged change_id=%d node=%s new_parent=%s old_parent=%s", |
| 220 static_cast<int>(server_change_id), | 242 static_cast<int>(server_change_id), |
| 221 NodeIdToString(node).c_str(), | 243 NodeIdToString(node).c_str(), |
| 222 NodeIdToString(new_parent).c_str(), | 244 NodeIdToString(new_parent).c_str(), |
| 223 NodeIdToString(old_parent).c_str())); | 245 NodeIdToString(old_parent).c_str())); |
| 246 hierarchy_changed_nodes_.clear(); |
| 247 INodesToTestNodes(nodes, &hierarchy_changed_nodes_); |
| 224 QuitIfNecessary(); | 248 QuitIfNecessary(); |
| 225 } | 249 } |
| 226 virtual void OnNodeDeleted(TransportNodeId node, | 250 virtual void OnNodeDeleted(TransportNodeId node, |
| 227 TransportChangeId server_change_id) OVERRIDE { | 251 TransportChangeId server_change_id) OVERRIDE { |
| 228 changes_.push_back( | 252 changes_.push_back( |
| 229 base::StringPrintf( | 253 base::StringPrintf( |
| 230 "NodeDeleted change_id=%d node=%s", | 254 "NodeDeleted change_id=%d node=%s", |
| 231 static_cast<int>(server_change_id), | 255 static_cast<int>(server_change_id), |
| 232 NodeIdToString(node).c_str())); | 256 NodeIdToString(node).c_str())); |
| 233 QuitIfNecessary(); | 257 QuitIfNecessary(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 257 } | 281 } |
| 258 | 282 |
| 259 TransportConnectionId id_; | 283 TransportConnectionId id_; |
| 260 TransportChangeId next_server_change_id_; | 284 TransportChangeId next_server_change_id_; |
| 261 | 285 |
| 262 // Used to determine when/if to quit the run loop. | 286 // Used to determine when/if to quit the run loop. |
| 263 size_t quit_count_; | 287 size_t quit_count_; |
| 264 | 288 |
| 265 Changes changes_; | 289 Changes changes_; |
| 266 | 290 |
| 291 // Set of nodes sent when connection created. |
| 292 std::vector<TestNode> initial_nodes_; |
| 293 |
| 294 // Nodes sent from last OnNodeHierarchyChanged. |
| 295 std::vector<TestNode> hierarchy_changed_nodes_; |
| 296 |
| 267 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); | 297 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); |
| 268 }; | 298 }; |
| 269 | 299 |
| 270 class ViewManagerConnectionTest : public testing::Test { | 300 class ViewManagerConnectionTest : public testing::Test { |
| 271 public: | 301 public: |
| 272 ViewManagerConnectionTest() {} | 302 ViewManagerConnectionTest() {} |
| 273 | 303 |
| 274 virtual void SetUp() OVERRIDE { | 304 virtual void SetUp() OVERRIDE { |
| 275 test_helper_.Init(); | 305 test_helper_.Init(); |
| 276 | 306 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 ASSERT_TRUE(AddNode(view_manager_.get(), | 384 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 355 CreateNodeId(client_.id(), 1), | 385 CreateNodeId(client_.id(), 1), |
| 356 CreateNodeId(client_.id(), 2), | 386 CreateNodeId(client_.id(), 2), |
| 357 1)); | 387 1)); |
| 358 Changes changes(client_.GetAndClearChanges()); | 388 Changes changes(client_.GetAndClearChanges()); |
| 359 ASSERT_TRUE(changes.empty()); | 389 ASSERT_TRUE(changes.empty()); |
| 360 | 390 |
| 361 client2_.DoRunLoopUntilChangesCount(1); | 391 client2_.DoRunLoopUntilChangesCount(1); |
| 362 changes = client2_.GetAndClearChanges(); | 392 changes = client2_.GetAndClearChanges(); |
| 363 ASSERT_EQ(1u, changes.size()); | 393 ASSERT_EQ(1u, changes.size()); |
| 364 EXPECT_EQ( | 394 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); |
| 365 "HierarchyChanged change_id=1 node=1,2 new_parent=1,1 old_parent=null", | |
| 366 changes[0]); | |
| 367 } | 395 } |
| 368 | 396 |
| 369 // Remove 2 from its parent. | 397 // Remove 2 from its parent. |
| 370 { | 398 { |
| 371 AllocationScope scope; | 399 AllocationScope scope; |
| 372 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), | 400 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), |
| 373 CreateNodeId(client_.id(), 2), | 401 CreateNodeId(client_.id(), 2), |
| 374 2)); | 402 2)); |
| 375 Changes changes(client_.GetAndClearChanges()); | 403 Changes changes(client_.GetAndClearChanges()); |
| 376 ASSERT_TRUE(changes.empty()); | 404 ASSERT_TRUE(changes.empty()); |
| 377 | 405 |
| 378 client2_.DoRunLoopUntilChangesCount(1); | 406 client2_.DoRunLoopUntilChangesCount(1); |
| 379 changes = client2_.GetAndClearChanges(); | 407 changes = client2_.GetAndClearChanges(); |
| 380 ASSERT_EQ(1u, changes.size()); | 408 ASSERT_EQ(1u, changes.size()); |
| 381 EXPECT_EQ( | 409 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); |
| 382 "HierarchyChanged change_id=2 node=1,2 new_parent=null old_parent=1,1", | |
| 383 changes[0]); | |
| 384 } | 410 } |
| 385 } | 411 } |
| 386 | 412 |
| 387 // Verifies AddNode fails when node is already in position. | 413 // Verifies AddNode fails when node is already in position. |
| 388 TEST_F(ViewManagerConnectionTest, AddNodeWithNoChange) { | 414 TEST_F(ViewManagerConnectionTest, AddNodeWithNoChange) { |
| 389 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 415 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
| 390 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | 416 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
| 391 | 417 |
| 392 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 418 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
| 393 | 419 |
| 394 EstablishSecondConnection(); | 420 EstablishSecondConnection(); |
| 395 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); | 421 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); |
| 396 | 422 |
| 397 // Make 2 a child of 1. | 423 // Make 2 a child of 1. |
| 398 { | 424 { |
| 399 AllocationScope scope; | 425 AllocationScope scope; |
| 400 ASSERT_TRUE(AddNode(view_manager_.get(), | 426 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 401 CreateNodeId(client_.id(), 1), | 427 CreateNodeId(client_.id(), 1), |
| 402 CreateNodeId(client_.id(), 2), | 428 CreateNodeId(client_.id(), 2), |
| 403 1)); | 429 1)); |
| 404 Changes changes(client_.GetAndClearChanges()); | 430 Changes changes(client_.GetAndClearChanges()); |
| 405 ASSERT_TRUE(changes.empty()); | 431 ASSERT_TRUE(changes.empty()); |
| 406 | 432 |
| 407 client2_.DoRunLoopUntilChangesCount(1); | 433 client2_.DoRunLoopUntilChangesCount(1); |
| 408 changes = client2_.GetAndClearChanges(); | 434 changes = client2_.GetAndClearChanges(); |
| 409 ASSERT_EQ(1u, changes.size()); | 435 ASSERT_EQ(1u, changes.size()); |
| 410 EXPECT_EQ( | 436 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); |
| 411 "HierarchyChanged change_id=1 node=1,2 new_parent=1,1 old_parent=null", | |
| 412 changes[0]); | |
| 413 } | 437 } |
| 414 | 438 |
| 415 // Try again, this should fail. | 439 // Try again, this should fail. |
| 416 { | 440 { |
| 417 AllocationScope scope; | 441 AllocationScope scope; |
| 418 EXPECT_FALSE(AddNode(view_manager_.get(), | 442 EXPECT_FALSE(AddNode(view_manager_.get(), |
| 419 CreateNodeId(client_.id(), 1), | 443 CreateNodeId(client_.id(), 1), |
| 420 CreateNodeId(client_.id(), 2), | 444 CreateNodeId(client_.id(), 2), |
| 421 2)); | 445 2)); |
| 422 Changes changes(client_.GetAndClearChanges()); | 446 Changes changes(client_.GetAndClearChanges()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 440 ASSERT_TRUE(AddNode(view_manager_.get(), | 464 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 441 CreateNodeId(client_.id(), 1), | 465 CreateNodeId(client_.id(), 1), |
| 442 CreateNodeId(client_.id(), 2), | 466 CreateNodeId(client_.id(), 2), |
| 443 1)); | 467 1)); |
| 444 Changes changes(client_.GetAndClearChanges()); | 468 Changes changes(client_.GetAndClearChanges()); |
| 445 ASSERT_TRUE(changes.empty()); | 469 ASSERT_TRUE(changes.empty()); |
| 446 | 470 |
| 447 client2_.DoRunLoopUntilChangesCount(1); | 471 client2_.DoRunLoopUntilChangesCount(1); |
| 448 changes = client2_.GetAndClearChanges(); | 472 changes = client2_.GetAndClearChanges(); |
| 449 ASSERT_EQ(1u, changes.size()); | 473 ASSERT_EQ(1u, changes.size()); |
| 450 EXPECT_EQ( | 474 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); |
| 451 "HierarchyChanged change_id=1 node=1,2 new_parent=1,1 old_parent=null", | |
| 452 changes[0]); | |
| 453 } | 475 } |
| 454 | 476 |
| 455 // Try to make 1 a child of 2, this should fail since 1 is an ancestor of 2. | 477 // Try to make 1 a child of 2, this should fail since 1 is an ancestor of 2. |
| 456 { | 478 { |
| 457 AllocationScope scope; | 479 AllocationScope scope; |
| 458 EXPECT_FALSE(AddNode(view_manager_.get(), | 480 EXPECT_FALSE(AddNode(view_manager_.get(), |
| 459 CreateNodeId(client_.id(), 2), | 481 CreateNodeId(client_.id(), 2), |
| 460 CreateNodeId(client_.id(), 1), | 482 CreateNodeId(client_.id(), 1), |
| 461 2)); | 483 2)); |
| 462 Changes changes(client_.GetAndClearChanges()); | 484 Changes changes(client_.GetAndClearChanges()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 ASSERT_TRUE(AddNode(view_manager_.get(), | 519 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 498 CreateNodeId(client_.id(), 21), | 520 CreateNodeId(client_.id(), 21), |
| 499 CreateNodeId(client_.id(), 3), | 521 CreateNodeId(client_.id(), 3), |
| 500 1)); | 522 1)); |
| 501 Changes changes(client_.GetAndClearChanges()); | 523 Changes changes(client_.GetAndClearChanges()); |
| 502 ASSERT_TRUE(changes.empty()); | 524 ASSERT_TRUE(changes.empty()); |
| 503 | 525 |
| 504 client2_.DoRunLoopUntilChangesCount(1); | 526 client2_.DoRunLoopUntilChangesCount(1); |
| 505 changes = client2_.GetAndClearChanges(); | 527 changes = client2_.GetAndClearChanges(); |
| 506 ASSERT_EQ(1u, changes.size()); | 528 ASSERT_EQ(1u, changes.size()); |
| 507 EXPECT_EQ( | 529 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); |
| 508 "HierarchyChanged change_id=1 node=1,3 new_parent=1,21 old_parent=null", | |
| 509 changes[0]); | |
| 510 } | 530 } |
| 511 | 531 |
| 512 // Make 21 a child of the root. | 532 // Make 21 a child of the root. |
| 513 { | 533 { |
| 514 AllocationScope scope; | 534 AllocationScope scope; |
| 515 ASSERT_TRUE(AddNode(view_manager_.get(), | 535 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 516 CreateNodeId(0, 1), | 536 CreateNodeId(0, 1), |
| 517 CreateNodeId(client_.id(), 21), | 537 CreateNodeId(client_.id(), 21), |
| 518 2)); | 538 2)); |
| 519 Changes changes(client_.GetAndClearChanges()); | 539 Changes changes(client_.GetAndClearChanges()); |
| 520 ASSERT_TRUE(changes.empty()); | 540 ASSERT_TRUE(changes.empty()); |
| 521 | 541 |
| 522 client2_.DoRunLoopUntilChangesCount(1); | 542 client2_.DoRunLoopUntilChangesCount(1); |
| 523 changes = client2_.GetAndClearChanges(); | 543 changes = client2_.GetAndClearChanges(); |
| 524 ASSERT_EQ(1u, changes.size()); | 544 ASSERT_EQ(1u, changes.size()); |
| 525 EXPECT_EQ( | 545 EXPECT_EQ( |
| 526 "HierarchyChanged change_id=2 node=1,21 new_parent=0,1 old_parent=null", | 546 "HierarchyChanged change_id=2 node=1,21 new_parent=0,1 old_parent=null", |
| 527 changes[0]); | 547 changes[0]); |
| 528 } | 548 } |
| 529 } | 549 } |
| 530 | 550 |
| 551 // Verifies adding to root sends right notifications. |
| 552 TEST_F(ViewManagerConnectionTest, NodeHierarchyChangedNodes) { |
| 553 // Create nodes 1 and 11 with 1 parented to the root and 11 a child of 1. |
| 554 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
| 555 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 11)); |
| 556 |
| 557 // Make 11 a child of 1. |
| 558 { |
| 559 AllocationScope scope; |
| 560 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 561 CreateNodeId(client_.id(), 1), |
| 562 CreateNodeId(client_.id(), 11), |
| 563 1)); |
| 564 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
| 565 } |
| 566 |
| 567 EstablishSecondConnection(); |
| 568 |
| 569 // Make 1 a child of the root. |
| 570 { |
| 571 AllocationScope scope; |
| 572 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 573 CreateNodeId(0, 1), |
| 574 CreateNodeId(client_.id(), 1), |
| 575 2)); |
| 576 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
| 577 |
| 578 // Client 2 should get a hierarchy change that includes the new nodes as it |
| 579 // has not yet seen them. |
| 580 client2_.DoRunLoopUntilChangesCount(1); |
| 581 Changes changes(client2_.GetAndClearChanges()); |
| 582 ASSERT_EQ(1u, changes.size()); |
| 583 EXPECT_EQ( |
| 584 "HierarchyChanged change_id=2 node=1,1 new_parent=0,1 old_parent=null", |
| 585 changes[0]); |
| 586 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); |
| 587 ASSERT_EQ(2u, nodes.size()); |
| 588 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); |
| 589 EXPECT_EQ("node=1,11 parent=1,1 view=null", nodes[1].ToString()); |
| 590 } |
| 591 |
| 592 // Remove 1 from the root. |
| 593 { |
| 594 AllocationScope scope; |
| 595 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), |
| 596 CreateNodeId(client_.id(), 1), |
| 597 3)); |
| 598 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
| 599 |
| 600 client2_.DoRunLoopUntilChangesCount(1); |
| 601 Changes changes(client2_.GetAndClearChanges()); |
| 602 ASSERT_EQ(1u, changes.size()); |
| 603 EXPECT_EQ( |
| 604 "HierarchyChanged change_id=3 node=1,1 new_parent=null old_parent=0,1", |
| 605 changes[0]); |
| 606 } |
| 607 |
| 608 // Create another node, 111, parent it to 11. |
| 609 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 111)); |
| 610 { |
| 611 AllocationScope scope; |
| 612 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 613 CreateNodeId(client_.id(), 11), |
| 614 CreateNodeId(client_.id(), 111), |
| 615 4)); |
| 616 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
| 617 |
| 618 client2_.DoRunLoopUntilChangesCount(1); |
| 619 Changes changes(client2_.GetAndClearChanges()); |
| 620 ASSERT_EQ(1u, changes.size()); |
| 621 // Even though 11 isn't attached to the root client 2 is still notified of |
| 622 // the change because it was told about 11. |
| 623 EXPECT_EQ( |
| 624 "HierarchyChanged change_id=4 node=1,111 new_parent=1,11 " |
| 625 "old_parent=null", changes[0]); |
| 626 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); |
| 627 ASSERT_EQ(1u, nodes.size()); |
| 628 EXPECT_EQ("node=1,111 parent=1,11 view=null", nodes[0].ToString()); |
| 629 } |
| 630 |
| 631 // Reattach 1 to the root. |
| 632 { |
| 633 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 634 CreateNodeId(0, 1), |
| 635 CreateNodeId(client_.id(), 1), |
| 636 5)); |
| 637 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
| 638 |
| 639 client2_.DoRunLoopUntilChangesCount(1); |
| 640 Changes changes = client2_.GetAndClearChanges(); |
| 641 ASSERT_EQ(1u, changes.size()); |
| 642 EXPECT_EQ( |
| 643 "HierarchyChanged change_id=5 node=1,1 new_parent=0,1 old_parent=null", |
| 644 changes[0]); |
| 645 ASSERT_TRUE(client2_.hierarchy_changed_nodes().empty()); |
| 646 } |
| 647 } |
| 648 |
| 649 TEST_F(ViewManagerConnectionTest, NodeHierarchyChangedAddingKnownToUnknown) { |
| 650 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no |
| 651 // parent). |
| 652 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
| 653 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 11)); |
| 654 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
| 655 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 21)); |
| 656 |
| 657 // Set up the hierarchy. |
| 658 { |
| 659 AllocationScope scope; |
| 660 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 661 CreateNodeId(0, 1), |
| 662 CreateNodeId(client_.id(), 1), |
| 663 1)); |
| 664 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 665 CreateNodeId(client_.id(), 1), |
| 666 CreateNodeId(client_.id(), 11), |
| 667 2)); |
| 668 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 669 CreateNodeId(client_.id(), 2), |
| 670 CreateNodeId(client_.id(), 21), |
| 671 3)); |
| 672 } |
| 673 |
| 674 EstablishSecondConnection(); |
| 675 |
| 676 // Remove 11. |
| 677 { |
| 678 AllocationScope scope; |
| 679 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), |
| 680 CreateNodeId(client_.id(), 11), |
| 681 4)); |
| 682 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
| 683 |
| 684 client2_.DoRunLoopUntilChangesCount(1); |
| 685 Changes changes(client2_.GetAndClearChanges()); |
| 686 ASSERT_EQ(1u, changes.size()); |
| 687 EXPECT_EQ( |
| 688 "HierarchyChanged change_id=4 node=1,11 new_parent=null old_parent=1,1", |
| 689 changes[0]); |
| 690 EXPECT_TRUE(client2_.hierarchy_changed_nodes().empty()); |
| 691 } |
| 692 |
| 693 // Add 11 to 21. As client2 knows about 11 it should receive the new |
| 694 // hierarchy. |
| 695 { |
| 696 AllocationScope scope; |
| 697 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 698 CreateNodeId(client_.id(), 21), |
| 699 CreateNodeId(client_.id(), 11), |
| 700 5)); |
| 701 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
| 702 |
| 703 client2_.DoRunLoopUntilChangesCount(1); |
| 704 Changes changes(client2_.GetAndClearChanges()); |
| 705 ASSERT_EQ(1u, changes.size()); |
| 706 EXPECT_EQ( |
| 707 "HierarchyChanged change_id=5 node=1,11 new_parent=1,21 " |
| 708 "old_parent=null", changes[0]); |
| 709 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); |
| 710 ASSERT_EQ(2u, nodes.size()); |
| 711 EXPECT_EQ("node=1,2 parent=null view=null", nodes[0].ToString()); |
| 712 EXPECT_EQ("node=1,21 parent=1,2 view=null", nodes[1].ToString()); |
| 713 } |
| 714 } |
| 715 |
| 716 // Verifies connection on told descendants of the root when connecting. |
| 717 TEST_F(ViewManagerConnectionTest, GetInitialNodesOnInit) { |
| 718 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 21)); |
| 719 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 3)); |
| 720 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
| 721 |
| 722 // Make 3 a child of 21. |
| 723 { |
| 724 AllocationScope scope; |
| 725 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 726 CreateNodeId(client_.id(), 21), |
| 727 CreateNodeId(client_.id(), 3), |
| 728 1)); |
| 729 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
| 730 } |
| 731 |
| 732 // Make 21 a child of the root. |
| 733 { |
| 734 AllocationScope scope; |
| 735 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 736 CreateNodeId(0, 1), |
| 737 CreateNodeId(client_.id(), 21), |
| 738 2)); |
| 739 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
| 740 } |
| 741 |
| 742 EstablishSecondConnection(); |
| 743 // Should get notification of children of the root. |
| 744 const std::vector<TestNode>& nodes(client2_.initial_nodes()); |
| 745 ASSERT_EQ(3u, nodes.size()); |
| 746 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString()); |
| 747 EXPECT_EQ("node=1,21 parent=0,1 view=null", nodes[1].ToString()); |
| 748 EXPECT_EQ("node=1,3 parent=1,21 view=null", nodes[2].ToString()); |
| 749 } |
| 750 |
| 531 // Verifies DeleteNode works. | 751 // Verifies DeleteNode works. |
| 532 TEST_F(ViewManagerConnectionTest, DeleteNode) { | 752 TEST_F(ViewManagerConnectionTest, DeleteNode) { |
| 533 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 753 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
| 534 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | 754 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
| 535 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 755 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
| 536 | 756 |
| 537 EstablishSecondConnection(); | 757 EstablishSecondConnection(); |
| 538 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); | 758 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); |
| 539 | 759 |
| 540 // Make 2 a child of 1. | 760 // Make 2 a child of 1. |
| 541 { | 761 { |
| 542 AllocationScope scope; | 762 AllocationScope scope; |
| 543 ASSERT_TRUE(AddNode(view_manager_.get(), | 763 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 544 CreateNodeId(client_.id(), 1), | 764 CreateNodeId(client_.id(), 1), |
| 545 CreateNodeId(client_.id(), 2), | 765 CreateNodeId(client_.id(), 2), |
| 546 1)); | 766 1)); |
| 547 Changes changes(client_.GetAndClearChanges()); | 767 Changes changes(client_.GetAndClearChanges()); |
| 548 ASSERT_TRUE(changes.empty()); | 768 ASSERT_TRUE(changes.empty()); |
| 549 | 769 |
| 550 client2_.DoRunLoopUntilChangesCount(1); | 770 client2_.DoRunLoopUntilChangesCount(1); |
| 551 changes = client2_.GetAndClearChanges(); | 771 changes = client2_.GetAndClearChanges(); |
| 552 ASSERT_EQ(1u, changes.size()); | 772 ASSERT_EQ(1u, changes.size()); |
| 553 EXPECT_EQ( | 773 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); |
| 554 "HierarchyChanged change_id=1 node=1,2 new_parent=1,1 old_parent=null", | |
| 555 changes[0]); | |
| 556 } | 774 } |
| 557 | 775 |
| 558 // Add 1 to the root | 776 // Add 1 to the root |
| 559 { | 777 { |
| 560 AllocationScope scope; | 778 AllocationScope scope; |
| 561 ASSERT_TRUE(AddNode(view_manager_.get(), | 779 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 562 CreateNodeId(0, 1), | 780 CreateNodeId(0, 1), |
| 563 CreateNodeId(client_.id(), 1), | 781 CreateNodeId(client_.id(), 1), |
| 564 2)); | 782 2)); |
| 565 Changes changes(client_.GetAndClearChanges()); | 783 Changes changes(client_.GetAndClearChanges()); |
| 566 ASSERT_TRUE(changes.empty()); | 784 ASSERT_TRUE(changes.empty()); |
| 567 | 785 |
| 568 client2_.DoRunLoopUntilChangesCount(1); | 786 client2_.DoRunLoopUntilChangesCount(1); |
| 569 changes = client2_.GetAndClearChanges(); | 787 changes = client2_.GetAndClearChanges(); |
| 570 ASSERT_EQ(1u, changes.size()); | 788 ASSERT_EQ(1u, changes.size()); |
| 571 EXPECT_EQ( | 789 EXPECT_EQ( |
| 572 "HierarchyChanged change_id=2 node=1,1 new_parent=0,1 old_parent=null", | 790 "HierarchyChanged change_id=2 node=1,1 new_parent=0,1 old_parent=null", |
| 573 changes[0]); | 791 changes[0]); |
| 574 } | 792 } |
| 575 | 793 |
| 576 // Delete 1. Deleting 1 sends out notification of a removal for both nodes (1 | 794 // Delete 1. |
| 577 // and 2). | |
| 578 { | 795 { |
| 579 AllocationScope scope; | 796 AllocationScope scope; |
| 580 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 1))); | 797 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 1))); |
| 581 Changes changes(client_.GetAndClearChanges()); | 798 Changes changes(client_.GetAndClearChanges()); |
| 582 ASSERT_TRUE(changes.empty()); | 799 ASSERT_TRUE(changes.empty()); |
| 583 | 800 |
| 584 client2_.DoRunLoopUntilChangesCount(3); | 801 client2_.DoRunLoopUntilChangesCount(1); |
| 585 changes = client2_.GetAndClearChanges(); | 802 changes = client2_.GetAndClearChanges(); |
| 586 ASSERT_EQ(3u, changes.size()); | 803 ASSERT_EQ(1u, changes.size()); |
| 587 EXPECT_EQ( | 804 EXPECT_EQ("NodeDeleted change_id=3 node=1,1", changes[0]); |
| 588 "HierarchyChanged change_id=3 node=1,1 new_parent=null old_parent=0,1", | |
| 589 changes[0]); | |
| 590 EXPECT_EQ( | |
| 591 "HierarchyChanged change_id=3 node=1,2 new_parent=null old_parent=1,1", | |
| 592 changes[1]); | |
| 593 EXPECT_EQ("NodeDeleted change_id=3 node=1,1", changes[2]); | |
| 594 } | 805 } |
| 595 } | 806 } |
| 596 | 807 |
| 808 // Verifies if a node was deleted and then reused that other clients are |
| 809 // properly notified. |
| 810 TEST_F(ViewManagerConnectionTest, ReusedDeletedId) { |
| 811 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
| 812 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
| 813 |
| 814 EstablishSecondConnection(); |
| 815 |
| 816 // Make 1 a child of the root. |
| 817 { |
| 818 AllocationScope scope; |
| 819 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 820 CreateNodeId(0, 1), |
| 821 CreateNodeId(client_.id(), 1), |
| 822 1)); |
| 823 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
| 824 |
| 825 client2_.DoRunLoopUntilChangesCount(1); |
| 826 Changes changes = client2_.GetAndClearChanges(); |
| 827 EXPECT_EQ( |
| 828 "HierarchyChanged change_id=1 node=1,1 new_parent=0,1 old_parent=null", |
| 829 changes[0]); |
| 830 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); |
| 831 ASSERT_EQ(1u, nodes.size()); |
| 832 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); |
| 833 } |
| 834 |
| 835 // Delete 1. |
| 836 { |
| 837 AllocationScope scope; |
| 838 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 1))); |
| 839 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
| 840 |
| 841 client2_.DoRunLoopUntilChangesCount(1); |
| 842 Changes changes = client2_.GetAndClearChanges(); |
| 843 ASSERT_EQ(1u, changes.size()); |
| 844 EXPECT_EQ("NodeDeleted change_id=2 node=1,1", changes[0]); |
| 845 } |
| 846 |
| 847 // Create 1 again, and add it back to the root. Should get the same |
| 848 // notification. |
| 849 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
| 850 { |
| 851 AllocationScope scope; |
| 852 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 853 CreateNodeId(0, 1), |
| 854 CreateNodeId(client_.id(), 1), |
| 855 3)); |
| 856 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
| 857 |
| 858 client2_.DoRunLoopUntilChangesCount(1); |
| 859 Changes changes = client2_.GetAndClearChanges(); |
| 860 EXPECT_EQ( |
| 861 "HierarchyChanged change_id=3 node=1,1 new_parent=0,1 old_parent=null", |
| 862 changes[0]); |
| 863 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); |
| 864 ASSERT_EQ(1u, nodes.size()); |
| 865 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); |
| 866 } |
| 867 } |
| 868 |
| 597 // Assertions around setting a view. | 869 // Assertions around setting a view. |
| 598 TEST_F(ViewManagerConnectionTest, SetView) { | 870 TEST_F(ViewManagerConnectionTest, SetView) { |
| 599 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 871 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
| 600 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | 872 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
| 601 ASSERT_TRUE(CreateView(view_manager_.get(), 1, 11)); | 873 ASSERT_TRUE(CreateView(view_manager_.get(), 1, 11)); |
| 602 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 874 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
| 603 | 875 |
| 604 EstablishSecondConnection(); | 876 EstablishSecondConnection(); |
| 605 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); | 877 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); |
| 606 | 878 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 // Delete node 1. | 929 // Delete node 1. |
| 658 { | 930 { |
| 659 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 1))); | 931 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 1))); |
| 660 Changes changes(client_.GetAndClearChanges()); | 932 Changes changes(client_.GetAndClearChanges()); |
| 661 ASSERT_TRUE(changes.empty()); | 933 ASSERT_TRUE(changes.empty()); |
| 662 | 934 |
| 663 client2_.DoRunLoopUntilChangesCount(2); | 935 client2_.DoRunLoopUntilChangesCount(2); |
| 664 changes = client2_.GetAndClearChanges(); | 936 changes = client2_.GetAndClearChanges(); |
| 665 ASSERT_EQ(2u, changes.size()); | 937 ASSERT_EQ(2u, changes.size()); |
| 666 EXPECT_EQ("ViewReplaced node=1,1 new_view=null old_view=1,11", changes[0]); | 938 EXPECT_EQ("ViewReplaced node=1,1 new_view=null old_view=1,11", changes[0]); |
| 667 EXPECT_EQ("NodeDeleted change_id=1 node=1,1", changes[1]); | 939 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[1]); |
| 668 } | 940 } |
| 669 | 941 |
| 942 // Parent 2 to the root. |
| 943 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 944 CreateNodeId(0, 1), |
| 945 CreateNodeId(client_.id(), 2), |
| 946 2)); |
| 947 client2_.DoRunLoopUntilChangesCount(1); |
| 948 client2_.GetAndClearChanges(); |
| 949 |
| 670 // Set view 11 on node 2. | 950 // Set view 11 on node 2. |
| 671 { | 951 { |
| 672 ASSERT_TRUE(SetView(view_manager_.get(), | 952 ASSERT_TRUE(SetView(view_manager_.get(), |
| 673 CreateNodeId(client_.id(), 2), | 953 CreateNodeId(client_.id(), 2), |
| 674 CreateViewId(client_.id(), 11))); | 954 CreateViewId(client_.id(), 11))); |
| 675 Changes changes(client_.GetAndClearChanges()); | 955 Changes changes(client_.GetAndClearChanges()); |
| 676 ASSERT_TRUE(changes.empty()); | 956 ASSERT_TRUE(changes.empty()); |
| 677 | 957 |
| 678 client2_.DoRunLoopUntilChangesCount(1); | 958 client2_.DoRunLoopUntilChangesCount(1); |
| 679 changes = client2_.GetAndClearChanges(); | 959 changes = client2_.GetAndClearChanges(); |
| 680 ASSERT_EQ(1u, changes.size()); | 960 ASSERT_EQ(1u, changes.size()); |
| 681 EXPECT_EQ("ViewReplaced node=1,2 new_view=1,11 old_view=null", changes[0]); | 961 EXPECT_EQ("ViewReplaced node=1,2 new_view=1,11 old_view=null", changes[0]); |
| 682 } | 962 } |
| 963 |
| 964 // Delete node. |
| 965 { |
| 966 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 2))); |
| 967 Changes changes(client_.GetAndClearChanges()); |
| 968 ASSERT_TRUE(changes.empty()); |
| 969 |
| 970 client2_.DoRunLoopUntilChangesCount(2); |
| 971 changes = client2_.GetAndClearChanges(); |
| 972 ASSERT_EQ(2u, changes.size()); |
| 973 EXPECT_EQ("ViewReplaced node=1,2 new_view=null old_view=1,11", changes[0]); |
| 974 EXPECT_EQ("NodeDeleted change_id=3 node=1,2", changes[1]); |
| 975 } |
| 683 } | 976 } |
| 684 | 977 |
| 685 // Sets view from one connection on another. | 978 // Sets view from one connection on another. |
| 686 TEST_F(ViewManagerConnectionTest, SetViewFromSecondConnection) { | 979 TEST_F(ViewManagerConnectionTest, SetViewFromSecondConnection) { |
| 687 EstablishSecondConnection(); | 980 EstablishSecondConnection(); |
| 688 | 981 |
| 689 // Create two nodes in first connection. | 982 // Create two nodes in first connection. |
| 690 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 983 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
| 691 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | 984 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
| 692 | 985 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); | 1066 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); |
| 774 ASSERT_EQ(2u, nodes.size()); | 1067 ASSERT_EQ(2u, nodes.size()); |
| 775 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); | 1068 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); |
| 776 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); | 1069 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); |
| 777 } | 1070 } |
| 778 } | 1071 } |
| 779 | 1072 |
| 780 } // namespace service | 1073 } // namespace service |
| 781 } // namespace view_manager | 1074 } // namespace view_manager |
| 782 } // namespace mojo | 1075 } // namespace mojo |
| OLD | NEW |