| 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/window_server_test_base.h" | 8 #include "components/mus/public/cpp/tests/window_server_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/window_observer.h" | 10 #include "components/mus/public/cpp/window_observer.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 public: | 124 public: |
| 125 OrderChangeObserver(Window* window) : window_(window) { | 125 OrderChangeObserver(Window* window) : window_(window) { |
| 126 window_->AddObserver(this); | 126 window_->AddObserver(this); |
| 127 } | 127 } |
| 128 ~OrderChangeObserver() override { window_->RemoveObserver(this); } | 128 ~OrderChangeObserver() override { window_->RemoveObserver(this); } |
| 129 | 129 |
| 130 private: | 130 private: |
| 131 // Overridden from WindowObserver: | 131 // Overridden from WindowObserver: |
| 132 void OnWindowReordered(Window* window, | 132 void OnWindowReordered(Window* window, |
| 133 Window* relative_window, | 133 Window* relative_window, |
| 134 mojo::OrderDirection direction) override { | 134 mojom::OrderDirection direction) override { |
| 135 DCHECK_EQ(window, window_); | 135 DCHECK_EQ(window, window_); |
| 136 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); | 136 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 Window* window_; | 139 Window* window_; |
| 140 | 140 |
| 141 MOJO_DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); | 141 MOJO_DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 // Wait until |window|'s tree size matches |tree_size|; returns false on | 144 // Wait until |window|'s tree size matches |tree_size|; returns false on |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 // service, that are given access to some root window. | 196 // service, that are given access to some root window. |
| 197 | 197 |
| 198 class WindowServerTest : public WindowServerTestBase { | 198 class WindowServerTest : public WindowServerTestBase { |
| 199 public: | 199 public: |
| 200 WindowServerTest() {} | 200 WindowServerTest() {} |
| 201 | 201 |
| 202 // Embeds another version of the test app @ window. This runs a run loop until | 202 // Embeds another version of the test app @ window. This runs a run loop until |
| 203 // a response is received, or a timeout. On success the new WindowServer is | 203 // a response is received, or a timeout. On success the new WindowServer is |
| 204 // returned. | 204 // returned. |
| 205 EmbedResult Embed(Window* window) { | 205 EmbedResult Embed(Window* window) { |
| 206 return Embed(window, mojo::ViewTree::ACCESS_POLICY_DEFAULT); | 206 return Embed(window, mus::mojom::WindowTree::ACCESS_POLICY_DEFAULT); |
| 207 } | 207 } |
| 208 | 208 |
| 209 EmbedResult Embed(Window* window, uint32_t access_policy_bitmask) { | 209 EmbedResult Embed(Window* window, uint32_t access_policy_bitmask) { |
| 210 DCHECK(!embed_details_); | 210 DCHECK(!embed_details_); |
| 211 embed_details_.reset(new EmbedDetails); | 211 embed_details_.reset(new EmbedDetails); |
| 212 window->Embed(ConnectToApplicationAndGetWindowServerClient(), | 212 window->Embed(ConnectToApplicationAndGetWindowServerClient(), |
| 213 access_policy_bitmask, | 213 access_policy_bitmask, |
| 214 base::Bind(&WindowServerTest::EmbedCallbackImpl, | 214 base::Bind(&WindowServerTest::EmbedCallbackImpl, |
| 215 base::Unretained(this))); | 215 base::Unretained(this))); |
| 216 embed_details_->waiting = true; | 216 embed_details_->waiting = true; |
| 217 if (!WindowServerTestBase::DoRunLoopWithTimeout()) | 217 if (!WindowServerTestBase::DoRunLoopWithTimeout()) |
| 218 return EmbedResult(); | 218 return EmbedResult(); |
| 219 const EmbedResult result(embed_details_->connection, | 219 const EmbedResult result(embed_details_->connection, |
| 220 embed_details_->connection_id); | 220 embed_details_->connection_id); |
| 221 embed_details_.reset(); | 221 embed_details_.reset(); |
| 222 return result; | 222 return result; |
| 223 } | 223 } |
| 224 | 224 |
| 225 // Establishes a connection to this application and asks for a | 225 // Establishes a connection to this application and asks for a |
| 226 // ViewTreeClient. | 226 // WindowTreeClient. |
| 227 mojo::ViewTreeClientPtr ConnectToApplicationAndGetWindowServerClient() { | 227 mus::mojom::WindowTreeClientPtr |
| 228 ConnectToApplicationAndGetWindowServerClient() { |
| 228 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 229 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 229 request->url = mojo::String::From(application_impl()->url()); | 230 request->url = mojo::String::From(application_impl()->url()); |
| 230 scoped_ptr<mojo::ApplicationConnection> connection = | 231 scoped_ptr<mojo::ApplicationConnection> connection = |
| 231 application_impl()->ConnectToApplication(request.Pass()); | 232 application_impl()->ConnectToApplication(request.Pass()); |
| 232 mojo::ViewTreeClientPtr client; | 233 mus::mojom::WindowTreeClientPtr client; |
| 233 connection->ConnectToService(&client); | 234 connection->ConnectToService(&client); |
| 234 return client.Pass(); | 235 return client.Pass(); |
| 235 } | 236 } |
| 236 | 237 |
| 237 // WindowServerTestBase: | 238 // WindowServerTestBase: |
| 238 void OnEmbed(Window* root) override { | 239 void OnEmbed(Window* root) override { |
| 239 if (!embed_details_) { | 240 if (!embed_details_) { |
| 240 WindowServerTestBase::OnEmbed(root); | 241 WindowServerTestBase::OnEmbed(root); |
| 241 return; | 242 return; |
| 242 } | 243 } |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 EXPECT_TRUE(got_destroy); | 816 EXPECT_TRUE(got_destroy); |
| 816 } | 817 } |
| 817 | 818 |
| 818 // Verifies an embed root sees windows created beneath it from another | 819 // Verifies an embed root sees windows created beneath it from another |
| 819 // connection. | 820 // connection. |
| 820 TEST_F(WindowServerTest, EmbedRootSeesHierarchyChanged) { | 821 TEST_F(WindowServerTest, EmbedRootSeesHierarchyChanged) { |
| 821 Window* embed_window = window_manager()->CreateWindow(); | 822 Window* embed_window = window_manager()->CreateWindow(); |
| 822 window_manager()->GetRoot()->AddChild(embed_window); | 823 window_manager()->GetRoot()->AddChild(embed_window); |
| 823 | 824 |
| 824 WindowTreeConnection* vm2 = | 825 WindowTreeConnection* vm2 = |
| 825 Embed(embed_window, mojo::ViewTree::ACCESS_POLICY_EMBED_ROOT).connection; | 826 Embed(embed_window, mus::mojom::WindowTree::ACCESS_POLICY_EMBED_ROOT) |
| 827 .connection; |
| 826 Window* vm2_v1 = vm2->CreateWindow(); | 828 Window* vm2_v1 = vm2->CreateWindow(); |
| 827 vm2->GetRoot()->AddChild(vm2_v1); | 829 vm2->GetRoot()->AddChild(vm2_v1); |
| 828 | 830 |
| 829 WindowTreeConnection* vm3 = Embed(vm2_v1).connection; | 831 WindowTreeConnection* vm3 = Embed(vm2_v1).connection; |
| 830 Window* vm3_v1 = vm3->CreateWindow(); | 832 Window* vm3_v1 = vm3->CreateWindow(); |
| 831 vm3->GetRoot()->AddChild(vm3_v1); | 833 vm3->GetRoot()->AddChild(vm3_v1); |
| 832 | 834 |
| 833 // As |vm2| is an embed root it should get notified about |vm3_v1|. | 835 // As |vm2| is an embed root it should get notified about |vm3_v1|. |
| 834 ASSERT_TRUE(WaitForTreeSizeToMatch(vm2_v1, 2)); | 836 ASSERT_TRUE(WaitForTreeSizeToMatch(vm2_v1, 2)); |
| 835 } | 837 } |
| 836 | 838 |
| 837 TEST_F(WindowServerTest, EmbedFromEmbedRoot) { | 839 TEST_F(WindowServerTest, EmbedFromEmbedRoot) { |
| 838 Window* embed_window = window_manager()->CreateWindow(); | 840 Window* embed_window = window_manager()->CreateWindow(); |
| 839 window_manager()->GetRoot()->AddChild(embed_window); | 841 window_manager()->GetRoot()->AddChild(embed_window); |
| 840 | 842 |
| 841 // Give the connection embedded at |embed_window| embed root powers. | 843 // Give the connection embedded at |embed_window| embed root powers. |
| 842 const EmbedResult result1 = | 844 const EmbedResult result1 = |
| 843 Embed(embed_window, mojo::ViewTree::ACCESS_POLICY_EMBED_ROOT); | 845 Embed(embed_window, mus::mojom::WindowTree::ACCESS_POLICY_EMBED_ROOT); |
| 844 WindowTreeConnection* vm2 = result1.connection; | 846 WindowTreeConnection* vm2 = result1.connection; |
| 845 EXPECT_EQ(result1.connection_id, vm2->GetConnectionId()); | 847 EXPECT_EQ(result1.connection_id, vm2->GetConnectionId()); |
| 846 Window* vm2_v1 = vm2->CreateWindow(); | 848 Window* vm2_v1 = vm2->CreateWindow(); |
| 847 vm2->GetRoot()->AddChild(vm2_v1); | 849 vm2->GetRoot()->AddChild(vm2_v1); |
| 848 | 850 |
| 849 const EmbedResult result2 = Embed(vm2_v1); | 851 const EmbedResult result2 = Embed(vm2_v1); |
| 850 WindowTreeConnection* vm3 = result2.connection; | 852 WindowTreeConnection* vm3 = result2.connection; |
| 851 EXPECT_EQ(result2.connection_id, vm3->GetConnectionId()); | 853 EXPECT_EQ(result2.connection_id, vm3->GetConnectionId()); |
| 852 Window* vm3_v1 = vm3->CreateWindow(); | 854 Window* vm3_v1 = vm3->CreateWindow(); |
| 853 vm3->GetRoot()->AddChild(vm3_v1); | 855 vm3->GetRoot()->AddChild(vm3_v1); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 // Verify bounds change results in resetting client area in embedded. | 888 // Verify bounds change results in resetting client area in embedded. |
| 887 embed_window->SetBounds(*mojo::Rect::From(gfx::Rect(21, 22, 23, 24))); | 889 embed_window->SetBounds(*mojo::Rect::From(gfx::Rect(21, 22, 23, 24))); |
| 888 WaitForBoundsToChange(embedded_connection->GetRoot()); | 890 WaitForBoundsToChange(embedded_connection->GetRoot()); |
| 889 EXPECT_TRUE(gfx::Rect(21, 22, 23, 24) == | 891 EXPECT_TRUE(gfx::Rect(21, 22, 23, 24) == |
| 890 embedded_connection->GetRoot()->bounds().To<gfx::Rect>()); | 892 embedded_connection->GetRoot()->bounds().To<gfx::Rect>()); |
| 891 EXPECT_TRUE(gfx::Rect(0, 0, 23, 24) == | 893 EXPECT_TRUE(gfx::Rect(0, 0, 23, 24) == |
| 892 embedded_connection->GetRoot()->client_area().To<gfx::Rect>()); | 894 embedded_connection->GetRoot()->client_area().To<gfx::Rect>()); |
| 893 } | 895 } |
| 894 | 896 |
| 895 } // namespace mus | 897 } // namespace mus |
| OLD | NEW |