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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 scroll_y_ = 0; | 131 scroll_y_ = 0; |
132 scroll_velocity_x_ = 0; | 132 scroll_velocity_x_ = 0; |
133 scroll_velocity_y_ = 0; | 133 scroll_velocity_y_ = 0; |
134 velocity_x_ = 0; | 134 velocity_x_ = 0; |
135 velocity_y_ = 0; | 135 velocity_y_ = 0; |
136 scroll_x_hint_ = 0; | 136 scroll_x_hint_ = 0; |
137 scroll_y_hint_ = 0; | 137 scroll_y_hint_ = 0; |
138 tap_count_ = 0; | 138 tap_count_ = 0; |
139 scale_ = 0; | 139 scale_ = 0; |
140 flags_ = 0; | 140 flags_ = 0; |
| 141 latency_info_.Clear(); |
141 } | 142 } |
142 | 143 |
143 const std::vector<ui::EventType>& events() const { return events_; }; | 144 const std::vector<ui::EventType>& events() const { return events_; }; |
144 | 145 |
145 bool tap() const { return tap_; } | 146 bool tap() const { return tap_; } |
146 bool tap_down() const { return tap_down_; } | 147 bool tap_down() const { return tap_down_; } |
147 bool tap_cancel() const { return tap_cancel_; } | 148 bool tap_cancel() const { return tap_cancel_; } |
148 bool begin() const { return begin_; } | 149 bool begin() const { return begin_; } |
149 bool end() const { return end_; } | 150 bool end() const { return end_; } |
150 bool scroll_begin() const { return scroll_begin_; } | 151 bool scroll_begin() const { return scroll_begin_; } |
(...skipping 29 matching lines...) Expand all Loading... |
180 float scroll_velocity_x() const { return scroll_velocity_x_; } | 181 float scroll_velocity_x() const { return scroll_velocity_x_; } |
181 float scroll_velocity_y() const { return scroll_velocity_y_; } | 182 float scroll_velocity_y() const { return scroll_velocity_y_; } |
182 float velocity_x() const { return velocity_x_; } | 183 float velocity_x() const { return velocity_x_; } |
183 float velocity_y() const { return velocity_y_; } | 184 float velocity_y() const { return velocity_y_; } |
184 float scroll_x_hint() const { return scroll_x_hint_; } | 185 float scroll_x_hint() const { return scroll_x_hint_; } |
185 float scroll_y_hint() const { return scroll_y_hint_; } | 186 float scroll_y_hint() const { return scroll_y_hint_; } |
186 float scale() const { return scale_; } | 187 float scale() const { return scale_; } |
187 const gfx::Rect& bounding_box() const { return bounding_box_; } | 188 const gfx::Rect& bounding_box() const { return bounding_box_; } |
188 int tap_count() const { return tap_count_; } | 189 int tap_count() const { return tap_count_; } |
189 int flags() const { return flags_; } | 190 int flags() const { return flags_; } |
| 191 const ui::LatencyInfo& latency_info() const { return latency_info_; } |
190 | 192 |
191 void WaitUntilReceivedGesture(ui::EventType type) { | 193 void WaitUntilReceivedGesture(ui::EventType type) { |
192 wait_until_event_ = type; | 194 wait_until_event_ = type; |
193 run_loop_.reset(new base::RunLoop()); | 195 run_loop_.reset(new base::RunLoop()); |
194 run_loop_->Run(); | 196 run_loop_->Run(); |
195 } | 197 } |
196 | 198 |
197 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE { | 199 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE { |
198 events_.push_back(gesture->type()); | 200 events_.push_back(gesture->type()); |
199 bounding_box_ = gesture->details().bounding_box(); | 201 bounding_box_ = gesture->details().bounding_box(); |
200 flags_ = gesture->flags(); | 202 flags_ = gesture->flags(); |
| 203 latency_info_ = *gesture->latency(); |
201 switch (gesture->type()) { | 204 switch (gesture->type()) { |
202 case ui::ET_GESTURE_TAP: | 205 case ui::ET_GESTURE_TAP: |
203 tap_location_ = gesture->location(); | 206 tap_location_ = gesture->location(); |
204 tap_count_ = gesture->details().tap_count(); | 207 tap_count_ = gesture->details().tap_count(); |
205 tap_ = true; | 208 tap_ = true; |
206 break; | 209 break; |
207 case ui::ET_GESTURE_TAP_DOWN: | 210 case ui::ET_GESTURE_TAP_DOWN: |
208 tap_down_ = true; | 211 tap_down_ = true; |
209 break; | 212 break; |
210 case ui::ET_GESTURE_TAP_CANCEL: | 213 case ui::ET_GESTURE_TAP_CANCEL: |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 float scroll_velocity_x_; | 318 float scroll_velocity_x_; |
316 float scroll_velocity_y_; | 319 float scroll_velocity_y_; |
317 float velocity_x_; | 320 float velocity_x_; |
318 float velocity_y_; | 321 float velocity_y_; |
319 float scroll_x_hint_; | 322 float scroll_x_hint_; |
320 float scroll_y_hint_; | 323 float scroll_y_hint_; |
321 float scale_; | 324 float scale_; |
322 gfx::Rect bounding_box_; | 325 gfx::Rect bounding_box_; |
323 int tap_count_; | 326 int tap_count_; |
324 int flags_; | 327 int flags_; |
| 328 ui::LatencyInfo latency_info_; |
325 | 329 |
326 ui::EventType wait_until_event_; | 330 ui::EventType wait_until_event_; |
327 | 331 |
328 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); | 332 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); |
329 }; | 333 }; |
330 | 334 |
331 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { | 335 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { |
332 public: | 336 public: |
333 explicit QueueTouchEventDelegate(WindowEventDispatcher* dispatcher) | 337 explicit QueueTouchEventDelegate(WindowEventDispatcher* dispatcher) |
334 : window_(NULL), | 338 : window_(NULL), |
(...skipping 3928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4263 int default_flags = delegate->flags(); | 4267 int default_flags = delegate->flags(); |
4264 | 4268 |
4265 ui::TouchEvent move1( | 4269 ui::TouchEvent move1( |
4266 ui::ET_TOUCH_MOVED, gfx::Point(397, 149), kTouchId, tes.LeapForward(50)); | 4270 ui::ET_TOUCH_MOVED, gfx::Point(397, 149), kTouchId, tes.LeapForward(50)); |
4267 move1.set_flags(992); | 4271 move1.set_flags(992); |
4268 | 4272 |
4269 DispatchEventUsingWindowDispatcher(&move1); | 4273 DispatchEventUsingWindowDispatcher(&move1); |
4270 EXPECT_NE(default_flags, delegate->flags()); | 4274 EXPECT_NE(default_flags, delegate->flags()); |
4271 } | 4275 } |
4272 | 4276 |
| 4277 // Test that latency info is passed through to the gesture event. |
| 4278 TEST_P(GestureRecognizerTest, LatencyPassedFromTouchEvent) { |
| 4279 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 4280 new GestureEventConsumeDelegate()); |
| 4281 TimedEvents tes; |
| 4282 const int kWindowWidth = 123; |
| 4283 const int kWindowHeight = 45; |
| 4284 const int kTouchId = 6; |
| 4285 |
| 4286 const base::TimeTicks time_original = base::TimeTicks::FromInternalValue(100); |
| 4287 const base::TimeTicks time_ui = base::TimeTicks::FromInternalValue(200); |
| 4288 const base::TimeTicks time_acked = base::TimeTicks::FromInternalValue(300); |
| 4289 |
| 4290 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
| 4291 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 4292 delegate.get(), -1234, bounds, root_window())); |
| 4293 |
| 4294 delegate->Reset(); |
| 4295 |
| 4296 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
| 4297 kTouchId, tes.Now()); |
| 4298 |
| 4299 // Ensure the only components around are the ones we add. |
| 4300 press1.latency()->Clear(); |
| 4301 |
| 4302 press1.latency()->AddLatencyNumberWithTimestamp( |
| 4303 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, time_original, 1); |
| 4304 |
| 4305 press1.latency()->AddLatencyNumberWithTimestamp( |
| 4306 ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0, time_ui, 1); |
| 4307 |
| 4308 press1.latency()->AddLatencyNumberWithTimestamp( |
| 4309 ui::INPUT_EVENT_LATENCY_ACKED_TOUCH_COMPONENT, 0, 0, time_acked, 1); |
| 4310 |
| 4311 DispatchEventUsingWindowDispatcher(&press1); |
| 4312 EXPECT_TRUE(delegate->tap_down()); |
| 4313 |
| 4314 ui::LatencyInfo::LatencyComponent component; |
| 4315 |
| 4316 EXPECT_EQ(3U, delegate->latency_info().latency_components.size()); |
| 4317 ASSERT_TRUE(delegate->latency_info().FindLatency( |
| 4318 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, &component)); |
| 4319 EXPECT_EQ(time_original, component.event_time); |
| 4320 |
| 4321 ASSERT_TRUE(delegate->latency_info().FindLatency( |
| 4322 ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component)); |
| 4323 EXPECT_EQ(time_ui, component.event_time); |
| 4324 |
| 4325 ASSERT_TRUE(delegate->latency_info().FindLatency( |
| 4326 ui::INPUT_EVENT_LATENCY_ACKED_TOUCH_COMPONENT, 0, &component)); |
| 4327 EXPECT_EQ(time_acked, component.event_time); |
| 4328 |
| 4329 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS); |
| 4330 EXPECT_TRUE(delegate->show_press()); |
| 4331 EXPECT_EQ(0U, delegate->latency_info().latency_components.size()); |
| 4332 } |
| 4333 |
4273 INSTANTIATE_TEST_CASE_P(GestureRecognizer, | 4334 INSTANTIATE_TEST_CASE_P(GestureRecognizer, |
4274 GestureRecognizerTest, | 4335 GestureRecognizerTest, |
4275 ::testing::Bool()); | 4336 ::testing::Bool()); |
4276 | 4337 |
4277 } // namespace test | 4338 } // namespace test |
4278 } // namespace aura | 4339 } // namespace aura |
OLD | NEW |