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

Unified Diff: content/browser/device_sensors/sensor_manager_unittest.cc

Issue 680383007: DeviceOrientation API on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
Index: content/browser/device_sensors/sensor_manager_unittest.cc
diff --git a/content/browser/device_sensors/sensor_manager_unittest.cc b/content/browser/device_sensors/sensor_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9d75a93b36b2af1cd118ead0a6ee0aa2210ec6b8
--- /dev/null
+++ b/content/browser/device_sensors/sensor_manager_unittest.cc
@@ -0,0 +1,139 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
timvolodine 2014/11/06 02:53:47 same here I think this should be sensor_manager_ch
jonross 2014/11/06 18:18:52 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/browser/sensor_manager.h"
+
+#include "base/memory/shared_memory.h"
+#include "base/process/process_handle.h"
+#include "content/browser/device_sensors/device_inertial_sensor_service.h"
+#include "content/browser/device_sensors/inertial_sensor_consts.h"
+#include "content/common/device_sensors/device_orientation_hardware_buffer.h"
+#include "content/public/browser/sensor_manager.h"
+#include "content/public/test/browser_test.h"
+#include "content/public/test/content_browser_test.h"
+
+namespace {
+const double kMeanGravity = 9.80665;
+}
+
+namespace content {
+
+class SensorManagerTest : public ContentBrowserTest {
timvolodine 2014/11/06 02:53:47 is this a browser or unittest? browser tests are u
jonross 2014/11/06 18:18:52 Just habit from development in ash. I'll switch th
+ public:
+ SensorManagerTest() {}
+ virtual ~SensorManagerTest() {}
+
+ DeviceOrientationHardwareBuffer* orientation_buffer() {
+ return SensorManager::GetInstance()->GetOrientationBufferForTest();
timvolodine 2014/11/06 02:53:47 for unit testing you can create a buffer manually
jonross 2014/11/06 18:18:52 Done.
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SensorManagerTest);
+};
+
+// Tests that starting to process orientation data will create a SharedMemory,
+// and that the SensorManager can update the associated buffer.
+IN_PROC_BROWSER_TEST_F(SensorManagerTest, OrientationBuffer) {
+ DeviceInertialSensorService* service =
+ DeviceInertialSensorService::GetInstance();
timvolodine 2014/11/06 02:53:47 if the purpose is to test sensor_manager then ther
jonross 2014/11/06 18:18:52 Done.
+ service->AddConsumer(CONSUMER_TYPE_ORIENTATION);
+
+ base::SharedMemoryHandle handle = service->GetSharedMemoryHandleForProcess(
+ CONSUMER_TYPE_ORIENTATION, base::GetCurrentProcessHandle());
+ EXPECT_TRUE(base::SharedMemory::IsHandleValid(handle));
+
+ 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_TRUE(buffer->data.allAvailableSensorsAreActive);
+
+ SensorManager::GetInstance()->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);
+
+ service->RemoveConsumer(CONSUMER_TYPE_ORIENTATION);
+ EXPECT_FALSE(buffer->data.allAvailableSensorsAreActive);
+}
+
+// Tests a device resting flat.
+IN_PROC_BROWSER_TEST_F(SensorManagerTest, NeutralOrientation) {
+ DeviceInertialSensorService::GetInstance()->AddConsumer(
+ CONSUMER_TYPE_ORIENTATION);
+ SensorManager::GetInstance()->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.
+IN_PROC_BROWSER_TEST_F(SensorManagerTest, UpsideDown) {
+ DeviceInertialSensorService::GetInstance()->AddConsumer(
+ CONSUMER_TYPE_ORIENTATION);
+ SensorManager::GetInstance()->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
+IN_PROC_BROWSER_TEST_F(SensorManagerTest, BeforeUpsideDownBoundary) {
+ DeviceInertialSensorService::GetInstance()->AddConsumer(
+ CONSUMER_TYPE_ORIENTATION);
+ SensorManager::GetInstance()->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.
+IN_PROC_BROWSER_TEST_F(SensorManagerTest, LeftEdge) {
+ DeviceInertialSensorService::GetInstance()->AddConsumer(
+ CONSUMER_TYPE_ORIENTATION);
+ SensorManager::GetInstance()->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.
+IN_PROC_BROWSER_TEST_F(SensorManagerTest, RightEdge) {
+ DeviceInertialSensorService::GetInstance()->AddConsumer(
+ CONSUMER_TYPE_ORIENTATION);
+ SensorManager::GetInstance()->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.
+IN_PROC_BROWSER_TEST_F(SensorManagerTest, BeforeRightEdgeBoundary) {
+ DeviceInertialSensorService::GetInstance()->AddConsumer(
+ CONSUMER_TYPE_ORIENTATION);
+ SensorManager::GetInstance()->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

Powered by Google App Engine
This is Rietveld 408576698