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

Side by Side Diff: content/browser/device_sensors/sensor_manager_chromeos_unittest.cc

Issue 934843002: Implement DeviceMotionEvent API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix missed test Created 5 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
« no previous file with comments | « content/browser/device_sensors/sensor_manager_chromeos.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/browser/device_sensors/sensor_manager_chromeos.h" 5 #include "content/browser/device_sensors/sensor_manager_chromeos.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "chromeos/accelerometer/accelerometer_types.h" 8 #include "chromeos/accelerometer/accelerometer_types.h"
9 #include "content/common/device_sensors/device_motion_hardware_buffer.h"
9 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" 10 #include "content/common/device_sensors/device_orientation_hardware_buffer.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace { 13 namespace {
13 14
14 const double kMeanGravity = 9.80665; 15 const double kMeanGravity = 9.80665;
15 16
16 // Isolated content::SensorManagerChromeOS from the active 17 // Isolated content::SensorManagerChromeOS from the active
17 // chromeos::AccelerometerReader. This allows for direct control over which 18 // chromeos::AccelerometerReader. This allows for direct control over which
18 // accelerometer events are provided to the sensor manager. 19 // accelerometer events are provided to the sensor manager.
(...skipping 10 matching lines...) Expand all
29 DISALLOW_COPY_AND_ASSIGN(TestSensorManagerChromeOS); 30 DISALLOW_COPY_AND_ASSIGN(TestSensorManagerChromeOS);
30 }; 31 };
31 32
32 } // namespace 33 } // namespace
33 34
34 namespace content { 35 namespace content {
35 36
36 class SensorManagerChromeOSTest : public testing::Test { 37 class SensorManagerChromeOSTest : public testing::Test {
37 public: 38 public:
38 SensorManagerChromeOSTest() { 39 SensorManagerChromeOSTest() {
40 motion_buffer_.reset(new DeviceMotionHardwareBuffer);
39 orientation_buffer_.reset(new DeviceOrientationHardwareBuffer); 41 orientation_buffer_.reset(new DeviceOrientationHardwareBuffer);
40 } 42 }
41 43
42 ~SensorManagerChromeOSTest() override {} 44 ~SensorManagerChromeOSTest() override {}
43 45
44 void OnAccelerationIncludingGravity(double x, double y, double z) { 46 void OnAccelerationIncludingGravity(double x, double y, double z) {
45 chromeos::AccelerometerUpdate update; 47 scoped_refptr<chromeos::AccelerometerUpdate> update(
46 update.Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, x, y, z); 48 new chromeos::AccelerometerUpdate());
49 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, x, y, z);
47 sensor_manager_->OnAccelerometerUpdated(update); 50 sensor_manager_->OnAccelerometerUpdated(update);
48 } 51 }
49 52
53 DeviceMotionHardwareBuffer* motion_buffer() { return motion_buffer_.get(); }
54
50 DeviceOrientationHardwareBuffer* orientation_buffer() { 55 DeviceOrientationHardwareBuffer* orientation_buffer() {
51 return orientation_buffer_.get(); 56 return orientation_buffer_.get();
52 } 57 }
53 58
54 SensorManagerChromeOS* sensor_manager() { return sensor_manager_.get(); } 59 SensorManagerChromeOS* sensor_manager() { return sensor_manager_.get(); }
55 60
56 // testing::Test: 61 // testing::Test:
57 void SetUp() override { 62 void SetUp() override {
58 testing::Test::SetUp(); 63 testing::Test::SetUp();
59 sensor_manager_.reset(new TestSensorManagerChromeOS); 64 sensor_manager_.reset(new TestSensorManagerChromeOS);
65 sensor_manager_->StartFetchingDeviceMotionData(motion_buffer_.get());
60 sensor_manager_->StartFetchingDeviceOrientationData( 66 sensor_manager_->StartFetchingDeviceOrientationData(
61 orientation_buffer_.get()); 67 orientation_buffer_.get());
62 } 68 }
63 69
64 void TearDown() override { 70 void TearDown() override {
71 sensor_manager_->StopFetchingDeviceMotionData();
65 sensor_manager_->StopFetchingDeviceOrientationData(); 72 sensor_manager_->StopFetchingDeviceOrientationData();
66 testing::Test::TearDown(); 73 testing::Test::TearDown();
67 } 74 }
68 75
69 private: 76 private:
70 scoped_ptr<TestSensorManagerChromeOS> sensor_manager_; 77 scoped_ptr<TestSensorManagerChromeOS> sensor_manager_;
71 78 scoped_ptr<DeviceMotionHardwareBuffer> motion_buffer_;
72 scoped_ptr<DeviceOrientationHardwareBuffer> orientation_buffer_; 79 scoped_ptr<DeviceOrientationHardwareBuffer> orientation_buffer_;
73 80
74 DISALLOW_COPY_AND_ASSIGN(SensorManagerChromeOSTest); 81 DISALLOW_COPY_AND_ASSIGN(SensorManagerChromeOSTest);
75 }; 82 };
76 83
84 // Tests that starting to process motion data will update the associated buffer.
85 TEST_F(SensorManagerChromeOSTest, MotionBuffer) {
86 DeviceMotionHardwareBuffer* buffer = motion_buffer();
87 EXPECT_FLOAT_EQ(100.0f, buffer->data.interval);
88 EXPECT_FALSE(buffer->data.hasAccelerationIncludingGravityX);
89 EXPECT_FALSE(buffer->data.hasAccelerationIncludingGravityY);
90 EXPECT_FALSE(buffer->data.hasAccelerationIncludingGravityZ);
91 EXPECT_FALSE(buffer->data.hasAccelerationX);
92 EXPECT_FALSE(buffer->data.hasAccelerationY);
93 EXPECT_FALSE(buffer->data.hasAccelerationZ);
94 EXPECT_FALSE(buffer->data.hasRotationRateAlpha);
95 EXPECT_FALSE(buffer->data.hasRotationRateBeta);
96 EXPECT_FALSE(buffer->data.hasRotationRateGamma);
97
98 OnAccelerationIncludingGravity(0.0f, 0.0f, 1.0f);
99 EXPECT_TRUE(buffer->data.hasAccelerationIncludingGravityX);
100 EXPECT_TRUE(buffer->data.hasAccelerationIncludingGravityY);
101 EXPECT_TRUE(buffer->data.hasAccelerationIncludingGravityZ);
102 EXPECT_FALSE(buffer->data.hasAccelerationX);
103 EXPECT_FALSE(buffer->data.hasAccelerationY);
104 EXPECT_FALSE(buffer->data.hasAccelerationZ);
105 EXPECT_FALSE(buffer->data.hasRotationRateAlpha);
106 EXPECT_FALSE(buffer->data.hasRotationRateBeta);
107 EXPECT_FALSE(buffer->data.hasRotationRateGamma);
108 EXPECT_TRUE(buffer->data.allAvailableSensorsAreActive);
109
110 sensor_manager()->StopFetchingDeviceMotionData();
111 EXPECT_FALSE(buffer->data.allAvailableSensorsAreActive);
112 }
113
77 // Tests that starting to process orientation data will update the associated 114 // Tests that starting to process orientation data will update the associated
78 // buffer. 115 // buffer.
79 TEST_F(SensorManagerChromeOSTest, OrientationBuffer) { 116 TEST_F(SensorManagerChromeOSTest, OrientationBuffer) {
80 DeviceOrientationHardwareBuffer* buffer = orientation_buffer(); 117 DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
81 EXPECT_TRUE(buffer->data.hasAbsolute); 118 EXPECT_TRUE(buffer->data.hasAbsolute);
82 EXPECT_FALSE(buffer->data.hasAlpha); 119 EXPECT_FALSE(buffer->data.hasAlpha);
83 EXPECT_FALSE(buffer->data.hasBeta); 120 EXPECT_FALSE(buffer->data.hasBeta);
84 EXPECT_FALSE(buffer->data.hasGamma); 121 EXPECT_FALSE(buffer->data.hasGamma);
85 EXPECT_FALSE(buffer->data.allAvailableSensorsAreActive); 122 EXPECT_FALSE(buffer->data.allAvailableSensorsAreActive);
86 123
87 OnAccelerationIncludingGravity(0.0f, 0.0f, 1.0f); 124 OnAccelerationIncludingGravity(0.0f, 0.0f, 1.0f);
88 EXPECT_FLOAT_EQ(0.0f, buffer->data.alpha); 125 EXPECT_FLOAT_EQ(0.0f, buffer->data.alpha);
89 EXPECT_FALSE(buffer->data.hasAlpha); 126 EXPECT_FALSE(buffer->data.hasAlpha);
90 EXPECT_TRUE(buffer->data.hasBeta); 127 EXPECT_TRUE(buffer->data.hasBeta);
91 EXPECT_TRUE(buffer->data.hasGamma); 128 EXPECT_TRUE(buffer->data.hasGamma);
92 EXPECT_TRUE(buffer->data.allAvailableSensorsAreActive); 129 EXPECT_TRUE(buffer->data.allAvailableSensorsAreActive);
93 130
94 sensor_manager()->StopFetchingDeviceOrientationData(); 131 sensor_manager()->StopFetchingDeviceOrientationData();
95 EXPECT_FALSE(buffer->data.allAvailableSensorsAreActive); 132 EXPECT_FALSE(buffer->data.allAvailableSensorsAreActive);
96 } 133 }
97 134
98 // Tests a device resting flat. 135 // Tests a device resting flat.
99 TEST_F(SensorManagerChromeOSTest, NeutralOrientation) { 136 TEST_F(SensorManagerChromeOSTest, NeutralOrientation) {
100 OnAccelerationIncludingGravity(0.0f, 0.0f, -kMeanGravity); 137 OnAccelerationIncludingGravity(0.0f, 0.0f, -kMeanGravity);
101 DeviceOrientationHardwareBuffer* buffer = orientation_buffer(); 138
102 EXPECT_FLOAT_EQ(0.0f, buffer->data.beta); 139 DeviceMotionHardwareBuffer* motion = motion_buffer();
103 EXPECT_FLOAT_EQ(0.0f, buffer->data.gamma); 140 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityX);
141 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityY);
142 EXPECT_FLOAT_EQ(-kMeanGravity, motion->data.accelerationIncludingGravityZ);
143
144 DeviceOrientationHardwareBuffer* orientation = orientation_buffer();
145 EXPECT_FLOAT_EQ(0.0f, orientation->data.beta);
146 EXPECT_FLOAT_EQ(0.0f, orientation->data.gamma);
104 } 147 }
105 148
106 // Tests an upside-down device, such that the W3C boundary [-180,180) causes the 149 // Tests an upside-down device, such that the W3C boundary [-180,180) causes the
107 // beta value to become negative. 150 // beta value to become negative.
108 TEST_F(SensorManagerChromeOSTest, UpsideDown) { 151 TEST_F(SensorManagerChromeOSTest, UpsideDown) {
109 OnAccelerationIncludingGravity(0.0f, 0.0f, kMeanGravity); 152 OnAccelerationIncludingGravity(0.0f, 0.0f, kMeanGravity);
110 DeviceOrientationHardwareBuffer* buffer = orientation_buffer(); 153
111 EXPECT_FLOAT_EQ(-180.0f, buffer->data.beta); 154 DeviceMotionHardwareBuffer* motion = motion_buffer();
112 EXPECT_FLOAT_EQ(0.0f, buffer->data.gamma); 155 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityX);
156 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityY);
157 EXPECT_FLOAT_EQ(kMeanGravity, motion->data.accelerationIncludingGravityZ);
158
159 DeviceOrientationHardwareBuffer* orientation = orientation_buffer();
160 EXPECT_FLOAT_EQ(-180.0f, orientation->data.beta);
161 EXPECT_FLOAT_EQ(0.0f, orientation->data.gamma);
113 } 162 }
114 163
115 // Tests for positive beta value before the device is completely upside-down 164 // Tests for positive beta value before the device is completely upside-down
116 TEST_F(SensorManagerChromeOSTest, BeforeUpsideDownBoundary) { 165 TEST_F(SensorManagerChromeOSTest, BeforeUpsideDownBoundary) {
117 OnAccelerationIncludingGravity(0.0f, -kMeanGravity / 2.0f, 166 OnAccelerationIncludingGravity(0.0f, -kMeanGravity / 2.0f,
118 kMeanGravity / 2.0f); 167 kMeanGravity / 2.0f);
119 DeviceOrientationHardwareBuffer* buffer = orientation_buffer(); 168
120 EXPECT_FLOAT_EQ(135.0f, buffer->data.beta); 169 DeviceMotionHardwareBuffer* motion = motion_buffer();
121 EXPECT_FLOAT_EQ(0.0f, buffer->data.gamma); 170 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityX);
171 EXPECT_FLOAT_EQ(-kMeanGravity / 2.0f,
172 motion->data.accelerationIncludingGravityY);
173 EXPECT_FLOAT_EQ(kMeanGravity / 2.0f,
174 motion->data.accelerationIncludingGravityZ);
175
176 DeviceOrientationHardwareBuffer* orientation = orientation_buffer();
177 EXPECT_FLOAT_EQ(135.0f, orientation->data.beta);
178 EXPECT_FLOAT_EQ(0.0f, orientation->data.gamma);
122 } 179 }
123 180
124 // Tests a device lying on its left-edge. 181 // Tests a device lying on its left-edge.
125 TEST_F(SensorManagerChromeOSTest, LeftEdge) { 182 TEST_F(SensorManagerChromeOSTest, LeftEdge) {
126 OnAccelerationIncludingGravity(-kMeanGravity, 0.0f, 0.0f); 183 OnAccelerationIncludingGravity(-kMeanGravity, 0.0f, 0.0f);
127 DeviceOrientationHardwareBuffer* buffer = orientation_buffer(); 184
128 EXPECT_FLOAT_EQ(0.0f, buffer->data.beta); 185 DeviceMotionHardwareBuffer* motion = motion_buffer();
129 EXPECT_FLOAT_EQ(-90.0f, buffer->data.gamma); 186 EXPECT_FLOAT_EQ(-kMeanGravity, motion->data.accelerationIncludingGravityX);
187 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityY);
188 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityZ);
189
190 DeviceOrientationHardwareBuffer* orientation = orientation_buffer();
191 EXPECT_FLOAT_EQ(0.0f, orientation->data.beta);
192 EXPECT_FLOAT_EQ(-90.0f, orientation->data.gamma);
130 } 193 }
131 194
132 // Tests a device lying on its right-edge, such that the W3C boundary [-90,90) 195 // Tests a device lying on its right-edge, such that the W3C boundary [-90,90)
133 // causes the gamma value to become negative. 196 // causes the gamma value to become negative.
134 TEST_F(SensorManagerChromeOSTest, RightEdge) { 197 TEST_F(SensorManagerChromeOSTest, RightEdge) {
135 OnAccelerationIncludingGravity(kMeanGravity, 0.0f, 0.0f); 198 OnAccelerationIncludingGravity(kMeanGravity, 0.0f, 0.0f);
136 DeviceOrientationHardwareBuffer* buffer = orientation_buffer(); 199
137 EXPECT_FLOAT_EQ(0.0f, buffer->data.beta); 200 DeviceMotionHardwareBuffer* motion = motion_buffer();
138 EXPECT_FLOAT_EQ(-90.0f, buffer->data.gamma); 201 EXPECT_FLOAT_EQ(kMeanGravity, motion->data.accelerationIncludingGravityX);
202 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityY);
203 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityZ);
204
205 DeviceOrientationHardwareBuffer* orientation = orientation_buffer();
206 EXPECT_FLOAT_EQ(0.0f, orientation->data.beta);
207 EXPECT_FLOAT_EQ(-90.0f, orientation->data.gamma);
139 } 208 }
140 209
141 // Tests for positive gamma value before the device is completely on its right 210 // Tests for positive gamma value before the device is completely on its right
142 // side. 211 // side.
143 TEST_F(SensorManagerChromeOSTest, BeforeRightEdgeBoundary) { 212 TEST_F(SensorManagerChromeOSTest, BeforeRightEdgeBoundary) {
144 OnAccelerationIncludingGravity(kMeanGravity / 2.0f, 0.0f, 213 OnAccelerationIncludingGravity(kMeanGravity / 2.0f, 0.0f,
145 -kMeanGravity / 2.0f); 214 -kMeanGravity / 2.0f);
146 DeviceOrientationHardwareBuffer* buffer = orientation_buffer(); 215
147 EXPECT_FLOAT_EQ(0.0f, buffer->data.beta); 216 DeviceMotionHardwareBuffer* motion = motion_buffer();
148 EXPECT_FLOAT_EQ(45.0f, buffer->data.gamma); 217 EXPECT_FLOAT_EQ(kMeanGravity / 2.0f,
218 motion->data.accelerationIncludingGravityX);
219 EXPECT_FLOAT_EQ(0.0f, motion->data.accelerationIncludingGravityY);
220 EXPECT_FLOAT_EQ(-kMeanGravity / 2.0f,
221 motion->data.accelerationIncludingGravityZ);
222
223 DeviceOrientationHardwareBuffer* orientation = orientation_buffer();
224 EXPECT_FLOAT_EQ(0.0f, orientation->data.beta);
225 EXPECT_FLOAT_EQ(45.0f, orientation->data.gamma);
149 } 226 }
150 227
151 } // namespace content 228 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/device_sensors/sensor_manager_chromeos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698