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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 16 matching lines...) Expand all
27 class ArcBridgeTest : public testing::Test, public ArcBridgeService::Observer { 27 class ArcBridgeTest : public testing::Test, public ArcBridgeService::Observer {
28 public: 28 public:
29 ArcBridgeTest() : ready_(false) {} 29 ArcBridgeTest() : ready_(false) {}
30 ~ArcBridgeTest() override {} 30 ~ArcBridgeTest() override {}
31 31
32 void OnBridgeReady() override { 32 void OnBridgeReady() override {
33 state_ = ArcBridgeService::State::READY; 33 state_ = ArcBridgeService::State::READY;
34 ready_ = true; 34 ready_ = true;
35 } 35 }
36 36
37 void OnBridgeStopped() override { 37 void OnBridgeStopped(ArcBridgeService::StopReason stop_reason) override {
38 state_ = ArcBridgeService::State::STOPPED; 38 state_ = ArcBridgeService::State::STOPPED;
39 stop_reason_ = stop_reason;
39 message_loop_.PostTask(FROM_HERE, message_loop_.QuitWhenIdleClosure()); 40 message_loop_.PostTask(FROM_HERE, message_loop_.QuitWhenIdleClosure());
40 } 41 }
41 42
42 bool ready() const { return ready_; } 43 bool ready() const { return ready_; }
43 ArcBridgeService::State state() const { return state_; } 44 ArcBridgeService::State state() const { return state_; }
44 45
45 protected: 46 protected:
46 std::unique_ptr<ArcBridgeServiceImpl> service_; 47 std::unique_ptr<ArcBridgeServiceImpl> service_;
47 std::unique_ptr<FakeArcBridgeInstance> instance_; 48 std::unique_ptr<FakeArcBridgeInstance> instance_;
49 ArcBridgeService::StopReason stop_reason_;
48 50
49 private: 51 private:
50 void SetUp() override { 52 void SetUp() override {
51 chromeos::DBusThreadManager::Initialize(); 53 chromeos::DBusThreadManager::Initialize();
52 54
53 ready_ = false; 55 ready_ = false;
54 state_ = ArcBridgeService::State::STOPPED; 56 state_ = ArcBridgeService::State::STOPPED;
57 stop_reason_ = ArcBridgeService::StopReason::SHUTDOWN;
55 58
56 instance_.reset(new FakeArcBridgeInstance()); 59 instance_.reset(new FakeArcBridgeInstance());
57 service_.reset(new ArcBridgeServiceImpl( 60 service_.reset(new ArcBridgeServiceImpl(
58 base::MakeUnique<FakeArcBridgeBootstrap>(instance_.get()))); 61 base::MakeUnique<FakeArcBridgeBootstrap>(instance_.get())));
59 62
60 service_->AddObserver(this); 63 service_->AddObserver(this);
61 } 64 }
62 65
63 void TearDown() override { 66 void TearDown() override {
64 service_->RemoveObserver(this); 67 service_->RemoveObserver(this);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 125
123 service_->SetAvailable(true); 126 service_->SetAvailable(true);
124 service_->HandleStartup(); 127 service_->HandleStartup();
125 instance_->WaitForInitCall(); 128 instance_->WaitForInitCall();
126 ASSERT_EQ(ArcBridgeService::State::READY, state()); 129 ASSERT_EQ(ArcBridgeService::State::READY, state());
127 ASSERT_EQ(1, instance_->init_calls()); 130 ASSERT_EQ(1, instance_->init_calls());
128 131
129 // Simulate a connection loss. 132 // Simulate a connection loss.
130 service_->DisableReconnectDelayForTesting(); 133 service_->DisableReconnectDelayForTesting();
131 service_->OnChannelClosed(); 134 service_->OnChannelClosed();
132 instance_->SimulateCrash(); 135 instance_->Stop(ArcBridgeService::StopReason::CRASH);
133 instance_->WaitForInitCall(); 136 instance_->WaitForInitCall();
134 ASSERT_EQ(ArcBridgeService::State::READY, state()); 137 ASSERT_EQ(ArcBridgeService::State::READY, state());
135 ASSERT_EQ(2, instance_->init_calls()); 138 ASSERT_EQ(2, instance_->init_calls());
136 139
137 service_->Shutdown(); 140 service_->Shutdown();
138 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); 141 ASSERT_EQ(ArcBridgeService::State::STOPPED, state());
139 } 142 }
140 143
144 // Makes sure OnBridgeStopped is called on stop.
145 TEST_F(ArcBridgeTest, OnBridgeStopped) {
146 ASSERT_FALSE(ready());
147
148 service_->DisableReconnectDelayForTesting();
149 service_->SetAvailable(true);
150 service_->HandleStartup();
151 instance_->WaitForInitCall();
152 ASSERT_EQ(ArcBridgeService::State::READY, state());
153
154 // Simulate boot failure.
155 service_->OnChannelClosed();
156 instance_->Stop(ArcBridgeService::StopReason::GENERIC_BOOT_FAILURE);
157 instance_->WaitForInitCall();
158 ASSERT_EQ(ArcBridgeService::StopReason::GENERIC_BOOT_FAILURE, stop_reason_);
159 ASSERT_EQ(ArcBridgeService::State::READY, state());
160
161 // Simulate crash.
162 service_->OnChannelClosed();
163 instance_->Stop(ArcBridgeService::StopReason::CRASH);
164 instance_->WaitForInitCall();
165 ASSERT_EQ(ArcBridgeService::StopReason::CRASH, stop_reason_);
166 ASSERT_EQ(ArcBridgeService::State::READY, state());
167
168 // Graceful shutdown.
169 service_->Shutdown();
170 ASSERT_EQ(ArcBridgeService::StopReason::SHUTDOWN, stop_reason_);
171 ASSERT_EQ(ArcBridgeService::State::STOPPED, state());
172 }
173
141 // Removing the same observer more than once should be okay. 174 // Removing the same observer more than once should be okay.
142 TEST_F(ArcBridgeTest, RemoveObserverTwice) { 175 TEST_F(ArcBridgeTest, RemoveObserverTwice) {
143 ASSERT_FALSE(ready()); 176 ASSERT_FALSE(ready());
144 service_->RemoveObserver(this); 177 service_->RemoveObserver(this);
145 // The teardown method will also remove |this|. 178 // The teardown method will also remove |this|.
146 } 179 }
147 180
148 // Removing an unknown observer should be allowed. 181 // Removing an unknown observer should be allowed.
149 TEST_F(ArcBridgeTest, RemoveUnknownObserver) { 182 TEST_F(ArcBridgeTest, RemoveUnknownObserver) {
150 ASSERT_FALSE(ready()); 183 ASSERT_FALSE(ready());
151 auto dummy_observer = base::MakeUnique<DummyObserver>(); 184 auto dummy_observer = base::MakeUnique<DummyObserver>();
152 service_->RemoveObserver(dummy_observer.get()); 185 service_->RemoveObserver(dummy_observer.get());
153 } 186 }
154 187
155 } // namespace arc 188 } // namespace arc
OLDNEW
« 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