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

Side by Side Diff: ui/events/ozone/evdev/touch_noise/touch_noise_finder_unittest.cc

Issue 991533002: Port Chromium OS touch noise filtering to Chromium (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/events/ozone/evdev/touch_noise/touch_noise_finder.h"
6
7 #include <algorithm>
8
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/stringprintf.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/events/ozone/evdev/touch_evdev_types.h"
14 #include "ui/gfx/geometry/point_f.h"
15
16 namespace ui {
17
18 class TouchNoiseFinderTest : public testing::Test {
19 public:
20 struct TouchEntry {
21 int time_ms;
22 size_t slot;
23 ui::EventType type;
24 gfx::PointF location;
25 bool expect_noise;
26 };
27
28 TouchNoiseFinderTest() {}
29 ~TouchNoiseFinderTest() override {}
30
31 bool FilterAndCheck(const TouchEntry entries[], size_t count) {
32 std::vector<InProgressTouchEvdev> touches;
33 size_t start_index = 0u;
34 for (size_t i = 0; i < count; ++i) {
35 const TouchEntry& entry = entries[i];
36
37 InProgressTouchEvdev touch;
38 touch.x = entry.location.x();
39 touch.y = entry.location.y();
40 touch.tracking_id = entry.slot;
41 touch.slot = entry.slot;
42 touch.type = entry.type;
43
44 if (i == count - 1 || entry.time_ms != entries[i + 1].time_ms) {
45 touch_noise_finder_->HandleTouches(
46 touches, base::TimeDelta::FromMilliseconds(entry.time_ms));
47
48 for (size_t j = 0; j < touches.size(); ++j) {
49 bool expect_noise = entries[j + start_index].expect_noise;
50 size_t slot = touches[j].slot;
51 if (touch_noise_finder_->SlotHasNoise(slot) != expect_noise)
52 LOG(ERROR) << base::StringPrintf(
53 "Incorrect filtering at %dms for slot %lu", entry.time_ms,
54 slot);
55 return false;
56 }
57
58 start_index = i + 1;
59 touches.clear();
60 }
61 }
62
63 return true;
64 }
65
66 private:
67 // testing::Test:
68 void SetUp() override {
69 touch_noise_finder_.reset(new TouchNoiseFinder);
70 }
71
72 scoped_ptr<TouchNoiseFinder> touch_noise_finder_;
73
74 DISALLOW_COPY_AND_ASSIGN(TouchNoiseFinderTest);
75 };
76
77 // Test that taps which are far apart in quick succession are considered noise.
78 TEST_F(TouchNoiseFinderTest, FarApartTaps) {
79 const TouchEntry kTestData[] = {
80 {10, 1, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 10), false},
81 {20, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 11), false},
82 {30, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 12), false},
83 {30, 2, ui::ET_TOUCH_PRESSED, gfx::PointF(2500, 1000), true},
84 {40, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 13), true},
85 {40, 2, ui::ET_TOUCH_MOVED, gfx::PointF(2500, 1001), true},
86 {50, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 14), true},
87 {50, 2, ui::ET_TOUCH_RELEASED, gfx::PointF(2500, 1002), true},
88 {60, 1, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 15), true}};
89 EXPECT_TRUE(FilterAndCheck(kTestData, arraysize(kTestData)));
90 }
91
92 // Test that taps which are far apart but do not occur in quick succession are
93 // not considered noise.
94 TEST_F(TouchNoiseFinderTest, FarApartTapsSlow) {
95 const TouchEntry kTestData[] = {
96 {1000, 1, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 10), false},
97 {1500, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 11), false},
98 {2000, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 12), false},
99 {2500, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 13), false},
100 {2500, 2, ui::ET_TOUCH_PRESSED, gfx::PointF(2500, 1000), false},
101 {3000, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 14), false},
102 {3000, 2, ui::ET_TOUCH_RELEASED, gfx::PointF(2500, 1001), false},
103 {3500, 1, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 15), false}};
104 EXPECT_TRUE(FilterAndCheck(kTestData, arraysize(kTestData)));
105 }
106
107 // Test that touches which are horizontally aligned are considered noise.
108 TEST_F(TouchNoiseFinderTest, HorizontallyAligned) {
109 const TouchEntry kTestData[] = {
110 {10, 1, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 10), false},
111 {20, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 10), false},
112 {20, 2, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 25), true},
113 {30, 1, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 10), false},
114 {30, 2, ui::ET_TOUCH_MOVED, gfx::PointF(10, 25), true},
115 {40, 2, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 25), true}};
116 EXPECT_TRUE(FilterAndCheck(kTestData, arraysize(kTestData)));
117 }
118
119 // Test that touches in the same position are considered noise.
120 TEST_F(TouchNoiseFinderTest, SamePosition) {
121 const TouchEntry kTestData[] = {
122 {1000, 1, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 10), false},
123 {1500, 1, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 10), false},
124 {2000, 1, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 10), false},
125 {2500, 1, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 10), false},
126 {3000, 1, ui::ET_TOUCH_PRESSED, gfx::PointF(50, 50), false},
127 {3500, 1, ui::ET_TOUCH_MOVED, gfx::PointF(50, 51), false},
128 {3500, 2, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 10), true},
129 {4000, 1, ui::ET_TOUCH_RELEASED, gfx::PointF(50, 52), false},
130 {4000, 2, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 10), true},
131 {4500, 1, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 10), true},
132 {5000, 1, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 10), true}};
133 EXPECT_TRUE(FilterAndCheck(kTestData, arraysize(kTestData)));
134 }
135
136 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698