Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/device_sensors/sensor_manager_chromeos.h" | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "ui/accelerometer/accelerometer_types.h" | |
| 11 | |
| 12 namespace { | |
| 13 const double kMeanGravity = 9.80665; | |
| 14 } // namespace | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 class SensorManagerChromeOSTest : public testing::Test { | |
| 19 public: | |
| 20 SensorManagerChromeOSTest() { | |
| 21 orientation_buffer_.reset(new DeviceOrientationHardwareBuffer); | |
| 22 } | |
| 23 | |
| 24 virtual ~SensorManagerChromeOSTest() {} | |
| 25 | |
| 26 void OnAccelerationIncludingGravity(double x, double y, double z) { | |
| 27 ui::AccelerometerUpdate update; | |
| 28 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, x, y, z); | |
| 29 sensor_manager_->OnAccelerometerUpdated(update); | |
| 30 } | |
| 31 | |
| 32 DeviceOrientationHardwareBuffer* orientation_buffer() { | |
| 33 return orientation_buffer_.get(); | |
| 34 } | |
| 35 | |
| 36 SensorManagerChromeOS* sensor_manager() { return sensor_manager_.get(); } | |
| 37 | |
| 38 // testing::Test: | |
| 39 void SetUp() override { | |
| 40 testing::Test::SetUp(); | |
| 41 sensor_manager_.reset(new SensorManagerChromeOS); | |
|
timvolodine
2015/01/21 13:16:57
you are using a real implementation here? does thi
jonross
2015/01/21 16:02:11
I am testing a real sensor manager here. However i
timvolodine
2015/01/21 19:08:21
It seems you are relying on AccelerometerReader::I
| |
| 42 sensor_manager_->StartFetchingDeviceOrientationData( | |
| 43 orientation_buffer_.get()); | |
| 44 } | |
| 45 | |
| 46 void TearDown() override { | |
| 47 sensor_manager_->StopFetchingDeviceOrientationData(); | |
| 48 testing::Test::TearDown(); | |
| 49 } | |
| 50 | |
| 51 private: | |
| 52 scoped_ptr<SensorManagerChromeOS> sensor_manager_; | |
| 53 | |
| 54 scoped_ptr<DeviceOrientationHardwareBuffer> orientation_buffer_; | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(SensorManagerChromeOSTest); | |
| 57 }; | |
| 58 | |
| 59 // Tests that starting to process orientation data will update the associated | |
| 60 // buffer. | |
| 61 TEST_F(SensorManagerChromeOSTest, OrientationBuffer) { | |
| 62 DeviceOrientationHardwareBuffer* buffer = orientation_buffer(); | |
| 63 EXPECT_TRUE(buffer->data.hasAbsolute); | |
| 64 EXPECT_FALSE(buffer->data.hasAlpha); | |
| 65 EXPECT_FALSE(buffer->data.hasBeta); | |
| 66 EXPECT_FALSE(buffer->data.hasGamma); | |
| 67 EXPECT_FALSE(buffer->data.allAvailableSensorsAreActive); | |
| 68 | |
| 69 OnAccelerationIncludingGravity(0.0f, 0.0f, 1.0f); | |
| 70 EXPECT_FLOAT_EQ(0.0f, buffer->data.alpha); | |
| 71 EXPECT_FALSE(buffer->data.hasAlpha); | |
| 72 EXPECT_TRUE(buffer->data.hasBeta); | |
| 73 EXPECT_TRUE(buffer->data.hasGamma); | |
| 74 EXPECT_TRUE(buffer->data.allAvailableSensorsAreActive); | |
| 75 | |
| 76 sensor_manager()->StopFetchingDeviceOrientationData(); | |
| 77 EXPECT_FALSE(buffer->data.allAvailableSensorsAreActive); | |
| 78 } | |
| 79 | |
| 80 // Tests a device resting flat. | |
| 81 TEST_F(SensorManagerChromeOSTest, NeutralOrientation) { | |
| 82 OnAccelerationIncludingGravity(0.0f, 0.0f, -kMeanGravity); | |
| 83 DeviceOrientationHardwareBuffer* buffer = orientation_buffer(); | |
| 84 EXPECT_FLOAT_EQ(0.0f, buffer->data.beta); | |
| 85 EXPECT_FLOAT_EQ(0.0f, buffer->data.gamma); | |
| 86 } | |
| 87 | |
| 88 // Tests an upside-down device, such that the W3C boundary [-180,180) causes the | |
| 89 // beta value to become negative. | |
| 90 TEST_F(SensorManagerChromeOSTest, UpsideDown) { | |
| 91 OnAccelerationIncludingGravity(0.0f, 0.0f, kMeanGravity); | |
| 92 DeviceOrientationHardwareBuffer* buffer = orientation_buffer(); | |
| 93 EXPECT_FLOAT_EQ(-180.0f, buffer->data.beta); | |
| 94 EXPECT_FLOAT_EQ(0.0f, buffer->data.gamma); | |
| 95 } | |
| 96 | |
| 97 // Tests for positive beta value before the device is completely upside-down | |
| 98 TEST_F(SensorManagerChromeOSTest, BeforeUpsideDownBoundary) { | |
| 99 OnAccelerationIncludingGravity(0.0f, -kMeanGravity / 2.0f, | |
| 100 kMeanGravity / 2.0f); | |
| 101 DeviceOrientationHardwareBuffer* buffer = orientation_buffer(); | |
| 102 EXPECT_FLOAT_EQ(135.0f, buffer->data.beta); | |
| 103 EXPECT_FLOAT_EQ(0.0f, buffer->data.gamma); | |
| 104 } | |
| 105 | |
| 106 // Tests a device lying on its left-edge. | |
| 107 TEST_F(SensorManagerChromeOSTest, LeftEdge) { | |
| 108 OnAccelerationIncludingGravity(-kMeanGravity, 0.0f, 0.0f); | |
| 109 DeviceOrientationHardwareBuffer* buffer = orientation_buffer(); | |
| 110 EXPECT_FLOAT_EQ(0.0f, buffer->data.beta); | |
| 111 EXPECT_FLOAT_EQ(-90.0f, buffer->data.gamma); | |
| 112 } | |
| 113 | |
| 114 // Tests a device lying on its right-edge, such that the W3C boundary [-90,90) | |
| 115 // causes the gamma value to become negative. | |
| 116 TEST_F(SensorManagerChromeOSTest, RightEdge) { | |
| 117 OnAccelerationIncludingGravity(kMeanGravity, 0.0f, 0.0f); | |
| 118 DeviceOrientationHardwareBuffer* buffer = orientation_buffer(); | |
| 119 EXPECT_FLOAT_EQ(0.0f, buffer->data.beta); | |
| 120 EXPECT_FLOAT_EQ(-90.0f, buffer->data.gamma); | |
| 121 } | |
| 122 | |
| 123 // Tests for positive gamma value before the device is completely on its right | |
| 124 // side. | |
| 125 TEST_F(SensorManagerChromeOSTest, BeforeRightEdgeBoundary) { | |
| 126 OnAccelerationIncludingGravity(kMeanGravity / 2.0f, 0.0f, | |
| 127 -kMeanGravity / 2.0f); | |
| 128 DeviceOrientationHardwareBuffer* buffer = orientation_buffer(); | |
| 129 EXPECT_FLOAT_EQ(0.0f, buffer->data.beta); | |
| 130 EXPECT_FLOAT_EQ(45.0f, buffer->data.gamma); | |
| 131 } | |
| 132 | |
| 133 } // namespace content | |
| OLD | NEW |