OLD | NEW |
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 23 matching lines...) Expand all Loading... |
34 | 34 |
35 case ArcBridgeService::State::STOPPED: | 35 case ArcBridgeService::State::STOPPED: |
36 message_loop_.PostTask(FROM_HERE, message_loop_.QuitWhenIdleClosure()); | 36 message_loop_.PostTask(FROM_HERE, message_loop_.QuitWhenIdleClosure()); |
37 break; | 37 break; |
38 | 38 |
39 default: | 39 default: |
40 break; | 40 break; |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
| 44 void OnBridgeStopped(ArcBridgeService::StopReason stop_reason) override { |
| 45 stop_reason_ = stop_reason; |
| 46 } |
| 47 |
44 bool ready() const { return ready_; } | 48 bool ready() const { return ready_; } |
45 ArcBridgeService::State state() const { return state_; } | 49 ArcBridgeService::State state() const { return state_; } |
46 | 50 |
47 protected: | 51 protected: |
48 std::unique_ptr<ArcBridgeServiceImpl> service_; | 52 std::unique_ptr<ArcBridgeServiceImpl> service_; |
49 std::unique_ptr<FakeArcBridgeInstance> instance_; | 53 std::unique_ptr<FakeArcBridgeInstance> instance_; |
| 54 ArcBridgeService::StopReason stop_reason_; |
50 | 55 |
51 private: | 56 private: |
52 void SetUp() override { | 57 void SetUp() override { |
53 chromeos::DBusThreadManager::Initialize(); | 58 chromeos::DBusThreadManager::Initialize(); |
54 | 59 |
55 ready_ = false; | 60 ready_ = false; |
56 state_ = ArcBridgeService::State::STOPPED; | 61 state_ = ArcBridgeService::State::STOPPED; |
| 62 stop_reason_ = ArcBridgeService::StopReason::NO_ERROR; |
57 | 63 |
58 instance_.reset(new FakeArcBridgeInstance()); | 64 instance_.reset(new FakeArcBridgeInstance()); |
59 service_.reset(new ArcBridgeServiceImpl( | 65 service_.reset(new ArcBridgeServiceImpl( |
60 base::MakeUnique<FakeArcBridgeBootstrap>(instance_.get()))); | 66 base::MakeUnique<FakeArcBridgeBootstrap>(instance_.get()))); |
61 | 67 |
62 service_->AddObserver(this); | 68 service_->AddObserver(this); |
63 } | 69 } |
64 | 70 |
65 void TearDown() override { | 71 void TearDown() override { |
66 service_->RemoveObserver(this); | 72 service_->RemoveObserver(this); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 134 |
129 service_->SetAvailable(true); | 135 service_->SetAvailable(true); |
130 service_->HandleStartup(); | 136 service_->HandleStartup(); |
131 instance_->WaitForInitCall(); | 137 instance_->WaitForInitCall(); |
132 ASSERT_EQ(ArcBridgeService::State::READY, state()); | 138 ASSERT_EQ(ArcBridgeService::State::READY, state()); |
133 ASSERT_EQ(1, instance_->init_calls()); | 139 ASSERT_EQ(1, instance_->init_calls()); |
134 | 140 |
135 // Simulate a connection loss. | 141 // Simulate a connection loss. |
136 service_->DisableReconnectDelayForTesting(); | 142 service_->DisableReconnectDelayForTesting(); |
137 service_->OnChannelClosed(); | 143 service_->OnChannelClosed(); |
138 instance_->SimulateCrash(); | 144 instance_->SimulateCrash(ArcBridgeService::StopReason::CRASH); |
139 instance_->WaitForInitCall(); | 145 instance_->WaitForInitCall(); |
140 ASSERT_EQ(ArcBridgeService::State::READY, state()); | 146 ASSERT_EQ(ArcBridgeService::State::READY, state()); |
141 ASSERT_EQ(2, instance_->init_calls()); | 147 ASSERT_EQ(2, instance_->init_calls()); |
142 | 148 |
143 service_->Shutdown(); | 149 service_->Shutdown(); |
144 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); | 150 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); |
145 } | 151 } |
146 | 152 |
| 153 TEST_F(ArcBridgeTest, BootFailure) { |
| 154 ASSERT_FALSE(ready()); |
| 155 |
| 156 service_->SetAvailable(true); |
| 157 service_->HandleStartup(); |
| 158 instance_->WaitForInitCall(); |
| 159 ASSERT_EQ(ArcBridgeService::State::READY, state()); |
| 160 |
| 161 // Simulate boot failure. |
| 162 service_->DisableReconnectDelayForTesting(); |
| 163 service_->OnChannelClosed(); |
| 164 instance_->SimulateCrash(ArcBridgeService::StopReason::GENERIC_BOOT_FAILURE); |
| 165 instance_->WaitForInitCall(); |
| 166 |
| 167 ASSERT_EQ(ArcBridgeService::StopReason::GENERIC_BOOT_FAILURE, stop_reason_); |
| 168 |
| 169 service_->Shutdown(); |
| 170 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); |
| 171 } |
| 172 |
| 173 TEST_F(ArcBridgeTest, Crash) { |
| 174 ASSERT_FALSE(ready()); |
| 175 |
| 176 service_->SetAvailable(true); |
| 177 service_->HandleStartup(); |
| 178 instance_->WaitForInitCall(); |
| 179 ASSERT_EQ(ArcBridgeService::State::READY, state()); |
| 180 |
| 181 // Simulate crash. |
| 182 service_->DisableReconnectDelayForTesting(); |
| 183 service_->OnChannelClosed(); |
| 184 instance_->SimulateCrash(ArcBridgeService::StopReason::CRASH); |
| 185 instance_->WaitForInitCall(); |
| 186 |
| 187 ASSERT_EQ(ArcBridgeService::StopReason::CRASH, stop_reason_); |
| 188 |
| 189 service_->Shutdown(); |
| 190 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); |
| 191 } |
| 192 |
147 // Removing the same observer more than once should be okay. | 193 // Removing the same observer more than once should be okay. |
148 TEST_F(ArcBridgeTest, RemoveObserverTwice) { | 194 TEST_F(ArcBridgeTest, RemoveObserverTwice) { |
149 ASSERT_FALSE(ready()); | 195 ASSERT_FALSE(ready()); |
150 service_->RemoveObserver(this); | 196 service_->RemoveObserver(this); |
151 // The teardown method will also remove |this|. | 197 // The teardown method will also remove |this|. |
152 } | 198 } |
153 | 199 |
154 // Removing an unknown observer should be allowed. | 200 // Removing an unknown observer should be allowed. |
155 TEST_F(ArcBridgeTest, RemoveUnknownObserver) { | 201 TEST_F(ArcBridgeTest, RemoveUnknownObserver) { |
156 ASSERT_FALSE(ready()); | 202 ASSERT_FALSE(ready()); |
157 auto dummy_observer = base::MakeUnique<DummyObserver>(); | 203 auto dummy_observer = base::MakeUnique<DummyObserver>(); |
158 service_->RemoveObserver(dummy_observer.get()); | 204 service_->RemoveObserver(dummy_observer.get()); |
159 } | 205 } |
160 | 206 |
161 } // namespace arc | 207 } // namespace arc |
OLD | NEW |