Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / chromeos / system / automatic_reboot_manager_unittest.cc
bloba6ac98325d0b748925f52d948bf755ea4faceba9
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"
7 #include <string>
9 #include "ash/shell.h"
10 #include "ash/test/test_shell_delegate.h"
11 #include "base/compiler_specific.h"
12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/message_loop/message_loop.h"
17 #include "base/path_service.h"
18 #include "base/prefs/pref_registry_simple.h"
19 #include "base/prefs/testing_pref_service.h"
20 #include "base/run_loop.h"
21 #include "base/strings/string_number_conversions.h"
22 #include "base/test/simple_test_tick_clock.h"
23 #include "base/test/test_mock_time_task_runner.h"
24 #include "base/thread_task_runner_handle.h"
25 #include "base/threading/sequenced_worker_pool.h"
26 #include "base/time/tick_clock.h"
27 #include "base/values.h"
28 #include "chrome/browser/chrome_notification_types.h"
29 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
30 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
31 #include "chrome/browser/chromeos/system/automatic_reboot_manager_observer.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_power_manager_client.h"
37 #include "chromeos/dbus/fake_update_engine_client.h"
38 #include "content/public/browser/browser_thread.h"
39 #include "content/public/browser/notification_details.h"
40 #include "content/public/browser/notification_service.h"
41 #include "content/public/browser/notification_source.h"
42 #include "content/public/test/test_browser_thread.h"
43 #include "testing/gmock/include/gmock/gmock.h"
44 #include "testing/gtest/include/gtest/gtest.h"
45 #include "ui/message_center/message_center.h"
47 using ::testing::_;
48 using ::testing::Invoke;
49 using ::testing::Mock;
50 using ::testing::ReturnPointee;
52 namespace chromeos {
53 namespace system {
55 namespace {
57 // Provides a mock device uptime that follows the mock time maintained by the
58 // given |mock_time_task_runner| with a configurable offset. The mock uptime can
59 // also be written to |uptime_file_|, thusly allowing to mock /proc/uptime.
60 class MockUptimeProvider {
61 public:
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);
68 void WriteUptimeToFile();
70 // Adjusts the offset so that the current mock uptime will be |uptime|.
71 void SetUptime(const base::TimeDelta& uptime);
73 void set_uptime_file_path(const base::FilePath& uptime_file_path) {
74 uptime_file_path_ = uptime_file_path;
77 base::TimeDelta uptime() const {
78 return mock_time_task_runner_->NowTicks() - base::TimeTicks() +
79 uptime_offset_;
82 private:
83 base::TestMockTimeTaskRunner* mock_time_task_runner_;
85 base::FilePath uptime_file_path_;
86 base::TimeDelta uptime_offset_;
88 DISALLOW_COPY_AND_ASSIGN(MockUptimeProvider);
91 class TestAutomaticRebootManagerTaskRunner
92 : public base::TestMockTimeTaskRunner {
93 public:
94 TestAutomaticRebootManagerTaskRunner();
96 MockUptimeProvider* uptime_provider() const {
97 return uptime_provider_.get();
100 private:
101 ~TestAutomaticRebootManagerTaskRunner() override;
103 // base::TestMockTimeTaskRunner:
104 void OnBeforeSelectingTask() override;
105 void OnAfterTimePassed() override;
106 void OnAfterTaskRun() override;
108 scoped_ptr<MockUptimeProvider> uptime_provider_;
110 DISALLOW_COPY_AND_ASSIGN(TestAutomaticRebootManagerTaskRunner);
113 class MockAutomaticRebootManagerObserver
114 : public AutomaticRebootManagerObserver {
115 public:
116 MockAutomaticRebootManagerObserver();
117 ~MockAutomaticRebootManagerObserver() override;
119 void Init(AutomaticRebootManager* automatic_reboot_manger);
121 // AutomaticRebootManagerObserver:
122 MOCK_METHOD1(OnRebootRequested, void(Reason));
123 MOCK_METHOD0(WillDestroyAutomaticRebootManager, void());
125 private:
126 void StopObserving();
128 AutomaticRebootManager* automatic_reboot_manger_;
130 DISALLOW_COPY_AND_ASSIGN(MockAutomaticRebootManagerObserver);
133 } // namespace
135 class AutomaticRebootManagerBasicTest : public testing::Test {
136 protected:
137 typedef base::OneShotTimer<AutomaticRebootManager> Timer;
139 AutomaticRebootManagerBasicTest();
140 ~AutomaticRebootManagerBasicTest() override;
142 // testing::Test:
143 void SetUp() override;
144 void TearDown() override;
146 void SetUpdateRebootNeededUptime(const base::TimeDelta& uptime);
147 void SetRebootAfterUpdate(bool reboot_after_update, bool expect_reboot);
148 void SetUptimeLimit(const base::TimeDelta& limit, bool expect_reboot);
149 void NotifyUpdateRebootNeeded();
150 void NotifyResumed(bool expect_reboot);
151 void NotifyTerminating(bool expect_reboot);
153 void FastForwardBy(const base::TimeDelta& delta, bool expect_reboot);
154 void FastForwardUntilNoTasksRemain(bool expect_reboot);
156 void ExpectRebootRequest(AutomaticRebootManagerObserver::Reason reason);
157 void ExpectNoRebootRequest();
159 void CreateAutomaticRebootManager(bool expect_reboot);
161 bool ReadUpdateRebootNeededUptimeFromFile(base::TimeDelta* uptime);
162 void VerifyRebootRequested(AutomaticRebootManagerObserver::Reason reason);
163 void VerifyNoRebootRequested() const;
164 void VerifyLoginScreenIdleTimerIsStopped() const;
165 void VerifyNoGracePeriod() const;
166 void VerifyGracePeriod(const base::TimeDelta& start_uptime) const;
168 // Sets the status of |update_engine_client_| to NEED_REBOOT for tests.
169 void SetUpdateStatusNeedReboot();
171 MockUptimeProvider* uptime_provider() const {
172 return task_runner_->uptime_provider();
175 bool is_user_logged_in_;
176 bool is_logged_in_as_kiosk_app_;
178 // The uptime is read in the blocking thread pool and then processed on the
179 // UI thread. This causes the UI thread to start processing the uptime when it
180 // has increased by a small offset already. The offset is calculated and
181 // stored in |uptime_processing_delay_| so that tests can accurately determine
182 // the uptime seen by the UI thread.
183 base::TimeDelta uptime_processing_delay_;
184 base::TimeDelta update_reboot_needed_uptime_;
185 base::TimeDelta uptime_limit_;
187 scoped_refptr<TestAutomaticRebootManagerTaskRunner> task_runner_;
189 MockAutomaticRebootManagerObserver automatic_reboot_manager_observer_;
190 scoped_ptr<AutomaticRebootManager> automatic_reboot_manager_;
192 private:
193 void VerifyTimerIsStopped(const Timer* timer) const;
194 void VerifyTimerIsRunning(const Timer* timer,
195 const base::TimeDelta& delay) const;
196 void VerifyLoginScreenIdleTimerIsRunning() const;
198 base::ScopedTempDir temp_dir_;
199 base::FilePath update_reboot_needed_uptime_file_;
201 bool reboot_after_update_;
203 base::ThreadTaskRunnerHandle ui_thread_task_runner_handle_;
205 TestingPrefServiceSimple local_state_;
206 MockUserManager* mock_user_manager_; // Not owned.
207 ScopedUserManagerEnabler user_manager_enabler_;
209 FakePowerManagerClient* power_manager_client_; // Not owned.
210 FakeUpdateEngineClient* update_engine_client_; // Not owned.
213 enum AutomaticRebootManagerTestScenario {
214 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN,
215 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION,
216 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION,
219 // This class runs each test case three times:
220 // * once while the login screen is being shown
221 // * once while a kiosk app session is in progress
222 // * once while a non-kiosk-app session is in progress
223 class AutomaticRebootManagerTest
224 : public AutomaticRebootManagerBasicTest,
225 public testing::WithParamInterface<AutomaticRebootManagerTestScenario> {
226 protected:
227 AutomaticRebootManagerTest();
228 virtual ~AutomaticRebootManagerTest();
231 void SaveUptimeToFile(const base::FilePath& path,
232 const base::TimeDelta& uptime) {
233 if (path.empty() || uptime == base::TimeDelta())
234 return;
236 const std::string uptime_seconds = base::DoubleToString(uptime.InSecondsF());
237 ASSERT_EQ(static_cast<int>(uptime_seconds.size()),
238 base::WriteFile(path, uptime_seconds.c_str(),
239 uptime_seconds.size()));
242 MockUptimeProvider::MockUptimeProvider(
243 base::TestMockTimeTaskRunner* mock_time_task_runner)
244 : mock_time_task_runner_(mock_time_task_runner) {
247 void MockUptimeProvider::WriteUptimeToFile() {
248 SaveUptimeToFile(uptime_file_path_, uptime());
251 void MockUptimeProvider::SetUptime(const base::TimeDelta& uptime) {
252 uptime_offset_ =
253 uptime - (mock_time_task_runner_->NowTicks() - base::TimeTicks());
254 WriteUptimeToFile();
257 TestAutomaticRebootManagerTaskRunner::TestAutomaticRebootManagerTaskRunner()
258 : uptime_provider_(new MockUptimeProvider(this)) {
261 TestAutomaticRebootManagerTaskRunner::~TestAutomaticRebootManagerTaskRunner() {
264 void TestAutomaticRebootManagerTaskRunner::OnBeforeSelectingTask() {
265 base::SequencedWorkerPool* blocking_pool =
266 content::BrowserThread::GetBlockingPool();
267 blocking_pool->FlushForTesting();
270 void TestAutomaticRebootManagerTaskRunner::OnAfterTimePassed() {
271 uptime_provider_->WriteUptimeToFile();
274 void TestAutomaticRebootManagerTaskRunner::OnAfterTaskRun() {
275 base::SequencedWorkerPool* blocking_pool =
276 content::BrowserThread::GetBlockingPool();
277 blocking_pool->FlushForTesting();
280 MockAutomaticRebootManagerObserver::MockAutomaticRebootManagerObserver()
281 : automatic_reboot_manger_(nullptr) {
282 ON_CALL(*this, WillDestroyAutomaticRebootManager())
283 .WillByDefault(
284 Invoke(this,
285 &MockAutomaticRebootManagerObserver::StopObserving));
288 void MockAutomaticRebootManagerObserver::Init(
289 AutomaticRebootManager* automatic_reboot_manger) {
290 EXPECT_FALSE(automatic_reboot_manger_);
291 automatic_reboot_manger_ = automatic_reboot_manger;
292 automatic_reboot_manger_->AddObserver(this);
295 MockAutomaticRebootManagerObserver::~MockAutomaticRebootManagerObserver() {
296 if (automatic_reboot_manger_)
297 automatic_reboot_manger_->RemoveObserver(this);
300 void MockAutomaticRebootManagerObserver::StopObserving() {
301 ASSERT_TRUE(automatic_reboot_manger_);
302 automatic_reboot_manger_->RemoveObserver(this);
303 automatic_reboot_manger_ = nullptr;
306 AutomaticRebootManagerBasicTest::AutomaticRebootManagerBasicTest()
307 : is_user_logged_in_(false),
308 is_logged_in_as_kiosk_app_(false),
309 task_runner_(new TestAutomaticRebootManagerTaskRunner),
310 reboot_after_update_(false),
311 ui_thread_task_runner_handle_(task_runner_),
312 mock_user_manager_(new MockUserManager),
313 user_manager_enabler_(mock_user_manager_),
314 power_manager_client_(NULL),
315 update_engine_client_(NULL) {
318 AutomaticRebootManagerBasicTest::~AutomaticRebootManagerBasicTest() {
321 void AutomaticRebootManagerBasicTest::SetUp() {
322 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
323 const base::FilePath& temp_dir = temp_dir_.path();
324 const base::FilePath uptime_file = temp_dir.Append("uptime");
325 uptime_provider()->set_uptime_file_path(uptime_file);
326 ASSERT_FALSE(base::WriteFile(uptime_file, NULL, 0));
327 update_reboot_needed_uptime_file_ =
328 temp_dir.Append("update_reboot_needed_uptime");
329 ASSERT_FALSE(base::WriteFile(update_reboot_needed_uptime_file_, NULL, 0));
330 ASSERT_TRUE(PathService::Override(chromeos::FILE_UPTIME, uptime_file));
331 ASSERT_TRUE(PathService::Override(chromeos::FILE_UPDATE_REBOOT_NEEDED_UPTIME,
332 update_reboot_needed_uptime_file_));
334 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
335 AutomaticRebootManager::RegisterPrefs(local_state_.registry());
337 scoped_ptr<DBusThreadManagerSetter> dbus_setter =
338 chromeos::DBusThreadManager::GetSetterForTesting();
339 power_manager_client_ = new FakePowerManagerClient;
340 dbus_setter->SetPowerManagerClient(
341 scoped_ptr<PowerManagerClient>(power_manager_client_));
342 update_engine_client_ = new FakeUpdateEngineClient;
343 dbus_setter->SetUpdateEngineClient(
344 scoped_ptr<UpdateEngineClient>(update_engine_client_));
346 EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn())
347 .WillRepeatedly(ReturnPointee(&is_user_logged_in_));
348 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsKioskApp())
349 .WillRepeatedly(ReturnPointee(&is_logged_in_as_kiosk_app_));
352 void AutomaticRebootManagerBasicTest::TearDown() {
353 if (automatic_reboot_manager_) {
354 Mock::VerifyAndClearExpectations(&automatic_reboot_manager_observer_);
355 EXPECT_CALL(automatic_reboot_manager_observer_,
356 WillDestroyAutomaticRebootManager()).Times(1);
357 EXPECT_CALL(automatic_reboot_manager_observer_,
358 OnRebootRequested(_)).Times(0);
359 // Let the AutomaticRebootManager, if any, unregister itself as an observer
360 // of several subsystems.
361 automatic_reboot_manager_.reset();
362 task_runner_->RunUntilIdle();
365 DBusThreadManager::Shutdown();
366 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
369 void AutomaticRebootManagerBasicTest::SetUpdateRebootNeededUptime(
370 const base::TimeDelta& uptime) {
371 update_reboot_needed_uptime_ = uptime;
372 SaveUptimeToFile(update_reboot_needed_uptime_file_, uptime);
375 void AutomaticRebootManagerBasicTest::SetRebootAfterUpdate(
376 bool reboot_after_update,
377 bool expect_reboot) {
378 reboot_after_update_ = reboot_after_update;
379 local_state_.SetManagedPref(prefs::kRebootAfterUpdate,
380 new base::FundamentalValue(reboot_after_update));
381 task_runner_->RunUntilIdle();
382 EXPECT_EQ(expect_reboot ? 1 : 0,
383 power_manager_client_->num_request_restart_calls());
386 void AutomaticRebootManagerBasicTest::SetUptimeLimit(
387 const base::TimeDelta& limit,
388 bool expect_reboot) {
389 uptime_limit_ = limit;
390 if (limit == base::TimeDelta()) {
391 local_state_.RemoveManagedPref(prefs::kUptimeLimit);
392 } else {
393 local_state_.SetManagedPref(
394 prefs::kUptimeLimit,
395 new base::FundamentalValue(static_cast<int>(limit.InSeconds())));
397 task_runner_->RunUntilIdle();
398 EXPECT_EQ(expect_reboot ? 1 : 0,
399 power_manager_client_->num_request_restart_calls());
402 void AutomaticRebootManagerBasicTest::NotifyUpdateRebootNeeded() {
403 SetUpdateStatusNeedReboot();
404 automatic_reboot_manager_->UpdateStatusChanged(
405 update_engine_client_->GetLastStatus());
406 task_runner_->RunUntilIdle();
407 EXPECT_EQ(0, power_manager_client_->num_request_restart_calls());
410 void AutomaticRebootManagerBasicTest::NotifyResumed(bool expect_reboot) {
411 automatic_reboot_manager_->SuspendDone(base::TimeDelta::FromHours(1));
412 task_runner_->RunUntilIdle();
413 EXPECT_EQ(expect_reboot ? 1 : 0,
414 power_manager_client_->num_request_restart_calls());
417 void AutomaticRebootManagerBasicTest::NotifyTerminating(bool expect_reboot) {
418 automatic_reboot_manager_->Observe(
419 chrome::NOTIFICATION_APP_TERMINATING,
420 content::Source<AutomaticRebootManagerBasicTest>(this),
421 content::NotificationService::NoDetails());
422 task_runner_->RunUntilIdle();
423 EXPECT_EQ(expect_reboot ? 1 : 0,
424 power_manager_client_->num_request_restart_calls());
427 void AutomaticRebootManagerBasicTest::FastForwardBy(
428 const base::TimeDelta& delta,
429 bool expect_reboot) {
430 task_runner_->FastForwardBy(delta);
431 EXPECT_EQ(expect_reboot ? 1 : 0,
432 power_manager_client_->num_request_restart_calls());
435 void AutomaticRebootManagerBasicTest::FastForwardUntilNoTasksRemain(
436 bool expect_reboot) {
437 task_runner_->FastForwardUntilNoTasksRemain();
438 EXPECT_EQ(expect_reboot ? 1 : 0,
439 power_manager_client_->num_request_restart_calls());
442 void AutomaticRebootManagerBasicTest::ExpectRebootRequest(
443 AutomaticRebootManagerObserver::Reason reason) {
444 Mock::VerifyAndClearExpectations(&automatic_reboot_manager_observer_);
445 EXPECT_CALL(automatic_reboot_manager_observer_,
446 WillDestroyAutomaticRebootManager()).Times(0);
447 EXPECT_CALL(automatic_reboot_manager_observer_,
448 OnRebootRequested(_)).Times(0);
449 EXPECT_CALL(automatic_reboot_manager_observer_,
450 OnRebootRequested(reason)).Times(1);
453 void AutomaticRebootManagerBasicTest::ExpectNoRebootRequest() {
454 Mock::VerifyAndClearExpectations(&automatic_reboot_manager_observer_);
455 EXPECT_CALL(automatic_reboot_manager_observer_,
456 WillDestroyAutomaticRebootManager()).Times(0);
457 EXPECT_CALL(automatic_reboot_manager_observer_,
458 OnRebootRequested(_)).Times(0);
461 void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager(
462 bool expect_reboot) {
463 automatic_reboot_manager_.reset(new AutomaticRebootManager(
464 scoped_ptr<base::TickClock>(task_runner_->GetMockTickClock())));
465 automatic_reboot_manager_observer_.Init(automatic_reboot_manager_.get());
466 task_runner_->RunUntilIdle();
467 EXPECT_EQ(expect_reboot ? 1 : 0,
468 power_manager_client_->num_request_restart_calls());
470 uptime_processing_delay_ =
471 base::TimeTicks() - automatic_reboot_manager_->boot_time_ -
472 uptime_provider()->uptime();
473 EXPECT_GE(uptime_processing_delay_, base::TimeDelta());
474 EXPECT_LE(uptime_processing_delay_, base::TimeDelta::FromSeconds(1));
476 if (is_user_logged_in_ || expect_reboot)
477 VerifyLoginScreenIdleTimerIsStopped();
478 else
479 VerifyLoginScreenIdleTimerIsRunning();
482 bool AutomaticRebootManagerBasicTest::ReadUpdateRebootNeededUptimeFromFile(
483 base::TimeDelta* uptime) {
484 std::string contents;
485 if (!base::ReadFileToString(update_reboot_needed_uptime_file_, &contents)) {
486 return false;
488 double seconds;
489 if (!base::StringToDouble(contents.substr(0, contents.find(' ')), &seconds) ||
490 seconds < 0.0) {
491 return false;
493 *uptime = base::TimeDelta::FromMilliseconds(seconds * 1000.0);
494 return true;
497 void AutomaticRebootManagerBasicTest::VerifyRebootRequested(
498 AutomaticRebootManagerObserver::Reason reason) {
499 EXPECT_TRUE(automatic_reboot_manager_->reboot_requested());
500 EXPECT_EQ(reason, automatic_reboot_manager_->reboot_reason());
503 void AutomaticRebootManagerBasicTest::VerifyNoRebootRequested() const {
504 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested());
507 void AutomaticRebootManagerBasicTest::
508 VerifyLoginScreenIdleTimerIsStopped() const {
509 VerifyTimerIsStopped(
510 automatic_reboot_manager_->login_screen_idle_timer_.get());
513 void AutomaticRebootManagerBasicTest::VerifyNoGracePeriod() const {
514 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_);
515 VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get());
516 VerifyTimerIsStopped(automatic_reboot_manager_->grace_end_timer_.get());
519 void AutomaticRebootManagerBasicTest::VerifyGracePeriod(
520 const base::TimeDelta& start_uptime) const {
521 const base::TimeDelta start =
522 start_uptime - uptime_provider()->uptime() - uptime_processing_delay_;
523 const base::TimeDelta end = start + base::TimeDelta::FromHours(24);
524 if (start <= base::TimeDelta()) {
525 EXPECT_TRUE(automatic_reboot_manager_->reboot_requested_);
526 VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get());
527 VerifyTimerIsRunning(automatic_reboot_manager_->grace_end_timer_.get(),
528 end);
529 } else {
530 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_);
531 VerifyTimerIsRunning(automatic_reboot_manager_->grace_start_timer_.get(),
532 start);
533 VerifyTimerIsRunning(automatic_reboot_manager_->grace_end_timer_.get(),
534 end);
538 void AutomaticRebootManagerBasicTest::SetUpdateStatusNeedReboot() {
539 UpdateEngineClient::Status client_status;
540 client_status.status = UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT;
541 update_engine_client_->set_default_status(client_status);
544 void AutomaticRebootManagerBasicTest::VerifyTimerIsStopped(
545 const Timer* timer) const {
546 if (timer)
547 EXPECT_FALSE(timer->IsRunning());
550 void AutomaticRebootManagerBasicTest::VerifyTimerIsRunning(
551 const Timer* timer,
552 const base::TimeDelta& delay) const {
553 ASSERT_TRUE(timer);
554 EXPECT_TRUE(timer->IsRunning());
555 EXPECT_EQ(delay.ToInternalValue(),
556 timer->GetCurrentDelay().ToInternalValue());
559 void AutomaticRebootManagerBasicTest::
560 VerifyLoginScreenIdleTimerIsRunning() const {
561 VerifyTimerIsRunning(
562 automatic_reboot_manager_->login_screen_idle_timer_.get(),
563 base::TimeDelta::FromSeconds(60));
566 AutomaticRebootManagerTest::AutomaticRebootManagerTest() {
567 switch (GetParam()) {
568 case AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN:
569 is_user_logged_in_ = false;
570 is_logged_in_as_kiosk_app_ = false;
571 break;
572 case AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION:
573 is_user_logged_in_ = true;
574 is_logged_in_as_kiosk_app_ = true;
575 break;
576 case AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION:
577 is_user_logged_in_ = true;
578 is_logged_in_as_kiosk_app_ = false;
579 break;
583 AutomaticRebootManagerTest::~AutomaticRebootManagerTest() {
586 // Chrome is showing the login screen. The current uptime is 12 hours.
587 // Verifies that the idle timer is running. Further verifies that when a kiosk
588 // app session begins, the idle timer is stopped.
589 TEST_F(AutomaticRebootManagerBasicTest, LoginStopsIdleTimer) {
590 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
592 // Verify that no reboot is requested, the device does not reboot immediately
593 // and the login screen idle timer is started.
594 ExpectNoRebootRequest();
595 CreateAutomaticRebootManager(false);
596 VerifyNoRebootRequested();
598 // Notify that a kiosk app session has been started.
599 is_user_logged_in_ = true;
600 is_logged_in_as_kiosk_app_ = true;
601 automatic_reboot_manager_->Observe(
602 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
603 content::Source<AutomaticRebootManagerBasicTest>(this),
604 content::NotificationService::NoDetails());
606 // Verify that the login screen idle timer is stopped.
607 VerifyLoginScreenIdleTimerIsStopped();
609 // Verify that a reboot is never requested and the device never reboots.
610 FastForwardUntilNoTasksRemain(false);
613 // Chrome is showing the login screen. The current uptime is 12 hours.
614 // Verifies that the idle timer is running. Further verifies that when a
615 // non-kiosk-app session begins, the idle timer is stopped.
616 TEST_F(AutomaticRebootManagerBasicTest, NonKioskLoginStopsIdleTimer) {
617 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
619 // Verify that no reboot is requested, the device does not reboot immediately
620 // and the login screen idle timer is started.
621 ExpectNoRebootRequest();
622 CreateAutomaticRebootManager(false);
623 VerifyNoRebootRequested();
625 // Notify that a non-kiosk-app session has been started.
626 is_user_logged_in_ = true;
627 automatic_reboot_manager_->Observe(
628 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
629 content::Source<AutomaticRebootManagerBasicTest>(this),
630 content::NotificationService::NoDetails());
632 // Verify that the login screen idle timer is stopped.
633 VerifyLoginScreenIdleTimerIsStopped();
635 // Verify that a reboot is never requested and the device never reboots.
636 FastForwardUntilNoTasksRemain(false);
639 // Chrome is showing the login screen. The uptime limit is 6 hours. The current
640 // uptime is 12 hours.
641 // Verifies that user activity prevents the device from rebooting. Further
642 // verifies that when user activity ceases, the devices reboots.
643 TEST_F(AutomaticRebootManagerBasicTest, UserActivityResetsIdleTimer) {
644 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
646 // Verify that no reboot is requested, the device does not reboot immediately
647 // and the login screen idle timer is started.
648 ExpectNoRebootRequest();
649 CreateAutomaticRebootManager(false);
650 VerifyNoRebootRequested();
652 // Set the uptime limit. Verify that a reboot is requested but the device does
653 // not reboot immediately.
654 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
655 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
657 // Verify that a grace period has started.
658 VerifyGracePeriod(uptime_limit_);
660 // Fast forward the uptime by 25 minutes while simulating user activity every
661 // 50 seconds.
662 for (int i = 0; i < 30; ++i) {
663 // Fast forward uptime by 50 seconds. Verify that the device does not reboot
664 // immediately.
665 FastForwardBy(base::TimeDelta::FromSeconds(50), false);
667 // Simulate user activity.
668 automatic_reboot_manager_->OnUserActivity(NULL);
671 // Fast forward the uptime by 60 seconds without simulating user activity.
672 // Verify that the device reboots immediately.
673 FastForwardBy(base::TimeDelta::FromSeconds(60), true);
676 // Chrome is running a kiosk app session. The current uptime is 10 days.
677 // Verifies that when the device is suspended and then resumes, it does not
678 // immediately reboot.
679 TEST_F(AutomaticRebootManagerBasicTest, ResumeNoPolicy) {
680 is_user_logged_in_ = true;
681 is_logged_in_as_kiosk_app_ = true;
682 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
684 // Verify that no reboot is requested and the device does not reboot
685 // immediately.
686 ExpectNoRebootRequest();
687 CreateAutomaticRebootManager(false);
688 VerifyNoRebootRequested();
690 // Verify that no grace period has started.
691 VerifyNoGracePeriod();
693 // Notify that the device has resumed from 1 hour of sleep. Verify that no
694 // reboot is requested and the device does not reboot immediately.
695 NotifyResumed(false);
697 // Verify that a reboot is never requested and the device never reboots.
698 FastForwardUntilNoTasksRemain(false);
701 // Chrome is running a non-kiosk-app session. The current uptime is 10 days.
702 // Verifies that when the device is suspended and then resumes, it does not
703 // immediately reboot.
704 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAppNoPolicy) {
705 is_user_logged_in_ = true;
706 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
708 // Verify that no reboot is requested and the device does not reboot
709 // immediately.
710 ExpectNoRebootRequest();
711 CreateAutomaticRebootManager(false);
712 VerifyNoRebootRequested();
714 // Verify that no grace period has started.
715 VerifyNoGracePeriod();
717 // Notify that the device has resumed from 1 hour of sleep. Verify that no
718 // reboot is requested and the device does not reboot immediately.
719 NotifyResumed(false);
721 // Verify that a reboot is never requested and the device never reboots.
722 FastForwardUntilNoTasksRemain(false);
725 // Chrome is running a kiosk app session. The uptime limit is 24 hours. The
726 // current uptime is 12 hours.
727 // Verifies that when the device is suspended and then resumes, it does not
728 // immediately reboot.
729 TEST_F(AutomaticRebootManagerBasicTest, ResumeBeforeGracePeriod) {
730 is_user_logged_in_ = true;
731 is_logged_in_as_kiosk_app_ = true;
732 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
734 // Verify that no reboot is requested and the device does not reboot
735 // immediately.
736 ExpectNoRebootRequest();
737 CreateAutomaticRebootManager(false);
738 VerifyNoRebootRequested();
740 // Set the uptime limit. Verify that no reboot is requested and the device
741 // does not reboot immediately.
742 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
744 // Verify that a grace period has been scheduled to start in the future.
745 VerifyGracePeriod(uptime_limit_);
747 // Notify that the device has resumed from 1 hour of sleep. Verify that no
748 // reboot is requested and the device does not reboot immediately.
749 NotifyResumed(false);
751 // Verify a reboot is requested and the device reboots eventually.
752 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
753 FastForwardUntilNoTasksRemain(true);
756 // Chrome is running a non-kiosk-app session. The uptime limit is 24 hours. The
757 // current uptime is 12 hours.
758 // Verifies that when the device is suspended and then resumes, it does not
759 // immediately reboot.
760 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeBeforeGracePeriod) {
761 is_user_logged_in_ = true;
762 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
764 // Verify that no reboot is requested and the device does not reboot
765 // immediately.
766 ExpectNoRebootRequest();
767 CreateAutomaticRebootManager(false);
768 VerifyNoRebootRequested();
770 // Set the uptime limit. Verify that no reboot is requested and the device
771 // does not reboot immediately.
772 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
774 // Verify that a grace period has been scheduled to start in the future.
775 VerifyGracePeriod(uptime_limit_);
777 // Notify that the device has resumed from 1 hour of sleep. Verify that no
778 // reboot is requested and the device does not reboot immediately.
779 NotifyResumed(false);
781 // Verify that a reboot is requested eventually but the device never reboots.
782 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
783 FastForwardUntilNoTasksRemain(false);
786 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The
787 // current uptime is 12 hours.
788 // Verifies that when the device is suspended and then resumes, it immediately
789 // reboots.
790 TEST_F(AutomaticRebootManagerBasicTest, ResumeInGracePeriod) {
791 is_user_logged_in_ = true;
792 is_logged_in_as_kiosk_app_ = true;
793 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
795 // Verify that no reboot is requested and the device does not reboot
796 // immediately.
797 ExpectNoRebootRequest();
798 CreateAutomaticRebootManager(false);
799 VerifyNoRebootRequested();
801 // Set the uptime limit. Verify that a reboot is requested but the device does
802 // not reboot immediately.
803 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
804 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
806 // Verify that a grace period has started.
807 VerifyGracePeriod(uptime_limit_);
809 // Notify that the device has resumed from 1 hour of sleep. Verify that the
810 // device reboots immediately.
811 NotifyResumed(true);
814 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The
815 // current uptime is 12 hours.
816 // Verifies that when the device is suspended and then resumes, it does not
817 // immediately reboot.
818 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeInGracePeriod) {
819 is_user_logged_in_ = true;
820 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
822 // Verify that no reboot is requested and the device does not reboot
823 // immediately.
824 ExpectNoRebootRequest();
825 CreateAutomaticRebootManager(false);
826 VerifyNoRebootRequested();
828 // Set the uptime limit. Verify that a reboot is requested but the device does
829 // not reboot immediately.
830 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
831 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
833 // Verify that a grace period has started.
834 VerifyGracePeriod(uptime_limit_);
836 // Notify that the device has resumed from 1 hour of sleep. Verify that the
837 // device does not reboot immediately.
838 NotifyResumed(false);
840 // Verify that the device never reboots.
841 FastForwardUntilNoTasksRemain(false);
844 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The
845 // current uptime is 29 hours 30 minutes.
846 // Verifies that when the device is suspended and then resumes, it immediately
847 // reboots.
848 TEST_F(AutomaticRebootManagerBasicTest, ResumeAfterGracePeriod) {
849 is_user_logged_in_ = true;
850 is_logged_in_as_kiosk_app_ = true;
851 uptime_provider()->SetUptime(base::TimeDelta::FromHours(29) +
852 base::TimeDelta::FromMinutes(30));
854 // Verify that no reboot is requested and the device does not reboot
855 // immediately.
856 ExpectNoRebootRequest();
857 CreateAutomaticRebootManager(false);
858 VerifyNoRebootRequested();
860 // Set the uptime limit. Verify that a reboot is requested but the device does
861 // not reboot immediately.
862 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
863 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
865 // Verify that a grace period has started.
866 VerifyGracePeriod(uptime_limit_);
868 // Notify that the device has resumed from 1 hour of sleep. Verify that the
869 // device reboots immediately.
870 NotifyResumed(true);
873 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The
874 // current uptime is 29 hours 30 minutes.
875 // Verifies that when the device is suspended and then resumes, it does not
876 // immediately reboot.
877 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAfterGracePeriod) {
878 is_user_logged_in_ = true;
879 uptime_provider()->SetUptime(base::TimeDelta::FromHours(29) +
880 base::TimeDelta::FromMinutes(30));
882 // Verify that no reboot is requested and the device does not reboot
883 // immediately.
884 ExpectNoRebootRequest();
885 CreateAutomaticRebootManager(false);
886 VerifyNoRebootRequested();
888 // Set the uptime limit. Verify that a reboot is requested but the device does
889 // not reboot immediately.
890 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
891 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
893 // Verify that a grace period has started.
894 VerifyGracePeriod(uptime_limit_);
896 // Notify that the device has resumed from 1 hour of sleep. Verify that the
897 // device does not reboot immediately.
898 NotifyResumed(false);
900 // Verify that the device never reboots.
901 FastForwardUntilNoTasksRemain(false);
904 // Chrome is running. The current uptime is 10 days.
905 // Verifies that when the browser terminates, the device does not immediately
906 // reboot.
907 TEST_P(AutomaticRebootManagerTest, TerminateNoPolicy) {
908 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
910 // Verify that no reboot is requested and the device does not reboot
911 // immediately.
912 ExpectNoRebootRequest();
913 CreateAutomaticRebootManager(false);
914 VerifyNoRebootRequested();
916 // Verify that no grace period has started.
917 VerifyNoGracePeriod();
919 // Notify that the browser is terminating. Verify that no reboot is requested
920 // and the device does not reboot immediately.
921 NotifyTerminating(false);
923 // Verify that a reboot is never requested and the device never reboots.
924 FastForwardUntilNoTasksRemain(false);
927 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is
928 // 12 hours.
929 // Verifies that when the browser terminates, it does not immediately reboot.
930 TEST_P(AutomaticRebootManagerTest, TerminateBeforeGracePeriod) {
931 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
933 // Verify that no reboot is requested and the device does not reboot
934 // immediately.
935 ExpectNoRebootRequest();
936 CreateAutomaticRebootManager(false);
937 VerifyNoRebootRequested();
939 // Set the uptime limit. Verify that no reboot is requested and the device
940 // does not reboot immediately.
941 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
943 // Verify that a grace period has been scheduled to start in the future.
944 VerifyGracePeriod(uptime_limit_);
946 // Notify that the browser is terminating. Verify that no reboot is requested
947 // and the device does not reboot immediately.
948 NotifyTerminating(false);
950 // Verify that a reboot is requested eventually and unless a non-kiosk-app
951 // session is in progress, the device eventually reboots.
952 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
953 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
954 is_logged_in_as_kiosk_app_);
957 // Chrome is running. The uptime limit is set to 6 hours. The current uptime is
958 // 12 hours.
959 // Verifies that when the browser terminates, the device immediately reboots if
960 // a kiosk app session is in progress.
961 TEST_P(AutomaticRebootManagerTest, TerminateInGracePeriod) {
962 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
964 // Verify that no reboot is requested and the device does not reboot
965 // immediately.
966 ExpectNoRebootRequest();
967 CreateAutomaticRebootManager(false);
968 VerifyNoRebootRequested();
970 // Set the uptime limit. Verify that a reboot is requested but the device does
971 // not reboot immediately.
972 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
973 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
975 // Verify that a grace period has started.
976 VerifyGracePeriod(uptime_limit_);
978 // Notify that the browser is terminating. Verify that the device immediately
979 // reboots if a kiosk app session is in progress.
980 NotifyTerminating(is_logged_in_as_kiosk_app_);
982 // Verify that if a non-kiosk-app session is in progress, the device never
983 // reboots.
984 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
985 is_logged_in_as_kiosk_app_);
988 // Chrome is running. The current uptime is 12 hours.
989 // Verifies that when the uptime limit is set to 24 hours, no reboot occurs and
990 // a grace period is scheduled to begin after 24 hours of uptime.
991 TEST_P(AutomaticRebootManagerTest, BeforeUptimeLimitGracePeriod) {
992 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
994 // Verify that no reboot is requested and the device does not reboot
995 // immediately.
996 ExpectNoRebootRequest();
997 CreateAutomaticRebootManager(false);
998 VerifyNoRebootRequested();
1000 // Verify that no grace period has started.
1001 VerifyNoGracePeriod();
1003 // Set the uptime limit. Verify that no reboot is requested and the device
1004 // does not reboot immediately.
1005 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1007 // Verify that a grace period has been scheduled to start in the future.
1008 VerifyGracePeriod(uptime_limit_);
1010 // Verify that a reboot is requested eventually and unless a non-kiosk-app
1011 // session is in progress, the device eventually reboots.
1012 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1013 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1014 is_logged_in_as_kiosk_app_);
1017 // Chrome is running. The current uptime is 12 hours.
1018 // Verifies that when the uptime limit is set to 6 hours, a reboot is requested
1019 // and a grace period is started that will end after 6 + 24 hours of uptime.
1020 TEST_P(AutomaticRebootManagerTest, InUptimeLimitGracePeriod) {
1021 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1023 // Verify that no reboot is requested and the device does not reboot
1024 // immediately.
1025 ExpectNoRebootRequest();
1026 CreateAutomaticRebootManager(false);
1027 VerifyNoRebootRequested();
1029 // Verify that no grace period has started.
1030 VerifyNoGracePeriod();
1032 // Set the uptime limit. Verify that a reboot is requested but the device does
1033 // not reboot immediately.
1034 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1035 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1037 // Verify that a grace period has started.
1038 VerifyGracePeriod(uptime_limit_);
1040 // Verify that unless a non-kiosk-app session is in progress, the device
1041 // eventually reboots.
1042 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1043 is_logged_in_as_kiosk_app_);
1046 // Chrome is running. The current uptime is 10 days.
1047 // Verifies that when the uptime limit is set to 6 hours, the device reboots
1048 // immediately if no non-kiosk-app-session is in progress because the grace
1049 // period ended after 6 + 24 hours of uptime.
1050 TEST_P(AutomaticRebootManagerTest, AfterUptimeLimitGracePeriod) {
1051 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
1053 // Verify that no reboot is requested and the device does not reboot
1054 // immediately.
1055 ExpectNoRebootRequest();
1056 CreateAutomaticRebootManager(false);
1057 VerifyNoRebootRequested();
1059 // Verify that no grace period has started.
1060 VerifyNoGracePeriod();
1062 // Set the uptime limit. Verify that a reboot is requested and unless a
1063 // non-kiosk-app session is in progress, the the device immediately reboots.
1064 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1065 SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ ||
1066 is_logged_in_as_kiosk_app_);
1068 // Verify that if a non-kiosk-app session is in progress, the device never
1069 // reboots.
1070 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1071 is_logged_in_as_kiosk_app_);
1074 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
1075 // 6 hours.
1076 // Verifies that when the uptime limit is removed, the grace period is removed.
1077 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffBeforeGracePeriod) {
1078 uptime_provider()->SetUptime(base::TimeDelta::FromHours(6));
1080 // Verify that no reboot is requested and the device does not reboot
1081 // immediately.
1082 ExpectNoRebootRequest();
1083 CreateAutomaticRebootManager(false);
1084 VerifyNoRebootRequested();
1086 // Set the uptime limit. Verify that no reboot is requested and the device
1087 // does not reboot immediately.
1088 SetUptimeLimit(base::TimeDelta::FromHours(12), false);
1090 // Verify that a grace period has been scheduled to start in the future.
1091 VerifyGracePeriod(uptime_limit_);
1093 // Fast forward the uptime by 1 hour. Verify that no reboot is requested and
1094 // the device does not reboot immediately.
1095 FastForwardBy(base::TimeDelta::FromHours(1), false);
1097 // Remove the uptime limit. Verify that no reboot is requested and the device
1098 // does not reboot immediately.
1099 SetUptimeLimit(base::TimeDelta(), false);
1101 // Verify that the grace period has been removed.
1102 VerifyNoGracePeriod();
1104 // Verify that a reboot is never requested and the device never reboots.
1105 FastForwardUntilNoTasksRemain(false);
1108 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
1109 // 24 hours.
1110 // Verifies that when the uptime limit is removed, the grace period is removed.
1111 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffInGracePeriod) {
1112 uptime_provider()->SetUptime(base::TimeDelta::FromHours(24));
1114 // Verify that no reboot is requested and the device does not reboot
1115 // immediately.
1116 ExpectNoRebootRequest();
1117 CreateAutomaticRebootManager(false);
1118 VerifyNoRebootRequested();
1120 // Set the uptime limit. Verify that a reboot is requested but the device does
1121 // not reboot immediately.
1122 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1123 SetUptimeLimit(base::TimeDelta::FromHours(12), false);
1125 // Verify that a grace period has started.
1126 VerifyGracePeriod(uptime_limit_);
1128 // Fast forward the uptime by 20 seconds. Verify that the device does not
1129 // reboot immediately.
1130 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1132 // Remove the uptime limit. Verify that the device does not reboot
1133 // immediately.
1134 SetUptimeLimit(base::TimeDelta(), false);
1136 // Verify that the grace period has been removed.
1137 VerifyNoGracePeriod();
1139 // Verify that the device never reboots.
1140 FastForwardUntilNoTasksRemain(false);
1143 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
1144 // 6 hours.
1145 // Verifies that when the uptime limit is extended to 24 hours, the grace period
1146 // is rescheduled to start further in the future.
1147 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitBeforeGracePeriod) {
1148 uptime_provider()->SetUptime(base::TimeDelta::FromHours(6));
1150 // Verify that no reboot is requested and the device does not reboot
1151 // immediately.
1152 ExpectNoRebootRequest();
1153 CreateAutomaticRebootManager(false);
1154 VerifyNoRebootRequested();
1156 // Set the uptime limit. Verify that no reboot is requested and the device
1157 // does not reboot immediately.
1158 SetUptimeLimit(base::TimeDelta::FromHours(12), false);
1160 // Verify that a grace period has been scheduled to start in the future.
1161 VerifyGracePeriod(uptime_limit_);
1163 // Fast forward the uptime by 20 seconds. Verify that no reboot is requested
1164 // and the device does not reboot immediately.
1165 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1167 // Extend the uptime limit. Verify that no reboot is requested and the device
1168 // does not reboot immediately.
1169 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1171 // Verify that the grace period has been rescheduled to start further in the
1172 // future.
1173 VerifyGracePeriod(uptime_limit_);
1175 // Verify that a reboot is requested eventually and unless a non-kiosk-app
1176 // session is in progress, the device eventually reboots.
1177 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1178 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1179 is_logged_in_as_kiosk_app_);
1182 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
1183 // 18 hours.
1184 // Verifies that when the uptime limit is extended to 24 hours, the grace period
1185 // is rescheduled to start in the future.
1186 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitInGracePeriod) {
1187 uptime_provider()->SetUptime(base::TimeDelta::FromHours(18));
1189 // Verify that no reboot is requested and the device does not reboot
1190 // immediately.
1191 ExpectNoRebootRequest();
1192 CreateAutomaticRebootManager(false);
1193 VerifyNoRebootRequested();
1195 // Set the uptime limit. Verify that a reboot is requested but the device does
1196 // not reboot immediately.
1197 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1198 SetUptimeLimit(base::TimeDelta::FromHours(12), false);
1200 // Verify that a grace period has started.
1201 VerifyGracePeriod(uptime_limit_);
1203 // Fast forward the uptime by 20 seconds. Verify that the device does not
1204 // reboot immediately.
1205 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1207 // Extend the uptime limit. Verify that the device does not reboot
1208 // immediately.
1209 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1211 // Verify that the grace period has been rescheduled to start in the future.
1212 VerifyGracePeriod(uptime_limit_);
1214 // Verify that a reboot is requested again eventually and unless a
1215 // non-kiosk-app session is in progress, the device eventually reboots.
1216 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1217 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1218 is_logged_in_as_kiosk_app_);
1221 // Chrome is running. The uptime limit is set to 18 hours. The current uptime is
1222 // 12 hours.
1223 // Verifies that when the uptime limit is shortened to 6 hours, the grace period
1224 // is rescheduled to have already started.
1225 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitBeforeToInGracePeriod) {
1226 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1228 // Verify that no reboot is requested and the device does not reboot
1229 // immediately.
1230 ExpectNoRebootRequest();
1231 CreateAutomaticRebootManager(false);
1232 VerifyNoRebootRequested();
1234 // Set the uptime limit. Verify that no reboot is requested and the device
1235 // does not reboot immediately.
1236 SetUptimeLimit(base::TimeDelta::FromHours(18), false);
1238 // Verify that a grace period has been scheduled to start in the future.
1239 VerifyGracePeriod(uptime_limit_);
1241 // Fast forward the uptime by 20 seconds. Verify that no reboot is requested
1242 // and the device does not reboot immediately.
1243 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1245 // Shorten the uptime limit. Verify that a reboot is requested but the device
1246 // does not reboot immediately.
1247 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1248 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1250 // Verify that the grace period has been rescheduled and has started already.
1251 VerifyGracePeriod(uptime_limit_);
1253 // Verify that unless a non-kiosk-app session is in progress, the device
1254 // eventually reboots.
1255 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1256 is_logged_in_as_kiosk_app_);
1259 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is
1260 // 36 hours.
1261 // Verifies that when the uptime limit is shortened to 18 hours, the grace
1262 // period is rescheduled to have started earlier.
1263 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToInGracePeriod) {
1264 uptime_provider()->SetUptime(base::TimeDelta::FromHours(36));
1266 // Verify that no reboot is requested and the device does not reboot
1267 // immediately.
1268 ExpectNoRebootRequest();
1269 CreateAutomaticRebootManager(false);
1270 VerifyNoRebootRequested();
1272 // Set the uptime limit. Verify that a reboot is requested but the device does
1273 // not reboot immediately.
1274 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1275 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1277 // Verify that a grace period has started.
1278 VerifyGracePeriod(uptime_limit_);
1280 // Fast forward the uptime by 20 seconds. Verify that the device does not
1281 // reboot immediately.
1282 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1284 // Shorten the uptime limit. Verify that a reboot is requested again but the
1285 // device does not reboot immediately.
1286 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1287 SetUptimeLimit(base::TimeDelta::FromHours(18), false);
1289 // Verify that the grace period has been rescheduled to have started earlier.
1290 VerifyGracePeriod(uptime_limit_);
1292 // Verify that unless a non-kiosk-app session is in progress, the device
1293 // eventually reboots.
1294 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1295 is_logged_in_as_kiosk_app_);
1298 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is
1299 // 36 hours.
1300 // Verifies that when the uptime limit is shortened to 6 hours, the device
1301 // reboots immediately if no non-kiosk-app session is in progress because the
1302 // grace period ended after 6 + 24 hours of uptime.
1303 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToAfterGracePeriod) {
1304 uptime_provider()->SetUptime(base::TimeDelta::FromHours(36));
1306 // Verify that no reboot is requested and the device does not reboot
1307 // immediately.
1308 ExpectNoRebootRequest();
1309 CreateAutomaticRebootManager(false);
1310 VerifyNoRebootRequested();
1312 // Set the uptime limit. Verify that a reboot is requested but the device does
1313 // not reboot immediately.
1314 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1315 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1317 // Verify that a grace period has started.
1318 VerifyGracePeriod(uptime_limit_);
1320 // Fast forward the uptime by 20 seconds. Verify that the device does not
1321 // reboot immediately.
1322 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1324 // Shorten the uptime limit. Verify that a reboot is requested again and
1325 // unless a non-kiosk-app session is in progress, the the device immediately
1326 // reboots.
1327 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1328 SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ ||
1329 is_logged_in_as_kiosk_app_);
1331 // Verify that if a non-kiosk-app session is in progress, the device never
1332 // reboots.
1333 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1334 is_logged_in_as_kiosk_app_);
1337 // Chrome is running. The current uptime is 12 hours.
1338 // Verifies that when an update is applied, the current uptime is persisted as
1339 // the time at which a reboot became necessary. Further verifies that when the
1340 // policy to automatically reboot after an update is not enabled, no reboot
1341 // occurs and no grace period is scheduled.
1342 TEST_P(AutomaticRebootManagerTest, UpdateNoPolicy) {
1343 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1345 // Verify that no reboot is requested and the device does not reboot
1346 // immediately.
1347 ExpectNoRebootRequest();
1348 CreateAutomaticRebootManager(false);
1349 VerifyNoRebootRequested();
1351 // Verify that no grace period has started.
1352 VerifyNoGracePeriod();
1354 // Notify that an update has been applied and a reboot is necessary. Verify
1355 // that no reboot is requested and the device does not reboot immediately.
1356 NotifyUpdateRebootNeeded();
1358 // Verify that the current uptime has been persisted as the time at which a
1359 // reboot became necessary.
1360 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1361 &update_reboot_needed_uptime_));
1362 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1364 // Verify that no grace period has started.
1365 VerifyNoGracePeriod();
1367 // Verify that a reboot is never requested and the device never reboots.
1368 FastForwardUntilNoTasksRemain(false);
1371 // Chrome is running. The current uptime is 12 hours.
1372 // Verifies that when an update is applied, the current uptime is persisted as
1373 // the time at which a reboot became necessary. Further verifies that when the
1374 // policy to automatically reboot after an update is enabled, a reboot is
1375 // requested and a grace period is started that will end 24 hours from now.
1376 TEST_P(AutomaticRebootManagerTest, Update) {
1377 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1378 SetRebootAfterUpdate(true, false);
1380 // Verify that no reboot is requested and the device does not reboot
1381 // immediately.
1382 ExpectNoRebootRequest();
1383 CreateAutomaticRebootManager(false);
1384 VerifyNoRebootRequested();
1386 // Verify that no grace period has started.
1387 VerifyNoGracePeriod();
1389 // Notify that an update has been applied and a reboot is necessary. Verify
1390 // that a reboot is requested but the device does not reboot immediately.
1391 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1392 NotifyUpdateRebootNeeded();
1394 // Verify that the current uptime has been persisted as the time at which a
1395 // reboot became necessary.
1396 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1397 &update_reboot_needed_uptime_));
1398 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1400 // Verify that a grace period has started.
1401 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1403 // Verify that unless a non-kiosk-app session is in progress, the device
1404 // eventually reboots.
1405 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1406 is_logged_in_as_kiosk_app_);
1409 // Chrome is running. The current uptime is 12 hours.
1410 // Verifies that when Chrome is notified twice that an update has been applied,
1411 // the second notification is ignored and the uptime at which it occurred does
1412 // not get persisted as the time at which an update became necessary.
1413 TEST_P(AutomaticRebootManagerTest, UpdateAfterUpdate) {
1414 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1415 SetRebootAfterUpdate(true, false);
1417 // Verify that no reboot is requested and the device does not reboot
1418 // immediately.
1419 ExpectNoRebootRequest();
1420 CreateAutomaticRebootManager(false);
1421 VerifyNoRebootRequested();
1423 // Verify that no grace period has started.
1424 VerifyNoGracePeriod();
1426 // Notify that an update has been applied and a reboot is necessary. Verify
1427 // that a reboot is requested but the device does not reboot immediately.
1428 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1429 NotifyUpdateRebootNeeded();
1431 // Verify that the current uptime has been persisted as the time at which a
1432 // reboot became necessary.
1433 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1434 &update_reboot_needed_uptime_));
1435 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1437 // Verify that a grace period has started.
1438 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1440 // Fast forward the uptime by 20 seconds. Verify that the device does not
1441 // reboot immediately.
1442 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1444 // Notify that an update has been applied and a reboot is necessary. Verify
1445 // that the device does not reboot immediately.
1446 NotifyUpdateRebootNeeded();
1448 // Verify that the previously persisted time at which a reboot became
1449 // necessary has not been overwritten.
1450 base::TimeDelta new_update_reboot_needed_uptime;
1451 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1452 &new_update_reboot_needed_uptime));
1453 EXPECT_EQ(update_reboot_needed_uptime_, new_update_reboot_needed_uptime);
1455 // Verify that unless a non-kiosk-app session is in progress, the device
1456 // eventually reboots.
1457 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1458 is_logged_in_as_kiosk_app_);
1461 // Chrome is running. The current uptime is 10 minutes.
1462 // Verifies that when the policy to automatically reboot after an update is
1463 // enabled, no reboot occurs and a grace period is scheduled to begin after the
1464 // minimum of 1 hour of uptime. Further verifies that when an update is applied,
1465 // the current uptime is persisted as the time at which a reboot became
1466 // necessary.
1467 TEST_P(AutomaticRebootManagerTest, UpdateBeforeMinimumUptime) {
1468 uptime_provider()->SetUptime(base::TimeDelta::FromMinutes(10));
1469 SetRebootAfterUpdate(true, false);
1471 // Verify that no reboot is requested and the device does not reboot
1472 // immediately.
1473 ExpectNoRebootRequest();
1474 CreateAutomaticRebootManager(false);
1475 VerifyNoRebootRequested();
1477 // Verify that no grace period has started.
1478 VerifyNoGracePeriod();
1480 // Notify that an update has been applied and a reboot is necessary. Verify
1481 // that no reboot is requested and the device does not reboot immediately.
1482 NotifyUpdateRebootNeeded();
1484 // Verify that the current uptime has been persisted as the time at which a
1485 // reboot became necessary.
1486 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1487 &update_reboot_needed_uptime_));
1488 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1490 // Verify that a grace period has been scheduled to begin in the future.
1491 VerifyGracePeriod(base::TimeDelta::FromHours(1));
1493 // Verify that a reboot is requested eventually and unless a non-kiosk-app
1494 // session is in progress, the device eventually reboots.
1495 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1496 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1497 is_logged_in_as_kiosk_app_);
1500 // Chrome is running. An update was applied and a reboot became necessary to
1501 // complete the update process after 6 hours of uptime. The current uptime is
1502 // 12 hours.
1503 // Verifies that when the policy to automatically reboot after an update is
1504 // enabled, a reboot is requested and a grace period is started that will end
1505 // after 6 + 24 hours of uptime.
1506 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateInGracePeriod) {
1507 uptime_provider()->SetUptime(base::TimeDelta::FromHours(6));
1509 // Verify that no reboot is requested and the device does not reboot
1510 // immediately.
1511 ExpectNoRebootRequest();
1512 CreateAutomaticRebootManager(false);
1513 VerifyNoRebootRequested();
1515 // Notify that an update has been applied and a reboot is necessary. Verify
1516 // that no reboot is requested and the device does not reboot immediately.
1517 NotifyUpdateRebootNeeded();
1519 // Fast forward the uptime to 12 hours. Verify that no reboot is requested and
1520 // the device does not reboot immediately.
1521 FastForwardBy(base::TimeDelta::FromHours(6), false);
1523 // Simulate user activity.
1524 automatic_reboot_manager_->OnUserActivity(NULL);
1526 // Enable automatic reboot after an update has been applied. Verify that a
1527 // reboot is requested but the device does not reboot immediately.
1528 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1529 SetRebootAfterUpdate(true, false);
1531 // Verify that a grace period has started.
1532 VerifyGracePeriod(base::TimeDelta::FromHours(6) + uptime_processing_delay_);
1534 // Verify that unless a non-kiosk-app session is in progress, the device
1535 // eventually reboots.
1536 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1537 is_logged_in_as_kiosk_app_);
1540 // Chrome is running. An update was applied and a reboot became necessary to
1541 // complete the update process after 6 hours of uptime. The current uptime is
1542 // 10 days.
1543 // Verifies that when the policy to automatically reboot after an update is
1544 // enabled, the device reboots immediately if no non-kiosk-app session is in
1545 // progress because the grace period ended after 6 + 24 hours of uptime.
1546 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateAfterGracePeriod) {
1547 uptime_provider()->SetUptime(base::TimeDelta::FromHours(6));
1549 // Verify that no reboot is requested and the device does not reboot
1550 // immediately.
1551 ExpectNoRebootRequest();
1552 CreateAutomaticRebootManager(false);
1553 VerifyNoRebootRequested();
1555 // Notify that an update has been applied and a reboot is necessary. Verify
1556 // that no reboot is requested and the device does not reboot immediately.
1557 NotifyUpdateRebootNeeded();
1559 // Fast forward the uptime to 12 hours. Verify that no reboot is requested and
1560 // the device does not reboot immediately.
1561 FastForwardBy(base::TimeDelta::FromDays(10) - base::TimeDelta::FromHours(6),
1562 false);
1564 // Simulate user activity.
1565 automatic_reboot_manager_->OnUserActivity(NULL);
1567 // Enable automatic rebooting after an update has been applied. Verify that
1568 // a reboot is requested and unless a non-kiosk-app session is in progress,
1569 // the the device immediately reboots.
1570 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1571 SetRebootAfterUpdate(true, !is_user_logged_in_ || is_logged_in_as_kiosk_app_);
1573 // Verify that if a non-kiosk-app session is in progress, the device never
1574 // reboots.
1575 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1576 is_logged_in_as_kiosk_app_);
1579 // Chrome is running. An update was applied and a reboot became necessary to
1580 // complete the update process after 6 hours of uptime. The policy to
1581 // automatically reboot after an update is enabled. The current uptime is
1582 // 6 hours 20 seconds.
1583 // Verifies that when the policy to automatically reboot after an update is
1584 // disabled, the reboot request and grace period are removed.
1585 TEST_P(AutomaticRebootManagerTest, PolicyOffAfterUpdate) {
1586 uptime_provider()->SetUptime(base::TimeDelta::FromHours(6));
1587 SetRebootAfterUpdate(true, false);
1589 // Verify that no reboot is requested and the device does not reboot
1590 // immediately.
1591 ExpectNoRebootRequest();
1592 CreateAutomaticRebootManager(false);
1593 VerifyNoRebootRequested();
1595 // Notify that an update has been applied and a reboot is necessary. Verify
1596 // that a reboot is requested but the device does not reboot immediately.
1597 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1598 NotifyUpdateRebootNeeded();
1600 // Verify that a grace period has started.
1601 VerifyGracePeriod(uptime_provider()->uptime() + uptime_processing_delay_);
1603 // Fast forward the uptime by 20 seconds. Verify that the device does not
1604 // reboot immediately.
1605 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1607 // Disable automatic rebooting after an update has been applied. Verify that
1608 // no reboot is requested and the device does not reboot immediately.
1609 SetRebootAfterUpdate(false, false);
1611 // Verify that the grace period has been removed.
1612 VerifyNoGracePeriod();
1614 // Verify that the device never reboots.
1615 FastForwardUntilNoTasksRemain(false);
1618 // Chrome is running. The current uptime is not available.
1619 // Verifies that even if an uptime limit is set, the policy to automatically
1620 // reboot after an update is enabled and an update has been applied, no reboot
1621 // occurs and no grace period is scheduled. Further verifies that no time is
1622 // persisted as the time at which a reboot became necessary.
1623 TEST_P(AutomaticRebootManagerTest, NoUptime) {
1624 // Verify that no reboot is requested and the device does not reboot
1625 // immediately.
1626 ExpectNoRebootRequest();
1627 CreateAutomaticRebootManager(false);
1628 VerifyNoRebootRequested();
1630 // Set the uptime limit. Verify that no reboot is requested and the device
1631 // does not reboot immediately.
1632 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1634 // Verify that no grace period has started.
1635 VerifyNoGracePeriod();
1637 // Enable automatic rebooting after an update has been applied. Verify that
1638 // no reboot is requested and the device does not reboot immediately.
1639 SetRebootAfterUpdate(true, false);
1641 // Verify that no grace period has started.
1642 VerifyNoGracePeriod();
1644 // Notify that an update has been applied and a reboot is necessary. Verify
1645 // that no reboot is requested and the device does not reboot immediately.
1646 NotifyUpdateRebootNeeded();
1648 // Verify that no time is persisted as the time at which a reboot became
1649 // necessary.
1650 EXPECT_FALSE(ReadUpdateRebootNeededUptimeFromFile(
1651 &update_reboot_needed_uptime_));
1653 // Verify that no grace period has started.
1654 VerifyNoGracePeriod();
1656 // Verify that a reboot is never requested and the device never reboots.
1657 FastForwardUntilNoTasksRemain(false);
1660 // Chrome is running. The policy to automatically reboot after an update is
1661 // enabled. The current uptime is 12 hours.
1662 // Verifies that when an uptime limit of 6 hours is set, the availability of an
1663 // update does not cause the grace period to be rescheduled. Further verifies
1664 // that the current uptime is persisted as the time at which a reboot became
1665 // necessary.
1666 TEST_P(AutomaticRebootManagerTest, UptimeLimitBeforeUpdate) {
1667 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1668 SetRebootAfterUpdate(true, false);
1670 // Verify that no reboot is requested and the device does not reboot
1671 // immediately.
1672 ExpectNoRebootRequest();
1673 CreateAutomaticRebootManager(false);
1674 VerifyNoRebootRequested();
1676 // Set the uptime limit. Verify that a reboot is requested but the device does
1677 // not reboot immediately.
1678 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1679 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1681 // Verify that a grace period has been scheduled to start in the future.
1682 VerifyGracePeriod(uptime_limit_);
1684 // Fast forward the uptime by 20 seconds. Verify that the device does not
1685 // reboot immediately.
1686 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1688 // Notify that an update has been applied and a reboot is necessary. Verify
1689 // that a reboot is requested again but the device does not reboot
1690 // immediately.
1691 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1692 NotifyUpdateRebootNeeded();
1694 // Verify that the current uptime has been persisted as the time at which a
1695 // reboot became necessary.
1696 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1697 &update_reboot_needed_uptime_));
1698 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1700 // Verify that the grace period has not been rescheduled.
1701 VerifyGracePeriod(uptime_limit_);
1703 // Verify that unless a non-kiosk-app session is in progress, the device
1704 // eventually reboots.
1705 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1706 is_logged_in_as_kiosk_app_);
1709 // Chrome is running. The policy to automatically reboot after an update is
1710 // enabled. The current uptime is 12 hours.
1711 // Verifies that when an uptime limit of 24 hours is set, the availability of an
1712 // update causes the grace period to be rescheduled so that it ends 24 hours
1713 // from now. Further verifies that the current uptime is persisted as the time
1714 // at which a reboot became necessary.
1715 TEST_P(AutomaticRebootManagerTest, UpdateBeforeUptimeLimit) {
1716 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1717 SetRebootAfterUpdate(true, false);
1719 // Verify that no reboot is requested and the device does not reboot
1720 // immediately.
1721 ExpectNoRebootRequest();
1722 CreateAutomaticRebootManager(false);
1723 VerifyNoRebootRequested();
1725 // Set the uptime limit. Verify that no reboot is requested and the device
1726 // does not reboot immediately.
1727 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1729 // Verify that a grace period has been scheduled to start in the future.
1730 VerifyGracePeriod(uptime_limit_);
1732 // Fast forward the uptime by 20 seconds. Verify that no reboot is requested
1733 // and the device does not reboot immediately.
1734 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1736 // Notify that an update has been applied and a reboot is necessary. Verify
1737 // that a reboot is requested but the device does not reboot immediately.
1738 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1739 NotifyUpdateRebootNeeded();
1741 // Verify that the current uptime has been persisted as the time at which a
1742 // reboot became necessary.
1743 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1744 &update_reboot_needed_uptime_));
1745 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1747 // Verify that the grace period has been rescheduled to start at the time that
1748 // the update became available.
1749 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1751 // Verify that unless a non-kiosk-app session is in progress, the device
1752 // eventually reboots.
1753 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1754 is_logged_in_as_kiosk_app_);
1757 // Chrome is running. The uptime limit is set to 24 hours. An update was applied
1758 // and a reboot became necessary to complete the update process after 12 hours.
1759 // The policy to automatically reboot after an update is enabled. The current
1760 // uptime is 12 hours 20 seconds.
1761 // Verifies that when the policy to reboot after an update is disabled, the
1762 // grace period is rescheduled to start after 12 hours of uptime. Further
1763 // verifies that when the uptime limit is removed, the grace period is removed.
1764 TEST_P(AutomaticRebootManagerTest, PolicyOffThenUptimeLimitOff) {
1765 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1766 SetRebootAfterUpdate(true, false);
1768 // Verify that no reboot is requested and the device does not reboot
1769 // immediately.
1770 ExpectNoRebootRequest();
1771 CreateAutomaticRebootManager(false);
1772 VerifyNoRebootRequested();
1774 // Set the uptime limit. Verify that no reboot is requested and the device
1775 // does not reboot immediately.
1776 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1778 // Verify that a grace period has been scheduled to start in the future.
1779 VerifyGracePeriod(uptime_limit_);
1781 // Notify that an update has been applied and a reboot is necessary. Verify
1782 // that a reboot is requested but the device does not reboot immediately.
1783 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1784 NotifyUpdateRebootNeeded();
1786 // Verify that the current uptime has been persisted as the time at which a
1787 // reboot became necessary.
1788 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1789 &update_reboot_needed_uptime_));
1790 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1792 // Verify that a grace period has been rescheduled to end 24 hours from now.
1793 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1795 // Fast forward the uptime by 20 seconds. Verify that the device does not
1796 // reboot immediately.
1797 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1799 // Disable automatic reboot after an update has been applied. Verify that the
1800 // device does not reboot immediately.
1801 SetRebootAfterUpdate(false, false);
1803 // Verify that the grace period has been rescheduled to start after 24 hours
1804 // of uptime.
1805 VerifyGracePeriod(uptime_limit_);
1807 // Remove the uptime limit. Verify that the device does not reboot
1808 // immediately.
1809 SetUptimeLimit(base::TimeDelta(), false);
1811 // Verify that the grace period has been removed.
1812 VerifyNoGracePeriod();
1814 // Verify that the device never reboots.
1815 FastForwardUntilNoTasksRemain(false);
1818 // Chrome is running. The uptime limit is set to 6 hours. An update was applied
1819 // and a reboot became necessary to complete the update process after 12 hours.
1820 // The policy to automatically reboot after an update is enabled. The current
1821 // uptime is 12 hours 20 seconds.
1822 // Verifies that when the uptime limit is removed, the grace period is
1823 // rescheduled to have started after 12 hours of uptime. Further verifies that
1824 // when the policy to reboot after an update is disabled, the reboot request and
1825 // grace period are removed.
1826 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffThenPolicyOff) {
1827 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1828 SetRebootAfterUpdate(true, false);
1830 // Verify that no reboot is requested and the device does not reboot
1831 // immediately.
1832 ExpectNoRebootRequest();
1833 CreateAutomaticRebootManager(false);
1834 VerifyNoRebootRequested();
1836 // Notify that an update has been applied and a reboot is necessary. Verify
1837 // that a reboot is requested but the device does not reboot immediately.
1838 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1839 NotifyUpdateRebootNeeded();
1841 // Verify that the current uptime has been persisted as the time at which a
1842 // reboot became necessary.
1843 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1844 &update_reboot_needed_uptime_));
1845 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1847 // Verify that the grace period has started.
1848 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1850 // Set the uptime limit. Verify that a reboot is requested again but the
1851 // device does not reboot immediately.
1852 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1853 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1855 // Verify that the grace period has been rescheduled to have started after
1856 // 6 hours of uptime.
1857 VerifyGracePeriod(uptime_limit_);
1859 // Fast forward the uptime by 20 seconds. Verify that the device does not
1860 // reboot immediately.
1861 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1863 // Remove the uptime limit. Verify that a reboot is requested again but the
1864 // device does not reboot immediately.
1865 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1866 SetUptimeLimit(base::TimeDelta(), false);
1868 // Verify that a grace period has been rescheduled to have started after 12
1869 // hours of uptime.
1870 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1872 // Disable automatic reboot after an update has been applied. Verify that the
1873 // device does not reboot immediately.
1874 SetRebootAfterUpdate(false, false);
1876 // Verify that the grace period has been removed.
1877 VerifyNoGracePeriod();
1879 // Verify that the device never reboots.
1880 FastForwardUntilNoTasksRemain(false);
1883 // Chrome is running. The uptime limit is 6 hours. The current uptime is
1884 // 29 hours 59 minutes 59 seconds.
1885 // Verifies that if no non-kiosk-app session is in progress, the device reboots
1886 // immediately when the grace period ends after 6 + 24 hours of uptime.
1887 TEST_P(AutomaticRebootManagerTest, GracePeriodEnd) {
1888 uptime_provider()->SetUptime(base::TimeDelta::FromHours(29) +
1889 base::TimeDelta::FromMinutes(59) +
1890 base::TimeDelta::FromSeconds(59));
1892 // Verify that no reboot is requested and the device does not reboot
1893 // immediately.
1894 ExpectNoRebootRequest();
1895 CreateAutomaticRebootManager(false);
1896 VerifyNoRebootRequested();
1898 // Set the uptime limit. Verify that a reboot is requested but the device does
1899 // not reboot immediately.
1900 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1901 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1903 // Verify that a grace period has started.
1904 VerifyGracePeriod(uptime_limit_);
1906 // Fast forward the uptime by 1 second. Verify that unless a non-kiosk-app
1907 // session is in progress, the the device immediately reboots.
1908 FastForwardBy(base::TimeDelta::FromSeconds(1), !is_user_logged_in_ ||
1909 is_logged_in_as_kiosk_app_);
1911 // Verify that if a non-kiosk-app session is in progress, the device never
1912 // reboots.
1913 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1914 is_logged_in_as_kiosk_app_);
1917 // Chrome is starting. The current uptime is 10 days.
1918 // Verifies that when no automatic reboot policy is enabled, no reboot occurs
1919 // and no grace period is scheduled.
1920 TEST_P(AutomaticRebootManagerTest, StartNoPolicy) {
1921 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
1923 // Verify that no reboot is requested and the device does not reboot
1924 // immediately.
1925 ExpectNoRebootRequest();
1926 CreateAutomaticRebootManager(false);
1927 VerifyNoRebootRequested();
1929 // Verify that no grace period has started.
1930 VerifyNoGracePeriod();
1932 // Verify that a reboot is never requested and the device never reboots.
1933 FastForwardUntilNoTasksRemain(false);
1936 // Chrome is starting. The uptime limit is set to 24 hours. The current uptime
1937 // is 12 hours.
1938 // Verifies that no reboot occurs and a grace period is scheduled to begin after
1939 // 24 hours of uptime.
1940 TEST_P(AutomaticRebootManagerTest, StartBeforeUptimeLimitGracePeriod) {
1941 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1942 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1944 // Verify that no reboot is requested and the device does not reboot
1945 // immediately.
1946 ExpectNoRebootRequest();
1947 CreateAutomaticRebootManager(false);
1948 VerifyNoRebootRequested();
1950 // Verify that a grace period has been scheduled to start in the future.
1951 VerifyGracePeriod(uptime_limit_);
1953 // Verify that a reboot is requested eventually and unless a non-kiosk-app
1954 // session is in progress, the device eventually reboots.
1955 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1956 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1957 is_logged_in_as_kiosk_app_);
1960 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is
1961 // 10 days.
1962 // Verifies that if no non-kiosk-app session is in progress, the device reboots
1963 // immediately because the grace period ended after 6 + 24 hours of uptime.
1964 TEST_P(AutomaticRebootManagerTest, StartAfterUptimeLimitGracePeriod) {
1965 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1966 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
1968 // Verify that a reboot is requested and unless a non-kiosk-app session is in
1969 // progress, the the device immediately reboots.
1970 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1971 CreateAutomaticRebootManager(!is_user_logged_in_ ||
1972 is_logged_in_as_kiosk_app_);
1973 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1975 // Verify that if a non-kiosk-app session is in progress, the device never
1976 // reboots.
1977 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1978 is_logged_in_as_kiosk_app_);
1981 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is
1982 // 12 hours.
1983 // Verifies that a reboot is requested and a grace period is started that will
1984 // end after 6 + 24 hours of uptime.
1985 TEST_P(AutomaticRebootManagerTest, StartInUptimeLimitGracePeriod) {
1986 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1987 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1989 // Verify that a reboot is requested but the device does not reboot
1990 // immediately.
1991 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1992 CreateAutomaticRebootManager(false);
1993 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1995 // Verify that a grace period has started.
1996 VerifyGracePeriod(uptime_limit_);
1998 // Verify that unless a non-kiosk-app session is in progress, the device
1999 // eventually reboots.
2000 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2001 is_logged_in_as_kiosk_app_);
2004 // Chrome is starting. An update was applied and a reboot became necessary to
2005 // complete the update process after 6 hours of uptime. The current uptime is
2006 // 10 days.
2007 // Verifies that when the policy to automatically reboot after an update is
2008 // enabled, the device reboots immediately if no non-kiosk-app session is in
2009 // progress because the grace period ended after 6 + 24 hours of uptime.
2010 TEST_P(AutomaticRebootManagerTest, StartAfterUpdateGracePeriod) {
2011 SetUpdateStatusNeedReboot();
2012 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
2013 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
2014 SetRebootAfterUpdate(true, false);
2016 // Verify that a reboot is requested and unless a non-kiosk-app session is in
2017 // progress, the the device immediately reboots.
2018 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2019 CreateAutomaticRebootManager(!is_user_logged_in_ ||
2020 is_logged_in_as_kiosk_app_);
2021 VerifyRebootRequested(
2022 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2024 // Verify that if a non-kiosk-app session is in progress, the device never
2025 // reboots.
2026 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2027 is_logged_in_as_kiosk_app_);
2030 // Chrome is starting. An update was applied and a reboot became necessary to
2031 // complete the update process after 6 hours of uptime. The current uptime is
2032 // 12 hours.
2033 // Verifies that when the policy to automatically reboot after an update is
2034 // enabled, a reboot is requested and a grace period is started that will end
2035 // after 6 + 24 hours of uptime.
2036 TEST_P(AutomaticRebootManagerTest, StartInUpdateGracePeriod) {
2037 SetUpdateStatusNeedReboot();
2038 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
2039 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
2040 SetRebootAfterUpdate(true, false);
2042 // Verify that a reboot is requested but the device does not reboot
2043 // immediately.
2044 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2045 CreateAutomaticRebootManager(false);
2046 VerifyRebootRequested(
2047 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2049 // Verify that a grace period has started.
2050 VerifyGracePeriod(update_reboot_needed_uptime_);
2052 // Verify that unless a non-kiosk-app session is in progress, the device
2053 // eventually reboots.
2054 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2055 is_logged_in_as_kiosk_app_);
2058 // Chrome is starting. An update was applied and a reboot became necessary to
2059 // complete the update process after 10 minutes of uptime. The current uptime is
2060 // 20 minutes.
2061 // Verifies that when the policy to automatically reboot after an update is
2062 // enabled, no reboot occurs and a grace period is scheduled to begin after the
2063 // minimum of 1 hour of uptime.
2064 TEST_P(AutomaticRebootManagerTest, StartBeforeUpdateGracePeriod) {
2065 SetUpdateStatusNeedReboot();
2066 SetUpdateRebootNeededUptime(base::TimeDelta::FromMinutes(10));
2067 uptime_provider()->SetUptime(base::TimeDelta::FromMinutes(20));
2068 SetRebootAfterUpdate(true, false);
2070 // Verify that no reboot is requested and the device does not reboot
2071 // immediately.
2072 ExpectNoRebootRequest();
2073 CreateAutomaticRebootManager(false);
2074 VerifyNoRebootRequested();
2076 // Verify that a grace period has been scheduled to start in the future.
2077 VerifyGracePeriod(base::TimeDelta::FromHours(1));
2079 // Verify that a reboot is requested eventually and unless a non-kiosk-app
2080 // session is in progress, the device eventually reboots.
2081 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2082 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2083 is_logged_in_as_kiosk_app_);
2086 // Chrome is starting. An update was applied and a reboot became necessary to
2087 // complete the update process after 6 hours of uptime. The current uptime is
2088 // 10 days.
2089 // Verifies that when the policy to automatically reboot after an update is not
2090 // enabled, no reboot occurs and no grace period is scheduled.
2091 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicy) {
2092 SetUpdateStatusNeedReboot();
2093 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
2094 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
2096 // Verify that no reboot is requested and the device does not reboot
2097 // immediately.
2098 ExpectNoRebootRequest();
2099 CreateAutomaticRebootManager(false);
2100 VerifyNoRebootRequested();
2102 // Verify that no grace period has started.
2103 VerifyNoGracePeriod();
2105 // Verify that a reboot is never requested and the device never reboots.
2106 FastForwardUntilNoTasksRemain(false);
2109 // Chrome is starting. An update was applied and a reboot became necessary to
2110 // complete the update process but the time at which this happened was lost. The
2111 // current uptime is 10 days.
2112 // Verifies that the current uptime is persisted as the time at which a reboot
2113 // became necessary. Further verifies that when the policy to automatically
2114 // reboot after an update is enabled, a reboot is requested and a grace period
2115 // is started that will end 24 hours from now.
2116 TEST_P(AutomaticRebootManagerTest, StartUpdateTimeLost) {
2117 SetUpdateStatusNeedReboot();
2118 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
2119 SetRebootAfterUpdate(true, false);
2121 // Verify that a reboot is requested but the device does not reboot
2122 // immediately.
2123 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2124 CreateAutomaticRebootManager(false);
2125 VerifyRebootRequested(
2126 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2128 // Verify that the current uptime has been persisted as the time at which a
2129 // reboot became necessary.
2130 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
2131 &update_reboot_needed_uptime_));
2132 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
2134 // Verify that a grace period has started.
2135 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
2137 // Verify that unless a non-kiosk-app session is in progress, the device
2138 // eventually reboots.
2139 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2140 is_logged_in_as_kiosk_app_);
2143 // Chrome is starting. An update was applied and a reboot became necessary to
2144 // complete the update process but the time at which this happened was lost. The
2145 // current uptime is 10 days.
2146 // Verifies that the current uptime is persisted as the time at which a reboot
2147 // became necessary. Further verifies that when the policy to automatically
2148 // reboot after an update is not enabled, no reboot occurs and no grace period
2149 // is scheduled.
2150 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicyTimeLost) {
2151 SetUpdateStatusNeedReboot();
2152 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
2154 // Verify that no reboot is requested and the device does not reboot
2155 // immediately.
2156 ExpectNoRebootRequest();
2157 CreateAutomaticRebootManager(false);
2158 VerifyNoRebootRequested();
2160 // Verify that the current uptime has been persisted as the time at which a
2161 // reboot became necessary.
2162 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
2163 &update_reboot_needed_uptime_));
2164 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
2166 // Verify that no grace period has started.
2167 VerifyNoGracePeriod();
2169 // Verify that a reboot is never requested and the device never reboots.
2170 FastForwardUntilNoTasksRemain(false);
2173 // Chrome is starting. No update has been applied. The current uptime is
2174 // 12 hours.
2175 // Verifies that no time is persisted as the time at which a reboot became
2176 // necessary. Further verifies that no reboot occurs and no grace period is
2177 // scheduled.
2178 TEST_P(AutomaticRebootManagerTest, StartNoUpdate) {
2179 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
2180 SetRebootAfterUpdate(true, false);
2182 // Verify that no reboot is requested and the device does not reboot
2183 // immediately.
2184 ExpectNoRebootRequest();
2185 CreateAutomaticRebootManager(false);
2186 VerifyNoRebootRequested();
2188 // Verify that no time is persisted as the time at which a reboot became
2189 // necessary.
2190 EXPECT_FALSE(ReadUpdateRebootNeededUptimeFromFile(
2191 &update_reboot_needed_uptime_));
2193 // Verify that no grace period has started.
2194 VerifyNoGracePeriod();
2196 // Verify that a reboot is never requested and the device never reboots.
2197 FastForwardUntilNoTasksRemain(false);
2200 // Chrome is starting. The uptime limit is set to 6 hours. Also, an update was
2201 // applied and a reboot became necessary to complete the update process after
2202 // 8 hours of uptime. The current uptime is 12 hours.
2203 // Verifies that when the policy to automatically reboot after an update is
2204 // enabled, a reboot is requested and a grace period is started that will end
2205 // after 6 + 24 hours of uptime.
2206 TEST_P(AutomaticRebootManagerTest, StartUptimeLimitBeforeUpdate) {
2207 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
2208 SetUpdateStatusNeedReboot();
2209 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(8));
2210 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
2211 SetRebootAfterUpdate(true, false);
2213 // Verify that a reboot is requested but the device does not reboot
2214 // immediately.
2215 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
2216 CreateAutomaticRebootManager(false);
2217 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
2219 // Verify that a grace period has started.
2220 VerifyGracePeriod(uptime_limit_);
2222 // Verify that unless a non-kiosk-app session is in progress, the device
2223 // eventually reboots.
2224 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2225 is_logged_in_as_kiosk_app_);
2228 // Chrome is starting. The uptime limit is set to 8 hours. Also, an update was
2229 // applied and a reboot became necessary to complete the update process after
2230 // 6 hours of uptime. The current uptime is 12 hours.
2231 // Verifies that when the policy to automatically reboot after an update is
2232 // enabled, a reboot is requested and a grace period is started that will end
2233 // after 6 + 24 hours of uptime.
2234 TEST_P(AutomaticRebootManagerTest, StartUpdateBeforeUptimeLimit) {
2235 SetUptimeLimit(base::TimeDelta::FromHours(8), false);
2236 SetUpdateStatusNeedReboot();
2237 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
2238 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
2239 SetRebootAfterUpdate(true, false);
2241 // Verify that a reboot is requested but the device does not reboot
2242 // immediately.
2243 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2244 CreateAutomaticRebootManager(false);
2245 VerifyRebootRequested(
2246 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2248 // Verify that a grace period has started.
2249 VerifyGracePeriod(update_reboot_needed_uptime_);
2251 // Verify that unless a non-kiosk-app session is in progress, the device
2252 // eventually reboots.
2253 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2254 is_logged_in_as_kiosk_app_);
2257 // Chrome is starting. The uptime limit is set to 6 hours. Also, an update was
2258 // applied and a reboot became necessary to complete the update process after
2259 // 6 hours of uptime. The current uptime is not available.
2260 // Verifies that even if the policy to automatically reboot after an update is
2261 // enabled, no reboot occurs and no grace period is scheduled.
2262 TEST_P(AutomaticRebootManagerTest, StartNoUptime) {
2263 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
2264 SetUpdateStatusNeedReboot();
2265 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
2266 SetRebootAfterUpdate(true, false);
2268 // Verify that no reboot is requested and the device does not reboot
2269 // immediately.
2270 ExpectNoRebootRequest();
2271 CreateAutomaticRebootManager(false);
2272 VerifyNoRebootRequested();
2274 // Verify that no grace period has started.
2275 VerifyNoGracePeriod();
2277 // Verify that a reboot is never requested and the device never reboots.
2278 FastForwardUntilNoTasksRemain(false);
2281 INSTANTIATE_TEST_CASE_P(
2282 AutomaticRebootManagerTestInstance,
2283 AutomaticRebootManagerTest,
2284 ::testing::Values(
2285 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN,
2286 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION,
2287 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION));
2289 } // namespace system
2290 } // namespace chromeos