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

Side by Side Diff: components/arc/arc_session_runner_unittest.cc

Issue 2586183002: Refactor ArcSessionRunner part 2. (Closed)
Patch Set: Created 4 years 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 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 static std::unique_ptr<ArcSession> CreateBootFailureArcSession( 73 static std::unique_ptr<ArcSession> CreateBootFailureArcSession(
74 StopReason reason) { 74 StopReason reason) {
75 auto arc_session = base::MakeUnique<FakeArcSession>(); 75 auto arc_session = base::MakeUnique<FakeArcSession>();
76 arc_session->EnableBootFailureEmulation(reason); 76 arc_session->EnableBootFailureEmulation(reason);
77 return std::move(arc_session); 77 return std::move(arc_session);
78 } 78 }
79 79
80 private: 80 private:
81 // ArcSessionObserver: 81 // ArcSessionObserver:
82 void OnSessionStopped(StopReason stop_reason) override { 82 void OnSessionStopped(StopReason stop_reason) override {
83 // The instance is already destructed in ArcSessionRunner::OnStopped(). 83 // The instance is already destructed in
84 // ArcSessionRunner::OnSessionStopped().
84 stop_reason_ = stop_reason; 85 stop_reason_ = stop_reason;
85 } 86 }
86 87
87 StopReason stop_reason_; 88 StopReason stop_reason_;
88 std::unique_ptr<ArcSessionRunner> arc_session_runner_; 89 std::unique_ptr<ArcSessionRunner> arc_session_runner_;
89 base::MessageLoopForUI message_loop_; 90 base::MessageLoopForUI message_loop_;
90 91
91 DISALLOW_COPY_AND_ASSIGN(ArcSessionRunnerTest); 92 DISALLOW_COPY_AND_ASSIGN(ArcSessionRunnerTest);
92 }; 93 };
93 94
(...skipping 21 matching lines...) Expand all
115 }; 116 };
116 117
117 Observer observer; 118 Observer observer;
118 arc_session_runner()->AddObserver(&observer); 119 arc_session_runner()->AddObserver(&observer);
119 base::ScopedClosureRunner teardown(base::Bind( 120 base::ScopedClosureRunner teardown(base::Bind(
120 [](ArcSessionRunner* arc_session_runner, Observer* observer) { 121 [](ArcSessionRunner* arc_session_runner, Observer* observer) {
121 arc_session_runner->RemoveObserver(observer); 122 arc_session_runner->RemoveObserver(observer);
122 }, 123 },
123 arc_session_runner(), &observer)); 124 arc_session_runner(), &observer));
124 125
125 EXPECT_TRUE(arc_session_runner()->stopped()); 126 EXPECT_TRUE(arc_session_runner()->IsStopped());
126 127
127 arc_session_runner()->RequestStart(); 128 arc_session_runner()->RequestStart();
128 EXPECT_TRUE(arc_session_runner()->ready()); 129 EXPECT_TRUE(arc_session_runner()->IsRunning());
129 EXPECT_TRUE(observer.IsReadyCalled()); 130 EXPECT_TRUE(observer.IsReadyCalled());
130 131
131 arc_session_runner()->RequestStop(); 132 arc_session_runner()->RequestStop();
132 EXPECT_TRUE(arc_session_runner()->stopped()); 133 EXPECT_TRUE(arc_session_runner()->IsStopped());
133 EXPECT_TRUE(observer.IsStoppedCalled()); 134 EXPECT_TRUE(observer.IsStoppedCalled());
134 arc_session_runner()->RemoveObserver(&observer); 135 arc_session_runner()->RemoveObserver(&observer);
135 } 136 }
136 137
137 // If the ArcSessionRunner accepts a request to stop ARC instance, it should 138 // If the ArcSessionRunner accepts a request to stop ARC instance, it should
138 // stop it, even mid-startup. 139 // stop it, even mid-startup.
139 TEST_F(ArcSessionRunnerTest, StopMidStartup) { 140 TEST_F(ArcSessionRunnerTest, StopMidStartup) {
140 ResetArcSessionFactory( 141 ResetArcSessionFactory(
141 base::Bind(&ArcSessionRunnerTest::CreateSuspendedArcSession)); 142 base::Bind(&ArcSessionRunnerTest::CreateSuspendedArcSession));
142 EXPECT_TRUE(arc_session_runner()->stopped()); 143 EXPECT_TRUE(arc_session_runner()->IsStopped());
143 144
144 arc_session_runner()->RequestStart(); 145 arc_session_runner()->RequestStart();
145 EXPECT_FALSE(arc_session_runner()->stopped()); 146 EXPECT_FALSE(arc_session_runner()->IsStopped());
146 EXPECT_FALSE(arc_session_runner()->ready()); 147 EXPECT_FALSE(arc_session_runner()->IsRunning());
147 148
148 arc_session_runner()->RequestStop(); 149 arc_session_runner()->RequestStop();
149 EXPECT_TRUE(arc_session_runner()->stopped()); 150 EXPECT_TRUE(arc_session_runner()->IsStopped());
150 } 151 }
151 152
152 // If the boot procedure is failed, then restarting mechanism should not 153 // If the boot procedure is failed, then restarting mechanism should not
153 // triggered. 154 // triggered.
154 TEST_F(ArcSessionRunnerTest, BootFailure) { 155 TEST_F(ArcSessionRunnerTest, BootFailure) {
155 ResetArcSessionFactory( 156 ResetArcSessionFactory(
156 base::Bind(&ArcSessionRunnerTest::CreateBootFailureArcSession, 157 base::Bind(&ArcSessionRunnerTest::CreateBootFailureArcSession,
157 StopReason::GENERIC_BOOT_FAILURE)); 158 StopReason::GENERIC_BOOT_FAILURE));
158 EXPECT_TRUE(arc_session_runner()->stopped()); 159 EXPECT_TRUE(arc_session_runner()->IsStopped());
159 160
160 arc_session_runner()->RequestStart(); 161 arc_session_runner()->RequestStart();
161 EXPECT_EQ(StopReason::GENERIC_BOOT_FAILURE, stop_reason()); 162 EXPECT_EQ(StopReason::GENERIC_BOOT_FAILURE, stop_reason());
162 EXPECT_TRUE(arc_session_runner()->stopped()); 163 EXPECT_TRUE(arc_session_runner()->IsStopped());
163 } 164 }
164 165
165 // If the instance is stopped, it should be re-started. 166 // If the instance is stopped, it should be re-started.
166 TEST_F(ArcSessionRunnerTest, Restart) { 167 TEST_F(ArcSessionRunnerTest, Restart) {
167 arc_session_runner()->SetRestartDelayForTesting(base::TimeDelta()); 168 arc_session_runner()->SetRestartDelayForTesting(base::TimeDelta());
168 EXPECT_TRUE(arc_session_runner()->stopped()); 169 EXPECT_TRUE(arc_session_runner()->IsStopped());
169 170
170 arc_session_runner()->RequestStart(); 171 arc_session_runner()->RequestStart();
171 EXPECT_TRUE(arc_session_runner()->ready()); 172 EXPECT_TRUE(arc_session_runner()->IsRunning());
172 173
173 // Simulate a connection loss. 174 // Simulate a connection loss.
174 ASSERT_TRUE(arc_session()); 175 ASSERT_TRUE(arc_session());
175 arc_session()->StopWithReason(StopReason::CRASH); 176 arc_session()->StopWithReason(StopReason::CRASH);
176 EXPECT_TRUE(arc_session_runner()->stopped()); 177 EXPECT_TRUE(arc_session_runner()->IsStopped());
177 base::RunLoop().RunUntilIdle(); 178 base::RunLoop().RunUntilIdle();
178 EXPECT_TRUE(arc_session_runner()->ready()); 179 EXPECT_TRUE(arc_session_runner()->IsRunning());
179 180
180 arc_session_runner()->RequestStop(); 181 arc_session_runner()->RequestStop();
181 EXPECT_TRUE(arc_session_runner()->stopped()); 182 EXPECT_TRUE(arc_session_runner()->IsStopped());
182 } 183 }
183 184
184 // Makes sure OnSessionStopped is called on stop. 185 // Makes sure OnSessionStopped is called on stop.
185 TEST_F(ArcSessionRunnerTest, OnSessionStopped) { 186 TEST_F(ArcSessionRunnerTest, OnSessionStopped) {
186 arc_session_runner()->SetRestartDelayForTesting(base::TimeDelta()); 187 arc_session_runner()->SetRestartDelayForTesting(base::TimeDelta());
187 EXPECT_TRUE(arc_session_runner()->stopped()); 188 EXPECT_TRUE(arc_session_runner()->IsStopped());
188 189
189 arc_session_runner()->RequestStart(); 190 arc_session_runner()->RequestStart();
190 EXPECT_TRUE(arc_session_runner()->ready()); 191 EXPECT_TRUE(arc_session_runner()->IsRunning());
191 192
192 // Simulate boot failure. 193 // Simulate boot failure.
193 ASSERT_TRUE(arc_session()); 194 ASSERT_TRUE(arc_session());
194 arc_session()->StopWithReason(StopReason::GENERIC_BOOT_FAILURE); 195 arc_session()->StopWithReason(StopReason::GENERIC_BOOT_FAILURE);
195 EXPECT_EQ(StopReason::GENERIC_BOOT_FAILURE, stop_reason()); 196 EXPECT_EQ(StopReason::GENERIC_BOOT_FAILURE, stop_reason());
196 EXPECT_TRUE(arc_session_runner()->stopped()); 197 EXPECT_TRUE(arc_session_runner()->IsStopped());
197 base::RunLoop().RunUntilIdle(); 198 base::RunLoop().RunUntilIdle();
198 EXPECT_TRUE(arc_session_runner()->ready()); 199 EXPECT_TRUE(arc_session_runner()->IsRunning());
199 200
200 // Simulate crash. 201 // Simulate crash.
201 ASSERT_TRUE(arc_session()); 202 ASSERT_TRUE(arc_session());
202 arc_session()->StopWithReason(StopReason::CRASH); 203 arc_session()->StopWithReason(StopReason::CRASH);
203 EXPECT_EQ(StopReason::CRASH, stop_reason()); 204 EXPECT_EQ(StopReason::CRASH, stop_reason());
204 EXPECT_TRUE(arc_session_runner()->stopped()); 205 EXPECT_TRUE(arc_session_runner()->IsStopped());
205 base::RunLoop().RunUntilIdle(); 206 base::RunLoop().RunUntilIdle();
206 EXPECT_TRUE(arc_session_runner()->ready()); 207 EXPECT_TRUE(arc_session_runner()->IsRunning());
207 208
208 // Graceful stop. 209 // Graceful stop.
209 arc_session_runner()->RequestStop(); 210 arc_session_runner()->RequestStop();
210 EXPECT_EQ(StopReason::SHUTDOWN, stop_reason()); 211 EXPECT_EQ(StopReason::SHUTDOWN, stop_reason());
211 EXPECT_TRUE(arc_session_runner()->stopped()); 212 EXPECT_TRUE(arc_session_runner()->IsStopped());
212 } 213 }
213 214
214 TEST_F(ArcSessionRunnerTest, Shutdown) { 215 TEST_F(ArcSessionRunnerTest, Shutdown) {
215 arc_session_runner()->SetRestartDelayForTesting(base::TimeDelta()); 216 arc_session_runner()->SetRestartDelayForTesting(base::TimeDelta());
216 EXPECT_TRUE(arc_session_runner()->stopped()); 217 EXPECT_TRUE(arc_session_runner()->IsStopped());
217 218
218 arc_session_runner()->RequestStart(); 219 arc_session_runner()->RequestStart();
219 EXPECT_TRUE(arc_session_runner()->ready()); 220 EXPECT_TRUE(arc_session_runner()->IsRunning());
220 221
221 // Simulate shutdown. 222 // Simulate shutdown.
222 arc_session_runner()->OnShutdown(); 223 arc_session_runner()->OnShutdown();
223 EXPECT_EQ(StopReason::SHUTDOWN, stop_reason()); 224 EXPECT_EQ(StopReason::SHUTDOWN, stop_reason());
224 EXPECT_TRUE(arc_session_runner()->stopped()); 225 EXPECT_TRUE(arc_session_runner()->IsStopped());
225 } 226 }
226 227
227 // Removing the same observer more than once should be okay. 228 // Removing the same observer more than once should be okay.
228 TEST_F(ArcSessionRunnerTest, RemoveObserverTwice) { 229 TEST_F(ArcSessionRunnerTest, RemoveObserverTwice) {
229 EXPECT_TRUE(arc_session_runner()->stopped()); 230 EXPECT_TRUE(arc_session_runner()->IsStopped());
230 231
231 DummyObserver dummy_observer; 232 DummyObserver dummy_observer;
232 arc_session_runner()->AddObserver(&dummy_observer); 233 arc_session_runner()->AddObserver(&dummy_observer);
233 // Call RemoveObserver() twice. 234 // Call RemoveObserver() twice.
234 arc_session_runner()->RemoveObserver(&dummy_observer); 235 arc_session_runner()->RemoveObserver(&dummy_observer);
235 arc_session_runner()->RemoveObserver(&dummy_observer); 236 arc_session_runner()->RemoveObserver(&dummy_observer);
236 } 237 }
237 238
238 // Removing an unknown observer should be allowed. 239 // Removing an unknown observer should be allowed.
239 TEST_F(ArcSessionRunnerTest, RemoveUnknownObserver) { 240 TEST_F(ArcSessionRunnerTest, RemoveUnknownObserver) {
240 EXPECT_TRUE(arc_session_runner()->stopped()); 241 EXPECT_TRUE(arc_session_runner()->IsStopped());
241 242
242 DummyObserver dummy_observer; 243 DummyObserver dummy_observer;
243 arc_session_runner()->RemoveObserver(&dummy_observer); 244 arc_session_runner()->RemoveObserver(&dummy_observer);
244 } 245 }
245 246
246 } // namespace arc 247 } // namespace arc
OLDNEW
« components/arc/arc_bridge_service.h ('K') | « components/arc/arc_session_runner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698