| 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" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 126 } |
| 127 | 127 |
| 128 base::TimeTicks last_navigation_start_time() const { | 128 base::TimeTicks last_navigation_start_time() const { |
| 129 return last_navigation_start_time_; | 129 return last_navigation_start_time_; |
| 130 } | 130 } |
| 131 | 131 |
| 132 // mojom::FrameClient: | 132 // mojom::FrameClient: |
| 133 void OnConnect(mojom::FramePtr frame, | 133 void OnConnect(mojom::FramePtr frame, |
| 134 uint32_t change_id, | 134 uint32_t change_id, |
| 135 uint32_t window_id, | 135 uint32_t window_id, |
| 136 mojom::ViewConnectType view_connect_type, | 136 mojom::WindowConnectType window_connect_type, |
| 137 mojo::Array<mojom::FrameDataPtr> frames, | 137 mojo::Array<mojom::FrameDataPtr> frames, |
| 138 int64_t navigation_start_time_ticks, | 138 int64_t navigation_start_time_ticks, |
| 139 const OnConnectCallback& callback) override { | 139 const OnConnectCallback& callback) override { |
| 140 connect_count_++; | 140 connect_count_++; |
| 141 connect_frames_ = frames.Pass(); | 141 connect_frames_ = frames.Pass(); |
| 142 if (frame) | 142 if (frame) |
| 143 server_frame_ = frame.Pass(); | 143 server_frame_ = frame.Pass(); |
| 144 callback.Run(); | 144 callback.Run(); |
| 145 if (!on_connect_callback_.is_null()) | 145 if (!on_connect_callback_.is_null()) |
| 146 on_connect_callback_.Run(); | 146 on_connect_callback_.Run(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 base::Closure on_dispatch_load_event_callback_; | 205 base::Closure on_dispatch_load_event_callback_; |
| 206 LoadingStateChangedNotification last_loading_state_changed_notification_; | 206 LoadingStateChangedNotification last_loading_state_changed_notification_; |
| 207 uint32_t last_dispatch_load_event_frame_id_; | 207 uint32_t last_dispatch_load_event_frame_id_; |
| 208 base::TimeTicks last_navigation_start_time_; | 208 base::TimeTicks last_navigation_start_time_; |
| 209 | 209 |
| 210 DISALLOW_COPY_AND_ASSIGN(TestFrameClient); | 210 DISALLOW_COPY_AND_ASSIGN(TestFrameClient); |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 class FrameTest; | 213 class FrameTest; |
| 214 | 214 |
| 215 // ViewAndFrame maintains the View and TestFrameClient associated with | 215 // WindowAndFrame maintains the Window and TestFrameClient associated with |
| 216 // a single FrameClient. In other words this maintains the data structures | 216 // a single FrameClient. In other words this maintains the data structures |
| 217 // needed to represent a client side frame. To obtain one use | 217 // needed to represent a client side frame. To obtain one use |
| 218 // FrameTest::WaitForViewAndFrame(). | 218 // FrameTest::WaitForViewAndFrame(). |
| 219 class ViewAndFrame : public mus::WindowTreeDelegate { | 219 class WindowAndFrame : public mus::WindowTreeDelegate { |
| 220 public: | 220 public: |
| 221 ~ViewAndFrame() override { | 221 ~WindowAndFrame() override { |
| 222 if (view_) | 222 if (window_) |
| 223 delete view_->connection(); | 223 delete window_->connection(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 // The View associated with the frame. | 226 // The Window associated with the frame. |
| 227 mus::Window* view() { return view_; } | 227 mus::Window* window() { return window_; } |
| 228 TestFrameClient* test_frame_client() { return &test_frame_tree_client_; } | 228 TestFrameClient* test_frame_client() { return &test_frame_tree_client_; } |
| 229 mojom::Frame* server_frame() { | 229 mojom::Frame* server_frame() { |
| 230 return test_frame_tree_client_.server_frame(); | 230 return test_frame_tree_client_.server_frame(); |
| 231 } | 231 } |
| 232 | 232 |
| 233 private: | 233 private: |
| 234 friend class FrameTest; | 234 friend class FrameTest; |
| 235 | 235 |
| 236 ViewAndFrame() | 236 WindowAndFrame() |
| 237 : view_(nullptr), frame_client_binding_(&test_frame_tree_client_) {} | 237 : window_(nullptr), frame_client_binding_(&test_frame_tree_client_) {} |
| 238 | 238 |
| 239 void set_view(Window* view) { view_ = view; } | 239 void set_window(Window* window) { window_ = window; } |
| 240 | 240 |
| 241 // Runs a message loop until the view and frame data have been received. | 241 // Runs a message loop until the window and frame data have been received. |
| 242 void WaitForViewAndFrame() { run_loop_.Run(); } | 242 void WaitForViewAndFrame() { run_loop_.Run(); } |
| 243 | 243 |
| 244 mojo::InterfaceRequest<mojom::Frame> GetServerFrameRequest() { | 244 mojo::InterfaceRequest<mojom::Frame> GetServerFrameRequest() { |
| 245 return test_frame_tree_client_.GetServerFrameRequest(); | 245 return test_frame_tree_client_.GetServerFrameRequest(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 mojom::FrameClientPtr GetFrameClientPtr() { | 248 mojom::FrameClientPtr GetFrameClientPtr() { |
| 249 mojom::FrameClientPtr client_ptr; | 249 mojom::FrameClientPtr client_ptr; |
| 250 frame_client_binding_.Bind(GetProxy(&client_ptr)); | 250 frame_client_binding_.Bind(GetProxy(&client_ptr)); |
| 251 return client_ptr.Pass(); | 251 return client_ptr.Pass(); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void Bind(mojo::InterfaceRequest<mojom::FrameClient> request) { | 254 void Bind(mojo::InterfaceRequest<mojom::FrameClient> request) { |
| 255 ASSERT_FALSE(frame_client_binding_.is_bound()); | 255 ASSERT_FALSE(frame_client_binding_.is_bound()); |
| 256 test_frame_tree_client_.set_on_connect_callback( | 256 test_frame_tree_client_.set_on_connect_callback( |
| 257 base::Bind(&ViewAndFrame::OnGotConnect, base::Unretained(this))); | 257 base::Bind(&WindowAndFrame::OnGotConnect, base::Unretained(this))); |
| 258 frame_client_binding_.Bind(request.Pass()); | 258 frame_client_binding_.Bind(request.Pass()); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void OnGotConnect() { QuitRunLoopIfNecessary(); } | 261 void OnGotConnect() { QuitRunLoopIfNecessary(); } |
| 262 | 262 |
| 263 void QuitRunLoopIfNecessary() { | 263 void QuitRunLoopIfNecessary() { |
| 264 if (view_ && test_frame_tree_client_.connect_count()) | 264 if (window_ && test_frame_tree_client_.connect_count()) |
| 265 run_loop_.Quit(); | 265 run_loop_.Quit(); |
| 266 } | 266 } |
| 267 | 267 |
| 268 // Overridden from WindowTreeDelegate: | 268 // Overridden from WindowTreeDelegate: |
| 269 void OnEmbed(Window* root) override { | 269 void OnEmbed(Window* root) override { |
| 270 view_ = root; | 270 window_ = root; |
| 271 QuitRunLoopIfNecessary(); | 271 QuitRunLoopIfNecessary(); |
| 272 } | 272 } |
| 273 void OnConnectionLost(WindowTreeConnection* connection) override { | 273 void OnConnectionLost(WindowTreeConnection* connection) override { |
| 274 view_ = nullptr; | 274 window_ = nullptr; |
| 275 } | 275 } |
| 276 | 276 |
| 277 mus::Window* view_; | 277 mus::Window* window_; |
| 278 base::RunLoop run_loop_; | 278 base::RunLoop run_loop_; |
| 279 TestFrameClient test_frame_tree_client_; | 279 TestFrameClient test_frame_tree_client_; |
| 280 mojo::Binding<mojom::FrameClient> frame_client_binding_; | 280 mojo::Binding<mojom::FrameClient> frame_client_binding_; |
| 281 | 281 |
| 282 DISALLOW_COPY_AND_ASSIGN(ViewAndFrame); | 282 DISALLOW_COPY_AND_ASSIGN(WindowAndFrame); |
| 283 }; | 283 }; |
| 284 | 284 |
| 285 class FrameTest : public mojo::test::ApplicationTestBase, | 285 class FrameTest : public mojo::test::ApplicationTestBase, |
| 286 public mojo::ApplicationDelegate, | 286 public mojo::ApplicationDelegate, |
| 287 public mus::WindowTreeDelegate, | 287 public mus::WindowTreeDelegate, |
| 288 public mojo::InterfaceFactory<mus::mojom::WindowTreeClient>, | 288 public mojo::InterfaceFactory<mus::mojom::WindowTreeClient>, |
| 289 public mojo::InterfaceFactory<mojom::FrameClient> { | 289 public mojo::InterfaceFactory<mojom::FrameClient> { |
| 290 public: | 290 public: |
| 291 FrameTest() : most_recent_connection_(nullptr), window_manager_(nullptr) {} | 291 FrameTest() : most_recent_connection_(nullptr), window_manager_(nullptr) {} |
| 292 | 292 |
| 293 WindowTreeConnection* most_recent_connection() { | 293 WindowTreeConnection* most_recent_connection() { |
| 294 return most_recent_connection_; | 294 return most_recent_connection_; |
| 295 } | 295 } |
| 296 | 296 |
| 297 protected: | 297 protected: |
| 298 WindowTreeConnection* window_manager() { return window_manager_; } | 298 WindowTreeConnection* window_manager() { return window_manager_; } |
| 299 TestFrameTreeDelegate* frame_tree_delegate() { | 299 TestFrameTreeDelegate* frame_tree_delegate() { |
| 300 return frame_tree_delegate_.get(); | 300 return frame_tree_delegate_.get(); |
| 301 } | 301 } |
| 302 FrameTree* frame_tree() { return frame_tree_.get(); } | 302 FrameTree* frame_tree() { return frame_tree_.get(); } |
| 303 ViewAndFrame* root_view_and_frame() { return root_view_and_frame_.get(); } | 303 WindowAndFrame* root_window_and_frame() { |
| 304 return root_window_and_frame_.get(); |
| 305 } |
| 304 | 306 |
| 305 scoped_ptr<ViewAndFrame> NavigateFrameWithStartTime( | 307 scoped_ptr<WindowAndFrame> NavigateFrameWithStartTime( |
| 306 ViewAndFrame* view_and_frame, | 308 WindowAndFrame* window_and_frame, |
| 307 base::TimeTicks navigation_start_time) { | 309 base::TimeTicks navigation_start_time) { |
| 308 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 310 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 309 request->url = mojo::String::From(application_impl()->url()); | 311 request->url = mojo::String::From(application_impl()->url()); |
| 310 request->originating_time_ticks = navigation_start_time.ToInternalValue(); | 312 request->originating_time_ticks = navigation_start_time.ToInternalValue(); |
| 311 view_and_frame->server_frame()->RequestNavigate( | 313 window_and_frame->server_frame()->RequestNavigate( |
| 312 mojom::NAVIGATION_TARGET_TYPE_EXISTING_FRAME, | 314 mojom::NAVIGATION_TARGET_TYPE_EXISTING_FRAME, |
| 313 view_and_frame->view()->id(), request.Pass()); | 315 window_and_frame->window()->id(), request.Pass()); |
| 314 return WaitForViewAndFrame(); | 316 return WaitForViewAndFrame(); |
| 315 } | 317 } |
| 316 | 318 |
| 317 scoped_ptr<ViewAndFrame> NavigateFrame(ViewAndFrame* view_and_frame) { | 319 scoped_ptr<WindowAndFrame> NavigateFrame(WindowAndFrame* window_and_frame) { |
| 318 return NavigateFrameWithStartTime(view_and_frame, base::TimeTicks()); | 320 return NavigateFrameWithStartTime(window_and_frame, base::TimeTicks()); |
| 319 } | 321 } |
| 320 | 322 |
| 321 // Creates a new shared frame as a child of |parent|. | 323 // Creates a new shared frame as a child of |parent|. |
| 322 scoped_ptr<ViewAndFrame> CreateChildViewAndFrame(ViewAndFrame* parent) { | 324 scoped_ptr<WindowAndFrame> CreateChildWindowAndFrame(WindowAndFrame* parent) { |
| 323 mus::Window* child_frame_view = | 325 mus::Window* child_frame_window = |
| 324 parent->view()->connection()->NewWindow(); | 326 parent->window()->connection()->NewWindow(); |
| 325 parent->view()->AddChild(child_frame_view); | 327 parent->window()->AddChild(child_frame_window); |
| 326 | 328 |
| 327 scoped_ptr<ViewAndFrame> view_and_frame(new ViewAndFrame); | 329 scoped_ptr<WindowAndFrame> window_and_frame(new WindowAndFrame); |
| 328 view_and_frame->set_view(child_frame_view); | 330 window_and_frame->set_window(child_frame_window); |
| 329 | 331 |
| 330 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties; | 332 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties; |
| 331 client_properties.mark_non_null(); | 333 client_properties.mark_non_null(); |
| 332 parent->server_frame()->OnCreatedFrame( | 334 parent->server_frame()->OnCreatedFrame( |
| 333 view_and_frame->GetServerFrameRequest(), | 335 window_and_frame->GetServerFrameRequest(), |
| 334 view_and_frame->GetFrameClientPtr(), child_frame_view->id(), | 336 window_and_frame->GetFrameClientPtr(), child_frame_window->id(), |
| 335 client_properties.Pass()); | 337 client_properties.Pass()); |
| 336 frame_tree_delegate()->WaitForCreateFrame(); | 338 frame_tree_delegate()->WaitForCreateFrame(); |
| 337 return HasFatalFailure() ? nullptr : view_and_frame.Pass(); | 339 return HasFatalFailure() ? nullptr : window_and_frame.Pass(); |
| 338 } | 340 } |
| 339 | 341 |
| 340 // Runs a message loop until the data necessary to represent to a client side | 342 // Runs a message loop until the data necessary to represent to a client side |
| 341 // frame has been obtained. | 343 // frame has been obtained. |
| 342 scoped_ptr<ViewAndFrame> WaitForViewAndFrame() { | 344 scoped_ptr<WindowAndFrame> WaitForViewAndFrame() { |
| 343 DCHECK(!view_and_frame_); | 345 DCHECK(!window_and_frame_); |
| 344 view_and_frame_.reset(new ViewAndFrame); | 346 window_and_frame_.reset(new WindowAndFrame); |
| 345 view_and_frame_->WaitForViewAndFrame(); | 347 window_and_frame_->WaitForViewAndFrame(); |
| 346 return view_and_frame_.Pass(); | 348 return window_and_frame_.Pass(); |
| 347 } | 349 } |
| 348 | 350 |
| 349 private: | 351 private: |
| 350 // ApplicationTestBase: | 352 // ApplicationTestBase: |
| 351 ApplicationDelegate* GetApplicationDelegate() override { return this; } | 353 ApplicationDelegate* GetApplicationDelegate() override { return this; } |
| 352 | 354 |
| 353 // ApplicationDelegate implementation. | 355 // ApplicationDelegate implementation. |
| 354 bool ConfigureIncomingConnection( | 356 bool ConfigureIncomingConnection( |
| 355 mojo::ApplicationConnection* connection) override { | 357 mojo::ApplicationConnection* connection) override { |
| 356 connection->AddService<mus::mojom::WindowTreeClient>(this); | 358 connection->AddService<mus::mojom::WindowTreeClient>(this); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 373 | 375 |
| 374 ASSERT_TRUE(DoRunLoopWithTimeout()); | 376 ASSERT_TRUE(DoRunLoopWithTimeout()); |
| 375 std::swap(window_manager_, most_recent_connection_); | 377 std::swap(window_manager_, most_recent_connection_); |
| 376 | 378 |
| 377 // Creates a FrameTree, which creates a single frame. Wait for the | 379 // Creates a FrameTree, which creates a single frame. Wait for the |
| 378 // FrameClient to be connected to. | 380 // FrameClient to be connected to. |
| 379 frame_tree_delegate_.reset(new TestFrameTreeDelegate(application_impl())); | 381 frame_tree_delegate_.reset(new TestFrameTreeDelegate(application_impl())); |
| 380 scoped_ptr<FrameConnection> frame_connection = | 382 scoped_ptr<FrameConnection> frame_connection = |
| 381 CreateFrameConnection(application_impl()); | 383 CreateFrameConnection(application_impl()); |
| 382 mojom::FrameClient* frame_client = frame_connection->frame_client(); | 384 mojom::FrameClient* frame_client = frame_connection->frame_client(); |
| 383 mus::mojom::WindowTreeClientPtr view_tree_client = | 385 mus::mojom::WindowTreeClientPtr window_tree_client = |
| 384 frame_connection->GetWindowTreeClient(); | 386 frame_connection->GetWindowTreeClient(); |
| 385 mus::Window* frame_root_view = window_manager()->NewWindow(); | 387 mus::Window* frame_root_view = window_manager()->NewWindow(); |
| 386 window_manager()->GetRoot()->AddChild(frame_root_view); | 388 window_manager()->GetRoot()->AddChild(frame_root_view); |
| 387 frame_tree_.reset(new FrameTree( | 389 frame_tree_.reset(new FrameTree( |
| 388 0u, frame_root_view, view_tree_client.Pass(), | 390 0u, frame_root_view, window_tree_client.Pass(), |
| 389 frame_tree_delegate_.get(), frame_client, frame_connection.Pass(), | 391 frame_tree_delegate_.get(), frame_client, frame_connection.Pass(), |
| 390 Frame::ClientPropertyMap(), base::TimeTicks::Now())); | 392 Frame::ClientPropertyMap(), base::TimeTicks::Now())); |
| 391 root_view_and_frame_ = WaitForViewAndFrame(); | 393 root_window_and_frame_ = WaitForViewAndFrame(); |
| 392 } | 394 } |
| 393 | 395 |
| 394 // Overridden from testing::Test: | 396 // Overridden from testing::Test: |
| 395 void TearDown() override { | 397 void TearDown() override { |
| 396 root_view_and_frame_.reset(); | 398 root_window_and_frame_.reset(); |
| 397 frame_tree_.reset(); | 399 frame_tree_.reset(); |
| 398 frame_tree_delegate_.reset(); | 400 frame_tree_delegate_.reset(); |
| 399 ApplicationTestBase::TearDown(); | 401 ApplicationTestBase::TearDown(); |
| 400 } | 402 } |
| 401 | 403 |
| 402 // Overridden from mojo::InterfaceFactory<mus::mojom::WindowTreeClient>: | 404 // Overridden from mojo::InterfaceFactory<mus::mojom::WindowTreeClient>: |
| 403 void Create( | 405 void Create( |
| 404 mojo::ApplicationConnection* connection, | 406 mojo::ApplicationConnection* connection, |
| 405 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) override { | 407 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) override { |
| 406 if (view_and_frame_) { | 408 if (window_and_frame_) { |
| 407 mus::WindowTreeConnection::Create( | 409 mus::WindowTreeConnection::Create( |
| 408 view_and_frame_.get(), request.Pass(), | 410 window_and_frame_.get(), request.Pass(), |
| 409 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); | 411 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); |
| 410 } else { | 412 } else { |
| 411 mus::WindowTreeConnection::Create( | 413 mus::WindowTreeConnection::Create( |
| 412 this, request.Pass(), | 414 this, request.Pass(), |
| 413 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); | 415 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); |
| 414 } | 416 } |
| 415 } | 417 } |
| 416 | 418 |
| 417 // Overridden from mojo::InterfaceFactory<mojom::FrameClient>: | 419 // Overridden from mojo::InterfaceFactory<mojom::FrameClient>: |
| 418 void Create(mojo::ApplicationConnection* connection, | 420 void Create(mojo::ApplicationConnection* connection, |
| 419 mojo::InterfaceRequest<mojom::FrameClient> request) override { | 421 mojo::InterfaceRequest<mojom::FrameClient> request) override { |
| 420 ASSERT_TRUE(view_and_frame_); | 422 ASSERT_TRUE(window_and_frame_); |
| 421 view_and_frame_->Bind(request.Pass()); | 423 window_and_frame_->Bind(request.Pass()); |
| 422 } | 424 } |
| 423 | 425 |
| 424 scoped_ptr<TestFrameTreeDelegate> frame_tree_delegate_; | 426 scoped_ptr<TestFrameTreeDelegate> frame_tree_delegate_; |
| 425 scoped_ptr<FrameTree> frame_tree_; | 427 scoped_ptr<FrameTree> frame_tree_; |
| 426 scoped_ptr<ViewAndFrame> root_view_and_frame_; | 428 scoped_ptr<WindowAndFrame> root_window_and_frame_; |
| 427 | 429 |
| 428 mus::mojom::WindowTreeHostPtr host_; | 430 mus::mojom::WindowTreeHostPtr host_; |
| 429 | 431 |
| 430 // Used to receive the most recent view manager loaded by an embed action. | 432 // Used to receive the most recent window manager loaded by an embed action. |
| 431 WindowTreeConnection* most_recent_connection_; | 433 WindowTreeConnection* most_recent_connection_; |
| 432 // The View Manager connection held by the window manager (app running at the | 434 // The Window Manager connection held by the window manager (app running at |
| 433 // root view). | 435 // the |
| 436 // root window). |
| 434 WindowTreeConnection* window_manager_; | 437 WindowTreeConnection* window_manager_; |
| 435 | 438 |
| 436 scoped_ptr<ViewAndFrame> view_and_frame_; | 439 scoped_ptr<WindowAndFrame> window_and_frame_; |
| 437 | 440 |
| 438 MOJO_DISALLOW_COPY_AND_ASSIGN(FrameTest); | 441 MOJO_DISALLOW_COPY_AND_ASSIGN(FrameTest); |
| 439 }; | 442 }; |
| 440 | 443 |
| 441 // Verifies the FrameData supplied to the root FrameClient::OnConnect(). | 444 // Verifies the FrameData supplied to the root FrameClient::OnConnect(). |
| 442 TEST_F(FrameTest, RootFrameClientConnectData) { | 445 TEST_F(FrameTest, RootFrameClientConnectData) { |
| 443 mojo::Array<mojom::FrameDataPtr> frames = | 446 mojo::Array<mojom::FrameDataPtr> frames = |
| 444 root_view_and_frame()->test_frame_client()->connect_frames(); | 447 root_window_and_frame()->test_frame_client()->connect_frames(); |
| 445 ASSERT_EQ(1u, frames.size()); | 448 ASSERT_EQ(1u, frames.size()); |
| 446 EXPECT_EQ(root_view_and_frame()->view()->id(), frames[0]->frame_id); | 449 EXPECT_EQ(root_window_and_frame()->window()->id(), frames[0]->frame_id); |
| 447 EXPECT_EQ(0u, frames[0]->parent_id); | 450 EXPECT_EQ(0u, frames[0]->parent_id); |
| 448 } | 451 } |
| 449 | 452 |
| 450 // Verifies the FrameData supplied to a child FrameClient::OnConnect(). | 453 // Verifies the FrameData supplied to a child FrameClient::OnConnect(). |
| 451 TEST_F(FrameTest, ChildFrameClientConnectData) { | 454 TEST_F(FrameTest, ChildFrameClientConnectData) { |
| 452 scoped_ptr<ViewAndFrame> child_view_and_frame( | 455 scoped_ptr<WindowAndFrame> child_view_and_frame( |
| 453 CreateChildViewAndFrame(root_view_and_frame())); | 456 CreateChildWindowAndFrame(root_window_and_frame())); |
| 454 ASSERT_TRUE(child_view_and_frame); | 457 ASSERT_TRUE(child_view_and_frame); |
| 455 // Initially created child frames don't get OnConnect(). | 458 // Initially created child frames don't get OnConnect(). |
| 456 EXPECT_EQ(0, child_view_and_frame->test_frame_client()->connect_count()); | 459 EXPECT_EQ(0, child_view_and_frame->test_frame_client()->connect_count()); |
| 457 | 460 |
| 458 scoped_ptr<ViewAndFrame> navigated_child_view_and_frame = | 461 scoped_ptr<WindowAndFrame> navigated_child_view_and_frame = |
| 459 NavigateFrame(child_view_and_frame.get()).Pass(); | 462 NavigateFrame(child_view_and_frame.get()).Pass(); |
| 460 | 463 |
| 461 mojo::Array<mojom::FrameDataPtr> frames_in_child = | 464 mojo::Array<mojom::FrameDataPtr> frames_in_child = |
| 462 navigated_child_view_and_frame->test_frame_client()->connect_frames(); | 465 navigated_child_view_and_frame->test_frame_client()->connect_frames(); |
| 463 EXPECT_EQ(child_view_and_frame->view()->id(), | 466 EXPECT_EQ(child_view_and_frame->window()->id(), |
| 464 navigated_child_view_and_frame->view()->id()); | 467 navigated_child_view_and_frame->window()->id()); |
| 465 // We expect 2 frames. One for the root, one for the child. | 468 // We expect 2 frames. One for the root, one for the child. |
| 466 ASSERT_EQ(2u, frames_in_child.size()); | 469 ASSERT_EQ(2u, frames_in_child.size()); |
| 467 EXPECT_EQ(frame_tree()->root()->id(), frames_in_child[0]->frame_id); | 470 EXPECT_EQ(frame_tree()->root()->id(), frames_in_child[0]->frame_id); |
| 468 EXPECT_EQ(0u, frames_in_child[0]->parent_id); | 471 EXPECT_EQ(0u, frames_in_child[0]->parent_id); |
| 469 EXPECT_EQ(navigated_child_view_and_frame->view()->id(), | 472 EXPECT_EQ(navigated_child_view_and_frame->window()->id(), |
| 470 frames_in_child[1]->frame_id); | 473 frames_in_child[1]->frame_id); |
| 471 EXPECT_EQ(frame_tree()->root()->id(), frames_in_child[1]->parent_id); | 474 EXPECT_EQ(frame_tree()->root()->id(), frames_in_child[1]->parent_id); |
| 472 } | 475 } |
| 473 | 476 |
| 474 TEST_F(FrameTest, OnViewEmbeddedInFrameDisconnected) { | 477 TEST_F(FrameTest, OnViewEmbeddedInFrameDisconnected) { |
| 475 scoped_ptr<ViewAndFrame> child_view_and_frame( | 478 scoped_ptr<WindowAndFrame> child_view_and_frame( |
| 476 CreateChildViewAndFrame(root_view_and_frame())); | 479 CreateChildWindowAndFrame(root_window_and_frame())); |
| 477 ASSERT_TRUE(child_view_and_frame); | 480 ASSERT_TRUE(child_view_and_frame); |
| 478 | 481 |
| 479 scoped_ptr<ViewAndFrame> navigated_child_view_and_frame = | 482 scoped_ptr<WindowAndFrame> navigated_child_view_and_frame = |
| 480 NavigateFrame(child_view_and_frame.get()).Pass(); | 483 NavigateFrame(child_view_and_frame.get()).Pass(); |
| 481 | 484 |
| 482 // Delete the WindowTreeConnection for the child, which should trigger | 485 // Delete the WindowTreeConnection for the child, which should trigger |
| 483 // notification. | 486 // notification. |
| 484 delete navigated_child_view_and_frame->view()->connection(); | 487 delete navigated_child_view_and_frame->window()->connection(); |
| 485 ASSERT_EQ(1u, frame_tree()->root()->children().size()); | 488 ASSERT_EQ(1u, frame_tree()->root()->children().size()); |
| 486 ASSERT_NO_FATAL_FAILURE(frame_tree_delegate()->WaitForFrameDisconnected( | 489 ASSERT_NO_FATAL_FAILURE(frame_tree_delegate()->WaitForFrameDisconnected( |
| 487 frame_tree()->root()->children()[0])); | 490 frame_tree()->root()->children()[0])); |
| 488 ASSERT_EQ(1u, frame_tree()->root()->children().size()); | 491 ASSERT_EQ(1u, frame_tree()->root()->children().size()); |
| 489 } | 492 } |
| 490 | 493 |
| 491 TEST_F(FrameTest, NotifyRemoteParentWithLoadingState) { | 494 TEST_F(FrameTest, NotifyRemoteParentWithLoadingState) { |
| 492 scoped_ptr<ViewAndFrame> child_view_and_frame( | 495 scoped_ptr<WindowAndFrame> child_view_and_frame( |
| 493 CreateChildViewAndFrame(root_view_and_frame())); | 496 CreateChildWindowAndFrame(root_window_and_frame())); |
| 494 uint32_t child_frame_id = child_view_and_frame->view()->id(); | 497 uint32_t child_frame_id = child_view_and_frame->window()->id(); |
| 495 | 498 |
| 496 { | 499 { |
| 497 base::RunLoop run_loop; | 500 base::RunLoop run_loop; |
| 498 root_view_and_frame() | 501 root_window_and_frame() |
| 499 ->test_frame_client() | 502 ->test_frame_client() |
| 500 ->set_on_loading_state_changed_callback(run_loop.QuitClosure()); | 503 ->set_on_loading_state_changed_callback(run_loop.QuitClosure()); |
| 501 | 504 |
| 502 child_view_and_frame->server_frame()->LoadingStateChanged(true, .5); | 505 child_view_and_frame->server_frame()->LoadingStateChanged(true, .5); |
| 503 | 506 |
| 504 run_loop.Run(); | 507 run_loop.Run(); |
| 505 | 508 |
| 506 uint32_t frame_id = 0; | 509 uint32_t frame_id = 0; |
| 507 bool loading = false; | 510 bool loading = false; |
| 508 root_view_and_frame() | 511 root_window_and_frame() |
| 509 ->test_frame_client() | 512 ->test_frame_client() |
| 510 ->last_loading_state_changed_notification(&frame_id, &loading); | 513 ->last_loading_state_changed_notification(&frame_id, &loading); |
| 511 EXPECT_EQ(child_frame_id, frame_id); | 514 EXPECT_EQ(child_frame_id, frame_id); |
| 512 EXPECT_TRUE(loading); | 515 EXPECT_TRUE(loading); |
| 513 } | 516 } |
| 514 { | 517 { |
| 515 base::RunLoop run_loop; | 518 base::RunLoop run_loop; |
| 516 root_view_and_frame() | 519 root_window_and_frame() |
| 517 ->test_frame_client() | 520 ->test_frame_client() |
| 518 ->set_on_loading_state_changed_callback(run_loop.QuitClosure()); | 521 ->set_on_loading_state_changed_callback(run_loop.QuitClosure()); |
| 519 | 522 |
| 520 ASSERT_TRUE(child_view_and_frame); | 523 ASSERT_TRUE(child_view_and_frame); |
| 521 ASSERT_TRUE(child_view_and_frame->server_frame()); | 524 ASSERT_TRUE(child_view_and_frame->server_frame()); |
| 522 | 525 |
| 523 child_view_and_frame->server_frame()->LoadingStateChanged(false, 1); | 526 child_view_and_frame->server_frame()->LoadingStateChanged(false, 1); |
| 524 | 527 |
| 525 run_loop.Run(); | 528 run_loop.Run(); |
| 526 | 529 |
| 527 uint32_t frame_id = 0; | 530 uint32_t frame_id = 0; |
| 528 bool loading = false; | 531 bool loading = false; |
| 529 root_view_and_frame() | 532 root_window_and_frame() |
| 530 ->test_frame_client() | 533 ->test_frame_client() |
| 531 ->last_loading_state_changed_notification(&frame_id, &loading); | 534 ->last_loading_state_changed_notification(&frame_id, &loading); |
| 532 EXPECT_EQ(child_frame_id, frame_id); | 535 EXPECT_EQ(child_frame_id, frame_id); |
| 533 EXPECT_FALSE(loading); | 536 EXPECT_FALSE(loading); |
| 534 } | 537 } |
| 535 } | 538 } |
| 536 | 539 |
| 537 TEST_F(FrameTest, NotifyRemoteParentWithLoadEvent) { | 540 TEST_F(FrameTest, NotifyRemoteParentWithLoadEvent) { |
| 538 scoped_ptr<ViewAndFrame> child_view_and_frame( | 541 scoped_ptr<WindowAndFrame> child_view_and_frame( |
| 539 CreateChildViewAndFrame(root_view_and_frame())); | 542 CreateChildWindowAndFrame(root_window_and_frame())); |
| 540 uint32_t child_frame_id = child_view_and_frame->view()->id(); | 543 uint32_t child_frame_id = child_view_and_frame->window()->id(); |
| 541 | 544 |
| 542 base::RunLoop run_loop; | 545 base::RunLoop run_loop; |
| 543 root_view_and_frame() | 546 root_window_and_frame() |
| 544 ->test_frame_client() | 547 ->test_frame_client() |
| 545 ->set_on_dispatch_load_event_callback(run_loop.QuitClosure()); | 548 ->set_on_dispatch_load_event_callback(run_loop.QuitClosure()); |
| 546 | 549 |
| 547 child_view_and_frame->server_frame()->DispatchLoadEventToParent(); | 550 child_view_and_frame->server_frame()->DispatchLoadEventToParent(); |
| 548 | 551 |
| 549 run_loop.Run(); | 552 run_loop.Run(); |
| 550 | 553 |
| 551 uint32_t frame_id = root_view_and_frame() | 554 uint32_t frame_id = root_window_and_frame() |
| 552 ->test_frame_client() | 555 ->test_frame_client() |
| 553 ->last_dispatch_load_event_frame_id(); | 556 ->last_dispatch_load_event_frame_id(); |
| 554 EXPECT_EQ(child_frame_id, frame_id); | 557 EXPECT_EQ(child_frame_id, frame_id); |
| 555 } | 558 } |
| 556 | 559 |
| 557 TEST_F(FrameTest, PassAlongNavigationStartTime) { | 560 TEST_F(FrameTest, PassAlongNavigationStartTime) { |
| 558 scoped_ptr<ViewAndFrame> child_view_and_frame( | 561 scoped_ptr<WindowAndFrame> child_view_and_frame( |
| 559 CreateChildViewAndFrame(root_view_and_frame())); | 562 CreateChildWindowAndFrame(root_window_and_frame())); |
| 560 ASSERT_TRUE(child_view_and_frame); | 563 ASSERT_TRUE(child_view_and_frame); |
| 561 | 564 |
| 562 base::TimeTicks navigation_start_time = base::TimeTicks::FromInternalValue(1); | 565 base::TimeTicks navigation_start_time = base::TimeTicks::FromInternalValue(1); |
| 563 scoped_ptr<ViewAndFrame> navigated_child_view_and_frame = | 566 scoped_ptr<WindowAndFrame> navigated_child_view_and_frame = |
| 564 NavigateFrameWithStartTime(child_view_and_frame.get(), | 567 NavigateFrameWithStartTime(child_view_and_frame.get(), |
| 565 navigation_start_time) | 568 navigation_start_time) |
| 566 .Pass(); | 569 .Pass(); |
| 567 EXPECT_EQ(navigation_start_time, | 570 EXPECT_EQ(navigation_start_time, |
| 568 navigated_child_view_and_frame->test_frame_client() | 571 navigated_child_view_and_frame->test_frame_client() |
| 569 ->last_navigation_start_time()); | 572 ->last_navigation_start_time()); |
| 570 } | 573 } |
| 571 | 574 |
| 572 } // namespace web_view | 575 } // namespace web_view |
| OLD | NEW |