Commit 8940ca98 authored by Wenjie Shi's avatar Wenjie Shi Committed by Commit Bot

Fix invalid PlatformSensorReaderWinrt creation due to bad switch case

The PlatformSensorReaderWinrtBase::IsSensorCreateSuccess function has a
switch case that determines whether a PlatformSensorReader was
successfully created.

The kErrorGetMinReportIntervalFailed (which is not fatal) and
kErrorISensorWinrtStaticsActivationFailedcases (which is fatal) cases
should have been swapped.

This is causing a non-null PlatformSensorReader to be returned, but
the underlying WinRT sensor object was null which triggers a null
pointer deference the next time it is used.

The fix is to swap the switch cases.

Verified by running the new unit test.

Bug: 1020987
Change-Id: Ia9ac960fb95de0b028677c1ff97b632aecd0b6f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1904503
Commit-Queue: Wenjie Shi <wensh@microsoft.com>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713672}
parent 392a873c
...@@ -126,35 +126,6 @@ void PlatformSensorReaderWinrtBase< ...@@ -126,35 +126,6 @@ void PlatformSensorReaderWinrtBase<
client_ = client; client_ = client;
} }
// static
template <wchar_t const* runtime_class_id,
class ISensorWinrtStatics,
class ISensorWinrtClass,
class ISensorReadingChangedHandler,
class ISensorReadingChangedEventArgs>
bool PlatformSensorReaderWinrtBase<runtime_class_id,
ISensorWinrtStatics,
ISensorWinrtClass,
ISensorReadingChangedHandler,
ISensorReadingChangedEventArgs>::
IsSensorCreateSuccess(SensorWinrtCreateFailure create_return_code) {
switch (create_return_code) {
case SensorWinrtCreateFailure::kErrorISensorWinrtStaticsActivationFailed:
// Failing to query the default report interval is not a fatal error. The
// consumer (PlatformSensorWin) should be able to handle this and return a
// default report interval instead.
FALLTHROUGH;
case SensorWinrtCreateFailure::kOk:
return true;
case SensorWinrtCreateFailure::kErrorGetDefaultSensorFailed:
FALLTHROUGH;
case SensorWinrtCreateFailure::kErrorDefaultSensorNull:
FALLTHROUGH;
case SensorWinrtCreateFailure::kErrorGetMinReportIntervalFailed:
return false;
}
}
template <wchar_t const* runtime_class_id, template <wchar_t const* runtime_class_id,
class ISensorWinrtStatics, class ISensorWinrtStatics,
class ISensorWinrtClass, class ISensorWinrtClass,
...@@ -183,35 +154,42 @@ template <wchar_t const* runtime_class_id, ...@@ -183,35 +154,42 @@ template <wchar_t const* runtime_class_id,
class ISensorWinrtClass, class ISensorWinrtClass,
class ISensorReadingChangedHandler, class ISensorReadingChangedHandler,
class ISensorReadingChangedEventArgs> class ISensorReadingChangedEventArgs>
SensorWinrtCreateFailure bool PlatformSensorReaderWinrtBase<
PlatformSensorReaderWinrtBase<runtime_class_id, runtime_class_id,
ISensorWinrtStatics, ISensorWinrtStatics,
ISensorWinrtClass, ISensorWinrtClass,
ISensorReadingChangedHandler, ISensorReadingChangedHandler,
ISensorReadingChangedEventArgs>::Initialize() { ISensorReadingChangedEventArgs>::Initialize() {
ComPtr<ISensorWinrtStatics> sensor_statics; ComPtr<ISensorWinrtStatics> sensor_statics;
HRESULT hr = get_sensor_factory_callback_.Run(&sensor_statics); HRESULT hr = get_sensor_factory_callback_.Run(&sensor_statics);
if (FAILED(hr)) if (FAILED(hr)) {
return SensorWinrtCreateFailure::kErrorISensorWinrtStaticsActivationFailed; DLOG(ERROR) << "Failed to get sensor activation factory: "
<< logging::SystemErrorCodeToString(hr);
return false;
}
hr = sensor_statics->GetDefault(&sensor_); hr = sensor_statics->GetDefault(&sensor_);
base::UmaHistogramSparse("Sensors.Windows.WinRT.Activation.Result", hr); base::UmaHistogramSparse("Sensors.Windows.WinRT.Activation.Result", hr);
if (FAILED(hr)) { if (FAILED(hr)) {
return SensorWinrtCreateFailure::kErrorGetDefaultSensorFailed; DLOG(ERROR) << "Failed to query default sensor: "
<< logging::SystemErrorCodeToString(hr);
return false;
} }
// GetDefault() returns null if the sensor does not exist // GetDefault() returns null if the sensor does not exist
if (!sensor_) if (!sensor_) {
return SensorWinrtCreateFailure::kErrorDefaultSensorNull; VLOG(1) << "Sensor does not exist on system";
return false;
}
minimum_report_interval_ = GetMinimumReportIntervalFromSensor(); minimum_report_interval_ = GetMinimumReportIntervalFromSensor();
if (minimum_report_interval_.is_zero()) if (minimum_report_interval_.is_zero())
return SensorWinrtCreateFailure::kErrorGetMinReportIntervalFailed; DLOG(WARNING) << "Failed to get sensor minimum report interval";
return SensorWinrtCreateFailure::kOk; return true;
} }
template <wchar_t const* runtime_class_id, template <wchar_t const* runtime_class_id,
...@@ -348,7 +326,7 @@ PlatformSensorReaderWinrtBase< ...@@ -348,7 +326,7 @@ PlatformSensorReaderWinrtBase<
std::unique_ptr<PlatformSensorReaderWinBase> std::unique_ptr<PlatformSensorReaderWinBase>
PlatformSensorReaderWinrtLightSensor::Create() { PlatformSensorReaderWinrtLightSensor::Create() {
auto light_sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>(); auto light_sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>();
if (IsSensorCreateSuccess(light_sensor->Initialize())) { if (light_sensor->Initialize()) {
return light_sensor; return light_sensor;
} }
return nullptr; return nullptr;
...@@ -406,7 +384,7 @@ std::unique_ptr<PlatformSensorReaderWinBase> ...@@ -406,7 +384,7 @@ std::unique_ptr<PlatformSensorReaderWinBase>
PlatformSensorReaderWinrtAccelerometer::Create() { PlatformSensorReaderWinrtAccelerometer::Create() {
auto accelerometer = auto accelerometer =
std::make_unique<PlatformSensorReaderWinrtAccelerometer>(); std::make_unique<PlatformSensorReaderWinrtAccelerometer>();
if (IsSensorCreateSuccess(accelerometer->Initialize())) { if (accelerometer->Initialize()) {
return accelerometer; return accelerometer;
} }
return nullptr; return nullptr;
...@@ -486,7 +464,7 @@ HRESULT PlatformSensorReaderWinrtAccelerometer::OnReadingChangedCallback( ...@@ -486,7 +464,7 @@ HRESULT PlatformSensorReaderWinrtAccelerometer::OnReadingChangedCallback(
std::unique_ptr<PlatformSensorReaderWinBase> std::unique_ptr<PlatformSensorReaderWinBase>
PlatformSensorReaderWinrtGyrometer::Create() { PlatformSensorReaderWinrtGyrometer::Create() {
auto gyrometer = std::make_unique<PlatformSensorReaderWinrtGyrometer>(); auto gyrometer = std::make_unique<PlatformSensorReaderWinrtGyrometer>();
if (IsSensorCreateSuccess(gyrometer->Initialize())) { if (gyrometer->Initialize()) {
return gyrometer; return gyrometer;
} }
return nullptr; return nullptr;
...@@ -565,7 +543,7 @@ HRESULT PlatformSensorReaderWinrtGyrometer::OnReadingChangedCallback( ...@@ -565,7 +543,7 @@ HRESULT PlatformSensorReaderWinrtGyrometer::OnReadingChangedCallback(
std::unique_ptr<PlatformSensorReaderWinBase> std::unique_ptr<PlatformSensorReaderWinBase>
PlatformSensorReaderWinrtMagnetometer::Create() { PlatformSensorReaderWinrtMagnetometer::Create() {
auto magnetometer = std::make_unique<PlatformSensorReaderWinrtMagnetometer>(); auto magnetometer = std::make_unique<PlatformSensorReaderWinrtMagnetometer>();
if (IsSensorCreateSuccess(magnetometer->Initialize())) { if (magnetometer->Initialize()) {
return magnetometer; return magnetometer;
} }
return nullptr; return nullptr;
...@@ -642,7 +620,7 @@ std::unique_ptr<PlatformSensorReaderWinBase> ...@@ -642,7 +620,7 @@ std::unique_ptr<PlatformSensorReaderWinBase>
PlatformSensorReaderWinrtAbsOrientationEulerAngles::Create() { PlatformSensorReaderWinrtAbsOrientationEulerAngles::Create() {
auto inclinometer = auto inclinometer =
std::make_unique<PlatformSensorReaderWinrtAbsOrientationEulerAngles>(); std::make_unique<PlatformSensorReaderWinrtAbsOrientationEulerAngles>();
if (IsSensorCreateSuccess(inclinometer->Initialize())) { if (inclinometer->Initialize()) {
return inclinometer; return inclinometer;
} }
return nullptr; return nullptr;
...@@ -720,7 +698,7 @@ std::unique_ptr<PlatformSensorReaderWinBase> ...@@ -720,7 +698,7 @@ std::unique_ptr<PlatformSensorReaderWinBase>
PlatformSensorReaderWinrtAbsOrientationQuaternion::Create() { PlatformSensorReaderWinrtAbsOrientationQuaternion::Create() {
auto orientation = auto orientation =
std::make_unique<PlatformSensorReaderWinrtAbsOrientationQuaternion>(); std::make_unique<PlatformSensorReaderWinrtAbsOrientationQuaternion>();
if (IsSensorCreateSuccess(orientation->Initialize())) { if (orientation->Initialize()) {
return orientation; return orientation;
} }
return nullptr; return nullptr;
......
...@@ -32,14 +32,6 @@ class PlatformSensorReaderWinrtFactory { ...@@ -32,14 +32,6 @@ class PlatformSensorReaderWinrtFactory {
mojom::SensorType type); mojom::SensorType type);
}; };
enum SensorWinrtCreateFailure {
kOk = 0,
kErrorISensorWinrtStaticsActivationFailed = 1,
kErrorGetDefaultSensorFailed = 2,
kErrorDefaultSensorNull = 3,
kErrorGetMinReportIntervalFailed = 4
};
// Base class that contains common helper functions used between all low // Base class that contains common helper functions used between all low
// level sensor types based on the Windows.Devices.Sensors API. Derived // level sensor types based on the Windows.Devices.Sensors API. Derived
// classes will specialize the template into a specific sensor. See // classes will specialize the template into a specific sensor. See
...@@ -65,11 +57,15 @@ class PlatformSensorReaderWinrtBase : public PlatformSensorReaderWinBase { ...@@ -65,11 +57,15 @@ class PlatformSensorReaderWinrtBase : public PlatformSensorReaderWinBase {
// Allows tests to specify their own implementation of the underlying sensor. // Allows tests to specify their own implementation of the underlying sensor.
// This function should be called before Initialize(). // This function should be called before Initialize().
void InitForTests(GetSensorFactoryFunctor get_sensor_factory_callback) { void InitForTesting(GetSensorFactoryFunctor get_sensor_factory_callback) {
get_sensor_factory_callback_ = get_sensor_factory_callback; get_sensor_factory_callback_ = get_sensor_factory_callback;
} }
SensorWinrtCreateFailure Initialize() WARN_UNUSED_RESULT; // Returns true if the underlying WinRT sensor object is valid, meant
// for testing purposes.
bool IsUnderlyingWinrtObjectValidForTesting() { return sensor_; }
bool Initialize() WARN_UNUSED_RESULT;
bool StartSensor(const PlatformSensorConfiguration& configuration) override bool StartSensor(const PlatformSensorConfiguration& configuration) override
WARN_UNUSED_RESULT; WARN_UNUSED_RESULT;
...@@ -80,11 +76,6 @@ class PlatformSensorReaderWinrtBase : public PlatformSensorReaderWinBase { ...@@ -80,11 +76,6 @@ class PlatformSensorReaderWinrtBase : public PlatformSensorReaderWinBase {
PlatformSensorReaderWinrtBase(); PlatformSensorReaderWinrtBase();
virtual ~PlatformSensorReaderWinrtBase(); virtual ~PlatformSensorReaderWinrtBase();
// Determines if the SensorWinrtCreateFailure code means a WinRT sensor
// was successfully created or not.
static bool IsSensorCreateSuccess(
SensorWinrtCreateFailure create_return_code);
// Derived classes should implement this function to handle sensor specific // Derived classes should implement this function to handle sensor specific
// parsing of the sensor reading. // parsing of the sensor reading.
virtual HRESULT OnReadingChangedCallback( virtual HRESULT OnReadingChangedCallback(
......
...@@ -558,23 +558,31 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedSensorCreate) { ...@@ -558,23 +558,31 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedSensorCreate) {
ABI::Windows::Devices::Sensors::ILightSensorReadingChangedEventArgs, ABI::Windows::Devices::Sensors::ILightSensorReadingChangedEventArgs,
ABI::Windows::Devices::Sensors::LightSensorReadingChangedEventArgs>>(); ABI::Windows::Devices::Sensors::LightSensorReadingChangedEventArgs>>();
// Case: sensor was created successfully
auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_TRUE(sensor->Initialize());
EXPECT_TRUE(sensor->IsUnderlyingWinrtObjectValidForTesting());
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); // Case: failed to query sensor
fake_sensor_factory->SetGetDefaultReturnCode(E_FAIL); fake_sensor_factory->SetGetDefaultReturnCode(E_FAIL);
EXPECT_EQ(sensor->Initialize(), EXPECT_FALSE(sensor->Initialize());
SensorWinrtCreateFailure::kErrorGetDefaultSensorFailed); EXPECT_FALSE(sensor->IsUnderlyingWinrtObjectValidForTesting());
fake_sensor_factory->SetGetDefaultReturnCode(S_OK);
// Case: Sensor does not exist on system
fake_sensor_factory->fake_sensor_ = nullptr;
EXPECT_FALSE(sensor->Initialize());
EXPECT_FALSE(sensor->IsUnderlyingWinrtObjectValidForTesting());
sensor->InitForTests(base::BindLambdaForTesting( // Case:: failed to activate sensor factory
sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory)
-> HRESULT { return E_FAIL; })); -> HRESULT { return E_FAIL; }));
EXPECT_EQ( EXPECT_FALSE(sensor->Initialize());
sensor->Initialize(), EXPECT_FALSE(sensor->IsUnderlyingWinrtObjectValidForTesting());
SensorWinrtCreateFailure::kErrorISensorWinrtStaticsActivationFailed);
} }
// Tests that PlatformSensorReaderWinrtBase returns the right // Tests that PlatformSensorReaderWinrtBase returns the right
...@@ -590,10 +598,10 @@ TEST_F(PlatformSensorReaderTestWinrt, SensorMinimumReportInterval) { ...@@ -590,10 +598,10 @@ TEST_F(PlatformSensorReaderTestWinrt, SensorMinimumReportInterval) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
EXPECT_EQ(sensor->GetMinimalReportingInterval().InMilliseconds(), EXPECT_EQ(sensor->GetMinimalReportingInterval().InMilliseconds(),
kExpectedMinimumReportInterval); kExpectedMinimumReportInterval);
...@@ -613,11 +621,10 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedSensorMinimumReportInterval) { ...@@ -613,11 +621,10 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedSensorMinimumReportInterval) {
auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>();
fake_sensor->SetGetMinimumReportIntervalReturnCode(E_FAIL); fake_sensor->SetGetMinimumReportIntervalReturnCode(E_FAIL);
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), EXPECT_TRUE(sensor->Initialize());
SensorWinrtCreateFailure::kErrorGetMinReportIntervalFailed);
EXPECT_EQ(sensor->GetMinimalReportingInterval().InMilliseconds(), 0); EXPECT_EQ(sensor->GetMinimalReportingInterval().InMilliseconds(), 0);
} }
...@@ -636,10 +643,10 @@ TEST_F(PlatformSensorReaderTestWinrt, SensorTimestampConversion) { ...@@ -636,10 +643,10 @@ TEST_F(PlatformSensorReaderTestWinrt, SensorTimestampConversion) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
...@@ -688,10 +695,10 @@ TEST_F(PlatformSensorReaderTestWinrt, StartStopSensorCallbacks) { ...@@ -688,10 +695,10 @@ TEST_F(PlatformSensorReaderTestWinrt, StartStopSensorCallbacks) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
PlatformSensorConfiguration sensor_config(kExpectedReportFrequencySet); PlatformSensorConfiguration sensor_config(kExpectedReportFrequencySet);
EXPECT_TRUE(sensor->StartSensor(sensor_config)); EXPECT_TRUE(sensor->StartSensor(sensor_config));
...@@ -722,10 +729,10 @@ TEST_F(PlatformSensorReaderTestWinrt, StartWithoutStopSensorCallbacks) { ...@@ -722,10 +729,10 @@ TEST_F(PlatformSensorReaderTestWinrt, StartWithoutStopSensorCallbacks) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
PlatformSensorConfiguration sensor_config(kExpectedReportFrequencySet); PlatformSensorConfiguration sensor_config(kExpectedReportFrequencySet);
EXPECT_TRUE(sensor->StartSensor(sensor_config)); EXPECT_TRUE(sensor->StartSensor(sensor_config));
...@@ -748,10 +755,10 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedSensorStart) { ...@@ -748,10 +755,10 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedSensorStart) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
fake_sensor->SetPutReportIntervalReturnCode(E_FAIL); fake_sensor->SetPutReportIntervalReturnCode(E_FAIL);
...@@ -777,10 +784,10 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedSensorStop) { ...@@ -777,10 +784,10 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedSensorStop) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
PlatformSensorConfiguration sensor_config(kExpectedReportFrequencySet); PlatformSensorConfiguration sensor_config(kExpectedReportFrequencySet);
EXPECT_TRUE(sensor->StartSensor(sensor_config)); EXPECT_TRUE(sensor->StartSensor(sensor_config));
...@@ -803,10 +810,10 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedLightSensorSampleParse) { ...@@ -803,10 +810,10 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedLightSensorSampleParse) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
...@@ -844,10 +851,10 @@ TEST_F(PlatformSensorReaderTestWinrt, SensorClientNotification) { ...@@ -844,10 +851,10 @@ TEST_F(PlatformSensorReaderTestWinrt, SensorClientNotification) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
...@@ -886,12 +893,12 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckAccelerometerReadingConversion) { ...@@ -886,12 +893,12 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckAccelerometerReadingConversion) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtAccelerometer>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtAccelerometer>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::IAccelerometerStatics** [&](ABI::Windows::Devices::Sensors::IAccelerometerStatics**
sensor_factory) -> HRESULT { sensor_factory) -> HRESULT {
return fake_sensor_factory.CopyTo(sensor_factory); return fake_sensor_factory.CopyTo(sensor_factory);
})); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
EXPECT_CALL(*mock_client, OnReadingUpdated(::testing::_)) EXPECT_CALL(*mock_client, OnReadingUpdated(::testing::_))
...@@ -927,12 +934,12 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedAccelerometerSampleParse) { ...@@ -927,12 +934,12 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedAccelerometerSampleParse) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtAccelerometer>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtAccelerometer>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::IAccelerometerStatics** [&](ABI::Windows::Devices::Sensors::IAccelerometerStatics**
sensor_factory) -> HRESULT { sensor_factory) -> HRESULT {
return fake_sensor_factory.CopyTo(sensor_factory); return fake_sensor_factory.CopyTo(sensor_factory);
})); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
sensor->SetClient(mock_client.get()); sensor->SetClient(mock_client.get());
...@@ -976,10 +983,10 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckGyrometerReadingConversion) { ...@@ -976,10 +983,10 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckGyrometerReadingConversion) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtGyrometer>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtGyrometer>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::IGyrometerStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::IGyrometerStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
EXPECT_CALL(*mock_client, OnReadingUpdated(::testing::_)) EXPECT_CALL(*mock_client, OnReadingUpdated(::testing::_))
...@@ -1013,10 +1020,10 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedGyrometerSampleParse) { ...@@ -1013,10 +1020,10 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedGyrometerSampleParse) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtGyrometer>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtGyrometer>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::IGyrometerStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::IGyrometerStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
sensor->SetClient(mock_client.get()); sensor->SetClient(mock_client.get());
...@@ -1060,10 +1067,10 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckMagnetometerReadingConversion) { ...@@ -1060,10 +1067,10 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckMagnetometerReadingConversion) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtMagnetometer>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtMagnetometer>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::IMagnetometerStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::IMagnetometerStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
EXPECT_CALL(*mock_client, OnReadingUpdated(::testing::_)) EXPECT_CALL(*mock_client, OnReadingUpdated(::testing::_))
...@@ -1097,10 +1104,10 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedMagnetometerSampleParse) { ...@@ -1097,10 +1104,10 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedMagnetometerSampleParse) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtMagnetometer>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtMagnetometer>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::IMagnetometerStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::IMagnetometerStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
sensor->SetClient(mock_client.get()); sensor->SetClient(mock_client.get());
...@@ -1145,10 +1152,10 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckInclinometerReadingConversion) { ...@@ -1145,10 +1152,10 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckInclinometerReadingConversion) {
auto sensor = auto sensor =
std::make_unique<PlatformSensorReaderWinrtAbsOrientationEulerAngles>(); std::make_unique<PlatformSensorReaderWinrtAbsOrientationEulerAngles>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::IInclinometerStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::IInclinometerStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
EXPECT_CALL(*mock_client, OnReadingUpdated(::testing::_)) EXPECT_CALL(*mock_client, OnReadingUpdated(::testing::_))
...@@ -1183,10 +1190,10 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedInclinometerSampleParse) { ...@@ -1183,10 +1190,10 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedInclinometerSampleParse) {
auto sensor = auto sensor =
std::make_unique<PlatformSensorReaderWinrtAbsOrientationEulerAngles>(); std::make_unique<PlatformSensorReaderWinrtAbsOrientationEulerAngles>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::IInclinometerStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::IInclinometerStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
sensor->SetClient(mock_client.get()); sensor->SetClient(mock_client.get());
...@@ -1233,12 +1240,12 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckOrientationSensorReadingConversion) { ...@@ -1233,12 +1240,12 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckOrientationSensorReadingConversion) {
auto sensor = auto sensor =
std::make_unique<PlatformSensorReaderWinrtAbsOrientationQuaternion>(); std::make_unique<PlatformSensorReaderWinrtAbsOrientationQuaternion>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::IOrientationSensorStatics** [&](ABI::Windows::Devices::Sensors::IOrientationSensorStatics**
sensor_factory) -> HRESULT { sensor_factory) -> HRESULT {
return fake_sensor_factory.CopyTo(sensor_factory); return fake_sensor_factory.CopyTo(sensor_factory);
})); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
EXPECT_CALL(*mock_client, OnReadingUpdated(::testing::_)) EXPECT_CALL(*mock_client, OnReadingUpdated(::testing::_))
...@@ -1276,12 +1283,12 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedOrientationSampleParse) { ...@@ -1276,12 +1283,12 @@ TEST_F(PlatformSensorReaderTestWinrt, FailedOrientationSampleParse) {
auto sensor = auto sensor =
std::make_unique<PlatformSensorReaderWinrtAbsOrientationQuaternion>(); std::make_unique<PlatformSensorReaderWinrtAbsOrientationQuaternion>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::IOrientationSensorStatics** [&](ABI::Windows::Devices::Sensors::IOrientationSensorStatics**
sensor_factory) -> HRESULT { sensor_factory) -> HRESULT {
return fake_sensor_factory.CopyTo(sensor_factory); return fake_sensor_factory.CopyTo(sensor_factory);
})); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
sensor->SetClient(mock_client.get()); sensor->SetClient(mock_client.get());
...@@ -1311,10 +1318,10 @@ TEST_F(PlatformSensorReaderTestWinrt, LightSensorThresholding) { ...@@ -1311,10 +1318,10 @@ TEST_F(PlatformSensorReaderTestWinrt, LightSensorThresholding) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
...@@ -1367,12 +1374,12 @@ TEST_F(PlatformSensorReaderTestWinrt, AccelerometerThresholding) { ...@@ -1367,12 +1374,12 @@ TEST_F(PlatformSensorReaderTestWinrt, AccelerometerThresholding) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtAccelerometer>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtAccelerometer>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::IAccelerometerStatics** [&](ABI::Windows::Devices::Sensors::IAccelerometerStatics**
sensor_factory) -> HRESULT { sensor_factory) -> HRESULT {
return fake_sensor_factory.CopyTo(sensor_factory); return fake_sensor_factory.CopyTo(sensor_factory);
})); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
...@@ -1437,10 +1444,10 @@ TEST_F(PlatformSensorReaderTestWinrt, GyrometerThresholding) { ...@@ -1437,10 +1444,10 @@ TEST_F(PlatformSensorReaderTestWinrt, GyrometerThresholding) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtGyrometer>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtGyrometer>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::IGyrometerStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::IGyrometerStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
...@@ -1505,10 +1512,10 @@ TEST_F(PlatformSensorReaderTestWinrt, MagnetometerThresholding) { ...@@ -1505,10 +1512,10 @@ TEST_F(PlatformSensorReaderTestWinrt, MagnetometerThresholding) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtMagnetometer>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtMagnetometer>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::IMagnetometerStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::IMagnetometerStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
...@@ -1580,10 +1587,10 @@ TEST_F(PlatformSensorReaderTestWinrt, AbsOrientationEulerThresholding) { ...@@ -1580,10 +1587,10 @@ TEST_F(PlatformSensorReaderTestWinrt, AbsOrientationEulerThresholding) {
auto sensor = auto sensor =
std::make_unique<PlatformSensorReaderWinrtAbsOrientationEulerAngles>(); std::make_unique<PlatformSensorReaderWinrtAbsOrientationEulerAngles>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::IInclinometerStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::IInclinometerStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
...@@ -1665,12 +1672,12 @@ TEST_F(PlatformSensorReaderTestWinrt, AbsOrientationQuatThresholding) { ...@@ -1665,12 +1672,12 @@ TEST_F(PlatformSensorReaderTestWinrt, AbsOrientationQuatThresholding) {
auto sensor = auto sensor =
std::make_unique<PlatformSensorReaderWinrtAbsOrientationQuaternion>(); std::make_unique<PlatformSensorReaderWinrtAbsOrientationQuaternion>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::IOrientationSensorStatics** [&](ABI::Windows::Devices::Sensors::IOrientationSensorStatics**
sensor_factory) -> HRESULT { sensor_factory) -> HRESULT {
return fake_sensor_factory.CopyTo(sensor_factory); return fake_sensor_factory.CopyTo(sensor_factory);
})); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
auto mock_client = std::make_unique<testing::NiceMock<MockClient>>(); auto mock_client = std::make_unique<testing::NiceMock<MockClient>>();
...@@ -1728,13 +1735,13 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckSensorActivationHistogram) { ...@@ -1728,13 +1735,13 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckSensorActivationHistogram) {
ABI::Windows::Devices::Sensors::LightSensorReadingChangedEventArgs>>(); ABI::Windows::Devices::Sensors::LightSensorReadingChangedEventArgs>>();
auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
// Trigger S_OK // Trigger S_OK
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
EXPECT_EQ(histogram_tester.GetBucketCount( EXPECT_EQ(histogram_tester.GetBucketCount(
"Sensors.Windows.WinRT.Activation.Result", S_OK), "Sensors.Windows.WinRT.Activation.Result", S_OK),
...@@ -1742,15 +1749,13 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckSensorActivationHistogram) { ...@@ -1742,15 +1749,13 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckSensorActivationHistogram) {
// Trigger E_ACCESSDENIED twice // Trigger E_ACCESSDENIED twice
fake_sensor_factory->SetGetDefaultReturnCode(E_ACCESSDENIED); fake_sensor_factory->SetGetDefaultReturnCode(E_ACCESSDENIED);
EXPECT_EQ(sensor->Initialize(), EXPECT_FALSE(sensor->Initialize());
SensorWinrtCreateFailure::kErrorGetDefaultSensorFailed);
EXPECT_EQ(histogram_tester.GetBucketCount( EXPECT_EQ(histogram_tester.GetBucketCount(
"Sensors.Windows.WinRT.Activation.Result", E_ACCESSDENIED), "Sensors.Windows.WinRT.Activation.Result", E_ACCESSDENIED),
1); 1);
EXPECT_EQ(sensor->Initialize(), EXPECT_FALSE(sensor->Initialize());
SensorWinrtCreateFailure::kErrorGetDefaultSensorFailed);
EXPECT_EQ(histogram_tester.GetBucketCount( EXPECT_EQ(histogram_tester.GetBucketCount(
"Sensors.Windows.WinRT.Activation.Result", E_ACCESSDENIED), "Sensors.Windows.WinRT.Activation.Result", E_ACCESSDENIED),
...@@ -1773,10 +1778,10 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckSensorStartHistogram) { ...@@ -1773,10 +1778,10 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckSensorStartHistogram) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
// Trigger S_OK // Trigger S_OK
...@@ -1823,10 +1828,10 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckSensorStopHistogram) { ...@@ -1823,10 +1828,10 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckSensorStopHistogram) {
auto fake_sensor = fake_sensor_factory->fake_sensor_; auto fake_sensor = fake_sensor_factory->fake_sensor_;
auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>(); auto sensor = std::make_unique<PlatformSensorReaderWinrtLightSensor>();
sensor->InitForTests(base::BindLambdaForTesting( sensor->InitForTesting(base::BindLambdaForTesting(
[&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory) [&](ABI::Windows::Devices::Sensors::ILightSensorStatics** sensor_factory)
-> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); })); -> HRESULT { return fake_sensor_factory.CopyTo(sensor_factory); }));
EXPECT_EQ(sensor->Initialize(), SensorWinrtCreateFailure::kOk); EXPECT_TRUE(sensor->Initialize());
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
// Trigger E_UNEXPECTED // Trigger E_UNEXPECTED
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment