OLD | NEW |
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 "content/browser/renderer_host/render_widget_host_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "cc/output/compositor_frame.h" | 11 #include "cc/output/compositor_frame.h" |
12 #include "cc/output/compositor_frame_metadata.h" | 12 #include "cc/output/compositor_frame_metadata.h" |
13 #include "cc/output/gl_frame_data.h" | 13 #include "cc/output/gl_frame_data.h" |
14 #include "content/browser/aura/resize_lock.h" | 14 #include "content/browser/aura/resize_lock.h" |
15 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
16 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 16 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
17 #include "content/browser/renderer_host/render_widget_host_impl.h" | 17 #include "content/browser/renderer_host/render_widget_host_impl.h" |
18 #include "content/common/gpu/gpu_messages.h" | 18 #include "content/common/gpu/gpu_messages.h" |
19 #include "content/common/input_messages.h" | 19 #include "content/common/input_messages.h" |
20 #include "content/common/view_messages.h" | 20 #include "content/common/view_messages.h" |
21 #include "content/public/browser/render_widget_host_view.h" | 21 #include "content/public/browser/render_widget_host_view.h" |
22 #include "content/public/test/mock_render_process_host.h" | 22 #include "content/public/test/mock_render_process_host.h" |
23 #include "content/public/test/test_browser_context.h" | 23 #include "content/public/test/test_browser_context.h" |
24 #include "ipc/ipc_test_sink.h" | 24 #include "ipc/ipc_test_sink.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "ui/aura/client/aura_constants.h" | 27 #include "ui/aura/client/aura_constants.h" |
| 28 #include "ui/aura/client/window_tree_client.h" |
28 #include "ui/aura/env.h" | 29 #include "ui/aura/env.h" |
29 #include "ui/aura/layout_manager.h" | 30 #include "ui/aura/layout_manager.h" |
30 #include "ui/aura/root_window.h" | 31 #include "ui/aura/root_window.h" |
31 #include "ui/aura/test/aura_test_helper.h" | 32 #include "ui/aura/test/aura_test_helper.h" |
32 #include "ui/aura/test/test_cursor_client.h" | 33 #include "ui/aura/test/test_cursor_client.h" |
33 #include "ui/aura/test/test_screen.h" | 34 #include "ui/aura/test/test_screen.h" |
34 #include "ui/aura/test/test_window_delegate.h" | 35 #include "ui/aura/test/test_window_delegate.h" |
35 #include "ui/aura/window.h" | 36 #include "ui/aura/window.h" |
36 #include "ui/aura/window_observer.h" | 37 #include "ui/aura/window_observer.h" |
37 #include "ui/base/ui_base_types.h" | 38 #include "ui/base/ui_base_types.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 MockRenderProcessHost* process_host = | 130 MockRenderProcessHost* process_host = |
130 new MockRenderProcessHost(browser_context_.get()); | 131 new MockRenderProcessHost(browser_context_.get()); |
131 | 132 |
132 sink_ = &process_host->sink(); | 133 sink_ = &process_host->sink(); |
133 | 134 |
134 parent_host_ = new RenderWidgetHostImpl( | 135 parent_host_ = new RenderWidgetHostImpl( |
135 &delegate_, process_host, MSG_ROUTING_NONE, false); | 136 &delegate_, process_host, MSG_ROUTING_NONE, false); |
136 parent_view_ = static_cast<RenderWidgetHostViewAura*>( | 137 parent_view_ = static_cast<RenderWidgetHostViewAura*>( |
137 RenderWidgetHostView::CreateViewForWidget(parent_host_)); | 138 RenderWidgetHostView::CreateViewForWidget(parent_host_)); |
138 parent_view_->InitAsChild(NULL); | 139 parent_view_->InitAsChild(NULL); |
139 parent_view_->GetNativeView()->SetDefaultParentByRootWindow( | 140 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(), |
140 aura_test_helper_->root_window(), gfx::Rect()); | 141 aura_test_helper_->root_window(), |
| 142 gfx::Rect()); |
141 | 143 |
142 widget_host_ = new RenderWidgetHostImpl( | 144 widget_host_ = new RenderWidgetHostImpl( |
143 &delegate_, process_host, MSG_ROUTING_NONE, false); | 145 &delegate_, process_host, MSG_ROUTING_NONE, false); |
144 widget_host_->Init(); | 146 widget_host_->Init(); |
145 widget_host_->OnMessageReceived( | 147 widget_host_->OnMessageReceived( |
146 ViewHostMsg_DidActivateAcceleratedCompositing(0, true)); | 148 ViewHostMsg_DidActivateAcceleratedCompositing(0, true)); |
147 view_ = new FakeRenderWidgetHostViewAura(widget_host_); | 149 view_ = new FakeRenderWidgetHostViewAura(widget_host_); |
148 } | 150 } |
149 | 151 |
150 virtual void TearDown() { | 152 virtual void TearDown() { |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 view_->touch_event_.touches[0].state); | 460 view_->touch_event_.touches[0].state); |
459 | 461 |
460 view_->OnTouchEvent(&release); | 462 view_->OnTouchEvent(&release); |
461 EXPECT_TRUE(release.stopped_propagation()); | 463 EXPECT_TRUE(release.stopped_propagation()); |
462 EXPECT_EQ(WebKit::WebInputEvent::TouchEnd, view_->touch_event_.type); | 464 EXPECT_EQ(WebKit::WebInputEvent::TouchEnd, view_->touch_event_.type); |
463 EXPECT_EQ(0U, view_->touch_event_.touchesLength); | 465 EXPECT_EQ(0U, view_->touch_event_.touchesLength); |
464 } | 466 } |
465 | 467 |
466 TEST_F(RenderWidgetHostViewAuraTest, PhysicalBackingSizeWithScale) { | 468 TEST_F(RenderWidgetHostViewAuraTest, PhysicalBackingSizeWithScale) { |
467 view_->InitAsChild(NULL); | 469 view_->InitAsChild(NULL); |
468 view_->GetNativeView()->SetDefaultParentByRootWindow( | 470 aura::client::ParentWindowWithContext( |
469 parent_view_->GetNativeView()->GetRootWindow(), gfx::Rect()); | 471 view_->GetNativeView(), |
| 472 parent_view_->GetNativeView()->GetRootWindow(), |
| 473 gfx::Rect()); |
470 sink_->ClearMessages(); | 474 sink_->ClearMessages(); |
471 view_->SetSize(gfx::Size(100, 100)); | 475 view_->SetSize(gfx::Size(100, 100)); |
472 EXPECT_EQ("100x100", view_->GetPhysicalBackingSize().ToString()); | 476 EXPECT_EQ("100x100", view_->GetPhysicalBackingSize().ToString()); |
473 EXPECT_EQ(1u, sink_->message_count()); | 477 EXPECT_EQ(1u, sink_->message_count()); |
474 EXPECT_EQ(ViewMsg_Resize::ID, sink_->GetMessageAt(0)->type()); | 478 EXPECT_EQ(ViewMsg_Resize::ID, sink_->GetMessageAt(0)->type()); |
475 { | 479 { |
476 const IPC::Message* msg = sink_->GetMessageAt(0); | 480 const IPC::Message* msg = sink_->GetMessageAt(0); |
477 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); | 481 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); |
478 ViewMsg_Resize::Param params; | 482 ViewMsg_Resize::Param params; |
479 ViewMsg_Resize::Read(msg, ¶ms); | 483 ViewMsg_Resize::Read(msg, ¶ms); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 EXPECT_EQ("100x100", params.a.new_size.ToString()); // dip size | 520 EXPECT_EQ("100x100", params.a.new_size.ToString()); // dip size |
517 EXPECT_EQ("100x100", | 521 EXPECT_EQ("100x100", |
518 params.a.physical_backing_size.ToString()); // backing size | 522 params.a.physical_backing_size.ToString()); // backing size |
519 } | 523 } |
520 } | 524 } |
521 | 525 |
522 // Checks that InputMsg_CursorVisibilityChange IPC messages are dispatched | 526 // Checks that InputMsg_CursorVisibilityChange IPC messages are dispatched |
523 // to the renderer at the correct times. | 527 // to the renderer at the correct times. |
524 TEST_F(RenderWidgetHostViewAuraTest, CursorVisibilityChange) { | 528 TEST_F(RenderWidgetHostViewAuraTest, CursorVisibilityChange) { |
525 view_->InitAsChild(NULL); | 529 view_->InitAsChild(NULL); |
526 view_->GetNativeView()->SetDefaultParentByRootWindow( | 530 aura::client::ParentWindowWithContext( |
527 parent_view_->GetNativeView()->GetRootWindow(), gfx::Rect()); | 531 view_->GetNativeView(), |
| 532 parent_view_->GetNativeView()->GetRootWindow(), |
| 533 gfx::Rect()); |
528 view_->SetSize(gfx::Size(100, 100)); | 534 view_->SetSize(gfx::Size(100, 100)); |
529 | 535 |
530 aura::test::TestCursorClient cursor_client( | 536 aura::test::TestCursorClient cursor_client( |
531 parent_view_->GetNativeView()->GetRootWindow()); | 537 parent_view_->GetNativeView()->GetRootWindow()); |
532 | 538 |
533 cursor_client.AddObserver(view_); | 539 cursor_client.AddObserver(view_); |
534 | 540 |
535 // Expect a message the first time the cursor is shown. | 541 // Expect a message the first time the cursor is shown. |
536 view_->WasShown(); | 542 view_->WasShown(); |
537 sink_->ClearMessages(); | 543 sink_->ClearMessages(); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 ui::DrawWaiterForTest::WaitForCommit(root_window->compositor()); | 698 ui::DrawWaiterForTest::WaitForCommit(root_window->compositor()); |
693 } | 699 } |
694 } | 700 } |
695 | 701 |
696 // Swapping a frame should notify the window. | 702 // Swapping a frame should notify the window. |
697 TEST_F(RenderWidgetHostViewAuraTest, SwapNotifiesWindow) { | 703 TEST_F(RenderWidgetHostViewAuraTest, SwapNotifiesWindow) { |
698 gfx::Size view_size(100, 100); | 704 gfx::Size view_size(100, 100); |
699 gfx::Rect view_rect(view_size); | 705 gfx::Rect view_rect(view_size); |
700 | 706 |
701 view_->InitAsChild(NULL); | 707 view_->InitAsChild(NULL); |
702 view_->GetNativeView()->SetDefaultParentByRootWindow( | 708 aura::client::ParentWindowWithContext( |
703 parent_view_->GetNativeView()->GetRootWindow(), gfx::Rect()); | 709 view_->GetNativeView(), |
| 710 parent_view_->GetNativeView()->GetRootWindow(), |
| 711 gfx::Rect()); |
704 view_->SetSize(view_size); | 712 view_->SetSize(view_size); |
705 view_->WasShown(); | 713 view_->WasShown(); |
706 | 714 |
707 MockWindowObserver observer; | 715 MockWindowObserver observer; |
708 view_->window_->AddObserver(&observer); | 716 view_->window_->AddObserver(&observer); |
709 | 717 |
710 // Swap a frame through the GPU path. | 718 // Swap a frame through the GPU path. |
711 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 719 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
712 params.surface_id = widget_host_->surface_id(); | 720 params.surface_id = widget_host_->surface_id(); |
713 params.route_id = widget_host_->GetRoutingID(); | 721 params.route_id = widget_host_->GetRoutingID(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 | 788 |
781 view_->window_->RemoveObserver(&observer); | 789 view_->window_->RemoveObserver(&observer); |
782 } | 790 } |
783 | 791 |
784 // Skipped frames should not drop their damage. | 792 // Skipped frames should not drop their damage. |
785 TEST_F(RenderWidgetHostViewAuraTest, SkippedDelegatedFrames) { | 793 TEST_F(RenderWidgetHostViewAuraTest, SkippedDelegatedFrames) { |
786 gfx::Rect view_rect(100, 100); | 794 gfx::Rect view_rect(100, 100); |
787 gfx::Size frame_size = view_rect.size(); | 795 gfx::Size frame_size = view_rect.size(); |
788 | 796 |
789 view_->InitAsChild(NULL); | 797 view_->InitAsChild(NULL); |
790 view_->GetNativeView()->SetDefaultParentByRootWindow( | 798 aura::client::ParentWindowWithContext( |
791 parent_view_->GetNativeView()->GetRootWindow(), gfx::Rect()); | 799 view_->GetNativeView(), |
| 800 parent_view_->GetNativeView()->GetRootWindow(), |
| 801 gfx::Rect()); |
792 view_->SetSize(view_rect.size()); | 802 view_->SetSize(view_rect.size()); |
793 | 803 |
794 MockWindowObserver observer; | 804 MockWindowObserver observer; |
795 view_->window_->AddObserver(&observer); | 805 view_->window_->AddObserver(&observer); |
796 | 806 |
797 // A full frame of damage. | 807 // A full frame of damage. |
798 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); | 808 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); |
799 view_->OnSwapCompositorFrame( | 809 view_->OnSwapCompositorFrame( |
800 0, MakeDelegatedFrame(1.f, frame_size, view_rect)); | 810 0, MakeDelegatedFrame(1.f, frame_size, view_rect)); |
801 testing::Mock::VerifyAndClearExpectations(&observer); | 811 testing::Mock::VerifyAndClearExpectations(&observer); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 | 861 |
852 | 862 |
853 view_->window_->RemoveObserver(&observer); | 863 view_->window_->RemoveObserver(&observer); |
854 } | 864 } |
855 | 865 |
856 TEST_F(RenderWidgetHostViewAuraTest, OutputSurfaceIdChange) { | 866 TEST_F(RenderWidgetHostViewAuraTest, OutputSurfaceIdChange) { |
857 gfx::Rect view_rect(100, 100); | 867 gfx::Rect view_rect(100, 100); |
858 gfx::Size frame_size = view_rect.size(); | 868 gfx::Size frame_size = view_rect.size(); |
859 | 869 |
860 view_->InitAsChild(NULL); | 870 view_->InitAsChild(NULL); |
861 view_->GetNativeView()->SetDefaultParentByRootWindow( | 871 aura::client::ParentWindowWithContext( |
862 parent_view_->GetNativeView()->GetRootWindow(), gfx::Rect()); | 872 view_->GetNativeView(), |
| 873 parent_view_->GetNativeView()->GetRootWindow(), |
| 874 gfx::Rect()); |
863 view_->SetSize(view_rect.size()); | 875 view_->SetSize(view_rect.size()); |
864 | 876 |
865 MockWindowObserver observer; | 877 MockWindowObserver observer; |
866 view_->window_->AddObserver(&observer); | 878 view_->window_->AddObserver(&observer); |
867 | 879 |
868 // Swap a frame. | 880 // Swap a frame. |
869 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); | 881 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); |
870 view_->OnSwapCompositorFrame( | 882 view_->OnSwapCompositorFrame( |
871 0, MakeDelegatedFrame(1.f, frame_size, view_rect)); | 883 0, MakeDelegatedFrame(1.f, frame_size, view_rect)); |
872 testing::Mock::VerifyAndClearExpectations(&observer); | 884 testing::Mock::VerifyAndClearExpectations(&observer); |
(...skipping 16 matching lines...) Expand all Loading... |
889 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); | 901 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); |
890 view_->OnSwapCompositorFrame( | 902 view_->OnSwapCompositorFrame( |
891 3, MakeDelegatedFrame(1.f, frame_size, view_rect)); | 903 3, MakeDelegatedFrame(1.f, frame_size, view_rect)); |
892 testing::Mock::VerifyAndClearExpectations(&observer); | 904 testing::Mock::VerifyAndClearExpectations(&observer); |
893 view_->RunOnCompositingDidCommit(); | 905 view_->RunOnCompositingDidCommit(); |
894 | 906 |
895 view_->window_->RemoveObserver(&observer); | 907 view_->window_->RemoveObserver(&observer); |
896 } | 908 } |
897 | 909 |
898 } // namespace content | 910 } // namespace content |
OLD | NEW |