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

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, 11 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..7a1864d8cf28cf5e8e2bc695a40a9e6118512ca1 100644
--- a/content/renderer/device_sensors/device_motion_event_pump_unittest.cc
+++ b/content/renderer/device_sensors/device_motion_event_pump_unittest.cc
@@ -9,6 +9,7 @@
#include "base/message_loop/message_loop.h"
#include "content/common/device_sensors/device_motion_hardware_buffer.h"
#include "content/public/test/test_utils.h"
+#include "content/renderer/device_sensors/device_sensor_event_pump.h"
timvolodine 2015/02/04 13:30:18 is this needed?
jonross 2015/02/04 14:52:55 Nope, forgot to remove that after testing
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/WebDeviceMotionListener.h"
@@ -16,7 +17,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 +27,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 +51,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 +69,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 +177,30 @@ TEST_F(DeviceMotionEventPumpTest, DidStartPollingNotAllSensorsActive) {
EXPECT_FALSE(received_data.hasRotationRateGamma);
}
+// Tests that the pump is not firing events at a rate faster than 60Hz.
+TEST_F(DeviceMotionEventPumpTest, PumpThrottlesEventRate) {
+ // Confirm that the delay for pumping events is 60 Hz.
+ EXPECT_EQ(60, base::Time::kMicrosecondsPerSecond /
timvolodine 2015/02/04 13:30:18 should this better be EXPECT_GE?
jonross 2015/02/04 14:52:55 Done.
+ motion_pump()->pump_delay_microseconds());
timvolodine 2015/02/04 13:30:17 indentation
jonross 2015/02/04 14:52:55 Done.
+
+ 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