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