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

Unified Diff: content/renderer/device_sensors/device_motion_event_pump_unittest.cc

Issue 870053009: Test DeviceMotionEventPump to ensure events deliver at 60Hz (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/device_sensors/device_motion_event_pump_unittest.cc
diff --git a/content/renderer/device_sensors/device_motion_event_pump_unittest.cc b/content/renderer/device_sensors/device_motion_event_pump_unittest.cc
index 5b88d66f8b8f58ffd4452a6e7d65d91091c92bc1..9b66ea0d5bf173fb9260f4d1fc6b5f4c79190c12 100644
--- a/content/renderer/device_sensors/device_motion_event_pump_unittest.cc
+++ b/content/renderer/device_sensors/device_motion_event_pump_unittest.cc
@@ -16,7 +16,8 @@ namespace content {
class MockDeviceMotionListener : public blink::WebDeviceMotionListener {
public:
- MockDeviceMotionListener() : did_change_device_motion_(false) {
+ MockDeviceMotionListener()
+ : did_change_device_motion_(false), number_of_events_(0) {
memset(&data_, 0, sizeof(data_));
}
virtual ~MockDeviceMotionListener() { }
@@ -25,17 +26,22 @@ class MockDeviceMotionListener : public blink::WebDeviceMotionListener {
const blink::WebDeviceMotionData& data) override {
memcpy(&data_, &data, sizeof(data));
did_change_device_motion_ = true;
+ ++number_of_events_;
}
bool did_change_device_motion() const {
return did_change_device_motion_;
}
+
+ int number_of_events() const { return number_of_events_; }
+
const blink::WebDeviceMotionData& data() const {
return data_;
}
private:
bool did_change_device_motion_;
+ int number_of_events_;
blink::WebDeviceMotionData data_;
DISALLOW_COPY_AND_ASSIGN(MockDeviceMotionListener);
@@ -44,9 +50,17 @@ class MockDeviceMotionListener : public blink::WebDeviceMotionListener {
class DeviceMotionEventPumpForTesting : public DeviceMotionEventPump {
public:
DeviceMotionEventPumpForTesting()
- : DeviceMotionEventPump(0) { }
+ : DeviceMotionEventPump(0), stop_on_fire_event_(true) {}
~DeviceMotionEventPumpForTesting() override {}
+ void set_stop_on_fire_event(bool stop_on_fire_event) {
+ stop_on_fire_event_ = stop_on_fire_event;
+ }
+
+ bool stop_on_fire_event() { return stop_on_fire_event_; }
+
+ int pump_delay_microseconds() const { return pump_delay_microseconds_; }
+
void OnDidStart(base::SharedMemoryHandle renderer_handle) {
DeviceMotionEventPump::OnDidStart(renderer_handle);
}
@@ -54,11 +68,15 @@ class DeviceMotionEventPumpForTesting : public DeviceMotionEventPump {
void SendStopMessage() override {}
void FireEvent() override {
DeviceMotionEventPump::FireEvent();
- Stop();
- base::MessageLoop::current()->QuitWhenIdle();
+ if (stop_on_fire_event_) {
+ Stop();
+ base::MessageLoop::current()->QuitWhenIdle();
+ }
}
private:
+ bool stop_on_fire_event_;
+
DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPumpForTesting);
};
@@ -158,4 +176,31 @@ TEST_F(DeviceMotionEventPumpTest, DidStartPollingNotAllSensorsActive) {
EXPECT_FALSE(received_data.hasRotationRateGamma);
}
+// Confirm that the frequency of pumping events is not greater than 60Hz. A rate
+// above 60Hz would allow for the detection of keystrokes (crbug.com/421691)
+TEST_F(DeviceMotionEventPumpTest, PumpThrottlesEventRate) {
+ // Confirm that the delay for pumping events is 60 Hz.
+ EXPECT_GE(60, base::Time::kMicrosecondsPerSecond /
+ motion_pump()->pump_delay_microseconds());
+
+ base::MessageLoopForUI loop;
+
+ InitBuffer(true);
+
+ motion_pump()->set_stop_on_fire_event(false);
+ motion_pump()->Start(listener());
+ motion_pump()->OnDidStart(handle());
+
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, base::MessageLoop::QuitClosure(),
+ base::TimeDelta::FromMilliseconds(100));
+ base::MessageLoop::current()->Run();
+ motion_pump()->Stop();
+
+ // Check that the blink::WebDeviceMotionListener does not receive excess
+ // events.
+ EXPECT_TRUE(listener()->did_change_device_motion());
+ EXPECT_GE(6, listener()->number_of_events());
+}
+
} // namespace content
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698