| 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_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #include <Cocoa/Cocoa.h> | 7 #include <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
| 10 #include "base/mac/scoped_nsautorelease_pool.h" | 10 #include "base/mac/scoped_nsautorelease_pool.h" |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 EXPECT_CALL(*rwh, Blur()); | 716 EXPECT_CALL(*rwh, Blur()); |
| 717 [window makeFirstResponder:nil]; | 717 [window makeFirstResponder:nil]; |
| 718 testing::Mock::VerifyAndClearExpectations(rwh); | 718 testing::Mock::VerifyAndClearExpectations(rwh); |
| 719 | 719 |
| 720 // |SetActive()| shoud not focus if view is not first responder. | 720 // |SetActive()| shoud not focus if view is not first responder. |
| 721 EXPECT_CALL(*rwh, Focus()).Times(0); | 721 EXPECT_CALL(*rwh, Focus()).Times(0); |
| 722 view->SetActive(true); | 722 view->SetActive(true); |
| 723 testing::Mock::VerifyAndClearExpectations(rwh); | 723 testing::Mock::VerifyAndClearExpectations(rwh); |
| 724 | 724 |
| 725 // Clean up. | 725 // Clean up. |
| 726 rwh->Shutdown(); | 726 rwh->ShutdownAndDestroyWidget(true); |
| 727 } | 727 } |
| 728 | 728 |
| 729 TEST_F(RenderWidgetHostViewMacTest, ScrollWheelEndEventDelivery) { | 729 TEST_F(RenderWidgetHostViewMacTest, ScrollWheelEndEventDelivery) { |
| 730 // This tests Lion+ functionality, so don't run the test pre-Lion. | 730 // This tests Lion+ functionality, so don't run the test pre-Lion. |
| 731 if (!base::mac::IsOSLionOrLater()) | 731 if (!base::mac::IsOSLionOrLater()) |
| 732 return; | 732 return; |
| 733 | 733 |
| 734 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than | 734 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than |
| 735 // the MockRenderProcessHost that is set up by the test harness which mocks | 735 // the MockRenderProcessHost that is set up by the test harness which mocks |
| 736 // out |OnMessageReceived()|. | 736 // out |OnMessageReceived()|. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 757 host->OnMessageReceived(*response); | 757 host->OnMessageReceived(*response); |
| 758 | 758 |
| 759 // Post the NSEventPhaseEnded wheel event to NSApp and check whether the | 759 // Post the NSEventPhaseEnded wheel event to NSApp and check whether the |
| 760 // render view receives it. | 760 // render view receives it. |
| 761 NSEvent* event2 = MockScrollWheelEventWithPhase(@selector(phaseEnded), 0); | 761 NSEvent* event2 = MockScrollWheelEventWithPhase(@selector(phaseEnded), 0); |
| 762 [NSApp postEvent:event2 atStart:NO]; | 762 [NSApp postEvent:event2 atStart:NO]; |
| 763 base::MessageLoop::current()->RunUntilIdle(); | 763 base::MessageLoop::current()->RunUntilIdle(); |
| 764 ASSERT_EQ(2U, process_host->sink().message_count()); | 764 ASSERT_EQ(2U, process_host->sink().message_count()); |
| 765 | 765 |
| 766 // Clean up. | 766 // Clean up. |
| 767 host->Shutdown(); | 767 host->ShutdownAndDestroyWidget(true); |
| 768 } | 768 } |
| 769 | 769 |
| 770 TEST_F(RenderWidgetHostViewMacTest, IgnoreEmptyUnhandledWheelEvent) { | 770 TEST_F(RenderWidgetHostViewMacTest, IgnoreEmptyUnhandledWheelEvent) { |
| 771 // This tests Lion+ functionality, so don't run the test pre-Lion. | 771 // This tests Lion+ functionality, so don't run the test pre-Lion. |
| 772 if (!base::mac::IsOSLionOrLater()) | 772 if (!base::mac::IsOSLionOrLater()) |
| 773 return; | 773 return; |
| 774 | 774 |
| 775 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than | 775 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than |
| 776 // the MockRenderProcessHost that is set up by the test harness which mocks | 776 // the MockRenderProcessHost that is set up by the test harness which mocks |
| 777 // out |OnMessageReceived()|. | 777 // out |OnMessageReceived()|. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 | 814 |
| 815 // Indicate that the wheel event was also unhandled. | 815 // Indicate that the wheel event was also unhandled. |
| 816 scoped_ptr<IPC::Message> response2( | 816 scoped_ptr<IPC::Message> response2( |
| 817 new InputHostMsg_HandleInputEvent_ACK(0, unhandled_ack)); | 817 new InputHostMsg_HandleInputEvent_ACK(0, unhandled_ack)); |
| 818 host->OnMessageReceived(*response2); | 818 host->OnMessageReceived(*response2); |
| 819 | 819 |
| 820 // Check that the view delegate ignored the empty unhandled wheel event. | 820 // Check that the view delegate ignored the empty unhandled wheel event. |
| 821 ASSERT_EQ(NO, view_delegate.get().unhandledWheelEventReceived); | 821 ASSERT_EQ(NO, view_delegate.get().unhandledWheelEventReceived); |
| 822 | 822 |
| 823 // Clean up. | 823 // Clean up. |
| 824 host->Shutdown(); | 824 host->ShutdownAndDestroyWidget(true); |
| 825 } | 825 } |
| 826 | 826 |
| 827 // Tests that when view initiated shutdown happens (i.e. RWHView is deleted | 827 // Tests that when view initiated shutdown happens (i.e. RWHView is deleted |
| 828 // before RWH), we clean up properly and don't leak the RWHVGuest. | 828 // before RWH), we clean up properly and don't leak the RWHVGuest. |
| 829 TEST_F(RenderWidgetHostViewMacTest, GuestViewDoesNotLeak) { | 829 TEST_F(RenderWidgetHostViewMacTest, GuestViewDoesNotLeak) { |
| 830 MockRenderWidgetHostDelegate delegate; | 830 MockRenderWidgetHostDelegate delegate; |
| 831 TestBrowserContext browser_context; | 831 TestBrowserContext browser_context; |
| 832 MockRenderProcessHost* process_host = | 832 MockRenderProcessHost* process_host = |
| 833 new MockRenderProcessHost(&browser_context); | 833 new MockRenderProcessHost(&browser_context); |
| 834 int32 routing_id = process_host->GetNextRoutingID(); | 834 int32 routing_id = process_host->GetNextRoutingID(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 848 rwh, NULL, view->GetWeakPtr()))->GetWeakPtr(); | 848 rwh, NULL, view->GetWeakPtr()))->GetWeakPtr(); |
| 849 | 849 |
| 850 // Remove the cocoa_view() so |view| also goes away before |rwh|. | 850 // Remove the cocoa_view() so |view| also goes away before |rwh|. |
| 851 { | 851 { |
| 852 base::scoped_nsobject<RenderWidgetHostViewCocoa> rwhv_cocoa; | 852 base::scoped_nsobject<RenderWidgetHostViewCocoa> rwhv_cocoa; |
| 853 rwhv_cocoa.reset([view->cocoa_view() retain]); | 853 rwhv_cocoa.reset([view->cocoa_view() retain]); |
| 854 } | 854 } |
| 855 RecycleAndWait(); | 855 RecycleAndWait(); |
| 856 | 856 |
| 857 // Clean up. | 857 // Clean up. |
| 858 rwh->Shutdown(); | 858 rwh->ShutdownAndDestroyWidget(true); |
| 859 | 859 |
| 860 // Let |guest_rwhv_weak| have a chance to delete itself. | 860 // Let |guest_rwhv_weak| have a chance to delete itself. |
| 861 base::RunLoop run_loop; | 861 base::RunLoop run_loop; |
| 862 content::BrowserThread::PostTask( | 862 content::BrowserThread::PostTask( |
| 863 content::BrowserThread::UI, FROM_HERE, run_loop.QuitClosure()); | 863 content::BrowserThread::UI, FROM_HERE, run_loop.QuitClosure()); |
| 864 run_loop.Run(); | 864 run_loop.Run(); |
| 865 | 865 |
| 866 ASSERT_FALSE(guest_rwhv_weak.get()); | 866 ASSERT_FALSE(guest_rwhv_weak.get()); |
| 867 } | 867 } |
| 868 | 868 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 898 process_host->sink().ClearMessages(); | 898 process_host->sink().ClearMessages(); |
| 899 view->SetBackgroundColor(SK_ColorWHITE); | 899 view->SetBackgroundColor(SK_ColorWHITE); |
| 900 EXPECT_TRUE(view->GetBackgroundOpaque()); | 900 EXPECT_TRUE(view->GetBackgroundOpaque()); |
| 901 EXPECT_TRUE([view->cocoa_view() isOpaque]); | 901 EXPECT_TRUE([view->cocoa_view() isOpaque]); |
| 902 set_background = process_host->sink().GetUniqueMessageMatching( | 902 set_background = process_host->sink().GetUniqueMessageMatching( |
| 903 ViewMsg_SetBackgroundOpaque::ID); | 903 ViewMsg_SetBackgroundOpaque::ID); |
| 904 ASSERT_TRUE(set_background); | 904 ASSERT_TRUE(set_background); |
| 905 ViewMsg_SetBackgroundOpaque::Read(set_background, &sent_background); | 905 ViewMsg_SetBackgroundOpaque::Read(set_background, &sent_background); |
| 906 EXPECT_TRUE(base::get<0>(sent_background)); | 906 EXPECT_TRUE(base::get<0>(sent_background)); |
| 907 | 907 |
| 908 host->Shutdown(); | 908 host->ShutdownAndDestroyWidget(true); |
| 909 } | 909 } |
| 910 | 910 |
| 911 class RenderWidgetHostViewMacPinchTest : public RenderWidgetHostViewMacTest { | 911 class RenderWidgetHostViewMacPinchTest : public RenderWidgetHostViewMacTest { |
| 912 public: | 912 public: |
| 913 RenderWidgetHostViewMacPinchTest() : process_host_(NULL) {} | 913 RenderWidgetHostViewMacPinchTest() : process_host_(NULL) {} |
| 914 | 914 |
| 915 bool ZoomDisabledForPinchUpdateMessage() { | 915 bool ZoomDisabledForPinchUpdateMessage() { |
| 916 const IPC::Message* message = NULL; | 916 const IPC::Message* message = NULL; |
| 917 // The first message may be a PinchBegin. Go for the second message if | 917 // The first message may be a PinchBegin. Go for the second message if |
| 918 // there are two. | 918 // there are two. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 EXPECT_TRUE(ZoomDisabledForPinchUpdateMessage()); | 1050 EXPECT_TRUE(ZoomDisabledForPinchUpdateMessage()); |
| 1051 host->OnMessageReceived(*response); | 1051 host->OnMessageReceived(*response); |
| 1052 process_host_->sink().ClearMessages(); | 1052 process_host_->sink().ClearMessages(); |
| 1053 | 1053 |
| 1054 [view->cocoa_view() endGestureWithEvent:pinchEndEvent]; | 1054 [view->cocoa_view() endGestureWithEvent:pinchEndEvent]; |
| 1055 EXPECT_EQ(1U, process_host_->sink().message_count()); | 1055 EXPECT_EQ(1U, process_host_->sink().message_count()); |
| 1056 process_host_->sink().ClearMessages(); | 1056 process_host_->sink().ClearMessages(); |
| 1057 } | 1057 } |
| 1058 | 1058 |
| 1059 // Clean up. | 1059 // Clean up. |
| 1060 host->Shutdown(); | 1060 host->ShutdownAndDestroyWidget(true); |
| 1061 } | 1061 } |
| 1062 | 1062 |
| 1063 | 1063 |
| 1064 } // namespace content | 1064 } // namespace content |
| OLD | NEW |