diff options
-rw-r--r-- | ui/events/ozone/evdev/touch_noise/single_position_touch_noise_filter.cc | 8 | ||||
-rw-r--r-- | ui/events/ozone/evdev/touch_noise/touch_noise_finder_unittest.cc | 24 |
2 files changed, 24 insertions, 8 deletions
diff --git a/ui/events/ozone/evdev/touch_noise/single_position_touch_noise_filter.cc b/ui/events/ozone/evdev/touch_noise/single_position_touch_noise_filter.cc index a57033d..428d566 100644 --- a/ui/events/ozone/evdev/touch_noise/single_position_touch_noise_filter.cc +++ b/ui/events/ozone/evdev/touch_noise/single_position_touch_noise_filter.cc @@ -126,12 +126,14 @@ void SinglePositionTouchNoiseFilter::StopTrackingTouch(size_t index) { void SinglePositionTouchNoiseFilter::TrackTouch( const InProgressTouchEvdev& touch, base::TimeDelta time) { - size_t index = (tracked_touches_end_ + 1) % kNumTrackedTouches; + size_t index = tracked_touches_end_; + tracked_touches_end_ = (tracked_touches_end_ + 1) % kNumTrackedTouches; // If we would reach the start touch index, we cannot track any more touches. - if (index == tracked_touches_start_) + if (tracked_touches_end_ == tracked_touches_start_) { + tracked_touches_end_ = index; return; + } - tracked_touches_end_ = index; tracked_touches_[index].valid = true; tracked_touches_[index].slot = touch.slot; tracked_touches_[index].x = touch.x; diff --git a/ui/events/ozone/evdev/touch_noise/touch_noise_finder_unittest.cc b/ui/events/ozone/evdev/touch_noise/touch_noise_finder_unittest.cc index febf493..3b578a3 100644 --- a/ui/events/ozone/evdev/touch_noise/touch_noise_finder_unittest.cc +++ b/ui/events/ozone/evdev/touch_noise/touch_noise_finder_unittest.cc @@ -31,7 +31,7 @@ class TouchNoiseFinderTest : public testing::Test { bool FilterAndCheck(const TouchEntry entries[], size_t count) { std::vector<InProgressTouchEvdev> touches; size_t start_index = 0u; - bool was_touching = false; + std::bitset<kNumTouchEvdevSlots> was_touching; for (size_t i = 0; i < count; ++i) { const TouchEntry& entry = entries[i]; @@ -40,8 +40,9 @@ class TouchNoiseFinderTest : public testing::Test { touch.y = entry.location.y(); touch.tracking_id = entry.slot; touch.slot = entry.slot; - touch.was_touching = was_touching; + touch.was_touching = was_touching.test(touch.slot); touch.touching = entry.touching; + touches.push_back(touch); if (i == count - 1 || entry.time_ms != entries[i + 1].time_ms) { touch_noise_finder_->HandleTouches( @@ -50,18 +51,19 @@ class TouchNoiseFinderTest : public testing::Test { for (size_t j = 0; j < touches.size(); ++j) { bool expect_noise = entries[j + start_index].expect_noise; size_t slot = touches[j].slot; - if (touch_noise_finder_->SlotHasNoise(slot) != expect_noise) + if (touch_noise_finder_->SlotHasNoise(slot) != expect_noise) { LOG(ERROR) << base::StringPrintf( "Incorrect filtering at %dms for slot %lu", entry.time_ms, slot); - return false; + return false; + } } start_index = i + 1; touches.clear(); } - was_touching = entry.touching; + was_touching.set(entry.slot, entry.touching); } return true; @@ -137,4 +139,16 @@ TEST_F(TouchNoiseFinderTest, SamePosition) { EXPECT_TRUE(FilterAndCheck(kTestData, arraysize(kTestData))); } +// Test that a multi-second touch is considered noise. +TEST_F(TouchNoiseFinderTest, MultiSecondTouch) { + const TouchEntry kTestData[] = { + {1000, 1, true, gfx::PointF(10, 10), false}, + {2000, 1, true, gfx::PointF(10, 11), false}, + {3000, 1, true, gfx::PointF(10, 10), false}, + {4000, 1, true, gfx::PointF(10, 11), true}, + {5000, 1, true, gfx::PointF(10, 10), true}, + {6000, 1, true, gfx::PointF(10, 11), true}}; + EXPECT_TRUE(FilterAndCheck(kTestData, arraysize(kTestData))); +} + } // namespace ui |