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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac_unittest.mm

Issue 1534933002: Don't process messages sent to dead routing ids. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More unittest fixes. Created 4 years, 10 months 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 "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 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 void Copy() override {} 143 void Copy() override {}
144 void Paste() override {} 144 void Paste() override {}
145 void SelectAll() override {} 145 void SelectAll() override {}
146 }; 146 };
147 147
148 class MockRenderWidgetHostImpl : public RenderWidgetHostImpl { 148 class MockRenderWidgetHostImpl : public RenderWidgetHostImpl {
149 public: 149 public:
150 MockRenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, 150 MockRenderWidgetHostImpl(RenderWidgetHostDelegate* delegate,
151 RenderProcessHost* process, 151 RenderProcessHost* process,
152 int32_t routing_id) 152 int32_t routing_id)
153 : RenderWidgetHostImpl(delegate, process, routing_id, false) {} 153 : RenderWidgetHostImpl(delegate, process, routing_id, false) {
154 set_renderer_initialized(true);
155 }
154 156
155 MOCK_METHOD0(Focus, void()); 157 MOCK_METHOD0(Focus, void());
156 MOCK_METHOD0(Blur, void()); 158 MOCK_METHOD0(Blur, void());
157 }; 159 };
158 160
159 // Generates the |length| of composition rectangle vector and save them to 161 // Generates the |length| of composition rectangle vector and save them to
160 // |output|. It starts from |origin| and each rectangle contains |unit_size|. 162 // |output|. It starts from |origin| and each rectangle contains |unit_size|.
161 void GenerateCompositionRectArray(const gfx::Point& origin, 163 void GenerateCompositionRectArray(const gfx::Point& origin,
162 const gfx::Size& unit_size, 164 const gfx::Size& unit_size,
163 size_t length, 165 size_t length,
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 EXPECT_EQ(gfx::Range(), gfx::Range(actual_range)); 749 EXPECT_EQ(gfx::Range(), gfx::Range(actual_range));
748 } 750 }
749 751
750 // Verify that |SetActive()| calls |RenderWidgetHostImpl::Blur()| and 752 // Verify that |SetActive()| calls |RenderWidgetHostImpl::Blur()| and
751 // |RenderWidgetHostImp::Focus()|. 753 // |RenderWidgetHostImp::Focus()|.
752 TEST_F(RenderWidgetHostViewMacTest, BlurAndFocusOnSetActive) { 754 TEST_F(RenderWidgetHostViewMacTest, BlurAndFocusOnSetActive) {
753 MockRenderWidgetHostDelegate delegate; 755 MockRenderWidgetHostDelegate delegate;
754 TestBrowserContext browser_context; 756 TestBrowserContext browser_context;
755 MockRenderProcessHost* process_host = 757 MockRenderProcessHost* process_host =
756 new MockRenderProcessHost(&browser_context); 758 new MockRenderProcessHost(&browser_context);
759 process_host->Init();
757 760
758 // Owned by its |cocoa_view()|. 761 // Owned by its |cocoa_view()|.
759 int32_t routing_id = process_host->GetNextRoutingID(); 762 int32_t routing_id = process_host->GetNextRoutingID();
760 MockRenderWidgetHostImpl* rwh = 763 MockRenderWidgetHostImpl* rwh =
761 new MockRenderWidgetHostImpl(&delegate, process_host, routing_id); 764 new MockRenderWidgetHostImpl(&delegate, process_host, routing_id);
762 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(rwh, false); 765 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(rwh, false);
763 766
764 base::scoped_nsobject<CocoaTestHelperWindow> window( 767 base::scoped_nsobject<CocoaTestHelperWindow> window(
765 [[CocoaTestHelperWindow alloc] init]); 768 [[CocoaTestHelperWindow alloc] init]);
766 [[window contentView] addSubview:view->cocoa_view()]; 769 [[window contentView] addSubview:view->cocoa_view()];
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 // out |OnMessageReceived()|. 804 // out |OnMessageReceived()|.
802 TestBrowserContext browser_context; 805 TestBrowserContext browser_context;
803 MockRenderProcessHost* process_host = 806 MockRenderProcessHost* process_host =
804 new MockRenderProcessHost(&browser_context); 807 new MockRenderProcessHost(&browser_context);
805 process_host->Init(); 808 process_host->Init();
806 MockRenderWidgetHostDelegate delegate; 809 MockRenderWidgetHostDelegate delegate;
807 int32_t routing_id = process_host->GetNextRoutingID(); 810 int32_t routing_id = process_host->GetNextRoutingID();
808 MockRenderWidgetHostImpl* host = 811 MockRenderWidgetHostImpl* host =
809 new MockRenderWidgetHostImpl(&delegate, process_host, routing_id); 812 new MockRenderWidgetHostImpl(&delegate, process_host, routing_id);
810 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false); 813 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false);
814 process_host->sink().ClearMessages();
811 815
812 // Send an initial wheel event with NSEventPhaseBegan to the view. 816 // Send an initial wheel event with NSEventPhaseBegan to the view.
813 NSEvent* event1 = MockScrollWheelEventWithPhase(@selector(phaseBegan), 0); 817 NSEvent* event1 = MockScrollWheelEventWithPhase(@selector(phaseBegan), 0);
814 [view->cocoa_view() scrollWheel:event1]; 818 [view->cocoa_view() scrollWheel:event1];
815 ASSERT_EQ(1U, process_host->sink().message_count()); 819 ASSERT_EQ(1U, process_host->sink().message_count());
816 820
817 // Send an ACK for the first wheel event, so that the queue will be flushed. 821 // Send an ACK for the first wheel event, so that the queue will be flushed.
818 InputEventAck ack(blink::WebInputEvent::MouseWheel, 822 InputEventAck ack(blink::WebInputEvent::MouseWheel,
819 INPUT_EVENT_ACK_STATE_CONSUMED); 823 INPUT_EVENT_ACK_STATE_CONSUMED);
820 scoped_ptr<IPC::Message> response( 824 scoped_ptr<IPC::Message> response(
(...skipping 21 matching lines...) Expand all
842 // out |OnMessageReceived()|. 846 // out |OnMessageReceived()|.
843 TestBrowserContext browser_context; 847 TestBrowserContext browser_context;
844 MockRenderProcessHost* process_host = 848 MockRenderProcessHost* process_host =
845 new MockRenderProcessHost(&browser_context); 849 new MockRenderProcessHost(&browser_context);
846 process_host->Init(); 850 process_host->Init();
847 MockRenderWidgetHostDelegate delegate; 851 MockRenderWidgetHostDelegate delegate;
848 int32_t routing_id = process_host->GetNextRoutingID(); 852 int32_t routing_id = process_host->GetNextRoutingID();
849 MockRenderWidgetHostImpl* host = 853 MockRenderWidgetHostImpl* host =
850 new MockRenderWidgetHostImpl(&delegate, process_host, routing_id); 854 new MockRenderWidgetHostImpl(&delegate, process_host, routing_id);
851 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false); 855 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false);
856 process_host->sink().ClearMessages();
852 857
853 // Add a delegate to the view. 858 // Add a delegate to the view.
854 base::scoped_nsobject<MockRenderWidgetHostViewMacDelegate> view_delegate( 859 base::scoped_nsobject<MockRenderWidgetHostViewMacDelegate> view_delegate(
855 [[MockRenderWidgetHostViewMacDelegate alloc] init]); 860 [[MockRenderWidgetHostViewMacDelegate alloc] init]);
856 view->SetDelegate(view_delegate.get()); 861 view->SetDelegate(view_delegate.get());
857 862
858 // Send an initial wheel event for scrolling by 3 lines. 863 // Send an initial wheel event for scrolling by 3 lines.
859 NSEvent* event1 = MockScrollWheelEventWithPhase(@selector(phaseBegan), 3); 864 NSEvent* event1 = MockScrollWheelEventWithPhase(@selector(phaseBegan), 3);
860 [view->cocoa_view() scrollWheel:event1]; 865 [view->cocoa_view() scrollWheel:event1];
861 ASSERT_EQ(1U, process_host->sink().message_count()); 866 ASSERT_EQ(1U, process_host->sink().message_count());
(...skipping 27 matching lines...) Expand all
889 host->ShutdownAndDestroyWidget(true); 894 host->ShutdownAndDestroyWidget(true);
890 } 895 }
891 896
892 // Tests that when view initiated shutdown happens (i.e. RWHView is deleted 897 // Tests that when view initiated shutdown happens (i.e. RWHView is deleted
893 // before RWH), we clean up properly and don't leak the RWHVGuest. 898 // before RWH), we clean up properly and don't leak the RWHVGuest.
894 TEST_F(RenderWidgetHostViewMacTest, GuestViewDoesNotLeak) { 899 TEST_F(RenderWidgetHostViewMacTest, GuestViewDoesNotLeak) {
895 MockRenderWidgetHostDelegate delegate; 900 MockRenderWidgetHostDelegate delegate;
896 TestBrowserContext browser_context; 901 TestBrowserContext browser_context;
897 MockRenderProcessHost* process_host = 902 MockRenderProcessHost* process_host =
898 new MockRenderProcessHost(&browser_context); 903 new MockRenderProcessHost(&browser_context);
904 process_host->Init();
899 int32_t routing_id = process_host->GetNextRoutingID(); 905 int32_t routing_id = process_host->GetNextRoutingID();
900 906
901 // Owned by its |cocoa_view()|. 907 // Owned by its |cocoa_view()|.
902 MockRenderWidgetHostImpl* rwh = 908 MockRenderWidgetHostImpl* rwh =
903 new MockRenderWidgetHostImpl(&delegate, process_host, routing_id); 909 new MockRenderWidgetHostImpl(&delegate, process_host, routing_id);
904 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(rwh, true); 910 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(rwh, true);
905 911
906 // Add a delegate to the view. 912 // Add a delegate to the view.
907 base::scoped_nsobject<MockRenderWidgetHostViewMacDelegate> view_delegate( 913 base::scoped_nsobject<MockRenderWidgetHostViewMacDelegate> view_delegate(
908 [[MockRenderWidgetHostViewMacDelegate alloc] init]); 914 [[MockRenderWidgetHostViewMacDelegate alloc] init]);
(...skipping 22 matching lines...) Expand all
931 ASSERT_FALSE(guest_rwhv_weak.get()); 937 ASSERT_FALSE(guest_rwhv_weak.get());
932 } 938 }
933 939
934 // Tests setting background transparency. See also (disabled on Mac) 940 // Tests setting background transparency. See also (disabled on Mac)
935 // RenderWidgetHostTest.Background. This test has some additional checks for 941 // RenderWidgetHostTest.Background. This test has some additional checks for
936 // Mac. 942 // Mac.
937 TEST_F(RenderWidgetHostViewMacTest, Background) { 943 TEST_F(RenderWidgetHostViewMacTest, Background) {
938 TestBrowserContext browser_context; 944 TestBrowserContext browser_context;
939 MockRenderProcessHost* process_host = 945 MockRenderProcessHost* process_host =
940 new MockRenderProcessHost(&browser_context); 946 new MockRenderProcessHost(&browser_context);
947 process_host->Init();
941 MockRenderWidgetHostDelegate delegate; 948 MockRenderWidgetHostDelegate delegate;
942 int32_t routing_id = process_host->GetNextRoutingID(); 949 int32_t routing_id = process_host->GetNextRoutingID();
943 MockRenderWidgetHostImpl* host = 950 MockRenderWidgetHostImpl* host =
944 new MockRenderWidgetHostImpl(&delegate, process_host, routing_id); 951 new MockRenderWidgetHostImpl(&delegate, process_host, routing_id);
945 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false); 952 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false);
946 953
947 EXPECT_TRUE(view->GetBackgroundOpaque()); 954 EXPECT_TRUE(view->GetBackgroundOpaque());
948 EXPECT_TRUE([view->cocoa_view() isOpaque]); 955 EXPECT_TRUE([view->cocoa_view() isOpaque]);
949 956
950 view->SetBackgroundColor(SK_ColorTRANSPARENT); 957 view->SetBackgroundColor(SK_ColorTRANSPARENT);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 // the MockRenderProcessHost that is set up by the test harness which mocks 1020 // the MockRenderProcessHost that is set up by the test harness which mocks
1014 // out |OnMessageReceived()|. 1021 // out |OnMessageReceived()|.
1015 TestBrowserContext browser_context; 1022 TestBrowserContext browser_context;
1016 process_host_ = new MockRenderProcessHost(&browser_context); 1023 process_host_ = new MockRenderProcessHost(&browser_context);
1017 process_host_->Init(); 1024 process_host_->Init();
1018 MockRenderWidgetHostDelegate delegate; 1025 MockRenderWidgetHostDelegate delegate;
1019 int32_t routing_id = process_host_->GetNextRoutingID(); 1026 int32_t routing_id = process_host_->GetNextRoutingID();
1020 MockRenderWidgetHostImpl* host = 1027 MockRenderWidgetHostImpl* host =
1021 new MockRenderWidgetHostImpl(&delegate, process_host_, routing_id); 1028 new MockRenderWidgetHostImpl(&delegate, process_host_, routing_id);
1022 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false); 1029 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false);
1030 process_host_->sink().ClearMessages();
1023 1031
1024 // We'll use this IPC message to ack events. 1032 // We'll use this IPC message to ack events.
1025 InputEventAck ack(blink::WebInputEvent::GesturePinchUpdate, 1033 InputEventAck ack(blink::WebInputEvent::GesturePinchUpdate,
1026 INPUT_EVENT_ACK_STATE_CONSUMED); 1034 INPUT_EVENT_ACK_STATE_CONSUMED);
1027 scoped_ptr<IPC::Message> response( 1035 scoped_ptr<IPC::Message> response(
1028 new InputHostMsg_HandleInputEvent_ACK(0, ack)); 1036 new InputHostMsg_HandleInputEvent_ACK(0, ack));
1029 1037
1030 // Do a gesture that crosses the threshold. 1038 // Do a gesture that crosses the threshold.
1031 { 1039 {
1032 NSEvent* pinchBeginEvent = 1040 NSEvent* pinchBeginEvent =
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 EXPECT_EQ(1U, process_host_->sink().message_count()); 1128 EXPECT_EQ(1U, process_host_->sink().message_count());
1121 process_host_->sink().ClearMessages(); 1129 process_host_->sink().ClearMessages();
1122 } 1130 }
1123 1131
1124 // Clean up. 1132 // Clean up.
1125 host->ShutdownAndDestroyWidget(true); 1133 host->ShutdownAndDestroyWidget(true);
1126 } 1134 }
1127 1135
1128 1136
1129 } // namespace content 1137 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.cc ('k') | content/browser/web_contents/web_contents_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698