Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/input/input_router_unittest.h" | 5 #include "content/browser/renderer_host/input/input_router_unittest.h" |
| 6 | 6 |
| 7 #include "content/browser/renderer_host/input/input_router.h" | 7 #include "content/browser/renderer_host/input/input_router.h" |
| 8 #include "content/common/input_messages.h" | 8 #include "content/common/input_messages.h" |
| 9 | 9 |
| 10 using blink::WebGestureEvent; | 10 using blink::WebGestureEvent; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 ui::LatencyInfo())); | 67 ui::LatencyInfo())); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void InputRouterTest::SimulateWheelEventWithPhase( | 70 void InputRouterTest::SimulateWheelEventWithPhase( |
| 71 WebMouseWheelEvent::Phase phase) { | 71 WebMouseWheelEvent::Phase phase) { |
| 72 input_router_->SendWheelEvent( | 72 input_router_->SendWheelEvent( |
| 73 MouseWheelEventWithLatencyInfo( | 73 MouseWheelEventWithLatencyInfo( |
| 74 SyntheticWebMouseWheelEventBuilder::Build(phase), ui::LatencyInfo())); | 74 SyntheticWebMouseWheelEventBuilder::Build(phase), ui::LatencyInfo())); |
| 75 } | 75 } |
| 76 | 76 |
| 77 // Inject provided synthetic WebGestureEvent instance. | |
| 78 void InputRouterTest::SimulateGestureEvent( | 77 void InputRouterTest::SimulateGestureEvent( |
| 79 const WebGestureEvent& gesture) { | 78 const WebGestureEvent& gesture) { |
| 80 GestureEventWithLatencyInfo gesture_with_latency(gesture, ui::LatencyInfo()); | 79 GestureEventWithLatencyInfo gesture_with_latency(gesture, ui::LatencyInfo()); |
| 81 input_router_->SendGestureEvent(gesture_with_latency); | 80 input_router_->SendGestureEvent(gesture_with_latency); |
| 82 } | 81 } |
| 83 | 82 |
| 84 // Inject simple synthetic WebGestureEvent instances. | |
| 85 void InputRouterTest::SimulateGestureEvent( | 83 void InputRouterTest::SimulateGestureEvent( |
| 86 WebInputEvent::Type type, | 84 WebInputEvent::Type type, |
| 87 WebGestureEvent::SourceDevice sourceDevice) { | 85 WebGestureEvent::SourceDevice sourceDevice) { |
| 88 SimulateGestureEvent( | 86 SimulateGestureEvent( |
| 89 SyntheticWebGestureEventBuilder::Build(type, sourceDevice)); | 87 SyntheticWebGestureEventBuilder::Build(type, sourceDevice)); |
| 90 } | 88 } |
| 91 | 89 |
| 92 void InputRouterTest::SimulateGestureScrollUpdateEvent(float dX, | 90 void InputRouterTest::SimulateGestureScrollUpdateEvent(float dX, |
| 93 float dY, | 91 float dY, |
| 94 int modifiers) { | 92 int modifiers) { |
| 95 SimulateGestureEvent( | 93 SimulateGestureEvent( |
| 96 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX, dY, modifiers)); | 94 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX, dY, modifiers)); |
| 97 } | 95 } |
| 98 | 96 |
| 99 void InputRouterTest::SimulateGesturePinchUpdateEvent(float scale, | 97 void InputRouterTest::SimulateGesturePinchUpdateEvent(float scale, |
| 100 float anchorX, | 98 float anchorX, |
| 101 float anchorY, | 99 float anchorY, |
| 102 int modifiers) { | 100 int modifiers) { |
| 103 SimulateGestureEvent( | 101 SimulateGestureEvent( |
| 104 SyntheticWebGestureEventBuilder::BuildPinchUpdate(scale, | 102 SyntheticWebGestureEventBuilder::BuildPinchUpdate(scale, |
| 105 anchorX, | 103 anchorX, |
| 106 anchorY, | 104 anchorY, |
| 107 modifiers)); | 105 modifiers)); |
| 108 } | 106 } |
| 109 | 107 |
| 110 // Inject synthetic GestureFlingStart events. | |
| 111 void InputRouterTest::SimulateGestureFlingStartEvent( | 108 void InputRouterTest::SimulateGestureFlingStartEvent( |
| 112 float velocityX, | 109 float velocityX, |
| 113 float velocityY, | 110 float velocityY, |
| 114 WebGestureEvent::SourceDevice sourceDevice) { | 111 WebGestureEvent::SourceDevice sourceDevice) { |
| 115 SimulateGestureEvent( | 112 SimulateGestureEvent( |
| 116 SyntheticWebGestureEventBuilder::BuildFling(velocityX, | 113 SyntheticWebGestureEventBuilder::BuildFling(velocityX, |
| 117 velocityY, | 114 velocityY, |
| 118 sourceDevice)); | 115 sourceDevice)); |
| 119 } | 116 } |
| 120 | 117 |
| 121 void InputRouterTest::SimulateTouchEvent(int x, int y) { | 118 void InputRouterTest::SimulateTouchEvent(WebInputEvent::Type type) { |
| 122 PressTouchPoint(x, y); | 119 ASSERT_TRUE(WebInputEvent::isTouchEventType(type)); |
| 120 touch_event_.ResetPoints(); | |
| 121 int index = PressTouchPoint(0, 0); | |
| 122 switch (type) { | |
| 123 case WebInputEvent::TouchMove: | |
| 124 MoveTouchPoint(index, 5, 5); | |
| 125 break; | |
| 126 case WebInputEvent::TouchEnd: | |
| 127 ReleaseTouchPoint(index); | |
| 128 break; | |
| 129 case WebInputEvent::TouchCancel: | |
| 130 CancelTouchPoint(index); | |
| 131 break; | |
| 132 default: | |
|
tdresser
2013/11/21 13:54:31
nit - add a NOTREACHED() here.
jdduke (slow)
2013/11/21 16:55:29
Hmm, I have the assert above for type being a vali
tdresser
2013/11/21 17:02:48
Ah, good point. I do like this somewhat better tho
| |
| 133 break; | |
| 134 } | |
| 123 SendTouchEvent(); | 135 SendTouchEvent(); |
| 124 } | 136 } |
| 125 | 137 |
| 126 // Set the timestamp for the touch-event. | |
| 127 void InputRouterTest::SetTouchTimestamp(base::TimeDelta timestamp) { | 138 void InputRouterTest::SetTouchTimestamp(base::TimeDelta timestamp) { |
| 128 touch_event_.SetTimestamp(timestamp); | 139 touch_event_.SetTimestamp(timestamp); |
| 129 } | 140 } |
| 130 | 141 |
| 131 // Sends a touch event (irrespective of whether the page has a touch-event | |
| 132 // handler or not). | |
| 133 void InputRouterTest::SendTouchEvent() { | 142 void InputRouterTest::SendTouchEvent() { |
| 134 input_router_->SendTouchEvent( | 143 input_router_->SendTouchEvent( |
| 135 TouchEventWithLatencyInfo(touch_event_, ui::LatencyInfo())); | 144 TouchEventWithLatencyInfo(touch_event_, ui::LatencyInfo())); |
| 136 touch_event_.ResetPoints(); | 145 touch_event_.ResetPoints(); |
| 137 } | 146 } |
| 138 | 147 |
| 139 int InputRouterTest::PressTouchPoint(int x, int y) { | 148 int InputRouterTest::PressTouchPoint(int x, int y) { |
| 140 return touch_event_.PressPoint(x, y); | 149 return touch_event_.PressPoint(x, y); |
| 141 } | 150 } |
| 142 | 151 |
| 143 void InputRouterTest::MoveTouchPoint(int index, int x, int y) { | 152 void InputRouterTest::MoveTouchPoint(int index, int x, int y) { |
| 144 touch_event_.MovePoint(index, x, y); | 153 touch_event_.MovePoint(index, x, y); |
| 145 } | 154 } |
| 146 | 155 |
| 147 void InputRouterTest::ReleaseTouchPoint(int index) { | 156 void InputRouterTest::ReleaseTouchPoint(int index) { |
| 148 touch_event_.ReleasePoint(index); | 157 touch_event_.ReleasePoint(index); |
| 149 } | 158 } |
| 150 | 159 |
| 160 void InputRouterTest::CancelTouchPoint(int index) { | |
| 161 touch_event_.CancelPoint(index); | |
| 162 } | |
| 163 | |
| 151 } // namespace content | 164 } // namespace content |
| OLD | NEW |