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

Side by Side Diff: device/sensors/sensor_manager_chromeos_unittest.cc

Issue 2763333002: Convert device sensors structs from Blink to Chromium naming (Closed)
Patch Set: Rebase Created 3 years, 9 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "device/sensors/sensor_manager_chromeos.h" 5 #include "device/sensors/sensor_manager_chromeos.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "chromeos/accelerometer/accelerometer_types.h" 10 #include "chromeos/accelerometer/accelerometer_types.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 std::unique_ptr<DeviceMotionHardwareBuffer> motion_buffer_; 80 std::unique_ptr<DeviceMotionHardwareBuffer> motion_buffer_;
81 std::unique_ptr<DeviceOrientationHardwareBuffer> orientation_buffer_; 81 std::unique_ptr<DeviceOrientationHardwareBuffer> orientation_buffer_;
82 82
83 DISALLOW_COPY_AND_ASSIGN(SensorManagerChromeOSTest); 83 DISALLOW_COPY_AND_ASSIGN(SensorManagerChromeOSTest);
84 }; 84 };
85 85
86 // Tests that starting to process motion data will update the associated buffer. 86 // Tests that starting to process motion data will update the associated buffer.
87 TEST_F(SensorManagerChromeOSTest, MotionBuffer) { 87 TEST_F(SensorManagerChromeOSTest, MotionBuffer) {
88 DeviceMotionHardwareBuffer* buffer = motion_buffer(); 88 DeviceMotionHardwareBuffer* buffer = motion_buffer();
89 EXPECT_FLOAT_EQ(100.0f, buffer->data.interval); 89 EXPECT_FLOAT_EQ(100.0f, buffer->data.interval);
90 EXPECT_FALSE(buffer->data.hasAccelerationIncludingGravityX); 90 EXPECT_FALSE(buffer->data.has_acceleration_including_gravity_x);
91 EXPECT_FALSE(buffer->data.hasAccelerationIncludingGravityY); 91 EXPECT_FALSE(buffer->data.has_acceleration_including_gravity_y);
92 EXPECT_FALSE(buffer->data.hasAccelerationIncludingGravityZ); 92 EXPECT_FALSE(buffer->data.has_acceleration_including_gravity_z);
93 EXPECT_FALSE(buffer->data.hasAccelerationX); 93 EXPECT_FALSE(buffer->data.has_acceleration_x);
94 EXPECT_FALSE(buffer->data.hasAccelerationY); 94 EXPECT_FALSE(buffer->data.has_acceleration_y);
95 EXPECT_FALSE(buffer->data.hasAccelerationZ); 95 EXPECT_FALSE(buffer->data.has_acceleration_z);
96 EXPECT_FALSE(buffer->data.hasRotationRateAlpha); 96 EXPECT_FALSE(buffer->data.has_rotation_rate_alpha);
97 EXPECT_FALSE(buffer->data.hasRotationRateBeta); 97 EXPECT_FALSE(buffer->data.has_rotation_rate_beta);
98 EXPECT_FALSE(buffer->data.hasRotationRateGamma); 98 EXPECT_FALSE(buffer->data.has_rotation_rate_gamma);
99 99
100 OnAccelerationIncludingGravity(0.0f, 0.0f, 1.0f); 100 OnAccelerationIncludingGravity(0.0f, 0.0f, 1.0f);
101 EXPECT_TRUE(buffer->data.hasAccelerationIncludingGravityX); 101 EXPECT_TRUE(buffer->data.has_acceleration_including_gravity_x);
102 EXPECT_TRUE(buffer->data.hasAccelerationIncludingGravityY); 102 EXPECT_TRUE(buffer->data.has_acceleration_including_gravity_y);
103 EXPECT_TRUE(buffer->data.hasAccelerationIncludingGravityZ); 103 EXPECT_TRUE(buffer->data.has_acceleration_including_gravity_z);
104 EXPECT_FALSE(buffer->data.hasAccelerationX); 104 EXPECT_FALSE(buffer->data.has_acceleration_x);
105 EXPECT_FALSE(buffer->data.hasAccelerationY); 105 EXPECT_FALSE(buffer->data.has_acceleration_y);
106 EXPECT_FALSE(buffer->data.hasAccelerationZ); 106 EXPECT_FALSE(buffer->data.has_acceleration_z);
107 EXPECT_FALSE(buffer->data.hasRotationRateAlpha); 107 EXPECT_FALSE(buffer->data.has_rotation_rate_alpha);
108 EXPECT_FALSE(buffer->data.hasRotationRateBeta); 108 EXPECT_FALSE(buffer->data.has_rotation_rate_beta);
109 EXPECT_FALSE(buffer->data.hasRotationRateGamma); 109 EXPECT_FALSE(buffer->data.has_rotation_rate_gamma);
110 EXPECT_TRUE(buffer->data.allAvailableSensorsAreActive); 110 EXPECT_TRUE(buffer->data.all_available_sensors_are_active);
111 111
112 sensor_manager()->StopFetchingDeviceMotionData(); 112 sensor_manager()->StopFetchingDeviceMotionData();
113 EXPECT_FALSE(buffer->data.allAvailableSensorsAreActive); 113 EXPECT_FALSE(buffer->data.all_available_sensors_are_active);
114 } 114 }
115 115
116 // Tests that starting to process orientation data will update the associated 116 // Tests that starting to process orientation data will update the associated
117 // buffer. 117 // buffer.
118 TEST_F(SensorManagerChromeOSTest, OrientationBuffer) { 118 TEST_F(SensorManagerChromeOSTest, OrientationBuffer) {
119 DeviceOrientationHardwareBuffer* buffer = orientation_buffer(); 119 DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
120 EXPECT_FALSE(buffer->data.hasAlpha); 120 EXPECT_FALSE(buffer->data.has_alpha);
121 EXPECT_FALSE(buffer->data.hasBeta); 121 EXPECT_FALSE(buffer->data.has_beta);
122 EXPECT_FALSE(buffer->data.hasGamma); 122 EXPECT_FALSE(buffer->data.has_gamma);
123 EXPECT_FALSE(buffer->data.allAvailableSensorsAreActive); 123 EXPECT_FALSE(buffer->data.all_available_sensors_are_active);
124 124
125 OnAccelerationIncludingGravity(0.0f, 0.0f, 1.0f); 125 OnAccelerationIncludingGravity(0.0f, 0.0f, 1.0f);
126 EXPECT_FLOAT_EQ(0.0f, buffer->data.alpha); 126 EXPECT_FLOAT_EQ(0.0f, buffer->data.alpha);
127 EXPECT_FALSE(buffer->data.hasAlpha); 127 EXPECT_FALSE(buffer->data.has_alpha);
128 EXPECT_TRUE(buffer->data.hasBeta); 128 EXPECT_TRUE(buffer->data.has_beta);
129 EXPECT_TRUE(buffer->data.hasGamma); 129 EXPECT_TRUE(buffer->data.has_gamma);
130 EXPECT_TRUE(buffer->data.allAvailableSensorsAreActive); 130 EXPECT_TRUE(buffer->data.all_available_sensors_are_active);
131 131
132 sensor_manager()->StopFetchingDeviceOrientationData(); 132 sensor_manager()->StopFetchingDeviceOrientationData();
133 EXPECT_FALSE(buffer->data.allAvailableSensorsAreActive); 133 EXPECT_FALSE(buffer->data.all_available_sensors_are_active);
134 } 134 }
135 135
136 // Tests a device resting flat. 136 // Tests a device resting flat.
137 TEST_F(SensorManagerChromeOSTest, NeutralOrientation) { 137 TEST_F(SensorManagerChromeOSTest, NeutralOrientation) {
138 OnAccelerationIncludingGravity(0.0f, 0.0f, -kMeanGravity); 138 OnAccelerationIncludingGravity(0.0f, 0.0f, -kMeanGravity);
139 139
140 DeviceMotionHardwareBuffer* motion = motion_buffer(); 140 DeviceMotionHardwareBuffer* motion = motion_buffer();
141 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityX); 141 EXPECT_FLOAT_EQ(0.0f, motion->data.acceleration_including_gravity_x);
142 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityY); 142 EXPECT_FLOAT_EQ(0.0f, motion->data.acceleration_including_gravity_y);
143 EXPECT_FLOAT_EQ(-kMeanGravity, motion->data.accelerationIncludingGravityZ); 143 EXPECT_FLOAT_EQ(-kMeanGravity, motion->data.acceleration_including_gravity_z);
144 144
145 DeviceOrientationHardwareBuffer* orientation = orientation_buffer(); 145 DeviceOrientationHardwareBuffer* orientation = orientation_buffer();
146 EXPECT_FLOAT_EQ(0.0f, orientation->data.beta); 146 EXPECT_FLOAT_EQ(0.0f, orientation->data.beta);
147 EXPECT_FLOAT_EQ(0.0f, orientation->data.gamma); 147 EXPECT_FLOAT_EQ(0.0f, orientation->data.gamma);
148 } 148 }
149 149
150 // Tests an upside-down device, such that the W3C boundary [-180,180) causes the 150 // Tests an upside-down device, such that the W3C boundary [-180,180) causes the
151 // beta value to become negative. 151 // beta value to become negative.
152 TEST_F(SensorManagerChromeOSTest, UpsideDown) { 152 TEST_F(SensorManagerChromeOSTest, UpsideDown) {
153 OnAccelerationIncludingGravity(0.0f, 0.0f, kMeanGravity); 153 OnAccelerationIncludingGravity(0.0f, 0.0f, kMeanGravity);
154 154
155 DeviceMotionHardwareBuffer* motion = motion_buffer(); 155 DeviceMotionHardwareBuffer* motion = motion_buffer();
156 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityX); 156 EXPECT_FLOAT_EQ(0.0f, motion->data.acceleration_including_gravity_x);
157 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityY); 157 EXPECT_FLOAT_EQ(0.0f, motion->data.acceleration_including_gravity_y);
158 EXPECT_FLOAT_EQ(kMeanGravity, motion->data.accelerationIncludingGravityZ); 158 EXPECT_FLOAT_EQ(kMeanGravity, motion->data.acceleration_including_gravity_z);
159 159
160 DeviceOrientationHardwareBuffer* orientation = orientation_buffer(); 160 DeviceOrientationHardwareBuffer* orientation = orientation_buffer();
161 EXPECT_FLOAT_EQ(-180.0f, orientation->data.beta); 161 EXPECT_FLOAT_EQ(-180.0f, orientation->data.beta);
162 EXPECT_FLOAT_EQ(0.0f, orientation->data.gamma); 162 EXPECT_FLOAT_EQ(0.0f, orientation->data.gamma);
163 } 163 }
164 164
165 // Tests for positive beta value before the device is completely upside-down 165 // Tests for positive beta value before the device is completely upside-down
166 TEST_F(SensorManagerChromeOSTest, BeforeUpsideDownBoundary) { 166 TEST_F(SensorManagerChromeOSTest, BeforeUpsideDownBoundary) {
167 OnAccelerationIncludingGravity(0.0f, -kMeanGravity / 2.0f, 167 OnAccelerationIncludingGravity(0.0f, -kMeanGravity / 2.0f,
168 kMeanGravity / 2.0f); 168 kMeanGravity / 2.0f);
169 169
170 DeviceMotionHardwareBuffer* motion = motion_buffer(); 170 DeviceMotionHardwareBuffer* motion = motion_buffer();
171 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityX); 171 EXPECT_FLOAT_EQ(0.0f, motion->data.acceleration_including_gravity_x);
172 EXPECT_FLOAT_EQ(-kMeanGravity / 2.0f, 172 EXPECT_FLOAT_EQ(-kMeanGravity / 2.0f,
173 motion->data.accelerationIncludingGravityY); 173 motion->data.acceleration_including_gravity_y);
174 EXPECT_FLOAT_EQ(kMeanGravity / 2.0f, 174 EXPECT_FLOAT_EQ(kMeanGravity / 2.0f,
175 motion->data.accelerationIncludingGravityZ); 175 motion->data.acceleration_including_gravity_z);
176 176
177 DeviceOrientationHardwareBuffer* orientation = orientation_buffer(); 177 DeviceOrientationHardwareBuffer* orientation = orientation_buffer();
178 EXPECT_FLOAT_EQ(135.0f, orientation->data.beta); 178 EXPECT_FLOAT_EQ(135.0f, orientation->data.beta);
179 EXPECT_FLOAT_EQ(0.0f, orientation->data.gamma); 179 EXPECT_FLOAT_EQ(0.0f, orientation->data.gamma);
180 } 180 }
181 181
182 // Tests a device lying on its left-edge. 182 // Tests a device lying on its left-edge.
183 TEST_F(SensorManagerChromeOSTest, LeftEdge) { 183 TEST_F(SensorManagerChromeOSTest, LeftEdge) {
184 OnAccelerationIncludingGravity(-kMeanGravity, 0.0f, 0.0f); 184 OnAccelerationIncludingGravity(-kMeanGravity, 0.0f, 0.0f);
185 185
186 DeviceMotionHardwareBuffer* motion = motion_buffer(); 186 DeviceMotionHardwareBuffer* motion = motion_buffer();
187 EXPECT_FLOAT_EQ(-kMeanGravity, motion->data.accelerationIncludingGravityX); 187 EXPECT_FLOAT_EQ(-kMeanGravity, motion->data.acceleration_including_gravity_x);
188 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityY); 188 EXPECT_FLOAT_EQ(0.0f, motion->data.acceleration_including_gravity_y);
189 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityZ); 189 EXPECT_FLOAT_EQ(0.0f, motion->data.acceleration_including_gravity_z);
190 190
191 DeviceOrientationHardwareBuffer* orientation = orientation_buffer(); 191 DeviceOrientationHardwareBuffer* orientation = orientation_buffer();
192 EXPECT_FLOAT_EQ(0.0f, orientation->data.beta); 192 EXPECT_FLOAT_EQ(0.0f, orientation->data.beta);
193 EXPECT_FLOAT_EQ(-90.0f, orientation->data.gamma); 193 EXPECT_FLOAT_EQ(-90.0f, orientation->data.gamma);
194 } 194 }
195 195
196 // Tests a device lying on its right-edge, such that the W3C boundary [-90,90) 196 // Tests a device lying on its right-edge, such that the W3C boundary [-90,90)
197 // causes the gamma value to become negative. 197 // causes the gamma value to become negative.
198 TEST_F(SensorManagerChromeOSTest, RightEdge) { 198 TEST_F(SensorManagerChromeOSTest, RightEdge) {
199 OnAccelerationIncludingGravity(kMeanGravity, 0.0f, 0.0f); 199 OnAccelerationIncludingGravity(kMeanGravity, 0.0f, 0.0f);
200 200
201 DeviceMotionHardwareBuffer* motion = motion_buffer(); 201 DeviceMotionHardwareBuffer* motion = motion_buffer();
202 EXPECT_FLOAT_EQ(kMeanGravity, motion->data.accelerationIncludingGravityX); 202 EXPECT_FLOAT_EQ(kMeanGravity, motion->data.acceleration_including_gravity_x);
203 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityY); 203 EXPECT_FLOAT_EQ(0.0f, motion->data.acceleration_including_gravity_y);
204 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityZ); 204 EXPECT_FLOAT_EQ(0.0f, motion->data.acceleration_including_gravity_z);
205 205
206 DeviceOrientationHardwareBuffer* orientation = orientation_buffer(); 206 DeviceOrientationHardwareBuffer* orientation = orientation_buffer();
207 EXPECT_FLOAT_EQ(0.0f, orientation->data.beta); 207 EXPECT_FLOAT_EQ(0.0f, orientation->data.beta);
208 EXPECT_FLOAT_EQ(-90.0f, orientation->data.gamma); 208 EXPECT_FLOAT_EQ(-90.0f, orientation->data.gamma);
209 } 209 }
210 210
211 // Tests for positive gamma value before the device is completely on its right 211 // Tests for positive gamma value before the device is completely on its right
212 // side. 212 // side.
213 TEST_F(SensorManagerChromeOSTest, BeforeRightEdgeBoundary) { 213 TEST_F(SensorManagerChromeOSTest, BeforeRightEdgeBoundary) {
214 OnAccelerationIncludingGravity(kMeanGravity / 2.0f, 0.0f, 214 OnAccelerationIncludingGravity(kMeanGravity / 2.0f, 0.0f,
215 -kMeanGravity / 2.0f); 215 -kMeanGravity / 2.0f);
216 216
217 DeviceMotionHardwareBuffer* motion = motion_buffer(); 217 DeviceMotionHardwareBuffer* motion = motion_buffer();
218 EXPECT_FLOAT_EQ(kMeanGravity / 2.0f, 218 EXPECT_FLOAT_EQ(kMeanGravity / 2.0f,
219 motion->data.accelerationIncludingGravityX); 219 motion->data.acceleration_including_gravity_x);
220 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityY); 220 EXPECT_FLOAT_EQ(0.0f, motion->data.acceleration_including_gravity_y);
221 EXPECT_FLOAT_EQ(-kMeanGravity / 2.0f, 221 EXPECT_FLOAT_EQ(-kMeanGravity / 2.0f,
222 motion->data.accelerationIncludingGravityZ); 222 motion->data.acceleration_including_gravity_z);
223 223
224 DeviceOrientationHardwareBuffer* orientation = orientation_buffer(); 224 DeviceOrientationHardwareBuffer* orientation = orientation_buffer();
225 EXPECT_FLOAT_EQ(0.0f, orientation->data.beta); 225 EXPECT_FLOAT_EQ(0.0f, orientation->data.beta);
226 EXPECT_FLOAT_EQ(45.0f, orientation->data.gamma); 226 EXPECT_FLOAT_EQ(45.0f, orientation->data.gamma);
227 } 227 }
228 228
229 } // namespace device 229 } // namespace device
OLDNEW
« no previous file with comments | « device/sensors/sensor_manager_chromeos.cc ('k') | third_party/WebKit/Source/modules/device_orientation/DeviceMotionData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698