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 bdba6c1688af91306375e5f4e0163d41d8c3985d..651f5cfb1463c30db45607dfd49d18561c184508 100644 |
--- a/content/renderer/device_sensors/device_motion_event_pump_unittest.cc |
+++ b/content/renderer/device_sensors/device_motion_event_pump_unittest.cc |
@@ -15,6 +15,7 @@ |
#include "base/threading/thread_task_runner_handle.h" |
#include "content/common/device_sensors/device_motion_hardware_buffer.h" |
#include "content/public/test/test_utils.h" |
+#include "mojo/public/cpp/system/buffer.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceMotionListener.h" |
@@ -66,8 +67,8 @@ class DeviceMotionEventPumpForTesting : public DeviceMotionEventPump { |
int pump_delay_microseconds() const { return pump_delay_microseconds_; } |
- void OnDidStart(base::SharedMemoryHandle renderer_handle) { |
- DeviceMotionEventPump::OnDidStart(renderer_handle); |
+ void DidStart(mojo::ScopedSharedBufferHandle renderer_handle) { |
+ DeviceMotionEventPump::DidStart(std::move(renderer_handle)); |
} |
void SendStartMessage() override {} |
void SendStopMessage() override {} |
@@ -87,25 +88,21 @@ class DeviceMotionEventPumpForTesting : public DeviceMotionEventPump { |
class DeviceMotionEventPumpTest : public testing::Test { |
public: |
- DeviceMotionEventPumpTest() { |
- EXPECT_TRUE(shared_memory_.CreateAndMapAnonymous( |
- sizeof(DeviceMotionHardwareBuffer))); |
- } |
+ DeviceMotionEventPumpTest() = default; |
protected: |
void SetUp() override { |
- const DeviceMotionHardwareBuffer* null_buffer = nullptr; |
listener_.reset(new MockDeviceMotionListener); |
motion_pump_.reset(new DeviceMotionEventPumpForTesting); |
- buffer_ = static_cast<DeviceMotionHardwareBuffer*>(shared_memory_.memory()); |
- ASSERT_NE(null_buffer, buffer_); |
- memset(buffer_, 0, sizeof(DeviceMotionHardwareBuffer)); |
- ASSERT_TRUE(shared_memory_.ShareToProcess(base::GetCurrentProcessHandle(), |
- &handle_)); |
+ shared_memory_ = |
+ mojo::SharedBufferHandle::Create(sizeof(DeviceMotionHardwareBuffer)); |
+ mapping_ = shared_memory_->Map(sizeof(DeviceMotionHardwareBuffer)); |
+ ASSERT_TRUE(mapping_); |
+ memset(buffer(), 0, sizeof(DeviceMotionHardwareBuffer)); |
} |
void InitBuffer(bool allAvailableSensorsActive) { |
- blink::WebDeviceMotionData& data = buffer_->data; |
+ blink::WebDeviceMotionData& data = buffer()->data; |
data.accelerationX = 1; |
data.hasAccelerationX = true; |
data.accelerationY = 2; |
@@ -117,25 +114,29 @@ class DeviceMotionEventPumpTest : public testing::Test { |
MockDeviceMotionListener* listener() { return listener_.get(); } |
DeviceMotionEventPumpForTesting* motion_pump() { return motion_pump_.get(); } |
- base::SharedMemoryHandle handle() { return handle_; } |
+ mojo::ScopedSharedBufferHandle handle() { |
+ return shared_memory_->Clone( |
+ mojo::SharedBufferHandle::AccessMode::READ_ONLY); |
+ } |
+ DeviceMotionHardwareBuffer* buffer() { |
+ return reinterpret_cast<DeviceMotionHardwareBuffer*>(mapping_.get()); |
+ } |
private: |
+ base::MessageLoop loop_; |
std::unique_ptr<MockDeviceMotionListener> listener_; |
std::unique_ptr<DeviceMotionEventPumpForTesting> motion_pump_; |
- base::SharedMemoryHandle handle_; |
- base::SharedMemory shared_memory_; |
- DeviceMotionHardwareBuffer* buffer_; |
+ mojo::ScopedSharedBufferHandle shared_memory_; |
+ mojo::ScopedSharedBufferMapping mapping_; |
DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPumpTest); |
}; |
TEST_F(DeviceMotionEventPumpTest, DidStartPolling) { |
- base::MessageLoopForUI loop; |
- |
InitBuffer(true); |
motion_pump()->Start(listener()); |
- motion_pump()->OnDidStart(handle()); |
+ motion_pump()->DidStart(handle()); |
base::MessageLoop::current()->Run(); |
@@ -157,12 +158,10 @@ TEST_F(DeviceMotionEventPumpTest, DidStartPolling) { |
} |
TEST_F(DeviceMotionEventPumpTest, DidStartPollingNotAllSensorsActive) { |
- base::MessageLoopForUI loop; |
- |
InitBuffer(false); |
motion_pump()->Start(listener()); |
- motion_pump()->OnDidStart(handle()); |
+ motion_pump()->DidStart(handle()); |
base::MessageLoop::current()->Run(); |
@@ -188,13 +187,11 @@ TEST_F(DeviceMotionEventPumpTest, PumpThrottlesEventRate) { |
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()); |
+ motion_pump()->DidStart(handle()); |
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |