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_impl.h" | 5 #include "content/browser/renderer_host/input/input_router_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "content/public/test/mock_render_process_host.h" | 32 #include "content/public/test/mock_render_process_host.h" |
33 #include "content/public/test/test_browser_context.h" | 33 #include "content/public/test/test_browser_context.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
35 #include "ui/events/keycodes/keyboard_codes.h" | 35 #include "ui/events/keycodes/keyboard_codes.h" |
36 | 36 |
37 #if defined(USE_AURA) | 37 #if defined(USE_AURA) |
38 #include "content/browser/renderer_host/ui_events_helper.h" | 38 #include "content/browser/renderer_host/ui_events_helper.h" |
39 #include "ui/events/event.h" | 39 #include "ui/events/event.h" |
40 #endif | 40 #endif |
41 | 41 |
42 using base::TimeDelta; | |
43 using blink::WebGestureDevice; | 42 using blink::WebGestureDevice; |
44 using blink::WebGestureEvent; | 43 using blink::WebGestureEvent; |
45 using blink::WebKeyboardEvent; | 44 using blink::WebKeyboardEvent; |
46 using blink::WebInputEvent; | 45 using blink::WebInputEvent; |
47 using blink::WebMouseEvent; | 46 using blink::WebMouseEvent; |
48 using blink::WebMouseWheelEvent; | 47 using blink::WebMouseWheelEvent; |
49 using blink::WebTouchEvent; | 48 using blink::WebTouchEvent; |
50 using blink::WebTouchPoint; | 49 using blink::WebTouchPoint; |
51 | 50 |
52 namespace content { | 51 namespace content { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 105 |
107 #if defined(USE_AURA) | 106 #if defined(USE_AURA) |
108 bool TouchEventsAreEquivalent(const ui::TouchEvent& first, | 107 bool TouchEventsAreEquivalent(const ui::TouchEvent& first, |
109 const ui::TouchEvent& second) { | 108 const ui::TouchEvent& second) { |
110 if (first.type() != second.type()) | 109 if (first.type() != second.type()) |
111 return false; | 110 return false; |
112 if (first.location() != second.location()) | 111 if (first.location() != second.location()) |
113 return false; | 112 return false; |
114 if (first.touch_id() != second.touch_id()) | 113 if (first.touch_id() != second.touch_id()) |
115 return false; | 114 return false; |
116 if (second.time_stamp().InSeconds() != first.time_stamp().InSeconds()) | 115 if (second.time_stamp() != first.time_stamp()) |
117 return false; | 116 return false; |
118 return true; | 117 return true; |
119 } | 118 } |
120 | 119 |
121 bool EventListIsSubset(const ScopedVector<ui::TouchEvent>& subset, | 120 bool EventListIsSubset(const ScopedVector<ui::TouchEvent>& subset, |
122 const ScopedVector<ui::TouchEvent>& set) { | 121 const ScopedVector<ui::TouchEvent>& set) { |
123 if (subset.size() > set.size()) | 122 if (subset.size() > set.size()) |
124 return false; | 123 return false; |
125 for (size_t i = 0; i < subset.size(); ++i) { | 124 for (size_t i = 0; i < subset.size(); ++i) { |
126 const ui::TouchEvent* first = subset[i]; | 125 const ui::TouchEvent* first = subset[i]; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 scale, anchor_x, anchor_y, modifiers, source_device)); | 257 scale, anchor_x, anchor_y, modifiers, source_device)); |
259 } | 258 } |
260 | 259 |
261 void SimulateGestureFlingStartEvent(float velocity_x, | 260 void SimulateGestureFlingStartEvent(float velocity_x, |
262 float velocity_y, | 261 float velocity_y, |
263 WebGestureDevice source_device) { | 262 WebGestureDevice source_device) { |
264 SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildFling( | 263 SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildFling( |
265 velocity_x, velocity_y, source_device)); | 264 velocity_x, velocity_y, source_device)); |
266 } | 265 } |
267 | 266 |
268 void SetTouchTimestamp(base::TimeDelta timestamp) { | 267 void SetTouchTimestamp(base::TimeTicks timestamp) { |
269 touch_event_.SetTimestamp(timestamp); | 268 touch_event_.SetTimestamp(timestamp); |
270 } | 269 } |
271 | 270 |
272 uint32_t SendTouchEvent() { | 271 uint32_t SendTouchEvent() { |
273 uint32_t touch_event_id = touch_event_.uniqueTouchEventId; | 272 uint32_t touch_event_id = touch_event_.uniqueTouchEventId; |
274 input_router_->SendTouchEvent(TouchEventWithLatencyInfo(touch_event_)); | 273 input_router_->SendTouchEvent(TouchEventWithLatencyInfo(touch_event_)); |
275 touch_event_.ResetPoints(); | 274 touch_event_.ResetPoints(); |
276 return touch_event_id; | 275 return touch_event_id; |
277 } | 276 } |
278 | 277 |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 TEST_F(InputRouterImplTest, AckedTouchEventState) { | 861 TEST_F(InputRouterImplTest, AckedTouchEventState) { |
863 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); | 862 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); |
864 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 863 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
865 EXPECT_TRUE(TouchEventQueueEmpty()); | 864 EXPECT_TRUE(TouchEventQueueEmpty()); |
866 | 865 |
867 // Send a bunch of events, and make sure the ACKed events are correct. | 866 // Send a bunch of events, and make sure the ACKed events are correct. |
868 ScopedVector<ui::TouchEvent> expected_events; | 867 ScopedVector<ui::TouchEvent> expected_events; |
869 | 868 |
870 // Use a custom timestamp for all the events to test that the acked events | 869 // Use a custom timestamp for all the events to test that the acked events |
871 // have the same timestamp; | 870 // have the same timestamp; |
872 base::TimeDelta timestamp = base::Time::NowFromSystemTime() - base::Time(); | 871 base::TimeTicks timestamp = base::TimeTicks::Now(); |
873 timestamp -= base::TimeDelta::FromSeconds(600); | 872 timestamp -= base::TimeDelta::FromSeconds(600); |
874 | 873 |
875 // Press the first finger. | 874 // Press the first finger. |
876 PressTouchPoint(1, 1); | 875 PressTouchPoint(1, 1); |
877 SetTouchTimestamp(timestamp); | 876 SetTouchTimestamp(timestamp); |
878 uint32_t touch_press_event_id1 = SendTouchEvent(); | 877 uint32_t touch_press_event_id1 = SendTouchEvent(); |
879 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 878 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
880 expected_events.push_back( | 879 expected_events.push_back( |
881 new ui::TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(1, 1), 0, timestamp)); | 880 new ui::TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(1, 1), 0, timestamp)); |
882 | 881 |
(...skipping 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2326 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); | 2325 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); |
2327 | 2326 |
2328 const WebGestureEvent* filter_event = | 2327 const WebGestureEvent* filter_event = |
2329 GetFilterWebInputEvent<WebGestureEvent>(); | 2328 GetFilterWebInputEvent<WebGestureEvent>(); |
2330 TestLocationInFilterEvent(filter_event, orig); | 2329 TestLocationInFilterEvent(filter_event, orig); |
2331 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); | 2330 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); |
2332 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); | 2331 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); |
2333 } | 2332 } |
2334 | 2333 |
2335 } // namespace content | 2334 } // namespace content |
OLD | NEW |