| 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 "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
| 8 #include "base/mac/scoped_nsautorelease_pool.h" | 8 #include "base/mac/scoped_nsautorelease_pool.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 196 } |
| 197 protected: | 197 protected: |
| 198 private: | 198 private: |
| 199 // This class isn't derived from PlatformTest. | 199 // This class isn't derived from PlatformTest. |
| 200 base::mac::ScopedNSAutoreleasePool pool_; | 200 base::mac::ScopedNSAutoreleasePool pool_; |
| 201 | 201 |
| 202 RenderWidgetHostView* old_rwhv_; | 202 RenderWidgetHostView* old_rwhv_; |
| 203 | 203 |
| 204 protected: | 204 protected: |
| 205 RenderWidgetHostViewMac* rwhv_mac_; | 205 RenderWidgetHostViewMac* rwhv_mac_; |
| 206 scoped_nsobject<RenderWidgetHostViewCocoa> rwhv_cocoa_; | 206 base::scoped_nsobject<RenderWidgetHostViewCocoa> rwhv_cocoa_; |
| 207 | 207 |
| 208 private: | 208 private: |
| 209 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewMacTest); | 209 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewMacTest); |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 TEST_F(RenderWidgetHostViewMacTest, Basic) { | 212 TEST_F(RenderWidgetHostViewMacTest, Basic) { |
| 213 } | 213 } |
| 214 | 214 |
| 215 TEST_F(RenderWidgetHostViewMacTest, AcceptsFirstResponder) { | 215 TEST_F(RenderWidgetHostViewMacTest, AcceptsFirstResponder) { |
| 216 // The RWHVCocoa should normally accept first responder status. | 216 // The RWHVCocoa should normally accept first responder status. |
| 217 EXPECT_TRUE([rwhv_cocoa_.get() acceptsFirstResponder]); | 217 EXPECT_TRUE([rwhv_cocoa_.get() acceptsFirstResponder]); |
| 218 | 218 |
| 219 // Unless we tell it not to. | 219 // Unless we tell it not to. |
| 220 rwhv_mac_->SetTakesFocusOnlyOnMouseDown(true); | 220 rwhv_mac_->SetTakesFocusOnlyOnMouseDown(true); |
| 221 EXPECT_FALSE([rwhv_cocoa_.get() acceptsFirstResponder]); | 221 EXPECT_FALSE([rwhv_cocoa_.get() acceptsFirstResponder]); |
| 222 | 222 |
| 223 // But we can set things back to the way they were originally. | 223 // But we can set things back to the way they were originally. |
| 224 rwhv_mac_->SetTakesFocusOnlyOnMouseDown(false); | 224 rwhv_mac_->SetTakesFocusOnlyOnMouseDown(false); |
| 225 EXPECT_TRUE([rwhv_cocoa_.get() acceptsFirstResponder]); | 225 EXPECT_TRUE([rwhv_cocoa_.get() acceptsFirstResponder]); |
| 226 } | 226 } |
| 227 | 227 |
| 228 TEST_F(RenderWidgetHostViewMacTest, TakesFocusOnMouseDown) { | 228 TEST_F(RenderWidgetHostViewMacTest, TakesFocusOnMouseDown) { |
| 229 scoped_nsobject<CocoaTestHelperWindow> | 229 base::scoped_nsobject<CocoaTestHelperWindow> window( |
| 230 window([[CocoaTestHelperWindow alloc] init]); | 230 [[CocoaTestHelperWindow alloc] init]); |
| 231 [[window contentView] addSubview:rwhv_cocoa_.get()]; | 231 [[window contentView] addSubview:rwhv_cocoa_.get()]; |
| 232 | 232 |
| 233 // Even if the RWHVCocoa disallows first responder, clicking on it gives it | 233 // Even if the RWHVCocoa disallows first responder, clicking on it gives it |
| 234 // focus. | 234 // focus. |
| 235 [window setPretendIsKeyWindow:YES]; | 235 [window setPretendIsKeyWindow:YES]; |
| 236 [window makeFirstResponder:nil]; | 236 [window makeFirstResponder:nil]; |
| 237 ASSERT_NE(rwhv_cocoa_.get(), [window firstResponder]); | 237 ASSERT_NE(rwhv_cocoa_.get(), [window firstResponder]); |
| 238 | 238 |
| 239 rwhv_mac_->SetTakesFocusOnlyOnMouseDown(true); | 239 rwhv_mac_->SetTakesFocusOnlyOnMouseDown(true); |
| 240 EXPECT_FALSE([rwhv_cocoa_.get() acceptsFirstResponder]); | 240 EXPECT_FALSE([rwhv_cocoa_.get() acceptsFirstResponder]); |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 TestBrowserContext browser_context; | 651 TestBrowserContext browser_context; |
| 652 MockRenderProcessHost* process_host = | 652 MockRenderProcessHost* process_host = |
| 653 new MockRenderProcessHost(&browser_context); | 653 new MockRenderProcessHost(&browser_context); |
| 654 | 654 |
| 655 // Owned by its |cocoa_view()|. | 655 // Owned by its |cocoa_view()|. |
| 656 MockRenderWidgetHostImpl* rwh = new MockRenderWidgetHostImpl( | 656 MockRenderWidgetHostImpl* rwh = new MockRenderWidgetHostImpl( |
| 657 &delegate, process_host, MSG_ROUTING_NONE); | 657 &delegate, process_host, MSG_ROUTING_NONE); |
| 658 RenderWidgetHostViewMac* view = static_cast<RenderWidgetHostViewMac*>( | 658 RenderWidgetHostViewMac* view = static_cast<RenderWidgetHostViewMac*>( |
| 659 RenderWidgetHostView::CreateViewForWidget(rwh)); | 659 RenderWidgetHostView::CreateViewForWidget(rwh)); |
| 660 | 660 |
| 661 scoped_nsobject<CocoaTestHelperWindow> | 661 base::scoped_nsobject<CocoaTestHelperWindow> window( |
| 662 window([[CocoaTestHelperWindow alloc] init]); | 662 [[CocoaTestHelperWindow alloc] init]); |
| 663 [[window contentView] addSubview:view->cocoa_view()]; | 663 [[window contentView] addSubview:view->cocoa_view()]; |
| 664 | 664 |
| 665 EXPECT_CALL(*rwh, Focus()); | 665 EXPECT_CALL(*rwh, Focus()); |
| 666 [window makeFirstResponder:view->cocoa_view()]; | 666 [window makeFirstResponder:view->cocoa_view()]; |
| 667 testing::Mock::VerifyAndClearExpectations(rwh); | 667 testing::Mock::VerifyAndClearExpectations(rwh); |
| 668 | 668 |
| 669 EXPECT_CALL(*rwh, Blur()); | 669 EXPECT_CALL(*rwh, Blur()); |
| 670 view->SetActive(false); | 670 view->SetActive(false); |
| 671 testing::Mock::VerifyAndClearExpectations(rwh); | 671 testing::Mock::VerifyAndClearExpectations(rwh); |
| 672 | 672 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 TestBrowserContext browser_context; | 737 TestBrowserContext browser_context; |
| 738 MockRenderProcessHost* process_host = | 738 MockRenderProcessHost* process_host = |
| 739 new MockRenderProcessHost(&browser_context); | 739 new MockRenderProcessHost(&browser_context); |
| 740 MockRenderWidgetHostDelegate delegate; | 740 MockRenderWidgetHostDelegate delegate; |
| 741 MockRenderWidgetHostImpl* host = new MockRenderWidgetHostImpl( | 741 MockRenderWidgetHostImpl* host = new MockRenderWidgetHostImpl( |
| 742 &delegate, process_host, MSG_ROUTING_NONE); | 742 &delegate, process_host, MSG_ROUTING_NONE); |
| 743 RenderWidgetHostViewMac* view = static_cast<RenderWidgetHostViewMac*>( | 743 RenderWidgetHostViewMac* view = static_cast<RenderWidgetHostViewMac*>( |
| 744 RenderWidgetHostView::CreateViewForWidget(host)); | 744 RenderWidgetHostView::CreateViewForWidget(host)); |
| 745 | 745 |
| 746 // Add a delegate to the view. | 746 // Add a delegate to the view. |
| 747 scoped_nsobject<MockRenderWidgetHostViewMacDelegate> view_delegate( | 747 base::scoped_nsobject<MockRenderWidgetHostViewMacDelegate> view_delegate( |
| 748 [[MockRenderWidgetHostViewMacDelegate alloc] init]); | 748 [[MockRenderWidgetHostViewMacDelegate alloc] init]); |
| 749 view->SetDelegate(view_delegate.get()); | 749 view->SetDelegate(view_delegate.get()); |
| 750 | 750 |
| 751 // Send an initial wheel event for scrolling by 3 lines. | 751 // Send an initial wheel event for scrolling by 3 lines. |
| 752 NSEvent* event1 = MockScrollWheelEventWithPhase(@selector(phaseBegan), 3); | 752 NSEvent* event1 = MockScrollWheelEventWithPhase(@selector(phaseBegan), 3); |
| 753 [view->cocoa_view() scrollWheel:event1]; | 753 [view->cocoa_view() scrollWheel:event1]; |
| 754 ASSERT_EQ(1U, process_host->sink().message_count()); | 754 ASSERT_EQ(1U, process_host->sink().message_count()); |
| 755 process_host->sink().ClearMessages(); | 755 process_host->sink().ClearMessages(); |
| 756 | 756 |
| 757 // Indicate that the wheel event was unhandled. | 757 // Indicate that the wheel event was unhandled. |
| 758 scoped_ptr<IPC::Message> response1(new InputHostMsg_HandleInputEvent_ACK(0, | 758 scoped_ptr<IPC::Message> response1(new InputHostMsg_HandleInputEvent_ACK(0, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 774 host->OnMessageReceived(*response2); | 774 host->OnMessageReceived(*response2); |
| 775 | 775 |
| 776 // Check that the view delegate ignored the empty unhandled wheel event. | 776 // Check that the view delegate ignored the empty unhandled wheel event. |
| 777 ASSERT_EQ(NO, view_delegate.get().unhandledWheelEventReceived); | 777 ASSERT_EQ(NO, view_delegate.get().unhandledWheelEventReceived); |
| 778 | 778 |
| 779 // Clean up. | 779 // Clean up. |
| 780 host->Shutdown(); | 780 host->Shutdown(); |
| 781 } | 781 } |
| 782 | 782 |
| 783 } // namespace content | 783 } // namespace content |
| OLD | NEW |