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

Side by Side Diff: content/browser/renderer_host/render_widget_host_unittest.cc

Issue 659093002: Pass the size to the RenderView on creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@java_enum
Patch Set: rebase Created 6 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/shared_memory.h" 9 #include "base/memory/shared_memory.h"
10 #include "base/timer/timer.h" 10 #include "base/timer/timer.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 MockRenderWidgetHost( 132 MockRenderWidgetHost(
133 RenderWidgetHostDelegate* delegate, 133 RenderWidgetHostDelegate* delegate,
134 RenderProcessHost* process, 134 RenderProcessHost* process,
135 int routing_id) 135 int routing_id)
136 : RenderWidgetHostImpl(delegate, process, routing_id, false), 136 : RenderWidgetHostImpl(delegate, process, routing_id, false),
137 unresponsive_timer_fired_(false) { 137 unresponsive_timer_fired_(false) {
138 acked_touch_event_type_ = blink::WebInputEvent::Undefined; 138 acked_touch_event_type_ = blink::WebInputEvent::Undefined;
139 } 139 }
140 140
141 // Allow poking at a few private members. 141 // Allow poking at a few private members.
142 using RenderWidgetHostImpl::GetResizeParams;
142 using RenderWidgetHostImpl::OnUpdateRect; 143 using RenderWidgetHostImpl::OnUpdateRect;
143 using RenderWidgetHostImpl::RendererExited; 144 using RenderWidgetHostImpl::RendererExited;
144 using RenderWidgetHostImpl::last_requested_size_; 145 using RenderWidgetHostImpl::SetInitialRenderSizeParams;
146 using RenderWidgetHostImpl::old_resize_params_;
145 using RenderWidgetHostImpl::is_hidden_; 147 using RenderWidgetHostImpl::is_hidden_;
146 using RenderWidgetHostImpl::resize_ack_pending_; 148 using RenderWidgetHostImpl::resize_ack_pending_;
147 using RenderWidgetHostImpl::input_router_; 149 using RenderWidgetHostImpl::input_router_;
148 150
149 void OnTouchEventAck(const TouchEventWithLatencyInfo& event, 151 void OnTouchEventAck(const TouchEventWithLatencyInfo& event,
150 InputEventAckState ack_result) override { 152 InputEventAckState ack_result) override {
151 // Sniff touch acks. 153 // Sniff touch acks.
152 acked_touch_event_type_ = event.event.type; 154 acked_touch_event_type_ = event.event.type;
153 RenderWidgetHostImpl::OnTouchEventAck(event, ack_result); 155 RenderWidgetHostImpl::OnTouchEventAck(event, ack_result);
154 } 156 }
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 } 435 }
434 #endif 436 #endif
435 #if defined(USE_AURA) 437 #if defined(USE_AURA)
436 aura::Env::CreateInstance(true); 438 aura::Env::CreateInstance(true);
437 screen_.reset(aura::TestScreen::Create(gfx::Size())); 439 screen_.reset(aura::TestScreen::Create(gfx::Size()));
438 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); 440 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
439 #endif 441 #endif
440 host_.reset( 442 host_.reset(
441 new MockRenderWidgetHost(delegate_.get(), process_, MSG_ROUTING_NONE)); 443 new MockRenderWidgetHost(delegate_.get(), process_, MSG_ROUTING_NONE));
442 view_.reset(new TestView(host_.get())); 444 view_.reset(new TestView(host_.get()));
445 ConfigureView(view_.get());
443 host_->SetView(view_.get()); 446 host_->SetView(view_.get());
447 SetInitialRenderSizeParams();
444 host_->Init(); 448 host_->Init();
445 host_->DisableGestureDebounce(); 449 host_->DisableGestureDebounce();
446 } 450 }
451
447 void TearDown() override { 452 void TearDown() override {
448 view_.reset(); 453 view_.reset();
449 host_.reset(); 454 host_.reset();
450 delegate_.reset(); 455 delegate_.reset();
451 process_ = NULL; 456 process_ = NULL;
452 browser_context_.reset(); 457 browser_context_.reset();
453 458
454 #if defined(USE_AURA) 459 #if defined(USE_AURA)
455 aura::Env::DeleteInstance(); 460 aura::Env::DeleteInstance();
456 screen_.reset(); 461 screen_.reset();
457 #endif 462 #endif
458 #if defined(USE_AURA) || (defined(OS_MACOSX) && !defined(OS_IOS)) 463 #if defined(USE_AURA) || (defined(OS_MACOSX) && !defined(OS_IOS))
459 if (IsDelegatedRendererEnabled()) 464 if (IsDelegatedRendererEnabled())
460 ImageTransportFactory::Terminate(); 465 ImageTransportFactory::Terminate();
461 #endif 466 #endif
462 467
463 // Process all pending tasks to avoid leaks. 468 // Process all pending tasks to avoid leaks.
464 base::MessageLoop::current()->RunUntilIdle(); 469 base::MessageLoop::current()->RunUntilIdle();
465 } 470 }
466 471
472 void SetInitialRenderSizeParams() {
473 ViewMsg_Resize_Params render_size_params;
474 host_->GetResizeParams(&render_size_params);
475 host_->SetInitialRenderSizeParams(render_size_params);
476 }
477
478 virtual void ConfigureView(TestView* view) {
479 }
480
467 int64 GetLatencyComponentId() { 481 int64 GetLatencyComponentId() {
468 return host_->GetLatencyComponentId(); 482 return host_->GetLatencyComponentId();
469 } 483 }
470 484
471 void SendInputEventACK(WebInputEvent::Type type, 485 void SendInputEventACK(WebInputEvent::Type type,
472 InputEventAckState ack_result) { 486 InputEventAckState ack_result) {
473 InputHostMsg_HandleInputEvent_ACK_Params ack; 487 InputHostMsg_HandleInputEvent_ACK_Params ack;
474 ack.type = type; 488 ack.type = type;
475 ack.state = ack_result; 489 ack.state = ack_result;
476 host_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack)); 490 host_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack));
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 637 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
624 638
625 // Setting the bounds to a "real" rect should send out the notification. 639 // Setting the bounds to a "real" rect should send out the notification.
626 // but should not expect ack for empty physical backing size. 640 // but should not expect ack for empty physical backing size.
627 gfx::Rect original_size(0, 0, 100, 100); 641 gfx::Rect original_size(0, 0, 100, 100);
628 process_->sink().ClearMessages(); 642 process_->sink().ClearMessages();
629 view_->set_bounds(original_size); 643 view_->set_bounds(original_size);
630 view_->SetMockPhysicalBackingSize(gfx::Size()); 644 view_->SetMockPhysicalBackingSize(gfx::Size());
631 host_->WasResized(); 645 host_->WasResized();
632 EXPECT_FALSE(host_->resize_ack_pending_); 646 EXPECT_FALSE(host_->resize_ack_pending_);
633 EXPECT_EQ(original_size.size(), host_->last_requested_size_); 647 EXPECT_EQ(original_size.size(), host_->old_resize_params_->new_size);
634 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 648 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
635 649
636 // Setting the bounds to a "real" rect should send out the notification. 650 // Setting the bounds to a "real" rect should send out the notification.
637 // but should not expect ack for only physical backing size change. 651 // but should not expect ack for only physical backing size change.
638 process_->sink().ClearMessages(); 652 process_->sink().ClearMessages();
639 view_->ClearMockPhysicalBackingSize(); 653 view_->ClearMockPhysicalBackingSize();
640 host_->WasResized(); 654 host_->WasResized();
641 EXPECT_FALSE(host_->resize_ack_pending_); 655 EXPECT_FALSE(host_->resize_ack_pending_);
642 EXPECT_EQ(original_size.size(), host_->last_requested_size_); 656 EXPECT_EQ(original_size.size(), host_->old_resize_params_->new_size);
643 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 657 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
644 658
645 // Send out a update that's not a resize ack after setting resize ack pending 659 // Send out a update that's not a resize ack after setting resize ack pending
646 // flag. This should not clean the resize ack pending flag. 660 // flag. This should not clean the resize ack pending flag.
647 process_->sink().ClearMessages(); 661 process_->sink().ClearMessages();
648 gfx::Rect second_size(0, 0, 110, 110); 662 gfx::Rect second_size(0, 0, 110, 110);
649 EXPECT_FALSE(host_->resize_ack_pending_); 663 EXPECT_FALSE(host_->resize_ack_pending_);
650 view_->set_bounds(second_size); 664 view_->set_bounds(second_size);
651 host_->WasResized(); 665 host_->WasResized();
652 EXPECT_TRUE(host_->resize_ack_pending_); 666 EXPECT_TRUE(host_->resize_ack_pending_);
653 ViewHostMsg_UpdateRect_Params params; 667 ViewHostMsg_UpdateRect_Params params;
654 process_->InitUpdateRectParams(&params); 668 process_->InitUpdateRectParams(&params);
655 host_->OnUpdateRect(params); 669 host_->OnUpdateRect(params);
656 EXPECT_TRUE(host_->resize_ack_pending_); 670 EXPECT_TRUE(host_->resize_ack_pending_);
657 EXPECT_EQ(second_size.size(), host_->last_requested_size_); 671 EXPECT_EQ(second_size.size(), host_->old_resize_params_->new_size);
658 672
659 // Sending out a new notification should NOT send out a new IPC message since 673 // Sending out a new notification should NOT send out a new IPC message since
660 // a resize ACK is pending. 674 // a resize ACK is pending.
661 gfx::Rect third_size(0, 0, 120, 120); 675 gfx::Rect third_size(0, 0, 120, 120);
662 process_->sink().ClearMessages(); 676 process_->sink().ClearMessages();
663 view_->set_bounds(third_size); 677 view_->set_bounds(third_size);
664 host_->WasResized(); 678 host_->WasResized();
665 EXPECT_TRUE(host_->resize_ack_pending_); 679 EXPECT_TRUE(host_->resize_ack_pending_);
666 EXPECT_EQ(second_size.size(), host_->last_requested_size_); 680 EXPECT_EQ(second_size.size(), host_->old_resize_params_->new_size);
667 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 681 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
668 682
669 // Send a update that's a resize ack, but for the original_size we sent. Since 683 // Send a update that's a resize ack, but for the original_size we sent. Since
670 // this isn't the second_size, the message handler should immediately send 684 // this isn't the second_size, the message handler should immediately send
671 // a new resize message for the new size to the renderer. 685 // a new resize message for the new size to the renderer.
672 process_->sink().ClearMessages(); 686 process_->sink().ClearMessages();
673 params.flags = ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; 687 params.flags = ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
674 params.view_size = original_size.size(); 688 params.view_size = original_size.size();
675 host_->OnUpdateRect(params); 689 host_->OnUpdateRect(params);
676 EXPECT_TRUE(host_->resize_ack_pending_); 690 EXPECT_TRUE(host_->resize_ack_pending_);
677 EXPECT_EQ(third_size.size(), host_->last_requested_size_); 691 EXPECT_EQ(third_size.size(), host_->old_resize_params_->new_size);
678 ASSERT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 692 ASSERT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
679 693
680 // Send the resize ack for the latest size. 694 // Send the resize ack for the latest size.
681 process_->sink().ClearMessages(); 695 process_->sink().ClearMessages();
682 params.view_size = third_size.size(); 696 params.view_size = third_size.size();
683 host_->OnUpdateRect(params); 697 host_->OnUpdateRect(params);
684 EXPECT_FALSE(host_->resize_ack_pending_); 698 EXPECT_FALSE(host_->resize_ack_pending_);
685 EXPECT_EQ(third_size.size(), host_->last_requested_size_); 699 EXPECT_EQ(third_size.size(), host_->old_resize_params_->new_size);
686 ASSERT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID)); 700 ASSERT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID));
687 701
688 // Now clearing the bounds should send out a notification but we shouldn't 702 // Now clearing the bounds should send out a notification but we shouldn't
689 // expect a resize ack (since the renderer won't ack empty sizes). The message 703 // expect a resize ack (since the renderer won't ack empty sizes). The message
690 // should contain the new size (0x0) and not the previous one that we skipped 704 // should contain the new size (0x0) and not the previous one that we skipped
691 process_->sink().ClearMessages(); 705 process_->sink().ClearMessages();
692 view_->set_bounds(gfx::Rect()); 706 view_->set_bounds(gfx::Rect());
693 host_->WasResized(); 707 host_->WasResized();
694 EXPECT_FALSE(host_->resize_ack_pending_); 708 EXPECT_FALSE(host_->resize_ack_pending_);
695 EXPECT_EQ(gfx::Size(), host_->last_requested_size_); 709 EXPECT_EQ(gfx::Size(), host_->old_resize_params_->new_size);
696 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 710 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
697 711
698 // Send a rect that has no area but has either width or height set. 712 // Send a rect that has no area but has either width or height set.
699 process_->sink().ClearMessages(); 713 process_->sink().ClearMessages();
700 view_->set_bounds(gfx::Rect(0, 0, 0, 30)); 714 view_->set_bounds(gfx::Rect(0, 0, 0, 30));
701 host_->WasResized(); 715 host_->WasResized();
702 EXPECT_FALSE(host_->resize_ack_pending_); 716 EXPECT_FALSE(host_->resize_ack_pending_);
703 EXPECT_EQ(gfx::Size(0, 30), host_->last_requested_size_); 717 EXPECT_EQ(gfx::Size(0, 30), host_->old_resize_params_->new_size);
704 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 718 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
705 719
706 // Set the same size again. It should not be sent again. 720 // Set the same size again. It should not be sent again.
707 process_->sink().ClearMessages(); 721 process_->sink().ClearMessages();
708 host_->WasResized(); 722 host_->WasResized();
709 EXPECT_FALSE(host_->resize_ack_pending_); 723 EXPECT_FALSE(host_->resize_ack_pending_);
710 EXPECT_EQ(gfx::Size(0, 30), host_->last_requested_size_); 724 EXPECT_EQ(gfx::Size(0, 30), host_->old_resize_params_->new_size);
711 EXPECT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID)); 725 EXPECT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID));
712 726
713 // A different size should be sent again, however. 727 // A different size should be sent again, however.
714 view_->set_bounds(gfx::Rect(0, 0, 0, 31)); 728 view_->set_bounds(gfx::Rect(0, 0, 0, 31));
715 host_->WasResized(); 729 host_->WasResized();
716 EXPECT_FALSE(host_->resize_ack_pending_); 730 EXPECT_FALSE(host_->resize_ack_pending_);
717 EXPECT_EQ(gfx::Size(0, 31), host_->last_requested_size_); 731 EXPECT_EQ(gfx::Size(0, 31), host_->old_resize_params_->new_size);
718 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 732 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
719 } 733 }
720 734
721 // Test for crbug.com/25097. If a renderer crashes between a resize and the 735 // Test for crbug.com/25097. If a renderer crashes between a resize and the
722 // corresponding update message, we must be sure to clear the resize ack logic. 736 // corresponding update message, we must be sure to clear the resize ack logic.
723 TEST_F(RenderWidgetHostTest, ResizeThenCrash) { 737 TEST_F(RenderWidgetHostTest, ResizeThenCrash) {
724 // Clear the first Resize message that carried screen info. 738 // Clear the first Resize message that carried screen info.
725 process_->sink().ClearMessages(); 739 process_->sink().ClearMessages();
726 740
727 // Setting the bounds to a "real" rect should send out the notification. 741 // Setting the bounds to a "real" rect should send out the notification.
728 gfx::Rect original_size(0, 0, 100, 100); 742 gfx::Rect original_size(0, 0, 100, 100);
729 view_->set_bounds(original_size); 743 view_->set_bounds(original_size);
730 host_->WasResized(); 744 host_->WasResized();
731 EXPECT_TRUE(host_->resize_ack_pending_); 745 EXPECT_TRUE(host_->resize_ack_pending_);
732 EXPECT_EQ(original_size.size(), host_->last_requested_size_); 746 EXPECT_EQ(original_size.size(), host_->old_resize_params_->new_size);
733 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 747 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
734 748
735 // Simulate a renderer crash before the update message. Ensure all the 749 // Simulate a renderer crash before the update message. Ensure all the
736 // resize ack logic is cleared. Must clear the view first so it doesn't get 750 // resize ack logic is cleared. Must clear the view first so it doesn't get
737 // deleted. 751 // deleted.
738 host_->SetView(NULL); 752 host_->SetView(NULL);
739 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); 753 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
740 EXPECT_FALSE(host_->resize_ack_pending_); 754 EXPECT_FALSE(host_->resize_ack_pending_);
741 EXPECT_EQ(gfx::Size(), host_->last_requested_size_); 755 EXPECT_EQ(gfx::Size(), host_->old_resize_params_->new_size);
742 756
743 // Reset the view so we can exit the test cleanly. 757 // Reset the view so we can exit the test cleanly.
744 host_->SetView(view_.get()); 758 host_->SetView(view_.get());
745 } 759 }
746 760
747 // Unable to include render_widget_host_view_mac.h and compile. 761 // Unable to include render_widget_host_view_mac.h and compile.
748 #if !defined(OS_MACOSX) 762 #if !defined(OS_MACOSX)
749 // Tests setting background transparency. 763 // Tests setting background transparency.
750 TEST_F(RenderWidgetHostTest, Background) { 764 TEST_F(RenderWidgetHostTest, Background) {
751 scoped_ptr<RenderWidgetHostViewBase> view; 765 scoped_ptr<RenderWidgetHostViewBase> view;
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 host_->WasHidden(); 1501 host_->WasHidden();
1488 1502
1489 ASSERT_TRUE(host_->is_hidden()); 1503 ASSERT_TRUE(host_->is_hidden());
1490 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); 1504 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1491 ASSERT_FALSE(host_->is_hidden()); 1505 ASSERT_FALSE(host_->is_hidden());
1492 1506
1493 // Make sure the input router is in a fresh state. 1507 // Make sure the input router is in a fresh state.
1494 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); 1508 ASSERT_FALSE(host_->input_router()->HasPendingEvents());
1495 } 1509 }
1496 1510
1511 TEST_F(RenderWidgetHostTest, ResizeParams) {
1512 gfx::Rect bounds(0, 0, 100, 100);
1513 gfx::Size physical_backing_size(40, 50);
1514 view_->set_bounds(bounds);
1515 view_->SetMockPhysicalBackingSize(physical_backing_size);
1516
1517 ViewMsg_Resize_Params resize_params;
1518 host_->GetResizeParams(&resize_params);
1519 EXPECT_EQ(bounds.size(), resize_params.new_size);
1520 EXPECT_EQ(physical_backing_size, resize_params.physical_backing_size);
1521 }
1522
1523 class RenderWidgetHostInitialSizeTest : public RenderWidgetHostTest {
1524 public:
1525 RenderWidgetHostInitialSizeTest()
1526 : RenderWidgetHostTest(), initial_size_(200, 100) {}
1527
1528 virtual void ConfigureView(TestView* view) override {
1529 view->set_bounds(gfx::Rect(initial_size_));
1530 }
1531
1532 protected:
1533 gfx::Size initial_size_;
1534 };
1535
1536 TEST_F(RenderWidgetHostInitialSizeTest, InitialSize) {
1537 // Having an initial size set means that the size information had been sent
1538 // with the reqiest to new up the RenderView and so subsequent WasResized
1539 // calls should not result in new IPC (unless the size has actually changed).
1540 host_->WasResized();
1541 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
1542 EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size);
1543 EXPECT_TRUE(host_->resize_ack_pending_);
1544 }
1545
1497 } // namespace content 1546 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698