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

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

Issue 2037513002: Convert device_sensors to use mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@conversion--mime-registry
Patch Set: Created 4 years, 5 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
Index: content/renderer/device_sensors/device_orientation_event_pump_unittest.cc
diff --git a/content/renderer/device_sensors/device_orientation_event_pump_unittest.cc b/content/renderer/device_sensors/device_orientation_event_pump_unittest.cc
index 141f8faabf40319b032481dc9aec45fa0b5d5df5..1a3a2852a71994649130095c7d5b6f2ce5db49b0 100644
--- a/content/renderer/device_sensors/device_orientation_event_pump_unittest.cc
+++ b/content/renderer/device_sensors/device_orientation_event_pump_unittest.cc
@@ -52,11 +52,11 @@ class MockDeviceOrientationListener
class DeviceOrientationEventPumpForTesting : public DeviceOrientationEventPump {
public:
DeviceOrientationEventPumpForTesting()
- : DeviceOrientationEventPump(0) { }
+ : DeviceOrientationEventPump(nullptr) {}
~DeviceOrientationEventPumpForTesting() override {}
- void OnDidStart(base::SharedMemoryHandle renderer_handle) {
- DeviceOrientationEventPump::OnDidStart(renderer_handle);
+ void DidStart(mojo::ScopedSharedBufferHandle renderer_handle) {
+ DeviceOrientationEventPump::DidStart(std::move(renderer_handle));
}
void SendStartMessage() override {}
void SendStopMessage() override {}
@@ -72,26 +72,21 @@ class DeviceOrientationEventPumpForTesting : public DeviceOrientationEventPump {
class DeviceOrientationEventPumpTest : public testing::Test {
public:
- DeviceOrientationEventPumpTest() {
- EXPECT_TRUE(shared_memory_.CreateAndMapAnonymous(
- sizeof(DeviceOrientationHardwareBuffer)));
- }
+ DeviceOrientationEventPumpTest() = default;
protected:
void SetUp() override {
- const DeviceOrientationHardwareBuffer* null_buffer = nullptr;
listener_.reset(new MockDeviceOrientationListener);
orientation_pump_.reset(new DeviceOrientationEventPumpForTesting);
- buffer_ = static_cast<DeviceOrientationHardwareBuffer*>(
- shared_memory_.memory());
- ASSERT_NE(null_buffer, buffer_);
- memset(buffer_, 0, sizeof(DeviceOrientationHardwareBuffer));
- ASSERT_TRUE(shared_memory_.ShareToProcess(base::GetCurrentProcessHandle(),
- &handle_));
+ shared_memory_ = mojo::SharedBufferHandle::Create(
+ sizeof(DeviceOrientationHardwareBuffer));
+ mapping_ = shared_memory_->Map(sizeof(DeviceOrientationHardwareBuffer));
+ ASSERT_TRUE(mapping_);
+ memset(buffer(), 0, sizeof(DeviceOrientationHardwareBuffer));
}
void InitBuffer() {
- blink::WebDeviceOrientationData& data = buffer_->data;
+ blink::WebDeviceOrientationData& data = buffer()->data;
data.alpha = 1;
data.hasAlpha = true;
data.beta = 2;
@@ -102,7 +97,7 @@ class DeviceOrientationEventPumpTest : public testing::Test {
}
void InitBufferNoData() {
- blink::WebDeviceOrientationData& data = buffer_->data;
+ blink::WebDeviceOrientationData& data = buffer()->data;
data.allAvailableSensorsAreActive = true;
}
@@ -110,25 +105,28 @@ class DeviceOrientationEventPumpTest : public testing::Test {
DeviceOrientationEventPumpForTesting* orientation_pump() {
return orientation_pump_.get();
}
- base::SharedMemoryHandle handle() { return handle_; }
- DeviceOrientationHardwareBuffer* buffer() { return buffer_; }
+ mojo::ScopedSharedBufferHandle handle() {
+ return shared_memory_->Clone(
+ mojo::SharedBufferHandle::AccessMode::READ_ONLY);
+ }
+ DeviceOrientationHardwareBuffer* buffer() {
+ return reinterpret_cast<DeviceOrientationHardwareBuffer*>(mapping_.get());
+ }
private:
+ base::MessageLoop loop_;
std::unique_ptr<MockDeviceOrientationListener> listener_;
std::unique_ptr<DeviceOrientationEventPumpForTesting> orientation_pump_;
- base::SharedMemoryHandle handle_;
- base::SharedMemory shared_memory_;
- DeviceOrientationHardwareBuffer* buffer_;
+ mojo::ScopedSharedBufferHandle shared_memory_;
+ mojo::ScopedSharedBufferMapping mapping_;
DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPumpTest);
};
TEST_F(DeviceOrientationEventPumpTest, DidStartPolling) {
- base::MessageLoop loop;
-
InitBuffer();
orientation_pump()->Start(listener());
- orientation_pump()->OnDidStart(handle());
+ orientation_pump()->DidStart(handle());
base::MessageLoop::current()->Run();
@@ -144,11 +142,9 @@ TEST_F(DeviceOrientationEventPumpTest, DidStartPolling) {
}
TEST_F(DeviceOrientationEventPumpTest, FireAllNullEvent) {
- base::MessageLoop loop;
-
InitBufferNoData();
orientation_pump()->Start(listener());
- orientation_pump()->OnDidStart(handle());
+ orientation_pump()->DidStart(handle());
base::MessageLoop::current()->Run();
@@ -161,11 +157,9 @@ TEST_F(DeviceOrientationEventPumpTest, FireAllNullEvent) {
}
TEST_F(DeviceOrientationEventPumpTest, UpdateRespectsOrientationThreshold) {
- base::MessageLoop loop;
-
InitBuffer();
orientation_pump()->Start(listener());
- orientation_pump()->OnDidStart(handle());
+ orientation_pump()->DidStart(handle());
base::MessageLoop::current()->Run();

Powered by Google App Engine
This is Rietveld 408576698