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

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

Issue 680383007: DeviceOrientation API on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "content/public/browser/sensor_manager_delegate_chromeos.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace {
13
14 const double kMeanGravity = 9.80665;
15
16 class SensorManagerDelegateTest
17 : public content::SensorManagerDelegateChromeOS {
18 public:
19 SensorManagerDelegateTest() {}
20 ~SensorManagerDelegateTest() override {}
21
22 // content::SensorManagerDelegateChromeOS:
23 void StartFetchingDeviceOrientationData(
24 const base::Callback<void(double, double, double)>& callback) override {}
25 void StopFetchingDeviceOrientationData() override {}
26
27 private:
28 DISALLOW_COPY_AND_ASSIGN(SensorManagerDelegateTest);
29 };
30
31 } // namespace
32
33 namespace content {
34
35 class SensorManagerChromeOSTest : public testing::Test {
36 public:
37 SensorManagerChromeOSTest() {
38 SensorManagerDelegateChromeOS::SetDelegate(&sensor_manager_delegate_test_);
39 orientation_buffer_.reset(new DeviceOrientationHardwareBuffer);
40 SensorManagerChromeOS::GetInstance()->StartFetchingDeviceOrientationData(
41 orientation_buffer_.get());
42 }
43
44 virtual ~SensorManagerChromeOSTest() {}
45
46 void OnAccelerationIncludingGravity(double x, double y, double z) {
47 SensorManagerChromeOS::GetInstance()->OnAccelerationIncludingGravity(x, y,
48 z);
49 }
50
51 DeviceOrientationHardwareBuffer* orientation_buffer() {
52 return orientation_buffer_.get();
53 }
54
55 private:
56 scoped_ptr<DeviceOrientationHardwareBuffer> orientation_buffer_;
57
58 SensorManagerDelegateTest sensor_manager_delegate_test_;
59
60 DISALLOW_COPY_AND_ASSIGN(SensorManagerChromeOSTest);
61 };
62
63 // Tests that starting to process orientation data will update the associated
64 // buffer.
65 TEST_F(SensorManagerChromeOSTest, OrientationBuffer) {
66 DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
67 EXPECT_TRUE(buffer->data.hasAbsolute);
68 EXPECT_FALSE(buffer->data.hasAlpha);
69 EXPECT_FALSE(buffer->data.hasBeta);
70 EXPECT_FALSE(buffer->data.hasGamma);
71 EXPECT_FALSE(buffer->data.allAvailableSensorsAreActive);
72
73 OnAccelerationIncludingGravity(0.0f, 0.0f, 1.0f);
74 EXPECT_FLOAT_EQ(0.0f, buffer->data.alpha);
75 EXPECT_FALSE(buffer->data.hasAlpha);
76 EXPECT_TRUE(buffer->data.hasBeta);
77 EXPECT_TRUE(buffer->data.hasGamma);
78 EXPECT_TRUE(buffer->data.allAvailableSensorsAreActive);
79
80 SensorManagerChromeOS::GetInstance()->StopFetchingDeviceOrientationData();
81 EXPECT_FALSE(buffer->data.allAvailableSensorsAreActive);
82 }
83
84 // Tests a device resting flat.
85 TEST_F(SensorManagerChromeOSTest, NeutralOrientation) {
86 OnAccelerationIncludingGravity(0.0f, 0.0f, -kMeanGravity);
87 DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
88 EXPECT_FLOAT_EQ(0.0f, buffer->data.beta);
89 EXPECT_FLOAT_EQ(0.0f, buffer->data.gamma);
90 }
91
92 // Tests an upside-down device, such that the W3C boundary [-180,180) causes the
93 // beta value to become negative.
94 TEST_F(SensorManagerChromeOSTest, UpsideDown) {
95 OnAccelerationIncludingGravity(0.0f, 0.0f, kMeanGravity);
96 DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
97 EXPECT_FLOAT_EQ(-180.0f, buffer->data.beta);
98 EXPECT_FLOAT_EQ(0.0f, buffer->data.gamma);
99 }
100
101 // Tests for positive beta value before the device is completely upside-down
102 TEST_F(SensorManagerChromeOSTest, BeforeUpsideDownBoundary) {
103 OnAccelerationIncludingGravity(0.0f, -kMeanGravity / 2.0f,
104 kMeanGravity / 2.0f);
105 DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
106 EXPECT_FLOAT_EQ(135.0f, buffer->data.beta);
107 EXPECT_FLOAT_EQ(0.0f, buffer->data.gamma);
108 }
109
110 // Tests a device lying on its left-edge.
111 TEST_F(SensorManagerChromeOSTest, LeftEdge) {
112 OnAccelerationIncludingGravity(-kMeanGravity, 0.0f, 0.0f);
113 DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
114 EXPECT_FLOAT_EQ(0.0f, buffer->data.beta);
115 EXPECT_FLOAT_EQ(-90.0f, buffer->data.gamma);
116 }
117
118 // Tests a device lying on its right-edge, such that the W3C boundary [-90,90)
119 // causes the gamma value to become negative.
120 TEST_F(SensorManagerChromeOSTest, RightEdge) {
121 OnAccelerationIncludingGravity(kMeanGravity, 0.0f, 0.0f);
122 DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
123 EXPECT_FLOAT_EQ(0.0f, buffer->data.beta);
124 EXPECT_FLOAT_EQ(-90.0f, buffer->data.gamma);
125 }
126
127 // Tests for positive gamma value before the device is completely on its right
128 // side.
129 TEST_F(SensorManagerChromeOSTest, BeforeRightEdgeBoundary) {
130 OnAccelerationIncludingGravity(kMeanGravity / 2.0f, 0.0f,
131 -kMeanGravity / 2.0f);
132 DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
133 EXPECT_FLOAT_EQ(0.0f, buffer->data.beta);
134 EXPECT_FLOAT_EQ(45.0f, buffer->data.gamma);
135 }
136
137 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/device_sensors/sensor_manager_chromeos.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698