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

Side by Side Diff: ui/touch_selection/touch_handle_unittest.cc

Issue 481683003: Support for Adaptive Handle Orientation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unittests Created 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/touch_selection/touch_handle.h" 5 #include "ui/touch_selection/touch_handle.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/events/test/motion_event_test_utils.h" 8 #include "ui/events/test/motion_event_test_utils.h"
9 #include "ui/gfx/geometry/rect_f.h" 9 #include "ui/gfx/geometry/rect_f.h"
10 #include "ui/touch_selection/touch_handle_orientation.h" 10 #include "ui/touch_selection/touch_handle_orientation.h"
11 11
12 using ui::test::MockMotionEvent; 12 using ui::test::MockMotionEvent;
13 13
14 namespace ui { 14 namespace ui {
15 namespace { 15 namespace {
16 16
17 const int kDefaultTapTimeoutMs = 200; 17 const int kDefaultTapTimeoutMs = 200;
18 const float kDefaultTapSlop = 10.f; 18 const float kDefaultTapSlop = 10.f;
19 const float kDefaultDrawableSize = 10.f; 19 const float kDefaultDrawableSize = 10.f;
20 const gfx::RectF kDefaultViewportRect(0, 0, 560, 1200);
20 21
21 struct MockDrawableData { 22 struct MockDrawableData {
22 MockDrawableData() 23 MockDrawableData()
23 : orientation(TouchHandleOrientation::UNDEFINED), 24 : orientation(TouchHandleOrientation::UNDEFINED),
24 alpha(0.f), 25 alpha(0.f),
25 enabled(false), 26 enabled(false),
26 visible(false), 27 visible(false),
27 rect(0, 0, kDefaultDrawableSize, kDefaultDrawableSize) {} 28 rect(0, 0, kDefaultDrawableSize, kDefaultDrawableSize) {}
28 TouchHandleOrientation orientation; 29 TouchHandleOrientation orientation;
29 float alpha; 30 float alpha;
31 bool mirror_horizontal;
32 bool mirror_vertical;
30 bool enabled; 33 bool enabled;
31 bool visible; 34 bool visible;
32 gfx::RectF rect; 35 gfx::RectF rect;
33 }; 36 };
34 37
35 class MockTouchHandleDrawable : public TouchHandleDrawable { 38 class MockTouchHandleDrawable : public TouchHandleDrawable {
36 public: 39 public:
37 explicit MockTouchHandleDrawable(MockDrawableData* data) : data_(data) {} 40 explicit MockTouchHandleDrawable(MockDrawableData* data) : data_(data) {}
38 ~MockTouchHandleDrawable() override {} 41 ~MockTouchHandleDrawable() override {}
39 42
40 void SetEnabled(bool enabled) override { data_->enabled = enabled; } 43 void SetEnabled(bool enabled) override { data_->enabled = enabled; }
41 44
42 void SetOrientation(TouchHandleOrientation orientation) override { 45 void SetLayout(const gfx::PointF& position,
46 TouchHandleOrientation orientation,
47 bool mirror_vertical,
48 bool mirror_horizontal) override {
49 data_->rect.set_origin(position);
43 data_->orientation = orientation; 50 data_->orientation = orientation;
51 data_->mirror_horizontal = mirror_horizontal;
52 data_->mirror_vertical = mirror_vertical;
44 } 53 }
45 54
46 void SetAlpha(float alpha) override { 55 void SetAlpha(float alpha) override {
47 data_->alpha = alpha; 56 data_->alpha = alpha;
48 data_->visible = alpha > 0; 57 data_->visible = alpha > 0;
49 } 58 }
50 59
51 void SetFocus(const gfx::PointF& position) override { 60 gfx::SizeF GetDrawablePadding() const override { return gfx::SizeF(); }
mfomitchev 2015/06/18 16:16:31 Once we have the implementation nailed down, we sh
AviD 2015/06/19 07:20:47 Acknowledged.
52 // Anchor focus to the top left of the rect (regardless of orientation).
53 data_->rect.set_origin(position);
54 }
55 61
56 gfx::RectF GetVisibleBounds() const override { 62 gfx::RectF GetVisibleBounds() const override {
57 return data_->rect; 63 return data_->rect;
58 } 64 }
59 65
60 private: 66 private:
61 MockDrawableData* data_; 67 MockDrawableData* data_;
62 }; 68 };
63 69
64 } // namespace 70 } // namespace
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 gfx::PointF drag_position_; 143 gfx::PointF drag_position_;
138 bool dragging_; 144 bool dragging_;
139 bool dragged_; 145 bool dragged_;
140 bool tapped_; 146 bool tapped_;
141 bool needs_animate_; 147 bool needs_animate_;
142 148
143 MockDrawableData drawable_data_; 149 MockDrawableData drawable_data_;
144 }; 150 };
145 151
146 TEST_F(TouchHandleTest, Visibility) { 152 TEST_F(TouchHandleTest, Visibility) {
147 TouchHandle handle(this, TouchHandleOrientation::CENTER); 153 TouchHandle handle(this, TouchHandleOrientation::CENTER,
154 kDefaultViewportRect);
148 EXPECT_FALSE(drawable().visible); 155 EXPECT_FALSE(drawable().visible);
149 156
150 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); 157 handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
151 EXPECT_TRUE(drawable().visible); 158 EXPECT_TRUE(drawable().visible);
152 EXPECT_EQ(1.f, drawable().alpha); 159 EXPECT_EQ(1.f, drawable().alpha);
153 160
154 handle.SetVisible(false, TouchHandle::ANIMATION_NONE); 161 handle.SetVisible(false, TouchHandle::ANIMATION_NONE);
155 EXPECT_FALSE(drawable().visible); 162 EXPECT_FALSE(drawable().visible);
156 163
157 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); 164 handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
158 EXPECT_TRUE(drawable().visible); 165 EXPECT_TRUE(drawable().visible);
159 EXPECT_EQ(1.f, drawable().alpha); 166 EXPECT_EQ(1.f, drawable().alpha);
160 } 167 }
161 168
162 TEST_F(TouchHandleTest, VisibilityAnimation) { 169 TEST_F(TouchHandleTest, VisibilityAnimation) {
163 TouchHandle handle(this, TouchHandleOrientation::CENTER); 170 TouchHandle handle(this, TouchHandleOrientation::CENTER,
171 kDefaultViewportRect);
164 ASSERT_FALSE(NeedsAnimate()); 172 ASSERT_FALSE(NeedsAnimate());
165 ASSERT_FALSE(drawable().visible); 173 ASSERT_FALSE(drawable().visible);
166 ASSERT_EQ(0.f, drawable().alpha); 174 ASSERT_EQ(0.f, drawable().alpha);
167 175
168 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH); 176 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH);
169 EXPECT_TRUE(NeedsAnimate()); 177 EXPECT_TRUE(NeedsAnimate());
170 EXPECT_FALSE(drawable().visible); 178 EXPECT_FALSE(drawable().visible);
171 EXPECT_EQ(0.f, drawable().alpha); 179 EXPECT_EQ(0.f, drawable().alpha);
172 180
173 Animate(handle); 181 Animate(handle);
(...skipping 15 matching lines...) Expand all
189 EXPECT_FALSE(GetAndResetNeedsAnimate()); 197 EXPECT_FALSE(GetAndResetNeedsAnimate());
190 handle.SetVisible(false, TouchHandle::ANIMATION_SMOOTH); 198 handle.SetVisible(false, TouchHandle::ANIMATION_SMOOTH);
191 EXPECT_EQ(1.f, drawable().alpha); 199 EXPECT_EQ(1.f, drawable().alpha);
192 EXPECT_TRUE(GetAndResetNeedsAnimate()); 200 EXPECT_TRUE(GetAndResetNeedsAnimate());
193 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH); 201 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH);
194 EXPECT_EQ(1.f, drawable().alpha); 202 EXPECT_EQ(1.f, drawable().alpha);
195 EXPECT_FALSE(GetAndResetNeedsAnimate()); 203 EXPECT_FALSE(GetAndResetNeedsAnimate());
196 } 204 }
197 205
198 TEST_F(TouchHandleTest, Orientation) { 206 TEST_F(TouchHandleTest, Orientation) {
199 TouchHandle handle(this, TouchHandleOrientation::CENTER); 207 TouchHandle handle(this, TouchHandleOrientation::CENTER,
208 kDefaultViewportRect);
200 EXPECT_EQ(TouchHandleOrientation::CENTER, drawable().orientation); 209 EXPECT_EQ(TouchHandleOrientation::CENTER, drawable().orientation);
201 210
211 handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
202 handle.SetOrientation(TouchHandleOrientation::LEFT); 212 handle.SetOrientation(TouchHandleOrientation::LEFT);
203 EXPECT_EQ(TouchHandleOrientation::LEFT, drawable().orientation); 213 EXPECT_EQ(TouchHandleOrientation::LEFT, drawable().orientation);
204 214
205 handle.SetOrientation(TouchHandleOrientation::RIGHT); 215 handle.SetOrientation(TouchHandleOrientation::RIGHT);
206 EXPECT_EQ(TouchHandleOrientation::RIGHT, drawable().orientation); 216 EXPECT_EQ(TouchHandleOrientation::RIGHT, drawable().orientation);
207 217
208 handle.SetOrientation(TouchHandleOrientation::CENTER); 218 handle.SetOrientation(TouchHandleOrientation::CENTER);
209 EXPECT_EQ(TouchHandleOrientation::CENTER, drawable().orientation); 219 EXPECT_EQ(TouchHandleOrientation::CENTER, drawable().orientation);
210 } 220 }
211 221
212 TEST_F(TouchHandleTest, Position) { 222 TEST_F(TouchHandleTest, Position) {
213 TouchHandle handle(this, TouchHandleOrientation::CENTER); 223 TouchHandle handle(this, TouchHandleOrientation::CENTER,
224 kDefaultViewportRect);
214 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); 225 handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
215 226
216 gfx::PointF position; 227 gfx::PointF focus_top;
228 gfx::PointF focus_bottom;
217 EXPECT_EQ(gfx::PointF(), drawable().rect.origin()); 229 EXPECT_EQ(gfx::PointF(), drawable().rect.origin());
218 230
219 position = gfx::PointF(7.3f, -3.7f); 231 focus_top = gfx::PointF(7.3f, -3.7f);
220 handle.SetPosition(position); 232 focus_bottom = gfx::PointF(7.3f, -2.7f);
221 EXPECT_EQ(position, drawable().rect.origin()); 233 handle.SetFocus(focus_top, focus_bottom);
234 EXPECT_EQ(focus_bottom, drawable().rect.origin());
222 235
223 position = gfx::PointF(-7.3f, 3.7f); 236 focus_top = gfx::PointF(-7.3f, 3.7f);
224 handle.SetPosition(position); 237 focus_bottom = gfx::PointF(-7.3f, 4.7f);
225 EXPECT_EQ(position, drawable().rect.origin()); 238 handle.SetFocus(focus_top, focus_bottom);
239 EXPECT_EQ(focus_bottom, drawable().rect.origin());
226 } 240 }
227 241
228 TEST_F(TouchHandleTest, PositionNotUpdatedWhileFadingOrInvisible) { 242 TEST_F(TouchHandleTest, PositionNotUpdatedWhileFadingOrInvisible) {
229 TouchHandle handle(this, TouchHandleOrientation::CENTER); 243 TouchHandle handle(this, TouchHandleOrientation::CENTER,
244 kDefaultViewportRect);
230 245
231 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); 246 handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
232 ASSERT_TRUE(drawable().visible); 247 ASSERT_TRUE(drawable().visible);
233 ASSERT_FALSE(NeedsAnimate()); 248 ASSERT_FALSE(NeedsAnimate());
234 249
235 gfx::PointF old_position(7.3f, -3.7f); 250 gfx::PointF old_focus_top(7.3f, -3.7f);
236 handle.SetPosition(old_position); 251 gfx::PointF old_focus_bottom(7.3f, -2.7f);
237 ASSERT_EQ(old_position, drawable().rect.origin()); 252 handle.SetFocus(old_focus_top, old_focus_bottom);
253 ASSERT_EQ(old_focus_bottom, drawable().rect.origin());
238 254
239 handle.SetVisible(false, TouchHandle::ANIMATION_SMOOTH); 255 handle.SetVisible(false, TouchHandle::ANIMATION_SMOOTH);
240 ASSERT_TRUE(NeedsAnimate()); 256 ASSERT_TRUE(NeedsAnimate());
241 257
242 gfx::PointF new_position(3.7f, -3.7f); 258 gfx::PointF new_position_top(3.7f, -3.7f);
243 handle.SetPosition(new_position); 259 gfx::PointF new_position_bottom(3.7f, -2.7f);
244 EXPECT_EQ(old_position, drawable().rect.origin()); 260 handle.SetFocus(new_position_top, new_position_bottom);
261 EXPECT_EQ(old_focus_bottom, drawable().rect.origin());
245 EXPECT_TRUE(NeedsAnimate()); 262 EXPECT_TRUE(NeedsAnimate());
246 263
247 // While the handle is fading, the new position should not take affect. 264 // While the handle is fading, the new position should not take affect.
248 base::TimeTicks now = base::TimeTicks::Now(); 265 base::TimeTicks now = base::TimeTicks::Now();
249 while (handle.Animate(now)) { 266 while (handle.Animate(now)) {
250 EXPECT_EQ(old_position, drawable().rect.origin()); 267 EXPECT_EQ(old_focus_bottom, drawable().rect.origin());
251 now += base::TimeDelta::FromMilliseconds(16); 268 now += base::TimeDelta::FromMilliseconds(16);
252 } 269 }
253 270
254 // Even after the animation terminates, the new position will not be pushed. 271 // Even after the animation terminates, the new position will not be pushed.
255 EXPECT_EQ(old_position, drawable().rect.origin()); 272 EXPECT_EQ(old_focus_bottom, drawable().rect.origin());
256 273
257 // As soon as the handle becomes visible, the new position will be pushed. 274 // As soon as the handle becomes visible, the new position will be pushed.
258 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH); 275 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH);
259 EXPECT_EQ(new_position, drawable().rect.origin()); 276 EXPECT_EQ(new_position_bottom, drawable().rect.origin());
260 } 277 }
261 278
262 TEST_F(TouchHandleTest, Enabled) { 279 TEST_F(TouchHandleTest, Enabled) {
263 // A newly created handle defaults to enabled. 280 // A newly created handle defaults to enabled.
264 TouchHandle handle(this, TouchHandleOrientation::CENTER); 281 TouchHandle handle(this, TouchHandleOrientation::CENTER,
282 kDefaultViewportRect);
265 EXPECT_TRUE(drawable().enabled); 283 EXPECT_TRUE(drawable().enabled);
266 284
267 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH); 285 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH);
268 EXPECT_TRUE(GetAndResetNeedsAnimate()); 286 EXPECT_TRUE(GetAndResetNeedsAnimate());
269 EXPECT_EQ(0.f, drawable().alpha); 287 EXPECT_EQ(0.f, drawable().alpha);
270 handle.SetEnabled(false); 288 handle.SetEnabled(false);
271 EXPECT_FALSE(drawable().enabled); 289 EXPECT_FALSE(drawable().enabled);
272 290
273 // Dragging should not be allowed while the handle is disabled. 291 // Dragging should not be allowed while the handle is disabled.
274 base::TimeTicks event_time = base::TimeTicks::Now(); 292 base::TimeTicks event_time = base::TimeTicks::Now();
(...skipping 16 matching lines...) Expand all
291 handle.SetEnabled(true); 309 handle.SetEnabled(true);
292 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); 310 handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
293 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 311 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
294 EXPECT_TRUE(IsDragging()); 312 EXPECT_TRUE(IsDragging());
295 handle.SetEnabled(false); 313 handle.SetEnabled(false);
296 EXPECT_FALSE(IsDragging()); 314 EXPECT_FALSE(IsDragging());
297 EXPECT_FALSE(handle.WillHandleTouchEvent(event)); 315 EXPECT_FALSE(handle.WillHandleTouchEvent(event));
298 } 316 }
299 317
300 TEST_F(TouchHandleTest, Drag) { 318 TEST_F(TouchHandleTest, Drag) {
301 TouchHandle handle(this, TouchHandleOrientation::CENTER); 319 TouchHandle handle(this, TouchHandleOrientation::CENTER,
320 kDefaultViewportRect);
302 321
303 base::TimeTicks event_time = base::TimeTicks::Now(); 322 base::TimeTicks event_time = base::TimeTicks::Now();
304 const float kOffset = kDefaultDrawableSize / 2.f; 323 const float kOffset = kDefaultDrawableSize / 2.f;
305 324
306 // The handle must be visible to trigger drag. 325 // The handle must be visible to trigger drag.
307 MockMotionEvent event( 326 MockMotionEvent event(
308 MockMotionEvent::ACTION_DOWN, event_time, kOffset, kOffset); 327 MockMotionEvent::ACTION_DOWN, event_time, kOffset, kOffset);
309 EXPECT_FALSE(handle.WillHandleTouchEvent(event)); 328 EXPECT_FALSE(handle.WillHandleTouchEvent(event));
310 EXPECT_FALSE(IsDragging()); 329 EXPECT_FALSE(IsDragging());
311 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); 330 handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 364 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
346 EXPECT_FALSE(GetAndResetHandleDragged()); 365 EXPECT_FALSE(GetAndResetHandleDragged());
347 EXPECT_FALSE(IsDragging()); 366 EXPECT_FALSE(IsDragging());
348 367
349 // Non-ACTION_DOWN events after the drag has terminated should not be handled. 368 // Non-ACTION_DOWN events after the drag has terminated should not be handled.
350 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL); 369 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL);
351 EXPECT_FALSE(handle.WillHandleTouchEvent(event)); 370 EXPECT_FALSE(handle.WillHandleTouchEvent(event));
352 } 371 }
353 372
354 TEST_F(TouchHandleTest, DragDefersOrientationChange) { 373 TEST_F(TouchHandleTest, DragDefersOrientationChange) {
355 TouchHandle handle(this, TouchHandleOrientation::RIGHT); 374 TouchHandle handle(this, TouchHandleOrientation::RIGHT, kDefaultViewportRect);
356 ASSERT_EQ(drawable().orientation, TouchHandleOrientation::RIGHT); 375 ASSERT_EQ(drawable().orientation, TouchHandleOrientation::RIGHT);
357 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); 376 handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
358 377
359 MockMotionEvent event(MockMotionEvent::ACTION_DOWN); 378 MockMotionEvent event(MockMotionEvent::ACTION_DOWN);
360 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 379 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
361 EXPECT_TRUE(IsDragging()); 380 EXPECT_TRUE(IsDragging());
362 381
363 // Orientation changes will be deferred until the drag ends. 382 // Orientation changes will be deferred until the drag ends.
364 handle.SetOrientation(TouchHandleOrientation::LEFT); 383 handle.SetOrientation(TouchHandleOrientation::LEFT);
365 EXPECT_EQ(TouchHandleOrientation::RIGHT, drawable().orientation); 384 EXPECT_EQ(TouchHandleOrientation::RIGHT, drawable().orientation);
366 385
367 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE); 386 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE);
368 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 387 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
369 EXPECT_TRUE(GetAndResetHandleDragged()); 388 EXPECT_TRUE(GetAndResetHandleDragged());
370 EXPECT_TRUE(IsDragging()); 389 EXPECT_TRUE(IsDragging());
371 EXPECT_EQ(TouchHandleOrientation::RIGHT, drawable().orientation); 390 EXPECT_EQ(TouchHandleOrientation::RIGHT, drawable().orientation);
372 391
373 event = MockMotionEvent(MockMotionEvent::ACTION_UP); 392 event = MockMotionEvent(MockMotionEvent::ACTION_UP);
374 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 393 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
375 EXPECT_FALSE(GetAndResetHandleDragged()); 394 EXPECT_FALSE(GetAndResetHandleDragged());
376 EXPECT_FALSE(IsDragging()); 395 EXPECT_FALSE(IsDragging());
377 EXPECT_EQ(TouchHandleOrientation::LEFT, drawable().orientation); 396 EXPECT_EQ(TouchHandleOrientation::LEFT, drawable().orientation);
378 } 397 }
379 398
380 TEST_F(TouchHandleTest, DragDefersFade) { 399 TEST_F(TouchHandleTest, DragDefersFade) {
381 TouchHandle handle(this, TouchHandleOrientation::CENTER); 400 TouchHandle handle(this, TouchHandleOrientation::CENTER,
401 kDefaultViewportRect);
382 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); 402 handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
383 403
384 MockMotionEvent event(MockMotionEvent::ACTION_DOWN); 404 MockMotionEvent event(MockMotionEvent::ACTION_DOWN);
385 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 405 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
386 EXPECT_TRUE(IsDragging()); 406 EXPECT_TRUE(IsDragging());
387 407
388 // Fade will be deferred until the drag ends. 408 // Fade will be deferred until the drag ends.
389 handle.SetVisible(false, TouchHandle::ANIMATION_SMOOTH); 409 handle.SetVisible(false, TouchHandle::ANIMATION_SMOOTH);
390 EXPECT_FALSE(NeedsAnimate()); 410 EXPECT_FALSE(NeedsAnimate());
391 EXPECT_TRUE(drawable().visible); 411 EXPECT_TRUE(drawable().visible);
392 EXPECT_EQ(1.f, drawable().alpha); 412 EXPECT_EQ(1.f, drawable().alpha);
393 413
394 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE); 414 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE);
395 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 415 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
396 EXPECT_FALSE(NeedsAnimate()); 416 EXPECT_FALSE(NeedsAnimate());
397 EXPECT_TRUE(drawable().visible); 417 EXPECT_TRUE(drawable().visible);
398 418
399 event = MockMotionEvent(MockMotionEvent::ACTION_UP); 419 event = MockMotionEvent(MockMotionEvent::ACTION_UP);
400 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 420 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
401 EXPECT_FALSE(IsDragging()); 421 EXPECT_FALSE(IsDragging());
402 EXPECT_TRUE(NeedsAnimate()); 422 EXPECT_TRUE(NeedsAnimate());
403 423
404 Animate(handle); 424 Animate(handle);
405 EXPECT_FALSE(drawable().visible); 425 EXPECT_FALSE(drawable().visible);
406 EXPECT_EQ(0.f, drawable().alpha); 426 EXPECT_EQ(0.f, drawable().alpha);
407 } 427 }
408 428
409 TEST_F(TouchHandleTest, DragTargettingUsesTouchSize) { 429 TEST_F(TouchHandleTest, DragTargettingUsesTouchSize) {
410 TouchHandle handle(this, TouchHandleOrientation::CENTER); 430 TouchHandle handle(this, TouchHandleOrientation::CENTER,
431 kDefaultViewportRect);
411 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); 432 handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
412 433
413 base::TimeTicks event_time = base::TimeTicks::Now(); 434 base::TimeTicks event_time = base::TimeTicks::Now();
414 const float kTouchSize = 24.f; 435 const float kTouchSize = 24.f;
415 const float kOffset = kDefaultDrawableSize + kTouchSize / 2.001f; 436 const float kOffset = kDefaultDrawableSize + kTouchSize / 2.001f;
416 437
417 MockMotionEvent event( 438 MockMotionEvent event(
418 MockMotionEvent::ACTION_DOWN, event_time, kOffset, 0); 439 MockMotionEvent::ACTION_DOWN, event_time, kOffset, 0);
419 event.SetTouchMajor(0.f); 440 event.SetTouchMajor(0.f);
420 EXPECT_FALSE(handle.WillHandleTouchEvent(event)); 441 EXPECT_FALSE(handle.WillHandleTouchEvent(event));
(...skipping 30 matching lines...) Expand all
451 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, 472 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN,
452 event_time, 473 event_time,
453 kDefaultDrawableSize / 2.f, 474 kDefaultDrawableSize / 2.f,
454 kDefaultDrawableSize / 2.f); 475 kDefaultDrawableSize / 2.f);
455 event.SetTouchMajor(0); 476 event.SetTouchMajor(0);
456 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 477 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
457 EXPECT_TRUE(IsDragging()); 478 EXPECT_TRUE(IsDragging());
458 } 479 }
459 480
460 TEST_F(TouchHandleTest, Tap) { 481 TEST_F(TouchHandleTest, Tap) {
461 TouchHandle handle(this, TouchHandleOrientation::CENTER); 482 TouchHandle handle(this, TouchHandleOrientation::CENTER,
483 kDefaultViewportRect);
462 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); 484 handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
463 485
464 base::TimeTicks event_time = base::TimeTicks::Now(); 486 base::TimeTicks event_time = base::TimeTicks::Now();
465 487
466 // ACTION_CANCEL shouldn't trigger a tap. 488 // ACTION_CANCEL shouldn't trigger a tap.
467 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); 489 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
468 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 490 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
469 event_time += base::TimeDelta::FromMilliseconds(50); 491 event_time += base::TimeDelta::FromMilliseconds(50);
470 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); 492 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0);
471 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 493 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
(...skipping 25 matching lines...) Expand all
497 event_time += GetTapTimeout() / 2; 519 event_time += GetTapTimeout() / 2;
498 event = MockMotionEvent( 520 event = MockMotionEvent(
499 MockMotionEvent::ACTION_MOVE, event_time, kDefaultTapSlop * 2.f, 0); 521 MockMotionEvent::ACTION_MOVE, event_time, kDefaultTapSlop * 2.f, 0);
500 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 522 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
501 event = MockMotionEvent( 523 event = MockMotionEvent(
502 MockMotionEvent::ACTION_UP, event_time, kDefaultTapSlop * 2.f, 0); 524 MockMotionEvent::ACTION_UP, event_time, kDefaultTapSlop * 2.f, 0);
503 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 525 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
504 EXPECT_FALSE(GetAndResetHandleTapped()); 526 EXPECT_FALSE(GetAndResetHandleTapped());
505 } 527 }
506 528
529 TEST_F(TouchHandleTest, MirrorFocusChange) {
530 TouchHandle handle(this, TouchHandleOrientation::LEFT, kDefaultViewportRect);
531 handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
532
533 gfx::PointF focus_top;
534 gfx::PointF focus_bottom;
535 EXPECT_EQ(gfx::PointF(), drawable().rect.origin());
536
537 // Moving the selection to the bottom of the screen
538 // should mirror the handle vertically.
539 focus_top = gfx::PointF(17.3f, 1199.0f);
540 focus_bottom = gfx::PointF(17.3f, 1200.0f);
541 handle.SetFocus(focus_top, focus_bottom);
542 EXPECT_TRUE(drawable().mirror_vertical);
543 EXPECT_FALSE(drawable().mirror_horizontal);
544
545 // Moving the left handle to the left edge of the viewport
546 // should mirror the handle horizontally as well.
547 focus_top = gfx::PointF(2.3f, 1199.0f);
548 focus_bottom = gfx::PointF(2.3f, 1200.0f);
549 handle.SetFocus(focus_top, focus_bottom);
550 EXPECT_TRUE(drawable().mirror_vertical);
551 EXPECT_TRUE(drawable().mirror_horizontal);
552
553 // When the selection is not at the bottom, only the
554 // horizontal mirror flag should be true.
555 focus_top = gfx::PointF(2.3f, 7.3f);
556 focus_bottom = gfx::PointF(2.3f, 8.3f);
557 handle.SetFocus(focus_top, focus_bottom);
558 EXPECT_FALSE(drawable().mirror_vertical);
559 EXPECT_TRUE(drawable().mirror_horizontal);
560
561 // When selection handles intersects the viewport fully,
562 // both mirror values should be false.
563 focus_top = gfx::PointF(23.3f, 7.3f);
564 focus_bottom = gfx::PointF(23.3f, 8.3f);
565 handle.SetFocus(focus_top, focus_bottom);
566 EXPECT_FALSE(drawable().mirror_vertical);
567 EXPECT_FALSE(drawable().mirror_horizontal);
568
569 // Horizontal mirror should be true for Right handle when
570 // the handle is at theright edge of the viewport.
571 handle.SetOrientation(TouchHandleOrientation::RIGHT);
572 focus_top = gfx::PointF(560.0f, 7.3f);
573 focus_bottom = gfx::PointF(560.0f, 8.3f);
574 handle.SetFocus(focus_top, focus_bottom);
575 EXPECT_FALSE(drawable().mirror_vertical);
576 EXPECT_TRUE(drawable().mirror_horizontal);
577 }
578
579 TEST_F(TouchHandleTest, DragDefersMirrorChange) {
580 TouchHandle handle(this, TouchHandleOrientation::RIGHT, kDefaultViewportRect);
581 ASSERT_EQ(drawable().orientation, TouchHandleOrientation::RIGHT);
582 handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
583
584 base::TimeTicks event_time = base::TimeTicks::Now();
585 const float kOffset = kDefaultDrawableSize / 2.f;
586
587 // Start the drag.
588 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, kOffset,
589 kOffset);
590 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
591 EXPECT_TRUE(IsDragging());
592
593 handle.SetOrientation(TouchHandleOrientation::LEFT);
594 gfx::PointF focus_top(17.3f, 1199.0f);
595 gfx::PointF focus_bottom(17.3f, 1200.0f);
596 handle.SetFocus(focus_top, focus_bottom);
597 EXPECT_FALSE(drawable().mirror_vertical);
598 EXPECT_FALSE(drawable().mirror_horizontal);
599
600 // Mirror flag changes will be deferred until the drag ends.
601 event = MockMotionEvent(MockMotionEvent::ACTION_UP);
602 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
603 EXPECT_FALSE(GetAndResetHandleDragged());
604 EXPECT_FALSE(IsDragging());
605 EXPECT_TRUE(drawable().mirror_vertical);
606 EXPECT_FALSE(drawable().mirror_horizontal);
607 }
608
609 TEST_F(TouchHandleTest, ViewportSizeChange) {
610 TouchHandle handle(this, TouchHandleOrientation::RIGHT, kDefaultViewportRect);
611 ASSERT_EQ(drawable().orientation, TouchHandleOrientation::RIGHT);
612 handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
613
614 gfx::PointF focus_top;
615 gfx::PointF focus_bottom;
616 EXPECT_EQ(gfx::PointF(), drawable().rect.origin());
617
618 focus_top = gfx::PointF(230.0f, 599.0f);
619 focus_bottom = gfx::PointF(230.0f, 600.0f);
620 handle.SetFocus(focus_top, focus_bottom);
621 EXPECT_FALSE(drawable().mirror_vertical);
622 EXPECT_FALSE(drawable().mirror_horizontal);
623
624 handle.SetViewportRect(gfx::RectF(0, 0, 560, 600));
625 EXPECT_TRUE(drawable().mirror_vertical);
626 EXPECT_FALSE(drawable().mirror_horizontal);
627
628 handle.SetViewportRect(gfx::RectF(0, 0, 230, 600));
629 EXPECT_TRUE(drawable().mirror_vertical);
630 EXPECT_TRUE(drawable().mirror_horizontal);
631
632 handle.SetViewportRect(kDefaultViewportRect);
633 EXPECT_FALSE(drawable().mirror_vertical);
634 EXPECT_FALSE(drawable().mirror_horizontal);
635 }
636
507 } // namespace ui 637 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698