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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
10 #include "ash/shell.h"
11 #include "ash/test/test_shell_delegate.h"
12 #include "base/compiler_specific.h"
13 #include "base/file_util.h"
14 #include "base/files/file_path.h"
15 #include "base/files/scoped_temp_dir.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/message_loop/message_loop.h"
18 #include "base/path_service.h"
19 #include "base/prefs/pref_registry_simple.h"
20 #include "base/prefs/testing_pref_service.h"
21 #include "base/run_loop.h"
22 #include "base/single_thread_task_runner.h"
23 #include "base/strings/string_number_conversions.h"
24 #include "base/test/simple_test_tick_clock.h"
25 #include "base/thread_task_runner_handle.h"
26 #include "base/threading/sequenced_worker_pool.h"
27 #include "base/time/tick_clock.h"
28 #include "base/values.h"
29 #include "chrome/browser/chrome_notification_types.h"
30 #include "chrome/browser/chromeos/login/mock_user_manager.h"
31 #include "chrome/browser/chromeos/login/user_manager.h"
32 #include "chrome/common/pref_names.h"
33 #include "chrome/test/base/testing_browser_process.h"
34 #include "chromeos/chromeos_paths.h"
35 #include "chromeos/dbus/dbus_thread_manager.h"
36 #include "chromeos/dbus/fake_dbus_thread_manager.h"
37 #include "chromeos/dbus/fake_power_manager_client.h"
38 #include "chromeos/dbus/fake_update_engine_client.h"
39 #include "content/public/browser/browser_thread.h"
40 #include "content/public/browser/notification_details.h"
41 #include "content/public/browser/notification_service.h"
42 #include "content/public/browser/notification_source.h"
43 #include "content/public/test/test_browser_thread.h"
44 #include "testing/gmock/include/gmock/gmock.h"
45 #include "testing/gtest/include/gtest/gtest.h"
46 #include "ui/message_center/message_center.h"
48 using ::testing::ReturnPointee;
55 // A SingleThreadTaskRunner that mocks the current time and allows it to be
56 // fast-forwarded. The current time in ticks is returned by Now(). The
57 // corresponding device uptime is written to |uptime_file_|, providing a mock
59 class MockTimeSingleThreadTaskRunner : public base::SingleThreadTaskRunner {
61 MockTimeSingleThreadTaskRunner();
63 // base::SingleThreadTaskRunner:
64 virtual bool RunsTasksOnCurrentThread() const OVERRIDE;
65 virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
66 const base::Closure& task,
67 base::TimeDelta delay) OVERRIDE;
68 virtual bool PostNonNestableDelayedTask(
69 const tracked_objects::Location& from_here,
70 const base::Closure& task,
71 base::TimeDelta delay) OVERRIDE;
73 void SetUptimeFile(const base::FilePath& uptime_file);
74 void SetUptime(const base::TimeDelta& uptime);
76 const base::TimeDelta& Uptime() const;
77 const base::TimeTicks& Now() const;
79 void FastForwardBy(const base::TimeDelta& delta);
80 void FastForwardUntilNoTasksRemain();
84 // Strict weak temporal ordering of tasks.
88 const std::pair<base::TimeTicks, base::Closure>& first_task,
89 const std::pair<base::TimeTicks, base::Closure>& second_task) const;
92 virtual ~MockTimeSingleThreadTaskRunner();
94 base::FilePath uptime_file_;
95 base::TimeDelta uptime_;
97 std::priority_queue<std::pair<base::TimeTicks, base::Closure>,
98 std::vector<std::pair<base::TimeTicks, base::Closure> >,
99 TemporalOrder> tasks_;
101 DISALLOW_COPY_AND_ASSIGN(MockTimeSingleThreadTaskRunner);
104 class MockTimeTickClock : public base::TickClock {
106 explicit MockTimeTickClock(
107 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner);
108 virtual ~MockTimeTickClock();
111 virtual base::TimeTicks NowTicks() OVERRIDE;
114 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_;
116 DISALLOW_COPY_AND_ASSIGN(MockTimeTickClock);
121 class AutomaticRebootManagerBasicTest : public testing::Test {
123 typedef base::OneShotTimer<AutomaticRebootManager> Timer;
125 AutomaticRebootManagerBasicTest();
126 virtual ~AutomaticRebootManagerBasicTest();
129 virtual void SetUp() OVERRIDE;
130 virtual void TearDown() OVERRIDE;
132 void SetUpdateRebootNeededUptime(const base::TimeDelta& uptime);
133 void SetRebootAfterUpdate(bool reboot_after_update, bool expect_reboot);
134 void SetUptimeLimit(const base::TimeDelta& limit, bool expect_reboot);
135 void NotifyUpdateRebootNeeded();
136 void NotifyResumed(bool expect_reboot);
137 void NotifyTerminating(bool expect_reboot);
139 void FastForwardBy(const base::TimeDelta& delta, bool expect_reboot);
140 void FastForwardUntilNoTasksRemain(bool expect_reboot);
142 void CreateAutomaticRebootManager(bool expect_reboot);
144 bool ReadUpdateRebootNeededUptimeFromFile(base::TimeDelta* uptime);
145 void VerifyLoginScreenIdleTimerIsStopped() const;
146 void VerifyNoGracePeriod() const;
147 void VerifyGracePeriod(const base::TimeDelta& start_uptime) const;
149 bool is_user_logged_in_;
150 bool is_logged_in_as_kiosk_app_;
152 // The uptime is read in the blocking thread pool and then processed on the
153 // UI thread. This causes the UI thread to start processing the uptime when it
154 // has increased by a small offset already. The offset is calculated and
155 // stored in |uptime_processing_delay_| so that tests can accurately determine
156 // the uptime seen by the UI thread.
157 base::TimeDelta uptime_processing_delay_;
158 base::TimeDelta update_reboot_needed_uptime_;
159 base::TimeDelta uptime_limit_;
161 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_;
163 scoped_ptr<AutomaticRebootManager> automatic_reboot_manager_;
166 FakePowerManagerClient* power_manager_client_; // Not owned.
167 FakeUpdateEngineClient* update_engine_client_; // Not owned.
169 // Sets the status of |update_engine_client_| to NEED_REBOOT for tests.
170 void SetUpdateStatusNeedReboot();
173 void VerifyTimerIsStopped(const Timer* timer) const;
174 void VerifyTimerIsRunning(const Timer* timer,
175 const base::TimeDelta& delay) const;
176 void VerifyLoginScreenIdleTimerIsRunning() const;
178 base::ScopedTempDir temp_dir_;
179 base::FilePath update_reboot_needed_uptime_file_;
181 bool reboot_after_update_;
183 base::ThreadTaskRunnerHandle ui_thread_task_runner_handle_;
185 TestingPrefServiceSimple local_state_;
186 MockUserManager* mock_user_manager_; // Not owned.
187 ScopedUserManagerEnabler user_manager_enabler_;
190 enum AutomaticRebootManagerTestScenario {
191 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN,
192 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION,
193 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION,
196 // This class runs each test case three times:
197 // * once while the login screen is being shown
198 // * once while a kiosk app session is in progress
199 // * once while a non-kiosk-app session is in progress
200 class AutomaticRebootManagerTest
201 : public AutomaticRebootManagerBasicTest,
202 public testing::WithParamInterface<AutomaticRebootManagerTestScenario> {
204 AutomaticRebootManagerTest();
205 virtual ~AutomaticRebootManagerTest();
208 void SaveUptimeToFile(const base::FilePath& path,
209 const base::TimeDelta& uptime) {
210 if (path.empty() || uptime == base::TimeDelta())
213 const std::string uptime_seconds = base::DoubleToString(uptime.InSecondsF());
214 ASSERT_EQ(static_cast<int>(uptime_seconds.size()),
215 file_util::WriteFile(path,
216 uptime_seconds.c_str(),
217 uptime_seconds.size()));
220 MockTimeSingleThreadTaskRunner::MockTimeSingleThreadTaskRunner() {
223 bool MockTimeSingleThreadTaskRunner::RunsTasksOnCurrentThread() const {
227 bool MockTimeSingleThreadTaskRunner::PostDelayedTask(
228 const tracked_objects::Location& from_here,
229 const base::Closure& task,
230 base::TimeDelta delay) {
231 tasks_.push(std::pair<base::TimeTicks, base::Closure>(now_ + delay, task));
235 bool MockTimeSingleThreadTaskRunner::PostNonNestableDelayedTask(
236 const tracked_objects::Location& from_here,
237 const base::Closure& task,
238 base::TimeDelta delay) {
243 void MockTimeSingleThreadTaskRunner::SetUptimeFile(
244 const base::FilePath& uptime_file) {
245 uptime_file_ = uptime_file;
246 SaveUptimeToFile(uptime_file_, uptime_);
249 void MockTimeSingleThreadTaskRunner::SetUptime(const base::TimeDelta& uptime) {
251 SaveUptimeToFile(uptime_file_, uptime_);
254 const base::TimeDelta& MockTimeSingleThreadTaskRunner::Uptime() const {
258 const base::TimeTicks& MockTimeSingleThreadTaskRunner::Now() const {
262 void MockTimeSingleThreadTaskRunner::FastForwardBy(
263 const base::TimeDelta& delta) {
264 const base::TimeTicks latest = now_ + delta;
265 base::SequencedWorkerPool* blocking_pool =
266 content::BrowserThread::GetBlockingPool();
267 blocking_pool->FlushForTesting();
268 while (!tasks_.empty() && tasks_.top().first <= latest) {
269 uptime_ += tasks_.top().first - now_;
270 SaveUptimeToFile(uptime_file_, uptime_);
271 now_ = tasks_.top().first;
272 base::Closure task = tasks_.top().second;
275 blocking_pool->FlushForTesting();
277 uptime_ += latest - now_;
278 SaveUptimeToFile(uptime_file_, uptime_);
282 void MockTimeSingleThreadTaskRunner::FastForwardUntilNoTasksRemain() {
283 base::SequencedWorkerPool* blocking_pool =
284 content::BrowserThread::GetBlockingPool();
285 blocking_pool->FlushForTesting();
286 while (!tasks_.empty()) {
287 uptime_ += tasks_.top().first - now_;
288 SaveUptimeToFile(uptime_file_, uptime_);
289 now_ = tasks_.top().first;
290 base::Closure task = tasks_.top().second;
293 blocking_pool->FlushForTesting();
297 void MockTimeSingleThreadTaskRunner::RunUntilIdle() {
298 base::SequencedWorkerPool* blocking_pool =
299 content::BrowserThread::GetBlockingPool();
300 blocking_pool->FlushForTesting();
301 while (!tasks_.empty() && tasks_.top().first <= now_) {
302 base::Closure task = tasks_.top().second;
305 blocking_pool->FlushForTesting();
309 bool MockTimeSingleThreadTaskRunner::TemporalOrder::operator()(
310 const std::pair<base::TimeTicks, base::Closure>& first_task,
311 const std::pair<base::TimeTicks, base::Closure>& second_task) const {
312 return first_task.first > second_task.first;
315 MockTimeSingleThreadTaskRunner::~MockTimeSingleThreadTaskRunner() {
318 MockTimeTickClock::MockTimeTickClock(
319 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner)
320 : task_runner_(task_runner) {
323 MockTimeTickClock::~MockTimeTickClock() {
326 base::TimeTicks MockTimeTickClock::NowTicks() {
327 return task_runner_->Now();
330 AutomaticRebootManagerBasicTest::AutomaticRebootManagerBasicTest()
331 : is_user_logged_in_(false),
332 is_logged_in_as_kiosk_app_(false),
333 task_runner_(new MockTimeSingleThreadTaskRunner),
334 power_manager_client_(NULL),
335 update_engine_client_(NULL),
336 reboot_after_update_(false),
337 ui_thread_task_runner_handle_(task_runner_),
338 mock_user_manager_(new MockUserManager),
339 user_manager_enabler_(mock_user_manager_) {
342 AutomaticRebootManagerBasicTest::~AutomaticRebootManagerBasicTest() {
345 void AutomaticRebootManagerBasicTest::SetUp() {
346 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
347 const base::FilePath& temp_dir = temp_dir_.path();
348 const base::FilePath uptime_file = temp_dir.Append("uptime");
349 task_runner_->SetUptimeFile(uptime_file);
350 ASSERT_FALSE(file_util::WriteFile(uptime_file, NULL, 0));
351 update_reboot_needed_uptime_file_ =
352 temp_dir.Append("update_reboot_needed_uptime");
353 ASSERT_FALSE(file_util::WriteFile(
354 update_reboot_needed_uptime_file_, NULL, 0));
355 ASSERT_TRUE(PathService::Override(chromeos::FILE_UPTIME, uptime_file));
356 ASSERT_TRUE(PathService::Override(chromeos::FILE_UPDATE_REBOOT_NEEDED_UPTIME,
357 update_reboot_needed_uptime_file_));
359 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
360 AutomaticRebootManager::RegisterPrefs(local_state_.registry());
361 FakeDBusThreadManager* dbus_manager = new FakeDBusThreadManager;
362 DBusThreadManager::InitializeForTesting(dbus_manager);
363 power_manager_client_ = dbus_manager->fake_power_manager_client();
364 update_engine_client_ = dbus_manager->fake_update_engine_client();
366 EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn())
367 .WillRepeatedly(ReturnPointee(&is_user_logged_in_));
368 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsKioskApp())
369 .WillRepeatedly(ReturnPointee(&is_logged_in_as_kiosk_app_));
372 void AutomaticRebootManagerBasicTest::TearDown() {
373 // Let the AutomaticRebootManager, if any, unregister itself as an observer of
374 // several subsystems.
375 automatic_reboot_manager_.reset();
376 task_runner_->RunUntilIdle();
378 DBusThreadManager::Shutdown();
379 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
382 void AutomaticRebootManagerBasicTest::SetUpdateRebootNeededUptime(
383 const base::TimeDelta& uptime) {
384 update_reboot_needed_uptime_ = uptime;
385 SaveUptimeToFile(update_reboot_needed_uptime_file_, uptime);
389 void AutomaticRebootManagerBasicTest::SetRebootAfterUpdate(
390 bool reboot_after_update,
391 bool expect_reboot) {
392 reboot_after_update_ = reboot_after_update;
393 local_state_.SetManagedPref(
394 prefs::kRebootAfterUpdate,
395 base::Value::CreateBooleanValue(reboot_after_update));
396 task_runner_->RunUntilIdle();
397 EXPECT_EQ(expect_reboot ? 1 : 0,
398 power_manager_client_->request_restart_call_count());
401 void AutomaticRebootManagerBasicTest::SetUptimeLimit(
402 const base::TimeDelta& limit,
403 bool expect_reboot) {
404 uptime_limit_ = limit;
405 if (limit == base::TimeDelta()) {
406 local_state_.RemoveManagedPref(prefs::kUptimeLimit);
408 local_state_.SetManagedPref(
410 base::Value::CreateIntegerValue(limit.InSeconds()));
412 task_runner_->RunUntilIdle();
413 EXPECT_EQ(expect_reboot ? 1 : 0,
414 power_manager_client_->request_restart_call_count());
417 void AutomaticRebootManagerBasicTest::NotifyUpdateRebootNeeded() {
418 SetUpdateStatusNeedReboot();
419 automatic_reboot_manager_->UpdateStatusChanged(
420 update_engine_client_->GetLastStatus());
421 task_runner_->RunUntilIdle();
422 EXPECT_EQ(0, power_manager_client_->request_restart_call_count());
425 void AutomaticRebootManagerBasicTest::NotifyResumed(bool expect_reboot) {
426 automatic_reboot_manager_->SystemResumed(base::TimeDelta::FromHours(1));
427 task_runner_->RunUntilIdle();
428 EXPECT_EQ(expect_reboot ? 1 : 0,
429 power_manager_client_->request_restart_call_count());
432 void AutomaticRebootManagerBasicTest::NotifyTerminating(bool expect_reboot) {
433 automatic_reboot_manager_->Observe(
434 chrome::NOTIFICATION_APP_TERMINATING,
435 content::Source<AutomaticRebootManagerBasicTest>(this),
436 content::NotificationService::NoDetails());
437 task_runner_->RunUntilIdle();
438 EXPECT_EQ(expect_reboot ? 1 : 0,
439 power_manager_client_->request_restart_call_count());
442 void AutomaticRebootManagerBasicTest::FastForwardBy(
443 const base::TimeDelta& delta,
444 bool expect_reboot) {
445 task_runner_->FastForwardBy(delta);
446 EXPECT_EQ(expect_reboot ? 1 : 0,
447 power_manager_client_->request_restart_call_count());
450 void AutomaticRebootManagerBasicTest::FastForwardUntilNoTasksRemain(
451 bool expect_reboot) {
452 task_runner_->FastForwardUntilNoTasksRemain();
453 EXPECT_EQ(expect_reboot ? 1 : 0,
454 power_manager_client_->request_restart_call_count());
457 void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager(
458 bool expect_reboot) {
459 automatic_reboot_manager_.reset(new AutomaticRebootManager(
460 scoped_ptr<base::TickClock>(new MockTimeTickClock(task_runner_))));
461 task_runner_->RunUntilIdle();
462 EXPECT_EQ(expect_reboot ? 1 : 0,
463 power_manager_client_->request_restart_call_count());
465 uptime_processing_delay_ =
466 base::TimeTicks() - automatic_reboot_manager_->boot_time_ -
467 task_runner_->Uptime();
468 EXPECT_GE(uptime_processing_delay_, base::TimeDelta());
469 EXPECT_LE(uptime_processing_delay_, base::TimeDelta::FromSeconds(1));
471 if (is_user_logged_in_ || expect_reboot)
472 VerifyLoginScreenIdleTimerIsStopped();
474 VerifyLoginScreenIdleTimerIsRunning();
477 bool AutomaticRebootManagerBasicTest::ReadUpdateRebootNeededUptimeFromFile(
478 base::TimeDelta* uptime) {
479 std::string contents;
480 if (!base::ReadFileToString(update_reboot_needed_uptime_file_, &contents)) {
484 if (!base::StringToDouble(contents.substr(0, contents.find(' ')), &seconds) ||
488 *uptime = base::TimeDelta::FromMilliseconds(seconds * 1000.0);
492 void AutomaticRebootManagerBasicTest::
493 VerifyLoginScreenIdleTimerIsStopped() const {
494 VerifyTimerIsStopped(
495 automatic_reboot_manager_->login_screen_idle_timer_.get());
498 void AutomaticRebootManagerBasicTest::VerifyNoGracePeriod() const {
499 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_);
500 VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get());
501 VerifyTimerIsStopped(automatic_reboot_manager_->grace_end_timer_.get());
504 void AutomaticRebootManagerBasicTest::VerifyGracePeriod(
505 const base::TimeDelta& start_uptime) const {
506 const base::TimeDelta start =
507 start_uptime - task_runner_->Uptime() - uptime_processing_delay_;
508 const base::TimeDelta end = start + base::TimeDelta::FromHours(24);
509 if (start <= base::TimeDelta()) {
510 EXPECT_TRUE(automatic_reboot_manager_->reboot_requested_);
511 VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get());
512 VerifyTimerIsRunning(automatic_reboot_manager_->grace_end_timer_.get(),
515 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_);
516 VerifyTimerIsRunning(automatic_reboot_manager_->grace_start_timer_.get(),
518 VerifyTimerIsRunning(automatic_reboot_manager_->grace_end_timer_.get(),
523 void AutomaticRebootManagerBasicTest::VerifyTimerIsStopped(
524 const Timer* timer) const {
526 EXPECT_FALSE(timer->IsRunning());
529 void AutomaticRebootManagerBasicTest::VerifyTimerIsRunning(
531 const base::TimeDelta& delay) const {
533 EXPECT_TRUE(timer->IsRunning());
534 EXPECT_EQ(delay.ToInternalValue(),
535 timer->GetCurrentDelay().ToInternalValue());
538 void AutomaticRebootManagerBasicTest::
539 VerifyLoginScreenIdleTimerIsRunning() const {
540 VerifyTimerIsRunning(
541 automatic_reboot_manager_->login_screen_idle_timer_.get(),
542 base::TimeDelta::FromSeconds(60));
545 void AutomaticRebootManagerBasicTest::SetUpdateStatusNeedReboot() {
546 UpdateEngineClient::Status client_status;
547 client_status.status = UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT;
548 update_engine_client_->set_default_status(client_status);
551 AutomaticRebootManagerTest::AutomaticRebootManagerTest() {
552 switch (GetParam()) {
553 case AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN:
554 is_user_logged_in_ = false;
555 is_logged_in_as_kiosk_app_ = false;
557 case AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION:
558 is_user_logged_in_ = true;
559 is_logged_in_as_kiosk_app_ = true;
561 case AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION:
562 is_user_logged_in_ = true;
563 is_logged_in_as_kiosk_app_ = false;
568 AutomaticRebootManagerTest::~AutomaticRebootManagerTest() {
571 // Chrome is showing the login screen. The current uptime is 12 hours.
572 // Verifies that the idle timer is running. Further verifies that when a kiosk
573 // app session begins, the idle timer is stopped.
574 TEST_F(AutomaticRebootManagerBasicTest, LoginStopsIdleTimer) {
575 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
577 // Verify that the device does not reboot immediately and the login screen
578 // idle timer is started.
579 CreateAutomaticRebootManager(false);
581 // Notify that a kiosk app session has been started.
582 is_user_logged_in_ = true;
583 is_logged_in_as_kiosk_app_ = true;
584 automatic_reboot_manager_->Observe(
585 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
586 content::Source<AutomaticRebootManagerBasicTest>(this),
587 content::NotificationService::NoDetails());
589 // Verify that the login screen idle timer is stopped.
590 VerifyLoginScreenIdleTimerIsStopped();
592 // Verify that the device does not reboot eventually.
593 FastForwardUntilNoTasksRemain(false);
596 // Chrome is showing the login screen. The current uptime is 12 hours.
597 // Verifies that the idle timer is running. Further verifies that when a
598 // non-kiosk-app session begins, the idle timer is stopped.
599 TEST_F(AutomaticRebootManagerBasicTest, NonKioskLoginStopsIdleTimer) {
600 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
602 // Verify that the device does not reboot immediately and the login screen
603 // idle timer is started.
604 CreateAutomaticRebootManager(false);
606 // Notify that a non-kiosk-app session has been started.
607 is_user_logged_in_ = true;
608 automatic_reboot_manager_->Observe(
609 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
610 content::Source<AutomaticRebootManagerBasicTest>(this),
611 content::NotificationService::NoDetails());
613 // Verify that the login screen idle timer is stopped.
614 VerifyLoginScreenIdleTimerIsStopped();
616 // Verify that the device does not reboot eventually.
617 FastForwardUntilNoTasksRemain(false);
620 // Chrome is showing the login screen. The uptime limit is 6 hours. The current
621 // uptime is 12 hours.
622 // Verifies that user activity prevents the device from rebooting. Further
623 // verifies that when user activity ceases, the devices reboots.
624 TEST_F(AutomaticRebootManagerBasicTest, UserActivityResetsIdleTimer) {
625 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
627 // Verify that the device does not reboot immediately and the login screen
628 // idle timer is started.
629 CreateAutomaticRebootManager(false);
631 // Set the uptime limit. Verify that the device does not reboot immediately.
632 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
634 // Verify that a grace period has started.
635 VerifyGracePeriod(uptime_limit_);
637 // Fast forward the uptime by 25 minutes while simulating user activity every
639 for (int i = 0; i < 30; ++i) {
640 // Fast forward uptime by 50 seconds. Verify that the device does not reboot
642 FastForwardBy(base::TimeDelta::FromSeconds(50), false);
644 // Simulate user activity.
645 automatic_reboot_manager_->OnUserActivity(NULL);
648 // Fast forward the uptime by 60 seconds without simulating user activity.
649 // Verify that the device reboots immediately.
650 FastForwardBy(base::TimeDelta::FromSeconds(60), true);
653 // Chrome is running a kiosk app session. The current uptime is 10 days.
654 // Verifies that when the device is suspended and then resumes, it does not
655 // immediately reboot.
656 TEST_F(AutomaticRebootManagerBasicTest, ResumeNoPolicy) {
657 is_user_logged_in_ = true;
658 is_logged_in_as_kiosk_app_ = true;
659 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
661 // Verify that the device does not reboot immediately.
662 CreateAutomaticRebootManager(false);
664 // Verify that no grace period has started.
665 VerifyNoGracePeriod();
667 // Notify that the device has resumed from 1 hour of sleep. Verify that the
668 // device does not reboot immediately.
669 NotifyResumed(false);
671 // Verify that the device does not reboot eventually.
672 FastForwardUntilNoTasksRemain(false);
675 // Chrome is running a non-kiosk-app session. The current uptime is 10 days.
676 // Verifies that when the device is suspended and then resumes, it does not
677 // immediately reboot.
678 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAppNoPolicy) {
679 is_user_logged_in_ = true;
680 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
682 // Verify that the device does not reboot immediately.
683 CreateAutomaticRebootManager(false);
685 // Verify that no grace period has started.
686 VerifyNoGracePeriod();
688 // Notify that the device has resumed from 1 hour of sleep. Verify that the
689 // device does not reboot immediately.
690 NotifyResumed(false);
692 // Verify that the device does not reboot eventually.
693 FastForwardUntilNoTasksRemain(false);
696 // Chrome is running a kiosk app session. The uptime limit is 24 hours. The
697 // current uptime is 12 hours.
698 // Verifies that when the device is suspended and then resumes, it does not
699 // immediately reboot.
700 TEST_F(AutomaticRebootManagerBasicTest, ResumeBeforeGracePeriod) {
701 is_user_logged_in_ = true;
702 is_logged_in_as_kiosk_app_ = true;
703 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
705 // Verify that the device does not reboot immediately.
706 CreateAutomaticRebootManager(false);
708 // Set the uptime limit. Verify that the device does not reboot immediately.
709 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
711 // Verify that a grace period has been scheduled to start in the future.
712 VerifyGracePeriod(uptime_limit_);
714 // Notify that the device has resumed from 1 hour of sleep. Verify that the
715 // device does not reboot immediately.
716 NotifyResumed(false);
718 // Verify that the device eventually reboots.
719 FastForwardUntilNoTasksRemain(true);
722 // Chrome is running a non-kiosk-app session. The uptime limit is 24 hours. The
723 // current uptime is 12 hours.
724 // Verifies that when the device is suspended and then resumes, it does not
725 // immediately reboot.
726 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeBeforeGracePeriod) {
727 is_user_logged_in_ = true;
728 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
730 // Verify that the device does not reboot immediately.
731 CreateAutomaticRebootManager(false);
733 // Set the uptime limit. Verify that the device does not reboot immediately.
734 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
736 // Verify that a grace period has been scheduled to start in the future.
737 VerifyGracePeriod(uptime_limit_);
739 // Notify that the device has resumed from 1 hour of sleep. Verify that the
740 // device does not reboot immediately.
741 NotifyResumed(false);
743 // Verify that the device does not reboot eventually.
744 FastForwardUntilNoTasksRemain(false);
747 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The
748 // current uptime is 12 hours.
749 // Verifies that when the device is suspended and then resumes, it immediately
751 TEST_F(AutomaticRebootManagerBasicTest, ResumeInGracePeriod) {
752 is_user_logged_in_ = true;
753 is_logged_in_as_kiosk_app_ = true;
754 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
756 // Verify that the device does not reboot immediately.
757 CreateAutomaticRebootManager(false);
759 // Set the uptime limit. Verify that the device does not reboot immediately.
760 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
762 // Verify that a grace period has started.
763 VerifyGracePeriod(uptime_limit_);
765 // Notify that the device has resumed from 1 hour of sleep. Verify that the
766 // device reboots immediately.
770 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The
771 // current uptime is 12 hours.
772 // Verifies that when the device is suspended and then resumes, it does not
773 // immediately reboot.
774 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeInGracePeriod) {
775 is_user_logged_in_ = true;
776 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
778 // Verify that the device does not reboot immediately.
779 CreateAutomaticRebootManager(false);
781 // Set the uptime limit. Verify that the device does not reboot immediately.
782 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
784 // Verify that a grace period has started.
785 VerifyGracePeriod(uptime_limit_);
787 // Notify that the device has resumed from 1 hour of sleep. Verify that the
788 // device does not reboot immediately.
789 NotifyResumed(false);
791 // Verify that the device does not reboot eventually.
792 FastForwardUntilNoTasksRemain(false);
795 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The
796 // current uptime is 29 hours 30 minutes.
797 // Verifies that when the device is suspended and then resumes, it immediately
799 TEST_F(AutomaticRebootManagerBasicTest, ResumeAfterGracePeriod) {
800 is_user_logged_in_ = true;
801 is_logged_in_as_kiosk_app_ = true;
802 task_runner_->SetUptime(base::TimeDelta::FromHours(29) +
803 base::TimeDelta::FromMinutes(30));
805 // Verify that the device does not reboot immediately.
806 CreateAutomaticRebootManager(false);
808 // Set the uptime limit. Verify that the device does not reboot immediately.
809 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
811 // Verify that a grace period has started.
812 VerifyGracePeriod(uptime_limit_);
814 // Notify that the device has resumed from 1 hour of sleep. Verify that the
815 // device reboots immediately.
819 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The
820 // current uptime is 29 hours 30 minutes.
821 // Verifies that when the device is suspended and then resumes, it does not
822 // immediately reboot.
823 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAfterGracePeriod) {
824 is_user_logged_in_ = true;
825 task_runner_->SetUptime(base::TimeDelta::FromHours(29) +
826 base::TimeDelta::FromMinutes(30));
828 // Verify that the device does not reboot immediately.
829 CreateAutomaticRebootManager(false);
831 // Set the uptime limit. Verify that the device does not reboot immediately.
832 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
834 // Verify that a grace period has started.
835 VerifyGracePeriod(uptime_limit_);
837 // Notify that the device has resumed from 1 hour of sleep. Verify that the
838 // device does not reboot immediately.
839 NotifyResumed(false);
841 // Verify that the device does not reboot eventually.
842 FastForwardUntilNoTasksRemain(false);
845 // Chrome is running. The current uptime is 10 days.
846 // Verifies that when the browser terminates, the device does not immediately
848 TEST_P(AutomaticRebootManagerTest, TerminateNoPolicy) {
849 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
851 // Verify that the device does not reboot immediately.
852 CreateAutomaticRebootManager(false);
854 // Verify that no grace period has started.
855 VerifyNoGracePeriod();
857 // Notify that the browser is terminating. Verify that the device does not
858 // reboot immediately.
859 NotifyTerminating(false);
861 // Verify that the device does not reboot eventually.
862 FastForwardUntilNoTasksRemain(false);
865 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is
867 // Verifies that when the browser terminates, it does not immediately reboot.
868 TEST_P(AutomaticRebootManagerTest, TerminateBeforeGracePeriod) {
869 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
871 // Verify that the device does not reboot immediately.
872 CreateAutomaticRebootManager(false);
874 // Set the uptime limit. Verify that the device does not reboot immediately.
875 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
877 // Verify that a grace period has been scheduled to start in the future.
878 VerifyGracePeriod(uptime_limit_);
880 // Notify that the browser is terminating. Verify that the device does not
881 // reboot immediately.
882 NotifyTerminating(false);
884 // Verify that unless a non-kiosk-app session is in progress, the device
885 // eventually reboots.
886 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
887 is_logged_in_as_kiosk_app_);
890 // Chrome is running. The uptime limit is set to 6 hours. The current uptime is
892 // Verifies that when the browser terminates, the device immediately reboots if
893 // a kiosk app session is in progress.
894 TEST_P(AutomaticRebootManagerTest, TerminateInGracePeriod) {
895 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
897 // Verify that the device does not reboot immediately.
898 CreateAutomaticRebootManager(false);
900 // Set the uptime limit. Verify that the device does not reboot immediately.
901 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
903 // Verify that a grace period has started.
904 VerifyGracePeriod(uptime_limit_);
906 // Notify that the browser is terminating. Verify that the device immediately
907 // reboots if a kiosk app session is in progress.
908 NotifyTerminating(is_logged_in_as_kiosk_app_);
910 // Verify that if a non-kiosk-app session is in progress, the device does not
911 // reboot eventually.
912 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
913 is_logged_in_as_kiosk_app_);
916 // Chrome is running. The current uptime is 12 hours.
917 // Verifies that when the uptime limit is set to 24 hours, no reboot occurs and
918 // a grace period is scheduled to begin after 24 hours of uptime.
919 TEST_P(AutomaticRebootManagerTest, BeforeUptimeLimitGracePeriod) {
920 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
922 // Verify that the device does not reboot immediately.
923 CreateAutomaticRebootManager(false);
925 // Verify that no grace period has started.
926 VerifyNoGracePeriod();
928 // Set the uptime limit. Verify that the device does not reboot immediately.
929 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
931 // Verify that a grace period has been scheduled to start in the future.
932 VerifyGracePeriod(uptime_limit_);
934 // Verify that unless a non-kiosk-app session is in progress, the device
935 // eventually reboots.
936 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
937 is_logged_in_as_kiosk_app_);
940 // Chrome is running. The current uptime is 12 hours.
941 // Verifies that when the uptime limit is set to 6 hours, a reboot is requested
942 // and a grace period is started that will end after 6 + 24 hours of uptime.
943 TEST_P(AutomaticRebootManagerTest, InUptimeLimitGracePeriod) {
944 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
946 // Verify that the device does not reboot immediately.
947 CreateAutomaticRebootManager(false);
949 // Verify that no grace period has started.
950 VerifyNoGracePeriod();
952 // Set the uptime limit. Verify that the device does not reboot immediately.
953 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
955 // Verify that a grace period has started.
956 VerifyGracePeriod(uptime_limit_);
958 // Verify that unless a non-kiosk-app session is in progress, the device
959 // eventually reboots.
960 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
961 is_logged_in_as_kiosk_app_);
964 // Chrome is running. The current uptime is 10 days.
965 // Verifies that when the uptime limit is set to 6 hours, the device reboots
966 // immediately if no non-kiosk-app-session is in progress because the grace
967 // period ended after 6 + 24 hours of uptime.
968 TEST_P(AutomaticRebootManagerTest, AfterUptimeLimitGracePeriod) {
969 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
971 // Verify that the device does not reboot immediately.
972 CreateAutomaticRebootManager(false);
974 // Verify that no grace period has started.
975 VerifyNoGracePeriod();
977 // Set the uptime limit. Verify that unless a non-kiosk-app session is in
978 // progress, the the device immediately reboots.
979 SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ ||
980 is_logged_in_as_kiosk_app_);
982 // Verify that if a non-kiosk-app session is in progress, the device does not
983 // reboot eventually.
984 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
985 is_logged_in_as_kiosk_app_);
988 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
990 // Verifies that when the uptime limit is removed, the grace period is removed.
991 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffBeforeGracePeriod) {
992 task_runner_->SetUptime(base::TimeDelta::FromHours(6));
994 // Verify that the device does not reboot immediately.
995 CreateAutomaticRebootManager(false);
997 // Set the uptime limit. Verify that the device does not reboot immediately.
998 SetUptimeLimit(base::TimeDelta::FromHours(12), false);
1000 // Verify that a grace period has been scheduled to start in the future.
1001 VerifyGracePeriod(uptime_limit_);
1003 // Fast forward the uptime by 1 hour. Verify that the device does not reboot
1005 FastForwardBy(base::TimeDelta::FromHours(1), false);
1007 // Remove the uptime limit. Verify that the device does not reboot
1009 SetUptimeLimit(base::TimeDelta(), false);
1011 // Verify that the grace period has been removed.
1012 VerifyNoGracePeriod();
1014 // Verify that the device does not reboot eventually.
1015 FastForwardUntilNoTasksRemain(false);
1018 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
1020 // Verifies that when the uptime limit is removed, the grace period is removed.
1021 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffInGracePeriod) {
1022 task_runner_->SetUptime(base::TimeDelta::FromHours(24));
1024 // Verify that the device does not reboot immediately.
1025 CreateAutomaticRebootManager(false);
1027 // Set the uptime limit. Verify that the device does not reboot immediately.
1028 SetUptimeLimit(base::TimeDelta::FromHours(12), false);
1030 // Verify that a grace period has started.
1031 VerifyGracePeriod(uptime_limit_);
1033 // Fast forward the uptime by 20 seconds. Verify that the device does not
1034 // reboot immediately.
1035 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1037 // Remove the uptime limit. Verify that the device does not reboot
1039 SetUptimeLimit(base::TimeDelta(), false);
1041 // Verify that the grace period has been removed.
1042 VerifyNoGracePeriod();
1044 // Verify that the device does not reboot eventually.
1045 FastForwardUntilNoTasksRemain(false);
1048 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
1050 // Verifies that when the uptime limit is extended to 24 hours, the grace period
1051 // is rescheduled to start further in the future.
1052 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitBeforeGracePeriod) {
1053 task_runner_->SetUptime(base::TimeDelta::FromHours(6));
1055 // Verify that the device does not reboot immediately.
1056 CreateAutomaticRebootManager(false);
1058 // Set the uptime limit. Verify that the device does not reboot immediately.
1059 SetUptimeLimit(base::TimeDelta::FromHours(12), false);
1061 // Verify that a grace period has been scheduled to start in the future.
1062 VerifyGracePeriod(uptime_limit_);
1064 // Fast forward the uptime by 20 seconds. Verify that the device does not
1065 // reboot immediately.
1066 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1068 // Extend the uptime limit. Verify that the device does not reboot
1070 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1072 // Verify that the grace period has been rescheduled to start further in the
1074 VerifyGracePeriod(uptime_limit_);
1076 // Verify that unless a non-kiosk-app session is in progress, the device
1077 // eventually reboots.
1078 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1079 is_logged_in_as_kiosk_app_);
1082 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
1084 // Verifies that when the uptime limit is extended to 24 hours, the grace period
1085 // is rescheduled to start in the future.
1086 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitInGracePeriod) {
1087 task_runner_->SetUptime(base::TimeDelta::FromHours(18));
1089 // Verify that the device does not reboot immediately.
1090 CreateAutomaticRebootManager(false);
1092 // Set the uptime limit. Verify that the device does not reboot immediately.
1093 SetUptimeLimit(base::TimeDelta::FromHours(12), false);
1095 // Verify that a grace period has started.
1096 VerifyGracePeriod(uptime_limit_);
1098 // Fast forward the uptime by 20 seconds. Verify that the device does not
1099 // reboot immediately.
1100 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1102 // Extend the uptime limit. Verify that the device does not reboot
1104 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1106 // Verify that the grace period has been rescheduled to start in the future.
1107 VerifyGracePeriod(uptime_limit_);
1109 // Verify that unless a non-kiosk-app session is in progress, the device
1110 // eventually reboots.
1111 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1112 is_logged_in_as_kiosk_app_);
1115 // Chrome is running. The uptime limit is set to 18 hours. The current uptime is
1117 // Verifies that when the uptime limit is shortened to 6 hours, the grace period
1118 // is rescheduled to have already started.
1119 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitBeforeToInGracePeriod) {
1120 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1122 // Verify that the device does not reboot immediately.
1123 CreateAutomaticRebootManager(false);
1125 // Set the uptime limit. Verify that the device does not reboot immediately.
1126 SetUptimeLimit(base::TimeDelta::FromHours(18), false);
1128 // Verify that a grace period has been scheduled to start in the future.
1129 VerifyGracePeriod(uptime_limit_);
1131 // Fast forward the uptime by 20 seconds. Verify that the device does not
1132 // reboot immediately.
1133 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1135 // Shorten the uptime limit. Verify that the device does not reboot
1137 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1139 // Verify that the grace period has been rescheduled and has started already.
1140 VerifyGracePeriod(uptime_limit_);
1142 // Verify that unless a non-kiosk-app session is in progress, the device
1143 // eventually reboots.
1144 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1145 is_logged_in_as_kiosk_app_);
1148 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is
1150 // Verifies that when the uptime limit is shortened to 18 hours, the grace
1151 // period is rescheduled to have started earlier.
1152 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToInGracePeriod) {
1153 task_runner_->SetUptime(base::TimeDelta::FromHours(36));
1155 // Verify that the device does not reboot immediately.
1156 CreateAutomaticRebootManager(false);
1158 // Set the uptime limit. Verify that the device does not reboot immediately.
1159 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1161 // Verify that a grace period has started.
1162 VerifyGracePeriod(uptime_limit_);
1164 // Fast forward the uptime by 20 seconds. Verify that the device does not
1165 // reboot immediately.
1166 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1168 // Shorten the uptime limit. Verify that the device does not reboot
1170 SetUptimeLimit(base::TimeDelta::FromHours(18), false);
1172 // Verify that the grace period has been rescheduled to have started earlier.
1173 VerifyGracePeriod(uptime_limit_);
1175 // Verify that unless a non-kiosk-app session is in progress, the device
1176 // eventually reboots.
1177 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1178 is_logged_in_as_kiosk_app_);
1181 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is
1183 // Verifies that when the uptime limit is shortened to 6 hours, the device
1184 // reboots immediately if no non-kiosk-app session is in progress because the
1185 // grace period ended after 6 + 24 hours of uptime.
1186 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToAfterGracePeriod) {
1187 task_runner_->SetUptime(base::TimeDelta::FromHours(36));
1189 // Verify that the device does not reboot immediately.
1190 CreateAutomaticRebootManager(false);
1192 // Set the uptime limit. Verify that the device does not reboot immediately.
1193 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1195 // Verify that a grace period has started.
1196 VerifyGracePeriod(uptime_limit_);
1198 // Fast forward the uptime by 20 seconds. Verify that the device does not
1199 // reboot immediately.
1200 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1202 // Shorten the uptime limit. Verify that unless a non-kiosk-app session is in
1203 // progress, the the device immediately reboots.
1204 SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ ||
1205 is_logged_in_as_kiosk_app_);
1207 // Verify that if a non-kiosk-app session is in progress, the device does not
1208 // reboot eventually.
1209 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1210 is_logged_in_as_kiosk_app_);
1213 // Chrome is running. The current uptime is 12 hours.
1214 // Verifies that when an update is applied, the current uptime is persisted as
1215 // the time at which a reboot became necessary. Further verifies that when the
1216 // policy to automatically reboot after an update is not enabled, no reboot
1217 // occurs and no grace period is scheduled.
1218 TEST_P(AutomaticRebootManagerTest, UpdateNoPolicy) {
1219 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1221 // Verify that the device does not reboot immediately.
1222 CreateAutomaticRebootManager(false);
1224 // Verify that no grace period has started.
1225 VerifyNoGracePeriod();
1227 // Notify that an update has been applied and a reboot is necessary. Verify
1228 // that the device does not reboot immediately.
1229 NotifyUpdateRebootNeeded();
1231 // Verify that the current uptime has been persisted as the time at which a
1232 // reboot became necessary.
1233 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1234 &update_reboot_needed_uptime_));
1235 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1237 // Verify that no grace period has started.
1238 VerifyNoGracePeriod();
1240 // Verify that the device does not reboot eventually.
1241 FastForwardUntilNoTasksRemain(false);
1244 // Chrome is running. The current uptime is 12 hours.
1245 // Verifies that when an update is applied, the current uptime is persisted as
1246 // the time at which a reboot became necessary. Further verifies that when the
1247 // policy to automatically reboot after an update is enabled, a reboot is
1248 // requested and a grace period is started that will end 24 hours from now.
1249 TEST_P(AutomaticRebootManagerTest, Update) {
1250 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1251 SetRebootAfterUpdate(true, false);
1253 // Verify that the device does not reboot immediately.
1254 CreateAutomaticRebootManager(false);
1256 // Verify that no grace period has started.
1257 VerifyNoGracePeriod();
1259 // Notify that an update has been applied and a reboot is necessary. Verify
1260 // that the device does not reboot immediately.
1261 NotifyUpdateRebootNeeded();
1263 // Verify that the current uptime has been persisted as the time at which a
1264 // reboot became necessary.
1265 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1266 &update_reboot_needed_uptime_));
1267 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1269 // Verify that a grace period has started.
1270 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1272 // Verify that unless a non-kiosk-app session is in progress, the device
1273 // eventually reboots.
1274 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1275 is_logged_in_as_kiosk_app_);
1278 // Chrome is running. The current uptime is 12 hours.
1279 // Verifies that when Chrome is notified twice that an update has been applied,
1280 // the second notification is ignored and the uptime at which it occured does
1281 // not get persisted as the time at which an update became necessary.
1282 TEST_P(AutomaticRebootManagerTest, UpdateAfterUpdate) {
1283 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1284 SetRebootAfterUpdate(true, false);
1286 // Verify that the device does not reboot immediately.
1287 CreateAutomaticRebootManager(false);
1289 // Verify that no grace period has started.
1290 VerifyNoGracePeriod();
1292 // Notify that an update has been applied and a reboot is necessary. Verify
1293 // that the device does not reboot immediately.
1294 NotifyUpdateRebootNeeded();
1296 // Verify that the current uptime has been persisted as the time at which a
1297 // reboot became necessary.
1298 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1299 &update_reboot_needed_uptime_));
1300 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1302 // Verify that a grace period has started.
1303 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1305 // Fast forward the uptime by 20 seconds. Verify that the device does not
1306 // reboot immediately.
1307 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1309 // Notify that an update has been applied and a reboot is necessary. Verify
1310 // that the device does not reboot immediately.
1311 NotifyUpdateRebootNeeded();
1313 // Verify that the previously persisted time at which a reboot became
1314 // necessary has not been overwritten.
1315 base::TimeDelta new_update_reboot_needed_uptime;
1316 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1317 &new_update_reboot_needed_uptime));
1318 EXPECT_EQ(update_reboot_needed_uptime_, new_update_reboot_needed_uptime);
1320 // Verify that unless a non-kiosk-app session is in progress, the device
1321 // eventually reboots.
1322 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1323 is_logged_in_as_kiosk_app_);
1326 // Chrome is running. The current uptime is 10 minutes.
1327 // Verifies that when the policy to automatically reboot after an update is
1328 // enabled, no reboot occurs a grace period is scheduled to begin after the
1329 // minimum of 1 hour of uptime. Further verifies that when an update is applied,
1330 // the current uptime is persisted as the time at which a reboot became
1332 TEST_P(AutomaticRebootManagerTest, UpdateBeforeMinimumUptime) {
1333 task_runner_->SetUptime(base::TimeDelta::FromMinutes(10));
1334 SetRebootAfterUpdate(true, false);
1336 // Verify that the device does not reboot immediately.
1337 CreateAutomaticRebootManager(false);
1339 // Verify that no grace period has started.
1340 VerifyNoGracePeriod();
1342 // Notify that an update has been applied and a reboot is necessary. Verify
1343 // that the device does not reboot immediately.
1344 NotifyUpdateRebootNeeded();
1346 // Verify that the current uptime has been persisted as the time at which a
1347 // reboot became necessary.
1348 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1349 &update_reboot_needed_uptime_));
1350 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1352 // Verify that a grace period has been scheduled to begin in the future.
1353 VerifyGracePeriod(base::TimeDelta::FromHours(1));
1355 // Verify that unless a non-kiosk-app session is in progress, the device
1356 // eventually reboots.
1357 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1358 is_logged_in_as_kiosk_app_);
1361 // Chrome is running. An update was applied and a reboot became necessary to
1362 // complete the update process after 6 hours of uptime. The current uptime is
1364 // Verifies that when the policy to automatically reboot after an update is
1365 // enabled, a reboot is requested and a grace period is started that will end
1366 // after 6 + 24 hours of uptime.
1367 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateInGracePeriod) {
1368 task_runner_->SetUptime(base::TimeDelta::FromHours(6));
1370 // Verify that the device does not reboot immediately.
1371 CreateAutomaticRebootManager(false);
1373 // Notify that an update has been applied and a reboot is necessary. Verify
1374 // that the device does not reboot immediately.
1375 NotifyUpdateRebootNeeded();
1377 // Fast forward the uptime to 12 hours. Verify that the device does not reboot
1379 FastForwardBy(base::TimeDelta::FromHours(6), false);
1381 // Simulate user activity.
1382 automatic_reboot_manager_->OnUserActivity(NULL);
1384 // Enable automatic reboot after an update has been applied. Verify that the
1385 // device does not reboot immediately.
1386 SetRebootAfterUpdate(true, false);
1388 // Verify that a grace period has started.
1389 VerifyGracePeriod(base::TimeDelta::FromHours(6) + uptime_processing_delay_);
1391 // Verify that unless a non-kiosk-app session is in progress, the device
1392 // eventually reboots.
1393 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1394 is_logged_in_as_kiosk_app_);
1397 // Chrome is running. An update was applied and a reboot became necessary to
1398 // complete the update process after 6 hours of uptime. The current uptime is
1400 // Verifies that when the policy to automatically reboot after an update is
1401 // enabled, the device reboots immediately if no non-kiosk-app session is in
1402 // progress because the grace period ended after 6 + 24 hours of uptime.
1403 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateAfterGracePeriod) {
1404 task_runner_->SetUptime(base::TimeDelta::FromHours(6));
1406 // Verify that the device does not reboot immediately.
1407 CreateAutomaticRebootManager(false);
1409 // Notify that an update has been applied and a reboot is necessary. Verify
1410 // that the device does not reboot immediately.
1411 NotifyUpdateRebootNeeded();
1413 // Fast forward the uptime to 12 hours. Verify that the device does not reboot
1415 FastForwardBy(base::TimeDelta::FromDays(10) - base::TimeDelta::FromHours(6),
1418 // Simulate user activity.
1419 automatic_reboot_manager_->OnUserActivity(NULL);
1421 // Enable automatic rebooting after an update has been applied. Verify that
1422 // unless a non-kiosk-app session is in progress, the the device immediately
1424 SetRebootAfterUpdate(true, !is_user_logged_in_ || is_logged_in_as_kiosk_app_);
1426 // Verify that if a non-kiosk-app session is in progress, the device does not
1427 // reboot eventually.
1428 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1429 is_logged_in_as_kiosk_app_);
1432 // Chrome is running. An update was applied and a reboot became necessary to
1433 // complete the update process after 6 hours of uptime. The policy to
1434 // automatically reboot after an update is enabled. The current uptime is
1435 // 6 hours 20 seconds.
1436 // Verifies that when the policy to automatically reboot after an update is
1437 // disabled, the reboot request and grace period are removed.
1438 TEST_P(AutomaticRebootManagerTest, PolicyOffAfterUpdate) {
1439 task_runner_->SetUptime(base::TimeDelta::FromHours(6));
1440 SetRebootAfterUpdate(true, false);
1442 // Verify that the device does not reboot immediately.
1443 CreateAutomaticRebootManager(false);
1445 // Notify that an update has been applied and a reboot is necessary. Verify
1446 // that the device does not reboot immediately.
1447 NotifyUpdateRebootNeeded();
1449 // Verify that a grace period has started.
1450 VerifyGracePeriod(task_runner_->Uptime() + uptime_processing_delay_);
1452 // Fast forward the uptime by 20 seconds. Verify that the device does not
1453 // reboot immediately.
1454 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1456 // Disable automatic rebooting after an update has been applied. Verify that
1457 // the device does not reboot immediately.
1458 SetRebootAfterUpdate(false, false);
1460 // Verify that the grace period has been removed.
1461 VerifyNoGracePeriod();
1463 // Verify that the device does not reboot eventually.
1464 FastForwardUntilNoTasksRemain(false);
1467 // Chrome is running. The current uptime is not available.
1468 // Verifies that even if an uptime limit is set, the policy to automatically
1469 // reboot after an update is enabled and an update has been applied, no reboot
1470 // occurs and no grace period is scheduled. Further verifies that no time is
1471 // persisted as the time at which a reboot became necessary.
1472 TEST_P(AutomaticRebootManagerTest, NoUptime) {
1473 // Verify that the device does not reboot immediately.
1474 CreateAutomaticRebootManager(false);
1476 // Set the uptime limit. Verify that the device does not reboot immediately.
1477 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1479 // Verify that no grace period has started.
1480 VerifyNoGracePeriod();
1482 // Enable automatic rebooting after an update has been applied. Verify that
1483 // the device does not reboot immediately.
1484 SetRebootAfterUpdate(true, false);
1486 // Verify that no grace period has started.
1487 VerifyNoGracePeriod();
1489 // Notify that an update has been applied and a reboot is necessary. Verify
1490 // that the device does not reboot immediately.
1491 NotifyUpdateRebootNeeded();
1493 // Verify that no time is persisted as the time at which a reboot became
1495 EXPECT_FALSE(ReadUpdateRebootNeededUptimeFromFile(
1496 &update_reboot_needed_uptime_));
1498 // Verify that no grace period has started.
1499 VerifyNoGracePeriod();
1501 // Verify that the device does not reboot eventually.
1502 FastForwardUntilNoTasksRemain(false);
1505 // Chrome is running. The policy to automatically reboot after an update is
1506 // enabled. The current uptime is 12 hours.
1507 // Verifies that when an uptime limit of 6 hours is set, the availability of an
1508 // update does not cause the grace period to be rescheduled. Further verifies
1509 // that the current uptime is persisted as the time at which a reboot became
1511 TEST_P(AutomaticRebootManagerTest, UptimeLimitBeforeUpdate) {
1512 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1513 SetRebootAfterUpdate(true, false);
1515 // Verify that the device does not reboot immediately.
1516 CreateAutomaticRebootManager(false);
1518 // Set the uptime limit. Verify that the device does not reboot immediately.
1519 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1521 // Verify that a grace period has been scheduled to start in the future.
1522 VerifyGracePeriod(uptime_limit_);
1524 // Fast forward the uptime by 20 seconds. Verify that the device does not
1525 // reboot immediately.
1526 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1528 // Notify that an update has been applied and a reboot is necessary. Verify
1529 // that the device does not reboot immediately.
1530 NotifyUpdateRebootNeeded();
1532 // Verify that the current uptime has been persisted as the time at which a
1533 // reboot became necessary.
1534 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1535 &update_reboot_needed_uptime_));
1536 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1538 // Verify that the grace period has not been rescheduled.
1539 VerifyGracePeriod(uptime_limit_);
1541 // Verify that unless a non-kiosk-app session is in progress, the device
1542 // eventually reboots.
1543 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1544 is_logged_in_as_kiosk_app_);
1547 // Chrome is running. The policy to automatically reboot after an update is
1548 // enabled. The current uptime is 12 hours.
1549 // Verifies that when an uptime limit of 24 hours is set, the availability of an
1550 // update causes the grace period to be rescheduled so that it ends 24 hours
1551 // from now. Further verifies that the current uptime is persisted as the time
1552 // at which a reboot became necessary.
1553 TEST_P(AutomaticRebootManagerTest, UpdateBeforeUptimeLimit) {
1554 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1555 SetRebootAfterUpdate(true, false);
1557 // Verify that the device does not reboot immediately.
1558 CreateAutomaticRebootManager(false);
1560 // Set the uptime limit. Verify that the device does not reboot immediately.
1561 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1563 // Verify that a grace period has been scheduled to start in the future.
1564 VerifyGracePeriod(uptime_limit_);
1566 // Fast forward the uptime by 20 seconds. Verify that the device does not
1567 // reboot immediately.
1568 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1570 // Notify that an update has been applied and a reboot is necessary. Verify
1571 // that the device does not reboot immediately.
1572 NotifyUpdateRebootNeeded();
1574 // Verify that the current uptime has been persisted as the time at which a
1575 // reboot became necessary.
1576 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1577 &update_reboot_needed_uptime_));
1578 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1580 // Verify that the grace period has been rescheduled to start at the time that
1581 // the update became available.
1582 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1584 // Verify that unless a non-kiosk-app session is in progress, the device
1585 // eventually reboots.
1586 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1587 is_logged_in_as_kiosk_app_);
1590 // Chrome is running. The uptime limit is set to 24 hours. An update was applied
1591 // and a reboot became necessary to complete the update process after 12 hours.
1592 // The policy to automatically reboot after an update is enabled. The current
1593 // uptime is 12 hours 20 seconds.
1594 // Verifies that when the policy to reboot after an update is disabled, the
1595 // grace period is rescheduled to start after 24 hours of uptime. Further
1596 // verifies that when the uptime limit is removed, the grace period is removed.
1597 TEST_P(AutomaticRebootManagerTest, PolicyOffThenUptimeLimitOff) {
1598 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1599 SetRebootAfterUpdate(true, false);
1601 // Verify that the device does not reboot immediately.
1602 CreateAutomaticRebootManager(false);
1604 // Set the uptime limit. Verify that the device does not reboot immediately.
1605 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1607 // Verify that the grace period has started.
1608 VerifyGracePeriod(uptime_limit_);
1610 // Notify that an update has been applied and a reboot is necessary. Verify
1611 // that the device does not reboot immediately.
1612 NotifyUpdateRebootNeeded();
1614 // Verify that the current uptime has been persisted as the time at which a
1615 // reboot became necessary.
1616 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1617 &update_reboot_needed_uptime_));
1618 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1620 // Verify that a grace period has been rescheduled to end 24 hours from now.
1621 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1623 // Fast forward the uptime by 20 seconds. Verify that the device does not
1624 // reboot immediately.
1625 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1627 // Disable automatic reboot after an update has been applied. Verify that the
1628 // device does not reboot immediately.
1629 SetRebootAfterUpdate(false, false);
1631 // Verify that the grace period has been rescheduled to start after 24 hours
1633 VerifyGracePeriod(uptime_limit_);
1635 // Remove the uptime limit. Verify that the device does not reboot
1637 SetUptimeLimit(base::TimeDelta(), false);
1639 // Verify that the grace period has been removed.
1640 VerifyNoGracePeriod();
1642 // Verify that the device does not reboot eventually.
1643 FastForwardUntilNoTasksRemain(false);
1646 // Chrome is running. The uptime limit is set to 6 hours. An update was applied
1647 // and a reboot became necessary to complete the update process after 12 hours.
1648 // The policy to automatically reboot after an update is enabled. The current
1649 // uptime is 12 hours 20 seconds.
1650 // Verifies that when the uptime limit is removed, the grace period is
1651 // rescheduled to have started after 12 hours of uptime. Further verifies that
1652 // when the policy to reboot after an update is disabled, the reboot request and
1653 // grace period are removed.
1654 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffThenPolicyOff) {
1655 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1656 SetRebootAfterUpdate(true, false);
1658 // Verify that the device does not reboot immediately.
1659 CreateAutomaticRebootManager(false);
1661 // Notify that an update has been applied and a reboot is necessary. Verify
1662 // that the device does not reboot immediately.
1663 NotifyUpdateRebootNeeded();
1665 // Verify that the current uptime has been persisted as the time at which a
1666 // reboot became necessary.
1667 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1668 &update_reboot_needed_uptime_));
1669 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1671 // Verify that the grace period has started.
1672 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1674 // Set the uptime limit. Verify that the device does not reboot immediately.
1675 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1677 // Verify that the grace period has been rescheduled to have started after
1678 // 6 hours of uptime.
1679 VerifyGracePeriod(uptime_limit_);
1681 // Fast forward the uptime by 20 seconds. Verify that the device does not
1682 // reboot immediately.
1683 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1685 // Remove the uptime limit. Verify that the device does not reboot
1687 SetUptimeLimit(base::TimeDelta(), false);
1689 // Verify that a grace period has been rescheduled to have started after 12
1691 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1693 // Disable automatic reboot after an update has been applied. Verify that the
1694 // device does not reboot immediately.
1695 SetRebootAfterUpdate(false, false);
1697 // Verify that the grace period has been removed.
1698 VerifyNoGracePeriod();
1700 // Verify that the device does not reboot eventually.
1701 FastForwardUntilNoTasksRemain(false);
1704 // Chrome is running. The uptime limit is 6 hours. The current uptime is
1705 // 29 hours 59 minutes 59 seconds.
1706 // Verifies that if no non-kiosk-app session is in progress, the device reboots
1707 // immediately when the grace period ends after 6 + 24 hours of uptime.
1708 TEST_P(AutomaticRebootManagerTest, GracePeriodEnd) {
1709 task_runner_->SetUptime(base::TimeDelta::FromHours(29) +
1710 base::TimeDelta::FromMinutes(59) +
1711 base::TimeDelta::FromSeconds(59));
1713 // Verify that the device does not reboot immediately.
1714 CreateAutomaticRebootManager(false);
1716 // Set the uptime limit. Verify that the device does not reboot immediately.
1717 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1719 // Verify that a grace period has started.
1720 VerifyGracePeriod(uptime_limit_);
1722 // Fast forward the uptime by 1 second. Verify that unless a non-kiosk-app
1723 // session is in progress, the the device immediately reboots.
1724 FastForwardBy(base::TimeDelta::FromSeconds(1), !is_user_logged_in_ ||
1725 is_logged_in_as_kiosk_app_);
1727 // Verify that if a non-kiosk-app session is in progress, the device does not
1728 // reboot eventually.
1729 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1730 is_logged_in_as_kiosk_app_);
1733 // Chrome is starting. The current uptime is 10 days.
1734 // Verifies that when no automatic reboot policy is enabled, no reboot occurs
1735 // and no grace period is scheduled.
1736 TEST_P(AutomaticRebootManagerTest, StartNoPolicy) {
1737 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
1739 // Verify that the device does not reboot immediately.
1740 CreateAutomaticRebootManager(false);
1742 // Verify that no grace period has started.
1743 VerifyNoGracePeriod();
1745 // Verify that the device does not reboot eventually.
1746 FastForwardUntilNoTasksRemain(false);
1749 // Chrome is starting. The uptime limit is set to 24 hours. The current uptime
1751 // Verifies that no reboot occurs and a grace period is scheduled to begin after
1752 // 24 hours of uptime.
1753 TEST_P(AutomaticRebootManagerTest, StartBeforeUptimeLimitGracePeriod) {
1754 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1755 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1757 // Verify that the device does not reboot immediately.
1758 CreateAutomaticRebootManager(false);
1760 // Verify that a grace period has been scheduled to start in the future.
1761 VerifyGracePeriod(uptime_limit_);
1763 // Verify that unless a non-kiosk-app session is in progress, the device
1764 // eventually reboots.
1765 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1766 is_logged_in_as_kiosk_app_);
1769 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is
1771 // Verifies that if no non-kiosk-app session is in progress, the device reboots
1772 // immediately because the grace period ended after 6 + 24 hours of uptime.
1773 TEST_P(AutomaticRebootManagerTest, StartAfterUptimeLimitGracePeriod) {
1774 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1775 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
1777 // Verify that unless a non-kiosk-app session is in progress, the the device
1778 // immediately reboots.
1779 CreateAutomaticRebootManager(!is_user_logged_in_ ||
1780 is_logged_in_as_kiosk_app_);
1782 // Verify that if a non-kiosk-app session is in progress, the device does not
1783 // reboot eventually.
1784 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1785 is_logged_in_as_kiosk_app_);
1788 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is
1790 // Verifies that a reboot is requested and a grace period is started that will
1791 // end after 6 + 24 hours of uptime.
1792 TEST_P(AutomaticRebootManagerTest, StartInUptimeLimitGracePeriod) {
1793 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1794 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1796 // Verify that the device does not reboot immediately.
1797 CreateAutomaticRebootManager(false);
1799 // Verify that a grace period has started.
1800 VerifyGracePeriod(uptime_limit_);
1802 // Verify that unless a non-kiosk-app session is in progress, the device
1803 // eventually reboots.
1804 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1805 is_logged_in_as_kiosk_app_);
1808 // Chrome is starting. An update was applied and a reboot became necessary to
1809 // complete the update process after 6 hours of uptime. The current uptime is
1811 // Verifies that when the policy to automatically reboot after an update is
1812 // enabled, the device reboots immediately if no non-kiosk-app session is in
1813 // progress because the grace period ended after 6 + 24 hours of uptime.
1814 TEST_P(AutomaticRebootManagerTest, StartAfterUpdateGracePeriod) {
1815 SetUpdateStatusNeedReboot();
1816 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
1817 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
1818 SetRebootAfterUpdate(true, false);
1820 // Verify that unless a non-kiosk-app session is in progress, the device
1821 // reboots immediately.
1822 CreateAutomaticRebootManager(!is_user_logged_in_ ||
1823 is_logged_in_as_kiosk_app_);
1825 // Verify that if a non-kiosk-app session is in progress, the device does not
1826 // reboot eventually.
1827 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1828 is_logged_in_as_kiosk_app_);
1831 // Chrome is starting. An update was applied and a reboot became necessary to
1832 // complete the update process after 6 hours of uptime. The current uptime is
1834 // Verifies that when the policy to automatically reboot after an update is
1835 // enabled, a reboot is requested and a grace period is started that will end
1836 // after 6 + 24 hours of uptime.
1837 TEST_P(AutomaticRebootManagerTest, StartInUpdateGracePeriod) {
1838 SetUpdateStatusNeedReboot();
1839 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
1840 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1841 SetRebootAfterUpdate(true, false);
1843 // Verify that the device does not reboot immediately.
1844 CreateAutomaticRebootManager(false);
1846 // Verify that a grace period has started.
1847 VerifyGracePeriod(update_reboot_needed_uptime_);
1849 // Verify that unless a non-kiosk-app session is in progress, the device
1850 // eventually reboots.
1851 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1852 is_logged_in_as_kiosk_app_);
1855 // Chrome is starting. An update was applied and a reboot became necessary to
1856 // complete the update process after 10 minutes of uptime. The current uptime is
1858 // Verifies that when the policy to automatically reboot after an update is
1859 // enabled, no reboot occurs and a grace period is scheduled to begin after the
1860 // minimum of 1 hour of uptime.
1861 TEST_P(AutomaticRebootManagerTest, StartBeforeUpdateGracePeriod) {
1862 SetUpdateStatusNeedReboot();
1863 SetUpdateRebootNeededUptime(base::TimeDelta::FromMinutes(10));
1864 task_runner_->SetUptime(base::TimeDelta::FromMinutes(20));
1865 SetRebootAfterUpdate(true, false);
1867 // Verify that the device does not reboot immediately.
1868 CreateAutomaticRebootManager(false);
1870 // Verify that a grace period has been scheduled to start in the future.
1871 VerifyGracePeriod(base::TimeDelta::FromHours(1));
1873 // Verify that unless a non-kiosk-app session is in progress, the device
1874 // eventually reboots.
1875 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1876 is_logged_in_as_kiosk_app_);
1879 // Chrome is starting. An update was applied and a reboot became necessary to
1880 // complete the update process after 6 hours of uptime. The current uptime is
1882 // Verifies that when the policy to automatically reboot after an update is not
1883 // enabled, no reboot occurs and no grace period is scheduled.
1884 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicy) {
1885 SetUpdateStatusNeedReboot();
1886 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
1887 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
1889 // Verify that the device does not reboot immediately.
1890 CreateAutomaticRebootManager(false);
1892 // Verify that no grace period has started.
1893 VerifyNoGracePeriod();
1895 // Verify that the device does not reboot eventually.
1896 FastForwardUntilNoTasksRemain(false);
1899 // Chrome is starting. An update was applied and a reboot became necessary to
1900 // complete the update process but the time at which this happened was lost. The
1901 // current uptime is 10 days.
1902 // Verifies that the current uptime is persisted as the time at which a reboot
1903 // became necessary. Further verifies that when the policy to automatically
1904 // reboot after an update is enabled, a reboot is requested and a grace period
1905 // is started that will end 24 hours from now.
1906 TEST_P(AutomaticRebootManagerTest, StartUpdateTimeLost) {
1907 SetUpdateStatusNeedReboot();
1908 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
1909 SetRebootAfterUpdate(true, false);
1911 // Verify that the device does not reboot immediately.
1912 CreateAutomaticRebootManager(false);
1914 // Verify that the current uptime has been persisted as the time at which a
1915 // reboot became necessary.
1916 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1917 &update_reboot_needed_uptime_));
1918 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1920 // Verify that a grace period has started.
1921 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1923 // Verify that unless a non-kiosk-app session is in progress, the device
1924 // eventually reboots.
1925 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1926 is_logged_in_as_kiosk_app_);
1929 // Chrome is starting. An update was applied and a reboot became necessary to
1930 // complete the update process but the time at which this happened was lost. The
1931 // current uptime is 10 days.
1932 // Verifies that the current uptime is persisted as the time at which a reboot
1933 // became necessary. Further verifies that when the policy to automatically
1934 // reboot after an update is not enabled, no reboot occurs and no grace period
1936 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicyTimeLost) {
1937 SetUpdateStatusNeedReboot();
1938 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
1940 // Verify that the device does not reboot immediately.
1941 CreateAutomaticRebootManager(false);
1943 // Verify that the current uptime has been persisted as the time at which a
1944 // reboot became necessary.
1945 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1946 &update_reboot_needed_uptime_));
1947 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1949 // Verify that no grace period has started.
1950 VerifyNoGracePeriod();
1952 // Verify that the device does not reboot eventually.
1953 FastForwardUntilNoTasksRemain(false);
1956 // Chrome is starting. No update has been applied. The current uptime is
1958 // Verifies that no time is persisted as the time at which a reboot became
1959 // necessary. Further verifies that no reboot occurs and no grace period is
1961 TEST_P(AutomaticRebootManagerTest, StartNoUpdate) {
1962 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1963 SetRebootAfterUpdate(true, false);
1965 // Verify that the device does not reboot immediately.
1966 CreateAutomaticRebootManager(false);
1968 // Verify that no time is persisted as the time at which a reboot became
1970 EXPECT_FALSE(ReadUpdateRebootNeededUptimeFromFile(
1971 &update_reboot_needed_uptime_));
1973 // Verify that no grace period has started.
1974 VerifyNoGracePeriod();
1976 // Verify that the device does not reboot eventually.
1977 FastForwardUntilNoTasksRemain(false);
1980 // Chrome is starting. The uptime limit is set to 6 hours. Also, an update was
1981 // applied and a reboot became necessary to complete the update process after
1982 // 8 hours of uptime. The current uptime is 12 hours.
1983 // Verifies that when the policy to automatically reboot after an update is
1984 // enabled, a reboot is requested and a grace period is started that will end
1985 // after 6 + 24 hours of uptime.
1986 TEST_P(AutomaticRebootManagerTest, StartUptimeLimitBeforeUpdate) {
1987 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1988 SetUpdateStatusNeedReboot();
1989 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(8));
1990 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1991 SetRebootAfterUpdate(true, false);
1993 // Verify that the device does not reboot immediately.
1994 CreateAutomaticRebootManager(false);
1996 // Verify that a grace period has started.
1997 VerifyGracePeriod(uptime_limit_);
1999 // Verify that unless a non-kiosk-app session is in progress, the device
2000 // eventually reboots.
2001 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2002 is_logged_in_as_kiosk_app_);
2005 // Chrome is starting. The uptime limit is set to 8 hours. Also, an update was
2006 // applied and a reboot became necessary to complete the update process after
2007 // 6 hours of uptime. The current uptime is 12 hours.
2008 // Verifies that when the policy to automatically reboot after an update is
2009 // enabled, a reboot is requested and a grace period is started that will end
2010 // after 6 + 24 hours of uptime.
2011 TEST_P(AutomaticRebootManagerTest, StartUpdateBeforeUptimeLimit) {
2012 SetUptimeLimit(base::TimeDelta::FromHours(8), false);
2013 SetUpdateStatusNeedReboot();
2014 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
2015 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
2016 SetRebootAfterUpdate(true, false);
2018 // Verify that the device does not reboot immediately.
2019 CreateAutomaticRebootManager(false);
2021 // Verify that a grace period has started.
2022 VerifyGracePeriod(update_reboot_needed_uptime_);
2024 // Verify that unless a non-kiosk-app session is in progress, the device
2025 // eventually reboots.
2026 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2027 is_logged_in_as_kiosk_app_);
2030 // Chrome is starting. The uptime limit is set to 6 hours. Also, an update was
2031 // applied and a reboot became necessary to complete the update process after
2032 // 6 hours of uptime. The current uptime is not available.
2033 // Verifies that even if the policy to automatically reboot after an update is
2034 // enabled, no reboot occurs and no grace period is scheduled.
2035 TEST_P(AutomaticRebootManagerTest, StartNoUptime) {
2036 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
2037 SetUpdateStatusNeedReboot();
2038 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
2039 SetRebootAfterUpdate(true, false);
2041 // Verify that the device does not reboot immediately.
2042 CreateAutomaticRebootManager(false);
2044 // Verify that no grace period has started.
2045 VerifyNoGracePeriod();
2047 // Verify that the device does not reboot eventually.
2048 FastForwardUntilNoTasksRemain(false);
2051 INSTANTIATE_TEST_CASE_P(
2052 AutomaticRebootManagerTestInstance,
2053 AutomaticRebootManagerTest,
2055 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN,
2056 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION,
2057 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION));
2059 } // namespace system
2060 } // namespace chromeos