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