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/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "content/public/test/mock_render_process_host.h" | 26 #include "content/public/test/mock_render_process_host.h" |
27 #include "content/public/test/test_browser_context.h" | 27 #include "content/public/test/test_browser_context.h" |
28 #include "ipc/ipc_test_sink.h" | 28 #include "ipc/ipc_test_sink.h" |
29 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "ui/aura/client/aura_constants.h" | 31 #include "ui/aura/client/aura_constants.h" |
32 #include "ui/aura/client/screen_position_client.h" | 32 #include "ui/aura/client/screen_position_client.h" |
33 #include "ui/aura/client/window_tree_client.h" | 33 #include "ui/aura/client/window_tree_client.h" |
34 #include "ui/aura/env.h" | 34 #include "ui/aura/env.h" |
35 #include "ui/aura/layout_manager.h" | 35 #include "ui/aura/layout_manager.h" |
36 #include "ui/aura/test/aura_test_helper.h" | |
37 #include "ui/aura/test/event_generator.h" | 36 #include "ui/aura/test/event_generator.h" |
38 #include "ui/aura/test/test_cursor_client.h" | 37 #include "ui/aura/test/test_cursor_client.h" |
39 #include "ui/aura/test/test_screen.h" | 38 #include "ui/aura/test/test_screen.h" |
40 #include "ui/aura/test/test_window_delegate.h" | 39 #include "ui/aura/test/test_window_delegate.h" |
41 #include "ui/aura/window.h" | 40 #include "ui/aura/window.h" |
42 #include "ui/aura/window_event_dispatcher.h" | 41 #include "ui/aura/window_event_dispatcher.h" |
43 #include "ui/aura/window_observer.h" | 42 #include "ui/aura/window_observer.h" |
44 #include "ui/base/ui_base_types.h" | 43 #include "ui/base/ui_base_types.h" |
45 #include "ui/compositor/compositor.h" | 44 #include "ui/compositor/compositor.h" |
46 #include "ui/compositor/test/draw_waiter_for_test.h" | 45 #include "ui/compositor/test/draw_waiter_for_test.h" |
47 #include "ui/compositor/test/in_process_context_factory.h" | 46 #include "ui/compositor/test/in_process_context_factory.h" |
48 #include "ui/events/event.h" | 47 #include "ui/events/event.h" |
49 #include "ui/events/event_utils.h" | 48 #include "ui/events/event_utils.h" |
| 49 #include "ui/wm/test/wm_test_helper.h" |
50 | 50 |
51 using testing::_; | 51 using testing::_; |
52 | 52 |
53 namespace content { | 53 namespace content { |
54 namespace { | 54 namespace { |
55 | 55 |
56 // Simple screen position client to test coordinate system conversion. | 56 // Simple screen position client to test coordinate system conversion. |
57 class TestScreenPositionClient | 57 class TestScreenPositionClient |
58 : public aura::client::ScreenPositionClient { | 58 : public aura::client::ScreenPositionClient { |
59 public: | 59 public: |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 }; | 198 }; |
199 | 199 |
200 class RenderWidgetHostViewAuraTest : public testing::Test { | 200 class RenderWidgetHostViewAuraTest : public testing::Test { |
201 public: | 201 public: |
202 RenderWidgetHostViewAuraTest() | 202 RenderWidgetHostViewAuraTest() |
203 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} | 203 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} |
204 | 204 |
205 void SetUpEnvironment() { | 205 void SetUpEnvironment() { |
206 ImageTransportFactory::InitializeForUnitTests( | 206 ImageTransportFactory::InitializeForUnitTests( |
207 scoped_ptr<ui::ContextFactory>(new ui::InProcessContextFactory)); | 207 scoped_ptr<ui::ContextFactory>(new ui::InProcessContextFactory)); |
208 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 208 wm_test_helper_.reset(new wm::WMTestHelper); |
209 aura_test_helper_->SetUp(); | 209 wm_test_helper_->SetUp(); |
210 | 210 |
211 browser_context_.reset(new TestBrowserContext); | 211 browser_context_.reset(new TestBrowserContext); |
212 process_host_ = new MockRenderProcessHost(browser_context_.get()); | 212 process_host_ = new MockRenderProcessHost(browser_context_.get()); |
213 | 213 |
214 sink_ = &process_host_->sink(); | 214 sink_ = &process_host_->sink(); |
215 | 215 |
216 parent_host_ = new RenderWidgetHostImpl( | 216 parent_host_ = new RenderWidgetHostImpl( |
217 &delegate_, process_host_, MSG_ROUTING_NONE, false); | 217 &delegate_, process_host_, MSG_ROUTING_NONE, false); |
218 parent_view_ = static_cast<RenderWidgetHostViewAura*>( | 218 parent_view_ = static_cast<RenderWidgetHostViewAura*>( |
219 RenderWidgetHostView::CreateViewForWidget(parent_host_)); | 219 RenderWidgetHostView::CreateViewForWidget(parent_host_)); |
220 parent_view_->InitAsChild(NULL); | 220 parent_view_->InitAsChild(NULL); |
221 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(), | 221 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(), |
222 aura_test_helper_->root_window(), | 222 wm_test_helper_->root_window(), |
223 gfx::Rect()); | 223 gfx::Rect()); |
224 | 224 |
225 widget_host_ = new RenderWidgetHostImpl( | 225 widget_host_ = new RenderWidgetHostImpl( |
226 &delegate_, process_host_, MSG_ROUTING_NONE, false); | 226 &delegate_, process_host_, MSG_ROUTING_NONE, false); |
227 widget_host_->Init(); | 227 widget_host_->Init(); |
228 widget_host_->OnMessageReceived( | 228 widget_host_->OnMessageReceived( |
229 ViewHostMsg_DidActivateAcceleratedCompositing(0, true)); | 229 ViewHostMsg_DidActivateAcceleratedCompositing(0, true)); |
230 view_ = new FakeRenderWidgetHostViewAura(widget_host_); | 230 view_ = new FakeRenderWidgetHostViewAura(widget_host_); |
231 } | 231 } |
232 | 232 |
233 void TearDownEnvironment() { | 233 void TearDownEnvironment() { |
234 sink_ = NULL; | 234 sink_ = NULL; |
235 process_host_ = NULL; | 235 process_host_ = NULL; |
236 if (view_) | 236 if (view_) |
237 view_->Destroy(); | 237 view_->Destroy(); |
238 delete widget_host_; | 238 delete widget_host_; |
239 | 239 |
240 parent_view_->Destroy(); | 240 parent_view_->Destroy(); |
241 delete parent_host_; | 241 delete parent_host_; |
242 | 242 |
243 browser_context_.reset(); | 243 browser_context_.reset(); |
244 aura_test_helper_->TearDown(); | 244 wm_test_helper_->TearDown(); |
245 | 245 |
246 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); | 246 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); |
247 message_loop_.RunUntilIdle(); | 247 message_loop_.RunUntilIdle(); |
248 ImageTransportFactory::Terminate(); | 248 ImageTransportFactory::Terminate(); |
249 } | 249 } |
250 | 250 |
251 virtual void SetUp() { SetUpEnvironment(); } | 251 virtual void SetUp() { SetUpEnvironment(); } |
252 | 252 |
253 virtual void TearDown() { TearDownEnvironment(); } | 253 virtual void TearDown() { TearDownEnvironment(); } |
254 | 254 |
255 protected: | 255 protected: |
256 base::MessageLoopForUI message_loop_; | 256 base::MessageLoopForUI message_loop_; |
257 BrowserThreadImpl browser_thread_for_ui_; | 257 BrowserThreadImpl browser_thread_for_ui_; |
258 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 258 scoped_ptr<wm::WMTestHelper> wm_test_helper_; |
259 scoped_ptr<BrowserContext> browser_context_; | 259 scoped_ptr<BrowserContext> browser_context_; |
260 MockRenderWidgetHostDelegate delegate_; | 260 MockRenderWidgetHostDelegate delegate_; |
261 MockRenderProcessHost* process_host_; | 261 MockRenderProcessHost* process_host_; |
262 | 262 |
263 // Tests should set these to NULL if they've already triggered their | 263 // Tests should set these to NULL if they've already triggered their |
264 // destruction. | 264 // destruction. |
265 RenderWidgetHostImpl* parent_host_; | 265 RenderWidgetHostImpl* parent_host_; |
266 RenderWidgetHostViewAura* parent_view_; | 266 RenderWidgetHostViewAura* parent_view_; |
267 | 267 |
268 // Tests should set these to NULL if they've already triggered their | 268 // Tests should set these to NULL if they've already triggered their |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 ViewMsg_Resize::Param params; | 674 ViewMsg_Resize::Param params; |
675 ViewMsg_Resize::Read(msg, ¶ms); | 675 ViewMsg_Resize::Read(msg, ¶ms); |
676 EXPECT_EQ("100x100", params.a.new_size.ToString()); // dip size | 676 EXPECT_EQ("100x100", params.a.new_size.ToString()); // dip size |
677 EXPECT_EQ("100x100", | 677 EXPECT_EQ("100x100", |
678 params.a.physical_backing_size.ToString()); // backing size | 678 params.a.physical_backing_size.ToString()); // backing size |
679 } | 679 } |
680 | 680 |
681 widget_host_->ResetSizeAndRepaintPendingFlags(); | 681 widget_host_->ResetSizeAndRepaintPendingFlags(); |
682 sink_->ClearMessages(); | 682 sink_->ClearMessages(); |
683 | 683 |
684 aura_test_helper_->test_screen()->SetDeviceScaleFactor(2.0f); | 684 wm_test_helper_->test_screen()->SetDeviceScaleFactor(2.0f); |
685 EXPECT_EQ("200x200", view_->GetPhysicalBackingSize().ToString()); | 685 EXPECT_EQ("200x200", view_->GetPhysicalBackingSize().ToString()); |
686 // Extra ScreenInfoChanged message for |parent_view_|. | 686 // Extra ScreenInfoChanged message for |parent_view_|. |
687 EXPECT_EQ(1u, sink_->message_count()); | 687 EXPECT_EQ(1u, sink_->message_count()); |
688 { | 688 { |
689 const IPC::Message* msg = sink_->GetMessageAt(0); | 689 const IPC::Message* msg = sink_->GetMessageAt(0); |
690 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); | 690 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); |
691 ViewMsg_Resize::Param params; | 691 ViewMsg_Resize::Param params; |
692 ViewMsg_Resize::Read(msg, ¶ms); | 692 ViewMsg_Resize::Read(msg, ¶ms); |
693 EXPECT_EQ(2.0f, params.a.screen_info.deviceScaleFactor); | 693 EXPECT_EQ(2.0f, params.a.screen_info.deviceScaleFactor); |
694 EXPECT_EQ("100x100", params.a.new_size.ToString()); // dip size | 694 EXPECT_EQ("100x100", params.a.new_size.ToString()); // dip size |
695 EXPECT_EQ("200x200", | 695 EXPECT_EQ("200x200", |
696 params.a.physical_backing_size.ToString()); // backing size | 696 params.a.physical_backing_size.ToString()); // backing size |
697 } | 697 } |
698 | 698 |
699 widget_host_->ResetSizeAndRepaintPendingFlags(); | 699 widget_host_->ResetSizeAndRepaintPendingFlags(); |
700 sink_->ClearMessages(); | 700 sink_->ClearMessages(); |
701 | 701 |
702 aura_test_helper_->test_screen()->SetDeviceScaleFactor(1.0f); | 702 wm_test_helper_->test_screen()->SetDeviceScaleFactor(1.0f); |
703 // Extra ScreenInfoChanged message for |parent_view_|. | 703 // Extra ScreenInfoChanged message for |parent_view_|. |
704 EXPECT_EQ(1u, sink_->message_count()); | 704 EXPECT_EQ(1u, sink_->message_count()); |
705 EXPECT_EQ("100x100", view_->GetPhysicalBackingSize().ToString()); | 705 EXPECT_EQ("100x100", view_->GetPhysicalBackingSize().ToString()); |
706 { | 706 { |
707 const IPC::Message* msg = sink_->GetMessageAt(0); | 707 const IPC::Message* msg = sink_->GetMessageAt(0); |
708 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); | 708 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); |
709 ViewMsg_Resize::Param params; | 709 ViewMsg_Resize::Param params; |
710 ViewMsg_Resize::Read(msg, ¶ms); | 710 ViewMsg_Resize::Read(msg, ¶ms); |
711 EXPECT_EQ(1.0f, params.a.screen_info.deviceScaleFactor); | 711 EXPECT_EQ(1.0f, params.a.screen_info.deviceScaleFactor); |
712 EXPECT_EQ("100x100", params.a.new_size.ToString()); // dip size | 712 EXPECT_EQ("100x100", params.a.new_size.ToString()); // dip size |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 pass->SetNew(cc::RenderPass::Id(1, 1), | 887 pass->SetNew(cc::RenderPass::Id(1, 1), |
888 gfx::Rect(size), | 888 gfx::Rect(size), |
889 gfx::RectF(damage), | 889 gfx::RectF(damage), |
890 gfx::Transform()); | 890 gfx::Transform()); |
891 frame->delegated_frame_data->render_pass_list.push_back(pass.Pass()); | 891 frame->delegated_frame_data->render_pass_list.push_back(pass.Pass()); |
892 return frame.Pass(); | 892 return frame.Pass(); |
893 } | 893 } |
894 | 894 |
895 // Resizing in fullscreen mode should send the up-to-date screen info. | 895 // Resizing in fullscreen mode should send the up-to-date screen info. |
896 TEST_F(RenderWidgetHostViewAuraTest, FullscreenResize) { | 896 TEST_F(RenderWidgetHostViewAuraTest, FullscreenResize) { |
897 aura::Window* root_window = aura_test_helper_->root_window(); | 897 aura::Window* root_window = wm_test_helper_->root_window(); |
898 root_window->SetLayoutManager(new FullscreenLayoutManager(root_window)); | 898 root_window->SetLayoutManager(new FullscreenLayoutManager(root_window)); |
899 view_->InitAsFullscreen(parent_view_); | 899 view_->InitAsFullscreen(parent_view_); |
900 view_->WasShown(); | 900 view_->WasShown(); |
901 widget_host_->ResetSizeAndRepaintPendingFlags(); | 901 widget_host_->ResetSizeAndRepaintPendingFlags(); |
902 sink_->ClearMessages(); | 902 sink_->ClearMessages(); |
903 | 903 |
904 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | 904 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
905 scoped_refptr<OwnedMailbox> owned_mailbox = new OwnedMailbox(gl_helper); | 905 scoped_refptr<OwnedMailbox> owned_mailbox = new OwnedMailbox(gl_helper); |
906 gl_helper->ResizeTexture(owned_mailbox->texture_id(), gfx::Size(1, 1)); | 906 gl_helper->ResizeTexture(owned_mailbox->texture_id(), gfx::Size(1, 1)); |
907 owned_mailbox->UpdateSyncPoint(gl_helper->InsertSyncPoint()); | 907 owned_mailbox->UpdateSyncPoint(gl_helper->InsertSyncPoint()); |
(...skipping 18 matching lines...) Expand all Loading... |
926 owned_mailbox.get())); | 926 owned_mailbox.get())); |
927 ui::DrawWaiterForTest::WaitForCommit( | 927 ui::DrawWaiterForTest::WaitForCommit( |
928 root_window->GetHost()->compositor()); | 928 root_window->GetHost()->compositor()); |
929 } | 929 } |
930 | 930 |
931 widget_host_->ResetSizeAndRepaintPendingFlags(); | 931 widget_host_->ResetSizeAndRepaintPendingFlags(); |
932 sink_->ClearMessages(); | 932 sink_->ClearMessages(); |
933 | 933 |
934 // Make sure the corrent screen size is set along in the resize | 934 // Make sure the corrent screen size is set along in the resize |
935 // request when the screen size has changed. | 935 // request when the screen size has changed. |
936 aura_test_helper_->test_screen()->SetUIScale(0.5); | 936 wm_test_helper_->test_screen()->SetUIScale(0.5); |
937 EXPECT_EQ(1u, sink_->message_count()); | 937 EXPECT_EQ(1u, sink_->message_count()); |
938 { | 938 { |
939 const IPC::Message* msg = sink_->GetMessageAt(0); | 939 const IPC::Message* msg = sink_->GetMessageAt(0); |
940 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); | 940 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); |
941 ViewMsg_Resize::Param params; | 941 ViewMsg_Resize::Param params; |
942 ViewMsg_Resize::Read(msg, ¶ms); | 942 ViewMsg_Resize::Read(msg, ¶ms); |
943 EXPECT_EQ("0,0 1600x1200", | 943 EXPECT_EQ("0,0 1600x1200", |
944 gfx::Rect(params.a.screen_info.availableRect).ToString()); | 944 gfx::Rect(params.a.screen_info.availableRect).ToString()); |
945 EXPECT_EQ("1600x1200", params.a.new_size.ToString()); | 945 EXPECT_EQ("1600x1200", params.a.new_size.ToString()); |
946 view_->OnSwapCompositorFrame(0, | 946 view_->OnSwapCompositorFrame(0, |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1452 | 1452 |
1453 // Because the copy request callback may be holding state within it, that | 1453 // Because the copy request callback may be holding state within it, that |
1454 // state must handle the RWHVA and ImageTransportFactory going away before the | 1454 // state must handle the RWHVA and ImageTransportFactory going away before the |
1455 // callback is called. This test passes if it does not crash as a result of | 1455 // callback is called. This test passes if it does not crash as a result of |
1456 // these things being destroyed. | 1456 // these things being destroyed. |
1457 EXPECT_EQ(2, callback_count_); | 1457 EXPECT_EQ(2, callback_count_); |
1458 EXPECT_FALSE(result_); | 1458 EXPECT_FALSE(result_); |
1459 } | 1459 } |
1460 | 1460 |
1461 } // namespace content | 1461 } // namespace content |
OLD | NEW |