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 598e54b058fc7b4fa798f2015d0e571fadc0eb19..4dc107bd388f2a72effa9eb497269e0cbe9d3111 100644 |
--- a/components/arc/arc_bridge_service_unittest.cc |
+++ b/components/arc/arc_bridge_service_unittest.cc |
@@ -41,12 +41,17 @@ class ArcBridgeTest : public testing::Test, public ArcBridgeService::Observer { |
} |
} |
+ void OnBridgeStopped(ArcBridgeService::StopReason stop_reason) override { |
+ stop_reason_ = stop_reason; |
+ } |
+ |
bool ready() const { return ready_; } |
ArcBridgeService::State state() const { return state_; } |
protected: |
std::unique_ptr<ArcBridgeServiceImpl> service_; |
std::unique_ptr<FakeArcBridgeInstance> instance_; |
+ ArcBridgeService::StopReason stop_reason_; |
private: |
void SetUp() override { |
@@ -54,6 +59,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( |
@@ -135,7 +141,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()); |
@@ -144,6 +150,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()); |