| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "components/mus/public/cpp/tests/view_manager_test_base.h" | 8 #include "components/mus/public/cpp/tests/view_manager_test_base.h" |
| 9 #include "components/mus/public/cpp/util.h" | 9 #include "components/mus/public/cpp/util.h" |
| 10 #include "components/mus/public/cpp/view_observer.h" | 10 #include "components/mus/public/cpp/view_observer.h" |
| 11 #include "components/mus/public/cpp/view_tree_connection.h" | 11 #include "components/mus/public/cpp/view_tree_connection.h" |
| 12 #include "components/mus/public/cpp/view_tree_delegate.h" | 12 #include "components/mus/public/cpp/view_tree_delegate.h" |
| 13 #include "mojo/application/public/cpp/application_connection.h" | 13 #include "mojo/application/public/cpp/application_connection.h" |
| 14 #include "mojo/application/public/cpp/application_impl.h" | 14 #include "mojo/application/public/cpp/application_impl.h" |
| 15 #include "mojo/application/public/cpp/application_test_base.h" | 15 #include "mojo/application/public/cpp/application_test_base.h" |
| 16 #include "ui/mojo/geometry/geometry_util.h" | 16 #include "ui/mojo/geometry/geometry_util.h" |
| 17 | 17 |
| 18 namespace mojo { | 18 namespace mus { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class BoundsChangeObserver : public ViewObserver { | 22 class BoundsChangeObserver : public ViewObserver { |
| 23 public: | 23 public: |
| 24 explicit BoundsChangeObserver(View* view) : view_(view) { | 24 explicit BoundsChangeObserver(View* view) : view_(view) { |
| 25 view_->AddObserver(this); | 25 view_->AddObserver(this); |
| 26 } | 26 } |
| 27 ~BoundsChangeObserver() override { view_->RemoveObserver(this); } | 27 ~BoundsChangeObserver() override { view_->RemoveObserver(this); } |
| 28 | 28 |
| 29 private: | 29 private: |
| 30 // Overridden from ViewObserver: | 30 // Overridden from ViewObserver: |
| 31 void OnViewBoundsChanged(View* view, | 31 void OnViewBoundsChanged(View* view, |
| 32 const Rect& old_bounds, | 32 const mojo::Rect& old_bounds, |
| 33 const Rect& new_bounds) override { | 33 const mojo::Rect& new_bounds) override { |
| 34 DCHECK_EQ(view, view_); | 34 DCHECK_EQ(view, view_); |
| 35 EXPECT_TRUE(ViewManagerTestBase::QuitRunLoop()); | 35 EXPECT_TRUE(ViewManagerTestBase::QuitRunLoop()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 View* view_; | 38 View* view_; |
| 39 | 39 |
| 40 MOJO_DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); | 40 MOJO_DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 // Wait until the bounds of the supplied view change; returns false on timeout. | 43 // Wait until the bounds of the supplied view change; returns false on timeout. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 class OrderChangeObserver : public ViewObserver { | 91 class OrderChangeObserver : public ViewObserver { |
| 92 public: | 92 public: |
| 93 OrderChangeObserver(View* view) : view_(view) { view_->AddObserver(this); } | 93 OrderChangeObserver(View* view) : view_(view) { view_->AddObserver(this); } |
| 94 ~OrderChangeObserver() override { view_->RemoveObserver(this); } | 94 ~OrderChangeObserver() override { view_->RemoveObserver(this); } |
| 95 | 95 |
| 96 private: | 96 private: |
| 97 // Overridden from ViewObserver: | 97 // Overridden from ViewObserver: |
| 98 void OnViewReordered(View* view, | 98 void OnViewReordered(View* view, |
| 99 View* relative_view, | 99 View* relative_view, |
| 100 OrderDirection direction) override { | 100 mojo::OrderDirection direction) override { |
| 101 DCHECK_EQ(view, view_); | 101 DCHECK_EQ(view, view_); |
| 102 EXPECT_TRUE(ViewManagerTestBase::QuitRunLoop()); | 102 EXPECT_TRUE(ViewManagerTestBase::QuitRunLoop()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 View* view_; | 105 View* view_; |
| 106 | 106 |
| 107 MOJO_DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); | 107 MOJO_DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 // Wait until |view|'s tree size matches |tree_size|; returns false on timeout. | 110 // Wait until |view|'s tree size matches |tree_size|; returns false on timeout. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 embed_details_->connection_id); | 181 embed_details_->connection_id); |
| 182 embed_details_.reset(); | 182 embed_details_.reset(); |
| 183 return result; | 183 return result; |
| 184 } | 184 } |
| 185 | 185 |
| 186 // Establishes a connection to this application and asks for a | 186 // Establishes a connection to this application and asks for a |
| 187 // ViewTreeClient. | 187 // ViewTreeClient. |
| 188 mojo::ViewTreeClientPtr ConnectToApplicationAndGetViewManagerClient() { | 188 mojo::ViewTreeClientPtr ConnectToApplicationAndGetViewManagerClient() { |
| 189 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 189 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 190 request->url = mojo::String::From(application_impl()->url()); | 190 request->url = mojo::String::From(application_impl()->url()); |
| 191 scoped_ptr<ApplicationConnection> connection = | 191 scoped_ptr<mojo::ApplicationConnection> connection = |
| 192 application_impl()->ConnectToApplication(request.Pass()); | 192 application_impl()->ConnectToApplication(request.Pass()); |
| 193 mojo::ViewTreeClientPtr client; | 193 mojo::ViewTreeClientPtr client; |
| 194 connection->ConnectToService(&client); | 194 connection->ConnectToService(&client); |
| 195 return client.Pass(); | 195 return client.Pass(); |
| 196 } | 196 } |
| 197 | 197 |
| 198 // ViewManagerTestBase: | 198 // ViewManagerTestBase: |
| 199 void OnEmbed(View* root) override { | 199 void OnEmbed(View* root) override { |
| 200 if (!embed_details_) { | 200 if (!embed_details_) { |
| 201 ViewManagerTestBase::OnEmbed(root); | 201 ViewManagerTestBase::OnEmbed(root); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 TEST_F(ViewManagerTest, SetBounds) { | 304 TEST_F(ViewManagerTest, SetBounds) { |
| 305 View* view = window_manager()->CreateView(); | 305 View* view = window_manager()->CreateView(); |
| 306 view->SetVisible(true); | 306 view->SetVisible(true); |
| 307 window_manager()->GetRoot()->AddChild(view); | 307 window_manager()->GetRoot()->AddChild(view); |
| 308 ViewTreeConnection* embedded = Embed(view).connection; | 308 ViewTreeConnection* embedded = Embed(view).connection; |
| 309 ASSERT_NE(nullptr, embedded); | 309 ASSERT_NE(nullptr, embedded); |
| 310 | 310 |
| 311 View* view_in_embedded = embedded->GetViewById(view->id()); | 311 View* view_in_embedded = embedded->GetViewById(view->id()); |
| 312 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); | 312 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); |
| 313 | 313 |
| 314 Rect rect; | 314 mojo::Rect rect; |
| 315 rect.width = rect.height = 100; | 315 rect.width = rect.height = 100; |
| 316 view->SetBounds(rect); | 316 view->SetBounds(rect); |
| 317 ASSERT_TRUE(WaitForBoundsToChange(view_in_embedded)); | 317 ASSERT_TRUE(WaitForBoundsToChange(view_in_embedded)); |
| 318 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); | 318 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); |
| 319 } | 319 } |
| 320 | 320 |
| 321 // Verifies that bounds changes applied to a view owned by a different | 321 // Verifies that bounds changes applied to a view owned by a different |
| 322 // connection are refused. | 322 // connection are refused. |
| 323 TEST_F(ViewManagerTest, SetBoundsSecurity) { | 323 TEST_F(ViewManagerTest, SetBoundsSecurity) { |
| 324 View* view = window_manager()->CreateView(); | 324 View* view = window_manager()->CreateView(); |
| 325 view->SetVisible(true); | 325 view->SetVisible(true); |
| 326 window_manager()->GetRoot()->AddChild(view); | 326 window_manager()->GetRoot()->AddChild(view); |
| 327 ViewTreeConnection* embedded = Embed(view).connection; | 327 ViewTreeConnection* embedded = Embed(view).connection; |
| 328 ASSERT_NE(nullptr, embedded); | 328 ASSERT_NE(nullptr, embedded); |
| 329 | 329 |
| 330 View* view_in_embedded = embedded->GetViewById(view->id()); | 330 View* view_in_embedded = embedded->GetViewById(view->id()); |
| 331 Rect rect; | 331 mojo::Rect rect; |
| 332 rect.width = 800; | 332 rect.width = 800; |
| 333 rect.height = 600; | 333 rect.height = 600; |
| 334 view->SetBounds(rect); | 334 view->SetBounds(rect); |
| 335 ASSERT_TRUE(WaitForBoundsToChange(view_in_embedded)); | 335 ASSERT_TRUE(WaitForBoundsToChange(view_in_embedded)); |
| 336 | 336 |
| 337 rect.width = 1024; | 337 rect.width = 1024; |
| 338 rect.height = 768; | 338 rect.height = 768; |
| 339 view_in_embedded->SetBounds(rect); | 339 view_in_embedded->SetBounds(rect); |
| 340 // Bounds change should have been rejected. | 340 // Bounds change should have been rejected. |
| 341 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); | 341 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 EXPECT_TRUE(got_destroy); | 771 EXPECT_TRUE(got_destroy); |
| 772 } | 772 } |
| 773 | 773 |
| 774 // Verifies an embed root sees views created beneath it from another | 774 // Verifies an embed root sees views created beneath it from another |
| 775 // connection. | 775 // connection. |
| 776 TEST_F(ViewManagerTest, EmbedRootSeesHierarchyChanged) { | 776 TEST_F(ViewManagerTest, EmbedRootSeesHierarchyChanged) { |
| 777 View* embed_view = window_manager()->CreateView(); | 777 View* embed_view = window_manager()->CreateView(); |
| 778 window_manager()->GetRoot()->AddChild(embed_view); | 778 window_manager()->GetRoot()->AddChild(embed_view); |
| 779 | 779 |
| 780 ViewTreeConnection* vm2 = | 780 ViewTreeConnection* vm2 = |
| 781 Embed(embed_view, ViewTree::ACCESS_POLICY_EMBED_ROOT).connection; | 781 Embed(embed_view, mojo::ViewTree::ACCESS_POLICY_EMBED_ROOT).connection; |
| 782 View* vm2_v1 = vm2->CreateView(); | 782 View* vm2_v1 = vm2->CreateView(); |
| 783 vm2->GetRoot()->AddChild(vm2_v1); | 783 vm2->GetRoot()->AddChild(vm2_v1); |
| 784 | 784 |
| 785 ViewTreeConnection* vm3 = Embed(vm2_v1).connection; | 785 ViewTreeConnection* vm3 = Embed(vm2_v1).connection; |
| 786 View* vm3_v1 = vm3->CreateView(); | 786 View* vm3_v1 = vm3->CreateView(); |
| 787 vm3->GetRoot()->AddChild(vm3_v1); | 787 vm3->GetRoot()->AddChild(vm3_v1); |
| 788 | 788 |
| 789 // As |vm2| is an embed root it should get notified about |vm3_v1|. | 789 // As |vm2| is an embed root it should get notified about |vm3_v1|. |
| 790 ASSERT_TRUE(WaitForTreeSizeToMatch(vm2_v1, 2)); | 790 ASSERT_TRUE(WaitForTreeSizeToMatch(vm2_v1, 2)); |
| 791 } | 791 } |
| 792 | 792 |
| 793 TEST_F(ViewManagerTest, EmbedFromEmbedRoot) { | 793 TEST_F(ViewManagerTest, EmbedFromEmbedRoot) { |
| 794 View* embed_view = window_manager()->CreateView(); | 794 View* embed_view = window_manager()->CreateView(); |
| 795 window_manager()->GetRoot()->AddChild(embed_view); | 795 window_manager()->GetRoot()->AddChild(embed_view); |
| 796 | 796 |
| 797 // Give the connection embedded at |embed_view| embed root powers. | 797 // Give the connection embedded at |embed_view| embed root powers. |
| 798 const EmbedResult result1 = | 798 const EmbedResult result1 = |
| 799 Embed(embed_view, ViewTree::ACCESS_POLICY_EMBED_ROOT); | 799 Embed(embed_view, mojo::ViewTree::ACCESS_POLICY_EMBED_ROOT); |
| 800 ViewTreeConnection* vm2 = result1.connection; | 800 ViewTreeConnection* vm2 = result1.connection; |
| 801 EXPECT_EQ(result1.connection_id, vm2->GetConnectionId()); | 801 EXPECT_EQ(result1.connection_id, vm2->GetConnectionId()); |
| 802 View* vm2_v1 = vm2->CreateView(); | 802 View* vm2_v1 = vm2->CreateView(); |
| 803 vm2->GetRoot()->AddChild(vm2_v1); | 803 vm2->GetRoot()->AddChild(vm2_v1); |
| 804 | 804 |
| 805 const EmbedResult result2 = Embed(vm2_v1); | 805 const EmbedResult result2 = Embed(vm2_v1); |
| 806 ViewTreeConnection* vm3 = result2.connection; | 806 ViewTreeConnection* vm3 = result2.connection; |
| 807 EXPECT_EQ(result2.connection_id, vm3->GetConnectionId()); | 807 EXPECT_EQ(result2.connection_id, vm3->GetConnectionId()); |
| 808 View* vm3_v1 = vm3->CreateView(); | 808 View* vm3_v1 = vm3->CreateView(); |
| 809 vm3->GetRoot()->AddChild(vm3_v1); | 809 vm3->GetRoot()->AddChild(vm3_v1); |
| 810 | 810 |
| 811 // Embed from v3, the callback should not get the connection id as vm3 is not | 811 // Embed from v3, the callback should not get the connection id as vm3 is not |
| 812 // an embed root. | 812 // an embed root. |
| 813 const EmbedResult result3 = Embed(vm3_v1); | 813 const EmbedResult result3 = Embed(vm3_v1); |
| 814 ASSERT_TRUE(result3.connection); | 814 ASSERT_TRUE(result3.connection); |
| 815 EXPECT_EQ(0, result3.connection_id); | 815 EXPECT_EQ(0, result3.connection_id); |
| 816 | 816 |
| 817 // As |vm2| is an embed root it should get notified about |vm3_v1|. | 817 // As |vm2| is an embed root it should get notified about |vm3_v1|. |
| 818 ASSERT_TRUE(WaitForTreeSizeToMatch(vm2_v1, 2)); | 818 ASSERT_TRUE(WaitForTreeSizeToMatch(vm2_v1, 2)); |
| 819 | 819 |
| 820 // Embed() from vm2 in vm3_v1. This is allowed as vm2 is an embed root, and | 820 // Embed() from vm2 in vm3_v1. This is allowed as vm2 is an embed root, and |
| 821 // further the callback should see the connection id. | 821 // further the callback should see the connection id. |
| 822 ASSERT_EQ(1u, vm2_v1->children().size()); | 822 ASSERT_EQ(1u, vm2_v1->children().size()); |
| 823 View* vm3_v1_in_vm2 = vm2_v1->children()[0]; | 823 View* vm3_v1_in_vm2 = vm2_v1->children()[0]; |
| 824 const EmbedResult result4 = Embed(vm3_v1_in_vm2); | 824 const EmbedResult result4 = Embed(vm3_v1_in_vm2); |
| 825 ASSERT_TRUE(result4.connection); | 825 ASSERT_TRUE(result4.connection); |
| 826 EXPECT_EQ(result4.connection_id, result4.connection->GetConnectionId()); | 826 EXPECT_EQ(result4.connection_id, result4.connection->GetConnectionId()); |
| 827 } | 827 } |
| 828 | 828 |
| 829 } // namespace mojo | 829 } // namespace mus |
| OLD | NEW |