chromium/services/device/generic_sensor/platform_sensor_and_provider_unittest_linux.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include <algorithm>
#include <memory>

#include "base/barrier_closure.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/shared_memory_mapping.h"
#include "base/numerics/math_constants.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "base/threading/thread_restrictions.h"
#include "build/chromeos_buildflags.h"
#include "services/device/generic_sensor/generic_sensor_consts.h"
#include "services/device/generic_sensor/linux/sensor_data_linux.h"
#include "services/device/generic_sensor/linux/sensor_device_manager.h"
#include "services/device/generic_sensor/platform_sensor_provider_linux.h"
#include "services/device/generic_sensor/platform_sensor_util.h"
#include "services/device/public/cpp/generic_sensor/sensor_reading_shared_buffer.h"
#include "services/device/public/cpp/generic_sensor/sensor_traits.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

TestFuture;
_;
Invoke;
IsNull;
NiceMock;
NotNull;
Return;

namespace device {

namespace {

SensorType;

constexpr size_t kSensorValuesSize =;

// Zero value can mean whether value is not being not used or zero value.
constexpr double kZero =;

constexpr double kAmbientLightFrequencyValue =;

constexpr double kAccelerometerFrequencyValue =;
constexpr double kAccelerometerOffsetValue =;
constexpr double kAccelerometerScalingValue =;

constexpr double kGyroscopeFrequencyValue =;
constexpr double kGyroscopeOffsetValue =;
constexpr double kGyroscopeScalingValue =;

constexpr double kMagnetometerFrequencyValue =;
constexpr double kMagnetometerOffsetValue =;
constexpr double kMagnetometerScalingValue =;

void WriteValueToFile(const base::FilePath& path, double value) {}

std::string ReadValueFromFile(const base::FilePath& path,
                              const std::string& file) {}

double RoundAccelerometerValue(double value) {}

double RoundGyroscopeValue(double value) {}

double RoundMagnetometerValue(double value) {}

}  // namespace

// Mock for SensorDeviceService that SensorDeviceManager owns.
// This mock is used to emulate udev events and send found sensor devices
// to SensorDeviceManager.
class MockSensorDeviceManager : public SensorDeviceManager {};

// Mock for PlatformSensor's client interface that is used to deliver
// error and data changes notifications.
class LinuxMockPlatformSensorClient : public PlatformSensor::Client {};

class PlatformSensorAndProviderLinuxTest : public ::testing::Test {};

// Tests sensor is not returned if not implemented.
TEST_F(PlatformSensorAndProviderLinuxTest, SensorIsNotImplemented) {}

// Tests sensor is not returned if not supported by hardware.
TEST_F(PlatformSensorAndProviderLinuxTest, SensorIsNotSupported) {}

// Tests sensor is returned if supported.
TEST_F(PlatformSensorAndProviderLinuxTest, SensorIsSupported) {}

// Tests that PlatformSensor::StartListening fails when provided reporting
// frequency is above hardware capabilities.
TEST_F(PlatformSensorAndProviderLinuxTest, StartFails) {}

// Tests that PlatformSensor::StartListening succeeds and notification about
// modified sensor reading is sent to the PlatformSensor::Client interface.
TEST_F(PlatformSensorAndProviderLinuxTest, SensorStarted) {}

// Tests that OnSensorError is called when sensor is disconnected.
TEST_F(PlatformSensorAndProviderLinuxTest, SensorRemoved) {}

// Tests that sensor is not returned if not connected and
// is created after it has been added.
TEST_F(PlatformSensorAndProviderLinuxTest, SensorAddedAndRemoved) {}

// Checks the main fields of all sensors and initialized right.
TEST_F(PlatformSensorAndProviderLinuxTest, CheckAllSupportedSensors) {}

// Tests that GetMaximumSupportedFrequency provides correct value.
TEST_F(PlatformSensorAndProviderLinuxTest, GetMaximumSupportedFrequency) {}

// Tests that GetMaximumSupportedFrequency provides correct value when
// OS does not provide any information about frequency.
TEST_F(PlatformSensorAndProviderLinuxTest,
       GetMaximumSupportedFrequencyDefault) {}

// Tests that Ambient Light sensor is correctly read.
TEST_F(PlatformSensorAndProviderLinuxTest, CheckAmbientLightReadings) {}

// Tests that Accelerometer readings are correctly converted.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckAccelerometerReadingConversion) {}

// Tests that LinearAcceleration sensor is not created if its source sensor is
// not available.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckLinearAccelerationSensorNotCreatedIfNoAccelerometer) {}

// Tests that LinearAcceleration sensor is successfully created and works.
TEST_F(PlatformSensorAndProviderLinuxTest, CheckLinearAcceleration) {}

// Tests that Gyroscope readings are correctly converted.
TEST_F(PlatformSensorAndProviderLinuxTest, CheckGyroscopeReadingConversion) {}

// Tests that Magnetometer readings are correctly converted.
TEST_F(PlatformSensorAndProviderLinuxTest, CheckMagnetometerReadingConversion) {}

// Tests that Ambient Light sensor client's OnSensorReadingChanged() is called
// when the Ambient Light sensor's reporting mode is
// mojom::ReportingMode::CONTINUOUS.
TEST_F(PlatformSensorAndProviderLinuxTest,
       SensorClientGetReadingChangedNotificationWhenSensorIsInContinuousMode) {}

// Tests that ABSOLUTE_ORIENTATION_EULER_ANGLES/ABSOLUTE_ORIENTATION_QUATERNION
// sensor is not created if both of its source sensors are not available.
TEST_F(
    PlatformSensorAndProviderLinuxTest,
    CheckAbsoluteOrientationSensorNotCreatedIfNoAccelerometerAndNoMagnetometer) {}

// Tests that ABSOLUTE_ORIENTATION_EULER_ANGLES/ABSOLUTE_ORIENTATION_QUATERNION
// sensor is not created if accelerometer is not available.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckAbsoluteOrientationSensorNotCreatedIfNoAccelerometer) {}

// Tests that ABSOLUTE_ORIENTATION_EULER_ANGLES/ABSOLUTE_ORIENTATION_QUATERNION
// sensor is not created if magnetometer is not available.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckAbsoluteOrientationSensorNotCreatedIfNoMagnetometer) {}

// Tests that ABSOLUTE_ORIENTATION_EULER_ANGLES sensor is successfully created.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckAbsoluteOrientationEulerAnglesSensor) {}

// Tests that ABSOLUTE_ORIENTATION_QUATERNION sensor is successfully created.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckAbsoluteOrientationQuaternionSensor) {}

// Tests that RELATIVE_ORIENTATION_EULER_ANGLES/RELATIVE_ORIENTATION_QUATERNION
// sensor is not created if both accelerometer and gyroscope are not available.
TEST_F(
    PlatformSensorAndProviderLinuxTest,
    CheckRelativeOrientationSensorNotCreatedIfNoAccelerometerAndNoGyroscope) {}

// Tests that RELATIVE_ORIENTATION_EULER_ANGLES/RELATIVE_ORIENTATION_QUATERNION
// sensor is not created if accelerometer is not available.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckRelativeOrientationSensorNotCreatedIfNoAccelerometer) {}

// Tests that RELATIVE_ORIENTATION_EULER_ANGLES sensor is successfully created
// if both accelerometer and gyroscope are available.
TEST_F(
    PlatformSensorAndProviderLinuxTest,
    CheckRelativeOrientationEulerAnglesSensorUsingAccelerometerAndGyroscope) {}

// Tests that RELATIVE_ORIENTATION_EULER_ANGLES sensor is successfully created
// if only accelerometer is available.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckRelativeOrientationEulerAnglesSensorUsingAccelerometer) {}

// Tests that RELATIVE_ORIENTATION_QUATERNION sensor is successfully created if
// both accelerometer and gyroscope are available.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckRelativeOrientationQuaternionSensorUsingAccelerometerAndGyroscope) {}

// Tests that RELATIVE_ORIENTATION_QUATERNION sensor is successfully created if
// only accelerometer is available.
TEST_F(PlatformSensorAndProviderLinuxTest,
       CheckRelativeOrientationQuaternionSensorUsingAccelerometer) {}

// https://crbug.com/1254396: Make sure sensor enumeration steps happen in the
// right order. This could be converted into a web test in the future if we
// stop using mocks there (just setting window.ondevicemotion is enough to
// trigger similar behavior).
TEST_F(PlatformSensorAndProviderLinuxTest,
       AccelerometerAndLinearAccelerationEnumeration) {}

// Tests that queued sensor creation requests are all processed.
TEST_F(PlatformSensorAndProviderLinuxTest, SensorCreationQueueManagement) {}

// Tests that there are no crashes if PlatformSensorProviderLinux is destroyed
// before DidEnumerateSensors() is called.
TEST_F(PlatformSensorAndProviderLinuxTest, EarlyProviderDeletion) {}

}  // namespace device