| Index: components/arc/arc_bridge_service_unittest.cc
|
| diff --git a/components/arc/arc_bridge_service_unittest.cc b/components/arc/arc_bridge_service_unittest.cc
|
| index 52ad15fc120c4ba76f44373e1133cc0b8e3b9270..a4bff474160c1c8f73ea80ebb0e23d85f4b5cae6 100644
|
| --- a/components/arc/arc_bridge_service_unittest.cc
|
| +++ b/components/arc/arc_bridge_service_unittest.cc
|
| @@ -34,8 +34,9 @@ class ArcBridgeTest : public testing::Test, public ArcBridgeService::Observer {
|
| ready_ = true;
|
| }
|
|
|
| - void OnBridgeStopped() override {
|
| + void OnBridgeStopped(ArcBridgeService::StopReason stop_reason) override {
|
| state_ = ArcBridgeService::State::STOPPED;
|
| + stop_reason_ = stop_reason;
|
| message_loop_.PostTask(FROM_HERE, message_loop_.QuitWhenIdleClosure());
|
| }
|
|
|
| @@ -45,6 +46,7 @@ class ArcBridgeTest : public testing::Test, public ArcBridgeService::Observer {
|
| protected:
|
| std::unique_ptr<ArcBridgeServiceImpl> service_;
|
| std::unique_ptr<FakeArcBridgeInstance> instance_;
|
| + ArcBridgeService::StopReason stop_reason_;
|
|
|
| private:
|
| void SetUp() override {
|
| @@ -52,6 +54,7 @@ class ArcBridgeTest : public testing::Test, public ArcBridgeService::Observer {
|
|
|
| ready_ = false;
|
| state_ = ArcBridgeService::State::STOPPED;
|
| + stop_reason_ = ArcBridgeService::StopReason::SHUTDOWN;
|
|
|
| instance_.reset(new FakeArcBridgeInstance());
|
| service_.reset(new ArcBridgeServiceImpl(
|
| @@ -129,7 +132,7 @@ TEST_F(ArcBridgeTest, Restart) {
|
| // Simulate a connection loss.
|
| service_->DisableReconnectDelayForTesting();
|
| service_->OnChannelClosed();
|
| - instance_->SimulateCrash();
|
| + instance_->Stop(ArcBridgeService::StopReason::CRASH);
|
| instance_->WaitForInitCall();
|
| ASSERT_EQ(ArcBridgeService::State::READY, state());
|
| ASSERT_EQ(2, instance_->init_calls());
|
| @@ -138,6 +141,36 @@ TEST_F(ArcBridgeTest, Restart) {
|
| ASSERT_EQ(ArcBridgeService::State::STOPPED, state());
|
| }
|
|
|
| +// Makes sure OnBridgeStopped is called on stop.
|
| +TEST_F(ArcBridgeTest, OnBridgeStopped) {
|
| + ASSERT_FALSE(ready());
|
| +
|
| + service_->DisableReconnectDelayForTesting();
|
| + service_->SetAvailable(true);
|
| + service_->HandleStartup();
|
| + instance_->WaitForInitCall();
|
| + ASSERT_EQ(ArcBridgeService::State::READY, state());
|
| +
|
| + // Simulate boot failure.
|
| + service_->OnChannelClosed();
|
| + instance_->Stop(ArcBridgeService::StopReason::GENERIC_BOOT_FAILURE);
|
| + instance_->WaitForInitCall();
|
| + ASSERT_EQ(ArcBridgeService::StopReason::GENERIC_BOOT_FAILURE, stop_reason_);
|
| + ASSERT_EQ(ArcBridgeService::State::READY, state());
|
| +
|
| + // Simulate crash.
|
| + service_->OnChannelClosed();
|
| + instance_->Stop(ArcBridgeService::StopReason::CRASH);
|
| + instance_->WaitForInitCall();
|
| + ASSERT_EQ(ArcBridgeService::StopReason::CRASH, stop_reason_);
|
| + ASSERT_EQ(ArcBridgeService::State::READY, state());
|
| +
|
| + // Graceful shutdown.
|
| + service_->Shutdown();
|
| + ASSERT_EQ(ArcBridgeService::StopReason::SHUTDOWN, stop_reason_);
|
| + ASSERT_EQ(ArcBridgeService::State::STOPPED, state());
|
| +}
|
| +
|
| // Removing the same observer more than once should be okay.
|
| TEST_F(ArcBridgeTest, RemoveObserverTwice) {
|
| ASSERT_FALSE(ready());
|
|
|