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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/device_sensors/sensor_manager_chromeos_unittest.cc
diff --git a/content/browser/device_sensors/sensor_manager_chromeos_unittest.cc b/content/browser/device_sensors/sensor_manager_chromeos_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7a29a16f0c22c042a5d955292ace3227a73606dd
--- /dev/null
+++ b/content/browser/device_sensors/sensor_manager_chromeos_unittest.cc
@@ -0,0 +1,137 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/device_sensors/sensor_manager_chromeos.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "content/common/device_sensors/device_orientation_hardware_buffer.h"
+#include "content/public/browser/sensor_manager_delegate_chromeos.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+const double kMeanGravity = 9.80665;
+
+class SensorManagerDelegateTest
+ : public content::SensorManagerDelegateChromeOS {
+ public:
+ SensorManagerDelegateTest() {}
+ ~SensorManagerDelegateTest() override {}
+
+ // content::SensorManagerDelegateChromeOS:
+ void StartFetchingDeviceOrientationData(
+ const base::Callback<void(double, double, double)>& callback) override {}
+ void StopFetchingDeviceOrientationData() override {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SensorManagerDelegateTest);
+};
+
+} // namespace
+
+namespace content {
+
+class SensorManagerChromeOSTest : public testing::Test {
+ public:
+ SensorManagerChromeOSTest() {
+ SensorManagerDelegateChromeOS::SetDelegate(&sensor_manager_delegate_test_);
+ orientation_buffer_.reset(new DeviceOrientationHardwareBuffer);
+ SensorManagerChromeOS::GetInstance()->StartFetchingDeviceOrientationData(
+ orientation_buffer_.get());
+ }
+
+ virtual ~SensorManagerChromeOSTest() {}
+
+ void OnAccelerationIncludingGravity(double x, double y, double z) {
+ SensorManagerChromeOS::GetInstance()->OnAccelerationIncludingGravity(x, y,
+ z);
+ }
+
+ DeviceOrientationHardwareBuffer* orientation_buffer() {
+ return orientation_buffer_.get();
+ }
+
+ private:
+ scoped_ptr<DeviceOrientationHardwareBuffer> orientation_buffer_;
+
+ SensorManagerDelegateTest sensor_manager_delegate_test_;
+
+ DISALLOW_COPY_AND_ASSIGN(SensorManagerChromeOSTest);
+};
+
+// Tests that starting to process orientation data will update the associated
+// buffer.
+TEST_F(SensorManagerChromeOSTest, OrientationBuffer) {
+ DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
+ EXPECT_TRUE(buffer->data.hasAbsolute);
+ EXPECT_FALSE(buffer->data.hasAlpha);
+ EXPECT_FALSE(buffer->data.hasBeta);
+ EXPECT_FALSE(buffer->data.hasGamma);
+ EXPECT_FALSE(buffer->data.allAvailableSensorsAreActive);
+
+ OnAccelerationIncludingGravity(0.0f, 0.0f, 1.0f);
+ EXPECT_FLOAT_EQ(0.0f, buffer->data.alpha);
+ EXPECT_FALSE(buffer->data.hasAlpha);
+ EXPECT_TRUE(buffer->data.hasBeta);
+ EXPECT_TRUE(buffer->data.hasGamma);
+ EXPECT_TRUE(buffer->data.allAvailableSensorsAreActive);
+
+ SensorManagerChromeOS::GetInstance()->StopFetchingDeviceOrientationData();
+ EXPECT_FALSE(buffer->data.allAvailableSensorsAreActive);
+}
+
+// Tests a device resting flat.
+TEST_F(SensorManagerChromeOSTest, NeutralOrientation) {
+ OnAccelerationIncludingGravity(0.0f, 0.0f, -kMeanGravity);
+ DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
+ EXPECT_FLOAT_EQ(0.0f, buffer->data.beta);
+ EXPECT_FLOAT_EQ(0.0f, buffer->data.gamma);
+}
+
+// Tests an upside-down device, such that the W3C boundary [-180,180) causes the
+// beta value to become negative.
+TEST_F(SensorManagerChromeOSTest, UpsideDown) {
+ OnAccelerationIncludingGravity(0.0f, 0.0f, kMeanGravity);
+ DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
+ EXPECT_FLOAT_EQ(-180.0f, buffer->data.beta);
+ EXPECT_FLOAT_EQ(0.0f, buffer->data.gamma);
+}
+
+// Tests for positive beta value before the device is completely upside-down
+TEST_F(SensorManagerChromeOSTest, BeforeUpsideDownBoundary) {
+ OnAccelerationIncludingGravity(0.0f, -kMeanGravity / 2.0f,
+ kMeanGravity / 2.0f);
+ DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
+ EXPECT_FLOAT_EQ(135.0f, buffer->data.beta);
+ EXPECT_FLOAT_EQ(0.0f, buffer->data.gamma);
+}
+
+// Tests a device lying on its left-edge.
+TEST_F(SensorManagerChromeOSTest, LeftEdge) {
+ OnAccelerationIncludingGravity(-kMeanGravity, 0.0f, 0.0f);
+ DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
+ EXPECT_FLOAT_EQ(0.0f, buffer->data.beta);
+ EXPECT_FLOAT_EQ(-90.0f, buffer->data.gamma);
+}
+
+// Tests a device lying on its right-edge, such that the W3C boundary [-90,90)
+// causes the gamma value to become negative.
+TEST_F(SensorManagerChromeOSTest, RightEdge) {
+ OnAccelerationIncludingGravity(kMeanGravity, 0.0f, 0.0f);
+ DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
+ EXPECT_FLOAT_EQ(0.0f, buffer->data.beta);
+ EXPECT_FLOAT_EQ(-90.0f, buffer->data.gamma);
+}
+
+// Tests for positive gamma value before the device is completely on its right
+// side.
+TEST_F(SensorManagerChromeOSTest, BeforeRightEdgeBoundary) {
+ OnAccelerationIncludingGravity(kMeanGravity / 2.0f, 0.0f,
+ -kMeanGravity / 2.0f);
+ DeviceOrientationHardwareBuffer* buffer = orientation_buffer();
+ EXPECT_FLOAT_EQ(0.0f, buffer->data.beta);
+ EXPECT_FLOAT_EQ(45.0f, buffer->data.gamma);
+}
+
+} // namespace content
« 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