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

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

Issue 1138073007: Nukes the windowmanager interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "components/view_manager/ids.h" 8 #include "components/view_manager/ids.h"
9 #include "components/view_manager/public/interfaces/view_manager.mojom.h" 9 #include "components/view_manager/public/interfaces/view_manager.mojom.h"
10 #include "components/view_manager/public/interfaces/view_manager_root.mojom.h"
10 #include "components/view_manager/test_change_tracker.h" 11 #include "components/view_manager/test_change_tracker.h"
11 #include "components/window_manager/public/interfaces/window_manager.mojom.h"
12 #include "components/window_manager/public/interfaces/window_manager_internal.mo jom.h"
13 #include "mojo/application/application_test_base_chromium.h" 12 #include "mojo/application/application_test_base_chromium.h"
14 #include "mojo/application/public/cpp/application_delegate.h" 13 #include "mojo/application/public/cpp/application_delegate.h"
15 #include "mojo/application/public/cpp/application_impl.h" 14 #include "mojo/application/public/cpp/application_impl.h"
16 15
17 using mojo::ApplicationConnection; 16 using mojo::ApplicationConnection;
18 using mojo::ApplicationDelegate; 17 using mojo::ApplicationDelegate;
19 using mojo::Array; 18 using mojo::Array;
20 using mojo::Callback; 19 using mojo::Callback;
21 using mojo::ConnectionSpecificId; 20 using mojo::ConnectionSpecificId;
22 using mojo::ERROR_CODE_NONE; 21 using mojo::ERROR_CODE_NONE;
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 if (run_loop_.get()) 387 if (run_loop_.get())
389 run_loop_->Quit(); 388 run_loop_->Quit();
390 } 389 }
391 390
392 scoped_ptr<ViewManagerClientImpl> client_impl_; 391 scoped_ptr<ViewManagerClientImpl> client_impl_;
393 scoped_ptr<base::RunLoop> run_loop_; 392 scoped_ptr<base::RunLoop> run_loop_;
394 393
395 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientFactory); 394 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientFactory);
396 }; 395 };
397 396
398 class ViewManagerServiceAppTest 397 class ViewManagerServiceAppTest : public mojo::test::ApplicationTestBase,
399 : public mojo::test::ApplicationTestBase, 398 public ApplicationDelegate {
400 public ApplicationDelegate,
401 public mojo::InterfaceFactory<mojo::WindowManagerInternal>,
402 public mojo::WindowManagerInternal {
403 public: 399 public:
404 ViewManagerServiceAppTest() : wm_internal_binding_(this) {} 400 ViewManagerServiceAppTest() {}
405 ~ViewManagerServiceAppTest() override {} 401 ~ViewManagerServiceAppTest() override {}
406 402
407 protected: 403 protected:
408 // Returns the changes from the various connections. 404 // Returns the changes from the various connections.
409 std::vector<Change>* changes1() { return vm_client1_.tracker()->changes(); } 405 std::vector<Change>* changes1() { return vm_client1_->tracker()->changes(); }
410 std::vector<Change>* changes2() { return vm_client2_->tracker()->changes(); } 406 std::vector<Change>* changes2() { return vm_client2_->tracker()->changes(); }
411 std::vector<Change>* changes3() { return vm_client3_->tracker()->changes(); } 407 std::vector<Change>* changes3() { return vm_client3_->tracker()->changes(); }
412 408
413 // Various connections. |vm1()|, being the first connection, has special 409 // Various connections. |vm1()|, being the first connection, has special
414 // permissions (it's treated as the window manager). 410 // permissions (it's treated as the window manager).
415 ViewManagerService* vm1() { return vm1_.get(); } 411 ViewManagerService* vm1() { return vm1_.get(); }
416 ViewManagerService* vm2() { return vm_client2_->service(); } 412 ViewManagerService* vm2() { return vm_client2_->service(); }
417 ViewManagerService* vm3() { return vm_client3_->service(); } 413 ViewManagerService* vm3() { return vm_client3_->service(); }
418 414
419 void EstablishSecondConnectionWithRoot(Id root_id) { 415 void EstablishSecondConnectionWithRoot(Id root_id) {
(...skipping 28 matching lines...) Expand all
448 return nullptr; 444 return nullptr;
449 } 445 }
450 scoped_ptr<ViewManagerClientImpl> client = 446 scoped_ptr<ViewManagerClientImpl> client =
451 client_factory_.WaitForInstance(); 447 client_factory_.WaitForInstance();
452 if (!client.get()) { 448 if (!client.get()) {
453 ADD_FAILURE() << "WaitForInstance failed"; 449 ADD_FAILURE() << "WaitForInstance failed";
454 return nullptr; 450 return nullptr;
455 } 451 }
456 client->WaitForOnEmbed(); 452 client->WaitForOnEmbed();
457 453
458 const std::string expected_creator = 454 EXPECT_EQ("OnEmbed creator=" + application_impl()->url(),
459 owner == vm1() ? "mojo:window_manager" : application_impl()->url();
460 EXPECT_EQ("OnEmbed creator=" + expected_creator,
461 SingleChangeToDescription(*client->tracker()->changes())); 455 SingleChangeToDescription(*client->tracker()->changes()));
462 return client.Pass(); 456 return client.Pass();
463 } 457 }
464 458
465 // ApplicationTestBase: 459 // ApplicationTestBase:
466 ApplicationDelegate* GetApplicationDelegate() override { return this; } 460 ApplicationDelegate* GetApplicationDelegate() override { return this; }
467 void SetUp() override { 461 void SetUp() override {
468 ApplicationTestBase::SetUp(); 462 ApplicationTestBase::SetUp();
469 ApplicationConnection* vm_connection = 463 ApplicationConnection* vm_connection =
470 application_impl()->ConnectToApplication("mojo:view_manager"); 464 application_impl()->ConnectToApplication("mojo:view_manager");
471 vm_connection->AddService(this);
472 vm_connection->ConnectToService(&vm1_); 465 vm_connection->ConnectToService(&vm1_);
473 vm_connection->ConnectToService(&wm_internal_client_); 466 vm_connection->ConnectToService(&view_manager_root_);
474 // Spin a run loop until the view manager service sends us the 467 vm_connection->AddService(&client_factory_);
475 // ViewManagerClient pipe to use for the "window manager" connection. 468 vm_client1_ = client_factory_.WaitForInstance();
476 view_manager_setup_run_loop_.reset(new base::RunLoop); 469 ASSERT_TRUE(vm_client1_);
477 view_manager_setup_run_loop_->Run();
478 view_manager_setup_run_loop_ = nullptr;
479 // Next we should get an embed call on the "window manager" client. 470 // Next we should get an embed call on the "window manager" client.
480 vm_client1_.WaitForIncomingMethodCall(); 471 vm_client1_->WaitForIncomingMethodCall();
481 ASSERT_EQ(1u, changes1()->size()); 472 ASSERT_EQ(1u, changes1()->size());
482 EXPECT_EQ(CHANGE_TYPE_EMBED, (*changes1())[0].type); 473 EXPECT_EQ(CHANGE_TYPE_EMBED, (*changes1())[0].type);
483 // All these tests assume 1 for the client id. The only real assertion here 474 // All these tests assume 1 for the client id. The only real assertion here
484 // is the client id is not zero, but adding this as rest of code here 475 // is the client id is not zero, but adding this as rest of code here
485 // assumes 1. 476 // assumes 1.
486 ASSERT_EQ(1, (*changes1())[0].connection_id); 477 ASSERT_EQ(1, (*changes1())[0].connection_id);
487 changes1()->clear(); 478 changes1()->clear();
488 } 479 }
489 480
490 // ApplicationDelegate implementation. 481 // ApplicationDelegate implementation.
491 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { 482 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
492 connection->AddService(&client_factory_); 483 connection->AddService(&client_factory_);
493 return true; 484 return true;
494 } 485 }
495 486
496 // mojo::InterfaceFactory<mojo::WindowManagerInternal> implementation. 487 scoped_ptr<ViewManagerClientImpl> vm_client1_;
497 void Create(
498 ApplicationConnection* connection,
499 mojo::InterfaceRequest<mojo::WindowManagerInternal> request) override {
500 DCHECK(!wm_internal_binding_.is_bound());
501 wm_internal_binding_.Bind(request.Pass());
502 }
503
504 // mojo::WindowManagerInternal implementation.
505 void SetViewManagerClient(
506 mojo::ScopedMessagePipeHandle view_manager_client_request) override {
507 auto typed_request = mojo::MakeRequest<mojo::ViewManagerClient>(
508 view_manager_client_request.Pass());
509 vm_client1_.Bind(typed_request.Pass());
510 view_manager_setup_run_loop_->Quit();
511 }
512 void OnAccelerator(mojo::EventPtr event) override {}
513
514 mojo::Binding<mojo::WindowManagerInternal> wm_internal_binding_;
515 mojo::WindowManagerInternalClientPtr wm_internal_client_;
516 ViewManagerClientImpl vm_client1_;
517 scoped_ptr<ViewManagerClientImpl> vm_client2_; 488 scoped_ptr<ViewManagerClientImpl> vm_client2_;
518 scoped_ptr<ViewManagerClientImpl> vm_client3_; 489 scoped_ptr<ViewManagerClientImpl> vm_client3_;
519 490
491 mojo::ViewManagerRootPtr view_manager_root_;
492
520 private: 493 private:
521 mojo::ViewManagerServicePtr vm1_; 494 mojo::ViewManagerServicePtr vm1_;
522 ViewManagerClientFactory client_factory_; 495 ViewManagerClientFactory client_factory_;
523 scoped_ptr<base::RunLoop> view_manager_setup_run_loop_;
524 496
525 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewManagerServiceAppTest); 497 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewManagerServiceAppTest);
526 }; 498 };
527 499
528 // Verifies two clients/connections get different ids. 500 // Verifies two clients/connections get different ids.
529 TEST_F(ViewManagerServiceAppTest, TwoClientsGetDifferentConnectionIds) { 501 TEST_F(ViewManagerServiceAppTest, TwoClientsGetDifferentConnectionIds) {
530 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 502 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
531 503
532 // It isn't strictly necessary that the second connection gets 2, but these 504 // It isn't strictly necessary that the second connection gets 2, but these
533 // tests are written assuming that is the case. The key thing is the 505 // tests are written assuming that is the case. The key thing is the
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 // Set up the hierarchy. 765 // Set up the hierarchy.
794 ASSERT_TRUE(AddView(vm1(), BuildViewId(0, 1), BuildViewId(1, 1))); 766 ASSERT_TRUE(AddView(vm1(), BuildViewId(0, 1), BuildViewId(1, 1)));
795 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 11))); 767 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 11)));
796 ASSERT_TRUE(AddView(vm2(), BuildViewId(2, 2), BuildViewId(2, 21))); 768 ASSERT_TRUE(AddView(vm2(), BuildViewId(2, 2), BuildViewId(2, 21)));
797 769
798 // Remove 11, should result in a hierarchy change for the root. 770 // Remove 11, should result in a hierarchy change for the root.
799 { 771 {
800 changes1()->clear(); 772 changes1()->clear();
801 ASSERT_TRUE(RemoveViewFromParent(vm2(), BuildViewId(2, 11))); 773 ASSERT_TRUE(RemoveViewFromParent(vm2(), BuildViewId(2, 11)));
802 774
803 vm_client1_.WaitForChangeCount(1); 775 vm_client1_->WaitForChangeCount(1);
804 EXPECT_EQ("HierarchyChanged view=2,11 new_parent=null old_parent=1,1", 776 EXPECT_EQ("HierarchyChanged view=2,11 new_parent=null old_parent=1,1",
805 SingleChangeToDescription(*changes1())); 777 SingleChangeToDescription(*changes1()));
806 } 778 }
807 779
808 // Add 2 to 1. 780 // Add 2 to 1.
809 { 781 {
810 changes1()->clear(); 782 changes1()->clear();
811 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 2))); 783 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 2)));
812 784
813 vm_client1_.WaitForChangeCount(1); 785 vm_client1_->WaitForChangeCount(1);
814 EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null", 786 EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null",
815 SingleChangeToDescription(*changes1())); 787 SingleChangeToDescription(*changes1()));
816 EXPECT_EQ( 788 EXPECT_EQ(
817 "[view=2,2 parent=1,1]," 789 "[view=2,2 parent=1,1],"
818 "[view=2,21 parent=2,2]", 790 "[view=2,21 parent=2,2]",
819 ChangeViewDescription(*changes1())); 791 ChangeViewDescription(*changes1()));
820 } 792 }
821 } 793 }
822 794
823 TEST_F(ViewManagerServiceAppTest, ReorderView) { 795 TEST_F(ViewManagerServiceAppTest, ReorderView) {
(...skipping 19 matching lines...) Expand all
843 ASSERT_TRUE(AddView(vm2(), view2_id, view6_id)); 815 ASSERT_TRUE(AddView(vm2(), view2_id, view6_id));
844 ASSERT_TRUE(AddView(vm2(), view1_id, view3_id)); 816 ASSERT_TRUE(AddView(vm2(), view1_id, view3_id));
845 ASSERT_TRUE(AddView(vm1(), ViewIdToTransportId(RootViewId()), view4_id)); 817 ASSERT_TRUE(AddView(vm1(), ViewIdToTransportId(RootViewId()), view4_id));
846 ASSERT_TRUE(AddView(vm1(), ViewIdToTransportId(RootViewId()), view5_id)); 818 ASSERT_TRUE(AddView(vm1(), ViewIdToTransportId(RootViewId()), view5_id));
847 ASSERT_TRUE(AddView(vm1(), ViewIdToTransportId(RootViewId()), view1_id)); 819 ASSERT_TRUE(AddView(vm1(), ViewIdToTransportId(RootViewId()), view1_id));
848 820
849 { 821 {
850 changes1()->clear(); 822 changes1()->clear();
851 ASSERT_TRUE(ReorderView(vm2(), view2_id, view3_id, ORDER_DIRECTION_ABOVE)); 823 ASSERT_TRUE(ReorderView(vm2(), view2_id, view3_id, ORDER_DIRECTION_ABOVE));
852 824
853 vm_client1_.WaitForChangeCount(1); 825 vm_client1_->WaitForChangeCount(1);
854 EXPECT_EQ("Reordered view=2,2 relative=2,3 direction=above", 826 EXPECT_EQ("Reordered view=2,2 relative=2,3 direction=above",
855 SingleChangeToDescription(*changes1())); 827 SingleChangeToDescription(*changes1()));
856 } 828 }
857 829
858 { 830 {
859 changes1()->clear(); 831 changes1()->clear();
860 ASSERT_TRUE(ReorderView(vm2(), view2_id, view3_id, ORDER_DIRECTION_BELOW)); 832 ASSERT_TRUE(ReorderView(vm2(), view2_id, view3_id, ORDER_DIRECTION_BELOW));
861 833
862 vm_client1_.WaitForChangeCount(1); 834 vm_client1_->WaitForChangeCount(1);
863 EXPECT_EQ("Reordered view=2,2 relative=2,3 direction=below", 835 EXPECT_EQ("Reordered view=2,2 relative=2,3 direction=below",
864 SingleChangeToDescription(*changes1())); 836 SingleChangeToDescription(*changes1()));
865 } 837 }
866 838
867 // view2 is already below view3. 839 // view2 is already below view3.
868 EXPECT_FALSE(ReorderView(vm2(), view2_id, view3_id, ORDER_DIRECTION_BELOW)); 840 EXPECT_FALSE(ReorderView(vm2(), view2_id, view3_id, ORDER_DIRECTION_BELOW));
869 841
870 // view4 & 5 are unknown to connection2_. 842 // view4 & 5 are unknown to connection2_.
871 EXPECT_FALSE(ReorderView(vm2(), view4_id, view5_id, ORDER_DIRECTION_ABOVE)); 843 EXPECT_FALSE(ReorderView(vm2(), view4_id, view5_id, ORDER_DIRECTION_ABOVE));
872 844
(...skipping 10 matching lines...) Expand all
883 855
884 // Verifies DeleteView works. 856 // Verifies DeleteView works.
885 TEST_F(ViewManagerServiceAppTest, DeleteView) { 857 TEST_F(ViewManagerServiceAppTest, DeleteView) {
886 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 858 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
887 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 2))); 859 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 2)));
888 860
889 // Make 2 a child of 1. 861 // Make 2 a child of 1.
890 { 862 {
891 changes1()->clear(); 863 changes1()->clear();
892 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 2))); 864 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 2)));
893 vm_client1_.WaitForChangeCount(1); 865 vm_client1_->WaitForChangeCount(1);
894 EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null", 866 EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null",
895 SingleChangeToDescription(*changes1())); 867 SingleChangeToDescription(*changes1()));
896 } 868 }
897 869
898 // Delete 2. 870 // Delete 2.
899 { 871 {
900 changes1()->clear(); 872 changes1()->clear();
901 changes2()->clear(); 873 changes2()->clear();
902 ASSERT_TRUE(DeleteView(vm2(), BuildViewId(2, 2))); 874 ASSERT_TRUE(DeleteView(vm2(), BuildViewId(2, 2)));
903 EXPECT_TRUE(changes2()->empty()); 875 EXPECT_TRUE(changes2()->empty());
904 876
905 vm_client1_.WaitForChangeCount(1); 877 vm_client1_->WaitForChangeCount(1);
906 EXPECT_EQ("ViewDeleted view=2,2", SingleChangeToDescription(*changes1())); 878 EXPECT_EQ("ViewDeleted view=2,2", SingleChangeToDescription(*changes1()));
907 } 879 }
908 } 880 }
909 881
910 // Verifies DeleteView isn't allowed from a separate connection. 882 // Verifies DeleteView isn't allowed from a separate connection.
911 TEST_F(ViewManagerServiceAppTest, DeleteViewFromAnotherConnectionDisallowed) { 883 TEST_F(ViewManagerServiceAppTest, DeleteViewFromAnotherConnectionDisallowed) {
912 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 884 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
913 EXPECT_FALSE(DeleteView(vm2(), BuildViewId(1, 1))); 885 EXPECT_FALSE(DeleteView(vm2(), BuildViewId(1, 1)));
914 } 886 }
915 887
916 // Verifies if a view was deleted and then reused that other clients are 888 // Verifies if a view was deleted and then reused that other clients are
917 // properly notified. 889 // properly notified.
918 TEST_F(ViewManagerServiceAppTest, ReuseDeletedViewId) { 890 TEST_F(ViewManagerServiceAppTest, ReuseDeletedViewId) {
919 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 891 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
920 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 2))); 892 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 2)));
921 893
922 // Add 2 to 1. 894 // Add 2 to 1.
923 { 895 {
924 changes1()->clear(); 896 changes1()->clear();
925 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 2))); 897 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 2)));
926 898
927 vm_client1_.WaitForChangeCount(1); 899 vm_client1_->WaitForChangeCount(1);
928 EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null", 900 EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null",
929 SingleChangeToDescription(*changes1())); 901 SingleChangeToDescription(*changes1()));
930 EXPECT_EQ("[view=2,2 parent=1,1]", ChangeViewDescription(*changes1())); 902 EXPECT_EQ("[view=2,2 parent=1,1]", ChangeViewDescription(*changes1()));
931 } 903 }
932 904
933 // Delete 2. 905 // Delete 2.
934 { 906 {
935 changes1()->clear(); 907 changes1()->clear();
936 ASSERT_TRUE(DeleteView(vm2(), BuildViewId(2, 2))); 908 ASSERT_TRUE(DeleteView(vm2(), BuildViewId(2, 2)));
937 909
938 vm_client1_.WaitForChangeCount(1); 910 vm_client1_->WaitForChangeCount(1);
939 EXPECT_EQ("ViewDeleted view=2,2", SingleChangeToDescription(*changes1())); 911 EXPECT_EQ("ViewDeleted view=2,2", SingleChangeToDescription(*changes1()));
940 } 912 }
941 913
942 // Create 2 again, and add it back to 1. Should get the same notification. 914 // Create 2 again, and add it back to 1. Should get the same notification.
943 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 2))); 915 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 2)));
944 { 916 {
945 changes1()->clear(); 917 changes1()->clear();
946 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 2))); 918 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 2)));
947 919
948 vm_client1_.WaitForChangeCount(1); 920 vm_client1_->WaitForChangeCount(1);
949 EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null", 921 EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null",
950 SingleChangeToDescription(*changes1())); 922 SingleChangeToDescription(*changes1()));
951 EXPECT_EQ("[view=2,2 parent=1,1]", ChangeViewDescription(*changes1())); 923 EXPECT_EQ("[view=2,2 parent=1,1]", ChangeViewDescription(*changes1()));
952 } 924 }
953 } 925 }
954 926
955 // Assertions for GetViewTree. 927 // Assertions for GetViewTree.
956 TEST_F(ViewManagerServiceAppTest, GetViewTree) { 928 TEST_F(ViewManagerServiceAppTest, GetViewTree) {
957 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 929 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
958 930
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 // Connection2 should have been told the view was deleted. 1098 // Connection2 should have been told the view was deleted.
1127 vm_client2_->WaitForChangeCount(1); 1099 vm_client2_->WaitForChangeCount(1);
1128 changes2()->clear(); 1100 changes2()->clear();
1129 1101
1130 // Create a view in the third connection and parent it to the root. 1102 // Create a view in the third connection and parent it to the root.
1131 ASSERT_TRUE(CreateView(vm3(), BuildViewId(3, 1))); 1103 ASSERT_TRUE(CreateView(vm3(), BuildViewId(3, 1)));
1132 ASSERT_TRUE(AddView(vm3(), BuildViewId(1, 1), BuildViewId(3, 1))); 1104 ASSERT_TRUE(AddView(vm3(), BuildViewId(1, 1), BuildViewId(3, 1)));
1133 1105
1134 // Connection 1 should have been told about the add (it owns the view). 1106 // Connection 1 should have been told about the add (it owns the view).
1135 { 1107 {
1136 vm_client1_.WaitForChangeCount(1); 1108 vm_client1_->WaitForChangeCount(1);
1137 EXPECT_EQ("HierarchyChanged view=3,1 new_parent=1,1 old_parent=null", 1109 EXPECT_EQ("HierarchyChanged view=3,1 new_parent=1,1 old_parent=null",
1138 SingleChangeToDescription(*changes1())); 1110 SingleChangeToDescription(*changes1()));
1139 } 1111 }
1140 1112
1141 // Embed 1,1 again. 1113 // Embed 1,1 again.
1142 { 1114 {
1143 changes3()->clear(); 1115 changes3()->clear();
1144 1116
1145 // We should get a new connection for the new embedding. 1117 // We should get a new connection for the new embedding.
1146 scoped_ptr<ViewManagerClientImpl> connection4( 1118 scoped_ptr<ViewManagerClientImpl> connection4(
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 { 1241 {
1270 vm_client2_->WaitForChangeCount(1); 1242 vm_client2_->WaitForChangeCount(1);
1271 EXPECT_EQ("VisibilityChanged view=1,2 visible=false", 1243 EXPECT_EQ("VisibilityChanged view=1,2 visible=false",
1272 SingleChangeToDescription(*changes2())); 1244 SingleChangeToDescription(*changes2()));
1273 } 1245 }
1274 1246
1275 changes1()->clear(); 1247 changes1()->clear();
1276 // Show 1,2 from connection 2, connection 1 should be notified. 1248 // Show 1,2 from connection 2, connection 1 should be notified.
1277 ASSERT_TRUE(SetViewVisibility(vm2(), BuildViewId(1, 2), true)); 1249 ASSERT_TRUE(SetViewVisibility(vm2(), BuildViewId(1, 2), true));
1278 { 1250 {
1279 vm_client1_.WaitForChangeCount(1); 1251 vm_client1_->WaitForChangeCount(1);
1280 EXPECT_EQ("VisibilityChanged view=1,2 visible=true", 1252 EXPECT_EQ("VisibilityChanged view=1,2 visible=true",
1281 SingleChangeToDescription(*changes1())); 1253 SingleChangeToDescription(*changes1()));
1282 } 1254 }
1283 1255
1284 changes2()->clear(); 1256 changes2()->clear();
1285 // Hide 1,1, connection 2 should be told the draw state changed. 1257 // Hide 1,1, connection 2 should be told the draw state changed.
1286 ASSERT_TRUE(SetViewVisibility(vm1(), BuildViewId(1, 1), false)); 1258 ASSERT_TRUE(SetViewVisibility(vm1(), BuildViewId(1, 1), false));
1287 { 1259 {
1288 vm_client2_->WaitForChangeCount(1); 1260 vm_client2_->WaitForChangeCount(1);
1289 EXPECT_EQ("DrawnStateChanged view=1,2 drawn=false", 1261 EXPECT_EQ("DrawnStateChanged view=1,2 drawn=false",
1290 SingleChangeToDescription(*changes2())); 1262 SingleChangeToDescription(*changes2()));
1291 } 1263 }
1292 1264
1293 changes2()->clear(); 1265 changes2()->clear();
1294 // Show 1,1 from connection 1. Connection 2 should see this. 1266 // Show 1,1 from connection 1. Connection 2 should see this.
1295 ASSERT_TRUE(SetViewVisibility(vm1(), BuildViewId(1, 1), true)); 1267 ASSERT_TRUE(SetViewVisibility(vm1(), BuildViewId(1, 1), true));
1296 { 1268 {
1297 vm_client2_->WaitForChangeCount(1); 1269 vm_client2_->WaitForChangeCount(1);
1298 EXPECT_EQ("DrawnStateChanged view=1,2 drawn=true", 1270 EXPECT_EQ("DrawnStateChanged view=1,2 drawn=true",
1299 SingleChangeToDescription(*changes2())); 1271 SingleChangeToDescription(*changes2()));
1300 } 1272 }
1301 1273
1302 // Change visibility of 2,3, connection 1 should see this. 1274 // Change visibility of 2,3, connection 1 should see this.
1303 changes1()->clear(); 1275 changes1()->clear();
1304 ASSERT_TRUE(SetViewVisibility(vm2(), BuildViewId(2, 3), false)); 1276 ASSERT_TRUE(SetViewVisibility(vm2(), BuildViewId(2, 3), false));
1305 { 1277 {
1306 vm_client1_.WaitForChangeCount(1); 1278 vm_client1_->WaitForChangeCount(1);
1307 EXPECT_EQ("VisibilityChanged view=2,3 visible=false", 1279 EXPECT_EQ("VisibilityChanged view=2,3 visible=false",
1308 SingleChangeToDescription(*changes1())); 1280 SingleChangeToDescription(*changes1()));
1309 } 1281 }
1310 1282
1311 changes2()->clear(); 1283 changes2()->clear();
1312 // Remove 1,1 from the root, connection 2 should see drawn state changed. 1284 // Remove 1,1 from the root, connection 2 should see drawn state changed.
1313 ASSERT_TRUE(RemoveViewFromParent(vm1(), BuildViewId(1, 1))); 1285 ASSERT_TRUE(RemoveViewFromParent(vm1(), BuildViewId(1, 1)));
1314 { 1286 {
1315 vm_client2_->WaitForChangeCount(1); 1287 vm_client2_->WaitForChangeCount(1);
1316 EXPECT_EQ("DrawnStateChanged view=1,2 drawn=false", 1288 EXPECT_EQ("DrawnStateChanged view=1,2 drawn=false",
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 EXPECT_EQ("ViewDeleted view=2,3", SingleChangeToDescription(*changes3())); 1380 EXPECT_EQ("ViewDeleted view=2,3", SingleChangeToDescription(*changes3()));
1409 } 1381 }
1410 1382
1411 // Verifies ViewManagerServiceImpl doesn't incorrectly erase from its internal 1383 // Verifies ViewManagerServiceImpl doesn't incorrectly erase from its internal
1412 // map when a view from another connection with the same view_id is removed. 1384 // map when a view from another connection with the same view_id is removed.
1413 TEST_F(ViewManagerServiceAppTest, DontCleanMapOnDestroy) { 1385 TEST_F(ViewManagerServiceAppTest, DontCleanMapOnDestroy) {
1414 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1386 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1415 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 1))); 1387 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 1)));
1416 changes1()->clear(); 1388 changes1()->clear();
1417 vm_client2_.reset(); 1389 vm_client2_.reset();
1418 vm_client1_.WaitForChangeCount(1); 1390 vm_client1_->WaitForChangeCount(1);
1419 EXPECT_EQ("OnEmbeddedAppDisconnected view=1,1", 1391 EXPECT_EQ("OnEmbeddedAppDisconnected view=1,1",
1420 SingleChangeToDescription(*changes1())); 1392 SingleChangeToDescription(*changes1()));
1421 std::vector<TestView> views; 1393 std::vector<TestView> views;
1422 GetViewTree(vm1(), BuildViewId(1, 1), &views); 1394 GetViewTree(vm1(), BuildViewId(1, 1), &views);
1423 EXPECT_FALSE(views.empty()); 1395 EXPECT_FALSE(views.empty());
1424 } 1396 }
1425 1397
1426 TEST_F(ViewManagerServiceAppTest, CloneAndAnimate) { 1398 TEST_F(ViewManagerServiceAppTest, CloneAndAnimate) {
1427 // Create connection 2 and 3. 1399 // Create connection 2 and 3.
1428 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1400 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1429 ASSERT_TRUE(AddView(vm1(), BuildViewId(0, 1), BuildViewId(1, 1))); 1401 ASSERT_TRUE(AddView(vm1(), BuildViewId(0, 1), BuildViewId(1, 1)));
1430 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 2))); 1402 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 2)));
1431 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 3))); 1403 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 3)));
1432 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 2))); 1404 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 2)));
1433 ASSERT_TRUE(AddView(vm2(), BuildViewId(2, 2), BuildViewId(2, 3))); 1405 ASSERT_TRUE(AddView(vm2(), BuildViewId(2, 2), BuildViewId(2, 3)));
1434 changes2()->clear(); 1406 changes2()->clear();
1435 1407
1436 ASSERT_TRUE(WaitForAllMessages(vm1())); 1408 ASSERT_TRUE(WaitForAllMessages(vm1()));
1437 changes1()->clear(); 1409 changes1()->clear();
1438 1410
1439 wm_internal_client_->CloneAndAnimate(BuildViewId(2, 3)); 1411 view_manager_root_->CloneAndAnimate(BuildViewId(2, 3));
1440 ASSERT_TRUE(WaitForAllMessages(vm1())); 1412 ASSERT_TRUE(WaitForAllMessages(vm1()));
1441 1413
1442 ASSERT_TRUE(WaitForAllMessages(vm1())); 1414 ASSERT_TRUE(WaitForAllMessages(vm1()));
1443 ASSERT_TRUE(WaitForAllMessages(vm2())); 1415 ASSERT_TRUE(WaitForAllMessages(vm2()));
1444 1416
1445 // No messages should have been received. 1417 // No messages should have been received.
1446 EXPECT_TRUE(changes1()->empty()); 1418 EXPECT_TRUE(changes1()->empty());
1447 EXPECT_TRUE(changes2()->empty()); 1419 EXPECT_TRUE(changes2()->empty());
1448 1420
1449 // No one should be able to see the cloned tree. 1421 // No one should be able to see the cloned tree.
1450 std::vector<TestView> views; 1422 std::vector<TestView> views;
1451 GetViewTree(vm1(), BuildViewId(1, 1), &views); 1423 GetViewTree(vm1(), BuildViewId(1, 1), &views);
1452 EXPECT_FALSE(HasClonedView(views)); 1424 EXPECT_FALSE(HasClonedView(views));
1453 views.clear(); 1425 views.clear();
1454 1426
1455 GetViewTree(vm2(), BuildViewId(1, 1), &views); 1427 GetViewTree(vm2(), BuildViewId(1, 1), &views);
1456 EXPECT_FALSE(HasClonedView(views)); 1428 EXPECT_FALSE(HasClonedView(views));
1457 } 1429 }
1458 1430
1459 // Verifies Embed() works when supplying a ViewManagerClient. 1431 // Verifies Embed() works when supplying a ViewManagerClient.
1460 TEST_F(ViewManagerServiceAppTest, EmbedSupplyingViewManagerClient) { 1432 TEST_F(ViewManagerServiceAppTest, EmbedSupplyingViewManagerClient) {
1461 ASSERT_TRUE(CreateView(vm1(), BuildViewId(1, 1))); 1433 ASSERT_TRUE(CreateView(vm1(), BuildViewId(1, 1)));
1462 1434
1463 ViewManagerClientImpl client2; 1435 ViewManagerClientImpl client2;
1464 mojo::ViewManagerClientPtr client2_ptr; 1436 mojo::ViewManagerClientPtr client2_ptr;
1465 mojo::Binding<ViewManagerClient> client2_binding(&client2, &client2_ptr); 1437 mojo::Binding<ViewManagerClient> client2_binding(&client2, &client2_ptr);
1466 ASSERT_TRUE(Embed(vm1(), BuildViewId(1, 1), client2_ptr.Pass())); 1438 ASSERT_TRUE(Embed(vm1(), BuildViewId(1, 1), client2_ptr.Pass()));
1467 client2.WaitForOnEmbed(); 1439 client2.WaitForOnEmbed();
1468 EXPECT_EQ("OnEmbed creator=mojo:window_manager", 1440 EXPECT_EQ("OnEmbed creator=" + application_impl()->url(),
1469 SingleChangeToDescription(*client2.tracker()->changes())); 1441 SingleChangeToDescription(*client2.tracker()->changes()));
1470 } 1442 }
1471 1443
1472 // TODO(sky): need to better track changes to initial connection. For example, 1444 // TODO(sky): need to better track changes to initial connection. For example,
1473 // that SetBounsdViews/AddView and the like don't result in messages to the 1445 // that SetBounsdViews/AddView and the like don't result in messages to the
1474 // originating connection. 1446 // originating connection.
1475 1447
1476 // TODO(sky): make sure coverage of what was 1448 // TODO(sky): make sure coverage of what was
1477 // ViewManagerTest.SecondEmbedRoot_InitService and 1449 // ViewManagerTest.SecondEmbedRoot_InitService and
1478 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager 1450 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager
1479 // tests. 1451 // tests.
1480 1452
1481 } // namespace view_manager 1453 } // namespace view_manager
OLDNEW
« no previous file with comments | « components/view_manager/view_manager_client_apptest.cc ('k') | components/view_manager/view_manager_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698