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

Unified Diff: device/generic_sensor/platform_sensor_and_provider_unittest_win.cc

Issue 2495073002: [sensors] [win] Fix ambient light not working properly Windows 10. (Closed)
Patch Set: Fix unit tests Created 4 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: device/generic_sensor/platform_sensor_and_provider_unittest_win.cc
diff --git a/device/generic_sensor/platform_sensor_and_provider_unittest_win.cc b/device/generic_sensor/platform_sensor_and_provider_unittest_win.cc
index f0f44bd71c442f3767c5adfb4b824638f4af2bf5..be9995a3c411014fb4d342e604bc6850abe58c4d 100644
--- a/device/generic_sensor/platform_sensor_and_provider_unittest_win.cc
+++ b/device/generic_sensor/platform_sensor_and_provider_unittest_win.cc
@@ -221,6 +221,20 @@ class PlatformSensorAndProviderTestWin : public ::testing::Test {
return sensor;
}
+ // Listening the sensor is asynchronous, therefore inner loop is used to wait
+ // for SetEventSink to be called.
+ bool StartListening(scoped_refptr<PlatformSensor> sensor,
+ PlatformSensor::Client* client,
+ const PlatformSensorConfiguration& config) {
+ run_loop_ = base::MakeUnique<base::RunLoop>();
+ bool ret = sensor->StartListening(client, config);
+ run_loop_->Run();
+ run_loop_ = nullptr;
+ return ret;
+ }
+
+ void QuitInnerLoop() { run_loop_->Quit(); }
+
// Sets sensor with REFSENSOR_TYPE_ID |sensor| to be supported by mocked
// ISensorMager and it will be present in ISensorCollection.
void SetSupportedSensor(REFSENSOR_TYPE_ID sensor) {
@@ -258,6 +272,12 @@ class PlatformSensorAndProviderTestWin : public ::testing::Test {
.WillByDefault(Invoke([this](ISensorEvents* events) {
events->AddRef();
sensor_events_.Attach(events);
+ if (this->run_loop_) {
+ message_loop_.task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&PlatformSensorAndProviderTestWin::QuitInnerLoop,
+ base::Unretained(this)));
+ }
return S_OK;
}));
@@ -266,6 +286,12 @@ class PlatformSensorAndProviderTestWin : public ::testing::Test {
ON_CALL(*sensor_, SetEventSink(IsNull()))
.WillByDefault(Invoke([this](ISensorEvents* events) {
sensor_events_.Release();
+ if (this->run_loop_) {
+ message_loop_.task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&PlatformSensorAndProviderTestWin::QuitInnerLoop,
+ base::Unretained(this)));
+ }
return S_OK;
}));
}
@@ -417,7 +443,7 @@ TEST_F(PlatformSensorAndProviderTestWin, SensorStarted) {
EXPECT_CALL(*sensor_, SetEventSink(NotNull())).Times(1);
EXPECT_CALL(*sensor_, SetEventSink(IsNull())).Times(1);
EXPECT_CALL(*sensor_, SetProperties(NotNull(), _))
- .WillOnce(Invoke(
+ .WillRepeatedly(Invoke(
[](IPortableDeviceValues* props, IPortableDeviceValues** result) {
ULONG value = 0;
HRESULT hr = props->GetUnsignedIntegerValue(
@@ -433,12 +459,12 @@ TEST_F(PlatformSensorAndProviderTestWin, SensorStarted) {
auto client = base::MakeUnique<NiceMock<MockPlatformSensorClient>>(sensor);
PlatformSensorConfiguration configuration(10);
- EXPECT_TRUE(sensor->StartListening(client.get(), configuration));
+ EXPECT_TRUE(StartListening(sensor, client.get(), configuration));
EXPECT_CALL(*client, OnSensorReadingChanged()).Times(1);
GenerateDataUpdatedEvent(SENSOR_DATA_TYPE_LIGHT_LEVEL_LUX, 3.14);
base::RunLoop().RunUntilIdle();
- EXPECT_TRUE(sensor->StopListening(client.get(), configuration));
+ EXPECT_TRUE(sensor->StartListening(client.get(), configuration));
}
// Tests that OnSensorError is called when sensor is disconnected.
@@ -449,7 +475,7 @@ TEST_F(PlatformSensorAndProviderTestWin, SensorRemoved) {
auto client = base::MakeUnique<NiceMock<MockPlatformSensorClient>>(sensor);
PlatformSensorConfiguration configuration(10);
- EXPECT_TRUE(sensor->StartListening(client.get(), configuration));
+ EXPECT_TRUE(StartListening(sensor, client.get(), configuration));
EXPECT_CALL(*client, OnSensorError()).Times(1);
GenerateLeaveEvent();
@@ -464,7 +490,7 @@ TEST_F(PlatformSensorAndProviderTestWin, SensorStateChangedToError) {
auto client = base::MakeUnique<NiceMock<MockPlatformSensorClient>>(sensor);
PlatformSensorConfiguration configuration(10);
- EXPECT_TRUE(sensor->StartListening(client.get(), configuration));
+ EXPECT_TRUE(StartListening(sensor, client.get(), configuration));
EXPECT_CALL(*client, OnSensorError()).Times(1);
GenerateStateChangeEvent(SENSOR_STATE_ERROR);
@@ -479,7 +505,7 @@ TEST_F(PlatformSensorAndProviderTestWin, SensorStateChangedToReady) {
auto client = base::MakeUnique<NiceMock<MockPlatformSensorClient>>(sensor);
PlatformSensorConfiguration configuration(10);
- EXPECT_TRUE(sensor->StartListening(client.get(), configuration));
+ EXPECT_TRUE(StartListening(sensor, client.get(), configuration));
EXPECT_CALL(*client, OnSensorError()).Times(0);
GenerateStateChangeEvent(SENSOR_STATE_READY);
« no previous file with comments | « no previous file | device/generic_sensor/platform_sensor_reader_win.h » ('j') | device/generic_sensor/platform_sensor_reader_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698