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

Side by Side Diff: content/renderer/device_sensors/device_motion_event_pump_unittest.cc

Issue 2646093002: Move //content/browser/device_sensor/ into device/sensors (Closed)
Patch Set: gn format & code rebase Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/device_sensors/device_motion_event_pump.h" 5 #include "content/renderer/device_sensors/device_motion_event_pump.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 }; 88 };
89 89
90 class DeviceMotionEventPumpTest : public testing::Test { 90 class DeviceMotionEventPumpTest : public testing::Test {
91 public: 91 public:
92 DeviceMotionEventPumpTest() = default; 92 DeviceMotionEventPumpTest() = default;
93 93
94 protected: 94 protected:
95 void SetUp() override { 95 void SetUp() override {
96 listener_.reset(new MockDeviceMotionListener); 96 listener_.reset(new MockDeviceMotionListener);
97 motion_pump_.reset(new DeviceMotionEventPumpForTesting); 97 motion_pump_.reset(new DeviceMotionEventPumpForTesting);
98 shared_memory_ = 98 shared_memory_ = mojo::SharedBufferHandle::Create(
99 mojo::SharedBufferHandle::Create(sizeof(DeviceMotionHardwareBuffer)); 99 sizeof(device::DeviceMotionHardwareBuffer));
100 mapping_ = shared_memory_->Map(sizeof(DeviceMotionHardwareBuffer)); 100 mapping_ = shared_memory_->Map(sizeof(device::DeviceMotionHardwareBuffer));
101 ASSERT_TRUE(mapping_); 101 ASSERT_TRUE(mapping_);
102 memset(buffer(), 0, sizeof(DeviceMotionHardwareBuffer)); 102 memset(buffer(), 0, sizeof(device::DeviceMotionHardwareBuffer));
103 } 103 }
104 104
105 void InitBuffer(bool allAvailableSensorsActive) { 105 void InitBuffer(bool allAvailableSensorsActive) {
106 blink::WebDeviceMotionData& data = buffer()->data; 106 blink::WebDeviceMotionData& data = buffer()->data;
107 data.accelerationX = 1; 107 data.accelerationX = 1;
108 data.hasAccelerationX = true; 108 data.hasAccelerationX = true;
109 data.accelerationY = 2; 109 data.accelerationY = 2;
110 data.hasAccelerationY = true; 110 data.hasAccelerationY = true;
111 data.accelerationZ = 3; 111 data.accelerationZ = 3;
112 data.hasAccelerationZ = true; 112 data.hasAccelerationZ = true;
113 data.allAvailableSensorsAreActive = allAvailableSensorsActive; 113 data.allAvailableSensorsAreActive = allAvailableSensorsActive;
114 } 114 }
115 115
116 MockDeviceMotionListener* listener() { return listener_.get(); } 116 MockDeviceMotionListener* listener() { return listener_.get(); }
117 DeviceMotionEventPumpForTesting* motion_pump() { return motion_pump_.get(); } 117 DeviceMotionEventPumpForTesting* motion_pump() { return motion_pump_.get(); }
118 mojo::ScopedSharedBufferHandle handle() { 118 mojo::ScopedSharedBufferHandle handle() {
119 return shared_memory_->Clone( 119 return shared_memory_->Clone(
120 mojo::SharedBufferHandle::AccessMode::READ_ONLY); 120 mojo::SharedBufferHandle::AccessMode::READ_ONLY);
121 } 121 }
122 DeviceMotionHardwareBuffer* buffer() { 122 device::DeviceMotionHardwareBuffer* buffer() {
123 return reinterpret_cast<DeviceMotionHardwareBuffer*>(mapping_.get()); 123 return reinterpret_cast<device::DeviceMotionHardwareBuffer*>(
124 mapping_.get());
124 } 125 }
125 126
126 private: 127 private:
127 base::MessageLoop loop_; 128 base::MessageLoop loop_;
128 std::unique_ptr<MockDeviceMotionListener> listener_; 129 std::unique_ptr<MockDeviceMotionListener> listener_;
129 std::unique_ptr<DeviceMotionEventPumpForTesting> motion_pump_; 130 std::unique_ptr<DeviceMotionEventPumpForTesting> motion_pump_;
130 mojo::ScopedSharedBufferHandle shared_memory_; 131 mojo::ScopedSharedBufferHandle shared_memory_;
131 mojo::ScopedSharedBufferMapping mapping_; 132 mojo::ScopedSharedBufferMapping mapping_;
132 133
133 DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPumpTest); 134 DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPumpTest);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 base::RunLoop().Run(); 201 base::RunLoop().Run();
201 motion_pump()->Stop(); 202 motion_pump()->Stop();
202 203
203 // Check that the blink::WebDeviceMotionListener does not receive excess 204 // Check that the blink::WebDeviceMotionListener does not receive excess
204 // events. 205 // events.
205 EXPECT_TRUE(listener()->did_change_device_motion()); 206 EXPECT_TRUE(listener()->did_change_device_motion());
206 EXPECT_GE(6, listener()->number_of_events()); 207 EXPECT_GE(6, listener()->number_of_events());
207 } 208 }
208 209
209 } // namespace content 210 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698