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 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 EXPECT_TRUE([view->cocoa_view() isOpaque]); | 859 EXPECT_TRUE([view->cocoa_view() isOpaque]); |
860 set_background = process_host->sink().GetUniqueMessageMatching( | 860 set_background = process_host->sink().GetUniqueMessageMatching( |
861 ViewMsg_SetBackgroundOpaque::ID); | 861 ViewMsg_SetBackgroundOpaque::ID); |
862 ASSERT_TRUE(set_background); | 862 ASSERT_TRUE(set_background); |
863 ViewMsg_SetBackgroundOpaque::Read(set_background, &sent_background); | 863 ViewMsg_SetBackgroundOpaque::Read(set_background, &sent_background); |
864 EXPECT_TRUE(get<0>(sent_background)); | 864 EXPECT_TRUE(get<0>(sent_background)); |
865 | 865 |
866 host->Shutdown(); | 866 host->Shutdown(); |
867 } | 867 } |
868 | 868 |
869 TEST_F(RenderWidgetHostViewMacTest, PinchThresholding) { | 869 class RenderWidgetHostViewMacPinchTest : public RenderWidgetHostViewMacTest { |
| 870 public: |
| 871 RenderWidgetHostViewMacPinchTest() : process_host_(NULL) {} |
| 872 |
| 873 bool ZoomDisabledForPinchUpdateMessage() { |
| 874 const IPC::Message* message = NULL; |
| 875 // The first message may be a PinchBegin. Go for the second message if |
| 876 // there are two. |
| 877 switch (process_host_->sink().message_count()) { |
| 878 case 1: |
| 879 message = process_host_->sink().GetMessageAt(0); |
| 880 break; |
| 881 case 2: |
| 882 message = process_host_->sink().GetMessageAt(1); |
| 883 break; |
| 884 default: |
| 885 NOTREACHED(); |
| 886 break; |
| 887 } |
| 888 DCHECK(message); |
| 889 Tuple<IPC::WebInputEventPointer, ui::LatencyInfo, bool> data; |
| 890 InputMsg_HandleInputEvent::Read(message, &data); |
| 891 IPC::WebInputEventPointer ipc_event = get<0>(data); |
| 892 const blink::WebGestureEvent* gesture_event = |
| 893 static_cast<const blink::WebGestureEvent*>(ipc_event); |
| 894 return gesture_event->data.pinchUpdate.zoomDisabled; |
| 895 } |
| 896 |
| 897 MockRenderProcessHost* process_host_; |
| 898 }; |
| 899 |
| 900 TEST_F(RenderWidgetHostViewMacPinchTest, PinchThresholding) { |
870 // This tests Lion+ functionality, so don't run the test pre-Lion. | 901 // This tests Lion+ functionality, so don't run the test pre-Lion. |
871 if (!base::mac::IsOSLionOrLater()) | 902 if (!base::mac::IsOSLionOrLater()) |
872 return; | 903 return; |
873 | 904 |
874 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than | 905 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than |
875 // the MockRenderProcessHost that is set up by the test harness which mocks | 906 // the MockRenderProcessHost that is set up by the test harness which mocks |
876 // out |OnMessageReceived()|. | 907 // out |OnMessageReceived()|. |
877 TestBrowserContext browser_context; | 908 TestBrowserContext browser_context; |
878 MockRenderProcessHost* process_host = | 909 process_host_ = new MockRenderProcessHost(&browser_context); |
879 new MockRenderProcessHost(&browser_context); | |
880 MockRenderWidgetHostDelegate delegate; | 910 MockRenderWidgetHostDelegate delegate; |
881 MockRenderWidgetHostImpl* host = new MockRenderWidgetHostImpl( | 911 MockRenderWidgetHostImpl* host = new MockRenderWidgetHostImpl( |
882 &delegate, process_host, MSG_ROUTING_NONE); | 912 &delegate, process_host_, MSG_ROUTING_NONE); |
883 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false); | 913 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false); |
884 | 914 |
885 // We'll use this IPC message to ack events. | 915 // We'll use this IPC message to ack events. |
886 InputHostMsg_HandleInputEvent_ACK_Params ack; | 916 InputHostMsg_HandleInputEvent_ACK_Params ack; |
887 ack.type = blink::WebInputEvent::GesturePinchUpdate; | 917 ack.type = blink::WebInputEvent::GesturePinchUpdate; |
888 ack.state = INPUT_EVENT_ACK_STATE_CONSUMED; | 918 ack.state = INPUT_EVENT_ACK_STATE_CONSUMED; |
889 scoped_ptr<IPC::Message> response( | 919 scoped_ptr<IPC::Message> response( |
890 new InputHostMsg_HandleInputEvent_ACK(0, ack)); | 920 new InputHostMsg_HandleInputEvent_ACK(0, ack)); |
891 | 921 |
892 // Do a gesture that crosses the threshold. | 922 // Do a gesture that crosses the threshold. |
893 { | 923 { |
894 NSEvent* pinchBeginEvent = | 924 NSEvent* pinchBeginEvent = |
895 MockGestureEvent(NSEventTypeBeginGesture, 100.1, 0); | 925 MockGestureEvent(NSEventTypeBeginGesture, 100.1, 0); |
896 NSEvent* pinchUpdateEvents[3] = { | 926 NSEvent* pinchUpdateEvents[3] = { |
897 MockGestureEvent(NSEventTypeMagnify, 100.2, 0.25), | 927 MockGestureEvent(NSEventTypeMagnify, 100.2, 0.25), |
898 MockGestureEvent(NSEventTypeMagnify, 100.3, 0.25), | 928 MockGestureEvent(NSEventTypeMagnify, 100.3, 0.25), |
899 MockGestureEvent(NSEventTypeMagnify, 100.4, 0.25), | 929 MockGestureEvent(NSEventTypeMagnify, 100.4, 0.25), |
900 }; | 930 }; |
901 NSEvent* pinchEndEvent = | 931 NSEvent* pinchEndEvent = |
902 MockGestureEvent(NSEventTypeEndGesture, 100.5, 0); | 932 MockGestureEvent(NSEventTypeEndGesture, 100.5, 0); |
903 | 933 |
904 // No messages are sent for the pinch begin and the first update event. | |
905 [view->cocoa_view() beginGestureWithEvent:pinchBeginEvent]; | 934 [view->cocoa_view() beginGestureWithEvent:pinchBeginEvent]; |
| 935 EXPECT_EQ(0U, process_host_->sink().message_count()); |
| 936 |
| 937 // No zoom is sent for the first update event. |
906 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvents[0]]; | 938 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvents[0]]; |
907 ASSERT_EQ(0U, process_host->sink().message_count()); | 939 host->OnMessageReceived(*response); |
| 940 EXPECT_EQ(2U, process_host_->sink().message_count()); |
| 941 EXPECT_TRUE(ZoomDisabledForPinchUpdateMessage()); |
| 942 process_host_->sink().ClearMessages(); |
908 | 943 |
909 // The second update event crosses the threshold of 0.4, and so a begin | 944 // The second update event crosses the threshold of 0.4, and so zoom is no |
910 // and update are sent. | 945 // longer disabled. |
911 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvents[1]]; | 946 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvents[1]]; |
912 ASSERT_EQ(2U, process_host->sink().message_count()); | 947 EXPECT_FALSE(ZoomDisabledForPinchUpdateMessage()); |
913 host->OnMessageReceived(*response); | 948 host->OnMessageReceived(*response); |
| 949 EXPECT_EQ(1U, process_host_->sink().message_count()); |
| 950 process_host_->sink().ClearMessages(); |
914 | 951 |
915 // The third update only causes one event to be sent. | 952 // The third update still has zoom enabled. |
916 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvents[2]]; | 953 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvents[2]]; |
917 ASSERT_EQ(3U, process_host->sink().message_count()); | 954 EXPECT_FALSE(ZoomDisabledForPinchUpdateMessage()); |
918 host->OnMessageReceived(*response); | 955 host->OnMessageReceived(*response); |
| 956 EXPECT_EQ(1U, process_host_->sink().message_count()); |
| 957 process_host_->sink().ClearMessages(); |
919 | 958 |
920 // As does the end. | |
921 [view->cocoa_view() endGestureWithEvent:pinchEndEvent]; | 959 [view->cocoa_view() endGestureWithEvent:pinchEndEvent]; |
922 ASSERT_EQ(4U, process_host->sink().message_count()); | 960 EXPECT_EQ(1U, process_host_->sink().message_count()); |
923 | 961 process_host_->sink().ClearMessages(); |
924 process_host->sink().ClearMessages(); | |
925 } | 962 } |
926 | 963 |
927 // Do a gesture that doesn't cross the threshold, but happens within 1 second, | 964 // Do a gesture that doesn't cross the threshold, but happens within 1 second, |
928 // so it should be sent to the renderer. | 965 // so it should be sent to the renderer. |
929 { | 966 { |
930 NSEvent* pinchBeginEvent = | 967 NSEvent* pinchBeginEvent = |
931 MockGestureEvent(NSEventTypeBeginGesture, 101.0, 0); | 968 MockGestureEvent(NSEventTypeBeginGesture, 101.0, 0); |
932 NSEvent* pinchUpdateEvent = | 969 NSEvent* pinchUpdateEvent = |
933 MockGestureEvent(NSEventTypeMagnify, 101.1, 0.25); | 970 MockGestureEvent(NSEventTypeMagnify, 101.1, 0.25); |
934 NSEvent* pinchEndEvent = | 971 NSEvent* pinchEndEvent = |
935 MockGestureEvent(NSEventTypeEndGesture, 101.2, 0); | 972 MockGestureEvent(NSEventTypeEndGesture, 101.2, 0); |
936 | 973 |
937 // No message comes for the begin event. | |
938 [view->cocoa_view() beginGestureWithEvent:pinchBeginEvent]; | 974 [view->cocoa_view() beginGestureWithEvent:pinchBeginEvent]; |
939 ASSERT_EQ(0U, process_host->sink().message_count()); | 975 EXPECT_EQ(0U, process_host_->sink().message_count()); |
940 | 976 |
941 // Two messages come for the first update event. | 977 // Expect that a zoom happen because the time threshold has not passed. |
942 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvent]; | 978 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvent]; |
943 ASSERT_EQ(2U, process_host->sink().message_count()); | 979 EXPECT_FALSE(ZoomDisabledForPinchUpdateMessage()); |
944 host->OnMessageReceived(*response); | 980 host->OnMessageReceived(*response); |
| 981 EXPECT_EQ(2U, process_host_->sink().message_count()); |
| 982 process_host_->sink().ClearMessages(); |
945 | 983 |
946 // The end event sends one message. | |
947 [view->cocoa_view() endGestureWithEvent:pinchEndEvent]; | 984 [view->cocoa_view() endGestureWithEvent:pinchEndEvent]; |
948 ASSERT_EQ(3U, process_host->sink().message_count()); | 985 EXPECT_EQ(1U, process_host_->sink().message_count()); |
949 | 986 process_host_->sink().ClearMessages(); |
950 process_host->sink().ClearMessages(); | |
951 } | 987 } |
952 | 988 |
953 // Do a gesture that doesn't cross the threshold and happens more than one | 989 // Do a gesture that doesn't cross the threshold and happens more than one |
954 // second later. | 990 // second later. |
955 { | 991 { |
956 NSEvent* pinchBeginEvent = | 992 NSEvent* pinchBeginEvent = |
957 MockGestureEvent(NSEventTypeBeginGesture, 103.0, 0); | 993 MockGestureEvent(NSEventTypeBeginGesture, 103.0, 0); |
958 NSEvent* pinchUpdateEvent = | 994 NSEvent* pinchUpdateEvent = |
959 MockGestureEvent(NSEventTypeMagnify, 103.1, 0.25); | 995 MockGestureEvent(NSEventTypeMagnify, 103.1, 0.25); |
960 NSEvent* pinchEndEvent = | 996 NSEvent* pinchEndEvent = |
961 MockGestureEvent(NSEventTypeEndGesture, 103.2, 0); | 997 MockGestureEvent(NSEventTypeEndGesture, 103.2, 0); |
962 | 998 |
963 // No message comes for the begin event. | |
964 [view->cocoa_view() beginGestureWithEvent:pinchBeginEvent]; | 999 [view->cocoa_view() beginGestureWithEvent:pinchBeginEvent]; |
965 ASSERT_EQ(0U, process_host->sink().message_count()); | 1000 EXPECT_EQ(0U, process_host_->sink().message_count()); |
966 | 1001 |
967 // Two messages come for the first update event. | 1002 // Expect that zoom be disabled because the time threshold has passed. |
968 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvent]; | 1003 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvent]; |
969 ASSERT_EQ(0U, process_host->sink().message_count()); | 1004 EXPECT_EQ(2U, process_host_->sink().message_count()); |
| 1005 EXPECT_TRUE(ZoomDisabledForPinchUpdateMessage()); |
| 1006 host->OnMessageReceived(*response); |
| 1007 process_host_->sink().ClearMessages(); |
970 | 1008 |
971 // As does the end. | |
972 [view->cocoa_view() endGestureWithEvent:pinchEndEvent]; | 1009 [view->cocoa_view() endGestureWithEvent:pinchEndEvent]; |
973 ASSERT_EQ(0U, process_host->sink().message_count()); | 1010 EXPECT_EQ(1U, process_host_->sink().message_count()); |
974 | 1011 process_host_->sink().ClearMessages(); |
975 process_host->sink().ClearMessages(); | |
976 } | 1012 } |
977 | 1013 |
978 // Clean up. | 1014 // Clean up. |
979 host->Shutdown(); | 1015 host->Shutdown(); |
980 } | 1016 } |
981 | 1017 |
982 | 1018 |
983 } // namespace content | 1019 } // namespace content |
OLD | NEW |