| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/generic_sensor/fake_platform_sensor.h" | 5 #include "device/generic_sensor/fake_platform_sensor.h" |
| 6 #include "device/generic_sensor/fake_platform_sensor_provider.h" | 6 #include "device/generic_sensor/fake_platform_sensor_provider.h" |
| 7 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom.h" | 7 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom.h" |
| 8 | 8 |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace device { | 11 namespace device { |
| 12 | 12 |
| 13 using mojom::SensorInitParams; | 13 using mojom::SensorInitParams; |
| 14 using mojom::SensorType; | 14 using mojom::SensorType; |
| 15 | 15 |
| 16 namespace { | |
| 17 | |
| 18 uint64_t GetBufferOffset(mojom::SensorType type) { | |
| 19 return (static_cast<uint64_t>(SensorType::LAST) - | |
| 20 static_cast<uint64_t>(type)) * | |
| 21 SensorInitParams::kReadBufferSize; | |
| 22 } | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 class PlatformSensorTestClient : public PlatformSensor::Client { | 16 class PlatformSensorTestClient : public PlatformSensor::Client { |
| 27 public: | 17 public: |
| 28 PlatformSensorTestClient() | 18 PlatformSensorTestClient() |
| 29 : notification_suspended_(false), | 19 : notification_suspended_(false), |
| 30 sensor_reading_changed_(false), | 20 sensor_reading_changed_(false), |
| 31 sensor_error_(false) {} | 21 sensor_error_(false) {} |
| 32 | 22 |
| 33 ~PlatformSensorTestClient() override { | 23 ~PlatformSensorTestClient() override { |
| 34 if (sensor_) | 24 if (sensor_) |
| 35 sensor_->RemoveClient(this); | 25 sensor_->RemoveClient(this); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 62 bool sensor_error_; | 52 bool sensor_error_; |
| 63 }; | 53 }; |
| 64 | 54 |
| 65 class PlatformSensorProviderTest : public ::testing::Test { | 55 class PlatformSensorProviderTest : public ::testing::Test { |
| 66 public: | 56 public: |
| 67 PlatformSensorProviderTest() | 57 PlatformSensorProviderTest() |
| 68 : sensor_client_(new PlatformSensorTestClient()) {} | 58 : sensor_client_(new PlatformSensorTestClient()) {} |
| 69 | 59 |
| 70 protected: | 60 protected: |
| 71 scoped_refptr<PlatformSensor> CreateSensor(mojom::SensorType type) { | 61 scoped_refptr<PlatformSensor> CreateSensor(mojom::SensorType type) { |
| 72 return FakePlatformSensorProvider::GetInstance()->CreateSensor( | 62 return FakePlatformSensorProvider::GetInstance()->CreateSensor(type); |
| 73 type, SensorInitParams::kReadBufferSize, GetBufferOffset(type)); | |
| 74 } | 63 } |
| 75 | 64 |
| 76 std::unique_ptr<PlatformSensorTestClient> sensor_client_; | 65 std::unique_ptr<PlatformSensorTestClient> sensor_client_; |
| 77 }; | 66 }; |
| 78 | 67 |
| 79 TEST_F(PlatformSensorProviderTest, CreateSensorsAndCheckType) { | 68 TEST_F(PlatformSensorProviderTest, CreateSensorsAndCheckType) { |
| 80 scoped_refptr<PlatformSensor> sensor1 = | 69 scoped_refptr<PlatformSensor> sensor1 = |
| 81 CreateSensor(SensorType::AMBIENT_LIGHT); | 70 CreateSensor(SensorType::AMBIENT_LIGHT); |
| 82 EXPECT_TRUE(sensor1); | 71 EXPECT_TRUE(sensor1); |
| 83 EXPECT_EQ(SensorType::AMBIENT_LIGHT, sensor1->GetType()); | 72 EXPECT_EQ(SensorType::AMBIENT_LIGHT, sensor1->GetType()); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 sensor_client_->set_notification_suspended(false); | 298 sensor_client_->set_notification_suspended(false); |
| 310 EXPECT_FALSE(sensor_client_->IsNotificationSuspended()); | 299 EXPECT_FALSE(sensor_client_->IsNotificationSuspended()); |
| 311 for (const auto& client : clients) | 300 for (const auto& client : clients) |
| 312 EXPECT_FALSE(client->IsNotificationSuspended()); | 301 EXPECT_FALSE(client->IsNotificationSuspended()); |
| 313 | 302 |
| 314 fake_sensor->UpdateSensor(); | 303 fake_sensor->UpdateSensor(); |
| 315 EXPECT_TRUE(fake_sensor->started()); | 304 EXPECT_TRUE(fake_sensor->started()); |
| 316 } | 305 } |
| 317 | 306 |
| 318 } // namespace device | 307 } // namespace device |
| OLD | NEW |