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

Unified Diff: components/arc/arc_bridge_service_unittest.cc

Issue 2133653002: arc: Notify ARC instance failures via callbacks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased to master. Created 4 years, 5 months 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
« no previous file with comments | « components/arc/arc_bridge_service_impl.cc ('k') | components/arc/test/fake_arc_bridge_bootstrap.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
« no previous file with comments | « components/arc/arc_bridge_service_impl.cc ('k') | components/arc/test/fake_arc_bridge_bootstrap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698