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

Side by Side Diff: ui/aura/gestures/gesture_recognizer_unittest.cc

Issue 309823002: Pass ui::LatencyInfo correct with unified gesture detector on Aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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/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
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
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
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 3933 matching lines...) Expand 10 before | Expand all | Expand 10 after
4268 int default_flags = delegate->flags(); 4272 int default_flags = delegate->flags();
4269 4273
4270 ui::TouchEvent move1( 4274 ui::TouchEvent move1(
4271 ui::ET_TOUCH_MOVED, gfx::Point(397, 149), kTouchId, tes.LeapForward(50)); 4275 ui::ET_TOUCH_MOVED, gfx::Point(397, 149), kTouchId, tes.LeapForward(50));
4272 move1.set_flags(992); 4276 move1.set_flags(992);
4273 4277
4274 DispatchEventUsingWindowDispatcher(&move1); 4278 DispatchEventUsingWindowDispatcher(&move1);
4275 EXPECT_NE(default_flags, delegate->flags()); 4279 EXPECT_NE(default_flags, delegate->flags());
4276 } 4280 }
4277 4281
4282 // Test that latency info is passed through to the gesture event.
4283 TEST_P(GestureRecognizerTest, LatencyPassedFromTouchEvent) {
4284 scoped_ptr<GestureEventConsumeDelegate> delegate(
4285 new GestureEventConsumeDelegate());
4286 TimedEvents tes;
4287 const int kWindowWidth = 123;
4288 const int kWindowHeight = 45;
4289 const int kTouchId = 6;
4290
4291 const base::TimeTicks time_original = base::TimeTicks::FromInternalValue(100);
4292 const base::TimeTicks time_ui = base::TimeTicks::FromInternalValue(200);
4293 const base::TimeTicks time_acked = base::TimeTicks::FromInternalValue(300);
4294
4295 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
4296 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4297 delegate.get(), -1234, bounds, root_window()));
4298
4299 delegate->Reset();
4300
4301 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
4302 kTouchId, tes.Now());
4303
4304 // Ensure the only components around are the ones we add.
4305 press1.latency()->Clear();
4306
4307 press1.latency()->AddLatencyNumberWithTimestamp(
4308 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, time_original, 1);
4309
4310 press1.latency()->AddLatencyNumberWithTimestamp(
4311 ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0, time_ui, 1);
4312
4313 press1.latency()->AddLatencyNumberWithTimestamp(
4314 ui::INPUT_EVENT_LATENCY_ACKED_TOUCH_COMPONENT, 0, 0, time_acked, 1);
4315
4316 DispatchEventUsingWindowDispatcher(&press1);
4317 EXPECT_TRUE(delegate->tap_down());
4318
4319 ui::LatencyInfo::LatencyComponent component;
4320
4321 ASSERT_TRUE(delegate->latency_info().FindLatency(
4322 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, &component));
4323 EXPECT_EQ(time_original, component.event_time);
4324
4325 ASSERT_TRUE(delegate->latency_info().FindLatency(
4326 ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component));
4327 EXPECT_EQ(time_ui, component.event_time);
4328
4329 ASSERT_TRUE(delegate->latency_info().FindLatency(
4330 ui::INPUT_EVENT_LATENCY_ACKED_TOUCH_COMPONENT, 0, &component));
4331 EXPECT_EQ(time_acked, component.event_time);
4332 }
4333
4278 INSTANTIATE_TEST_CASE_P(GestureRecognizer, 4334 INSTANTIATE_TEST_CASE_P(GestureRecognizer,
4279 GestureRecognizerTest, 4335 GestureRecognizerTest,
4280 ::testing::Bool()); 4336 ::testing::Bool());
4281 4337
4282 } // namespace test 4338 } // namespace test
4283 } // namespace aura 4339 } // namespace aura
OLDNEW
« no previous file with comments | « no previous file | ui/events/gestures/gesture_provider_aura.h » ('j') | ui/events/gestures/gesture_provider_aura.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698