summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/device_orientation/device_motion_event_pump_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/device_orientation/device_motion_event_pump_unittest.cc')
-rw-r--r--chromium/third_party/blink/renderer/modules/device_orientation/device_motion_event_pump_unittest.cc105
1 files changed, 11 insertions, 94 deletions
diff --git a/chromium/third_party/blink/renderer/modules/device_orientation/device_motion_event_pump_unittest.cc b/chromium/third_party/blink/renderer/modules/device_orientation/device_motion_event_pump_unittest.cc
index e428ac1e682..c7eb637e3bf 100644
--- a/chromium/third_party/blink/renderer/modules/device_orientation/device_motion_event_pump_unittest.cc
+++ b/chromium/third_party/blink/renderer/modules/device_orientation/device_motion_event_pump_unittest.cc
@@ -39,7 +39,7 @@ class MockDeviceMotionController final
motion_pump_(motion_pump) {}
~MockDeviceMotionController() override {}
- void Trace(Visitor* visitor) override {
+ void Trace(Visitor* visitor) const override {
PlatformEventController::Trace(visitor);
visitor->Trace(motion_pump_);
}
@@ -79,17 +79,17 @@ class DeviceMotionEventPumpTest : public testing::Test {
protected:
void SetUp() override {
+ page_holder_ = std::make_unique<DummyPageHolder>();
+
mojo::PendingRemote<device::mojom::SensorProvider> sensor_provider;
sensor_provider_.Bind(sensor_provider.InitWithNewPipeAndPassReceiver());
- auto* motion_pump = MakeGarbageCollected<DeviceMotionEventPump>(
- base::ThreadTaskRunnerHandle::Get());
+ auto* motion_pump =
+ MakeGarbageCollected<DeviceMotionEventPump>(page_holder_->GetFrame());
motion_pump->SetSensorProviderForTesting(
mojo::PendingRemote<device::mojom::blink::SensorProvider>(
sensor_provider.PassPipe(),
device::mojom::SensorProvider::Version_));
- page_holder_ = std::make_unique<DummyPageHolder>();
-
controller_ = MakeGarbageCollected<MockDeviceMotionController>(
motion_pump, *page_holder_->GetFrame().DomWindow());
@@ -138,86 +138,8 @@ class DeviceMotionEventPumpTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPumpTest);
};
-TEST_F(DeviceMotionEventPumpTest, MultipleStartAndStopWithWait) {
- controller()->motion_pump()->Start(nullptr);
- base::RunLoop().RunUntilIdle();
-
- ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::ACTIVE);
- EXPECT_EQ(DeviceMotionEventPump::PumpState::RUNNING,
- controller()->motion_pump()->GetPumpStateForTesting());
-
- controller()->motion_pump()->Stop();
- base::RunLoop().RunUntilIdle();
-
- ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::SUSPENDED);
- EXPECT_EQ(DeviceMotionEventPump::PumpState::STOPPED,
- controller()->motion_pump()->GetPumpStateForTesting());
-
- controller()->motion_pump()->Start(nullptr);
- base::RunLoop().RunUntilIdle();
-
- ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::ACTIVE);
- EXPECT_EQ(DeviceMotionEventPump::PumpState::RUNNING,
- controller()->motion_pump()->GetPumpStateForTesting());
-
- controller()->motion_pump()->Stop();
- base::RunLoop().RunUntilIdle();
-
- ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::SUSPENDED);
- EXPECT_EQ(DeviceMotionEventPump::PumpState::STOPPED,
- controller()->motion_pump()->GetPumpStateForTesting());
-}
-
-TEST_F(DeviceMotionEventPumpTest, CallStop) {
- controller()->motion_pump()->Stop();
- base::RunLoop().RunUntilIdle();
-
- ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::NOT_INITIALIZED);
-}
-
-TEST_F(DeviceMotionEventPumpTest, CallStartAndStop) {
- controller()->motion_pump()->Start(nullptr);
- controller()->motion_pump()->Stop();
- base::RunLoop().RunUntilIdle();
-
- ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::SUSPENDED);
-}
-
-TEST_F(DeviceMotionEventPumpTest, CallStartMultipleTimes) {
- controller()->motion_pump()->Start(nullptr);
- controller()->motion_pump()->Start(nullptr);
- controller()->motion_pump()->Stop();
- base::RunLoop().RunUntilIdle();
-
- ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::SUSPENDED);
-}
-
-TEST_F(DeviceMotionEventPumpTest, CallStopMultipleTimes) {
- controller()->motion_pump()->Start(nullptr);
- controller()->motion_pump()->Stop();
- controller()->motion_pump()->Stop();
- base::RunLoop().RunUntilIdle();
-
- ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::SUSPENDED);
-}
-
-// Test multiple DeviceSensorEventPump::Start() calls only bind sensor once.
-TEST_F(DeviceMotionEventPumpTest, SensorOnlyBindOnce) {
- controller()->motion_pump()->Start(nullptr);
- controller()->motion_pump()->Stop();
- controller()->motion_pump()->Start(nullptr);
- base::RunLoop().RunUntilIdle();
-
- ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::ACTIVE);
-
- controller()->motion_pump()->Stop();
-
- ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::SUSPENDED);
-}
-
TEST_F(DeviceMotionEventPumpTest, AllSensorsAreActive) {
controller()->RegisterWithDispatcher();
- controller()->motion_pump()->Start(nullptr);
base::RunLoop().RunUntilIdle();
ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::ACTIVE);
@@ -250,7 +172,7 @@ TEST_F(DeviceMotionEventPumpTest, AllSensorsAreActive) {
EXPECT_EQ(gfx::RadToDeg(9.0),
received_data->GetRotationRate()->gamma().value());
- controller()->motion_pump()->Stop();
+ controller()->UnregisterWithDispatcher();
ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::SUSPENDED);
}
@@ -259,7 +181,6 @@ TEST_F(DeviceMotionEventPumpTest, TwoSensorsAreActive) {
sensor_provider()->set_linear_acceleration_sensor_is_available(false);
controller()->RegisterWithDispatcher();
- controller()->motion_pump()->Start(nullptr);
base::RunLoop().RunUntilIdle();
ExpectAccelerometerStateToBe(DeviceSensorEntry::State::ACTIVE);
@@ -293,7 +214,7 @@ TEST_F(DeviceMotionEventPumpTest, TwoSensorsAreActive) {
EXPECT_EQ(gfx::RadToDeg(9.0),
received_data->GetRotationRate()->gamma().value());
- controller()->motion_pump()->Stop();
+ controller()->UnregisterWithDispatcher();
ExpectAccelerometerStateToBe(DeviceSensorEntry::State::SUSPENDED);
ExpectLinearAccelerationSensorStateToBe(
@@ -303,7 +224,6 @@ TEST_F(DeviceMotionEventPumpTest, TwoSensorsAreActive) {
TEST_F(DeviceMotionEventPumpTest, SomeSensorDataFieldsNotAvailable) {
controller()->RegisterWithDispatcher();
- controller()->motion_pump()->Start(nullptr);
base::RunLoop().RunUntilIdle();
ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::ACTIVE);
@@ -333,7 +253,7 @@ TEST_F(DeviceMotionEventPumpTest, SomeSensorDataFieldsNotAvailable) {
received_data->GetRotationRate()->beta().value());
EXPECT_FALSE(received_data->GetRotationRate()->gamma().has_value());
- controller()->motion_pump()->Stop();
+ controller()->UnregisterWithDispatcher();
ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::SUSPENDED);
}
@@ -345,7 +265,6 @@ TEST_F(DeviceMotionEventPumpTest, FireAllNullEvent) {
sensor_provider()->set_gyroscope_is_available(false);
controller()->RegisterWithDispatcher();
- controller()->motion_pump()->Start(nullptr);
base::RunLoop().RunUntilIdle();
ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::NOT_INITIALIZED);
@@ -362,7 +281,7 @@ TEST_F(DeviceMotionEventPumpTest, FireAllNullEvent) {
EXPECT_FALSE(received_data->GetRotationRate()->HasRotationData());
- controller()->motion_pump()->Stop();
+ controller()->UnregisterWithDispatcher();
ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::NOT_INITIALIZED);
}
@@ -370,7 +289,6 @@ TEST_F(DeviceMotionEventPumpTest, FireAllNullEvent) {
TEST_F(DeviceMotionEventPumpTest,
NotFireEventWhenSensorReadingTimeStampIsZero) {
controller()->RegisterWithDispatcher();
- controller()->motion_pump()->Start(nullptr);
base::RunLoop().RunUntilIdle();
ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::ACTIVE);
@@ -391,7 +309,7 @@ TEST_F(DeviceMotionEventPumpTest,
// Event is fired only after all the available sensors have data.
EXPECT_TRUE(controller()->did_change_device_motion());
- controller()->motion_pump()->Stop();
+ controller()->UnregisterWithDispatcher();
ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::SUSPENDED);
}
@@ -405,7 +323,6 @@ TEST_F(DeviceMotionEventPumpTest, PumpThrottlesEventRate) {
DeviceMotionEventPump::kDefaultPumpDelayMicroseconds);
controller()->RegisterWithDispatcher();
- controller()->motion_pump()->Start(nullptr);
base::RunLoop().RunUntilIdle();
ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::ACTIVE);
@@ -419,7 +336,7 @@ TEST_F(DeviceMotionEventPumpTest, PumpThrottlesEventRate) {
FROM_HERE, loop.QuitWhenIdleClosure(),
base::TimeDelta::FromMilliseconds(100));
loop.Run();
- controller()->motion_pump()->Stop();
+ controller()->UnregisterWithDispatcher();
ExpectAllThreeSensorsStateToBe(DeviceSensorEntry::State::SUSPENDED);