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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 | 8 |
9 #include "device/generic_sensor/fake_platform_sensor.h" | 9 #include "device/generic_sensor/fake_platform_sensor.h" |
10 #include "device/generic_sensor/fake_platform_sensor_provider.h" | 10 #include "device/generic_sensor/fake_platform_sensor_provider.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 provider_->CreateSensor(type, callback->callback()); | 98 provider_->CreateSensor(type, callback->callback()); |
99 return callback->WaitForResult(); | 99 return callback->WaitForResult(); |
100 } | 100 } |
101 | 101 |
102 std::unique_ptr<FakePlatformSensorProvider> provider_; | 102 std::unique_ptr<FakePlatformSensorProvider> provider_; |
103 std::unique_ptr<PlatformSensorTestClient> sensor_client_; | 103 std::unique_ptr<PlatformSensorTestClient> sensor_client_; |
104 std::unique_ptr<base::MessageLoop> message_loop_; | 104 std::unique_ptr<base::MessageLoop> message_loop_; |
105 }; | 105 }; |
106 | 106 |
107 TEST_F(PlatformSensorProviderTest, CreateSensorsAndCheckType) { | 107 TEST_F(PlatformSensorProviderTest, CreateSensorsAndCheckType) { |
108 TestSensorCreateCallback callback1; | 108 { |
109 scoped_refptr<PlatformSensor> sensor1 = | 109 TestSensorCreateCallback callback; |
110 CreateSensor(SensorType::AMBIENT_LIGHT, &callback1); | 110 scoped_refptr<PlatformSensor> sensor = |
111 EXPECT_TRUE(sensor1); | 111 CreateSensor(SensorType::AMBIENT_LIGHT, &callback); |
112 EXPECT_EQ(SensorType::AMBIENT_LIGHT, sensor1->GetType()); | 112 EXPECT_TRUE(sensor); |
| 113 EXPECT_EQ(SensorType::AMBIENT_LIGHT, sensor->GetType()); |
| 114 } |
113 | 115 |
114 TestSensorCreateCallback callback2; | 116 { |
115 scoped_refptr<PlatformSensor> sensor2 = | 117 TestSensorCreateCallback callback; |
116 CreateSensor(SensorType::PROXIMITY, &callback2); | 118 scoped_refptr<PlatformSensor> sensor = |
117 EXPECT_TRUE(sensor2); | 119 CreateSensor(SensorType::PROXIMITY, &callback); |
118 EXPECT_EQ(SensorType::PROXIMITY, sensor2->GetType()); | 120 EXPECT_TRUE(sensor); |
| 121 EXPECT_EQ(SensorType::PROXIMITY, sensor->GetType()); |
| 122 } |
119 | 123 |
120 TestSensorCreateCallback callback3; | 124 { |
121 scoped_refptr<PlatformSensor> sensor3 = | 125 TestSensorCreateCallback callback; |
122 CreateSensor(SensorType::ACCELEROMETER, &callback3); | 126 scoped_refptr<PlatformSensor> sensor = |
123 EXPECT_TRUE(sensor3); | 127 CreateSensor(SensorType::ACCELEROMETER, &callback); |
124 EXPECT_EQ(SensorType::ACCELEROMETER, sensor3->GetType()); | 128 EXPECT_TRUE(sensor); |
| 129 EXPECT_EQ(SensorType::ACCELEROMETER, sensor->GetType()); |
| 130 } |
125 | 131 |
126 TestSensorCreateCallback callback4; | 132 { |
127 scoped_refptr<PlatformSensor> sensor4 = | 133 TestSensorCreateCallback callback; |
128 CreateSensor(SensorType::GYROSCOPE, &callback4); | 134 scoped_refptr<PlatformSensor> sensor = |
129 EXPECT_TRUE(sensor4); | 135 CreateSensor(SensorType::LINEAR_ACCELERATION, &callback); |
130 EXPECT_EQ(SensorType::GYROSCOPE, sensor4->GetType()); | 136 EXPECT_TRUE(sensor); |
| 137 EXPECT_EQ(SensorType::LINEAR_ACCELERATION, sensor->GetType()); |
| 138 } |
131 | 139 |
132 TestSensorCreateCallback callback5; | 140 { |
133 scoped_refptr<PlatformSensor> sensor5 = | 141 TestSensorCreateCallback callback; |
134 CreateSensor(SensorType::PRESSURE, &callback5); | 142 scoped_refptr<PlatformSensor> sensor = |
135 EXPECT_TRUE(sensor5); | 143 CreateSensor(SensorType::GYROSCOPE, &callback); |
136 EXPECT_EQ(SensorType::PRESSURE, sensor5->GetType()); | 144 EXPECT_TRUE(sensor); |
| 145 EXPECT_EQ(SensorType::GYROSCOPE, sensor->GetType()); |
| 146 } |
| 147 |
| 148 { |
| 149 TestSensorCreateCallback callback; |
| 150 scoped_refptr<PlatformSensor> sensor = |
| 151 CreateSensor(SensorType::MAGNETOMETER, &callback); |
| 152 EXPECT_TRUE(sensor); |
| 153 EXPECT_EQ(SensorType::MAGNETOMETER, sensor->GetType()); |
| 154 } |
| 155 |
| 156 { |
| 157 TestSensorCreateCallback callback; |
| 158 scoped_refptr<PlatformSensor> sensor = |
| 159 CreateSensor(SensorType::PRESSURE, &callback); |
| 160 EXPECT_TRUE(sensor); |
| 161 EXPECT_EQ(SensorType::PRESSURE, sensor->GetType()); |
| 162 } |
| 163 |
| 164 { |
| 165 TestSensorCreateCallback callback; |
| 166 scoped_refptr<PlatformSensor> sensor = |
| 167 CreateSensor(SensorType::ABSOLUTE_ORIENTATION, &callback); |
| 168 EXPECT_TRUE(sensor); |
| 169 EXPECT_EQ(SensorType::ABSOLUTE_ORIENTATION, sensor->GetType()); |
| 170 } |
| 171 |
| 172 { |
| 173 TestSensorCreateCallback callback; |
| 174 scoped_refptr<PlatformSensor> sensor = |
| 175 CreateSensor(SensorType::RELATIVE_ORIENTATION, &callback); |
| 176 EXPECT_TRUE(sensor); |
| 177 EXPECT_EQ(SensorType::RELATIVE_ORIENTATION, sensor->GetType()); |
| 178 } |
137 } | 179 } |
138 | 180 |
139 TEST_F(PlatformSensorProviderTest, CreateAndGetSensor) { | 181 TEST_F(PlatformSensorProviderTest, CreateAndGetSensor) { |
140 // Create Ambient Light sensor. | 182 // Create Ambient Light sensor. |
141 TestSensorCreateCallback callback1; | 183 TestSensorCreateCallback callback1; |
142 scoped_refptr<PlatformSensor> sensor1 = | 184 scoped_refptr<PlatformSensor> sensor1 = |
143 CreateSensor(SensorType::AMBIENT_LIGHT, &callback1); | 185 CreateSensor(SensorType::AMBIENT_LIGHT, &callback1); |
144 EXPECT_TRUE(sensor1); | 186 EXPECT_TRUE(sensor1); |
145 EXPECT_EQ(SensorType::AMBIENT_LIGHT, sensor1->GetType()); | 187 EXPECT_EQ(SensorType::AMBIENT_LIGHT, sensor1->GetType()); |
146 | 188 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 sensor_client_->set_notification_suspended(false); | 401 sensor_client_->set_notification_suspended(false); |
360 EXPECT_FALSE(sensor_client_->IsNotificationSuspended()); | 402 EXPECT_FALSE(sensor_client_->IsNotificationSuspended()); |
361 for (const auto& client : clients) | 403 for (const auto& client : clients) |
362 EXPECT_FALSE(client->IsNotificationSuspended()); | 404 EXPECT_FALSE(client->IsNotificationSuspended()); |
363 | 405 |
364 fake_sensor->UpdateSensor(); | 406 fake_sensor->UpdateSensor(); |
365 EXPECT_TRUE(fake_sensor->started()); | 407 EXPECT_TRUE(fake_sensor->started()); |
366 } | 408 } |
367 | 409 |
368 } // namespace device | 410 } // namespace device |
OLD | NEW |