| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/web_view/frame.h" | 5 #include "components/web_view/frame.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
| 13 #include "components/mus/public/cpp/view_observer.h" | 13 #include "components/mus/public/cpp/view_observer.h" |
| 14 #include "components/mus/public/cpp/view_tree_connection.h" | 14 #include "components/mus/public/cpp/view_tree_connection.h" |
| 15 #include "components/mus/public/cpp/view_tree_delegate.h" | 15 #include "components/mus/public/cpp/view_tree_delegate.h" |
| 16 #include "components/mus/public/cpp/view_tree_host_factory.h" | 16 #include "components/mus/public/cpp/view_tree_host_factory.h" |
| 17 #include "components/web_view/frame.h" | 17 #include "components/web_view/frame.h" |
| 18 #include "components/web_view/frame_connection.h" | 18 #include "components/web_view/frame_connection.h" |
| 19 #include "components/web_view/frame_tree.h" | 19 #include "components/web_view/frame_tree.h" |
| 20 #include "components/web_view/frame_tree_delegate.h" | 20 #include "components/web_view/frame_tree_delegate.h" |
| 21 #include "components/web_view/frame_user_data.h" | 21 #include "components/web_view/frame_user_data.h" |
| 22 #include "components/web_view/test_frame_tree_delegate.h" | 22 #include "components/web_view/test_frame_tree_delegate.h" |
| 23 #include "mojo/application/public/cpp/application_connection.h" | 23 #include "mojo/application/public/cpp/application_connection.h" |
| 24 #include "mojo/application/public/cpp/application_delegate.h" | 24 #include "mojo/application/public/cpp/application_delegate.h" |
| 25 #include "mojo/application/public/cpp/application_impl.h" | 25 #include "mojo/application/public/cpp/application_impl.h" |
| 26 #include "mojo/application/public/cpp/application_test_base.h" | 26 #include "mojo/application/public/cpp/application_test_base.h" |
| 27 #include "mojo/application/public/cpp/service_provider_impl.h" | 27 #include "mojo/application/public/cpp/service_provider_impl.h" |
| 28 | 28 |
| 29 using mus::View; | 29 using mojo::View; |
| 30 using mus::ViewTreeConnection; | 30 using mojo::ViewTreeConnection; |
| 31 | 31 |
| 32 namespace web_view { | 32 namespace web_view { |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 base::RunLoop* current_run_loop = nullptr; | 36 base::RunLoop* current_run_loop = nullptr; |
| 37 | 37 |
| 38 void TimeoutRunLoop(const base::Closure& timeout_task, bool* timeout) { | 38 void TimeoutRunLoop(const base::Closure& timeout_task, bool* timeout) { |
| 39 CHECK(current_run_loop); | 39 CHECK(current_run_loop); |
| 40 *timeout = true; | 40 *timeout = true; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 134 |
| 135 DISALLOW_COPY_AND_ASSIGN(TestFrameTreeClient); | 135 DISALLOW_COPY_AND_ASSIGN(TestFrameTreeClient); |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 class FrameTest; | 138 class FrameTest; |
| 139 | 139 |
| 140 // ViewAndFrame maintains the View and TestFrameTreeClient associated with | 140 // ViewAndFrame maintains the View and TestFrameTreeClient associated with |
| 141 // a single FrameTreeClient. In other words this maintains the data structures | 141 // a single FrameTreeClient. In other words this maintains the data structures |
| 142 // needed to represent a client side frame. To obtain one use | 142 // needed to represent a client side frame. To obtain one use |
| 143 // FrameTest::WaitForViewAndFrame(). | 143 // FrameTest::WaitForViewAndFrame(). |
| 144 class ViewAndFrame : public mus::ViewTreeDelegate { | 144 class ViewAndFrame : public mojo::ViewTreeDelegate { |
| 145 public: | 145 public: |
| 146 ~ViewAndFrame() override { | 146 ~ViewAndFrame() override { |
| 147 if (view_) | 147 if (view_) |
| 148 delete view_->connection(); | 148 delete view_->connection(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 // The View associated with the frame. | 151 // The View associated with the frame. |
| 152 mus::View* view() { return view_; } | 152 mojo::View* view() { return view_; } |
| 153 TestFrameTreeClient* test_frame_tree_client() { | 153 TestFrameTreeClient* test_frame_tree_client() { |
| 154 return &test_frame_tree_client_; | 154 return &test_frame_tree_client_; |
| 155 } | 155 } |
| 156 FrameTreeServer* frame_tree_server() { | 156 FrameTreeServer* frame_tree_server() { |
| 157 return test_frame_tree_client_.server(); | 157 return test_frame_tree_client_.server(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 private: | 160 private: |
| 161 friend class FrameTest; | 161 friend class FrameTest; |
| 162 | 162 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 182 | 182 |
| 183 // Overridden from ViewTreeDelegate: | 183 // Overridden from ViewTreeDelegate: |
| 184 void OnEmbed(View* root) override { | 184 void OnEmbed(View* root) override { |
| 185 view_ = root; | 185 view_ = root; |
| 186 QuitRunLoopIfNecessary(); | 186 QuitRunLoopIfNecessary(); |
| 187 } | 187 } |
| 188 void OnConnectionLost(ViewTreeConnection* connection) override { | 188 void OnConnectionLost(ViewTreeConnection* connection) override { |
| 189 view_ = nullptr; | 189 view_ = nullptr; |
| 190 } | 190 } |
| 191 | 191 |
| 192 mus::View* view_; | 192 mojo::View* view_; |
| 193 base::RunLoop run_loop_; | 193 base::RunLoop run_loop_; |
| 194 TestFrameTreeClient test_frame_tree_client_; | 194 TestFrameTreeClient test_frame_tree_client_; |
| 195 mojo::Binding<FrameTreeClient> frame_tree_binding_; | 195 mojo::Binding<FrameTreeClient> frame_tree_binding_; |
| 196 | 196 |
| 197 DISALLOW_COPY_AND_ASSIGN(ViewAndFrame); | 197 DISALLOW_COPY_AND_ASSIGN(ViewAndFrame); |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 class FrameTest : public mojo::test::ApplicationTestBase, | 200 class FrameTest : public mojo::test::ApplicationTestBase, |
| 201 public mojo::ApplicationDelegate, | 201 public mojo::ApplicationDelegate, |
| 202 public mus::ViewTreeDelegate, | 202 public mojo::ViewTreeDelegate, |
| 203 public mojo::InterfaceFactory<mojo::ViewTreeClient>, | 203 public mojo::InterfaceFactory<mojo::ViewTreeClient>, |
| 204 public mojo::InterfaceFactory<FrameTreeClient> { | 204 public mojo::InterfaceFactory<FrameTreeClient> { |
| 205 public: | 205 public: |
| 206 FrameTest() : most_recent_connection_(nullptr), window_manager_(nullptr) {} | 206 FrameTest() : most_recent_connection_(nullptr), window_manager_(nullptr) {} |
| 207 | 207 |
| 208 ViewTreeConnection* most_recent_connection() { | 208 ViewTreeConnection* most_recent_connection() { |
| 209 return most_recent_connection_; | 209 return most_recent_connection_; |
| 210 } | 210 } |
| 211 | 211 |
| 212 protected: | 212 protected: |
| 213 ViewTreeConnection* window_manager() { return window_manager_; } | 213 ViewTreeConnection* window_manager() { return window_manager_; } |
| 214 TestFrameTreeDelegate* frame_tree_delegate() { | 214 TestFrameTreeDelegate* frame_tree_delegate() { |
| 215 return frame_tree_delegate_.get(); | 215 return frame_tree_delegate_.get(); |
| 216 } | 216 } |
| 217 FrameTree* frame_tree() { return frame_tree_.get(); } | 217 FrameTree* frame_tree() { return frame_tree_.get(); } |
| 218 ViewAndFrame* root_view_and_frame() { return root_view_and_frame_.get(); } | 218 ViewAndFrame* root_view_and_frame() { return root_view_and_frame_.get(); } |
| 219 | 219 |
| 220 mojo::Binding<FrameTreeServer>* frame_tree_server_binding(Frame* frame) { | 220 mojo::Binding<FrameTreeServer>* frame_tree_server_binding(Frame* frame) { |
| 221 return frame->frame_tree_server_binding_.get(); | 221 return frame->frame_tree_server_binding_.get(); |
| 222 } | 222 } |
| 223 | 223 |
| 224 // Creates a new shared frame as a child of |parent|. | 224 // Creates a new shared frame as a child of |parent|. |
| 225 Frame* CreateSharedFrame(ViewAndFrame* parent) { | 225 Frame* CreateSharedFrame(ViewAndFrame* parent) { |
| 226 mus::View* child_frame_view = parent->view()->connection()->CreateView(); | 226 mojo::View* child_frame_view = parent->view()->connection()->CreateView(); |
| 227 parent->view()->AddChild(child_frame_view); | 227 parent->view()->AddChild(child_frame_view); |
| 228 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties; | 228 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties; |
| 229 client_properties.mark_non_null(); | 229 client_properties.mark_non_null(); |
| 230 parent->frame_tree_server()->OnCreatedFrame( | 230 parent->frame_tree_server()->OnCreatedFrame( |
| 231 child_frame_view->parent()->id(), child_frame_view->id(), | 231 child_frame_view->parent()->id(), child_frame_view->id(), |
| 232 client_properties.Pass()); | 232 client_properties.Pass()); |
| 233 Frame* frame = frame_tree_delegate()->WaitForCreateFrame(); | 233 Frame* frame = frame_tree_delegate()->WaitForCreateFrame(); |
| 234 return HasFatalFailure() ? nullptr : frame; | 234 return HasFatalFailure() ? nullptr : frame; |
| 235 } | 235 } |
| 236 | 236 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 void OnEmbed(View* root) override { | 274 void OnEmbed(View* root) override { |
| 275 most_recent_connection_ = root->connection(); | 275 most_recent_connection_ = root->connection(); |
| 276 QuitRunLoop(); | 276 QuitRunLoop(); |
| 277 } | 277 } |
| 278 void OnConnectionLost(ViewTreeConnection* connection) override {} | 278 void OnConnectionLost(ViewTreeConnection* connection) override {} |
| 279 | 279 |
| 280 // Overridden from testing::Test: | 280 // Overridden from testing::Test: |
| 281 void SetUp() override { | 281 void SetUp() override { |
| 282 ApplicationTestBase::SetUp(); | 282 ApplicationTestBase::SetUp(); |
| 283 | 283 |
| 284 mus::CreateSingleViewTreeHost(application_impl(), this, &host_); | 284 mojo::CreateSingleViewTreeHost(application_impl(), this, &host_); |
| 285 | 285 |
| 286 ASSERT_TRUE(DoRunLoopWithTimeout()); | 286 ASSERT_TRUE(DoRunLoopWithTimeout()); |
| 287 std::swap(window_manager_, most_recent_connection_); | 287 std::swap(window_manager_, most_recent_connection_); |
| 288 | 288 |
| 289 // Creates a FrameTree, which creates a single frame. Wait for the | 289 // Creates a FrameTree, which creates a single frame. Wait for the |
| 290 // FrameTreeClient to be connected to. | 290 // FrameTreeClient to be connected to. |
| 291 frame_tree_delegate_.reset(new TestFrameTreeDelegate(application_impl())); | 291 frame_tree_delegate_.reset(new TestFrameTreeDelegate(application_impl())); |
| 292 scoped_ptr<FrameConnection> frame_connection = | 292 scoped_ptr<FrameConnection> frame_connection = |
| 293 CreateFrameConnection(application_impl()); | 293 CreateFrameConnection(application_impl()); |
| 294 FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client(); | 294 FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client(); |
| 295 mojo::ViewTreeClientPtr view_tree_client = | 295 mojo::ViewTreeClientPtr view_tree_client = |
| 296 frame_connection->GetViewTreeClient(); | 296 frame_connection->GetViewTreeClient(); |
| 297 mus::View* frame_root_view = window_manager()->CreateView(); | 297 mojo::View* frame_root_view = window_manager()->CreateView(); |
| 298 window_manager()->GetRoot()->AddChild(frame_root_view); | 298 window_manager()->GetRoot()->AddChild(frame_root_view); |
| 299 frame_tree_.reset( | 299 frame_tree_.reset( |
| 300 new FrameTree(0u, frame_root_view, view_tree_client.Pass(), | 300 new FrameTree(0u, frame_root_view, view_tree_client.Pass(), |
| 301 frame_tree_delegate_.get(), frame_tree_client, | 301 frame_tree_delegate_.get(), frame_tree_client, |
| 302 frame_connection.Pass(), Frame::ClientPropertyMap())); | 302 frame_connection.Pass(), Frame::ClientPropertyMap())); |
| 303 root_view_and_frame_ = WaitForViewAndFrame(); | 303 root_view_and_frame_ = WaitForViewAndFrame(); |
| 304 } | 304 } |
| 305 | 305 |
| 306 // Overridden from testing::Test: | 306 // Overridden from testing::Test: |
| 307 void TearDown() override { | 307 void TearDown() override { |
| 308 root_view_and_frame_.reset(); | 308 root_view_and_frame_.reset(); |
| 309 frame_tree_.reset(); | 309 frame_tree_.reset(); |
| 310 frame_tree_delegate_.reset(); | 310 frame_tree_delegate_.reset(); |
| 311 ApplicationTestBase::TearDown(); | 311 ApplicationTestBase::TearDown(); |
| 312 } | 312 } |
| 313 | 313 |
| 314 // Overridden from mojo::InterfaceFactory<mojo::ViewTreeClient>: | 314 // Overridden from mojo::InterfaceFactory<mojo::ViewTreeClient>: |
| 315 void Create( | 315 void Create( |
| 316 mojo::ApplicationConnection* connection, | 316 mojo::ApplicationConnection* connection, |
| 317 mojo::InterfaceRequest<mojo::ViewTreeClient> request) override { | 317 mojo::InterfaceRequest<mojo::ViewTreeClient> request) override { |
| 318 if (view_and_frame_) { | 318 if (view_and_frame_) { |
| 319 mus::ViewTreeConnection::Create(view_and_frame_.get(), request.Pass()); | 319 mojo::ViewTreeConnection::Create(view_and_frame_.get(), request.Pass()); |
| 320 } else { | 320 } else { |
| 321 mus::ViewTreeConnection::Create(this, request.Pass()); | 321 mojo::ViewTreeConnection::Create(this, request.Pass()); |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 | 324 |
| 325 // Overridden from mojo::InterfaceFactory<FrameTreeClient>: | 325 // Overridden from mojo::InterfaceFactory<FrameTreeClient>: |
| 326 void Create(mojo::ApplicationConnection* connection, | 326 void Create(mojo::ApplicationConnection* connection, |
| 327 mojo::InterfaceRequest<FrameTreeClient> request) override { | 327 mojo::InterfaceRequest<FrameTreeClient> request) override { |
| 328 ASSERT_TRUE(view_and_frame_); | 328 ASSERT_TRUE(view_and_frame_); |
| 329 view_and_frame_->Bind(request.Pass()); | 329 view_and_frame_->Bind(request.Pass()); |
| 330 } | 330 } |
| 331 | 331 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 395 |
| 396 // Send LoadingStarted() from the root targetting a frame from another | 396 // Send LoadingStarted() from the root targetting a frame from another |
| 397 // connection. It should be ignored (not update the loading status). | 397 // connection. It should be ignored (not update the loading status). |
| 398 root_view_and_frame()->frame_tree_server()->LoadingStarted( | 398 root_view_and_frame()->frame_tree_server()->LoadingStarted( |
| 399 shared_frame->id()); | 399 shared_frame->id()); |
| 400 frame_tree_server_binding(frame_tree()->root())->WaitForIncomingMethodCall(); | 400 frame_tree_server_binding(frame_tree()->root())->WaitForIncomingMethodCall(); |
| 401 EXPECT_FALSE(frame_tree()->root()->IsLoading()); | 401 EXPECT_FALSE(frame_tree()->root()->IsLoading()); |
| 402 } | 402 } |
| 403 | 403 |
| 404 } // namespace web_view | 404 } // namespace web_view |
| OLD | NEW |