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 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <tuple> |
10 | 11 |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/mac/scoped_nsautorelease_pool.h" | 13 #include "base/mac/scoped_nsautorelease_pool.h" |
13 #include "base/mac/sdk_forward_declarations.h" | 14 #include "base/mac/sdk_forward_declarations.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #include "base/test/histogram_tester.h" | 17 #include "base/test/histogram_tester.h" |
17 #include "content/browser/browser_thread_impl.h" | 18 #include "content/browser/browser_thread_impl.h" |
18 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 19 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
19 #include "content/browser/frame_host/render_widget_host_view_guest.h" | 20 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 105 |
105 namespace { | 106 namespace { |
106 | 107 |
107 std::string GetInputMessageTypes(MockRenderProcessHost* process) { | 108 std::string GetInputMessageTypes(MockRenderProcessHost* process) { |
108 std::string result; | 109 std::string result; |
109 for (size_t i = 0; i < process->sink().message_count(); ++i) { | 110 for (size_t i = 0; i < process->sink().message_count(); ++i) { |
110 const IPC::Message* message = process->sink().GetMessageAt(i); | 111 const IPC::Message* message = process->sink().GetMessageAt(i); |
111 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type()); | 112 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type()); |
112 InputMsg_HandleInputEvent::Param params; | 113 InputMsg_HandleInputEvent::Param params; |
113 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, ¶ms)); | 114 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, ¶ms)); |
114 const blink::WebInputEvent* event = base::get<0>(params); | 115 const blink::WebInputEvent* event = std::get<0>(params); |
115 if (i != 0) | 116 if (i != 0) |
116 result += " "; | 117 result += " "; |
117 result += WebInputEventTraits::GetName(event->type); | 118 result += WebInputEventTraits::GetName(event->type); |
118 } | 119 } |
119 process->sink().ClearMessages(); | 120 process->sink().ClearMessages(); |
120 return result; | 121 return result; |
121 } | 122 } |
122 | 123 |
123 id MockGestureEvent(NSEventType type, double magnification) { | 124 id MockGestureEvent(NSEventType type, double magnification) { |
124 id event = [OCMockObject mockForClass:[NSEvent class]]; | 125 id event = [OCMockObject mockForClass:[NSEvent class]]; |
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 EXPECT_TRUE([view->cocoa_view() isOpaque]); | 1115 EXPECT_TRUE([view->cocoa_view() isOpaque]); |
1115 | 1116 |
1116 view->SetBackgroundColor(SK_ColorTRANSPARENT); | 1117 view->SetBackgroundColor(SK_ColorTRANSPARENT); |
1117 EXPECT_FALSE(view->GetBackgroundOpaque()); | 1118 EXPECT_FALSE(view->GetBackgroundOpaque()); |
1118 EXPECT_FALSE([view->cocoa_view() isOpaque]); | 1119 EXPECT_FALSE([view->cocoa_view() isOpaque]); |
1119 | 1120 |
1120 const IPC::Message* set_background; | 1121 const IPC::Message* set_background; |
1121 set_background = process_host->sink().GetUniqueMessageMatching( | 1122 set_background = process_host->sink().GetUniqueMessageMatching( |
1122 ViewMsg_SetBackgroundOpaque::ID); | 1123 ViewMsg_SetBackgroundOpaque::ID); |
1123 ASSERT_TRUE(set_background); | 1124 ASSERT_TRUE(set_background); |
1124 base::Tuple<bool> sent_background; | 1125 std::tuple<bool> sent_background; |
1125 ViewMsg_SetBackgroundOpaque::Read(set_background, &sent_background); | 1126 ViewMsg_SetBackgroundOpaque::Read(set_background, &sent_background); |
1126 EXPECT_FALSE(base::get<0>(sent_background)); | 1127 EXPECT_FALSE(std::get<0>(sent_background)); |
1127 | 1128 |
1128 // Try setting it back. | 1129 // Try setting it back. |
1129 process_host->sink().ClearMessages(); | 1130 process_host->sink().ClearMessages(); |
1130 view->SetBackgroundColor(SK_ColorWHITE); | 1131 view->SetBackgroundColor(SK_ColorWHITE); |
1131 EXPECT_TRUE(view->GetBackgroundOpaque()); | 1132 EXPECT_TRUE(view->GetBackgroundOpaque()); |
1132 EXPECT_TRUE([view->cocoa_view() isOpaque]); | 1133 EXPECT_TRUE([view->cocoa_view() isOpaque]); |
1133 set_background = process_host->sink().GetUniqueMessageMatching( | 1134 set_background = process_host->sink().GetUniqueMessageMatching( |
1134 ViewMsg_SetBackgroundOpaque::ID); | 1135 ViewMsg_SetBackgroundOpaque::ID); |
1135 ASSERT_TRUE(set_background); | 1136 ASSERT_TRUE(set_background); |
1136 ViewMsg_SetBackgroundOpaque::Read(set_background, &sent_background); | 1137 ViewMsg_SetBackgroundOpaque::Read(set_background, &sent_background); |
1137 EXPECT_TRUE(base::get<0>(sent_background)); | 1138 EXPECT_TRUE(std::get<0>(sent_background)); |
1138 | 1139 |
1139 host->ShutdownAndDestroyWidget(true); | 1140 host->ShutdownAndDestroyWidget(true); |
1140 } | 1141 } |
1141 | 1142 |
1142 class RenderWidgetHostViewMacPinchTest : public RenderWidgetHostViewMacTest { | 1143 class RenderWidgetHostViewMacPinchTest : public RenderWidgetHostViewMacTest { |
1143 public: | 1144 public: |
1144 RenderWidgetHostViewMacPinchTest() : process_host_(NULL) {} | 1145 RenderWidgetHostViewMacPinchTest() : process_host_(NULL) {} |
1145 | 1146 |
1146 bool ZoomDisabledForPinchUpdateMessage() { | 1147 bool ZoomDisabledForPinchUpdateMessage() { |
1147 const IPC::Message* message = NULL; | 1148 const IPC::Message* message = NULL; |
1148 // The first message may be a PinchBegin. Go for the second message if | 1149 // The first message may be a PinchBegin. Go for the second message if |
1149 // there are two. | 1150 // there are two. |
1150 switch (process_host_->sink().message_count()) { | 1151 switch (process_host_->sink().message_count()) { |
1151 case 1: | 1152 case 1: |
1152 message = process_host_->sink().GetMessageAt(0); | 1153 message = process_host_->sink().GetMessageAt(0); |
1153 break; | 1154 break; |
1154 case 2: | 1155 case 2: |
1155 message = process_host_->sink().GetMessageAt(1); | 1156 message = process_host_->sink().GetMessageAt(1); |
1156 break; | 1157 break; |
1157 default: | 1158 default: |
1158 NOTREACHED(); | 1159 NOTREACHED(); |
1159 break; | 1160 break; |
1160 } | 1161 } |
1161 DCHECK(message); | 1162 DCHECK(message); |
1162 base::Tuple<IPC::WebInputEventPointer, ui::LatencyInfo, | 1163 std::tuple<IPC::WebInputEventPointer, ui::LatencyInfo, |
1163 InputEventDispatchType> | 1164 InputEventDispatchType> |
1164 data; | 1165 data; |
1165 InputMsg_HandleInputEvent::Read(message, &data); | 1166 InputMsg_HandleInputEvent::Read(message, &data); |
1166 IPC::WebInputEventPointer ipc_event = base::get<0>(data); | 1167 IPC::WebInputEventPointer ipc_event = std::get<0>(data); |
1167 const blink::WebGestureEvent* gesture_event = | 1168 const blink::WebGestureEvent* gesture_event = |
1168 static_cast<const blink::WebGestureEvent*>(ipc_event); | 1169 static_cast<const blink::WebGestureEvent*>(ipc_event); |
1169 return gesture_event->data.pinchUpdate.zoomDisabled; | 1170 return gesture_event->data.pinchUpdate.zoomDisabled; |
1170 } | 1171 } |
1171 | 1172 |
1172 MockRenderProcessHost* process_host_; | 1173 MockRenderProcessHost* process_host_; |
1173 }; | 1174 }; |
1174 | 1175 |
1175 TEST_F(RenderWidgetHostViewMacPinchTest, PinchThresholding) { | 1176 TEST_F(RenderWidgetHostViewMacPinchTest, PinchThresholding) { |
1176 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than | 1177 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1311 // Verify that Event.Latency.OS.MOUSE_WHEEL histogram is computed properly. | 1312 // Verify that Event.Latency.OS.MOUSE_WHEEL histogram is computed properly. |
1312 NSEvent* wheelEvent = MockScrollWheelEventWithPhase(@selector(phaseBegan),3); | 1313 NSEvent* wheelEvent = MockScrollWheelEventWithPhase(@selector(phaseBegan),3); |
1313 [view->cocoa_view() scrollWheel:wheelEvent]; | 1314 [view->cocoa_view() scrollWheel:wheelEvent]; |
1314 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1); | 1315 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1); |
1315 | 1316 |
1316 // Clean up. | 1317 // Clean up. |
1317 host->ShutdownAndDestroyWidget(true); | 1318 host->ShutdownAndDestroyWidget(true); |
1318 } | 1319 } |
1319 | 1320 |
1320 } // namespace content | 1321 } // namespace content |
OLD | NEW |