OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/chromeos/system/automatic_reboot_manager.h" | 5 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
| 8 #include <utility> |
8 | 9 |
9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
10 #include "ash/test/test_shell_delegate.h" | 11 #include "ash/test/test_shell_delegate.h" |
11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
14 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
16 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
17 #include "base/path_service.h" | 18 #include "base/path_service.h" |
18 #include "base/prefs/pref_registry_simple.h" | 19 #include "base/prefs/pref_registry_simple.h" |
19 #include "base/prefs/testing_pref_service.h" | 20 #include "base/prefs/testing_pref_service.h" |
20 #include "base/run_loop.h" | 21 #include "base/run_loop.h" |
| 22 #include "base/single_thread_task_runner.h" |
21 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
22 #include "base/test/simple_test_tick_clock.h" | 24 #include "base/test/simple_test_tick_clock.h" |
23 #include "base/test/test_mock_time_task_runner.h" | |
24 #include "base/thread_task_runner_handle.h" | 25 #include "base/thread_task_runner_handle.h" |
25 #include "base/threading/sequenced_worker_pool.h" | 26 #include "base/threading/sequenced_worker_pool.h" |
26 #include "base/time/tick_clock.h" | 27 #include "base/time/tick_clock.h" |
27 #include "base/values.h" | 28 #include "base/values.h" |
28 #include "chrome/browser/chrome_notification_types.h" | 29 #include "chrome/browser/chrome_notification_types.h" |
29 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 30 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
30 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 31 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
31 #include "chrome/browser/chromeos/system/automatic_reboot_manager_observer.h" | 32 #include "chrome/browser/chromeos/system/automatic_reboot_manager_observer.h" |
32 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
33 #include "chrome/test/base/testing_browser_process.h" | 34 #include "chrome/test/base/testing_browser_process.h" |
(...skipping 13 matching lines...) Expand all Loading... |
47 using ::testing::_; | 48 using ::testing::_; |
48 using ::testing::Invoke; | 49 using ::testing::Invoke; |
49 using ::testing::Mock; | 50 using ::testing::Mock; |
50 using ::testing::ReturnPointee; | 51 using ::testing::ReturnPointee; |
51 | 52 |
52 namespace chromeos { | 53 namespace chromeos { |
53 namespace system { | 54 namespace system { |
54 | 55 |
55 namespace { | 56 namespace { |
56 | 57 |
57 // Provides a mock device uptime that follows the given |tick_clock_| with a | 58 // A SingleThreadTaskRunner that mocks the current time and allows it to be |
58 // configurable offset. The mock uptime can also be written to |uptime_file_|, | 59 // fast-forwarded. The current time in ticks is returned by Now(). The |
59 // thusly allowing to mock /proc/uptime. | 60 // corresponding device uptime is written to |uptime_file_|, providing a mock |
60 class MockUptimeProvider { | 61 // for /proc/uptime. |
| 62 class MockTimeSingleThreadTaskRunner : public base::SingleThreadTaskRunner { |
61 public: | 63 public: |
62 explicit MockUptimeProvider(scoped_ptr<base::TickClock> tick_clock); | 64 MockTimeSingleThreadTaskRunner(); |
63 | 65 |
64 void WriteUptimeToFile(); | 66 // base::SingleThreadTaskRunner: |
| 67 virtual bool RunsTasksOnCurrentThread() const override; |
| 68 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 69 const base::Closure& task, |
| 70 base::TimeDelta delay) override; |
| 71 virtual bool PostNonNestableDelayedTask( |
| 72 const tracked_objects::Location& from_here, |
| 73 const base::Closure& task, |
| 74 base::TimeDelta delay) override; |
65 | 75 |
66 // Adjusts the offset so that the current mock uptime will be |uptime|. | 76 void SetUptimeFile(const base::FilePath& uptime_file); |
67 void SetUptime(const base::TimeDelta& uptime); | 77 void SetUptime(const base::TimeDelta& uptime); |
68 | 78 |
69 void set_uptime_file_path(const base::FilePath& uptime_file_path) { | 79 const base::TimeDelta& Uptime() const; |
70 uptime_file_path_ = uptime_file_path; | 80 const base::TimeTicks& Now() const; |
71 } | |
72 | 81 |
73 base::TimeDelta uptime() const { | 82 void FastForwardBy(const base::TimeDelta& delta); |
74 return tick_clock_->NowTicks() - base::TimeTicks() + uptime_offset_; | 83 void FastForwardUntilNoTasksRemain(); |
75 } | 84 void RunUntilIdle(); |
76 | 85 |
77 private: | 86 private: |
78 scoped_ptr<base::TickClock> tick_clock_; | 87 // Strict weak temporal ordering of tasks. |
| 88 class TemporalOrder { |
| 89 public: |
| 90 bool operator()( |
| 91 const std::pair<base::TimeTicks, base::Closure>& first_task, |
| 92 const std::pair<base::TimeTicks, base::Closure>& second_task) const; |
| 93 }; |
79 | 94 |
80 base::FilePath uptime_file_path_; | 95 virtual ~MockTimeSingleThreadTaskRunner(); |
81 base::TimeDelta uptime_offset_; | |
82 | 96 |
83 DISALLOW_COPY_AND_ASSIGN(MockUptimeProvider); | 97 base::FilePath uptime_file_; |
| 98 base::TimeDelta uptime_; |
| 99 base::TimeTicks now_; |
| 100 std::priority_queue<std::pair<base::TimeTicks, base::Closure>, |
| 101 std::vector<std::pair<base::TimeTicks, base::Closure> >, |
| 102 TemporalOrder> tasks_; |
| 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(MockTimeSingleThreadTaskRunner); |
84 }; | 105 }; |
85 | 106 |
86 class TestAutomaticRebootManagerTaskRunner | 107 class MockTimeTickClock : public base::TickClock { |
87 : public base::TestMockTimeTaskRunner { | |
88 public: | 108 public: |
89 TestAutomaticRebootManagerTaskRunner(); | 109 explicit MockTimeTickClock( |
| 110 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner); |
| 111 virtual ~MockTimeTickClock(); |
90 | 112 |
91 MockUptimeProvider* uptime_provider() const { | 113 // base::TickClock: |
92 return uptime_provider_.get(); | 114 virtual base::TimeTicks NowTicks() override; |
93 } | |
94 | 115 |
95 private: | 116 private: |
96 ~TestAutomaticRebootManagerTaskRunner() override; | 117 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_; |
97 | 118 |
98 // base::TestMockTimeTaskRunner: | 119 DISALLOW_COPY_AND_ASSIGN(MockTimeTickClock); |
99 void OnBeforeSelectingTask() override; | |
100 void OnAfterTimePassed() override; | |
101 void OnAfterTaskRun() override; | |
102 | |
103 scoped_ptr<MockUptimeProvider> uptime_provider_; | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(TestAutomaticRebootManagerTaskRunner); | |
106 }; | 120 }; |
107 | 121 |
108 class MockAutomaticRebootManagerObserver | 122 class MockAutomaticRebootManagerObserver |
109 : public AutomaticRebootManagerObserver { | 123 : public AutomaticRebootManagerObserver { |
110 public: | 124 public: |
111 MockAutomaticRebootManagerObserver(); | 125 MockAutomaticRebootManagerObserver(); |
112 ~MockAutomaticRebootManagerObserver() override; | 126 ~MockAutomaticRebootManagerObserver() override; |
113 | 127 |
114 void Init(AutomaticRebootManager* automatic_reboot_manger); | 128 void Init(AutomaticRebootManager* automatic_reboot_manger); |
115 | 129 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 bool ReadUpdateRebootNeededUptimeFromFile(base::TimeDelta* uptime); | 170 bool ReadUpdateRebootNeededUptimeFromFile(base::TimeDelta* uptime); |
157 void VerifyRebootRequested(AutomaticRebootManagerObserver::Reason reason); | 171 void VerifyRebootRequested(AutomaticRebootManagerObserver::Reason reason); |
158 void VerifyNoRebootRequested() const; | 172 void VerifyNoRebootRequested() const; |
159 void VerifyLoginScreenIdleTimerIsStopped() const; | 173 void VerifyLoginScreenIdleTimerIsStopped() const; |
160 void VerifyNoGracePeriod() const; | 174 void VerifyNoGracePeriod() const; |
161 void VerifyGracePeriod(const base::TimeDelta& start_uptime) const; | 175 void VerifyGracePeriod(const base::TimeDelta& start_uptime) const; |
162 | 176 |
163 // Sets the status of |update_engine_client_| to NEED_REBOOT for tests. | 177 // Sets the status of |update_engine_client_| to NEED_REBOOT for tests. |
164 void SetUpdateStatusNeedReboot(); | 178 void SetUpdateStatusNeedReboot(); |
165 | 179 |
166 MockUptimeProvider* uptime_provider() const { | |
167 return task_runner_->uptime_provider(); | |
168 } | |
169 | |
170 bool is_user_logged_in_; | 180 bool is_user_logged_in_; |
171 bool is_logged_in_as_kiosk_app_; | 181 bool is_logged_in_as_kiosk_app_; |
172 | 182 |
173 // The uptime is read in the blocking thread pool and then processed on the | 183 // The uptime is read in the blocking thread pool and then processed on the |
174 // UI thread. This causes the UI thread to start processing the uptime when it | 184 // UI thread. This causes the UI thread to start processing the uptime when it |
175 // has increased by a small offset already. The offset is calculated and | 185 // has increased by a small offset already. The offset is calculated and |
176 // stored in |uptime_processing_delay_| so that tests can accurately determine | 186 // stored in |uptime_processing_delay_| so that tests can accurately determine |
177 // the uptime seen by the UI thread. | 187 // the uptime seen by the UI thread. |
178 base::TimeDelta uptime_processing_delay_; | 188 base::TimeDelta uptime_processing_delay_; |
179 base::TimeDelta update_reboot_needed_uptime_; | 189 base::TimeDelta update_reboot_needed_uptime_; |
180 base::TimeDelta uptime_limit_; | 190 base::TimeDelta uptime_limit_; |
181 | 191 |
182 scoped_refptr<TestAutomaticRebootManagerTaskRunner> task_runner_; | 192 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_; |
183 | 193 |
184 MockAutomaticRebootManagerObserver automatic_reboot_manager_observer_; | 194 MockAutomaticRebootManagerObserver automatic_reboot_manager_observer_; |
185 scoped_ptr<AutomaticRebootManager> automatic_reboot_manager_; | 195 scoped_ptr<AutomaticRebootManager> automatic_reboot_manager_; |
186 | 196 |
187 private: | 197 private: |
188 void VerifyTimerIsStopped(const Timer* timer) const; | 198 void VerifyTimerIsStopped(const Timer* timer) const; |
189 void VerifyTimerIsRunning(const Timer* timer, | 199 void VerifyTimerIsRunning(const Timer* timer, |
190 const base::TimeDelta& delay) const; | 200 const base::TimeDelta& delay) const; |
191 void VerifyLoginScreenIdleTimerIsRunning() const; | 201 void VerifyLoginScreenIdleTimerIsRunning() const; |
192 | 202 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 const base::TimeDelta& uptime) { | 237 const base::TimeDelta& uptime) { |
228 if (path.empty() || uptime == base::TimeDelta()) | 238 if (path.empty() || uptime == base::TimeDelta()) |
229 return; | 239 return; |
230 | 240 |
231 const std::string uptime_seconds = base::DoubleToString(uptime.InSecondsF()); | 241 const std::string uptime_seconds = base::DoubleToString(uptime.InSecondsF()); |
232 ASSERT_EQ(static_cast<int>(uptime_seconds.size()), | 242 ASSERT_EQ(static_cast<int>(uptime_seconds.size()), |
233 base::WriteFile(path, uptime_seconds.c_str(), | 243 base::WriteFile(path, uptime_seconds.c_str(), |
234 uptime_seconds.size())); | 244 uptime_seconds.size())); |
235 } | 245 } |
236 | 246 |
237 MockUptimeProvider::MockUptimeProvider(scoped_ptr<base::TickClock> tick_clock) | 247 MockTimeSingleThreadTaskRunner::MockTimeSingleThreadTaskRunner() { |
238 : tick_clock_(tick_clock.Pass()) { | |
239 } | 248 } |
240 | 249 |
241 void MockUptimeProvider::WriteUptimeToFile() { | 250 bool MockTimeSingleThreadTaskRunner::RunsTasksOnCurrentThread() const { |
242 SaveUptimeToFile(uptime_file_path_, uptime()); | 251 return true; |
243 } | 252 } |
244 | 253 |
245 void MockUptimeProvider::SetUptime(const base::TimeDelta& uptime) { | 254 bool MockTimeSingleThreadTaskRunner::PostDelayedTask( |
246 uptime_offset_ = uptime - (tick_clock_->NowTicks() - base::TimeTicks()); | 255 const tracked_objects::Location& from_here, |
247 WriteUptimeToFile(); | 256 const base::Closure& task, |
| 257 base::TimeDelta delay) { |
| 258 tasks_.push(std::pair<base::TimeTicks, base::Closure>(now_ + delay, task)); |
| 259 return true; |
248 } | 260 } |
249 | 261 |
250 TestAutomaticRebootManagerTaskRunner::TestAutomaticRebootManagerTaskRunner() | 262 bool MockTimeSingleThreadTaskRunner::PostNonNestableDelayedTask( |
251 : uptime_provider_(new MockUptimeProvider(GetMockTickClock())) { | 263 const tracked_objects::Location& from_here, |
| 264 const base::Closure& task, |
| 265 base::TimeDelta delay) { |
| 266 NOTREACHED(); |
| 267 return false; |
252 } | 268 } |
253 | 269 |
254 TestAutomaticRebootManagerTaskRunner::~TestAutomaticRebootManagerTaskRunner() { | 270 void MockTimeSingleThreadTaskRunner::SetUptimeFile( |
| 271 const base::FilePath& uptime_file) { |
| 272 uptime_file_ = uptime_file; |
| 273 SaveUptimeToFile(uptime_file_, uptime_); |
255 } | 274 } |
256 | 275 |
257 void TestAutomaticRebootManagerTaskRunner::OnBeforeSelectingTask() { | 276 void MockTimeSingleThreadTaskRunner::SetUptime(const base::TimeDelta& uptime) { |
| 277 uptime_ = uptime; |
| 278 SaveUptimeToFile(uptime_file_, uptime_); |
| 279 } |
| 280 |
| 281 const base::TimeDelta& MockTimeSingleThreadTaskRunner::Uptime() const { |
| 282 return uptime_; |
| 283 } |
| 284 |
| 285 const base::TimeTicks& MockTimeSingleThreadTaskRunner::Now() const { |
| 286 return now_; |
| 287 } |
| 288 |
| 289 void MockTimeSingleThreadTaskRunner::FastForwardBy( |
| 290 const base::TimeDelta& delta) { |
| 291 const base::TimeTicks latest = now_ + delta; |
258 base::SequencedWorkerPool* blocking_pool = | 292 base::SequencedWorkerPool* blocking_pool = |
259 content::BrowserThread::GetBlockingPool(); | 293 content::BrowserThread::GetBlockingPool(); |
260 blocking_pool->FlushForTesting(); | 294 blocking_pool->FlushForTesting(); |
| 295 while (!tasks_.empty() && tasks_.top().first <= latest) { |
| 296 uptime_ += tasks_.top().first - now_; |
| 297 SaveUptimeToFile(uptime_file_, uptime_); |
| 298 now_ = tasks_.top().first; |
| 299 base::Closure task = tasks_.top().second; |
| 300 tasks_.pop(); |
| 301 task.Run(); |
| 302 blocking_pool->FlushForTesting(); |
| 303 } |
| 304 uptime_ += latest - now_; |
| 305 SaveUptimeToFile(uptime_file_, uptime_); |
| 306 now_ = latest; |
261 } | 307 } |
262 | 308 |
263 void TestAutomaticRebootManagerTaskRunner::OnAfterTimePassed() { | 309 void MockTimeSingleThreadTaskRunner::FastForwardUntilNoTasksRemain() { |
264 uptime_provider_->WriteUptimeToFile(); | |
265 } | |
266 | |
267 void TestAutomaticRebootManagerTaskRunner::OnAfterTaskRun() { | |
268 base::SequencedWorkerPool* blocking_pool = | 310 base::SequencedWorkerPool* blocking_pool = |
269 content::BrowserThread::GetBlockingPool(); | 311 content::BrowserThread::GetBlockingPool(); |
270 blocking_pool->FlushForTesting(); | 312 blocking_pool->FlushForTesting(); |
| 313 while (!tasks_.empty()) { |
| 314 uptime_ += tasks_.top().first - now_; |
| 315 SaveUptimeToFile(uptime_file_, uptime_); |
| 316 now_ = tasks_.top().first; |
| 317 base::Closure task = tasks_.top().second; |
| 318 tasks_.pop(); |
| 319 task.Run(); |
| 320 blocking_pool->FlushForTesting(); |
| 321 } |
| 322 } |
| 323 |
| 324 void MockTimeSingleThreadTaskRunner::RunUntilIdle() { |
| 325 base::SequencedWorkerPool* blocking_pool = |
| 326 content::BrowserThread::GetBlockingPool(); |
| 327 blocking_pool->FlushForTesting(); |
| 328 while (!tasks_.empty() && tasks_.top().first <= now_) { |
| 329 base::Closure task = tasks_.top().second; |
| 330 tasks_.pop(); |
| 331 task.Run(); |
| 332 blocking_pool->FlushForTesting(); |
| 333 } |
| 334 } |
| 335 |
| 336 bool MockTimeSingleThreadTaskRunner::TemporalOrder::operator()( |
| 337 const std::pair<base::TimeTicks, base::Closure>& first_task, |
| 338 const std::pair<base::TimeTicks, base::Closure>& second_task) const { |
| 339 return first_task.first > second_task.first; |
| 340 } |
| 341 |
| 342 MockTimeSingleThreadTaskRunner::~MockTimeSingleThreadTaskRunner() { |
| 343 } |
| 344 |
| 345 MockTimeTickClock::MockTimeTickClock( |
| 346 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner) |
| 347 : task_runner_(task_runner) { |
| 348 } |
| 349 |
| 350 MockTimeTickClock::~MockTimeTickClock() { |
| 351 } |
| 352 |
| 353 base::TimeTicks MockTimeTickClock::NowTicks() { |
| 354 return task_runner_->Now(); |
271 } | 355 } |
272 | 356 |
273 MockAutomaticRebootManagerObserver::MockAutomaticRebootManagerObserver() | 357 MockAutomaticRebootManagerObserver::MockAutomaticRebootManagerObserver() |
274 : automatic_reboot_manger_(nullptr) { | 358 : automatic_reboot_manger_(nullptr) { |
275 ON_CALL(*this, WillDestroyAutomaticRebootManager()) | 359 ON_CALL(*this, WillDestroyAutomaticRebootManager()) |
276 .WillByDefault( | 360 .WillByDefault( |
277 Invoke(this, | 361 Invoke(this, |
278 &MockAutomaticRebootManagerObserver::StopObserving)); | 362 &MockAutomaticRebootManagerObserver::StopObserving)); |
279 } | 363 } |
280 | 364 |
(...skipping 11 matching lines...) Expand all Loading... |
292 | 376 |
293 void MockAutomaticRebootManagerObserver::StopObserving() { | 377 void MockAutomaticRebootManagerObserver::StopObserving() { |
294 ASSERT_TRUE(automatic_reboot_manger_); | 378 ASSERT_TRUE(automatic_reboot_manger_); |
295 automatic_reboot_manger_->RemoveObserver(this); | 379 automatic_reboot_manger_->RemoveObserver(this); |
296 automatic_reboot_manger_ = nullptr; | 380 automatic_reboot_manger_ = nullptr; |
297 } | 381 } |
298 | 382 |
299 AutomaticRebootManagerBasicTest::AutomaticRebootManagerBasicTest() | 383 AutomaticRebootManagerBasicTest::AutomaticRebootManagerBasicTest() |
300 : is_user_logged_in_(false), | 384 : is_user_logged_in_(false), |
301 is_logged_in_as_kiosk_app_(false), | 385 is_logged_in_as_kiosk_app_(false), |
302 task_runner_(new TestAutomaticRebootManagerTaskRunner), | 386 task_runner_(new MockTimeSingleThreadTaskRunner), |
303 reboot_after_update_(false), | 387 reboot_after_update_(false), |
304 ui_thread_task_runner_handle_(task_runner_), | 388 ui_thread_task_runner_handle_(task_runner_), |
305 mock_user_manager_(new MockUserManager), | 389 mock_user_manager_(new MockUserManager), |
306 user_manager_enabler_(mock_user_manager_), | 390 user_manager_enabler_(mock_user_manager_), |
307 power_manager_client_(NULL), | 391 power_manager_client_(NULL), |
308 update_engine_client_(NULL) { | 392 update_engine_client_(NULL) { |
309 } | 393 } |
310 | 394 |
311 AutomaticRebootManagerBasicTest::~AutomaticRebootManagerBasicTest() { | 395 AutomaticRebootManagerBasicTest::~AutomaticRebootManagerBasicTest() { |
312 } | 396 } |
313 | 397 |
314 void AutomaticRebootManagerBasicTest::SetUp() { | 398 void AutomaticRebootManagerBasicTest::SetUp() { |
315 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 399 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
316 const base::FilePath& temp_dir = temp_dir_.path(); | 400 const base::FilePath& temp_dir = temp_dir_.path(); |
317 const base::FilePath uptime_file = temp_dir.Append("uptime"); | 401 const base::FilePath uptime_file = temp_dir.Append("uptime"); |
318 uptime_provider()->set_uptime_file_path(uptime_file); | 402 task_runner_->SetUptimeFile(uptime_file); |
319 ASSERT_FALSE(base::WriteFile(uptime_file, NULL, 0)); | 403 ASSERT_FALSE(base::WriteFile(uptime_file, NULL, 0)); |
320 update_reboot_needed_uptime_file_ = | 404 update_reboot_needed_uptime_file_ = |
321 temp_dir.Append("update_reboot_needed_uptime"); | 405 temp_dir.Append("update_reboot_needed_uptime"); |
322 ASSERT_FALSE(base::WriteFile(update_reboot_needed_uptime_file_, NULL, 0)); | 406 ASSERT_FALSE(base::WriteFile(update_reboot_needed_uptime_file_, NULL, 0)); |
323 ASSERT_TRUE(PathService::Override(chromeos::FILE_UPTIME, uptime_file)); | 407 ASSERT_TRUE(PathService::Override(chromeos::FILE_UPTIME, uptime_file)); |
324 ASSERT_TRUE(PathService::Override(chromeos::FILE_UPDATE_REBOOT_NEEDED_UPTIME, | 408 ASSERT_TRUE(PathService::Override(chromeos::FILE_UPDATE_REBOOT_NEEDED_UPTIME, |
325 update_reboot_needed_uptime_file_)); | 409 update_reboot_needed_uptime_file_)); |
326 | 410 |
327 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); | 411 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); |
328 AutomaticRebootManager::RegisterPrefs(local_state_.registry()); | 412 AutomaticRebootManager::RegisterPrefs(local_state_.registry()); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 Mock::VerifyAndClearExpectations(&automatic_reboot_manager_observer_); | 531 Mock::VerifyAndClearExpectations(&automatic_reboot_manager_observer_); |
448 EXPECT_CALL(automatic_reboot_manager_observer_, | 532 EXPECT_CALL(automatic_reboot_manager_observer_, |
449 WillDestroyAutomaticRebootManager()).Times(0); | 533 WillDestroyAutomaticRebootManager()).Times(0); |
450 EXPECT_CALL(automatic_reboot_manager_observer_, | 534 EXPECT_CALL(automatic_reboot_manager_observer_, |
451 OnRebootRequested(_)).Times(0); | 535 OnRebootRequested(_)).Times(0); |
452 } | 536 } |
453 | 537 |
454 void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager( | 538 void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager( |
455 bool expect_reboot) { | 539 bool expect_reboot) { |
456 automatic_reboot_manager_.reset(new AutomaticRebootManager( | 540 automatic_reboot_manager_.reset(new AutomaticRebootManager( |
457 scoped_ptr<base::TickClock>(task_runner_->GetMockTickClock()))); | 541 scoped_ptr<base::TickClock>(new MockTimeTickClock(task_runner_)))); |
458 automatic_reboot_manager_observer_.Init(automatic_reboot_manager_.get()); | 542 automatic_reboot_manager_observer_.Init(automatic_reboot_manager_.get()); |
459 task_runner_->RunUntilIdle(); | 543 task_runner_->RunUntilIdle(); |
460 EXPECT_EQ(expect_reboot ? 1 : 0, | 544 EXPECT_EQ(expect_reboot ? 1 : 0, |
461 power_manager_client_->num_request_restart_calls()); | 545 power_manager_client_->num_request_restart_calls()); |
462 | 546 |
463 uptime_processing_delay_ = | 547 uptime_processing_delay_ = |
464 base::TimeTicks() - automatic_reboot_manager_->boot_time_ - | 548 base::TimeTicks() - automatic_reboot_manager_->boot_time_ - |
465 uptime_provider()->uptime(); | 549 task_runner_->Uptime(); |
466 EXPECT_GE(uptime_processing_delay_, base::TimeDelta()); | 550 EXPECT_GE(uptime_processing_delay_, base::TimeDelta()); |
467 EXPECT_LE(uptime_processing_delay_, base::TimeDelta::FromSeconds(1)); | 551 EXPECT_LE(uptime_processing_delay_, base::TimeDelta::FromSeconds(1)); |
468 | 552 |
469 if (is_user_logged_in_ || expect_reboot) | 553 if (is_user_logged_in_ || expect_reboot) |
470 VerifyLoginScreenIdleTimerIsStopped(); | 554 VerifyLoginScreenIdleTimerIsStopped(); |
471 else | 555 else |
472 VerifyLoginScreenIdleTimerIsRunning(); | 556 VerifyLoginScreenIdleTimerIsRunning(); |
473 } | 557 } |
474 | 558 |
475 bool AutomaticRebootManagerBasicTest::ReadUpdateRebootNeededUptimeFromFile( | 559 bool AutomaticRebootManagerBasicTest::ReadUpdateRebootNeededUptimeFromFile( |
(...skipping 29 matching lines...) Expand all Loading... |
505 | 589 |
506 void AutomaticRebootManagerBasicTest::VerifyNoGracePeriod() const { | 590 void AutomaticRebootManagerBasicTest::VerifyNoGracePeriod() const { |
507 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_); | 591 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_); |
508 VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get()); | 592 VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get()); |
509 VerifyTimerIsStopped(automatic_reboot_manager_->grace_end_timer_.get()); | 593 VerifyTimerIsStopped(automatic_reboot_manager_->grace_end_timer_.get()); |
510 } | 594 } |
511 | 595 |
512 void AutomaticRebootManagerBasicTest::VerifyGracePeriod( | 596 void AutomaticRebootManagerBasicTest::VerifyGracePeriod( |
513 const base::TimeDelta& start_uptime) const { | 597 const base::TimeDelta& start_uptime) const { |
514 const base::TimeDelta start = | 598 const base::TimeDelta start = |
515 start_uptime - uptime_provider()->uptime() - uptime_processing_delay_; | 599 start_uptime - task_runner_->Uptime() - uptime_processing_delay_; |
516 const base::TimeDelta end = start + base::TimeDelta::FromHours(24); | 600 const base::TimeDelta end = start + base::TimeDelta::FromHours(24); |
517 if (start <= base::TimeDelta()) { | 601 if (start <= base::TimeDelta()) { |
518 EXPECT_TRUE(automatic_reboot_manager_->reboot_requested_); | 602 EXPECT_TRUE(automatic_reboot_manager_->reboot_requested_); |
519 VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get()); | 603 VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get()); |
520 VerifyTimerIsRunning(automatic_reboot_manager_->grace_end_timer_.get(), | 604 VerifyTimerIsRunning(automatic_reboot_manager_->grace_end_timer_.get(), |
521 end); | 605 end); |
522 } else { | 606 } else { |
523 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_); | 607 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_); |
524 VerifyTimerIsRunning(automatic_reboot_manager_->grace_start_timer_.get(), | 608 VerifyTimerIsRunning(automatic_reboot_manager_->grace_start_timer_.get(), |
525 start); | 609 start); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 } | 657 } |
574 } | 658 } |
575 | 659 |
576 AutomaticRebootManagerTest::~AutomaticRebootManagerTest() { | 660 AutomaticRebootManagerTest::~AutomaticRebootManagerTest() { |
577 } | 661 } |
578 | 662 |
579 // Chrome is showing the login screen. The current uptime is 12 hours. | 663 // Chrome is showing the login screen. The current uptime is 12 hours. |
580 // Verifies that the idle timer is running. Further verifies that when a kiosk | 664 // Verifies that the idle timer is running. Further verifies that when a kiosk |
581 // app session begins, the idle timer is stopped. | 665 // app session begins, the idle timer is stopped. |
582 TEST_F(AutomaticRebootManagerBasicTest, LoginStopsIdleTimer) { | 666 TEST_F(AutomaticRebootManagerBasicTest, LoginStopsIdleTimer) { |
583 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 667 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
584 | 668 |
585 // Verify that no reboot is requested, the device does not reboot immediately | 669 // Verify that no reboot is requested, the device does not reboot immediately |
586 // and the login screen idle timer is started. | 670 // and the login screen idle timer is started. |
587 ExpectNoRebootRequest(); | 671 ExpectNoRebootRequest(); |
588 CreateAutomaticRebootManager(false); | 672 CreateAutomaticRebootManager(false); |
589 VerifyNoRebootRequested(); | 673 VerifyNoRebootRequested(); |
590 | 674 |
591 // Notify that a kiosk app session has been started. | 675 // Notify that a kiosk app session has been started. |
592 is_user_logged_in_ = true; | 676 is_user_logged_in_ = true; |
593 is_logged_in_as_kiosk_app_ = true; | 677 is_logged_in_as_kiosk_app_ = true; |
594 automatic_reboot_manager_->Observe( | 678 automatic_reboot_manager_->Observe( |
595 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 679 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
596 content::Source<AutomaticRebootManagerBasicTest>(this), | 680 content::Source<AutomaticRebootManagerBasicTest>(this), |
597 content::NotificationService::NoDetails()); | 681 content::NotificationService::NoDetails()); |
598 | 682 |
599 // Verify that the login screen idle timer is stopped. | 683 // Verify that the login screen idle timer is stopped. |
600 VerifyLoginScreenIdleTimerIsStopped(); | 684 VerifyLoginScreenIdleTimerIsStopped(); |
601 | 685 |
602 // Verify that a reboot is never requested and the device never reboots. | 686 // Verify that a reboot is never requested and the device never reboots. |
603 FastForwardUntilNoTasksRemain(false); | 687 FastForwardUntilNoTasksRemain(false); |
604 } | 688 } |
605 | 689 |
606 // Chrome is showing the login screen. The current uptime is 12 hours. | 690 // Chrome is showing the login screen. The current uptime is 12 hours. |
607 // Verifies that the idle timer is running. Further verifies that when a | 691 // Verifies that the idle timer is running. Further verifies that when a |
608 // non-kiosk-app session begins, the idle timer is stopped. | 692 // non-kiosk-app session begins, the idle timer is stopped. |
609 TEST_F(AutomaticRebootManagerBasicTest, NonKioskLoginStopsIdleTimer) { | 693 TEST_F(AutomaticRebootManagerBasicTest, NonKioskLoginStopsIdleTimer) { |
610 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 694 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
611 | 695 |
612 // Verify that no reboot is requested, the device does not reboot immediately | 696 // Verify that no reboot is requested, the device does not reboot immediately |
613 // and the login screen idle timer is started. | 697 // and the login screen idle timer is started. |
614 ExpectNoRebootRequest(); | 698 ExpectNoRebootRequest(); |
615 CreateAutomaticRebootManager(false); | 699 CreateAutomaticRebootManager(false); |
616 VerifyNoRebootRequested(); | 700 VerifyNoRebootRequested(); |
617 | 701 |
618 // Notify that a non-kiosk-app session has been started. | 702 // Notify that a non-kiosk-app session has been started. |
619 is_user_logged_in_ = true; | 703 is_user_logged_in_ = true; |
620 automatic_reboot_manager_->Observe( | 704 automatic_reboot_manager_->Observe( |
621 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 705 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
622 content::Source<AutomaticRebootManagerBasicTest>(this), | 706 content::Source<AutomaticRebootManagerBasicTest>(this), |
623 content::NotificationService::NoDetails()); | 707 content::NotificationService::NoDetails()); |
624 | 708 |
625 // Verify that the login screen idle timer is stopped. | 709 // Verify that the login screen idle timer is stopped. |
626 VerifyLoginScreenIdleTimerIsStopped(); | 710 VerifyLoginScreenIdleTimerIsStopped(); |
627 | 711 |
628 // Verify that a reboot is never requested and the device never reboots. | 712 // Verify that a reboot is never requested and the device never reboots. |
629 FastForwardUntilNoTasksRemain(false); | 713 FastForwardUntilNoTasksRemain(false); |
630 } | 714 } |
631 | 715 |
632 // Chrome is showing the login screen. The uptime limit is 6 hours. The current | 716 // Chrome is showing the login screen. The uptime limit is 6 hours. The current |
633 // uptime is 12 hours. | 717 // uptime is 12 hours. |
634 // Verifies that user activity prevents the device from rebooting. Further | 718 // Verifies that user activity prevents the device from rebooting. Further |
635 // verifies that when user activity ceases, the devices reboots. | 719 // verifies that when user activity ceases, the devices reboots. |
636 TEST_F(AutomaticRebootManagerBasicTest, UserActivityResetsIdleTimer) { | 720 TEST_F(AutomaticRebootManagerBasicTest, UserActivityResetsIdleTimer) { |
637 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 721 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
638 | 722 |
639 // Verify that no reboot is requested, the device does not reboot immediately | 723 // Verify that no reboot is requested, the device does not reboot immediately |
640 // and the login screen idle timer is started. | 724 // and the login screen idle timer is started. |
641 ExpectNoRebootRequest(); | 725 ExpectNoRebootRequest(); |
642 CreateAutomaticRebootManager(false); | 726 CreateAutomaticRebootManager(false); |
643 VerifyNoRebootRequested(); | 727 VerifyNoRebootRequested(); |
644 | 728 |
645 // Set the uptime limit. Verify that a reboot is requested but the device does | 729 // Set the uptime limit. Verify that a reboot is requested but the device does |
646 // not reboot immediately. | 730 // not reboot immediately. |
647 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 731 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
(...skipping 17 matching lines...) Expand all Loading... |
665 // Verify that the device reboots immediately. | 749 // Verify that the device reboots immediately. |
666 FastForwardBy(base::TimeDelta::FromSeconds(60), true); | 750 FastForwardBy(base::TimeDelta::FromSeconds(60), true); |
667 } | 751 } |
668 | 752 |
669 // Chrome is running a kiosk app session. The current uptime is 10 days. | 753 // Chrome is running a kiosk app session. The current uptime is 10 days. |
670 // Verifies that when the device is suspended and then resumes, it does not | 754 // Verifies that when the device is suspended and then resumes, it does not |
671 // immediately reboot. | 755 // immediately reboot. |
672 TEST_F(AutomaticRebootManagerBasicTest, ResumeNoPolicy) { | 756 TEST_F(AutomaticRebootManagerBasicTest, ResumeNoPolicy) { |
673 is_user_logged_in_ = true; | 757 is_user_logged_in_ = true; |
674 is_logged_in_as_kiosk_app_ = true; | 758 is_logged_in_as_kiosk_app_ = true; |
675 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10)); | 759 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); |
676 | 760 |
677 // Verify that no reboot is requested and the device does not reboot | 761 // Verify that no reboot is requested and the device does not reboot |
678 // immediately. | 762 // immediately. |
679 ExpectNoRebootRequest(); | 763 ExpectNoRebootRequest(); |
680 CreateAutomaticRebootManager(false); | 764 CreateAutomaticRebootManager(false); |
681 VerifyNoRebootRequested(); | 765 VerifyNoRebootRequested(); |
682 | 766 |
683 // Verify that no grace period has started. | 767 // Verify that no grace period has started. |
684 VerifyNoGracePeriod(); | 768 VerifyNoGracePeriod(); |
685 | 769 |
686 // Notify that the device has resumed from 1 hour of sleep. Verify that no | 770 // Notify that the device has resumed from 1 hour of sleep. Verify that no |
687 // reboot is requested and the device does not reboot immediately. | 771 // reboot is requested and the device does not reboot immediately. |
688 NotifyResumed(false); | 772 NotifyResumed(false); |
689 | 773 |
690 // Verify that a reboot is never requested and the device never reboots. | 774 // Verify that a reboot is never requested and the device never reboots. |
691 FastForwardUntilNoTasksRemain(false); | 775 FastForwardUntilNoTasksRemain(false); |
692 } | 776 } |
693 | 777 |
694 // Chrome is running a non-kiosk-app session. The current uptime is 10 days. | 778 // Chrome is running a non-kiosk-app session. The current uptime is 10 days. |
695 // Verifies that when the device is suspended and then resumes, it does not | 779 // Verifies that when the device is suspended and then resumes, it does not |
696 // immediately reboot. | 780 // immediately reboot. |
697 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAppNoPolicy) { | 781 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAppNoPolicy) { |
698 is_user_logged_in_ = true; | 782 is_user_logged_in_ = true; |
699 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10)); | 783 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); |
700 | 784 |
701 // Verify that no reboot is requested and the device does not reboot | 785 // Verify that no reboot is requested and the device does not reboot |
702 // immediately. | 786 // immediately. |
703 ExpectNoRebootRequest(); | 787 ExpectNoRebootRequest(); |
704 CreateAutomaticRebootManager(false); | 788 CreateAutomaticRebootManager(false); |
705 VerifyNoRebootRequested(); | 789 VerifyNoRebootRequested(); |
706 | 790 |
707 // Verify that no grace period has started. | 791 // Verify that no grace period has started. |
708 VerifyNoGracePeriod(); | 792 VerifyNoGracePeriod(); |
709 | 793 |
710 // Notify that the device has resumed from 1 hour of sleep. Verify that no | 794 // Notify that the device has resumed from 1 hour of sleep. Verify that no |
711 // reboot is requested and the device does not reboot immediately. | 795 // reboot is requested and the device does not reboot immediately. |
712 NotifyResumed(false); | 796 NotifyResumed(false); |
713 | 797 |
714 // Verify that a reboot is never requested and the device never reboots. | 798 // Verify that a reboot is never requested and the device never reboots. |
715 FastForwardUntilNoTasksRemain(false); | 799 FastForwardUntilNoTasksRemain(false); |
716 } | 800 } |
717 | 801 |
718 // Chrome is running a kiosk app session. The uptime limit is 24 hours. The | 802 // Chrome is running a kiosk app session. The uptime limit is 24 hours. The |
719 // current uptime is 12 hours. | 803 // current uptime is 12 hours. |
720 // Verifies that when the device is suspended and then resumes, it does not | 804 // Verifies that when the device is suspended and then resumes, it does not |
721 // immediately reboot. | 805 // immediately reboot. |
722 TEST_F(AutomaticRebootManagerBasicTest, ResumeBeforeGracePeriod) { | 806 TEST_F(AutomaticRebootManagerBasicTest, ResumeBeforeGracePeriod) { |
723 is_user_logged_in_ = true; | 807 is_user_logged_in_ = true; |
724 is_logged_in_as_kiosk_app_ = true; | 808 is_logged_in_as_kiosk_app_ = true; |
725 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 809 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
726 | 810 |
727 // Verify that no reboot is requested and the device does not reboot | 811 // Verify that no reboot is requested and the device does not reboot |
728 // immediately. | 812 // immediately. |
729 ExpectNoRebootRequest(); | 813 ExpectNoRebootRequest(); |
730 CreateAutomaticRebootManager(false); | 814 CreateAutomaticRebootManager(false); |
731 VerifyNoRebootRequested(); | 815 VerifyNoRebootRequested(); |
732 | 816 |
733 // Set the uptime limit. Verify that no reboot is requested and the device | 817 // Set the uptime limit. Verify that no reboot is requested and the device |
734 // does not reboot immediately. | 818 // does not reboot immediately. |
735 SetUptimeLimit(base::TimeDelta::FromHours(24), false); | 819 SetUptimeLimit(base::TimeDelta::FromHours(24), false); |
736 | 820 |
737 // Verify that a grace period has been scheduled to start in the future. | 821 // Verify that a grace period has been scheduled to start in the future. |
738 VerifyGracePeriod(uptime_limit_); | 822 VerifyGracePeriod(uptime_limit_); |
739 | 823 |
740 // Notify that the device has resumed from 1 hour of sleep. Verify that no | 824 // Notify that the device has resumed from 1 hour of sleep. Verify that no |
741 // reboot is requested and the device does not reboot immediately. | 825 // reboot is requested and the device does not reboot immediately. |
742 NotifyResumed(false); | 826 NotifyResumed(false); |
743 | 827 |
744 // Verify a reboot is requested and the device reboots eventually. | 828 // Verify a reboot is requested and the device reboots eventually. |
745 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 829 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
746 FastForwardUntilNoTasksRemain(true); | 830 FastForwardUntilNoTasksRemain(true); |
747 } | 831 } |
748 | 832 |
749 // Chrome is running a non-kiosk-app session. The uptime limit is 24 hours. The | 833 // Chrome is running a non-kiosk-app session. The uptime limit is 24 hours. The |
750 // current uptime is 12 hours. | 834 // current uptime is 12 hours. |
751 // Verifies that when the device is suspended and then resumes, it does not | 835 // Verifies that when the device is suspended and then resumes, it does not |
752 // immediately reboot. | 836 // immediately reboot. |
753 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeBeforeGracePeriod) { | 837 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeBeforeGracePeriod) { |
754 is_user_logged_in_ = true; | 838 is_user_logged_in_ = true; |
755 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 839 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
756 | 840 |
757 // Verify that no reboot is requested and the device does not reboot | 841 // Verify that no reboot is requested and the device does not reboot |
758 // immediately. | 842 // immediately. |
759 ExpectNoRebootRequest(); | 843 ExpectNoRebootRequest(); |
760 CreateAutomaticRebootManager(false); | 844 CreateAutomaticRebootManager(false); |
761 VerifyNoRebootRequested(); | 845 VerifyNoRebootRequested(); |
762 | 846 |
763 // Set the uptime limit. Verify that no reboot is requested and the device | 847 // Set the uptime limit. Verify that no reboot is requested and the device |
764 // does not reboot immediately. | 848 // does not reboot immediately. |
765 SetUptimeLimit(base::TimeDelta::FromHours(24), false); | 849 SetUptimeLimit(base::TimeDelta::FromHours(24), false); |
(...skipping 10 matching lines...) Expand all Loading... |
776 FastForwardUntilNoTasksRemain(false); | 860 FastForwardUntilNoTasksRemain(false); |
777 } | 861 } |
778 | 862 |
779 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The | 863 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The |
780 // current uptime is 12 hours. | 864 // current uptime is 12 hours. |
781 // Verifies that when the device is suspended and then resumes, it immediately | 865 // Verifies that when the device is suspended and then resumes, it immediately |
782 // reboots. | 866 // reboots. |
783 TEST_F(AutomaticRebootManagerBasicTest, ResumeInGracePeriod) { | 867 TEST_F(AutomaticRebootManagerBasicTest, ResumeInGracePeriod) { |
784 is_user_logged_in_ = true; | 868 is_user_logged_in_ = true; |
785 is_logged_in_as_kiosk_app_ = true; | 869 is_logged_in_as_kiosk_app_ = true; |
786 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 870 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
787 | 871 |
788 // Verify that no reboot is requested and the device does not reboot | 872 // Verify that no reboot is requested and the device does not reboot |
789 // immediately. | 873 // immediately. |
790 ExpectNoRebootRequest(); | 874 ExpectNoRebootRequest(); |
791 CreateAutomaticRebootManager(false); | 875 CreateAutomaticRebootManager(false); |
792 VerifyNoRebootRequested(); | 876 VerifyNoRebootRequested(); |
793 | 877 |
794 // Set the uptime limit. Verify that a reboot is requested but the device does | 878 // Set the uptime limit. Verify that a reboot is requested but the device does |
795 // not reboot immediately. | 879 // not reboot immediately. |
796 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 880 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
797 SetUptimeLimit(base::TimeDelta::FromHours(6), false); | 881 SetUptimeLimit(base::TimeDelta::FromHours(6), false); |
798 | 882 |
799 // Verify that a grace period has started. | 883 // Verify that a grace period has started. |
800 VerifyGracePeriod(uptime_limit_); | 884 VerifyGracePeriod(uptime_limit_); |
801 | 885 |
802 // Notify that the device has resumed from 1 hour of sleep. Verify that the | 886 // Notify that the device has resumed from 1 hour of sleep. Verify that the |
803 // device reboots immediately. | 887 // device reboots immediately. |
804 NotifyResumed(true); | 888 NotifyResumed(true); |
805 } | 889 } |
806 | 890 |
807 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The | 891 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The |
808 // current uptime is 12 hours. | 892 // current uptime is 12 hours. |
809 // Verifies that when the device is suspended and then resumes, it does not | 893 // Verifies that when the device is suspended and then resumes, it does not |
810 // immediately reboot. | 894 // immediately reboot. |
811 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeInGracePeriod) { | 895 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeInGracePeriod) { |
812 is_user_logged_in_ = true; | 896 is_user_logged_in_ = true; |
813 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 897 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
814 | 898 |
815 // Verify that no reboot is requested and the device does not reboot | 899 // Verify that no reboot is requested and the device does not reboot |
816 // immediately. | 900 // immediately. |
817 ExpectNoRebootRequest(); | 901 ExpectNoRebootRequest(); |
818 CreateAutomaticRebootManager(false); | 902 CreateAutomaticRebootManager(false); |
819 VerifyNoRebootRequested(); | 903 VerifyNoRebootRequested(); |
820 | 904 |
821 // Set the uptime limit. Verify that a reboot is requested but the device does | 905 // Set the uptime limit. Verify that a reboot is requested but the device does |
822 // not reboot immediately. | 906 // not reboot immediately. |
823 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 907 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
(...skipping 10 matching lines...) Expand all Loading... |
834 FastForwardUntilNoTasksRemain(false); | 918 FastForwardUntilNoTasksRemain(false); |
835 } | 919 } |
836 | 920 |
837 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The | 921 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The |
838 // current uptime is 29 hours 30 minutes. | 922 // current uptime is 29 hours 30 minutes. |
839 // Verifies that when the device is suspended and then resumes, it immediately | 923 // Verifies that when the device is suspended and then resumes, it immediately |
840 // reboots. | 924 // reboots. |
841 TEST_F(AutomaticRebootManagerBasicTest, ResumeAfterGracePeriod) { | 925 TEST_F(AutomaticRebootManagerBasicTest, ResumeAfterGracePeriod) { |
842 is_user_logged_in_ = true; | 926 is_user_logged_in_ = true; |
843 is_logged_in_as_kiosk_app_ = true; | 927 is_logged_in_as_kiosk_app_ = true; |
844 uptime_provider()->SetUptime(base::TimeDelta::FromHours(29) + | 928 task_runner_->SetUptime(base::TimeDelta::FromHours(29) + |
845 base::TimeDelta::FromMinutes(30)); | 929 base::TimeDelta::FromMinutes(30)); |
846 | 930 |
847 // Verify that no reboot is requested and the device does not reboot | 931 // Verify that no reboot is requested and the device does not reboot |
848 // immediately. | 932 // immediately. |
849 ExpectNoRebootRequest(); | 933 ExpectNoRebootRequest(); |
850 CreateAutomaticRebootManager(false); | 934 CreateAutomaticRebootManager(false); |
851 VerifyNoRebootRequested(); | 935 VerifyNoRebootRequested(); |
852 | 936 |
853 // Set the uptime limit. Verify that a reboot is requested but the device does | 937 // Set the uptime limit. Verify that a reboot is requested but the device does |
854 // not reboot immediately. | 938 // not reboot immediately. |
855 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 939 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
856 SetUptimeLimit(base::TimeDelta::FromHours(6), false); | 940 SetUptimeLimit(base::TimeDelta::FromHours(6), false); |
857 | 941 |
858 // Verify that a grace period has started. | 942 // Verify that a grace period has started. |
859 VerifyGracePeriod(uptime_limit_); | 943 VerifyGracePeriod(uptime_limit_); |
860 | 944 |
861 // Notify that the device has resumed from 1 hour of sleep. Verify that the | 945 // Notify that the device has resumed from 1 hour of sleep. Verify that the |
862 // device reboots immediately. | 946 // device reboots immediately. |
863 NotifyResumed(true); | 947 NotifyResumed(true); |
864 } | 948 } |
865 | 949 |
866 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The | 950 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The |
867 // current uptime is 29 hours 30 minutes. | 951 // current uptime is 29 hours 30 minutes. |
868 // Verifies that when the device is suspended and then resumes, it does not | 952 // Verifies that when the device is suspended and then resumes, it does not |
869 // immediately reboot. | 953 // immediately reboot. |
870 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAfterGracePeriod) { | 954 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAfterGracePeriod) { |
871 is_user_logged_in_ = true; | 955 is_user_logged_in_ = true; |
872 uptime_provider()->SetUptime(base::TimeDelta::FromHours(29) + | 956 task_runner_->SetUptime(base::TimeDelta::FromHours(29) + |
873 base::TimeDelta::FromMinutes(30)); | 957 base::TimeDelta::FromMinutes(30)); |
874 | 958 |
875 // Verify that no reboot is requested and the device does not reboot | 959 // Verify that no reboot is requested and the device does not reboot |
876 // immediately. | 960 // immediately. |
877 ExpectNoRebootRequest(); | 961 ExpectNoRebootRequest(); |
878 CreateAutomaticRebootManager(false); | 962 CreateAutomaticRebootManager(false); |
879 VerifyNoRebootRequested(); | 963 VerifyNoRebootRequested(); |
880 | 964 |
881 // Set the uptime limit. Verify that a reboot is requested but the device does | 965 // Set the uptime limit. Verify that a reboot is requested but the device does |
882 // not reboot immediately. | 966 // not reboot immediately. |
883 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 967 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
884 SetUptimeLimit(base::TimeDelta::FromHours(6), false); | 968 SetUptimeLimit(base::TimeDelta::FromHours(6), false); |
885 | 969 |
886 // Verify that a grace period has started. | 970 // Verify that a grace period has started. |
887 VerifyGracePeriod(uptime_limit_); | 971 VerifyGracePeriod(uptime_limit_); |
888 | 972 |
889 // Notify that the device has resumed from 1 hour of sleep. Verify that the | 973 // Notify that the device has resumed from 1 hour of sleep. Verify that the |
890 // device does not reboot immediately. | 974 // device does not reboot immediately. |
891 NotifyResumed(false); | 975 NotifyResumed(false); |
892 | 976 |
893 // Verify that the device never reboots. | 977 // Verify that the device never reboots. |
894 FastForwardUntilNoTasksRemain(false); | 978 FastForwardUntilNoTasksRemain(false); |
895 } | 979 } |
896 | 980 |
897 // Chrome is running. The current uptime is 10 days. | 981 // Chrome is running. The current uptime is 10 days. |
898 // Verifies that when the browser terminates, the device does not immediately | 982 // Verifies that when the browser terminates, the device does not immediately |
899 // reboot. | 983 // reboot. |
900 TEST_P(AutomaticRebootManagerTest, TerminateNoPolicy) { | 984 TEST_P(AutomaticRebootManagerTest, TerminateNoPolicy) { |
901 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10)); | 985 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); |
902 | 986 |
903 // Verify that no reboot is requested and the device does not reboot | 987 // Verify that no reboot is requested and the device does not reboot |
904 // immediately. | 988 // immediately. |
905 ExpectNoRebootRequest(); | 989 ExpectNoRebootRequest(); |
906 CreateAutomaticRebootManager(false); | 990 CreateAutomaticRebootManager(false); |
907 VerifyNoRebootRequested(); | 991 VerifyNoRebootRequested(); |
908 | 992 |
909 // Verify that no grace period has started. | 993 // Verify that no grace period has started. |
910 VerifyNoGracePeriod(); | 994 VerifyNoGracePeriod(); |
911 | 995 |
912 // Notify that the browser is terminating. Verify that no reboot is requested | 996 // Notify that the browser is terminating. Verify that no reboot is requested |
913 // and the device does not reboot immediately. | 997 // and the device does not reboot immediately. |
914 NotifyTerminating(false); | 998 NotifyTerminating(false); |
915 | 999 |
916 // Verify that a reboot is never requested and the device never reboots. | 1000 // Verify that a reboot is never requested and the device never reboots. |
917 FastForwardUntilNoTasksRemain(false); | 1001 FastForwardUntilNoTasksRemain(false); |
918 } | 1002 } |
919 | 1003 |
920 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is | 1004 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is |
921 // 12 hours. | 1005 // 12 hours. |
922 // Verifies that when the browser terminates, it does not immediately reboot. | 1006 // Verifies that when the browser terminates, it does not immediately reboot. |
923 TEST_P(AutomaticRebootManagerTest, TerminateBeforeGracePeriod) { | 1007 TEST_P(AutomaticRebootManagerTest, TerminateBeforeGracePeriod) { |
924 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 1008 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
925 | 1009 |
926 // Verify that no reboot is requested and the device does not reboot | 1010 // Verify that no reboot is requested and the device does not reboot |
927 // immediately. | 1011 // immediately. |
928 ExpectNoRebootRequest(); | 1012 ExpectNoRebootRequest(); |
929 CreateAutomaticRebootManager(false); | 1013 CreateAutomaticRebootManager(false); |
930 VerifyNoRebootRequested(); | 1014 VerifyNoRebootRequested(); |
931 | 1015 |
932 // Set the uptime limit. Verify that no reboot is requested and the device | 1016 // Set the uptime limit. Verify that no reboot is requested and the device |
933 // does not reboot immediately. | 1017 // does not reboot immediately. |
934 SetUptimeLimit(base::TimeDelta::FromHours(24), false); | 1018 SetUptimeLimit(base::TimeDelta::FromHours(24), false); |
(...skipping 10 matching lines...) Expand all Loading... |
945 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 1029 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
946 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 1030 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
947 is_logged_in_as_kiosk_app_); | 1031 is_logged_in_as_kiosk_app_); |
948 } | 1032 } |
949 | 1033 |
950 // Chrome is running. The uptime limit is set to 6 hours. The current uptime is | 1034 // Chrome is running. The uptime limit is set to 6 hours. The current uptime is |
951 // 12 hours. | 1035 // 12 hours. |
952 // Verifies that when the browser terminates, the device immediately reboots if | 1036 // Verifies that when the browser terminates, the device immediately reboots if |
953 // a kiosk app session is in progress. | 1037 // a kiosk app session is in progress. |
954 TEST_P(AutomaticRebootManagerTest, TerminateInGracePeriod) { | 1038 TEST_P(AutomaticRebootManagerTest, TerminateInGracePeriod) { |
955 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 1039 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
956 | 1040 |
957 // Verify that no reboot is requested and the device does not reboot | 1041 // Verify that no reboot is requested and the device does not reboot |
958 // immediately. | 1042 // immediately. |
959 ExpectNoRebootRequest(); | 1043 ExpectNoRebootRequest(); |
960 CreateAutomaticRebootManager(false); | 1044 CreateAutomaticRebootManager(false); |
961 VerifyNoRebootRequested(); | 1045 VerifyNoRebootRequested(); |
962 | 1046 |
963 // Set the uptime limit. Verify that a reboot is requested but the device does | 1047 // Set the uptime limit. Verify that a reboot is requested but the device does |
964 // not reboot immediately. | 1048 // not reboot immediately. |
965 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 1049 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
966 SetUptimeLimit(base::TimeDelta::FromHours(6), false); | 1050 SetUptimeLimit(base::TimeDelta::FromHours(6), false); |
967 | 1051 |
968 // Verify that a grace period has started. | 1052 // Verify that a grace period has started. |
969 VerifyGracePeriod(uptime_limit_); | 1053 VerifyGracePeriod(uptime_limit_); |
970 | 1054 |
971 // Notify that the browser is terminating. Verify that the device immediately | 1055 // Notify that the browser is terminating. Verify that the device immediately |
972 // reboots if a kiosk app session is in progress. | 1056 // reboots if a kiosk app session is in progress. |
973 NotifyTerminating(is_logged_in_as_kiosk_app_); | 1057 NotifyTerminating(is_logged_in_as_kiosk_app_); |
974 | 1058 |
975 // Verify that if a non-kiosk-app session is in progress, the device never | 1059 // Verify that if a non-kiosk-app session is in progress, the device never |
976 // reboots. | 1060 // reboots. |
977 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 1061 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
978 is_logged_in_as_kiosk_app_); | 1062 is_logged_in_as_kiosk_app_); |
979 } | 1063 } |
980 | 1064 |
981 // Chrome is running. The current uptime is 12 hours. | 1065 // Chrome is running. The current uptime is 12 hours. |
982 // Verifies that when the uptime limit is set to 24 hours, no reboot occurs and | 1066 // Verifies that when the uptime limit is set to 24 hours, no reboot occurs and |
983 // a grace period is scheduled to begin after 24 hours of uptime. | 1067 // a grace period is scheduled to begin after 24 hours of uptime. |
984 TEST_P(AutomaticRebootManagerTest, BeforeUptimeLimitGracePeriod) { | 1068 TEST_P(AutomaticRebootManagerTest, BeforeUptimeLimitGracePeriod) { |
985 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 1069 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
986 | 1070 |
987 // Verify that no reboot is requested and the device does not reboot | 1071 // Verify that no reboot is requested and the device does not reboot |
988 // immediately. | 1072 // immediately. |
989 ExpectNoRebootRequest(); | 1073 ExpectNoRebootRequest(); |
990 CreateAutomaticRebootManager(false); | 1074 CreateAutomaticRebootManager(false); |
991 VerifyNoRebootRequested(); | 1075 VerifyNoRebootRequested(); |
992 | 1076 |
993 // Verify that no grace period has started. | 1077 // Verify that no grace period has started. |
994 VerifyNoGracePeriod(); | 1078 VerifyNoGracePeriod(); |
995 | 1079 |
996 // Set the uptime limit. Verify that no reboot is requested and the device | 1080 // Set the uptime limit. Verify that no reboot is requested and the device |
997 // does not reboot immediately. | 1081 // does not reboot immediately. |
998 SetUptimeLimit(base::TimeDelta::FromHours(24), false); | 1082 SetUptimeLimit(base::TimeDelta::FromHours(24), false); |
999 | 1083 |
1000 // Verify that a grace period has been scheduled to start in the future. | 1084 // Verify that a grace period has been scheduled to start in the future. |
1001 VerifyGracePeriod(uptime_limit_); | 1085 VerifyGracePeriod(uptime_limit_); |
1002 | 1086 |
1003 // Verify that a reboot is requested eventually and unless a non-kiosk-app | 1087 // Verify that a reboot is requested eventually and unless a non-kiosk-app |
1004 // session is in progress, the device eventually reboots. | 1088 // session is in progress, the device eventually reboots. |
1005 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 1089 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
1006 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 1090 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1007 is_logged_in_as_kiosk_app_); | 1091 is_logged_in_as_kiosk_app_); |
1008 } | 1092 } |
1009 | 1093 |
1010 // Chrome is running. The current uptime is 12 hours. | 1094 // Chrome is running. The current uptime is 12 hours. |
1011 // Verifies that when the uptime limit is set to 6 hours, a reboot is requested | 1095 // Verifies that when the uptime limit is set to 6 hours, a reboot is requested |
1012 // and a grace period is started that will end after 6 + 24 hours of uptime. | 1096 // and a grace period is started that will end after 6 + 24 hours of uptime. |
1013 TEST_P(AutomaticRebootManagerTest, InUptimeLimitGracePeriod) { | 1097 TEST_P(AutomaticRebootManagerTest, InUptimeLimitGracePeriod) { |
1014 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 1098 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
1015 | 1099 |
1016 // Verify that no reboot is requested and the device does not reboot | 1100 // Verify that no reboot is requested and the device does not reboot |
1017 // immediately. | 1101 // immediately. |
1018 ExpectNoRebootRequest(); | 1102 ExpectNoRebootRequest(); |
1019 CreateAutomaticRebootManager(false); | 1103 CreateAutomaticRebootManager(false); |
1020 VerifyNoRebootRequested(); | 1104 VerifyNoRebootRequested(); |
1021 | 1105 |
1022 // Verify that no grace period has started. | 1106 // Verify that no grace period has started. |
1023 VerifyNoGracePeriod(); | 1107 VerifyNoGracePeriod(); |
1024 | 1108 |
1025 // Set the uptime limit. Verify that a reboot is requested but the device does | 1109 // Set the uptime limit. Verify that a reboot is requested but the device does |
1026 // not reboot immediately. | 1110 // not reboot immediately. |
1027 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 1111 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
1028 SetUptimeLimit(base::TimeDelta::FromHours(6), false); | 1112 SetUptimeLimit(base::TimeDelta::FromHours(6), false); |
1029 | 1113 |
1030 // Verify that a grace period has started. | 1114 // Verify that a grace period has started. |
1031 VerifyGracePeriod(uptime_limit_); | 1115 VerifyGracePeriod(uptime_limit_); |
1032 | 1116 |
1033 // Verify that unless a non-kiosk-app session is in progress, the device | 1117 // Verify that unless a non-kiosk-app session is in progress, the device |
1034 // eventually reboots. | 1118 // eventually reboots. |
1035 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 1119 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1036 is_logged_in_as_kiosk_app_); | 1120 is_logged_in_as_kiosk_app_); |
1037 } | 1121 } |
1038 | 1122 |
1039 // Chrome is running. The current uptime is 10 days. | 1123 // Chrome is running. The current uptime is 10 days. |
1040 // Verifies that when the uptime limit is set to 6 hours, the device reboots | 1124 // Verifies that when the uptime limit is set to 6 hours, the device reboots |
1041 // immediately if no non-kiosk-app-session is in progress because the grace | 1125 // immediately if no non-kiosk-app-session is in progress because the grace |
1042 // period ended after 6 + 24 hours of uptime. | 1126 // period ended after 6 + 24 hours of uptime. |
1043 TEST_P(AutomaticRebootManagerTest, AfterUptimeLimitGracePeriod) { | 1127 TEST_P(AutomaticRebootManagerTest, AfterUptimeLimitGracePeriod) { |
1044 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10)); | 1128 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); |
1045 | 1129 |
1046 // Verify that no reboot is requested and the device does not reboot | 1130 // Verify that no reboot is requested and the device does not reboot |
1047 // immediately. | 1131 // immediately. |
1048 ExpectNoRebootRequest(); | 1132 ExpectNoRebootRequest(); |
1049 CreateAutomaticRebootManager(false); | 1133 CreateAutomaticRebootManager(false); |
1050 VerifyNoRebootRequested(); | 1134 VerifyNoRebootRequested(); |
1051 | 1135 |
1052 // Verify that no grace period has started. | 1136 // Verify that no grace period has started. |
1053 VerifyNoGracePeriod(); | 1137 VerifyNoGracePeriod(); |
1054 | 1138 |
1055 // Set the uptime limit. Verify that a reboot is requested and unless a | 1139 // Set the uptime limit. Verify that a reboot is requested and unless a |
1056 // non-kiosk-app session is in progress, the the device immediately reboots. | 1140 // non-kiosk-app session is in progress, the the device immediately reboots. |
1057 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 1141 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
1058 SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ || | 1142 SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ || |
1059 is_logged_in_as_kiosk_app_); | 1143 is_logged_in_as_kiosk_app_); |
1060 | 1144 |
1061 // Verify that if a non-kiosk-app session is in progress, the device never | 1145 // Verify that if a non-kiosk-app session is in progress, the device never |
1062 // reboots. | 1146 // reboots. |
1063 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 1147 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1064 is_logged_in_as_kiosk_app_); | 1148 is_logged_in_as_kiosk_app_); |
1065 } | 1149 } |
1066 | 1150 |
1067 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is | 1151 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is |
1068 // 6 hours. | 1152 // 6 hours. |
1069 // Verifies that when the uptime limit is removed, the grace period is removed. | 1153 // Verifies that when the uptime limit is removed, the grace period is removed. |
1070 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffBeforeGracePeriod) { | 1154 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffBeforeGracePeriod) { |
1071 uptime_provider()->SetUptime(base::TimeDelta::FromHours(6)); | 1155 task_runner_->SetUptime(base::TimeDelta::FromHours(6)); |
1072 | 1156 |
1073 // Verify that no reboot is requested and the device does not reboot | 1157 // Verify that no reboot is requested and the device does not reboot |
1074 // immediately. | 1158 // immediately. |
1075 ExpectNoRebootRequest(); | 1159 ExpectNoRebootRequest(); |
1076 CreateAutomaticRebootManager(false); | 1160 CreateAutomaticRebootManager(false); |
1077 VerifyNoRebootRequested(); | 1161 VerifyNoRebootRequested(); |
1078 | 1162 |
1079 // Set the uptime limit. Verify that no reboot is requested and the device | 1163 // Set the uptime limit. Verify that no reboot is requested and the device |
1080 // does not reboot immediately. | 1164 // does not reboot immediately. |
1081 SetUptimeLimit(base::TimeDelta::FromHours(12), false); | 1165 SetUptimeLimit(base::TimeDelta::FromHours(12), false); |
(...skipping 13 matching lines...) Expand all Loading... |
1095 VerifyNoGracePeriod(); | 1179 VerifyNoGracePeriod(); |
1096 | 1180 |
1097 // Verify that a reboot is never requested and the device never reboots. | 1181 // Verify that a reboot is never requested and the device never reboots. |
1098 FastForwardUntilNoTasksRemain(false); | 1182 FastForwardUntilNoTasksRemain(false); |
1099 } | 1183 } |
1100 | 1184 |
1101 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is | 1185 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is |
1102 // 24 hours. | 1186 // 24 hours. |
1103 // Verifies that when the uptime limit is removed, the grace period is removed. | 1187 // Verifies that when the uptime limit is removed, the grace period is removed. |
1104 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffInGracePeriod) { | 1188 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffInGracePeriod) { |
1105 uptime_provider()->SetUptime(base::TimeDelta::FromHours(24)); | 1189 task_runner_->SetUptime(base::TimeDelta::FromHours(24)); |
1106 | 1190 |
1107 // Verify that no reboot is requested and the device does not reboot | 1191 // Verify that no reboot is requested and the device does not reboot |
1108 // immediately. | 1192 // immediately. |
1109 ExpectNoRebootRequest(); | 1193 ExpectNoRebootRequest(); |
1110 CreateAutomaticRebootManager(false); | 1194 CreateAutomaticRebootManager(false); |
1111 VerifyNoRebootRequested(); | 1195 VerifyNoRebootRequested(); |
1112 | 1196 |
1113 // Set the uptime limit. Verify that a reboot is requested but the device does | 1197 // Set the uptime limit. Verify that a reboot is requested but the device does |
1114 // not reboot immediately. | 1198 // not reboot immediately. |
1115 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 1199 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
(...skipping 15 matching lines...) Expand all Loading... |
1131 | 1215 |
1132 // Verify that the device never reboots. | 1216 // Verify that the device never reboots. |
1133 FastForwardUntilNoTasksRemain(false); | 1217 FastForwardUntilNoTasksRemain(false); |
1134 } | 1218 } |
1135 | 1219 |
1136 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is | 1220 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is |
1137 // 6 hours. | 1221 // 6 hours. |
1138 // Verifies that when the uptime limit is extended to 24 hours, the grace period | 1222 // Verifies that when the uptime limit is extended to 24 hours, the grace period |
1139 // is rescheduled to start further in the future. | 1223 // is rescheduled to start further in the future. |
1140 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitBeforeGracePeriod) { | 1224 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitBeforeGracePeriod) { |
1141 uptime_provider()->SetUptime(base::TimeDelta::FromHours(6)); | 1225 task_runner_->SetUptime(base::TimeDelta::FromHours(6)); |
1142 | 1226 |
1143 // Verify that no reboot is requested and the device does not reboot | 1227 // Verify that no reboot is requested and the device does not reboot |
1144 // immediately. | 1228 // immediately. |
1145 ExpectNoRebootRequest(); | 1229 ExpectNoRebootRequest(); |
1146 CreateAutomaticRebootManager(false); | 1230 CreateAutomaticRebootManager(false); |
1147 VerifyNoRebootRequested(); | 1231 VerifyNoRebootRequested(); |
1148 | 1232 |
1149 // Set the uptime limit. Verify that no reboot is requested and the device | 1233 // Set the uptime limit. Verify that no reboot is requested and the device |
1150 // does not reboot immediately. | 1234 // does not reboot immediately. |
1151 SetUptimeLimit(base::TimeDelta::FromHours(12), false); | 1235 SetUptimeLimit(base::TimeDelta::FromHours(12), false); |
(...skipping 18 matching lines...) Expand all Loading... |
1170 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 1254 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
1171 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 1255 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1172 is_logged_in_as_kiosk_app_); | 1256 is_logged_in_as_kiosk_app_); |
1173 } | 1257 } |
1174 | 1258 |
1175 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is | 1259 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is |
1176 // 18 hours. | 1260 // 18 hours. |
1177 // Verifies that when the uptime limit is extended to 24 hours, the grace period | 1261 // Verifies that when the uptime limit is extended to 24 hours, the grace period |
1178 // is rescheduled to start in the future. | 1262 // is rescheduled to start in the future. |
1179 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitInGracePeriod) { | 1263 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitInGracePeriod) { |
1180 uptime_provider()->SetUptime(base::TimeDelta::FromHours(18)); | 1264 task_runner_->SetUptime(base::TimeDelta::FromHours(18)); |
1181 | 1265 |
1182 // Verify that no reboot is requested and the device does not reboot | 1266 // Verify that no reboot is requested and the device does not reboot |
1183 // immediately. | 1267 // immediately. |
1184 ExpectNoRebootRequest(); | 1268 ExpectNoRebootRequest(); |
1185 CreateAutomaticRebootManager(false); | 1269 CreateAutomaticRebootManager(false); |
1186 VerifyNoRebootRequested(); | 1270 VerifyNoRebootRequested(); |
1187 | 1271 |
1188 // Set the uptime limit. Verify that a reboot is requested but the device does | 1272 // Set the uptime limit. Verify that a reboot is requested but the device does |
1189 // not reboot immediately. | 1273 // not reboot immediately. |
1190 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 1274 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
(...skipping 18 matching lines...) Expand all Loading... |
1209 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 1293 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
1210 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 1294 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1211 is_logged_in_as_kiosk_app_); | 1295 is_logged_in_as_kiosk_app_); |
1212 } | 1296 } |
1213 | 1297 |
1214 // Chrome is running. The uptime limit is set to 18 hours. The current uptime is | 1298 // Chrome is running. The uptime limit is set to 18 hours. The current uptime is |
1215 // 12 hours. | 1299 // 12 hours. |
1216 // Verifies that when the uptime limit is shortened to 6 hours, the grace period | 1300 // Verifies that when the uptime limit is shortened to 6 hours, the grace period |
1217 // is rescheduled to have already started. | 1301 // is rescheduled to have already started. |
1218 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitBeforeToInGracePeriod) { | 1302 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitBeforeToInGracePeriod) { |
1219 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 1303 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
1220 | 1304 |
1221 // Verify that no reboot is requested and the device does not reboot | 1305 // Verify that no reboot is requested and the device does not reboot |
1222 // immediately. | 1306 // immediately. |
1223 ExpectNoRebootRequest(); | 1307 ExpectNoRebootRequest(); |
1224 CreateAutomaticRebootManager(false); | 1308 CreateAutomaticRebootManager(false); |
1225 VerifyNoRebootRequested(); | 1309 VerifyNoRebootRequested(); |
1226 | 1310 |
1227 // Set the uptime limit. Verify that no reboot is requested and the device | 1311 // Set the uptime limit. Verify that no reboot is requested and the device |
1228 // does not reboot immediately. | 1312 // does not reboot immediately. |
1229 SetUptimeLimit(base::TimeDelta::FromHours(18), false); | 1313 SetUptimeLimit(base::TimeDelta::FromHours(18), false); |
(...skipping 17 matching lines...) Expand all Loading... |
1247 // eventually reboots. | 1331 // eventually reboots. |
1248 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 1332 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1249 is_logged_in_as_kiosk_app_); | 1333 is_logged_in_as_kiosk_app_); |
1250 } | 1334 } |
1251 | 1335 |
1252 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is | 1336 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is |
1253 // 36 hours. | 1337 // 36 hours. |
1254 // Verifies that when the uptime limit is shortened to 18 hours, the grace | 1338 // Verifies that when the uptime limit is shortened to 18 hours, the grace |
1255 // period is rescheduled to have started earlier. | 1339 // period is rescheduled to have started earlier. |
1256 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToInGracePeriod) { | 1340 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToInGracePeriod) { |
1257 uptime_provider()->SetUptime(base::TimeDelta::FromHours(36)); | 1341 task_runner_->SetUptime(base::TimeDelta::FromHours(36)); |
1258 | 1342 |
1259 // Verify that no reboot is requested and the device does not reboot | 1343 // Verify that no reboot is requested and the device does not reboot |
1260 // immediately. | 1344 // immediately. |
1261 ExpectNoRebootRequest(); | 1345 ExpectNoRebootRequest(); |
1262 CreateAutomaticRebootManager(false); | 1346 CreateAutomaticRebootManager(false); |
1263 VerifyNoRebootRequested(); | 1347 VerifyNoRebootRequested(); |
1264 | 1348 |
1265 // Set the uptime limit. Verify that a reboot is requested but the device does | 1349 // Set the uptime limit. Verify that a reboot is requested but the device does |
1266 // not reboot immediately. | 1350 // not reboot immediately. |
1267 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 1351 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
(...skipping 19 matching lines...) Expand all Loading... |
1287 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 1371 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1288 is_logged_in_as_kiosk_app_); | 1372 is_logged_in_as_kiosk_app_); |
1289 } | 1373 } |
1290 | 1374 |
1291 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is | 1375 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is |
1292 // 36 hours. | 1376 // 36 hours. |
1293 // Verifies that when the uptime limit is shortened to 6 hours, the device | 1377 // Verifies that when the uptime limit is shortened to 6 hours, the device |
1294 // reboots immediately if no non-kiosk-app session is in progress because the | 1378 // reboots immediately if no non-kiosk-app session is in progress because the |
1295 // grace period ended after 6 + 24 hours of uptime. | 1379 // grace period ended after 6 + 24 hours of uptime. |
1296 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToAfterGracePeriod) { | 1380 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToAfterGracePeriod) { |
1297 uptime_provider()->SetUptime(base::TimeDelta::FromHours(36)); | 1381 task_runner_->SetUptime(base::TimeDelta::FromHours(36)); |
1298 | 1382 |
1299 // Verify that no reboot is requested and the device does not reboot | 1383 // Verify that no reboot is requested and the device does not reboot |
1300 // immediately. | 1384 // immediately. |
1301 ExpectNoRebootRequest(); | 1385 ExpectNoRebootRequest(); |
1302 CreateAutomaticRebootManager(false); | 1386 CreateAutomaticRebootManager(false); |
1303 VerifyNoRebootRequested(); | 1387 VerifyNoRebootRequested(); |
1304 | 1388 |
1305 // Set the uptime limit. Verify that a reboot is requested but the device does | 1389 // Set the uptime limit. Verify that a reboot is requested but the device does |
1306 // not reboot immediately. | 1390 // not reboot immediately. |
1307 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 1391 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
(...skipping 18 matching lines...) Expand all Loading... |
1326 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 1410 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1327 is_logged_in_as_kiosk_app_); | 1411 is_logged_in_as_kiosk_app_); |
1328 } | 1412 } |
1329 | 1413 |
1330 // Chrome is running. The current uptime is 12 hours. | 1414 // Chrome is running. The current uptime is 12 hours. |
1331 // Verifies that when an update is applied, the current uptime is persisted as | 1415 // Verifies that when an update is applied, the current uptime is persisted as |
1332 // the time at which a reboot became necessary. Further verifies that when the | 1416 // the time at which a reboot became necessary. Further verifies that when the |
1333 // policy to automatically reboot after an update is not enabled, no reboot | 1417 // policy to automatically reboot after an update is not enabled, no reboot |
1334 // occurs and no grace period is scheduled. | 1418 // occurs and no grace period is scheduled. |
1335 TEST_P(AutomaticRebootManagerTest, UpdateNoPolicy) { | 1419 TEST_P(AutomaticRebootManagerTest, UpdateNoPolicy) { |
1336 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 1420 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
1337 | 1421 |
1338 // Verify that no reboot is requested and the device does not reboot | 1422 // Verify that no reboot is requested and the device does not reboot |
1339 // immediately. | 1423 // immediately. |
1340 ExpectNoRebootRequest(); | 1424 ExpectNoRebootRequest(); |
1341 CreateAutomaticRebootManager(false); | 1425 CreateAutomaticRebootManager(false); |
1342 VerifyNoRebootRequested(); | 1426 VerifyNoRebootRequested(); |
1343 | 1427 |
1344 // Verify that no grace period has started. | 1428 // Verify that no grace period has started. |
1345 VerifyNoGracePeriod(); | 1429 VerifyNoGracePeriod(); |
1346 | 1430 |
1347 // Notify that an update has been applied and a reboot is necessary. Verify | 1431 // Notify that an update has been applied and a reboot is necessary. Verify |
1348 // that no reboot is requested and the device does not reboot immediately. | 1432 // that no reboot is requested and the device does not reboot immediately. |
1349 NotifyUpdateRebootNeeded(); | 1433 NotifyUpdateRebootNeeded(); |
1350 | 1434 |
1351 // Verify that the current uptime has been persisted as the time at which a | 1435 // Verify that the current uptime has been persisted as the time at which a |
1352 // reboot became necessary. | 1436 // reboot became necessary. |
1353 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( | 1437 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( |
1354 &update_reboot_needed_uptime_)); | 1438 &update_reboot_needed_uptime_)); |
1355 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_); | 1439 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); |
1356 | 1440 |
1357 // Verify that no grace period has started. | 1441 // Verify that no grace period has started. |
1358 VerifyNoGracePeriod(); | 1442 VerifyNoGracePeriod(); |
1359 | 1443 |
1360 // Verify that a reboot is never requested and the device never reboots. | 1444 // Verify that a reboot is never requested and the device never reboots. |
1361 FastForwardUntilNoTasksRemain(false); | 1445 FastForwardUntilNoTasksRemain(false); |
1362 } | 1446 } |
1363 | 1447 |
1364 // Chrome is running. The current uptime is 12 hours. | 1448 // Chrome is running. The current uptime is 12 hours. |
1365 // Verifies that when an update is applied, the current uptime is persisted as | 1449 // Verifies that when an update is applied, the current uptime is persisted as |
1366 // the time at which a reboot became necessary. Further verifies that when the | 1450 // the time at which a reboot became necessary. Further verifies that when the |
1367 // policy to automatically reboot after an update is enabled, a reboot is | 1451 // policy to automatically reboot after an update is enabled, a reboot is |
1368 // requested and a grace period is started that will end 24 hours from now. | 1452 // requested and a grace period is started that will end 24 hours from now. |
1369 TEST_P(AutomaticRebootManagerTest, Update) { | 1453 TEST_P(AutomaticRebootManagerTest, Update) { |
1370 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 1454 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
1371 SetRebootAfterUpdate(true, false); | 1455 SetRebootAfterUpdate(true, false); |
1372 | 1456 |
1373 // Verify that no reboot is requested and the device does not reboot | 1457 // Verify that no reboot is requested and the device does not reboot |
1374 // immediately. | 1458 // immediately. |
1375 ExpectNoRebootRequest(); | 1459 ExpectNoRebootRequest(); |
1376 CreateAutomaticRebootManager(false); | 1460 CreateAutomaticRebootManager(false); |
1377 VerifyNoRebootRequested(); | 1461 VerifyNoRebootRequested(); |
1378 | 1462 |
1379 // Verify that no grace period has started. | 1463 // Verify that no grace period has started. |
1380 VerifyNoGracePeriod(); | 1464 VerifyNoGracePeriod(); |
1381 | 1465 |
1382 // Notify that an update has been applied and a reboot is necessary. Verify | 1466 // Notify that an update has been applied and a reboot is necessary. Verify |
1383 // that a reboot is requested but the device does not reboot immediately. | 1467 // that a reboot is requested but the device does not reboot immediately. |
1384 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 1468 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
1385 NotifyUpdateRebootNeeded(); | 1469 NotifyUpdateRebootNeeded(); |
1386 | 1470 |
1387 // Verify that the current uptime has been persisted as the time at which a | 1471 // Verify that the current uptime has been persisted as the time at which a |
1388 // reboot became necessary. | 1472 // reboot became necessary. |
1389 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( | 1473 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( |
1390 &update_reboot_needed_uptime_)); | 1474 &update_reboot_needed_uptime_)); |
1391 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_); | 1475 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); |
1392 | 1476 |
1393 // Verify that a grace period has started. | 1477 // Verify that a grace period has started. |
1394 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); | 1478 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); |
1395 | 1479 |
1396 // Verify that unless a non-kiosk-app session is in progress, the device | 1480 // Verify that unless a non-kiosk-app session is in progress, the device |
1397 // eventually reboots. | 1481 // eventually reboots. |
1398 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 1482 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1399 is_logged_in_as_kiosk_app_); | 1483 is_logged_in_as_kiosk_app_); |
1400 } | 1484 } |
1401 | 1485 |
1402 // Chrome is running. The current uptime is 12 hours. | 1486 // Chrome is running. The current uptime is 12 hours. |
1403 // Verifies that when Chrome is notified twice that an update has been applied, | 1487 // Verifies that when Chrome is notified twice that an update has been applied, |
1404 // the second notification is ignored and the uptime at which it occurred does | 1488 // the second notification is ignored and the uptime at which it occurred does |
1405 // not get persisted as the time at which an update became necessary. | 1489 // not get persisted as the time at which an update became necessary. |
1406 TEST_P(AutomaticRebootManagerTest, UpdateAfterUpdate) { | 1490 TEST_P(AutomaticRebootManagerTest, UpdateAfterUpdate) { |
1407 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 1491 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
1408 SetRebootAfterUpdate(true, false); | 1492 SetRebootAfterUpdate(true, false); |
1409 | 1493 |
1410 // Verify that no reboot is requested and the device does not reboot | 1494 // Verify that no reboot is requested and the device does not reboot |
1411 // immediately. | 1495 // immediately. |
1412 ExpectNoRebootRequest(); | 1496 ExpectNoRebootRequest(); |
1413 CreateAutomaticRebootManager(false); | 1497 CreateAutomaticRebootManager(false); |
1414 VerifyNoRebootRequested(); | 1498 VerifyNoRebootRequested(); |
1415 | 1499 |
1416 // Verify that no grace period has started. | 1500 // Verify that no grace period has started. |
1417 VerifyNoGracePeriod(); | 1501 VerifyNoGracePeriod(); |
1418 | 1502 |
1419 // Notify that an update has been applied and a reboot is necessary. Verify | 1503 // Notify that an update has been applied and a reboot is necessary. Verify |
1420 // that a reboot is requested but the device does not reboot immediately. | 1504 // that a reboot is requested but the device does not reboot immediately. |
1421 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 1505 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
1422 NotifyUpdateRebootNeeded(); | 1506 NotifyUpdateRebootNeeded(); |
1423 | 1507 |
1424 // Verify that the current uptime has been persisted as the time at which a | 1508 // Verify that the current uptime has been persisted as the time at which a |
1425 // reboot became necessary. | 1509 // reboot became necessary. |
1426 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( | 1510 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( |
1427 &update_reboot_needed_uptime_)); | 1511 &update_reboot_needed_uptime_)); |
1428 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_); | 1512 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); |
1429 | 1513 |
1430 // Verify that a grace period has started. | 1514 // Verify that a grace period has started. |
1431 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); | 1515 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); |
1432 | 1516 |
1433 // Fast forward the uptime by 20 seconds. Verify that the device does not | 1517 // Fast forward the uptime by 20 seconds. Verify that the device does not |
1434 // reboot immediately. | 1518 // reboot immediately. |
1435 FastForwardBy(base::TimeDelta::FromSeconds(20), false); | 1519 FastForwardBy(base::TimeDelta::FromSeconds(20), false); |
1436 | 1520 |
1437 // Notify that an update has been applied and a reboot is necessary. Verify | 1521 // Notify that an update has been applied and a reboot is necessary. Verify |
1438 // that the device does not reboot immediately. | 1522 // that the device does not reboot immediately. |
(...skipping 12 matching lines...) Expand all Loading... |
1451 is_logged_in_as_kiosk_app_); | 1535 is_logged_in_as_kiosk_app_); |
1452 } | 1536 } |
1453 | 1537 |
1454 // Chrome is running. The current uptime is 10 minutes. | 1538 // Chrome is running. The current uptime is 10 minutes. |
1455 // Verifies that when the policy to automatically reboot after an update is | 1539 // Verifies that when the policy to automatically reboot after an update is |
1456 // enabled, no reboot occurs and a grace period is scheduled to begin after the | 1540 // enabled, no reboot occurs and a grace period is scheduled to begin after the |
1457 // minimum of 1 hour of uptime. Further verifies that when an update is applied, | 1541 // minimum of 1 hour of uptime. Further verifies that when an update is applied, |
1458 // the current uptime is persisted as the time at which a reboot became | 1542 // the current uptime is persisted as the time at which a reboot became |
1459 // necessary. | 1543 // necessary. |
1460 TEST_P(AutomaticRebootManagerTest, UpdateBeforeMinimumUptime) { | 1544 TEST_P(AutomaticRebootManagerTest, UpdateBeforeMinimumUptime) { |
1461 uptime_provider()->SetUptime(base::TimeDelta::FromMinutes(10)); | 1545 task_runner_->SetUptime(base::TimeDelta::FromMinutes(10)); |
1462 SetRebootAfterUpdate(true, false); | 1546 SetRebootAfterUpdate(true, false); |
1463 | 1547 |
1464 // Verify that no reboot is requested and the device does not reboot | 1548 // Verify that no reboot is requested and the device does not reboot |
1465 // immediately. | 1549 // immediately. |
1466 ExpectNoRebootRequest(); | 1550 ExpectNoRebootRequest(); |
1467 CreateAutomaticRebootManager(false); | 1551 CreateAutomaticRebootManager(false); |
1468 VerifyNoRebootRequested(); | 1552 VerifyNoRebootRequested(); |
1469 | 1553 |
1470 // Verify that no grace period has started. | 1554 // Verify that no grace period has started. |
1471 VerifyNoGracePeriod(); | 1555 VerifyNoGracePeriod(); |
1472 | 1556 |
1473 // Notify that an update has been applied and a reboot is necessary. Verify | 1557 // Notify that an update has been applied and a reboot is necessary. Verify |
1474 // that no reboot is requested and the device does not reboot immediately. | 1558 // that no reboot is requested and the device does not reboot immediately. |
1475 NotifyUpdateRebootNeeded(); | 1559 NotifyUpdateRebootNeeded(); |
1476 | 1560 |
1477 // Verify that the current uptime has been persisted as the time at which a | 1561 // Verify that the current uptime has been persisted as the time at which a |
1478 // reboot became necessary. | 1562 // reboot became necessary. |
1479 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( | 1563 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( |
1480 &update_reboot_needed_uptime_)); | 1564 &update_reboot_needed_uptime_)); |
1481 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_); | 1565 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); |
1482 | 1566 |
1483 // Verify that a grace period has been scheduled to begin in the future. | 1567 // Verify that a grace period has been scheduled to begin in the future. |
1484 VerifyGracePeriod(base::TimeDelta::FromHours(1)); | 1568 VerifyGracePeriod(base::TimeDelta::FromHours(1)); |
1485 | 1569 |
1486 // Verify that a reboot is requested eventually and unless a non-kiosk-app | 1570 // Verify that a reboot is requested eventually and unless a non-kiosk-app |
1487 // session is in progress, the device eventually reboots. | 1571 // session is in progress, the device eventually reboots. |
1488 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 1572 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
1489 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 1573 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1490 is_logged_in_as_kiosk_app_); | 1574 is_logged_in_as_kiosk_app_); |
1491 } | 1575 } |
1492 | 1576 |
1493 // Chrome is running. An update was applied and a reboot became necessary to | 1577 // Chrome is running. An update was applied and a reboot became necessary to |
1494 // complete the update process after 6 hours of uptime. The current uptime is | 1578 // complete the update process after 6 hours of uptime. The current uptime is |
1495 // 12 hours. | 1579 // 12 hours. |
1496 // Verifies that when the policy to automatically reboot after an update is | 1580 // Verifies that when the policy to automatically reboot after an update is |
1497 // enabled, a reboot is requested and a grace period is started that will end | 1581 // enabled, a reboot is requested and a grace period is started that will end |
1498 // after 6 + 24 hours of uptime. | 1582 // after 6 + 24 hours of uptime. |
1499 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateInGracePeriod) { | 1583 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateInGracePeriod) { |
1500 uptime_provider()->SetUptime(base::TimeDelta::FromHours(6)); | 1584 task_runner_->SetUptime(base::TimeDelta::FromHours(6)); |
1501 | 1585 |
1502 // Verify that no reboot is requested and the device does not reboot | 1586 // Verify that no reboot is requested and the device does not reboot |
1503 // immediately. | 1587 // immediately. |
1504 ExpectNoRebootRequest(); | 1588 ExpectNoRebootRequest(); |
1505 CreateAutomaticRebootManager(false); | 1589 CreateAutomaticRebootManager(false); |
1506 VerifyNoRebootRequested(); | 1590 VerifyNoRebootRequested(); |
1507 | 1591 |
1508 // Notify that an update has been applied and a reboot is necessary. Verify | 1592 // Notify that an update has been applied and a reboot is necessary. Verify |
1509 // that no reboot is requested and the device does not reboot immediately. | 1593 // that no reboot is requested and the device does not reboot immediately. |
1510 NotifyUpdateRebootNeeded(); | 1594 NotifyUpdateRebootNeeded(); |
(...skipping 19 matching lines...) Expand all Loading... |
1530 is_logged_in_as_kiosk_app_); | 1614 is_logged_in_as_kiosk_app_); |
1531 } | 1615 } |
1532 | 1616 |
1533 // Chrome is running. An update was applied and a reboot became necessary to | 1617 // Chrome is running. An update was applied and a reboot became necessary to |
1534 // complete the update process after 6 hours of uptime. The current uptime is | 1618 // complete the update process after 6 hours of uptime. The current uptime is |
1535 // 10 days. | 1619 // 10 days. |
1536 // Verifies that when the policy to automatically reboot after an update is | 1620 // Verifies that when the policy to automatically reboot after an update is |
1537 // enabled, the device reboots immediately if no non-kiosk-app session is in | 1621 // enabled, the device reboots immediately if no non-kiosk-app session is in |
1538 // progress because the grace period ended after 6 + 24 hours of uptime. | 1622 // progress because the grace period ended after 6 + 24 hours of uptime. |
1539 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateAfterGracePeriod) { | 1623 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateAfterGracePeriod) { |
1540 uptime_provider()->SetUptime(base::TimeDelta::FromHours(6)); | 1624 task_runner_->SetUptime(base::TimeDelta::FromHours(6)); |
1541 | 1625 |
1542 // Verify that no reboot is requested and the device does not reboot | 1626 // Verify that no reboot is requested and the device does not reboot |
1543 // immediately. | 1627 // immediately. |
1544 ExpectNoRebootRequest(); | 1628 ExpectNoRebootRequest(); |
1545 CreateAutomaticRebootManager(false); | 1629 CreateAutomaticRebootManager(false); |
1546 VerifyNoRebootRequested(); | 1630 VerifyNoRebootRequested(); |
1547 | 1631 |
1548 // Notify that an update has been applied and a reboot is necessary. Verify | 1632 // Notify that an update has been applied and a reboot is necessary. Verify |
1549 // that no reboot is requested and the device does not reboot immediately. | 1633 // that no reboot is requested and the device does not reboot immediately. |
1550 NotifyUpdateRebootNeeded(); | 1634 NotifyUpdateRebootNeeded(); |
(...skipping 18 matching lines...) Expand all Loading... |
1569 is_logged_in_as_kiosk_app_); | 1653 is_logged_in_as_kiosk_app_); |
1570 } | 1654 } |
1571 | 1655 |
1572 // Chrome is running. An update was applied and a reboot became necessary to | 1656 // Chrome is running. An update was applied and a reboot became necessary to |
1573 // complete the update process after 6 hours of uptime. The policy to | 1657 // complete the update process after 6 hours of uptime. The policy to |
1574 // automatically reboot after an update is enabled. The current uptime is | 1658 // automatically reboot after an update is enabled. The current uptime is |
1575 // 6 hours 20 seconds. | 1659 // 6 hours 20 seconds. |
1576 // Verifies that when the policy to automatically reboot after an update is | 1660 // Verifies that when the policy to automatically reboot after an update is |
1577 // disabled, the reboot request and grace period are removed. | 1661 // disabled, the reboot request and grace period are removed. |
1578 TEST_P(AutomaticRebootManagerTest, PolicyOffAfterUpdate) { | 1662 TEST_P(AutomaticRebootManagerTest, PolicyOffAfterUpdate) { |
1579 uptime_provider()->SetUptime(base::TimeDelta::FromHours(6)); | 1663 task_runner_->SetUptime(base::TimeDelta::FromHours(6)); |
1580 SetRebootAfterUpdate(true, false); | 1664 SetRebootAfterUpdate(true, false); |
1581 | 1665 |
1582 // Verify that no reboot is requested and the device does not reboot | 1666 // Verify that no reboot is requested and the device does not reboot |
1583 // immediately. | 1667 // immediately. |
1584 ExpectNoRebootRequest(); | 1668 ExpectNoRebootRequest(); |
1585 CreateAutomaticRebootManager(false); | 1669 CreateAutomaticRebootManager(false); |
1586 VerifyNoRebootRequested(); | 1670 VerifyNoRebootRequested(); |
1587 | 1671 |
1588 // Notify that an update has been applied and a reboot is necessary. Verify | 1672 // Notify that an update has been applied and a reboot is necessary. Verify |
1589 // that a reboot is requested but the device does not reboot immediately. | 1673 // that a reboot is requested but the device does not reboot immediately. |
1590 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 1674 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
1591 NotifyUpdateRebootNeeded(); | 1675 NotifyUpdateRebootNeeded(); |
1592 | 1676 |
1593 // Verify that a grace period has started. | 1677 // Verify that a grace period has started. |
1594 VerifyGracePeriod(uptime_provider()->uptime() + uptime_processing_delay_); | 1678 VerifyGracePeriod(task_runner_->Uptime() + uptime_processing_delay_); |
1595 | 1679 |
1596 // Fast forward the uptime by 20 seconds. Verify that the device does not | 1680 // Fast forward the uptime by 20 seconds. Verify that the device does not |
1597 // reboot immediately. | 1681 // reboot immediately. |
1598 FastForwardBy(base::TimeDelta::FromSeconds(20), false); | 1682 FastForwardBy(base::TimeDelta::FromSeconds(20), false); |
1599 | 1683 |
1600 // Disable automatic rebooting after an update has been applied. Verify that | 1684 // Disable automatic rebooting after an update has been applied. Verify that |
1601 // no reboot is requested and the device does not reboot immediately. | 1685 // no reboot is requested and the device does not reboot immediately. |
1602 SetRebootAfterUpdate(false, false); | 1686 SetRebootAfterUpdate(false, false); |
1603 | 1687 |
1604 // Verify that the grace period has been removed. | 1688 // Verify that the grace period has been removed. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1650 FastForwardUntilNoTasksRemain(false); | 1734 FastForwardUntilNoTasksRemain(false); |
1651 } | 1735 } |
1652 | 1736 |
1653 // Chrome is running. The policy to automatically reboot after an update is | 1737 // Chrome is running. The policy to automatically reboot after an update is |
1654 // enabled. The current uptime is 12 hours. | 1738 // enabled. The current uptime is 12 hours. |
1655 // Verifies that when an uptime limit of 6 hours is set, the availability of an | 1739 // Verifies that when an uptime limit of 6 hours is set, the availability of an |
1656 // update does not cause the grace period to be rescheduled. Further verifies | 1740 // update does not cause the grace period to be rescheduled. Further verifies |
1657 // that the current uptime is persisted as the time at which a reboot became | 1741 // that the current uptime is persisted as the time at which a reboot became |
1658 // necessary. | 1742 // necessary. |
1659 TEST_P(AutomaticRebootManagerTest, UptimeLimitBeforeUpdate) { | 1743 TEST_P(AutomaticRebootManagerTest, UptimeLimitBeforeUpdate) { |
1660 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 1744 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
1661 SetRebootAfterUpdate(true, false); | 1745 SetRebootAfterUpdate(true, false); |
1662 | 1746 |
1663 // Verify that no reboot is requested and the device does not reboot | 1747 // Verify that no reboot is requested and the device does not reboot |
1664 // immediately. | 1748 // immediately. |
1665 ExpectNoRebootRequest(); | 1749 ExpectNoRebootRequest(); |
1666 CreateAutomaticRebootManager(false); | 1750 CreateAutomaticRebootManager(false); |
1667 VerifyNoRebootRequested(); | 1751 VerifyNoRebootRequested(); |
1668 | 1752 |
1669 // Set the uptime limit. Verify that a reboot is requested but the device does | 1753 // Set the uptime limit. Verify that a reboot is requested but the device does |
1670 // not reboot immediately. | 1754 // not reboot immediately. |
(...skipping 10 matching lines...) Expand all Loading... |
1681 // Notify that an update has been applied and a reboot is necessary. Verify | 1765 // Notify that an update has been applied and a reboot is necessary. Verify |
1682 // that a reboot is requested again but the device does not reboot | 1766 // that a reboot is requested again but the device does not reboot |
1683 // immediately. | 1767 // immediately. |
1684 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 1768 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
1685 NotifyUpdateRebootNeeded(); | 1769 NotifyUpdateRebootNeeded(); |
1686 | 1770 |
1687 // Verify that the current uptime has been persisted as the time at which a | 1771 // Verify that the current uptime has been persisted as the time at which a |
1688 // reboot became necessary. | 1772 // reboot became necessary. |
1689 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( | 1773 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( |
1690 &update_reboot_needed_uptime_)); | 1774 &update_reboot_needed_uptime_)); |
1691 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_); | 1775 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); |
1692 | 1776 |
1693 // Verify that the grace period has not been rescheduled. | 1777 // Verify that the grace period has not been rescheduled. |
1694 VerifyGracePeriod(uptime_limit_); | 1778 VerifyGracePeriod(uptime_limit_); |
1695 | 1779 |
1696 // Verify that unless a non-kiosk-app session is in progress, the device | 1780 // Verify that unless a non-kiosk-app session is in progress, the device |
1697 // eventually reboots. | 1781 // eventually reboots. |
1698 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 1782 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1699 is_logged_in_as_kiosk_app_); | 1783 is_logged_in_as_kiosk_app_); |
1700 } | 1784 } |
1701 | 1785 |
1702 // Chrome is running. The policy to automatically reboot after an update is | 1786 // Chrome is running. The policy to automatically reboot after an update is |
1703 // enabled. The current uptime is 12 hours. | 1787 // enabled. The current uptime is 12 hours. |
1704 // Verifies that when an uptime limit of 24 hours is set, the availability of an | 1788 // Verifies that when an uptime limit of 24 hours is set, the availability of an |
1705 // update causes the grace period to be rescheduled so that it ends 24 hours | 1789 // update causes the grace period to be rescheduled so that it ends 24 hours |
1706 // from now. Further verifies that the current uptime is persisted as the time | 1790 // from now. Further verifies that the current uptime is persisted as the time |
1707 // at which a reboot became necessary. | 1791 // at which a reboot became necessary. |
1708 TEST_P(AutomaticRebootManagerTest, UpdateBeforeUptimeLimit) { | 1792 TEST_P(AutomaticRebootManagerTest, UpdateBeforeUptimeLimit) { |
1709 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 1793 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
1710 SetRebootAfterUpdate(true, false); | 1794 SetRebootAfterUpdate(true, false); |
1711 | 1795 |
1712 // Verify that no reboot is requested and the device does not reboot | 1796 // Verify that no reboot is requested and the device does not reboot |
1713 // immediately. | 1797 // immediately. |
1714 ExpectNoRebootRequest(); | 1798 ExpectNoRebootRequest(); |
1715 CreateAutomaticRebootManager(false); | 1799 CreateAutomaticRebootManager(false); |
1716 VerifyNoRebootRequested(); | 1800 VerifyNoRebootRequested(); |
1717 | 1801 |
1718 // Set the uptime limit. Verify that no reboot is requested and the device | 1802 // Set the uptime limit. Verify that no reboot is requested and the device |
1719 // does not reboot immediately. | 1803 // does not reboot immediately. |
1720 SetUptimeLimit(base::TimeDelta::FromHours(24), false); | 1804 SetUptimeLimit(base::TimeDelta::FromHours(24), false); |
1721 | 1805 |
1722 // Verify that a grace period has been scheduled to start in the future. | 1806 // Verify that a grace period has been scheduled to start in the future. |
1723 VerifyGracePeriod(uptime_limit_); | 1807 VerifyGracePeriod(uptime_limit_); |
1724 | 1808 |
1725 // Fast forward the uptime by 20 seconds. Verify that no reboot is requested | 1809 // Fast forward the uptime by 20 seconds. Verify that no reboot is requested |
1726 // and the device does not reboot immediately. | 1810 // and the device does not reboot immediately. |
1727 FastForwardBy(base::TimeDelta::FromSeconds(20), false); | 1811 FastForwardBy(base::TimeDelta::FromSeconds(20), false); |
1728 | 1812 |
1729 // Notify that an update has been applied and a reboot is necessary. Verify | 1813 // Notify that an update has been applied and a reboot is necessary. Verify |
1730 // that a reboot is requested but the device does not reboot immediately. | 1814 // that a reboot is requested but the device does not reboot immediately. |
1731 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 1815 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
1732 NotifyUpdateRebootNeeded(); | 1816 NotifyUpdateRebootNeeded(); |
1733 | 1817 |
1734 // Verify that the current uptime has been persisted as the time at which a | 1818 // Verify that the current uptime has been persisted as the time at which a |
1735 // reboot became necessary. | 1819 // reboot became necessary. |
1736 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( | 1820 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( |
1737 &update_reboot_needed_uptime_)); | 1821 &update_reboot_needed_uptime_)); |
1738 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_); | 1822 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); |
1739 | 1823 |
1740 // Verify that the grace period has been rescheduled to start at the time that | 1824 // Verify that the grace period has been rescheduled to start at the time that |
1741 // the update became available. | 1825 // the update became available. |
1742 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); | 1826 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); |
1743 | 1827 |
1744 // Verify that unless a non-kiosk-app session is in progress, the device | 1828 // Verify that unless a non-kiosk-app session is in progress, the device |
1745 // eventually reboots. | 1829 // eventually reboots. |
1746 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 1830 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1747 is_logged_in_as_kiosk_app_); | 1831 is_logged_in_as_kiosk_app_); |
1748 } | 1832 } |
1749 | 1833 |
1750 // Chrome is running. The uptime limit is set to 24 hours. An update was applied | 1834 // Chrome is running. The uptime limit is set to 24 hours. An update was applied |
1751 // and a reboot became necessary to complete the update process after 12 hours. | 1835 // and a reboot became necessary to complete the update process after 12 hours. |
1752 // The policy to automatically reboot after an update is enabled. The current | 1836 // The policy to automatically reboot after an update is enabled. The current |
1753 // uptime is 12 hours 20 seconds. | 1837 // uptime is 12 hours 20 seconds. |
1754 // Verifies that when the policy to reboot after an update is disabled, the | 1838 // Verifies that when the policy to reboot after an update is disabled, the |
1755 // grace period is rescheduled to start after 12 hours of uptime. Further | 1839 // grace period is rescheduled to start after 12 hours of uptime. Further |
1756 // verifies that when the uptime limit is removed, the grace period is removed. | 1840 // verifies that when the uptime limit is removed, the grace period is removed. |
1757 TEST_P(AutomaticRebootManagerTest, PolicyOffThenUptimeLimitOff) { | 1841 TEST_P(AutomaticRebootManagerTest, PolicyOffThenUptimeLimitOff) { |
1758 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 1842 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
1759 SetRebootAfterUpdate(true, false); | 1843 SetRebootAfterUpdate(true, false); |
1760 | 1844 |
1761 // Verify that no reboot is requested and the device does not reboot | 1845 // Verify that no reboot is requested and the device does not reboot |
1762 // immediately. | 1846 // immediately. |
1763 ExpectNoRebootRequest(); | 1847 ExpectNoRebootRequest(); |
1764 CreateAutomaticRebootManager(false); | 1848 CreateAutomaticRebootManager(false); |
1765 VerifyNoRebootRequested(); | 1849 VerifyNoRebootRequested(); |
1766 | 1850 |
1767 // Set the uptime limit. Verify that no reboot is requested and the device | 1851 // Set the uptime limit. Verify that no reboot is requested and the device |
1768 // does not reboot immediately. | 1852 // does not reboot immediately. |
1769 SetUptimeLimit(base::TimeDelta::FromHours(24), false); | 1853 SetUptimeLimit(base::TimeDelta::FromHours(24), false); |
1770 | 1854 |
1771 // Verify that a grace period has been scheduled to start in the future. | 1855 // Verify that a grace period has been scheduled to start in the future. |
1772 VerifyGracePeriod(uptime_limit_); | 1856 VerifyGracePeriod(uptime_limit_); |
1773 | 1857 |
1774 // Notify that an update has been applied and a reboot is necessary. Verify | 1858 // Notify that an update has been applied and a reboot is necessary. Verify |
1775 // that a reboot is requested but the device does not reboot immediately. | 1859 // that a reboot is requested but the device does not reboot immediately. |
1776 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 1860 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
1777 NotifyUpdateRebootNeeded(); | 1861 NotifyUpdateRebootNeeded(); |
1778 | 1862 |
1779 // Verify that the current uptime has been persisted as the time at which a | 1863 // Verify that the current uptime has been persisted as the time at which a |
1780 // reboot became necessary. | 1864 // reboot became necessary. |
1781 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( | 1865 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( |
1782 &update_reboot_needed_uptime_)); | 1866 &update_reboot_needed_uptime_)); |
1783 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_); | 1867 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); |
1784 | 1868 |
1785 // Verify that a grace period has been rescheduled to end 24 hours from now. | 1869 // Verify that a grace period has been rescheduled to end 24 hours from now. |
1786 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); | 1870 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); |
1787 | 1871 |
1788 // Fast forward the uptime by 20 seconds. Verify that the device does not | 1872 // Fast forward the uptime by 20 seconds. Verify that the device does not |
1789 // reboot immediately. | 1873 // reboot immediately. |
1790 FastForwardBy(base::TimeDelta::FromSeconds(20), false); | 1874 FastForwardBy(base::TimeDelta::FromSeconds(20), false); |
1791 | 1875 |
1792 // Disable automatic reboot after an update has been applied. Verify that the | 1876 // Disable automatic reboot after an update has been applied. Verify that the |
1793 // device does not reboot immediately. | 1877 // device does not reboot immediately. |
(...skipping 16 matching lines...) Expand all Loading... |
1810 | 1894 |
1811 // Chrome is running. The uptime limit is set to 6 hours. An update was applied | 1895 // Chrome is running. The uptime limit is set to 6 hours. An update was applied |
1812 // and a reboot became necessary to complete the update process after 12 hours. | 1896 // and a reboot became necessary to complete the update process after 12 hours. |
1813 // The policy to automatically reboot after an update is enabled. The current | 1897 // The policy to automatically reboot after an update is enabled. The current |
1814 // uptime is 12 hours 20 seconds. | 1898 // uptime is 12 hours 20 seconds. |
1815 // Verifies that when the uptime limit is removed, the grace period is | 1899 // Verifies that when the uptime limit is removed, the grace period is |
1816 // rescheduled to have started after 12 hours of uptime. Further verifies that | 1900 // rescheduled to have started after 12 hours of uptime. Further verifies that |
1817 // when the policy to reboot after an update is disabled, the reboot request and | 1901 // when the policy to reboot after an update is disabled, the reboot request and |
1818 // grace period are removed. | 1902 // grace period are removed. |
1819 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffThenPolicyOff) { | 1903 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffThenPolicyOff) { |
1820 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 1904 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
1821 SetRebootAfterUpdate(true, false); | 1905 SetRebootAfterUpdate(true, false); |
1822 | 1906 |
1823 // Verify that no reboot is requested and the device does not reboot | 1907 // Verify that no reboot is requested and the device does not reboot |
1824 // immediately. | 1908 // immediately. |
1825 ExpectNoRebootRequest(); | 1909 ExpectNoRebootRequest(); |
1826 CreateAutomaticRebootManager(false); | 1910 CreateAutomaticRebootManager(false); |
1827 VerifyNoRebootRequested(); | 1911 VerifyNoRebootRequested(); |
1828 | 1912 |
1829 // Notify that an update has been applied and a reboot is necessary. Verify | 1913 // Notify that an update has been applied and a reboot is necessary. Verify |
1830 // that a reboot is requested but the device does not reboot immediately. | 1914 // that a reboot is requested but the device does not reboot immediately. |
1831 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 1915 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
1832 NotifyUpdateRebootNeeded(); | 1916 NotifyUpdateRebootNeeded(); |
1833 | 1917 |
1834 // Verify that the current uptime has been persisted as the time at which a | 1918 // Verify that the current uptime has been persisted as the time at which a |
1835 // reboot became necessary. | 1919 // reboot became necessary. |
1836 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( | 1920 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( |
1837 &update_reboot_needed_uptime_)); | 1921 &update_reboot_needed_uptime_)); |
1838 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_); | 1922 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); |
1839 | 1923 |
1840 // Verify that the grace period has started. | 1924 // Verify that the grace period has started. |
1841 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); | 1925 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); |
1842 | 1926 |
1843 // Set the uptime limit. Verify that a reboot is requested again but the | 1927 // Set the uptime limit. Verify that a reboot is requested again but the |
1844 // device does not reboot immediately. | 1928 // device does not reboot immediately. |
1845 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 1929 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
1846 SetUptimeLimit(base::TimeDelta::FromHours(6), false); | 1930 SetUptimeLimit(base::TimeDelta::FromHours(6), false); |
1847 | 1931 |
1848 // Verify that the grace period has been rescheduled to have started after | 1932 // Verify that the grace period has been rescheduled to have started after |
(...skipping 22 matching lines...) Expand all Loading... |
1871 | 1955 |
1872 // Verify that the device never reboots. | 1956 // Verify that the device never reboots. |
1873 FastForwardUntilNoTasksRemain(false); | 1957 FastForwardUntilNoTasksRemain(false); |
1874 } | 1958 } |
1875 | 1959 |
1876 // Chrome is running. The uptime limit is 6 hours. The current uptime is | 1960 // Chrome is running. The uptime limit is 6 hours. The current uptime is |
1877 // 29 hours 59 minutes 59 seconds. | 1961 // 29 hours 59 minutes 59 seconds. |
1878 // Verifies that if no non-kiosk-app session is in progress, the device reboots | 1962 // Verifies that if no non-kiosk-app session is in progress, the device reboots |
1879 // immediately when the grace period ends after 6 + 24 hours of uptime. | 1963 // immediately when the grace period ends after 6 + 24 hours of uptime. |
1880 TEST_P(AutomaticRebootManagerTest, GracePeriodEnd) { | 1964 TEST_P(AutomaticRebootManagerTest, GracePeriodEnd) { |
1881 uptime_provider()->SetUptime(base::TimeDelta::FromHours(29) + | 1965 task_runner_->SetUptime(base::TimeDelta::FromHours(29) + |
1882 base::TimeDelta::FromMinutes(59) + | 1966 base::TimeDelta::FromMinutes(59) + |
1883 base::TimeDelta::FromSeconds(59)); | 1967 base::TimeDelta::FromSeconds(59)); |
1884 | 1968 |
1885 // Verify that no reboot is requested and the device does not reboot | 1969 // Verify that no reboot is requested and the device does not reboot |
1886 // immediately. | 1970 // immediately. |
1887 ExpectNoRebootRequest(); | 1971 ExpectNoRebootRequest(); |
1888 CreateAutomaticRebootManager(false); | 1972 CreateAutomaticRebootManager(false); |
1889 VerifyNoRebootRequested(); | 1973 VerifyNoRebootRequested(); |
1890 | 1974 |
1891 // Set the uptime limit. Verify that a reboot is requested but the device does | 1975 // Set the uptime limit. Verify that a reboot is requested but the device does |
(...skipping 12 matching lines...) Expand all Loading... |
1904 // Verify that if a non-kiosk-app session is in progress, the device never | 1988 // Verify that if a non-kiosk-app session is in progress, the device never |
1905 // reboots. | 1989 // reboots. |
1906 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 1990 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1907 is_logged_in_as_kiosk_app_); | 1991 is_logged_in_as_kiosk_app_); |
1908 } | 1992 } |
1909 | 1993 |
1910 // Chrome is starting. The current uptime is 10 days. | 1994 // Chrome is starting. The current uptime is 10 days. |
1911 // Verifies that when no automatic reboot policy is enabled, no reboot occurs | 1995 // Verifies that when no automatic reboot policy is enabled, no reboot occurs |
1912 // and no grace period is scheduled. | 1996 // and no grace period is scheduled. |
1913 TEST_P(AutomaticRebootManagerTest, StartNoPolicy) { | 1997 TEST_P(AutomaticRebootManagerTest, StartNoPolicy) { |
1914 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10)); | 1998 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); |
1915 | 1999 |
1916 // Verify that no reboot is requested and the device does not reboot | 2000 // Verify that no reboot is requested and the device does not reboot |
1917 // immediately. | 2001 // immediately. |
1918 ExpectNoRebootRequest(); | 2002 ExpectNoRebootRequest(); |
1919 CreateAutomaticRebootManager(false); | 2003 CreateAutomaticRebootManager(false); |
1920 VerifyNoRebootRequested(); | 2004 VerifyNoRebootRequested(); |
1921 | 2005 |
1922 // Verify that no grace period has started. | 2006 // Verify that no grace period has started. |
1923 VerifyNoGracePeriod(); | 2007 VerifyNoGracePeriod(); |
1924 | 2008 |
1925 // Verify that a reboot is never requested and the device never reboots. | 2009 // Verify that a reboot is never requested and the device never reboots. |
1926 FastForwardUntilNoTasksRemain(false); | 2010 FastForwardUntilNoTasksRemain(false); |
1927 } | 2011 } |
1928 | 2012 |
1929 // Chrome is starting. The uptime limit is set to 24 hours. The current uptime | 2013 // Chrome is starting. The uptime limit is set to 24 hours. The current uptime |
1930 // is 12 hours. | 2014 // is 12 hours. |
1931 // Verifies that no reboot occurs and a grace period is scheduled to begin after | 2015 // Verifies that no reboot occurs and a grace period is scheduled to begin after |
1932 // 24 hours of uptime. | 2016 // 24 hours of uptime. |
1933 TEST_P(AutomaticRebootManagerTest, StartBeforeUptimeLimitGracePeriod) { | 2017 TEST_P(AutomaticRebootManagerTest, StartBeforeUptimeLimitGracePeriod) { |
1934 SetUptimeLimit(base::TimeDelta::FromHours(24), false); | 2018 SetUptimeLimit(base::TimeDelta::FromHours(24), false); |
1935 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 2019 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
1936 | 2020 |
1937 // Verify that no reboot is requested and the device does not reboot | 2021 // Verify that no reboot is requested and the device does not reboot |
1938 // immediately. | 2022 // immediately. |
1939 ExpectNoRebootRequest(); | 2023 ExpectNoRebootRequest(); |
1940 CreateAutomaticRebootManager(false); | 2024 CreateAutomaticRebootManager(false); |
1941 VerifyNoRebootRequested(); | 2025 VerifyNoRebootRequested(); |
1942 | 2026 |
1943 // Verify that a grace period has been scheduled to start in the future. | 2027 // Verify that a grace period has been scheduled to start in the future. |
1944 VerifyGracePeriod(uptime_limit_); | 2028 VerifyGracePeriod(uptime_limit_); |
1945 | 2029 |
1946 // Verify that a reboot is requested eventually and unless a non-kiosk-app | 2030 // Verify that a reboot is requested eventually and unless a non-kiosk-app |
1947 // session is in progress, the device eventually reboots. | 2031 // session is in progress, the device eventually reboots. |
1948 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 2032 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
1949 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 2033 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1950 is_logged_in_as_kiosk_app_); | 2034 is_logged_in_as_kiosk_app_); |
1951 } | 2035 } |
1952 | 2036 |
1953 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is | 2037 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is |
1954 // 10 days. | 2038 // 10 days. |
1955 // Verifies that if no non-kiosk-app session is in progress, the device reboots | 2039 // Verifies that if no non-kiosk-app session is in progress, the device reboots |
1956 // immediately because the grace period ended after 6 + 24 hours of uptime. | 2040 // immediately because the grace period ended after 6 + 24 hours of uptime. |
1957 TEST_P(AutomaticRebootManagerTest, StartAfterUptimeLimitGracePeriod) { | 2041 TEST_P(AutomaticRebootManagerTest, StartAfterUptimeLimitGracePeriod) { |
1958 SetUptimeLimit(base::TimeDelta::FromHours(6), false); | 2042 SetUptimeLimit(base::TimeDelta::FromHours(6), false); |
1959 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10)); | 2043 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); |
1960 | 2044 |
1961 // Verify that a reboot is requested and unless a non-kiosk-app session is in | 2045 // Verify that a reboot is requested and unless a non-kiosk-app session is in |
1962 // progress, the the device immediately reboots. | 2046 // progress, the the device immediately reboots. |
1963 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 2047 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
1964 CreateAutomaticRebootManager(!is_user_logged_in_ || | 2048 CreateAutomaticRebootManager(!is_user_logged_in_ || |
1965 is_logged_in_as_kiosk_app_); | 2049 is_logged_in_as_kiosk_app_); |
1966 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 2050 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
1967 | 2051 |
1968 // Verify that if a non-kiosk-app session is in progress, the device never | 2052 // Verify that if a non-kiosk-app session is in progress, the device never |
1969 // reboots. | 2053 // reboots. |
1970 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 2054 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1971 is_logged_in_as_kiosk_app_); | 2055 is_logged_in_as_kiosk_app_); |
1972 } | 2056 } |
1973 | 2057 |
1974 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is | 2058 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is |
1975 // 12 hours. | 2059 // 12 hours. |
1976 // Verifies that a reboot is requested and a grace period is started that will | 2060 // Verifies that a reboot is requested and a grace period is started that will |
1977 // end after 6 + 24 hours of uptime. | 2061 // end after 6 + 24 hours of uptime. |
1978 TEST_P(AutomaticRebootManagerTest, StartInUptimeLimitGracePeriod) { | 2062 TEST_P(AutomaticRebootManagerTest, StartInUptimeLimitGracePeriod) { |
1979 SetUptimeLimit(base::TimeDelta::FromHours(6), false); | 2063 SetUptimeLimit(base::TimeDelta::FromHours(6), false); |
1980 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 2064 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
1981 | 2065 |
1982 // Verify that a reboot is requested but the device does not reboot | 2066 // Verify that a reboot is requested but the device does not reboot |
1983 // immediately. | 2067 // immediately. |
1984 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 2068 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
1985 CreateAutomaticRebootManager(false); | 2069 CreateAutomaticRebootManager(false); |
1986 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 2070 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
1987 | 2071 |
1988 // Verify that a grace period has started. | 2072 // Verify that a grace period has started. |
1989 VerifyGracePeriod(uptime_limit_); | 2073 VerifyGracePeriod(uptime_limit_); |
1990 | 2074 |
1991 // Verify that unless a non-kiosk-app session is in progress, the device | 2075 // Verify that unless a non-kiosk-app session is in progress, the device |
1992 // eventually reboots. | 2076 // eventually reboots. |
1993 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 2077 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
1994 is_logged_in_as_kiosk_app_); | 2078 is_logged_in_as_kiosk_app_); |
1995 } | 2079 } |
1996 | 2080 |
1997 // Chrome is starting. An update was applied and a reboot became necessary to | 2081 // Chrome is starting. An update was applied and a reboot became necessary to |
1998 // complete the update process after 6 hours of uptime. The current uptime is | 2082 // complete the update process after 6 hours of uptime. The current uptime is |
1999 // 10 days. | 2083 // 10 days. |
2000 // Verifies that when the policy to automatically reboot after an update is | 2084 // Verifies that when the policy to automatically reboot after an update is |
2001 // enabled, the device reboots immediately if no non-kiosk-app session is in | 2085 // enabled, the device reboots immediately if no non-kiosk-app session is in |
2002 // progress because the grace period ended after 6 + 24 hours of uptime. | 2086 // progress because the grace period ended after 6 + 24 hours of uptime. |
2003 TEST_P(AutomaticRebootManagerTest, StartAfterUpdateGracePeriod) { | 2087 TEST_P(AutomaticRebootManagerTest, StartAfterUpdateGracePeriod) { |
2004 SetUpdateStatusNeedReboot(); | 2088 SetUpdateStatusNeedReboot(); |
2005 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); | 2089 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); |
2006 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10)); | 2090 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); |
2007 SetRebootAfterUpdate(true, false); | 2091 SetRebootAfterUpdate(true, false); |
2008 | 2092 |
2009 // Verify that a reboot is requested and unless a non-kiosk-app session is in | 2093 // Verify that a reboot is requested and unless a non-kiosk-app session is in |
2010 // progress, the the device immediately reboots. | 2094 // progress, the the device immediately reboots. |
2011 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 2095 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
2012 CreateAutomaticRebootManager(!is_user_logged_in_ || | 2096 CreateAutomaticRebootManager(!is_user_logged_in_ || |
2013 is_logged_in_as_kiosk_app_); | 2097 is_logged_in_as_kiosk_app_); |
2014 VerifyRebootRequested( | 2098 VerifyRebootRequested( |
2015 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 2099 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
2016 | 2100 |
2017 // Verify that if a non-kiosk-app session is in progress, the device never | 2101 // Verify that if a non-kiosk-app session is in progress, the device never |
2018 // reboots. | 2102 // reboots. |
2019 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 2103 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
2020 is_logged_in_as_kiosk_app_); | 2104 is_logged_in_as_kiosk_app_); |
2021 } | 2105 } |
2022 | 2106 |
2023 // Chrome is starting. An update was applied and a reboot became necessary to | 2107 // Chrome is starting. An update was applied and a reboot became necessary to |
2024 // complete the update process after 6 hours of uptime. The current uptime is | 2108 // complete the update process after 6 hours of uptime. The current uptime is |
2025 // 12 hours. | 2109 // 12 hours. |
2026 // Verifies that when the policy to automatically reboot after an update is | 2110 // Verifies that when the policy to automatically reboot after an update is |
2027 // enabled, a reboot is requested and a grace period is started that will end | 2111 // enabled, a reboot is requested and a grace period is started that will end |
2028 // after 6 + 24 hours of uptime. | 2112 // after 6 + 24 hours of uptime. |
2029 TEST_P(AutomaticRebootManagerTest, StartInUpdateGracePeriod) { | 2113 TEST_P(AutomaticRebootManagerTest, StartInUpdateGracePeriod) { |
2030 SetUpdateStatusNeedReboot(); | 2114 SetUpdateStatusNeedReboot(); |
2031 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); | 2115 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); |
2032 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 2116 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
2033 SetRebootAfterUpdate(true, false); | 2117 SetRebootAfterUpdate(true, false); |
2034 | 2118 |
2035 // Verify that a reboot is requested but the device does not reboot | 2119 // Verify that a reboot is requested but the device does not reboot |
2036 // immediately. | 2120 // immediately. |
2037 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 2121 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
2038 CreateAutomaticRebootManager(false); | 2122 CreateAutomaticRebootManager(false); |
2039 VerifyRebootRequested( | 2123 VerifyRebootRequested( |
2040 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 2124 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
2041 | 2125 |
2042 // Verify that a grace period has started. | 2126 // Verify that a grace period has started. |
2043 VerifyGracePeriod(update_reboot_needed_uptime_); | 2127 VerifyGracePeriod(update_reboot_needed_uptime_); |
2044 | 2128 |
2045 // Verify that unless a non-kiosk-app session is in progress, the device | 2129 // Verify that unless a non-kiosk-app session is in progress, the device |
2046 // eventually reboots. | 2130 // eventually reboots. |
2047 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 2131 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
2048 is_logged_in_as_kiosk_app_); | 2132 is_logged_in_as_kiosk_app_); |
2049 } | 2133 } |
2050 | 2134 |
2051 // Chrome is starting. An update was applied and a reboot became necessary to | 2135 // Chrome is starting. An update was applied and a reboot became necessary to |
2052 // complete the update process after 10 minutes of uptime. The current uptime is | 2136 // complete the update process after 10 minutes of uptime. The current uptime is |
2053 // 20 minutes. | 2137 // 20 minutes. |
2054 // Verifies that when the policy to automatically reboot after an update is | 2138 // Verifies that when the policy to automatically reboot after an update is |
2055 // enabled, no reboot occurs and a grace period is scheduled to begin after the | 2139 // enabled, no reboot occurs and a grace period is scheduled to begin after the |
2056 // minimum of 1 hour of uptime. | 2140 // minimum of 1 hour of uptime. |
2057 TEST_P(AutomaticRebootManagerTest, StartBeforeUpdateGracePeriod) { | 2141 TEST_P(AutomaticRebootManagerTest, StartBeforeUpdateGracePeriod) { |
2058 SetUpdateStatusNeedReboot(); | 2142 SetUpdateStatusNeedReboot(); |
2059 SetUpdateRebootNeededUptime(base::TimeDelta::FromMinutes(10)); | 2143 SetUpdateRebootNeededUptime(base::TimeDelta::FromMinutes(10)); |
2060 uptime_provider()->SetUptime(base::TimeDelta::FromMinutes(20)); | 2144 task_runner_->SetUptime(base::TimeDelta::FromMinutes(20)); |
2061 SetRebootAfterUpdate(true, false); | 2145 SetRebootAfterUpdate(true, false); |
2062 | 2146 |
2063 // Verify that no reboot is requested and the device does not reboot | 2147 // Verify that no reboot is requested and the device does not reboot |
2064 // immediately. | 2148 // immediately. |
2065 ExpectNoRebootRequest(); | 2149 ExpectNoRebootRequest(); |
2066 CreateAutomaticRebootManager(false); | 2150 CreateAutomaticRebootManager(false); |
2067 VerifyNoRebootRequested(); | 2151 VerifyNoRebootRequested(); |
2068 | 2152 |
2069 // Verify that a grace period has been scheduled to start in the future. | 2153 // Verify that a grace period has been scheduled to start in the future. |
2070 VerifyGracePeriod(base::TimeDelta::FromHours(1)); | 2154 VerifyGracePeriod(base::TimeDelta::FromHours(1)); |
2071 | 2155 |
2072 // Verify that a reboot is requested eventually and unless a non-kiosk-app | 2156 // Verify that a reboot is requested eventually and unless a non-kiosk-app |
2073 // session is in progress, the device eventually reboots. | 2157 // session is in progress, the device eventually reboots. |
2074 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 2158 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
2075 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 2159 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
2076 is_logged_in_as_kiosk_app_); | 2160 is_logged_in_as_kiosk_app_); |
2077 } | 2161 } |
2078 | 2162 |
2079 // Chrome is starting. An update was applied and a reboot became necessary to | 2163 // Chrome is starting. An update was applied and a reboot became necessary to |
2080 // complete the update process after 6 hours of uptime. The current uptime is | 2164 // complete the update process after 6 hours of uptime. The current uptime is |
2081 // 10 days. | 2165 // 10 days. |
2082 // Verifies that when the policy to automatically reboot after an update is not | 2166 // Verifies that when the policy to automatically reboot after an update is not |
2083 // enabled, no reboot occurs and no grace period is scheduled. | 2167 // enabled, no reboot occurs and no grace period is scheduled. |
2084 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicy) { | 2168 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicy) { |
2085 SetUpdateStatusNeedReboot(); | 2169 SetUpdateStatusNeedReboot(); |
2086 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); | 2170 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); |
2087 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10)); | 2171 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); |
2088 | 2172 |
2089 // Verify that no reboot is requested and the device does not reboot | 2173 // Verify that no reboot is requested and the device does not reboot |
2090 // immediately. | 2174 // immediately. |
2091 ExpectNoRebootRequest(); | 2175 ExpectNoRebootRequest(); |
2092 CreateAutomaticRebootManager(false); | 2176 CreateAutomaticRebootManager(false); |
2093 VerifyNoRebootRequested(); | 2177 VerifyNoRebootRequested(); |
2094 | 2178 |
2095 // Verify that no grace period has started. | 2179 // Verify that no grace period has started. |
2096 VerifyNoGracePeriod(); | 2180 VerifyNoGracePeriod(); |
2097 | 2181 |
2098 // Verify that a reboot is never requested and the device never reboots. | 2182 // Verify that a reboot is never requested and the device never reboots. |
2099 FastForwardUntilNoTasksRemain(false); | 2183 FastForwardUntilNoTasksRemain(false); |
2100 } | 2184 } |
2101 | 2185 |
2102 // Chrome is starting. An update was applied and a reboot became necessary to | 2186 // Chrome is starting. An update was applied and a reboot became necessary to |
2103 // complete the update process but the time at which this happened was lost. The | 2187 // complete the update process but the time at which this happened was lost. The |
2104 // current uptime is 10 days. | 2188 // current uptime is 10 days. |
2105 // Verifies that the current uptime is persisted as the time at which a reboot | 2189 // Verifies that the current uptime is persisted as the time at which a reboot |
2106 // became necessary. Further verifies that when the policy to automatically | 2190 // became necessary. Further verifies that when the policy to automatically |
2107 // reboot after an update is enabled, a reboot is requested and a grace period | 2191 // reboot after an update is enabled, a reboot is requested and a grace period |
2108 // is started that will end 24 hours from now. | 2192 // is started that will end 24 hours from now. |
2109 TEST_P(AutomaticRebootManagerTest, StartUpdateTimeLost) { | 2193 TEST_P(AutomaticRebootManagerTest, StartUpdateTimeLost) { |
2110 SetUpdateStatusNeedReboot(); | 2194 SetUpdateStatusNeedReboot(); |
2111 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10)); | 2195 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); |
2112 SetRebootAfterUpdate(true, false); | 2196 SetRebootAfterUpdate(true, false); |
2113 | 2197 |
2114 // Verify that a reboot is requested but the device does not reboot | 2198 // Verify that a reboot is requested but the device does not reboot |
2115 // immediately. | 2199 // immediately. |
2116 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 2200 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
2117 CreateAutomaticRebootManager(false); | 2201 CreateAutomaticRebootManager(false); |
2118 VerifyRebootRequested( | 2202 VerifyRebootRequested( |
2119 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 2203 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
2120 | 2204 |
2121 // Verify that the current uptime has been persisted as the time at which a | 2205 // Verify that the current uptime has been persisted as the time at which a |
2122 // reboot became necessary. | 2206 // reboot became necessary. |
2123 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( | 2207 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( |
2124 &update_reboot_needed_uptime_)); | 2208 &update_reboot_needed_uptime_)); |
2125 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_); | 2209 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); |
2126 | 2210 |
2127 // Verify that a grace period has started. | 2211 // Verify that a grace period has started. |
2128 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); | 2212 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); |
2129 | 2213 |
2130 // Verify that unless a non-kiosk-app session is in progress, the device | 2214 // Verify that unless a non-kiosk-app session is in progress, the device |
2131 // eventually reboots. | 2215 // eventually reboots. |
2132 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 2216 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
2133 is_logged_in_as_kiosk_app_); | 2217 is_logged_in_as_kiosk_app_); |
2134 } | 2218 } |
2135 | 2219 |
2136 // Chrome is starting. An update was applied and a reboot became necessary to | 2220 // Chrome is starting. An update was applied and a reboot became necessary to |
2137 // complete the update process but the time at which this happened was lost. The | 2221 // complete the update process but the time at which this happened was lost. The |
2138 // current uptime is 10 days. | 2222 // current uptime is 10 days. |
2139 // Verifies that the current uptime is persisted as the time at which a reboot | 2223 // Verifies that the current uptime is persisted as the time at which a reboot |
2140 // became necessary. Further verifies that when the policy to automatically | 2224 // became necessary. Further verifies that when the policy to automatically |
2141 // reboot after an update is not enabled, no reboot occurs and no grace period | 2225 // reboot after an update is not enabled, no reboot occurs and no grace period |
2142 // is scheduled. | 2226 // is scheduled. |
2143 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicyTimeLost) { | 2227 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicyTimeLost) { |
2144 SetUpdateStatusNeedReboot(); | 2228 SetUpdateStatusNeedReboot(); |
2145 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10)); | 2229 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); |
2146 | 2230 |
2147 // Verify that no reboot is requested and the device does not reboot | 2231 // Verify that no reboot is requested and the device does not reboot |
2148 // immediately. | 2232 // immediately. |
2149 ExpectNoRebootRequest(); | 2233 ExpectNoRebootRequest(); |
2150 CreateAutomaticRebootManager(false); | 2234 CreateAutomaticRebootManager(false); |
2151 VerifyNoRebootRequested(); | 2235 VerifyNoRebootRequested(); |
2152 | 2236 |
2153 // Verify that the current uptime has been persisted as the time at which a | 2237 // Verify that the current uptime has been persisted as the time at which a |
2154 // reboot became necessary. | 2238 // reboot became necessary. |
2155 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( | 2239 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( |
2156 &update_reboot_needed_uptime_)); | 2240 &update_reboot_needed_uptime_)); |
2157 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_); | 2241 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); |
2158 | 2242 |
2159 // Verify that no grace period has started. | 2243 // Verify that no grace period has started. |
2160 VerifyNoGracePeriod(); | 2244 VerifyNoGracePeriod(); |
2161 | 2245 |
2162 // Verify that a reboot is never requested and the device never reboots. | 2246 // Verify that a reboot is never requested and the device never reboots. |
2163 FastForwardUntilNoTasksRemain(false); | 2247 FastForwardUntilNoTasksRemain(false); |
2164 } | 2248 } |
2165 | 2249 |
2166 // Chrome is starting. No update has been applied. The current uptime is | 2250 // Chrome is starting. No update has been applied. The current uptime is |
2167 // 12 hours. | 2251 // 12 hours. |
2168 // Verifies that no time is persisted as the time at which a reboot became | 2252 // Verifies that no time is persisted as the time at which a reboot became |
2169 // necessary. Further verifies that no reboot occurs and no grace period is | 2253 // necessary. Further verifies that no reboot occurs and no grace period is |
2170 // scheduled. | 2254 // scheduled. |
2171 TEST_P(AutomaticRebootManagerTest, StartNoUpdate) { | 2255 TEST_P(AutomaticRebootManagerTest, StartNoUpdate) { |
2172 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 2256 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
2173 SetRebootAfterUpdate(true, false); | 2257 SetRebootAfterUpdate(true, false); |
2174 | 2258 |
2175 // Verify that no reboot is requested and the device does not reboot | 2259 // Verify that no reboot is requested and the device does not reboot |
2176 // immediately. | 2260 // immediately. |
2177 ExpectNoRebootRequest(); | 2261 ExpectNoRebootRequest(); |
2178 CreateAutomaticRebootManager(false); | 2262 CreateAutomaticRebootManager(false); |
2179 VerifyNoRebootRequested(); | 2263 VerifyNoRebootRequested(); |
2180 | 2264 |
2181 // Verify that no time is persisted as the time at which a reboot became | 2265 // Verify that no time is persisted as the time at which a reboot became |
2182 // necessary. | 2266 // necessary. |
(...skipping 10 matching lines...) Expand all Loading... |
2193 // Chrome is starting. The uptime limit is set to 6 hours. Also, an update was | 2277 // Chrome is starting. The uptime limit is set to 6 hours. Also, an update was |
2194 // applied and a reboot became necessary to complete the update process after | 2278 // applied and a reboot became necessary to complete the update process after |
2195 // 8 hours of uptime. The current uptime is 12 hours. | 2279 // 8 hours of uptime. The current uptime is 12 hours. |
2196 // Verifies that when the policy to automatically reboot after an update is | 2280 // Verifies that when the policy to automatically reboot after an update is |
2197 // enabled, a reboot is requested and a grace period is started that will end | 2281 // enabled, a reboot is requested and a grace period is started that will end |
2198 // after 6 + 24 hours of uptime. | 2282 // after 6 + 24 hours of uptime. |
2199 TEST_P(AutomaticRebootManagerTest, StartUptimeLimitBeforeUpdate) { | 2283 TEST_P(AutomaticRebootManagerTest, StartUptimeLimitBeforeUpdate) { |
2200 SetUptimeLimit(base::TimeDelta::FromHours(6), false); | 2284 SetUptimeLimit(base::TimeDelta::FromHours(6), false); |
2201 SetUpdateStatusNeedReboot(); | 2285 SetUpdateStatusNeedReboot(); |
2202 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(8)); | 2286 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(8)); |
2203 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 2287 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
2204 SetRebootAfterUpdate(true, false); | 2288 SetRebootAfterUpdate(true, false); |
2205 | 2289 |
2206 // Verify that a reboot is requested but the device does not reboot | 2290 // Verify that a reboot is requested but the device does not reboot |
2207 // immediately. | 2291 // immediately. |
2208 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 2292 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
2209 CreateAutomaticRebootManager(false); | 2293 CreateAutomaticRebootManager(false); |
2210 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); | 2294 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); |
2211 | 2295 |
2212 // Verify that a grace period has started. | 2296 // Verify that a grace period has started. |
2213 VerifyGracePeriod(uptime_limit_); | 2297 VerifyGracePeriod(uptime_limit_); |
2214 | 2298 |
2215 // Verify that unless a non-kiosk-app session is in progress, the device | 2299 // Verify that unless a non-kiosk-app session is in progress, the device |
2216 // eventually reboots. | 2300 // eventually reboots. |
2217 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || | 2301 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || |
2218 is_logged_in_as_kiosk_app_); | 2302 is_logged_in_as_kiosk_app_); |
2219 } | 2303 } |
2220 | 2304 |
2221 // Chrome is starting. The uptime limit is set to 8 hours. Also, an update was | 2305 // Chrome is starting. The uptime limit is set to 8 hours. Also, an update was |
2222 // applied and a reboot became necessary to complete the update process after | 2306 // applied and a reboot became necessary to complete the update process after |
2223 // 6 hours of uptime. The current uptime is 12 hours. | 2307 // 6 hours of uptime. The current uptime is 12 hours. |
2224 // Verifies that when the policy to automatically reboot after an update is | 2308 // Verifies that when the policy to automatically reboot after an update is |
2225 // enabled, a reboot is requested and a grace period is started that will end | 2309 // enabled, a reboot is requested and a grace period is started that will end |
2226 // after 6 + 24 hours of uptime. | 2310 // after 6 + 24 hours of uptime. |
2227 TEST_P(AutomaticRebootManagerTest, StartUpdateBeforeUptimeLimit) { | 2311 TEST_P(AutomaticRebootManagerTest, StartUpdateBeforeUptimeLimit) { |
2228 SetUptimeLimit(base::TimeDelta::FromHours(8), false); | 2312 SetUptimeLimit(base::TimeDelta::FromHours(8), false); |
2229 SetUpdateStatusNeedReboot(); | 2313 SetUpdateStatusNeedReboot(); |
2230 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); | 2314 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); |
2231 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12)); | 2315 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); |
2232 SetRebootAfterUpdate(true, false); | 2316 SetRebootAfterUpdate(true, false); |
2233 | 2317 |
2234 // Verify that a reboot is requested but the device does not reboot | 2318 // Verify that a reboot is requested but the device does not reboot |
2235 // immediately. | 2319 // immediately. |
2236 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 2320 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
2237 CreateAutomaticRebootManager(false); | 2321 CreateAutomaticRebootManager(false); |
2238 VerifyRebootRequested( | 2322 VerifyRebootRequested( |
2239 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); | 2323 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); |
2240 | 2324 |
2241 // Verify that a grace period has started. | 2325 // Verify that a grace period has started. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2274 INSTANTIATE_TEST_CASE_P( | 2358 INSTANTIATE_TEST_CASE_P( |
2275 AutomaticRebootManagerTestInstance, | 2359 AutomaticRebootManagerTestInstance, |
2276 AutomaticRebootManagerTest, | 2360 AutomaticRebootManagerTest, |
2277 ::testing::Values( | 2361 ::testing::Values( |
2278 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN, | 2362 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN, |
2279 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION, | 2363 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION, |
2280 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION)); | 2364 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION)); |
2281 | 2365 |
2282 } // namespace system | 2366 } // namespace system |
2283 } // namespace chromeos | 2367 } // namespace chromeos |
OLD | NEW |