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

Side by Side Diff: ui/events/ozone/evdev/touch_noise/touch_noise_remover_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_remover.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/device_event_dispatcher_evdev.h"
14
15 namespace ui {
16
17 namespace {
18
19 bool TouchEventParamsEquals(const TouchEventParams& p1,
20 const TouchEventParams& p2) {
21 return p1.device_id == p2.device_id && p1.touch_id == p2.touch_id &&
22 p1.tracking_id == p2.tracking_id && p1.type == p2.type &&
23 p1.location == p2.location && p1.radii == p2.radii &&
24 p1.pressure == p2.pressure && p1.timestamp == p2.timestamp;
25 }
26
27 } // namespace
28
29 class TouchNoiseRemoverTest : public testing::Test {
30 public:
31 struct TouchEntry {
32 int time_ms;
33 int touch_id;
34 ui::EventType type;
35 gfx::PointF location;
36 bool should_be_canceled;
37 };
38
39 TouchNoiseRemoverTest() {}
40 ~TouchNoiseRemoverTest() override {}
41
42 bool FilterAndCheck(const TouchEntry entries[], size_t count) {
43 std::vector<TouchEventParams> params;
44 std::vector<TouchEventParams> expected_params;
45 for (size_t i = 0; i < count; ++i) {
46 const TouchEntry& entry = entries[i];
47 int entry_time_ms = entry.time_ms;
48 params.push_back(
49 TouchEventParams(0, entry.touch_id, entry.touch_id, entry.type,
50 entry.location, gfx::Vector2dF(), 0.0f,
51 base::TimeDelta::FromMilliseconds(entry_time_ms)));
52 if (!entry.should_be_canceled)
53 expected_params.push_back(params.back());
54
55 if (i == count - 1 || entry_time_ms != entries[i + 1].time_ms) {
56 touch_noise_remover_->RemoveNoise(
57 &params, base::TimeDelta::FromMilliseconds(entry_time_ms));
58 if (params.size() != expected_params.size() ||
59 !std::equal(params.begin(), params.end(), expected_params.begin(),
60 TouchEventParamsEquals)) {
61 LOG(ERROR) << base::StringPrintf("Incorrect filtering at %dms",
62 entry_time_ms);
63 return false;
64 }
65
66 params.clear();
67 expected_params.clear();
68 }
69 }
70
71 return true;
72 }
73
74 private:
75 // testing::Test:
76 void SetUp() override {
77 touch_noise_remover_.reset(new TouchNoiseRemover);
78 }
79
80 scoped_ptr<TouchNoiseRemover> touch_noise_remover_;
81
82 DISALLOW_COPY_AND_ASSIGN(TouchNoiseRemoverTest);
83 };
84
85 // Test that taps which are far apart in quick succession are considered noise.
86 TEST_F(TouchNoiseRemoverTest, FarApartTaps) {
87 const TouchEntry kTestData[] = {
88 {10, 1, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 10), false},
89 {20, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 11), false},
90 {30, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 12), false},
91 {30, 2, ui::ET_TOUCH_PRESSED, gfx::PointF(2500, 1000), true},
92 {40, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 13), true},
93 {40, 2, ui::ET_TOUCH_MOVED, gfx::PointF(2500, 1001), true},
94 {50, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 14), true},
95 {50, 2, ui::ET_TOUCH_RELEASED, gfx::PointF(2500, 1002), true},
96 {60, 1, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 15), true}};
97 EXPECT_TRUE(FilterAndCheck(kTestData, arraysize(kTestData)));
98 }
99
100 // Test that taps which are far apart but do not occur in quick succession are
101 // not considered noise.
102 TEST_F(TouchNoiseRemoverTest, FarApartTapsSlow) {
103 const TouchEntry kTestData[] = {
104 {1000, 1, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 10), false},
105 {1500, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 11), false},
106 {2000, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 12), false},
107 {2500, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 13), false},
108 {2500, 2, ui::ET_TOUCH_PRESSED, gfx::PointF(2500, 1000), false},
109 {3000, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 14), false},
110 {3000, 2, ui::ET_TOUCH_RELEASED, gfx::PointF(2500, 1001), false},
111 {3500, 1, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 15), false}};
112 EXPECT_TRUE(FilterAndCheck(kTestData, arraysize(kTestData)));
113 }
114
115 // Test that touches which are horizontally aligned are considered noise.
116 TEST_F(TouchNoiseRemoverTest, HorizontallyAligned) {
117 const TouchEntry kTestData[] = {
118 {10, 1, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 10), false},
119 {20, 1, ui::ET_TOUCH_MOVED, gfx::PointF(10, 10), false},
120 {20, 2, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 25), true},
121 {30, 1, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 10), false},
122 {30, 2, ui::ET_TOUCH_MOVED, gfx::PointF(10, 25), true},
123 {40, 2, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 25), true}};
124 EXPECT_TRUE(FilterAndCheck(kTestData, arraysize(kTestData)));
125 }
126
127 // Test that touches in the same position are considered noise.
128 TEST_F(TouchNoiseRemoverTest, SamePosition) {
129 const TouchEntry kTestData[] = {
130 {1000, 1, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 10), false},
131 {1500, 1, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 10), false},
132 {2000, 1, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 10), false},
133 {2500, 1, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 10), false},
134 {3000, 1, ui::ET_TOUCH_PRESSED, gfx::PointF(50, 50), false},
135 {3500, 1, ui::ET_TOUCH_MOVED, gfx::PointF(50, 51), false},
136 {3500, 2, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 10), true},
137 {4000, 1, ui::ET_TOUCH_RELEASED, gfx::PointF(50, 52), false},
138 {4000, 2, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 10), true},
139 {4500, 1, ui::ET_TOUCH_PRESSED, gfx::PointF(10, 10), true},
140 {5000, 1, ui::ET_TOUCH_RELEASED, gfx::PointF(10, 10), true}};
141 EXPECT_TRUE(FilterAndCheck(kTestData, arraysize(kTestData)));
142 }
flackr 2015/03/10 05:23:40 Thanks for adding unit tests! The cancel behavior
143
144 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698