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

Side by Side Diff: content/browser/renderer_host/render_widget_host_unittest.cc

Issue 474213002: DevTools: control touch emulation from the browser side only. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebaselined Created 6 years, 4 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 | Annotate | Revision Log
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/shared_memory.h" 9 #include "base/memory/shared_memory.h"
10 #include "base/timer/timer.h" 10 #include "base/timer/timer.h"
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 result += WebInputEventTraits::GetName(event->type); 1025 result += WebInputEventTraits::GetName(event->type);
1026 } 1026 }
1027 process->sink().ClearMessages(); 1027 process->sink().ClearMessages();
1028 return result; 1028 return result;
1029 } 1029 }
1030 1030
1031 TEST_F(RenderWidgetHostTest, TouchEmulator) { 1031 TEST_F(RenderWidgetHostTest, TouchEmulator) {
1032 simulated_event_time_delta_seconds_ = 0.1; 1032 simulated_event_time_delta_seconds_ = 0.1;
1033 // Immediately ack all touches instead of sending them to the renderer. 1033 // Immediately ack all touches instead of sending them to the renderer.
1034 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false)); 1034 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
1035 host_->OnMessageReceived( 1035 host_->SetTouchEventEmulationEnabled(true);
1036 ViewHostMsg_SetTouchEventEmulationEnabled(0, true, true));
1037 process_->sink().ClearMessages(); 1036 process_->sink().ClearMessages();
1038 view_->set_bounds(gfx::Rect(0, 0, 400, 200)); 1037 view_->set_bounds(gfx::Rect(0, 0, 400, 200));
1039 view_->Show(); 1038 view_->Show();
1040 1039
1041 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false); 1040 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false);
1042 EXPECT_EQ(0U, process_->sink().message_count()); 1041 EXPECT_EQ(0U, process_->sink().message_count());
1043 1042
1044 // Mouse press becomes touch start which in turn becomes tap. 1043 // Mouse press becomes touch start which in turn becomes tap.
1045 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 10, 0, true); 1044 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 10, 0, true);
1046 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type()); 1045 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 SimulateMouseEvent( 1124 SimulateMouseEvent(
1126 WebInputEvent::MouseMove, 10, 120, WebInputEvent::ShiftKey, true); 1125 WebInputEvent::MouseMove, 10, 120, WebInputEvent::ShiftKey, true);
1127 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type()); 1126 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
1128 EXPECT_EQ("GesturePinchUpdate", 1127 EXPECT_EQ("GesturePinchUpdate",
1129 GetInputMessageTypes(process_)); 1128 GetInputMessageTypes(process_));
1130 SendInputEventACK(WebInputEvent::GesturePinchUpdate, 1129 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
1131 INPUT_EVENT_ACK_STATE_CONSUMED); 1130 INPUT_EVENT_ACK_STATE_CONSUMED);
1132 EXPECT_EQ(0U, process_->sink().message_count()); 1131 EXPECT_EQ(0U, process_->sink().message_count());
1133 1132
1134 // Turn off emulation during a pinch. 1133 // Turn off emulation during a pinch.
1135 host_->OnMessageReceived( 1134 host_->SetTouchEventEmulationEnabled(false);
1136 ViewHostMsg_SetTouchEventEmulationEnabled(0, false, false));
1137 EXPECT_EQ(WebInputEvent::TouchCancel, host_->acked_touch_event_type()); 1135 EXPECT_EQ(WebInputEvent::TouchCancel, host_->acked_touch_event_type());
1138 EXPECT_EQ("GesturePinchEnd GestureScrollEnd", 1136 EXPECT_EQ("GesturePinchEnd GestureScrollEnd",
1139 GetInputMessageTypes(process_)); 1137 GetInputMessageTypes(process_));
1140 EXPECT_EQ(0U, process_->sink().message_count()); 1138 EXPECT_EQ(0U, process_->sink().message_count());
1141 1139
1142 // Mouse event should pass untouched. 1140 // Mouse event should pass untouched.
1143 SimulateMouseEvent( 1141 SimulateMouseEvent(
1144 WebInputEvent::MouseMove, 10, 10, WebInputEvent::ShiftKey, true); 1142 WebInputEvent::MouseMove, 10, 10, WebInputEvent::ShiftKey, true);
1145 EXPECT_EQ("MouseMove", GetInputMessageTypes(process_)); 1143 EXPECT_EQ("MouseMove", GetInputMessageTypes(process_));
1146 SendInputEventACK(WebInputEvent::MouseMove, 1144 SendInputEventACK(WebInputEvent::MouseMove,
1147 INPUT_EVENT_ACK_STATE_CONSUMED); 1145 INPUT_EVENT_ACK_STATE_CONSUMED);
1148 EXPECT_EQ(0U, process_->sink().message_count()); 1146 EXPECT_EQ(0U, process_->sink().message_count());
1149 1147
1150 // Turn on emulation. 1148 // Turn on emulation.
1151 host_->OnMessageReceived( 1149 host_->SetTouchEventEmulationEnabled(true);
1152 ViewHostMsg_SetTouchEventEmulationEnabled(0, true, true));
1153 EXPECT_EQ(0U, process_->sink().message_count()); 1150 EXPECT_EQ(0U, process_->sink().message_count());
1154 1151
1155 // Another touch. 1152 // Another touch.
1156 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 10, 0, true); 1153 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 10, 0, true);
1157 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type()); 1154 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type());
1158 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_)); 1155 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_));
1159 EXPECT_EQ(0U, process_->sink().message_count()); 1156 EXPECT_EQ(0U, process_->sink().message_count());
1160 1157
1161 // Scroll. 1158 // Scroll.
1162 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 30, 0, true); 1159 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 30, 0, true);
1163 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type()); 1160 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
1164 EXPECT_EQ( 1161 EXPECT_EQ(
1165 "GestureTapCancel GestureScrollBegin GestureScrollUpdate", 1162 "GestureTapCancel GestureScrollBegin GestureScrollUpdate",
1166 GetInputMessageTypes(process_)); 1163 GetInputMessageTypes(process_));
1167 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1164 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1168 INPUT_EVENT_ACK_STATE_CONSUMED); 1165 INPUT_EVENT_ACK_STATE_CONSUMED);
1169 1166
1170 // Turn off emulation during a scroll. 1167 // Turn off emulation during a scroll.
1171 host_->OnMessageReceived( 1168 host_->SetTouchEventEmulationEnabled(false);
1172 ViewHostMsg_SetTouchEventEmulationEnabled(0, false, false));
1173 EXPECT_EQ(WebInputEvent::TouchCancel, host_->acked_touch_event_type()); 1169 EXPECT_EQ(WebInputEvent::TouchCancel, host_->acked_touch_event_type());
1174 1170
1175 EXPECT_EQ("GestureScrollEnd", GetInputMessageTypes(process_)); 1171 EXPECT_EQ("GestureScrollEnd", GetInputMessageTypes(process_));
1176 EXPECT_EQ(0U, process_->sink().message_count()); 1172 EXPECT_EQ(0U, process_->sink().message_count());
1177 } 1173 }
1178 1174
1179 #define TEST_InputRouterRoutes_NOARGS(INPUTMSG) \ 1175 #define TEST_InputRouterRoutes_NOARGS(INPUTMSG) \
1180 TEST_F(RenderWidgetHostTest, InputRouterRoutes##INPUTMSG) { \ 1176 TEST_F(RenderWidgetHostTest, InputRouterRoutes##INPUTMSG) { \
1181 host_->SetupForInputRouterTest(); \ 1177 host_->SetupForInputRouterTest(); \
1182 host_->INPUTMSG(); \ 1178 host_->INPUTMSG(); \
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 TEST_F(RenderWidgetHostTest, RendererExitedResetsInputRouter) { 1410 TEST_F(RenderWidgetHostTest, RendererExitedResetsInputRouter) {
1415 // RendererExited will delete the view. 1411 // RendererExited will delete the view.
1416 host_->SetView(new TestView(host_.get())); 1412 host_->SetView(new TestView(host_.get()));
1417 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); 1413 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1418 1414
1419 // Make sure the input router is in a fresh state. 1415 // Make sure the input router is in a fresh state.
1420 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); 1416 ASSERT_FALSE(host_->input_router()->HasPendingEvents());
1421 } 1417 }
1422 1418
1423 } // namespace content 1419 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698