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

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

Issue 2586183002: Refactor ArcSessionRunner part 2. (Closed)
Patch Set: Rebase Created 3 years, 12 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
« no previous file with comments | « components/arc/arc_session_runner.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.ready_called()); 130 EXPECT_TRUE(observer.ready_called());
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.stopped_called()); 134 EXPECT_TRUE(observer.stopped_called());
134 } 135 }
135 136
136 // If the ArcSessionRunner accepts a request to stop ARC instance, it should 137 // If the ArcSessionRunner accepts a request to stop ARC instance, it should
137 // stop it, even mid-startup. 138 // stop it, even mid-startup.
138 TEST_F(ArcSessionRunnerTest, StopMidStartup) { 139 TEST_F(ArcSessionRunnerTest, StopMidStartup) {
139 ResetArcSessionFactory( 140 ResetArcSessionFactory(
140 base::Bind(&ArcSessionRunnerTest::CreateSuspendedArcSession)); 141 base::Bind(&ArcSessionRunnerTest::CreateSuspendedArcSession));
141 EXPECT_TRUE(arc_session_runner()->stopped()); 142 EXPECT_TRUE(arc_session_runner()->IsStopped());
142 143
143 arc_session_runner()->RequestStart(); 144 arc_session_runner()->RequestStart();
144 EXPECT_FALSE(arc_session_runner()->stopped()); 145 EXPECT_FALSE(arc_session_runner()->IsStopped());
145 EXPECT_FALSE(arc_session_runner()->ready()); 146 EXPECT_FALSE(arc_session_runner()->IsRunning());
146 147
147 arc_session_runner()->RequestStop(); 148 arc_session_runner()->RequestStop();
148 EXPECT_TRUE(arc_session_runner()->stopped()); 149 EXPECT_TRUE(arc_session_runner()->IsStopped());
149 } 150 }
150 151
151 // If the boot procedure is failed, then restarting mechanism should not 152 // If the boot procedure is failed, then restarting mechanism should not
152 // triggered. 153 // triggered.
153 TEST_F(ArcSessionRunnerTest, BootFailure) { 154 TEST_F(ArcSessionRunnerTest, BootFailure) {
154 ResetArcSessionFactory( 155 ResetArcSessionFactory(
155 base::Bind(&ArcSessionRunnerTest::CreateBootFailureArcSession, 156 base::Bind(&ArcSessionRunnerTest::CreateBootFailureArcSession,
156 StopReason::GENERIC_BOOT_FAILURE)); 157 StopReason::GENERIC_BOOT_FAILURE));
157 EXPECT_TRUE(arc_session_runner()->stopped()); 158 EXPECT_TRUE(arc_session_runner()->IsStopped());
158 159
159 arc_session_runner()->RequestStart(); 160 arc_session_runner()->RequestStart();
160 EXPECT_EQ(StopReason::GENERIC_BOOT_FAILURE, stop_reason()); 161 EXPECT_EQ(StopReason::GENERIC_BOOT_FAILURE, stop_reason());
161 EXPECT_TRUE(arc_session_runner()->stopped()); 162 EXPECT_TRUE(arc_session_runner()->IsStopped());
162 } 163 }
163 164
164 // If the instance is stopped, it should be re-started. 165 // If the instance is stopped, it should be re-started.
165 TEST_F(ArcSessionRunnerTest, Restart) { 166 TEST_F(ArcSessionRunnerTest, Restart) {
166 arc_session_runner()->SetRestartDelayForTesting(base::TimeDelta()); 167 arc_session_runner()->SetRestartDelayForTesting(base::TimeDelta());
167 EXPECT_TRUE(arc_session_runner()->stopped()); 168 EXPECT_TRUE(arc_session_runner()->IsStopped());
168 169
169 arc_session_runner()->RequestStart(); 170 arc_session_runner()->RequestStart();
170 EXPECT_TRUE(arc_session_runner()->ready()); 171 EXPECT_TRUE(arc_session_runner()->IsRunning());
171 172
172 // Simulate a connection loss. 173 // Simulate a connection loss.
173 ASSERT_TRUE(arc_session()); 174 ASSERT_TRUE(arc_session());
174 arc_session()->StopWithReason(StopReason::CRASH); 175 arc_session()->StopWithReason(StopReason::CRASH);
175 EXPECT_TRUE(arc_session_runner()->stopped()); 176 EXPECT_TRUE(arc_session_runner()->IsStopped());
176 base::RunLoop().RunUntilIdle(); 177 base::RunLoop().RunUntilIdle();
177 EXPECT_TRUE(arc_session_runner()->ready()); 178 EXPECT_TRUE(arc_session_runner()->IsRunning());
178 179
179 arc_session_runner()->RequestStop(); 180 arc_session_runner()->RequestStop();
180 EXPECT_TRUE(arc_session_runner()->stopped()); 181 EXPECT_TRUE(arc_session_runner()->IsStopped());
181 } 182 }
182 183
183 // Makes sure OnSessionStopped is called on stop. 184 // Makes sure OnSessionStopped is called on stop.
184 TEST_F(ArcSessionRunnerTest, OnSessionStopped) { 185 TEST_F(ArcSessionRunnerTest, OnSessionStopped) {
185 arc_session_runner()->SetRestartDelayForTesting(base::TimeDelta()); 186 arc_session_runner()->SetRestartDelayForTesting(base::TimeDelta());
186 EXPECT_TRUE(arc_session_runner()->stopped()); 187 EXPECT_TRUE(arc_session_runner()->IsStopped());
187 188
188 arc_session_runner()->RequestStart(); 189 arc_session_runner()->RequestStart();
189 EXPECT_TRUE(arc_session_runner()->ready()); 190 EXPECT_TRUE(arc_session_runner()->IsRunning());
190 191
191 // Simulate boot failure. 192 // Simulate boot failure.
192 ASSERT_TRUE(arc_session()); 193 ASSERT_TRUE(arc_session());
193 arc_session()->StopWithReason(StopReason::GENERIC_BOOT_FAILURE); 194 arc_session()->StopWithReason(StopReason::GENERIC_BOOT_FAILURE);
194 EXPECT_EQ(StopReason::GENERIC_BOOT_FAILURE, stop_reason()); 195 EXPECT_EQ(StopReason::GENERIC_BOOT_FAILURE, stop_reason());
195 EXPECT_TRUE(arc_session_runner()->stopped()); 196 EXPECT_TRUE(arc_session_runner()->IsStopped());
196 base::RunLoop().RunUntilIdle(); 197 base::RunLoop().RunUntilIdle();
197 EXPECT_TRUE(arc_session_runner()->ready()); 198 EXPECT_TRUE(arc_session_runner()->IsRunning());
198 199
199 // Simulate crash. 200 // Simulate crash.
200 ASSERT_TRUE(arc_session()); 201 ASSERT_TRUE(arc_session());
201 arc_session()->StopWithReason(StopReason::CRASH); 202 arc_session()->StopWithReason(StopReason::CRASH);
202 EXPECT_EQ(StopReason::CRASH, stop_reason()); 203 EXPECT_EQ(StopReason::CRASH, stop_reason());
203 EXPECT_TRUE(arc_session_runner()->stopped()); 204 EXPECT_TRUE(arc_session_runner()->IsStopped());
204 base::RunLoop().RunUntilIdle(); 205 base::RunLoop().RunUntilIdle();
205 EXPECT_TRUE(arc_session_runner()->ready()); 206 EXPECT_TRUE(arc_session_runner()->IsRunning());
206 207
207 // Graceful stop. 208 // Graceful stop.
208 arc_session_runner()->RequestStop(); 209 arc_session_runner()->RequestStop();
209 EXPECT_EQ(StopReason::SHUTDOWN, stop_reason()); 210 EXPECT_EQ(StopReason::SHUTDOWN, stop_reason());
210 EXPECT_TRUE(arc_session_runner()->stopped()); 211 EXPECT_TRUE(arc_session_runner()->IsStopped());
211 } 212 }
212 213
213 TEST_F(ArcSessionRunnerTest, Shutdown) { 214 TEST_F(ArcSessionRunnerTest, Shutdown) {
214 arc_session_runner()->SetRestartDelayForTesting(base::TimeDelta()); 215 arc_session_runner()->SetRestartDelayForTesting(base::TimeDelta());
215 EXPECT_TRUE(arc_session_runner()->stopped()); 216 EXPECT_TRUE(arc_session_runner()->IsStopped());
216 217
217 arc_session_runner()->RequestStart(); 218 arc_session_runner()->RequestStart();
218 EXPECT_TRUE(arc_session_runner()->ready()); 219 EXPECT_TRUE(arc_session_runner()->IsRunning());
219 220
220 // Simulate shutdown. 221 // Simulate shutdown.
221 arc_session_runner()->OnShutdown(); 222 arc_session_runner()->OnShutdown();
222 EXPECT_EQ(StopReason::SHUTDOWN, stop_reason()); 223 EXPECT_EQ(StopReason::SHUTDOWN, stop_reason());
223 EXPECT_TRUE(arc_session_runner()->stopped()); 224 EXPECT_TRUE(arc_session_runner()->IsStopped());
224 } 225 }
225 226
226 // Removing the same observer more than once should be okay. 227 // Removing the same observer more than once should be okay.
227 TEST_F(ArcSessionRunnerTest, RemoveObserverTwice) { 228 TEST_F(ArcSessionRunnerTest, RemoveObserverTwice) {
228 EXPECT_TRUE(arc_session_runner()->stopped()); 229 EXPECT_TRUE(arc_session_runner()->IsStopped());
229 230
230 DummyObserver dummy_observer; 231 DummyObserver dummy_observer;
231 arc_session_runner()->AddObserver(&dummy_observer); 232 arc_session_runner()->AddObserver(&dummy_observer);
232 // Call RemoveObserver() twice. 233 // Call RemoveObserver() twice.
233 arc_session_runner()->RemoveObserver(&dummy_observer); 234 arc_session_runner()->RemoveObserver(&dummy_observer);
234 arc_session_runner()->RemoveObserver(&dummy_observer); 235 arc_session_runner()->RemoveObserver(&dummy_observer);
235 } 236 }
236 237
237 // Removing an unknown observer should be allowed. 238 // Removing an unknown observer should be allowed.
238 TEST_F(ArcSessionRunnerTest, RemoveUnknownObserver) { 239 TEST_F(ArcSessionRunnerTest, RemoveUnknownObserver) {
239 EXPECT_TRUE(arc_session_runner()->stopped()); 240 EXPECT_TRUE(arc_session_runner()->IsStopped());
240 241
241 DummyObserver dummy_observer; 242 DummyObserver dummy_observer;
242 arc_session_runner()->RemoveObserver(&dummy_observer); 243 arc_session_runner()->RemoveObserver(&dummy_observer);
243 } 244 }
244 245
245 } // namespace arc 246 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/arc_session_runner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698