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/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "mojo/common/common_type_converters.h" | 14 #include "mojo/common/common_type_converters.h" |
15 #include "mojo/public/cpp/application/application.h" | 15 #include "mojo/public/cpp/application/application.h" |
16 #include "mojo/public/cpp/application/connect.h" | 16 #include "mojo/public/cpp/application/connect.h" |
17 #include "mojo/public/cpp/bindings/allocation_scope.h" | |
18 #include "mojo/public/cpp/environment/environment.h" | 17 #include "mojo/public/cpp/environment/environment.h" |
19 #include "mojo/service_manager/service_manager.h" | 18 #include "mojo/service_manager/service_manager.h" |
20 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 19 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
21 #include "mojo/services/public/cpp/view_manager/util.h" | 20 #include "mojo/services/public/cpp/view_manager/util.h" |
22 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" | 21 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" |
23 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | 22 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
24 #include "mojo/services/view_manager/test_change_tracker.h" | 23 #include "mojo/services/view_manager/test_change_tracker.h" |
25 #include "mojo/shell/shell_test_helper.h" | 24 #include "mojo/shell/shell_test_helper.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "ui/gfx/geometry/rect.h" | 26 #include "ui/gfx/geometry/rect.h" |
28 | 27 |
29 namespace mojo { | 28 namespace mojo { |
30 | |
31 // TODO(sky): remove this when Darin is done with cleanup. | |
32 template <typename T> | |
33 class MOJO_COMMON_EXPORT TypeConverter<T, T> { | |
34 public: | |
35 static T ConvertFrom(T input, Buffer* buf) { | |
36 return input; | |
37 } | |
38 static T ConvertTo(T input) { | |
39 return input; | |
40 } | |
41 | |
42 MOJO_ALLOW_IMPLICIT_TYPE_CONVERSION(); | |
43 }; | |
44 | |
45 namespace view_manager { | 29 namespace view_manager { |
46 namespace service { | 30 namespace service { |
47 | 31 |
48 namespace { | 32 namespace { |
49 | 33 |
50 base::RunLoop* current_run_loop = NULL; | 34 base::RunLoop* current_run_loop = NULL; |
51 | 35 |
52 const char kTestServiceURL[] = "mojo:test_url"; | 36 const char kTestServiceURL[] = "mojo:test_url"; |
53 | 37 |
54 void INodesToTestNodes(const Array<INode>& data, | 38 void INodesToTestNodes(const Array<INodePtr>& data, |
55 std::vector<TestNode>* test_nodes) { | 39 std::vector<TestNode>* test_nodes) { |
56 for (size_t i = 0; i < data.size(); ++i) { | 40 for (size_t i = 0; i < data.size(); ++i) { |
57 TestNode node; | 41 TestNode node; |
58 node.parent_id = data[i].parent_id(); | 42 node.parent_id = data[i]->parent_id; |
59 node.node_id = data[i].node_id(); | 43 node.node_id = data[i]->node_id; |
60 node.view_id = data[i].view_id(); | 44 node.view_id = data[i]->view_id; |
61 test_nodes->push_back(node); | 45 test_nodes->push_back(node); |
62 } | 46 } |
63 } | 47 } |
64 | 48 |
65 // BackgroundConnection is used when a child ViewManagerConnection is created by | 49 // BackgroundConnection is used when a child ViewManagerConnection is created by |
66 // way of Connect(). BackgroundConnection is created on a background thread (the | 50 // way of Connect(). BackgroundConnection is created on a background thread (the |
67 // thread where the shell lives). All public methods are to be invoked on the | 51 // thread where the shell lives). All public methods are to be invoked on the |
68 // main thread. They wait for a result (by spinning a nested message loop), | 52 // main thread. They wait for a result (by spinning a nested message loop), |
69 // calling through to background thread, then the underlying IViewManager* and | 53 // calling through to background thread, then the underlying IViewManager* and |
70 // respond back to the calling thread to return control to the test. | 54 // respond back to the calling thread to return control to the test. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 // Callbacks from the various IViewManager functions. | 196 // Callbacks from the various IViewManager functions. |
213 void GotResultOnBackgroundThread(bool* result_cache, bool result) { | 197 void GotResultOnBackgroundThread(bool* result_cache, bool result) { |
214 *result_cache = result; | 198 *result_cache = result; |
215 main_loop_->PostTask( | 199 main_loop_->PostTask( |
216 FROM_HERE, | 200 FROM_HERE, |
217 base::Bind(&BackgroundConnection::QuitOnMainThread, | 201 base::Bind(&BackgroundConnection::QuitOnMainThread, |
218 base::Unretained(this))); | 202 base::Unretained(this))); |
219 } | 203 } |
220 | 204 |
221 void GotNodeTreeOnBackgroundThread(std::vector<TestNode>* nodes, | 205 void GotNodeTreeOnBackgroundThread(std::vector<TestNode>* nodes, |
222 const Array<INode>& results) { | 206 Array<INodePtr> results) { |
223 INodesToTestNodes(results, nodes); | 207 INodesToTestNodes(results, nodes); |
224 main_loop_->PostTask( | 208 main_loop_->PostTask( |
225 FROM_HERE, | 209 FROM_HERE, |
226 base::Bind(&BackgroundConnection::QuitOnMainThread, | 210 base::Bind(&BackgroundConnection::QuitOnMainThread, |
227 base::Unretained(this))); | 211 base::Unretained(this))); |
228 } | 212 } |
229 | 213 |
230 void QuitOnMainThread() { | 214 void QuitOnMainThread() { |
231 DCHECK(main_run_loop_); | 215 DCHECK(main_run_loop_); |
232 main_run_loop_->Quit(); | 216 main_run_loop_->Quit(); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 303 |
320 // InterfaceImp: | 304 // InterfaceImp: |
321 virtual void OnConnectionEstablished() OVERRIDE { | 305 virtual void OnConnectionEstablished() OVERRIDE { |
322 connection_.set_view_manager(client()); | 306 connection_.set_view_manager(client()); |
323 } | 307 } |
324 | 308 |
325 // IViewMangerClient: | 309 // IViewMangerClient: |
326 virtual void OnViewManagerConnectionEstablished( | 310 virtual void OnViewManagerConnectionEstablished( |
327 TransportConnectionId connection_id, | 311 TransportConnectionId connection_id, |
328 TransportChangeId next_server_change_id, | 312 TransportChangeId next_server_change_id, |
329 const Array<INode>& nodes) OVERRIDE { | 313 Array<INodePtr> nodes) OVERRIDE { |
330 tracker_.OnViewManagerConnectionEstablished( | 314 tracker_.OnViewManagerConnectionEstablished( |
331 connection_id, next_server_change_id, nodes); | 315 connection_id, next_server_change_id, nodes.Pass()); |
332 } | 316 } |
333 virtual void OnServerChangeIdAdvanced( | 317 virtual void OnServerChangeIdAdvanced( |
334 TransportChangeId next_server_change_id) OVERRIDE { | 318 TransportChangeId next_server_change_id) OVERRIDE { |
335 tracker_.OnServerChangeIdAdvanced(next_server_change_id); | 319 tracker_.OnServerChangeIdAdvanced(next_server_change_id); |
336 } | 320 } |
337 virtual void OnNodeBoundsChanged(TransportNodeId node_id, | 321 virtual void OnNodeBoundsChanged(TransportNodeId node_id, |
338 const Rect& old_bounds, | 322 RectPtr old_bounds, |
339 const Rect& new_bounds) OVERRIDE { | 323 RectPtr new_bounds) OVERRIDE { |
340 tracker_.OnNodeBoundsChanged(node_id, old_bounds, new_bounds); | 324 tracker_.OnNodeBoundsChanged(node_id, old_bounds.Pass(), new_bounds.Pass()); |
341 } | 325 } |
342 virtual void OnNodeHierarchyChanged( | 326 virtual void OnNodeHierarchyChanged( |
343 TransportNodeId node, | 327 TransportNodeId node, |
344 TransportNodeId new_parent, | 328 TransportNodeId new_parent, |
345 TransportNodeId old_parent, | 329 TransportNodeId old_parent, |
346 TransportChangeId server_change_id, | 330 TransportChangeId server_change_id, |
347 const Array<INode>& nodes) OVERRIDE { | 331 Array<INodePtr> nodes) OVERRIDE { |
348 tracker_.OnNodeHierarchyChanged(node, new_parent, old_parent, | 332 tracker_.OnNodeHierarchyChanged(node, new_parent, old_parent, |
349 server_change_id, nodes); | 333 server_change_id, nodes.Pass()); |
350 } | 334 } |
351 virtual void OnNodeDeleted(TransportNodeId node, | 335 virtual void OnNodeDeleted(TransportNodeId node, |
352 TransportChangeId server_change_id) OVERRIDE { | 336 TransportChangeId server_change_id) OVERRIDE { |
353 tracker_.OnNodeDeleted(node, server_change_id); | 337 tracker_.OnNodeDeleted(node, server_change_id); |
354 } | 338 } |
355 virtual void OnViewDeleted(TransportViewId view) OVERRIDE { | 339 virtual void OnViewDeleted(TransportViewId view) OVERRIDE { |
356 tracker_.OnViewDeleted(view); | 340 tracker_.OnViewDeleted(view); |
357 } | 341 } |
358 virtual void OnNodeViewReplaced(TransportNodeId node, | 342 virtual void OnNodeViewReplaced(TransportNodeId node, |
359 TransportViewId new_view_id, | 343 TransportViewId new_view_id, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 // Boolean callback. Sets |result_cache| to the value of |result| and quits | 394 // Boolean callback. Sets |result_cache| to the value of |result| and quits |
411 // the run loop. | 395 // the run loop. |
412 void BooleanCallback(bool* result_cache, bool result) { | 396 void BooleanCallback(bool* result_cache, bool result) { |
413 *result_cache = result; | 397 *result_cache = result; |
414 current_run_loop->Quit(); | 398 current_run_loop->Quit(); |
415 } | 399 } |
416 | 400 |
417 // Callback that results in a vector of INodes. The INodes are converted to | 401 // Callback that results in a vector of INodes. The INodes are converted to |
418 // TestNodes. | 402 // TestNodes. |
419 void INodesCallback(std::vector<TestNode>* test_nodes, | 403 void INodesCallback(std::vector<TestNode>* test_nodes, |
420 const Array<INode>& data) { | 404 Array<INodePtr> data) { |
421 INodesToTestNodes(data, test_nodes); | 405 INodesToTestNodes(data, test_nodes); |
422 current_run_loop->Quit(); | 406 current_run_loop->Quit(); |
423 } | 407 } |
424 | 408 |
425 // Creates an id used for transport from the specified parameters. | 409 // Creates an id used for transport from the specified parameters. |
426 TransportNodeId CreateNodeId(TransportConnectionId connection_id, | 410 TransportNodeId CreateNodeId(TransportConnectionId connection_id, |
427 TransportConnectionSpecificNodeId node_id) { | 411 TransportConnectionSpecificNodeId node_id) { |
428 return (connection_id << 16) | node_id; | 412 return (connection_id << 16) | node_id; |
429 } | 413 } |
430 | 414 |
(...skipping 28 matching lines...) Expand all Loading... |
459 bool result = false; | 443 bool result = false; |
460 view_manager->DeleteView(view_id, base::Bind(&BooleanCallback, &result)); | 444 view_manager->DeleteView(view_id, base::Bind(&BooleanCallback, &result)); |
461 DoRunLoop(); | 445 DoRunLoop(); |
462 return result; | 446 return result; |
463 } | 447 } |
464 | 448 |
465 bool SetNodeBounds(IViewManager* view_manager, | 449 bool SetNodeBounds(IViewManager* view_manager, |
466 TransportNodeId node_id, | 450 TransportNodeId node_id, |
467 const gfx::Rect& bounds) { | 451 const gfx::Rect& bounds) { |
468 bool result = false; | 452 bool result = false; |
469 view_manager->SetNodeBounds(node_id, bounds, | 453 view_manager->SetNodeBounds(node_id, Rect::From(bounds), |
470 base::Bind(&BooleanCallback, &result)); | 454 base::Bind(&BooleanCallback, &result)); |
471 DoRunLoop(); | 455 DoRunLoop(); |
472 return result; | 456 return result; |
473 } | 457 } |
474 | 458 |
475 // Adds a node, blocking until done. | 459 // Adds a node, blocking until done. |
476 bool AddNode(IViewManager* view_manager, | 460 bool AddNode(IViewManager* view_manager, |
477 TransportNodeId parent, | 461 TransportNodeId parent, |
478 TransportNodeId child, | 462 TransportNodeId child, |
479 TransportChangeId server_change_id) { | 463 TransportChangeId server_change_id) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 view_manager->SetView(node_id, view_id, | 507 view_manager->SetView(node_id, view_id, |
524 base::Bind(&BooleanCallback, &result)); | 508 base::Bind(&BooleanCallback, &result)); |
525 DoRunLoop(); | 509 DoRunLoop(); |
526 return result; | 510 return result; |
527 } | 511 } |
528 | 512 |
529 bool Connect(IViewManager* view_manager, | 513 bool Connect(IViewManager* view_manager, |
530 const std::string& url, | 514 const std::string& url, |
531 TransportNodeId id, | 515 TransportNodeId id, |
532 TransportNodeId id2) { | 516 TransportNodeId id2) { |
533 AllocationScope scope; | |
534 bool result = false; | 517 bool result = false; |
535 std::vector<TransportNodeId> node_ids; | 518 std::vector<TransportNodeId> node_ids; |
536 node_ids.push_back(id); | 519 node_ids.push_back(id); |
537 if (id2 != 0) | 520 if (id2 != 0) |
538 node_ids.push_back(id2); | 521 node_ids.push_back(id2); |
539 view_manager->Connect(url, Array<uint32_t>::From(node_ids), | 522 view_manager->Connect(url, Array<uint32_t>::From(node_ids), |
540 base::Bind(&BooleanCallback, &result)); | 523 base::Bind(&BooleanCallback, &result)); |
541 DoRunLoop(); | 524 DoRunLoop(); |
542 return result; | 525 return result; |
543 } | 526 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 | 593 |
611 void DoRunLoopUntilChangesCount(size_t count) { | 594 void DoRunLoopUntilChangesCount(size_t count) { |
612 main_loop_tracker_delegate_.DoRunLoopUntilChangesCount(count); | 595 main_loop_tracker_delegate_.DoRunLoopUntilChangesCount(count); |
613 } | 596 } |
614 | 597 |
615 private: | 598 private: |
616 // IViewManagerClient overrides: | 599 // IViewManagerClient overrides: |
617 virtual void OnViewManagerConnectionEstablished( | 600 virtual void OnViewManagerConnectionEstablished( |
618 TransportConnectionId connection_id, | 601 TransportConnectionId connection_id, |
619 TransportChangeId next_server_change_id, | 602 TransportChangeId next_server_change_id, |
620 const Array<INode>& nodes) OVERRIDE { | 603 mojo::Array<INodePtr> nodes) OVERRIDE { |
621 id_ = connection_id; | 604 id_ = connection_id; |
622 next_server_change_id_ = next_server_change_id; | 605 next_server_change_id_ = next_server_change_id; |
623 initial_nodes_.clear(); | 606 initial_nodes_.clear(); |
624 INodesToTestNodes(nodes, &initial_nodes_); | 607 INodesToTestNodes(nodes, &initial_nodes_); |
625 tracker_.OnViewManagerConnectionEstablished( | 608 tracker_.OnViewManagerConnectionEstablished( |
626 connection_id, next_server_change_id, nodes); | 609 connection_id, next_server_change_id, nodes.Pass()); |
627 } | 610 } |
628 virtual void OnServerChangeIdAdvanced( | 611 virtual void OnServerChangeIdAdvanced( |
629 TransportChangeId next_server_change_id) OVERRIDE { | 612 TransportChangeId next_server_change_id) OVERRIDE { |
630 tracker_.OnServerChangeIdAdvanced(next_server_change_id); | 613 tracker_.OnServerChangeIdAdvanced(next_server_change_id); |
631 } | 614 } |
632 virtual void OnNodeBoundsChanged(TransportNodeId node_id, | 615 virtual void OnNodeBoundsChanged(TransportNodeId node_id, |
633 const Rect& old_bounds, | 616 RectPtr old_bounds, |
634 const Rect& new_bounds) OVERRIDE { | 617 RectPtr new_bounds) OVERRIDE { |
635 tracker_.OnNodeBoundsChanged(node_id, old_bounds, new_bounds); | 618 tracker_.OnNodeBoundsChanged(node_id, old_bounds.Pass(), new_bounds.Pass()); |
636 } | 619 } |
637 virtual void OnNodeHierarchyChanged( | 620 virtual void OnNodeHierarchyChanged( |
638 TransportNodeId node, | 621 TransportNodeId node, |
639 TransportNodeId new_parent, | 622 TransportNodeId new_parent, |
640 TransportNodeId old_parent, | 623 TransportNodeId old_parent, |
641 TransportChangeId server_change_id, | 624 TransportChangeId server_change_id, |
642 const Array<INode>& nodes) OVERRIDE { | 625 mojo::Array<INodePtr> nodes) OVERRIDE { |
643 tracker_.OnNodeHierarchyChanged(node, new_parent, old_parent, | |
644 server_change_id, nodes); | |
645 hierarchy_changed_nodes_.clear(); | 626 hierarchy_changed_nodes_.clear(); |
646 INodesToTestNodes(nodes, &hierarchy_changed_nodes_); | 627 INodesToTestNodes(nodes, &hierarchy_changed_nodes_); |
| 628 tracker_.OnNodeHierarchyChanged(node, new_parent, old_parent, |
| 629 server_change_id, nodes.Pass()); |
647 } | 630 } |
648 virtual void OnNodeDeleted(TransportNodeId node, | 631 virtual void OnNodeDeleted(TransportNodeId node, |
649 TransportChangeId server_change_id) OVERRIDE { | 632 TransportChangeId server_change_id) OVERRIDE { |
650 tracker_.OnNodeDeleted(node, server_change_id); | 633 tracker_.OnNodeDeleted(node, server_change_id); |
651 } | 634 } |
652 virtual void OnViewDeleted(TransportViewId view) OVERRIDE { | 635 virtual void OnViewDeleted(TransportViewId view) OVERRIDE { |
653 tracker_.OnViewDeleted(view); | 636 tracker_.OnViewDeleted(view); |
654 } | 637 } |
655 virtual void OnNodeViewReplaced(TransportNodeId node, | 638 virtual void OnNodeViewReplaced(TransportNodeId node, |
656 TransportViewId new_view_id, | 639 TransportViewId new_view_id, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 763 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
781 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | 764 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
782 | 765 |
783 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 766 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
784 | 767 |
785 EstablishSecondConnection(); | 768 EstablishSecondConnection(); |
786 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); | 769 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); |
787 | 770 |
788 // Make 2 a child of 1. | 771 // Make 2 a child of 1. |
789 { | 772 { |
790 AllocationScope scope; | |
791 ASSERT_TRUE(AddNode(view_manager_.get(), | 773 ASSERT_TRUE(AddNode(view_manager_.get(), |
792 CreateNodeId(client_.id(), 1), | 774 CreateNodeId(client_.id(), 1), |
793 CreateNodeId(client_.id(), 2), | 775 CreateNodeId(client_.id(), 2), |
794 1)); | 776 1)); |
795 Changes changes(client_.GetAndClearChanges()); | 777 Changes changes(client_.GetAndClearChanges()); |
796 ASSERT_TRUE(changes.empty()); | 778 ASSERT_TRUE(changes.empty()); |
797 | 779 |
798 client2_.DoRunLoopUntilChangesCount(1); | 780 client2_.DoRunLoopUntilChangesCount(1); |
799 changes = client2_.GetAndClearChanges(); | 781 changes = client2_.GetAndClearChanges(); |
800 ASSERT_EQ(1u, changes.size()); | 782 ASSERT_EQ(1u, changes.size()); |
801 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); | 783 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); |
802 } | 784 } |
803 | 785 |
804 // Remove 2 from its parent. | 786 // Remove 2 from its parent. |
805 { | 787 { |
806 AllocationScope scope; | |
807 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), | 788 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), |
808 CreateNodeId(client_.id(), 2), | 789 CreateNodeId(client_.id(), 2), |
809 2)); | 790 2)); |
810 Changes changes(client_.GetAndClearChanges()); | 791 Changes changes(client_.GetAndClearChanges()); |
811 ASSERT_TRUE(changes.empty()); | 792 ASSERT_TRUE(changes.empty()); |
812 | 793 |
813 client2_.DoRunLoopUntilChangesCount(1); | 794 client2_.DoRunLoopUntilChangesCount(1); |
814 changes = client2_.GetAndClearChanges(); | 795 changes = client2_.GetAndClearChanges(); |
815 ASSERT_EQ(1u, changes.size()); | 796 ASSERT_EQ(1u, changes.size()); |
816 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); | 797 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); |
817 } | 798 } |
818 } | 799 } |
819 | 800 |
820 // Verifies AddNode fails when node is already in position. | 801 // Verifies AddNode fails when node is already in position. |
821 TEST_F(ViewManagerConnectionTest, AddNodeWithNoChange) { | 802 TEST_F(ViewManagerConnectionTest, AddNodeWithNoChange) { |
822 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 803 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
823 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | 804 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
824 | 805 |
825 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 806 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
826 | 807 |
827 EstablishSecondConnection(); | 808 EstablishSecondConnection(); |
828 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); | 809 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); |
829 | 810 |
830 // Make 2 a child of 1. | 811 // Make 2 a child of 1. |
831 { | 812 { |
832 AllocationScope scope; | |
833 ASSERT_TRUE(AddNode(view_manager_.get(), | 813 ASSERT_TRUE(AddNode(view_manager_.get(), |
834 CreateNodeId(client_.id(), 1), | 814 CreateNodeId(client_.id(), 1), |
835 CreateNodeId(client_.id(), 2), | 815 CreateNodeId(client_.id(), 2), |
836 1)); | 816 1)); |
837 Changes changes(client_.GetAndClearChanges()); | 817 Changes changes(client_.GetAndClearChanges()); |
838 ASSERT_TRUE(changes.empty()); | 818 ASSERT_TRUE(changes.empty()); |
839 | 819 |
840 client2_.DoRunLoopUntilChangesCount(1); | 820 client2_.DoRunLoopUntilChangesCount(1); |
841 changes = client2_.GetAndClearChanges(); | 821 changes = client2_.GetAndClearChanges(); |
842 ASSERT_EQ(1u, changes.size()); | 822 ASSERT_EQ(1u, changes.size()); |
843 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); | 823 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); |
844 } | 824 } |
845 | 825 |
846 // Try again, this should fail. | 826 // Try again, this should fail. |
847 { | 827 { |
848 AllocationScope scope; | |
849 EXPECT_FALSE(AddNode(view_manager_.get(), | 828 EXPECT_FALSE(AddNode(view_manager_.get(), |
850 CreateNodeId(client_.id(), 1), | 829 CreateNodeId(client_.id(), 1), |
851 CreateNodeId(client_.id(), 2), | 830 CreateNodeId(client_.id(), 2), |
852 2)); | 831 2)); |
853 Changes changes(client_.GetAndClearChanges()); | 832 Changes changes(client_.GetAndClearChanges()); |
854 EXPECT_TRUE(changes.empty()); | 833 EXPECT_TRUE(changes.empty()); |
855 } | 834 } |
856 } | 835 } |
857 | 836 |
858 // Verifies AddNode fails when node is already in position. | 837 // Verifies AddNode fails when node is already in position. |
859 TEST_F(ViewManagerConnectionTest, AddAncestorFails) { | 838 TEST_F(ViewManagerConnectionTest, AddAncestorFails) { |
860 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 839 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
861 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | 840 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
862 | 841 |
863 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 842 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
864 | 843 |
865 EstablishSecondConnection(); | 844 EstablishSecondConnection(); |
866 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); | 845 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); |
867 | 846 |
868 // Make 2 a child of 1. | 847 // Make 2 a child of 1. |
869 { | 848 { |
870 AllocationScope scope; | |
871 ASSERT_TRUE(AddNode(view_manager_.get(), | 849 ASSERT_TRUE(AddNode(view_manager_.get(), |
872 CreateNodeId(client_.id(), 1), | 850 CreateNodeId(client_.id(), 1), |
873 CreateNodeId(client_.id(), 2), | 851 CreateNodeId(client_.id(), 2), |
874 1)); | 852 1)); |
875 Changes changes(client_.GetAndClearChanges()); | 853 Changes changes(client_.GetAndClearChanges()); |
876 ASSERT_TRUE(changes.empty()); | 854 ASSERT_TRUE(changes.empty()); |
877 | 855 |
878 client2_.DoRunLoopUntilChangesCount(1); | 856 client2_.DoRunLoopUntilChangesCount(1); |
879 changes = client2_.GetAndClearChanges(); | 857 changes = client2_.GetAndClearChanges(); |
880 ASSERT_EQ(1u, changes.size()); | 858 ASSERT_EQ(1u, changes.size()); |
881 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); | 859 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); |
882 } | 860 } |
883 | 861 |
884 // Try to make 1 a child of 2, this should fail since 1 is an ancestor of 2. | 862 // Try to make 1 a child of 2, this should fail since 1 is an ancestor of 2. |
885 { | 863 { |
886 AllocationScope scope; | |
887 EXPECT_FALSE(AddNode(view_manager_.get(), | 864 EXPECT_FALSE(AddNode(view_manager_.get(), |
888 CreateNodeId(client_.id(), 2), | 865 CreateNodeId(client_.id(), 2), |
889 CreateNodeId(client_.id(), 1), | 866 CreateNodeId(client_.id(), 1), |
890 2)); | 867 2)); |
891 Changes changes(client_.GetAndClearChanges()); | 868 Changes changes(client_.GetAndClearChanges()); |
892 EXPECT_TRUE(changes.empty()); | 869 EXPECT_TRUE(changes.empty()); |
893 } | 870 } |
894 } | 871 } |
895 | 872 |
896 // Verifies adding with an invalid id fails. | 873 // Verifies adding with an invalid id fails. |
897 TEST_F(ViewManagerConnectionTest, AddWithInvalidServerId) { | 874 TEST_F(ViewManagerConnectionTest, AddWithInvalidServerId) { |
898 // Create two nodes. | 875 // Create two nodes. |
899 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 876 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
900 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | 877 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
901 | 878 |
902 // Make 2 a child of 1. Supply an invalid change id, which should fail. | 879 // Make 2 a child of 1. Supply an invalid change id, which should fail. |
903 { | 880 { |
904 AllocationScope scope; | |
905 ASSERT_FALSE(AddNode(view_manager_.get(), | 881 ASSERT_FALSE(AddNode(view_manager_.get(), |
906 CreateNodeId(client_.id(), 1), | 882 CreateNodeId(client_.id(), 1), |
907 CreateNodeId(client_.id(), 2), | 883 CreateNodeId(client_.id(), 2), |
908 0)); | 884 0)); |
909 Changes changes(client_.GetAndClearChanges()); | 885 Changes changes(client_.GetAndClearChanges()); |
910 EXPECT_TRUE(changes.empty()); | 886 EXPECT_TRUE(changes.empty()); |
911 } | 887 } |
912 } | 888 } |
913 | 889 |
914 // Verifies adding to root sends right notifications. | 890 // Verifies adding to root sends right notifications. |
915 TEST_F(ViewManagerConnectionTest, AddToRoot) { | 891 TEST_F(ViewManagerConnectionTest, AddToRoot) { |
916 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 21)); | 892 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 21)); |
917 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 3)); | 893 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 3)); |
918 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 894 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
919 | 895 |
920 EstablishSecondConnection(); | 896 EstablishSecondConnection(); |
921 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); | 897 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); |
922 | 898 |
923 // Make 3 a child of 21. | 899 // Make 3 a child of 21. |
924 { | 900 { |
925 AllocationScope scope; | |
926 ASSERT_TRUE(AddNode(view_manager_.get(), | 901 ASSERT_TRUE(AddNode(view_manager_.get(), |
927 CreateNodeId(client_.id(), 21), | 902 CreateNodeId(client_.id(), 21), |
928 CreateNodeId(client_.id(), 3), | 903 CreateNodeId(client_.id(), 3), |
929 1)); | 904 1)); |
930 Changes changes(client_.GetAndClearChanges()); | 905 Changes changes(client_.GetAndClearChanges()); |
931 ASSERT_TRUE(changes.empty()); | 906 ASSERT_TRUE(changes.empty()); |
932 | 907 |
933 client2_.DoRunLoopUntilChangesCount(1); | 908 client2_.DoRunLoopUntilChangesCount(1); |
934 changes = client2_.GetAndClearChanges(); | 909 changes = client2_.GetAndClearChanges(); |
935 ASSERT_EQ(1u, changes.size()); | 910 ASSERT_EQ(1u, changes.size()); |
936 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); | 911 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); |
937 } | 912 } |
938 | 913 |
939 // Make 21 a child of the root. | 914 // Make 21 a child of the root. |
940 { | 915 { |
941 AllocationScope scope; | |
942 ASSERT_TRUE(AddNode(view_manager_.get(), | 916 ASSERT_TRUE(AddNode(view_manager_.get(), |
943 CreateNodeId(0, 1), | 917 CreateNodeId(0, 1), |
944 CreateNodeId(client_.id(), 21), | 918 CreateNodeId(client_.id(), 21), |
945 2)); | 919 2)); |
946 Changes changes(client_.GetAndClearChanges()); | 920 Changes changes(client_.GetAndClearChanges()); |
947 ASSERT_TRUE(changes.empty()); | 921 ASSERT_TRUE(changes.empty()); |
948 | 922 |
949 client2_.DoRunLoopUntilChangesCount(1); | 923 client2_.DoRunLoopUntilChangesCount(1); |
950 changes = client2_.GetAndClearChanges(); | 924 changes = client2_.GetAndClearChanges(); |
951 ASSERT_EQ(1u, changes.size()); | 925 ASSERT_EQ(1u, changes.size()); |
952 EXPECT_EQ( | 926 EXPECT_EQ( |
953 "HierarchyChanged change_id=2 node=1,21 new_parent=0,1 old_parent=null", | 927 "HierarchyChanged change_id=2 node=1,21 new_parent=0,1 old_parent=null", |
954 changes[0]); | 928 changes[0]); |
955 } | 929 } |
956 } | 930 } |
957 | 931 |
958 // Verifies adding to root sends right notifications. | 932 // Verifies adding to root sends right notifications. |
959 TEST_F(ViewManagerConnectionTest, NodeHierarchyChangedNodes) { | 933 TEST_F(ViewManagerConnectionTest, NodeHierarchyChangedNodes) { |
960 // Create nodes 1 and 11 with 1 parented to the root and 11 a child of 1. | 934 // Create nodes 1 and 11 with 1 parented to the root and 11 a child of 1. |
961 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 935 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
962 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 11)); | 936 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 11)); |
963 | 937 |
964 // Make 11 a child of 1. | 938 // Make 11 a child of 1. |
965 { | 939 { |
966 AllocationScope scope; | |
967 ASSERT_TRUE(AddNode(view_manager_.get(), | 940 ASSERT_TRUE(AddNode(view_manager_.get(), |
968 CreateNodeId(client_.id(), 1), | 941 CreateNodeId(client_.id(), 1), |
969 CreateNodeId(client_.id(), 11), | 942 CreateNodeId(client_.id(), 11), |
970 1)); | 943 1)); |
971 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | 944 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
972 } | 945 } |
973 | 946 |
974 EstablishSecondConnection(); | 947 EstablishSecondConnection(); |
975 | 948 |
976 // Make 1 a child of the root. | 949 // Make 1 a child of the root. |
977 { | 950 { |
978 AllocationScope scope; | |
979 ASSERT_TRUE(AddNode(view_manager_.get(), | 951 ASSERT_TRUE(AddNode(view_manager_.get(), |
980 CreateNodeId(0, 1), | 952 CreateNodeId(0, 1), |
981 CreateNodeId(client_.id(), 1), | 953 CreateNodeId(client_.id(), 1), |
982 2)); | 954 2)); |
983 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | 955 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
984 | 956 |
985 // Client 2 should get a hierarchy change that includes the new nodes as it | 957 // Client 2 should get a hierarchy change that includes the new nodes as it |
986 // has not yet seen them. | 958 // has not yet seen them. |
987 client2_.DoRunLoopUntilChangesCount(1); | 959 client2_.DoRunLoopUntilChangesCount(1); |
988 Changes changes(client2_.GetAndClearChanges()); | 960 Changes changes(client2_.GetAndClearChanges()); |
989 ASSERT_EQ(1u, changes.size()); | 961 ASSERT_EQ(1u, changes.size()); |
990 EXPECT_EQ( | 962 EXPECT_EQ( |
991 "HierarchyChanged change_id=2 node=1,1 new_parent=0,1 old_parent=null", | 963 "HierarchyChanged change_id=2 node=1,1 new_parent=0,1 old_parent=null", |
992 changes[0]); | 964 changes[0]); |
993 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); | 965 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); |
994 ASSERT_EQ(2u, nodes.size()); | 966 ASSERT_EQ(2u, nodes.size()); |
995 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); | 967 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); |
996 EXPECT_EQ("node=1,11 parent=1,1 view=null", nodes[1].ToString()); | 968 EXPECT_EQ("node=1,11 parent=1,1 view=null", nodes[1].ToString()); |
997 } | 969 } |
998 | 970 |
999 // Remove 1 from the root. | 971 // Remove 1 from the root. |
1000 { | 972 { |
1001 AllocationScope scope; | |
1002 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), | 973 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), |
1003 CreateNodeId(client_.id(), 1), | 974 CreateNodeId(client_.id(), 1), |
1004 3)); | 975 3)); |
1005 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | 976 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
1006 | 977 |
1007 client2_.DoRunLoopUntilChangesCount(1); | 978 client2_.DoRunLoopUntilChangesCount(1); |
1008 Changes changes(client2_.GetAndClearChanges()); | 979 Changes changes(client2_.GetAndClearChanges()); |
1009 ASSERT_EQ(1u, changes.size()); | 980 ASSERT_EQ(1u, changes.size()); |
1010 EXPECT_EQ( | 981 EXPECT_EQ( |
1011 "HierarchyChanged change_id=3 node=1,1 new_parent=null old_parent=0,1", | 982 "HierarchyChanged change_id=3 node=1,1 new_parent=null old_parent=0,1", |
1012 changes[0]); | 983 changes[0]); |
1013 } | 984 } |
1014 | 985 |
1015 // Create another node, 111, parent it to 11. | 986 // Create another node, 111, parent it to 11. |
1016 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 111)); | 987 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 111)); |
1017 { | 988 { |
1018 AllocationScope scope; | |
1019 ASSERT_TRUE(AddNode(view_manager_.get(), | 989 ASSERT_TRUE(AddNode(view_manager_.get(), |
1020 CreateNodeId(client_.id(), 11), | 990 CreateNodeId(client_.id(), 11), |
1021 CreateNodeId(client_.id(), 111), | 991 CreateNodeId(client_.id(), 111), |
1022 4)); | 992 4)); |
1023 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | 993 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
1024 | 994 |
1025 client2_.DoRunLoopUntilChangesCount(1); | 995 client2_.DoRunLoopUntilChangesCount(1); |
1026 Changes changes(client2_.GetAndClearChanges()); | 996 Changes changes(client2_.GetAndClearChanges()); |
1027 ASSERT_EQ(1u, changes.size()); | 997 ASSERT_EQ(1u, changes.size()); |
1028 // Even though 11 isn't attached to the root client 2 is still notified of | 998 // Even though 11 isn't attached to the root client 2 is still notified of |
(...skipping 27 matching lines...) Expand all Loading... |
1056 TEST_F(ViewManagerConnectionTest, NodeHierarchyChangedAddingKnownToUnknown) { | 1026 TEST_F(ViewManagerConnectionTest, NodeHierarchyChangedAddingKnownToUnknown) { |
1057 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no | 1027 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no |
1058 // parent). | 1028 // parent). |
1059 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 1029 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
1060 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 11)); | 1030 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 11)); |
1061 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | 1031 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
1062 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 21)); | 1032 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 21)); |
1063 | 1033 |
1064 // Set up the hierarchy. | 1034 // Set up the hierarchy. |
1065 { | 1035 { |
1066 AllocationScope scope; | |
1067 ASSERT_TRUE(AddNode(view_manager_.get(), | 1036 ASSERT_TRUE(AddNode(view_manager_.get(), |
1068 CreateNodeId(0, 1), | 1037 CreateNodeId(0, 1), |
1069 CreateNodeId(client_.id(), 1), | 1038 CreateNodeId(client_.id(), 1), |
1070 1)); | 1039 1)); |
1071 ASSERT_TRUE(AddNode(view_manager_.get(), | 1040 ASSERT_TRUE(AddNode(view_manager_.get(), |
1072 CreateNodeId(client_.id(), 1), | 1041 CreateNodeId(client_.id(), 1), |
1073 CreateNodeId(client_.id(), 11), | 1042 CreateNodeId(client_.id(), 11), |
1074 2)); | 1043 2)); |
1075 ASSERT_TRUE(AddNode(view_manager_.get(), | 1044 ASSERT_TRUE(AddNode(view_manager_.get(), |
1076 CreateNodeId(client_.id(), 2), | 1045 CreateNodeId(client_.id(), 2), |
1077 CreateNodeId(client_.id(), 21), | 1046 CreateNodeId(client_.id(), 21), |
1078 3)); | 1047 3)); |
1079 } | 1048 } |
1080 | 1049 |
1081 EstablishSecondConnection(); | 1050 EstablishSecondConnection(); |
1082 | 1051 |
1083 // Remove 11. | 1052 // Remove 11. |
1084 { | 1053 { |
1085 AllocationScope scope; | |
1086 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), | 1054 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), |
1087 CreateNodeId(client_.id(), 11), | 1055 CreateNodeId(client_.id(), 11), |
1088 4)); | 1056 4)); |
1089 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | 1057 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
1090 | 1058 |
1091 client2_.DoRunLoopUntilChangesCount(1); | 1059 client2_.DoRunLoopUntilChangesCount(1); |
1092 Changes changes(client2_.GetAndClearChanges()); | 1060 Changes changes(client2_.GetAndClearChanges()); |
1093 ASSERT_EQ(1u, changes.size()); | 1061 ASSERT_EQ(1u, changes.size()); |
1094 EXPECT_EQ( | 1062 EXPECT_EQ( |
1095 "HierarchyChanged change_id=4 node=1,11 new_parent=null old_parent=1,1", | 1063 "HierarchyChanged change_id=4 node=1,11 new_parent=null old_parent=1,1", |
1096 changes[0]); | 1064 changes[0]); |
1097 EXPECT_TRUE(client2_.hierarchy_changed_nodes().empty()); | 1065 EXPECT_TRUE(client2_.hierarchy_changed_nodes().empty()); |
1098 } | 1066 } |
1099 | 1067 |
1100 // Add 11 to 21. As client2 knows about 11 it should receive the new | 1068 // Add 11 to 21. As client2 knows about 11 it should receive the new |
1101 // hierarchy. | 1069 // hierarchy. |
1102 { | 1070 { |
1103 AllocationScope scope; | |
1104 ASSERT_TRUE(AddNode(view_manager_.get(), | 1071 ASSERT_TRUE(AddNode(view_manager_.get(), |
1105 CreateNodeId(client_.id(), 21), | 1072 CreateNodeId(client_.id(), 21), |
1106 CreateNodeId(client_.id(), 11), | 1073 CreateNodeId(client_.id(), 11), |
1107 5)); | 1074 5)); |
1108 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | 1075 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
1109 | 1076 |
1110 client2_.DoRunLoopUntilChangesCount(1); | 1077 client2_.DoRunLoopUntilChangesCount(1); |
1111 Changes changes(client2_.GetAndClearChanges()); | 1078 Changes changes(client2_.GetAndClearChanges()); |
1112 ASSERT_EQ(1u, changes.size()); | 1079 ASSERT_EQ(1u, changes.size()); |
1113 EXPECT_EQ( | 1080 EXPECT_EQ( |
1114 "HierarchyChanged change_id=5 node=1,11 new_parent=1,21 " | 1081 "HierarchyChanged change_id=5 node=1,11 new_parent=1,21 " |
1115 "old_parent=null", changes[0]); | 1082 "old_parent=null", changes[0]); |
1116 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); | 1083 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); |
1117 ASSERT_EQ(2u, nodes.size()); | 1084 ASSERT_EQ(2u, nodes.size()); |
1118 EXPECT_EQ("node=1,2 parent=null view=null", nodes[0].ToString()); | 1085 EXPECT_EQ("node=1,2 parent=null view=null", nodes[0].ToString()); |
1119 EXPECT_EQ("node=1,21 parent=1,2 view=null", nodes[1].ToString()); | 1086 EXPECT_EQ("node=1,21 parent=1,2 view=null", nodes[1].ToString()); |
1120 } | 1087 } |
1121 } | 1088 } |
1122 | 1089 |
1123 // Verifies connection on told descendants of the root when connecting. | 1090 // Verifies connection on told descendants of the root when connecting. |
1124 TEST_F(ViewManagerConnectionTest, GetInitialNodesOnInit) { | 1091 TEST_F(ViewManagerConnectionTest, GetInitialNodesOnInit) { |
1125 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 21)); | 1092 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 21)); |
1126 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 3)); | 1093 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 3)); |
1127 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 1094 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
1128 | 1095 |
1129 // Make 3 a child of 21. | 1096 // Make 3 a child of 21. |
1130 { | 1097 { |
1131 AllocationScope scope; | |
1132 ASSERT_TRUE(AddNode(view_manager_.get(), | 1098 ASSERT_TRUE(AddNode(view_manager_.get(), |
1133 CreateNodeId(client_.id(), 21), | 1099 CreateNodeId(client_.id(), 21), |
1134 CreateNodeId(client_.id(), 3), | 1100 CreateNodeId(client_.id(), 3), |
1135 1)); | 1101 1)); |
1136 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | 1102 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
1137 } | 1103 } |
1138 | 1104 |
1139 // Make 21 a child of the root. | 1105 // Make 21 a child of the root. |
1140 { | 1106 { |
1141 AllocationScope scope; | |
1142 ASSERT_TRUE(AddNode(view_manager_.get(), | 1107 ASSERT_TRUE(AddNode(view_manager_.get(), |
1143 CreateNodeId(0, 1), | 1108 CreateNodeId(0, 1), |
1144 CreateNodeId(client_.id(), 21), | 1109 CreateNodeId(client_.id(), 21), |
1145 2)); | 1110 2)); |
1146 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | 1111 ASSERT_TRUE(client_.GetAndClearChanges().empty()); |
1147 } | 1112 } |
1148 | 1113 |
1149 EstablishSecondConnection(); | 1114 EstablishSecondConnection(); |
1150 // Should get notification of children of the root. | 1115 // Should get notification of children of the root. |
1151 const std::vector<TestNode>& nodes(client2_.initial_nodes()); | 1116 const std::vector<TestNode>& nodes(client2_.initial_nodes()); |
1152 ASSERT_EQ(3u, nodes.size()); | 1117 ASSERT_EQ(3u, nodes.size()); |
1153 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString()); | 1118 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString()); |
1154 EXPECT_EQ("node=1,21 parent=0,1 view=null", nodes[1].ToString()); | 1119 EXPECT_EQ("node=1,21 parent=0,1 view=null", nodes[1].ToString()); |
1155 EXPECT_EQ("node=1,3 parent=1,21 view=null", nodes[2].ToString()); | 1120 EXPECT_EQ("node=1,3 parent=1,21 view=null", nodes[2].ToString()); |
1156 } | 1121 } |
1157 | 1122 |
1158 // Verifies DeleteNode works. | 1123 // Verifies DeleteNode works. |
1159 TEST_F(ViewManagerConnectionTest, DeleteNode) { | 1124 TEST_F(ViewManagerConnectionTest, DeleteNode) { |
1160 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 1125 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
1161 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | 1126 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
1162 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 1127 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
1163 | 1128 |
1164 EstablishSecondConnection(); | 1129 EstablishSecondConnection(); |
1165 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); | 1130 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); |
1166 | 1131 |
1167 // Make 2 a child of 1. | 1132 // Make 2 a child of 1. |
1168 { | 1133 { |
1169 AllocationScope scope; | |
1170 ASSERT_TRUE(AddNode(view_manager_.get(), | 1134 ASSERT_TRUE(AddNode(view_manager_.get(), |
1171 CreateNodeId(client_.id(), 1), | 1135 CreateNodeId(client_.id(), 1), |
1172 CreateNodeId(client_.id(), 2), | 1136 CreateNodeId(client_.id(), 2), |
1173 1)); | 1137 1)); |
1174 Changes changes(client_.GetAndClearChanges()); | 1138 Changes changes(client_.GetAndClearChanges()); |
1175 ASSERT_TRUE(changes.empty()); | 1139 ASSERT_TRUE(changes.empty()); |
1176 | 1140 |
1177 client2_.DoRunLoopUntilChangesCount(1); | 1141 client2_.DoRunLoopUntilChangesCount(1); |
1178 changes = client2_.GetAndClearChanges(); | 1142 changes = client2_.GetAndClearChanges(); |
1179 ASSERT_EQ(1u, changes.size()); | 1143 ASSERT_EQ(1u, changes.size()); |
1180 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); | 1144 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); |
1181 } | 1145 } |
1182 | 1146 |
1183 // Add 1 to the root | 1147 // Add 1 to the root |
1184 { | 1148 { |
1185 AllocationScope scope; | |
1186 ASSERT_TRUE(AddNode(view_manager_.get(), | 1149 ASSERT_TRUE(AddNode(view_manager_.get(), |
1187 CreateNodeId(0, 1), | 1150 CreateNodeId(0, 1), |
1188 CreateNodeId(client_.id(), 1), | 1151 CreateNodeId(client_.id(), 1), |
1189 2)); | 1152 2)); |
1190 Changes changes(client_.GetAndClearChanges()); | 1153 Changes changes(client_.GetAndClearChanges()); |
1191 ASSERT_TRUE(changes.empty()); | 1154 ASSERT_TRUE(changes.empty()); |
1192 | 1155 |
1193 client2_.DoRunLoopUntilChangesCount(1); | 1156 client2_.DoRunLoopUntilChangesCount(1); |
1194 changes = client2_.GetAndClearChanges(); | 1157 changes = client2_.GetAndClearChanges(); |
1195 ASSERT_EQ(1u, changes.size()); | 1158 ASSERT_EQ(1u, changes.size()); |
1196 EXPECT_EQ( | 1159 EXPECT_EQ( |
1197 "HierarchyChanged change_id=2 node=1,1 new_parent=0,1 old_parent=null", | 1160 "HierarchyChanged change_id=2 node=1,1 new_parent=0,1 old_parent=null", |
1198 changes[0]); | 1161 changes[0]); |
1199 } | 1162 } |
1200 | 1163 |
1201 // Delete 1. | 1164 // Delete 1. |
1202 { | 1165 { |
1203 AllocationScope scope; | |
1204 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 1))); | 1166 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 1))); |
1205 Changes changes(client_.GetAndClearChanges()); | 1167 Changes changes(client_.GetAndClearChanges()); |
1206 ASSERT_TRUE(changes.empty()); | 1168 ASSERT_TRUE(changes.empty()); |
1207 | 1169 |
1208 client2_.DoRunLoopUntilChangesCount(1); | 1170 client2_.DoRunLoopUntilChangesCount(1); |
1209 changes = client2_.GetAndClearChanges(); | 1171 changes = client2_.GetAndClearChanges(); |
1210 ASSERT_EQ(1u, changes.size()); | 1172 ASSERT_EQ(1u, changes.size()); |
1211 EXPECT_EQ("NodeDeleted change_id=3 node=1,1", changes[0]); | 1173 EXPECT_EQ("NodeDeleted change_id=3 node=1,1", changes[0]); |
1212 } | 1174 } |
1213 } | 1175 } |
(...skipping 15 matching lines...) Expand all Loading... |
1229 // Verifies if a node was deleted and then reused that other clients are | 1191 // Verifies if a node was deleted and then reused that other clients are |
1230 // properly notified. | 1192 // properly notified. |
1231 TEST_F(ViewManagerConnectionTest, ReusedDeletedId) { | 1193 TEST_F(ViewManagerConnectionTest, ReusedDeletedId) { |
1232 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 1194 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
1233 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 1195 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
1234 | 1196 |
1235 EstablishSecondConnection(); | 1197 EstablishSecondConnection(); |
1236 | 1198 |
1237 // Make 1 a child of the root. | 1199 // Make 1 a child of the root. |
1238 { | 1200 { |
1239 AllocationScope scope; | |
1240 ASSERT_TRUE(AddNode(view_manager_.get(), | 1201 ASSERT_TRUE(AddNode(view_manager_.get(), |
1241 CreateNodeId(0, 1), | 1202 CreateNodeId(0, 1), |
1242 CreateNodeId(client_.id(), 1), | 1203 CreateNodeId(client_.id(), 1), |
1243 1)); | 1204 1)); |
1244 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 1205 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
1245 | 1206 |
1246 client2_.DoRunLoopUntilChangesCount(1); | 1207 client2_.DoRunLoopUntilChangesCount(1); |
1247 Changes changes = client2_.GetAndClearChanges(); | 1208 Changes changes = client2_.GetAndClearChanges(); |
1248 EXPECT_EQ( | 1209 EXPECT_EQ( |
1249 "HierarchyChanged change_id=1 node=1,1 new_parent=0,1 old_parent=null", | 1210 "HierarchyChanged change_id=1 node=1,1 new_parent=0,1 old_parent=null", |
1250 changes[0]); | 1211 changes[0]); |
1251 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); | 1212 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); |
1252 ASSERT_EQ(1u, nodes.size()); | 1213 ASSERT_EQ(1u, nodes.size()); |
1253 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); | 1214 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); |
1254 } | 1215 } |
1255 | 1216 |
1256 // Delete 1. | 1217 // Delete 1. |
1257 { | 1218 { |
1258 AllocationScope scope; | |
1259 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 1))); | 1219 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 1))); |
1260 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 1220 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
1261 | 1221 |
1262 client2_.DoRunLoopUntilChangesCount(1); | 1222 client2_.DoRunLoopUntilChangesCount(1); |
1263 Changes changes = client2_.GetAndClearChanges(); | 1223 Changes changes = client2_.GetAndClearChanges(); |
1264 ASSERT_EQ(1u, changes.size()); | 1224 ASSERT_EQ(1u, changes.size()); |
1265 EXPECT_EQ("NodeDeleted change_id=2 node=1,1", changes[0]); | 1225 EXPECT_EQ("NodeDeleted change_id=2 node=1,1", changes[0]); |
1266 } | 1226 } |
1267 | 1227 |
1268 // Create 1 again, and add it back to the root. Should get the same | 1228 // Create 1 again, and add it back to the root. Should get the same |
1269 // notification. | 1229 // notification. |
1270 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 1230 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
1271 { | 1231 { |
1272 AllocationScope scope; | |
1273 ASSERT_TRUE(AddNode(view_manager_.get(), | 1232 ASSERT_TRUE(AddNode(view_manager_.get(), |
1274 CreateNodeId(0, 1), | 1233 CreateNodeId(0, 1), |
1275 CreateNodeId(client_.id(), 1), | 1234 CreateNodeId(client_.id(), 1), |
1276 3)); | 1235 3)); |
1277 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 1236 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
1278 | 1237 |
1279 client2_.DoRunLoopUntilChangesCount(1); | 1238 client2_.DoRunLoopUntilChangesCount(1); |
1280 Changes changes = client2_.GetAndClearChanges(); | 1239 Changes changes = client2_.GetAndClearChanges(); |
1281 EXPECT_EQ( | 1240 EXPECT_EQ( |
1282 "HierarchyChanged change_id=3 node=1,1 new_parent=0,1 old_parent=null", | 1241 "HierarchyChanged change_id=3 node=1,1 new_parent=0,1 old_parent=null", |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1464 4)); | 1423 4)); |
1465 | 1424 |
1466 // Attach view to node 11 in the first connection. | 1425 // Attach view to node 11 in the first connection. |
1467 ASSERT_TRUE(CreateView(view_manager_.get(), 1, 51)); | 1426 ASSERT_TRUE(CreateView(view_manager_.get(), 1, 51)); |
1468 ASSERT_TRUE(SetView(view_manager_.get(), | 1427 ASSERT_TRUE(SetView(view_manager_.get(), |
1469 CreateNodeId(client_.id(), 11), | 1428 CreateNodeId(client_.id(), 11), |
1470 CreateViewId(client_.id(), 51))); | 1429 CreateViewId(client_.id(), 51))); |
1471 | 1430 |
1472 // Verifies GetNodeTree() on the root. | 1431 // Verifies GetNodeTree() on the root. |
1473 { | 1432 { |
1474 AllocationScope scope; | |
1475 std::vector<TestNode> nodes; | 1433 std::vector<TestNode> nodes; |
1476 GetNodeTree(view_manager2_.get(), CreateNodeId(0, 1), &nodes); | 1434 GetNodeTree(view_manager2_.get(), CreateNodeId(0, 1), &nodes); |
1477 ASSERT_EQ(5u, nodes.size()); | 1435 ASSERT_EQ(5u, nodes.size()); |
1478 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString()); | 1436 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString()); |
1479 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[1].ToString()); | 1437 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[1].ToString()); |
1480 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[2].ToString()); | 1438 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[2].ToString()); |
1481 EXPECT_EQ("node=2,2 parent=0,1 view=null", nodes[3].ToString()); | 1439 EXPECT_EQ("node=2,2 parent=0,1 view=null", nodes[3].ToString()); |
1482 EXPECT_EQ("node=2,3 parent=0,1 view=null", nodes[4].ToString()); | 1440 EXPECT_EQ("node=2,3 parent=0,1 view=null", nodes[4].ToString()); |
1483 } | 1441 } |
1484 | 1442 |
1485 // Verifies GetNodeTree() on the node 1,1. | 1443 // Verifies GetNodeTree() on the node 1,1. |
1486 { | 1444 { |
1487 AllocationScope scope; | |
1488 std::vector<TestNode> nodes; | 1445 std::vector<TestNode> nodes; |
1489 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); | 1446 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); |
1490 ASSERT_EQ(2u, nodes.size()); | 1447 ASSERT_EQ(2u, nodes.size()); |
1491 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); | 1448 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); |
1492 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); | 1449 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); |
1493 } | 1450 } |
1494 } | 1451 } |
1495 | 1452 |
1496 TEST_F(ViewManagerConnectionTest, SetNodeBounds) { | 1453 TEST_F(ViewManagerConnectionTest, SetNodeBounds) { |
1497 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 1454 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
1498 ASSERT_TRUE(AddNode(view_manager_.get(), | 1455 ASSERT_TRUE(AddNode(view_manager_.get(), |
1499 CreateNodeId(0, 1), | 1456 CreateNodeId(0, 1), |
1500 CreateNodeId(1, 1), | 1457 CreateNodeId(1, 1), |
1501 1)); | 1458 1)); |
1502 EstablishSecondConnection(); | 1459 EstablishSecondConnection(); |
1503 | 1460 |
1504 AllocationScope scope; | |
1505 ASSERT_TRUE(SetNodeBounds(view_manager_.get(), | 1461 ASSERT_TRUE(SetNodeBounds(view_manager_.get(), |
1506 CreateNodeId(1, 1), | 1462 CreateNodeId(1, 1), |
1507 gfx::Rect(0, 0, 100, 100))); | 1463 gfx::Rect(0, 0, 100, 100))); |
1508 | 1464 |
1509 client2_.DoRunLoopUntilChangesCount(1); | 1465 client2_.DoRunLoopUntilChangesCount(1); |
1510 Changes changes(client2_.GetAndClearChanges()); | 1466 Changes changes(client2_.GetAndClearChanges()); |
1511 ASSERT_EQ(1u, changes.size()); | 1467 ASSERT_EQ(1u, changes.size()); |
1512 EXPECT_EQ("BoundsChanged node=1,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100", | 1468 EXPECT_EQ("BoundsChanged node=1,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100", |
1513 changes[0]); | 1469 changes[0]); |
1514 | 1470 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1650 | 1606 |
1651 // Parent 11 to 10. | 1607 // Parent 11 to 10. |
1652 ASSERT_TRUE(background_connection_->AddNode(CreateNodeId(2, 10), | 1608 ASSERT_TRUE(background_connection_->AddNode(CreateNodeId(2, 10), |
1653 CreateNodeId(2, 11), 3)); | 1609 CreateNodeId(2, 11), 3)); |
1654 // Remove 11 from 10. | 1610 // Remove 11 from 10. |
1655 ASSERT_TRUE(background_connection_->RemoveNodeFromParent( | 1611 ASSERT_TRUE(background_connection_->RemoveNodeFromParent( |
1656 CreateNodeId(2, 11), 4)); | 1612 CreateNodeId(2, 11), 4)); |
1657 | 1613 |
1658 // Verify nothing was actually removed. | 1614 // Verify nothing was actually removed. |
1659 { | 1615 { |
1660 AllocationScope scope; | |
1661 std::vector<TestNode> nodes; | 1616 std::vector<TestNode> nodes; |
1662 GetNodeTree(view_manager_.get(), CreateNodeId(0, 1), &nodes); | 1617 GetNodeTree(view_manager_.get(), CreateNodeId(0, 1), &nodes); |
1663 ASSERT_EQ(3u, nodes.size()); | 1618 ASSERT_EQ(3u, nodes.size()); |
1664 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString()); | 1619 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString()); |
1665 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[1].ToString()); | 1620 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[1].ToString()); |
1666 EXPECT_EQ("node=1,2 parent=0,1 view=null", nodes[2].ToString()); | 1621 EXPECT_EQ("node=1,2 parent=0,1 view=null", nodes[2].ToString()); |
1667 } | 1622 } |
1668 } | 1623 } |
1669 | 1624 |
1670 // Verify SetView fails for nodes that are not descendants of the roots. | 1625 // Verify SetView fails for nodes that are not descendants of the roots. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1705 CreateNodeId(0, 1), | 1660 CreateNodeId(0, 1), |
1706 CreateNodeId(client_.id(), 1), | 1661 CreateNodeId(client_.id(), 1), |
1707 1)); | 1662 1)); |
1708 ASSERT_TRUE(AddNode(view_manager_.get(), | 1663 ASSERT_TRUE(AddNode(view_manager_.get(), |
1709 CreateNodeId(0, 1), | 1664 CreateNodeId(0, 1), |
1710 CreateNodeId(client_.id(), 2), | 1665 CreateNodeId(client_.id(), 2), |
1711 2)); | 1666 2)); |
1712 | 1667 |
1713 ASSERT_NO_FATAL_FAILURE(EstablishBackgroundConnectionWithRoot1()); | 1668 ASSERT_NO_FATAL_FAILURE(EstablishBackgroundConnectionWithRoot1()); |
1714 | 1669 |
1715 AllocationScope scope; | |
1716 std::vector<TestNode> nodes; | 1670 std::vector<TestNode> nodes; |
1717 | 1671 |
1718 // Should get nothing for the root. | 1672 // Should get nothing for the root. |
1719 background_connection_->GetNodeTree(CreateNodeId(0, 1), &nodes); | 1673 background_connection_->GetNodeTree(CreateNodeId(0, 1), &nodes); |
1720 ASSERT_TRUE(nodes.empty()); | 1674 ASSERT_TRUE(nodes.empty()); |
1721 | 1675 |
1722 // Should get nothing for node 2. | 1676 // Should get nothing for node 2. |
1723 background_connection_->GetNodeTree(CreateNodeId(1, 2), &nodes); | 1677 background_connection_->GetNodeTree(CreateNodeId(1, 2), &nodes); |
1724 ASSERT_TRUE(nodes.empty()); | 1678 ASSERT_TRUE(nodes.empty()); |
1725 | 1679 |
(...skipping 15 matching lines...) Expand all Loading... |
1741 ASSERT_EQ(1u, changes.size()); | 1695 ASSERT_EQ(1u, changes.size()); |
1742 EXPECT_EQ("OnConnectionEstablished", changes[0]); | 1696 EXPECT_EQ("OnConnectionEstablished", changes[0]); |
1743 } | 1697 } |
1744 | 1698 |
1745 // TODO(sky): add coverage of test that destroys connections and ensures other | 1699 // TODO(sky): add coverage of test that destroys connections and ensures other |
1746 // connections get deletion notification (or advanced server id). | 1700 // connections get deletion notification (or advanced server id). |
1747 | 1701 |
1748 } // namespace service | 1702 } // namespace service |
1749 } // namespace view_manager | 1703 } // namespace view_manager |
1750 } // namespace mojo | 1704 } // namespace mojo |
OLD | NEW |