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

Side by Side Diff: ui/events/blink/blink_event_util_unittest.cc

Issue 2605193002: Fix mouse wheel over-scrolls when display is scaled and scroll is paginated (Closed)
Patch Set: Better function/variable names. Created 3 years, 10 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/events/blink/blink_event_util.h" 5 #include "ui/events/blink/blink_event_util.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/WebKit/public/platform/WebGestureEvent.h" 9 #include "third_party/WebKit/public/platform/WebGestureEvent.h"
10 #include "third_party/WebKit/public/platform/WebInputEvent.h" 10 #include "third_party/WebKit/public/platform/WebInputEvent.h"
(...skipping 10 matching lines...) Expand all
21 CreateWebGestureEvent(details, 21 CreateWebGestureEvent(details,
22 base::TimeTicks(), 22 base::TimeTicks(),
23 gfx::PointF(1.f, 1.f), 23 gfx::PointF(1.f, 1.f),
24 gfx::PointF(1.f, 1.f), 24 gfx::PointF(1.f, 1.f),
25 0, 25 0,
26 0U); 26 0U);
27 EXPECT_FALSE(ScaleWebInputEvent(event, 1.f)); 27 EXPECT_FALSE(ScaleWebInputEvent(event, 1.f));
28 EXPECT_TRUE(ScaleWebInputEvent(event, 2.f)); 28 EXPECT_TRUE(ScaleWebInputEvent(event, 2.f));
29 } 29 }
30 30
31 TEST(BlinkEventUtilTest, PaginatedScrollBeginEvent) {
32 ui::GestureEventDetails details(ui::ET_GESTURE_SCROLL_BEGIN, 1, 1,
33 ui::GestureEventDetails::ScrollUnits::PAGE);
34 details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
35 auto event =
36 CreateWebGestureEvent(details, base::TimeTicks(), gfx::PointF(1.f, 1.f),
37 gfx::PointF(1.f, 1.f), 0, 0U);
38 std::unique_ptr<blink::WebInputEvent> webEvent =
39 ScaleWebInputEvent(event, 2.f);
40 EXPECT_TRUE(webEvent);
41 blink::WebGestureEvent* gestureEvent =
42 static_cast<blink::WebGestureEvent*>(webEvent.get());
43 EXPECT_EQ(1, gestureEvent->data.scrollUpdate.deltaY);
Bret 2017/02/17 21:06:03 nit: it's probably worth adding the one line to ch
chengx 2017/02/17 21:57:45 Added checks for deltaX. Also, I should use scroll
44 }
45
46 TEST(BlinkEventUtilTest, PaginatedScrollUpdateEvent) {
47 ui::GestureEventDetails details(ui::ET_GESTURE_SCROLL_UPDATE, 1, 1,
48 ui::GestureEventDetails::ScrollUnits::PAGE);
49 details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
50 auto event =
51 CreateWebGestureEvent(details, base::TimeTicks(), gfx::PointF(1.f, 1.f),
52 gfx::PointF(1.f, 1.f), 0, 0U);
53 std::unique_ptr<blink::WebInputEvent> webEvent =
54 ScaleWebInputEvent(event, 2.f);
55 EXPECT_TRUE(webEvent);
56 blink::WebGestureEvent* gestureEvent =
57 static_cast<blink::WebGestureEvent*>(webEvent.get());
58 EXPECT_EQ(1, gestureEvent->data.scrollUpdate.deltaY);
59 }
60
31 TEST(BlinkEventUtilTest, TouchEventCoalescing) { 61 TEST(BlinkEventUtilTest, TouchEventCoalescing) {
32 blink::WebTouchPoint touch_point; 62 blink::WebTouchPoint touch_point;
33 touch_point.id = 1; 63 touch_point.id = 1;
34 touch_point.state = blink::WebTouchPoint::StateMoved; 64 touch_point.state = blink::WebTouchPoint::StateMoved;
35 65
36 blink::WebTouchEvent coalesced_event; 66 blink::WebTouchEvent coalesced_event;
37 coalesced_event.setType(blink::WebInputEvent::TouchMove); 67 coalesced_event.setType(blink::WebInputEvent::TouchMove);
38 touch_point.movementX = 5; 68 touch_point.movementX = 5;
39 touch_point.movementY = 10; 69 touch_point.movementY = 10;
40 coalesced_event.touches[coalesced_event.touchesLength++] = touch_point; 70 coalesced_event.touches[coalesced_event.touchesLength++] = touch_point;
41 71
42 blink::WebTouchEvent event_to_be_coalesced; 72 blink::WebTouchEvent event_to_be_coalesced;
43 event_to_be_coalesced.setType(blink::WebInputEvent::TouchMove); 73 event_to_be_coalesced.setType(blink::WebInputEvent::TouchMove);
44 touch_point.movementX = 3; 74 touch_point.movementX = 3;
45 touch_point.movementY = -4; 75 touch_point.movementY = -4;
46 event_to_be_coalesced.touches[event_to_be_coalesced.touchesLength++] = 76 event_to_be_coalesced.touches[event_to_be_coalesced.touchesLength++] =
47 touch_point; 77 touch_point;
48 78
49 EXPECT_TRUE(CanCoalesce(event_to_be_coalesced, coalesced_event)); 79 EXPECT_TRUE(CanCoalesce(event_to_be_coalesced, coalesced_event));
50 Coalesce(event_to_be_coalesced, &coalesced_event); 80 Coalesce(event_to_be_coalesced, &coalesced_event);
51 EXPECT_EQ(8, coalesced_event.touches[0].movementX); 81 EXPECT_EQ(8, coalesced_event.touches[0].movementX);
52 EXPECT_EQ(6, coalesced_event.touches[0].movementY); 82 EXPECT_EQ(6, coalesced_event.touches[0].movementY);
53 } 83 }
54 84
55 } // namespace ui 85 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698