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

Side by Side Diff: chrome/browser/chromeos/system/automatic_reboot_manager_unittest.cc

Issue 727363002: Fire notifications when reboot is requested, not scheduled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@managed_cros
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h" 5 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 11 matching lines...) Expand all
22 #include "base/single_thread_task_runner.h" 22 #include "base/single_thread_task_runner.h"
23 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
24 #include "base/test/simple_test_tick_clock.h" 24 #include "base/test/simple_test_tick_clock.h"
25 #include "base/thread_task_runner_handle.h" 25 #include "base/thread_task_runner_handle.h"
26 #include "base/threading/sequenced_worker_pool.h" 26 #include "base/threading/sequenced_worker_pool.h"
27 #include "base/time/tick_clock.h" 27 #include "base/time/tick_clock.h"
28 #include "base/values.h" 28 #include "base/values.h"
29 #include "chrome/browser/chrome_notification_types.h" 29 #include "chrome/browser/chrome_notification_types.h"
30 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" 30 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
31 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 31 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
32 #include "chrome/browser/chromeos/system/automatic_reboot_manager_observer.h"
32 #include "chrome/common/pref_names.h" 33 #include "chrome/common/pref_names.h"
33 #include "chrome/test/base/testing_browser_process.h" 34 #include "chrome/test/base/testing_browser_process.h"
34 #include "chromeos/chromeos_paths.h" 35 #include "chromeos/chromeos_paths.h"
35 #include "chromeos/dbus/dbus_thread_manager.h" 36 #include "chromeos/dbus/dbus_thread_manager.h"
36 #include "chromeos/dbus/fake_power_manager_client.h" 37 #include "chromeos/dbus/fake_power_manager_client.h"
37 #include "chromeos/dbus/fake_update_engine_client.h" 38 #include "chromeos/dbus/fake_update_engine_client.h"
38 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
39 #include "content/public/browser/notification_details.h" 40 #include "content/public/browser/notification_details.h"
40 #include "content/public/browser/notification_service.h" 41 #include "content/public/browser/notification_service.h"
41 #include "content/public/browser/notification_source.h" 42 #include "content/public/browser/notification_source.h"
42 #include "content/public/test/test_browser_thread.h" 43 #include "content/public/test/test_browser_thread.h"
43 #include "testing/gmock/include/gmock/gmock.h" 44 #include "testing/gmock/include/gmock/gmock.h"
44 #include "testing/gtest/include/gtest/gtest.h" 45 #include "testing/gtest/include/gtest/gtest.h"
45 #include "ui/message_center/message_center.h" 46 #include "ui/message_center/message_center.h"
46 47
48 using ::testing::_;
49 using ::testing::Mock;
47 using ::testing::ReturnPointee; 50 using ::testing::ReturnPointee;
48 51
49 namespace chromeos { 52 namespace chromeos {
50 namespace system { 53 namespace system {
51 54
52 namespace { 55 namespace {
53 56
54 // A SingleThreadTaskRunner that mocks the current time and allows it to be 57 // A SingleThreadTaskRunner that mocks the current time and allows it to be
55 // fast-forwarded. The current time in ticks is returned by Now(). The 58 // fast-forwarded. The current time in ticks is returned by Now(). The
56 // corresponding device uptime is written to |uptime_file_|, providing a mock 59 // corresponding device uptime is written to |uptime_file_|, providing a mock
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 111
109 // base::TickClock: 112 // base::TickClock:
110 virtual base::TimeTicks NowTicks() override; 113 virtual base::TimeTicks NowTicks() override;
111 114
112 private: 115 private:
113 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_; 116 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_;
114 117
115 DISALLOW_COPY_AND_ASSIGN(MockTimeTickClock); 118 DISALLOW_COPY_AND_ASSIGN(MockTimeTickClock);
116 }; 119 };
117 120
121 class MockAutomaticRebootManagerObserver
122 : public AutomaticRebootManagerObserver {
123 public:
124 MockAutomaticRebootManagerObserver();
125 ~MockAutomaticRebootManagerObserver() override;
126
127 // AutomaticRebootManagerObserver:
128 MOCK_METHOD1(OnRebootRequested, void(Reason));
129 MOCK_METHOD0(WillDestroyAutomaticRebootManager, void());
130
131 private:
132 DISALLOW_COPY_AND_ASSIGN(MockAutomaticRebootManagerObserver);
133 };
134
118 } // namespace 135 } // namespace
119 136
120 class AutomaticRebootManagerBasicTest : public testing::Test { 137 class AutomaticRebootManagerBasicTest : public testing::Test {
121 protected: 138 protected:
122 typedef base::OneShotTimer<AutomaticRebootManager> Timer; 139 typedef base::OneShotTimer<AutomaticRebootManager> Timer;
123 140
124 AutomaticRebootManagerBasicTest(); 141 AutomaticRebootManagerBasicTest();
125 virtual ~AutomaticRebootManagerBasicTest(); 142 virtual ~AutomaticRebootManagerBasicTest();
126 143
127 // testing::Test: 144 // testing::Test:
128 virtual void SetUp() override; 145 virtual void SetUp() override;
129 virtual void TearDown() override; 146 virtual void TearDown() override;
130 147
131 void SetUpdateRebootNeededUptime(const base::TimeDelta& uptime); 148 void SetUpdateRebootNeededUptime(const base::TimeDelta& uptime);
132 void SetRebootAfterUpdate(bool reboot_after_update, bool expect_reboot); 149 void SetRebootAfterUpdate(bool reboot_after_update, bool expect_reboot);
133 void SetUptimeLimit(const base::TimeDelta& limit, bool expect_reboot); 150 void SetUptimeLimit(const base::TimeDelta& limit, bool expect_reboot);
134 void NotifyUpdateRebootNeeded(); 151 void NotifyUpdateRebootNeeded();
135 void NotifyResumed(bool expect_reboot); 152 void NotifyResumed(bool expect_reboot);
136 void NotifyTerminating(bool expect_reboot); 153 void NotifyTerminating(bool expect_reboot);
137 154
138 void FastForwardBy(const base::TimeDelta& delta, bool expect_reboot); 155 void FastForwardBy(const base::TimeDelta& delta, bool expect_reboot);
139 void FastForwardUntilNoTasksRemain(bool expect_reboot); 156 void FastForwardUntilNoTasksRemain(bool expect_reboot);
140 157
158 void ExpectRebootRequest(AutomaticRebootManagerObserver::Reason reason);
159 void ExpectNoRebootRequest();
160
141 void CreateAutomaticRebootManager(bool expect_reboot); 161 void CreateAutomaticRebootManager(bool expect_reboot);
142 162
143 bool ReadUpdateRebootNeededUptimeFromFile(base::TimeDelta* uptime); 163 bool ReadUpdateRebootNeededUptimeFromFile(base::TimeDelta* uptime);
164 void VerifyRebootRequested(AutomaticRebootManagerObserver::Reason reason);
165 void VerifyNoRebootRequested() const;
144 void VerifyLoginScreenIdleTimerIsStopped() const; 166 void VerifyLoginScreenIdleTimerIsStopped() const;
145 void VerifyNoGracePeriod() const; 167 void VerifyNoGracePeriod() const;
146 void VerifyGracePeriod(const base::TimeDelta& start_uptime) const; 168 void VerifyGracePeriod(const base::TimeDelta& start_uptime) const;
147 169
148 bool is_user_logged_in_; 170 bool is_user_logged_in_;
149 bool is_logged_in_as_kiosk_app_; 171 bool is_logged_in_as_kiosk_app_;
150 172
151 // The uptime is read in the blocking thread pool and then processed on the 173 // The uptime is read in the blocking thread pool and then processed on the
152 // UI thread. This causes the UI thread to start processing the uptime when it 174 // UI thread. This causes the UI thread to start processing the uptime when it
153 // has increased by a small offset already. The offset is calculated and 175 // has increased by a small offset already. The offset is calculated and
154 // stored in |uptime_processing_delay_| so that tests can accurately determine 176 // stored in |uptime_processing_delay_| so that tests can accurately determine
155 // the uptime seen by the UI thread. 177 // the uptime seen by the UI thread.
156 base::TimeDelta uptime_processing_delay_; 178 base::TimeDelta uptime_processing_delay_;
157 base::TimeDelta update_reboot_needed_uptime_; 179 base::TimeDelta update_reboot_needed_uptime_;
158 base::TimeDelta uptime_limit_; 180 base::TimeDelta uptime_limit_;
159 181
160 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_; 182 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_;
161 183
184 MockAutomaticRebootManagerObserver automatic_reboot_manager_observer_;
162 scoped_ptr<AutomaticRebootManager> automatic_reboot_manager_; 185 scoped_ptr<AutomaticRebootManager> automatic_reboot_manager_;
163 186
164 protected: 187 protected:
165 FakePowerManagerClient* power_manager_client_; // Not owned. 188 FakePowerManagerClient* power_manager_client_; // Not owned.
166 FakeUpdateEngineClient* update_engine_client_; // Not owned. 189 FakeUpdateEngineClient* update_engine_client_; // Not owned.
167 190
168 // Sets the status of |update_engine_client_| to NEED_REBOOT for tests. 191 // Sets the status of |update_engine_client_| to NEED_REBOOT for tests.
169 void SetUpdateStatusNeedReboot(); 192 void SetUpdateStatusNeedReboot();
170 193
171 private: 194 private:
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 : task_runner_(task_runner) { 341 : task_runner_(task_runner) {
319 } 342 }
320 343
321 MockTimeTickClock::~MockTimeTickClock() { 344 MockTimeTickClock::~MockTimeTickClock() {
322 } 345 }
323 346
324 base::TimeTicks MockTimeTickClock::NowTicks() { 347 base::TimeTicks MockTimeTickClock::NowTicks() {
325 return task_runner_->Now(); 348 return task_runner_->Now();
326 } 349 }
327 350
351 MockAutomaticRebootManagerObserver::MockAutomaticRebootManagerObserver() {
352 }
353
354 MockAutomaticRebootManagerObserver::~MockAutomaticRebootManagerObserver() {
355 }
356
328 AutomaticRebootManagerBasicTest::AutomaticRebootManagerBasicTest() 357 AutomaticRebootManagerBasicTest::AutomaticRebootManagerBasicTest()
329 : is_user_logged_in_(false), 358 : is_user_logged_in_(false),
330 is_logged_in_as_kiosk_app_(false), 359 is_logged_in_as_kiosk_app_(false),
331 task_runner_(new MockTimeSingleThreadTaskRunner), 360 task_runner_(new MockTimeSingleThreadTaskRunner),
332 power_manager_client_(NULL), 361 power_manager_client_(NULL),
333 update_engine_client_(NULL), 362 update_engine_client_(NULL),
334 reboot_after_update_(false), 363 reboot_after_update_(false),
335 ui_thread_task_runner_handle_(task_runner_), 364 ui_thread_task_runner_handle_(task_runner_),
336 mock_user_manager_(new MockUserManager), 365 mock_user_manager_(new MockUserManager),
337 user_manager_enabler_(mock_user_manager_) { 366 user_manager_enabler_(mock_user_manager_) {
(...skipping 27 matching lines...) Expand all
365 dbus_setter->SetUpdateEngineClient( 394 dbus_setter->SetUpdateEngineClient(
366 scoped_ptr<UpdateEngineClient>(update_engine_client_)); 395 scoped_ptr<UpdateEngineClient>(update_engine_client_));
367 396
368 EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn()) 397 EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn())
369 .WillRepeatedly(ReturnPointee(&is_user_logged_in_)); 398 .WillRepeatedly(ReturnPointee(&is_user_logged_in_));
370 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsKioskApp()) 399 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsKioskApp())
371 .WillRepeatedly(ReturnPointee(&is_logged_in_as_kiosk_app_)); 400 .WillRepeatedly(ReturnPointee(&is_logged_in_as_kiosk_app_));
372 } 401 }
373 402
374 void AutomaticRebootManagerBasicTest::TearDown() { 403 void AutomaticRebootManagerBasicTest::TearDown() {
375 // Let the AutomaticRebootManager, if any, unregister itself as an observer of 404 if (automatic_reboot_manager_) {
376 // several subsystems. 405 Mock::VerifyAndClearExpectations(&automatic_reboot_manager_observer_);
377 automatic_reboot_manager_.reset(); 406 EXPECT_CALL(automatic_reboot_manager_observer_,
378 task_runner_->RunUntilIdle(); 407 WillDestroyAutomaticRebootManager()).Times(1);
408 EXPECT_CALL(automatic_reboot_manager_observer_,
409 OnRebootRequested(_)).Times(0);
410 // Let the AutomaticRebootManager, if any, unregister itself as an observer
411 // of several subsystems.
412 automatic_reboot_manager_.reset();
413 task_runner_->RunUntilIdle();
414 }
379 415
380 DBusThreadManager::Shutdown(); 416 DBusThreadManager::Shutdown();
381 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); 417 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
382 } 418 }
383 419
384 void AutomaticRebootManagerBasicTest::SetUpdateRebootNeededUptime( 420 void AutomaticRebootManagerBasicTest::SetUpdateRebootNeededUptime(
385 const base::TimeDelta& uptime) { 421 const base::TimeDelta& uptime) {
386 update_reboot_needed_uptime_ = uptime; 422 update_reboot_needed_uptime_ = uptime;
387 SaveUptimeToFile(update_reboot_needed_uptime_file_, uptime); 423 SaveUptimeToFile(update_reboot_needed_uptime_file_, uptime);
388 } 424 }
389 425
390
391 void AutomaticRebootManagerBasicTest::SetRebootAfterUpdate( 426 void AutomaticRebootManagerBasicTest::SetRebootAfterUpdate(
392 bool reboot_after_update, 427 bool reboot_after_update,
393 bool expect_reboot) { 428 bool expect_reboot) {
394 reboot_after_update_ = reboot_after_update; 429 reboot_after_update_ = reboot_after_update;
395 local_state_.SetManagedPref(prefs::kRebootAfterUpdate, 430 local_state_.SetManagedPref(prefs::kRebootAfterUpdate,
396 new base::FundamentalValue(reboot_after_update)); 431 new base::FundamentalValue(reboot_after_update));
397 task_runner_->RunUntilIdle(); 432 task_runner_->RunUntilIdle();
398 EXPECT_EQ(expect_reboot ? 1 : 0, 433 EXPECT_EQ(expect_reboot ? 1 : 0,
399 power_manager_client_->num_request_restart_calls()); 434 power_manager_client_->num_request_restart_calls());
400 } 435 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 power_manager_client_->num_request_restart_calls()); 483 power_manager_client_->num_request_restart_calls());
449 } 484 }
450 485
451 void AutomaticRebootManagerBasicTest::FastForwardUntilNoTasksRemain( 486 void AutomaticRebootManagerBasicTest::FastForwardUntilNoTasksRemain(
452 bool expect_reboot) { 487 bool expect_reboot) {
453 task_runner_->FastForwardUntilNoTasksRemain(); 488 task_runner_->FastForwardUntilNoTasksRemain();
454 EXPECT_EQ(expect_reboot ? 1 : 0, 489 EXPECT_EQ(expect_reboot ? 1 : 0,
455 power_manager_client_->num_request_restart_calls()); 490 power_manager_client_->num_request_restart_calls());
456 } 491 }
457 492
493 void AutomaticRebootManagerBasicTest::ExpectRebootRequest(
494 AutomaticRebootManagerObserver::Reason reason) {
495 Mock::VerifyAndClearExpectations(&automatic_reboot_manager_observer_);
496 EXPECT_CALL(automatic_reboot_manager_observer_,
497 WillDestroyAutomaticRebootManager()).Times(0);
498 EXPECT_CALL(automatic_reboot_manager_observer_,
499 OnRebootRequested(_)).Times(0);
500 EXPECT_CALL(automatic_reboot_manager_observer_,
501 OnRebootRequested(reason)).Times(1);
502 }
503
504 void AutomaticRebootManagerBasicTest::ExpectNoRebootRequest() {
505 Mock::VerifyAndClearExpectations(&automatic_reboot_manager_observer_);
506 EXPECT_CALL(automatic_reboot_manager_observer_,
507 WillDestroyAutomaticRebootManager()).Times(0);
508 EXPECT_CALL(automatic_reboot_manager_observer_,
509 OnRebootRequested(_)).Times(0);
510 }
511
458 void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager( 512 void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager(
459 bool expect_reboot) { 513 bool expect_reboot) {
460 automatic_reboot_manager_.reset(new AutomaticRebootManager( 514 automatic_reboot_manager_.reset(new AutomaticRebootManager(
461 scoped_ptr<base::TickClock>(new MockTimeTickClock(task_runner_)))); 515 scoped_ptr<base::TickClock>(new MockTimeTickClock(task_runner_))));
516 automatic_reboot_manager_->AddObserver(&automatic_reboot_manager_observer_);
462 task_runner_->RunUntilIdle(); 517 task_runner_->RunUntilIdle();
463 EXPECT_EQ(expect_reboot ? 1 : 0, 518 EXPECT_EQ(expect_reboot ? 1 : 0,
464 power_manager_client_->num_request_restart_calls()); 519 power_manager_client_->num_request_restart_calls());
465 520
466 uptime_processing_delay_ = 521 uptime_processing_delay_ =
467 base::TimeTicks() - automatic_reboot_manager_->boot_time_ - 522 base::TimeTicks() - automatic_reboot_manager_->boot_time_ -
468 task_runner_->Uptime(); 523 task_runner_->Uptime();
469 EXPECT_GE(uptime_processing_delay_, base::TimeDelta()); 524 EXPECT_GE(uptime_processing_delay_, base::TimeDelta());
470 EXPECT_LE(uptime_processing_delay_, base::TimeDelta::FromSeconds(1)); 525 EXPECT_LE(uptime_processing_delay_, base::TimeDelta::FromSeconds(1));
471 526
(...skipping 11 matching lines...) Expand all
483 } 538 }
484 double seconds; 539 double seconds;
485 if (!base::StringToDouble(contents.substr(0, contents.find(' ')), &seconds) || 540 if (!base::StringToDouble(contents.substr(0, contents.find(' ')), &seconds) ||
486 seconds < 0.0) { 541 seconds < 0.0) {
487 return false; 542 return false;
488 } 543 }
489 *uptime = base::TimeDelta::FromMilliseconds(seconds * 1000.0); 544 *uptime = base::TimeDelta::FromMilliseconds(seconds * 1000.0);
490 return true; 545 return true;
491 } 546 }
492 547
548 void AutomaticRebootManagerBasicTest::VerifyRebootRequested(
549 AutomaticRebootManagerObserver::Reason reason) {
550 EXPECT_TRUE(automatic_reboot_manager_->reboot_requested());
551 EXPECT_EQ(reason, automatic_reboot_manager_->reboot_reason());
552 }
553
554 void AutomaticRebootManagerBasicTest::VerifyNoRebootRequested() const {
555 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested());
556 }
557
493 void AutomaticRebootManagerBasicTest:: 558 void AutomaticRebootManagerBasicTest::
494 VerifyLoginScreenIdleTimerIsStopped() const { 559 VerifyLoginScreenIdleTimerIsStopped() const {
495 VerifyTimerIsStopped( 560 VerifyTimerIsStopped(
496 automatic_reboot_manager_->login_screen_idle_timer_.get()); 561 automatic_reboot_manager_->login_screen_idle_timer_.get());
497 } 562 }
498 563
499 void AutomaticRebootManagerBasicTest::VerifyNoGracePeriod() const { 564 void AutomaticRebootManagerBasicTest::VerifyNoGracePeriod() const {
500 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_); 565 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_);
501 VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get()); 566 VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get());
502 VerifyTimerIsStopped(automatic_reboot_manager_->grace_end_timer_.get()); 567 VerifyTimerIsStopped(automatic_reboot_manager_->grace_end_timer_.get());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 633
569 AutomaticRebootManagerTest::~AutomaticRebootManagerTest() { 634 AutomaticRebootManagerTest::~AutomaticRebootManagerTest() {
570 } 635 }
571 636
572 // Chrome is showing the login screen. The current uptime is 12 hours. 637 // Chrome is showing the login screen. The current uptime is 12 hours.
573 // Verifies that the idle timer is running. Further verifies that when a kiosk 638 // Verifies that the idle timer is running. Further verifies that when a kiosk
574 // app session begins, the idle timer is stopped. 639 // app session begins, the idle timer is stopped.
575 TEST_F(AutomaticRebootManagerBasicTest, LoginStopsIdleTimer) { 640 TEST_F(AutomaticRebootManagerBasicTest, LoginStopsIdleTimer) {
576 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 641 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
577 642
578 // Verify that the device does not reboot immediately and the login screen 643 // Verify that no reboot is requested, the device does not reboot immediately
579 // idle timer is started. 644 // and the login screen idle timer is started.
645 ExpectNoRebootRequest();
580 CreateAutomaticRebootManager(false); 646 CreateAutomaticRebootManager(false);
647 VerifyNoRebootRequested();
581 648
582 // Notify that a kiosk app session has been started. 649 // Notify that a kiosk app session has been started.
583 is_user_logged_in_ = true; 650 is_user_logged_in_ = true;
584 is_logged_in_as_kiosk_app_ = true; 651 is_logged_in_as_kiosk_app_ = true;
585 automatic_reboot_manager_->Observe( 652 automatic_reboot_manager_->Observe(
586 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 653 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
587 content::Source<AutomaticRebootManagerBasicTest>(this), 654 content::Source<AutomaticRebootManagerBasicTest>(this),
588 content::NotificationService::NoDetails()); 655 content::NotificationService::NoDetails());
589 656
590 // Verify that the login screen idle timer is stopped. 657 // Verify that the login screen idle timer is stopped.
591 VerifyLoginScreenIdleTimerIsStopped(); 658 VerifyLoginScreenIdleTimerIsStopped();
592 659
593 // Verify that the device does not reboot eventually. 660 // Verify that a reboot is never requested and the device never reboots.
594 FastForwardUntilNoTasksRemain(false); 661 FastForwardUntilNoTasksRemain(false);
595 } 662 }
596 663
597 // Chrome is showing the login screen. The current uptime is 12 hours. 664 // Chrome is showing the login screen. The current uptime is 12 hours.
598 // Verifies that the idle timer is running. Further verifies that when a 665 // Verifies that the idle timer is running. Further verifies that when a
599 // non-kiosk-app session begins, the idle timer is stopped. 666 // non-kiosk-app session begins, the idle timer is stopped.
600 TEST_F(AutomaticRebootManagerBasicTest, NonKioskLoginStopsIdleTimer) { 667 TEST_F(AutomaticRebootManagerBasicTest, NonKioskLoginStopsIdleTimer) {
601 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 668 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
602 669
603 // Verify that the device does not reboot immediately and the login screen 670 // Verify that no reboot is requested, the device does not reboot immediately
604 // idle timer is started. 671 // and the login screen idle timer is started.
672 ExpectNoRebootRequest();
605 CreateAutomaticRebootManager(false); 673 CreateAutomaticRebootManager(false);
674 VerifyNoRebootRequested();
606 675
607 // Notify that a non-kiosk-app session has been started. 676 // Notify that a non-kiosk-app session has been started.
608 is_user_logged_in_ = true; 677 is_user_logged_in_ = true;
609 automatic_reboot_manager_->Observe( 678 automatic_reboot_manager_->Observe(
610 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 679 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
611 content::Source<AutomaticRebootManagerBasicTest>(this), 680 content::Source<AutomaticRebootManagerBasicTest>(this),
612 content::NotificationService::NoDetails()); 681 content::NotificationService::NoDetails());
613 682
614 // Verify that the login screen idle timer is stopped. 683 // Verify that the login screen idle timer is stopped.
615 VerifyLoginScreenIdleTimerIsStopped(); 684 VerifyLoginScreenIdleTimerIsStopped();
616 685
617 // Verify that the device does not reboot eventually. 686 // Verify that a reboot is never requested and the device never reboots.
618 FastForwardUntilNoTasksRemain(false); 687 FastForwardUntilNoTasksRemain(false);
619 } 688 }
620 689
621 // Chrome is showing the login screen. The uptime limit is 6 hours. The current 690 // Chrome is showing the login screen. The uptime limit is 6 hours. The current
622 // uptime is 12 hours. 691 // uptime is 12 hours.
623 // Verifies that user activity prevents the device from rebooting. Further 692 // Verifies that user activity prevents the device from rebooting. Further
624 // verifies that when user activity ceases, the devices reboots. 693 // verifies that when user activity ceases, the devices reboots.
625 TEST_F(AutomaticRebootManagerBasicTest, UserActivityResetsIdleTimer) { 694 TEST_F(AutomaticRebootManagerBasicTest, UserActivityResetsIdleTimer) {
626 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 695 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
627 696
628 // Verify that the device does not reboot immediately and the login screen 697 // Verify that no reboot is requested, the device does not reboot immediately
629 // idle timer is started. 698 // and the login screen idle timer is started.
699 ExpectNoRebootRequest();
630 CreateAutomaticRebootManager(false); 700 CreateAutomaticRebootManager(false);
701 VerifyNoRebootRequested();
631 702
632 // Set the uptime limit. Verify that the device does not reboot immediately. 703 // Set the uptime limit. Verify that a reboot is requested but the device does
704 // not reboot immediately.
705 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
633 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 706 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
634 707
635 // Verify that a grace period has started. 708 // Verify that a grace period has started.
636 VerifyGracePeriod(uptime_limit_); 709 VerifyGracePeriod(uptime_limit_);
637 710
638 // Fast forward the uptime by 25 minutes while simulating user activity every 711 // Fast forward the uptime by 25 minutes while simulating user activity every
639 // 50 seconds. 712 // 50 seconds.
640 for (int i = 0; i < 30; ++i) { 713 for (int i = 0; i < 30; ++i) {
641 // Fast forward uptime by 50 seconds. Verify that the device does not reboot 714 // Fast forward uptime by 50 seconds. Verify that the device does not reboot
642 // immediately. 715 // immediately.
643 FastForwardBy(base::TimeDelta::FromSeconds(50), false); 716 FastForwardBy(base::TimeDelta::FromSeconds(50), false);
644 717
645 // Simulate user activity. 718 // Simulate user activity.
646 automatic_reboot_manager_->OnUserActivity(NULL); 719 automatic_reboot_manager_->OnUserActivity(NULL);
647 } 720 }
648 721
649 // Fast forward the uptime by 60 seconds without simulating user activity. 722 // Fast forward the uptime by 60 seconds without simulating user activity.
650 // Verify that the device reboots immediately. 723 // Verify that the device reboots immediately.
651 FastForwardBy(base::TimeDelta::FromSeconds(60), true); 724 FastForwardBy(base::TimeDelta::FromSeconds(60), true);
652 } 725 }
653 726
654 // Chrome is running a kiosk app session. The current uptime is 10 days. 727 // Chrome is running a kiosk app session. The current uptime is 10 days.
655 // Verifies that when the device is suspended and then resumes, it does not 728 // Verifies that when the device is suspended and then resumes, it does not
656 // immediately reboot. 729 // immediately reboot.
657 TEST_F(AutomaticRebootManagerBasicTest, ResumeNoPolicy) { 730 TEST_F(AutomaticRebootManagerBasicTest, ResumeNoPolicy) {
658 is_user_logged_in_ = true; 731 is_user_logged_in_ = true;
659 is_logged_in_as_kiosk_app_ = true; 732 is_logged_in_as_kiosk_app_ = true;
660 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 733 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
661 734
662 // Verify that the device does not reboot immediately. 735 // Verify that no reboot is requested and the device does not reboot
736 // immediately.
737 ExpectNoRebootRequest();
663 CreateAutomaticRebootManager(false); 738 CreateAutomaticRebootManager(false);
739 VerifyNoRebootRequested();
664 740
665 // Verify that no grace period has started. 741 // Verify that no grace period has started.
666 VerifyNoGracePeriod(); 742 VerifyNoGracePeriod();
667 743
668 // Notify that the device has resumed from 1 hour of sleep. Verify that the 744 // Notify that the device has resumed from 1 hour of sleep. Verify that no
669 // device does not reboot immediately. 745 // reboot is requested and the device does not reboot immediately.
670 NotifyResumed(false); 746 NotifyResumed(false);
671 747
672 // Verify that the device does not reboot eventually. 748 // Verify that a reboot is never requested and the device never reboots.
673 FastForwardUntilNoTasksRemain(false); 749 FastForwardUntilNoTasksRemain(false);
674 } 750 }
675 751
676 // Chrome is running a non-kiosk-app session. The current uptime is 10 days. 752 // Chrome is running a non-kiosk-app session. The current uptime is 10 days.
677 // Verifies that when the device is suspended and then resumes, it does not 753 // Verifies that when the device is suspended and then resumes, it does not
678 // immediately reboot. 754 // immediately reboot.
679 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAppNoPolicy) { 755 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAppNoPolicy) {
680 is_user_logged_in_ = true; 756 is_user_logged_in_ = true;
681 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 757 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
682 758
683 // Verify that the device does not reboot immediately. 759 // Verify that no reboot is requested and the device does not reboot
760 // immediately.
761 ExpectNoRebootRequest();
684 CreateAutomaticRebootManager(false); 762 CreateAutomaticRebootManager(false);
763 VerifyNoRebootRequested();
685 764
686 // Verify that no grace period has started. 765 // Verify that no grace period has started.
687 VerifyNoGracePeriod(); 766 VerifyNoGracePeriod();
688 767
689 // Notify that the device has resumed from 1 hour of sleep. Verify that the 768 // Notify that the device has resumed from 1 hour of sleep. Verify that no
690 // device does not reboot immediately. 769 // reboot is requested and the device does not reboot immediately.
691 NotifyResumed(false); 770 NotifyResumed(false);
692 771
693 // Verify that the device does not reboot eventually. 772 // Verify that a reboot is never requested and the device never reboots.
694 FastForwardUntilNoTasksRemain(false); 773 FastForwardUntilNoTasksRemain(false);
695 } 774 }
696 775
697 // Chrome is running a kiosk app session. The uptime limit is 24 hours. The 776 // Chrome is running a kiosk app session. The uptime limit is 24 hours. The
698 // current uptime is 12 hours. 777 // current uptime is 12 hours.
699 // Verifies that when the device is suspended and then resumes, it does not 778 // Verifies that when the device is suspended and then resumes, it does not
700 // immediately reboot. 779 // immediately reboot.
701 TEST_F(AutomaticRebootManagerBasicTest, ResumeBeforeGracePeriod) { 780 TEST_F(AutomaticRebootManagerBasicTest, ResumeBeforeGracePeriod) {
702 is_user_logged_in_ = true; 781 is_user_logged_in_ = true;
703 is_logged_in_as_kiosk_app_ = true; 782 is_logged_in_as_kiosk_app_ = true;
704 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 783 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
705 784
706 // Verify that the device does not reboot immediately. 785 // Verify that no reboot is requested and the device does not reboot
786 // immediately.
787 ExpectNoRebootRequest();
707 CreateAutomaticRebootManager(false); 788 CreateAutomaticRebootManager(false);
789 VerifyNoRebootRequested();
708 790
709 // Set the uptime limit. Verify that the device does not reboot immediately. 791 // Set the uptime limit. Verify that no reboot is requested and the device
792 // does not reboot immediately.
710 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 793 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
711 794
712 // Verify that a grace period has been scheduled to start in the future. 795 // Verify that a grace period has been scheduled to start in the future.
713 VerifyGracePeriod(uptime_limit_); 796 VerifyGracePeriod(uptime_limit_);
714 797
715 // Notify that the device has resumed from 1 hour of sleep. Verify that the 798 // Notify that the device has resumed from 1 hour of sleep. Verify that no
716 // device does not reboot immediately. 799 // reboot is requested and the device does not reboot immediately.
717 NotifyResumed(false); 800 NotifyResumed(false);
718 801
719 // Verify that the device eventually reboots. 802 // Verify a reboot is requested and the device reboots eventually.
803 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
720 FastForwardUntilNoTasksRemain(true); 804 FastForwardUntilNoTasksRemain(true);
721 } 805 }
722 806
723 // Chrome is running a non-kiosk-app session. The uptime limit is 24 hours. The 807 // Chrome is running a non-kiosk-app session. The uptime limit is 24 hours. The
724 // current uptime is 12 hours. 808 // current uptime is 12 hours.
725 // Verifies that when the device is suspended and then resumes, it does not 809 // Verifies that when the device is suspended and then resumes, it does not
726 // immediately reboot. 810 // immediately reboot.
727 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeBeforeGracePeriod) { 811 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeBeforeGracePeriod) {
728 is_user_logged_in_ = true; 812 is_user_logged_in_ = true;
729 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 813 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
730 814
731 // Verify that the device does not reboot immediately. 815 // Verify that no reboot is requested and the device does not reboot
816 // immediately.
817 ExpectNoRebootRequest();
732 CreateAutomaticRebootManager(false); 818 CreateAutomaticRebootManager(false);
819 VerifyNoRebootRequested();
733 820
734 // Set the uptime limit. Verify that the device does not reboot immediately. 821 // Set the uptime limit. Verify that no reboot is requested and the device
822 // does not reboot immediately.
735 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 823 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
736 824
737 // Verify that a grace period has been scheduled to start in the future. 825 // Verify that a grace period has been scheduled to start in the future.
738 VerifyGracePeriod(uptime_limit_); 826 VerifyGracePeriod(uptime_limit_);
739 827
740 // Notify that the device has resumed from 1 hour of sleep. Verify that the 828 // Notify that the device has resumed from 1 hour of sleep. Verify that no
741 // device does not reboot immediately. 829 // reboot is requested and the device does not reboot immediately.
742 NotifyResumed(false); 830 NotifyResumed(false);
743 831
744 // Verify that the device does not reboot eventually. 832 // Verify that a reboot is requested eventually but the device never reboots.
833 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
745 FastForwardUntilNoTasksRemain(false); 834 FastForwardUntilNoTasksRemain(false);
746 } 835 }
747 836
748 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The 837 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The
749 // current uptime is 12 hours. 838 // current uptime is 12 hours.
750 // Verifies that when the device is suspended and then resumes, it immediately 839 // Verifies that when the device is suspended and then resumes, it immediately
751 // reboots. 840 // reboots.
752 TEST_F(AutomaticRebootManagerBasicTest, ResumeInGracePeriod) { 841 TEST_F(AutomaticRebootManagerBasicTest, ResumeInGracePeriod) {
753 is_user_logged_in_ = true; 842 is_user_logged_in_ = true;
754 is_logged_in_as_kiosk_app_ = true; 843 is_logged_in_as_kiosk_app_ = true;
755 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 844 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
756 845
757 // Verify that the device does not reboot immediately. 846 // Verify that no reboot is requested and the device does not reboot
847 // immediately.
848 ExpectNoRebootRequest();
758 CreateAutomaticRebootManager(false); 849 CreateAutomaticRebootManager(false);
850 VerifyNoRebootRequested();
759 851
760 // Set the uptime limit. Verify that the device does not reboot immediately. 852 // Set the uptime limit. Verify that a reboot is requested but the device does
853 // not reboot immediately.
854 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
761 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 855 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
762 856
763 // Verify that a grace period has started. 857 // Verify that a grace period has started.
764 VerifyGracePeriod(uptime_limit_); 858 VerifyGracePeriod(uptime_limit_);
765 859
766 // Notify that the device has resumed from 1 hour of sleep. Verify that the 860 // Notify that the device has resumed from 1 hour of sleep. Verify that the
767 // device reboots immediately. 861 // device reboots immediately.
768 NotifyResumed(true); 862 NotifyResumed(true);
769 } 863 }
770 864
771 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The 865 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The
772 // current uptime is 12 hours. 866 // current uptime is 12 hours.
773 // Verifies that when the device is suspended and then resumes, it does not 867 // Verifies that when the device is suspended and then resumes, it does not
774 // immediately reboot. 868 // immediately reboot.
775 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeInGracePeriod) { 869 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeInGracePeriod) {
776 is_user_logged_in_ = true; 870 is_user_logged_in_ = true;
777 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 871 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
778 872
779 // Verify that the device does not reboot immediately. 873 // Verify that no reboot is requested and the device does not reboot
874 // immediately.
875 ExpectNoRebootRequest();
780 CreateAutomaticRebootManager(false); 876 CreateAutomaticRebootManager(false);
877 VerifyNoRebootRequested();
781 878
782 // Set the uptime limit. Verify that the device does not reboot immediately. 879 // Set the uptime limit. Verify that a reboot is requested but the device does
880 // not reboot immediately.
881 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
783 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 882 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
784 883
785 // Verify that a grace period has started. 884 // Verify that a grace period has started.
786 VerifyGracePeriod(uptime_limit_); 885 VerifyGracePeriod(uptime_limit_);
787 886
788 // Notify that the device has resumed from 1 hour of sleep. Verify that the 887 // Notify that the device has resumed from 1 hour of sleep. Verify that the
789 // device does not reboot immediately. 888 // device does not reboot immediately.
790 NotifyResumed(false); 889 NotifyResumed(false);
791 890
792 // Verify that the device does not reboot eventually. 891 // Verify that the device never reboots.
793 FastForwardUntilNoTasksRemain(false); 892 FastForwardUntilNoTasksRemain(false);
794 } 893 }
795 894
796 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The 895 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The
797 // current uptime is 29 hours 30 minutes. 896 // current uptime is 29 hours 30 minutes.
798 // Verifies that when the device is suspended and then resumes, it immediately 897 // Verifies that when the device is suspended and then resumes, it immediately
799 // reboots. 898 // reboots.
800 TEST_F(AutomaticRebootManagerBasicTest, ResumeAfterGracePeriod) { 899 TEST_F(AutomaticRebootManagerBasicTest, ResumeAfterGracePeriod) {
801 is_user_logged_in_ = true; 900 is_user_logged_in_ = true;
802 is_logged_in_as_kiosk_app_ = true; 901 is_logged_in_as_kiosk_app_ = true;
803 task_runner_->SetUptime(base::TimeDelta::FromHours(29) + 902 task_runner_->SetUptime(base::TimeDelta::FromHours(29) +
804 base::TimeDelta::FromMinutes(30)); 903 base::TimeDelta::FromMinutes(30));
805 904
806 // Verify that the device does not reboot immediately. 905 // Verify that no reboot is requested and the device does not reboot
906 // immediately.
907 ExpectNoRebootRequest();
807 CreateAutomaticRebootManager(false); 908 CreateAutomaticRebootManager(false);
909 VerifyNoRebootRequested();
808 910
809 // Set the uptime limit. Verify that the device does not reboot immediately. 911 // Set the uptime limit. Verify that a reboot is requested but the device does
912 // not reboot immediately.
913 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
810 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 914 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
811 915
812 // Verify that a grace period has started. 916 // Verify that a grace period has started.
813 VerifyGracePeriod(uptime_limit_); 917 VerifyGracePeriod(uptime_limit_);
814 918
815 // Notify that the device has resumed from 1 hour of sleep. Verify that the 919 // Notify that the device has resumed from 1 hour of sleep. Verify that the
816 // device reboots immediately. 920 // device reboots immediately.
817 NotifyResumed(true); 921 NotifyResumed(true);
818 } 922 }
819 923
820 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The 924 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The
821 // current uptime is 29 hours 30 minutes. 925 // current uptime is 29 hours 30 minutes.
822 // Verifies that when the device is suspended and then resumes, it does not 926 // Verifies that when the device is suspended and then resumes, it does not
823 // immediately reboot. 927 // immediately reboot.
824 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAfterGracePeriod) { 928 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAfterGracePeriod) {
825 is_user_logged_in_ = true; 929 is_user_logged_in_ = true;
826 task_runner_->SetUptime(base::TimeDelta::FromHours(29) + 930 task_runner_->SetUptime(base::TimeDelta::FromHours(29) +
827 base::TimeDelta::FromMinutes(30)); 931 base::TimeDelta::FromMinutes(30));
828 932
829 // Verify that the device does not reboot immediately. 933 // Verify that no reboot is requested and the device does not reboot
934 // immediately.
935 ExpectNoRebootRequest();
830 CreateAutomaticRebootManager(false); 936 CreateAutomaticRebootManager(false);
937 VerifyNoRebootRequested();
831 938
832 // Set the uptime limit. Verify that the device does not reboot immediately. 939 // Set the uptime limit. Verify that a reboot is requested but the device does
940 // not reboot immediately.
941 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
833 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 942 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
834 943
835 // Verify that a grace period has started. 944 // Verify that a grace period has started.
836 VerifyGracePeriod(uptime_limit_); 945 VerifyGracePeriod(uptime_limit_);
837 946
838 // Notify that the device has resumed from 1 hour of sleep. Verify that the 947 // Notify that the device has resumed from 1 hour of sleep. Verify that the
839 // device does not reboot immediately. 948 // device does not reboot immediately.
840 NotifyResumed(false); 949 NotifyResumed(false);
841 950
842 // Verify that the device does not reboot eventually. 951 // Verify that the device never reboots.
843 FastForwardUntilNoTasksRemain(false); 952 FastForwardUntilNoTasksRemain(false);
844 } 953 }
845 954
846 // Chrome is running. The current uptime is 10 days. 955 // Chrome is running. The current uptime is 10 days.
847 // Verifies that when the browser terminates, the device does not immediately 956 // Verifies that when the browser terminates, the device does not immediately
848 // reboot. 957 // reboot.
849 TEST_P(AutomaticRebootManagerTest, TerminateNoPolicy) { 958 TEST_P(AutomaticRebootManagerTest, TerminateNoPolicy) {
850 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 959 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
851 960
852 // Verify that the device does not reboot immediately. 961 // Verify that no reboot is requested and the device does not reboot
962 // immediately.
963 ExpectNoRebootRequest();
853 CreateAutomaticRebootManager(false); 964 CreateAutomaticRebootManager(false);
965 VerifyNoRebootRequested();
854 966
855 // Verify that no grace period has started. 967 // Verify that no grace period has started.
856 VerifyNoGracePeriod(); 968 VerifyNoGracePeriod();
857 969
858 // Notify that the browser is terminating. Verify that the device does not 970 // Notify that the browser is terminating. Verify that no reboot is requested
859 // reboot immediately. 971 // and the device does not reboot immediately.
860 NotifyTerminating(false); 972 NotifyTerminating(false);
861 973
862 // Verify that the device does not reboot eventually. 974 // Verify that a reboot is never requested and the device never reboots.
863 FastForwardUntilNoTasksRemain(false); 975 FastForwardUntilNoTasksRemain(false);
864 } 976 }
865 977
866 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is 978 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is
867 // 12 hours. 979 // 12 hours.
868 // Verifies that when the browser terminates, it does not immediately reboot. 980 // Verifies that when the browser terminates, it does not immediately reboot.
869 TEST_P(AutomaticRebootManagerTest, TerminateBeforeGracePeriod) { 981 TEST_P(AutomaticRebootManagerTest, TerminateBeforeGracePeriod) {
870 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 982 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
871 983
872 // Verify that the device does not reboot immediately. 984 // Verify that no reboot is requested and the device does not reboot
985 // immediately.
986 ExpectNoRebootRequest();
873 CreateAutomaticRebootManager(false); 987 CreateAutomaticRebootManager(false);
988 VerifyNoRebootRequested();
874 989
875 // Set the uptime limit. Verify that the device does not reboot immediately. 990 // Set the uptime limit. Verify that no reboot is requested and the device
991 // does not reboot immediately.
876 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 992 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
877 993
878 // Verify that a grace period has been scheduled to start in the future. 994 // Verify that a grace period has been scheduled to start in the future.
879 VerifyGracePeriod(uptime_limit_); 995 VerifyGracePeriod(uptime_limit_);
880 996
881 // Notify that the browser is terminating. Verify that the device does not 997 // Notify that the browser is terminating. Verify that no reboot is requested
882 // reboot immediately. 998 // and the device does not reboot immediately.
883 NotifyTerminating(false); 999 NotifyTerminating(false);
884 1000
885 // Verify that unless a non-kiosk-app session is in progress, the device 1001 // Verify that a reboot is requested eventually and unless a non-kiosk-app
886 // eventually reboots. 1002 // session is in progress, the device eventually reboots.
1003 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
887 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1004 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
888 is_logged_in_as_kiosk_app_); 1005 is_logged_in_as_kiosk_app_);
889 } 1006 }
890 1007
891 // Chrome is running. The uptime limit is set to 6 hours. The current uptime is 1008 // Chrome is running. The uptime limit is set to 6 hours. The current uptime is
892 // 12 hours. 1009 // 12 hours.
893 // Verifies that when the browser terminates, the device immediately reboots if 1010 // Verifies that when the browser terminates, the device immediately reboots if
894 // a kiosk app session is in progress. 1011 // a kiosk app session is in progress.
895 TEST_P(AutomaticRebootManagerTest, TerminateInGracePeriod) { 1012 TEST_P(AutomaticRebootManagerTest, TerminateInGracePeriod) {
896 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1013 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
897 1014
898 // Verify that the device does not reboot immediately. 1015 // Verify that no reboot is requested and the device does not reboot
1016 // immediately.
1017 ExpectNoRebootRequest();
899 CreateAutomaticRebootManager(false); 1018 CreateAutomaticRebootManager(false);
1019 VerifyNoRebootRequested();
900 1020
901 // Set the uptime limit. Verify that the device does not reboot immediately. 1021 // Set the uptime limit. Verify that a reboot is requested but the device does
1022 // not reboot immediately.
1023 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
902 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 1024 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
903 1025
904 // Verify that a grace period has started. 1026 // Verify that a grace period has started.
905 VerifyGracePeriod(uptime_limit_); 1027 VerifyGracePeriod(uptime_limit_);
906 1028
907 // Notify that the browser is terminating. Verify that the device immediately 1029 // Notify that the browser is terminating. Verify that the device immediately
908 // reboots if a kiosk app session is in progress. 1030 // reboots if a kiosk app session is in progress.
909 NotifyTerminating(is_logged_in_as_kiosk_app_); 1031 NotifyTerminating(is_logged_in_as_kiosk_app_);
910 1032
911 // Verify that if a non-kiosk-app session is in progress, the device does not 1033 // Verify that if a non-kiosk-app session is in progress, the device never
912 // reboot eventually. 1034 // reboots.
913 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1035 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
914 is_logged_in_as_kiosk_app_); 1036 is_logged_in_as_kiosk_app_);
915 } 1037 }
916 1038
917 // Chrome is running. The current uptime is 12 hours. 1039 // Chrome is running. The current uptime is 12 hours.
918 // Verifies that when the uptime limit is set to 24 hours, no reboot occurs and 1040 // Verifies that when the uptime limit is set to 24 hours, no reboot occurs and
919 // a grace period is scheduled to begin after 24 hours of uptime. 1041 // a grace period is scheduled to begin after 24 hours of uptime.
920 TEST_P(AutomaticRebootManagerTest, BeforeUptimeLimitGracePeriod) { 1042 TEST_P(AutomaticRebootManagerTest, BeforeUptimeLimitGracePeriod) {
921 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1043 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
922 1044
923 // Verify that the device does not reboot immediately. 1045 // Verify that no reboot is requested and the device does not reboot
1046 // immediately.
1047 ExpectNoRebootRequest();
924 CreateAutomaticRebootManager(false); 1048 CreateAutomaticRebootManager(false);
1049 VerifyNoRebootRequested();
925 1050
926 // Verify that no grace period has started. 1051 // Verify that no grace period has started.
927 VerifyNoGracePeriod(); 1052 VerifyNoGracePeriod();
928 1053
929 // Set the uptime limit. Verify that the device does not reboot immediately. 1054 // Set the uptime limit. Verify that no reboot is requested and the device
1055 // does not reboot immediately.
930 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 1056 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
931 1057
932 // Verify that a grace period has been scheduled to start in the future. 1058 // Verify that a grace period has been scheduled to start in the future.
933 VerifyGracePeriod(uptime_limit_); 1059 VerifyGracePeriod(uptime_limit_);
934 1060
935 // Verify that unless a non-kiosk-app session is in progress, the device 1061 // Verify that a reboot is requested eventually and unless a non-kiosk-app
936 // eventually reboots. 1062 // session is in progress, the device eventually reboots.
1063 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
937 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1064 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
938 is_logged_in_as_kiosk_app_); 1065 is_logged_in_as_kiosk_app_);
939 } 1066 }
940 1067
941 // Chrome is running. The current uptime is 12 hours. 1068 // Chrome is running. The current uptime is 12 hours.
942 // Verifies that when the uptime limit is set to 6 hours, a reboot is requested 1069 // Verifies that when the uptime limit is set to 6 hours, a reboot is requested
943 // and a grace period is started that will end after 6 + 24 hours of uptime. 1070 // and a grace period is started that will end after 6 + 24 hours of uptime.
944 TEST_P(AutomaticRebootManagerTest, InUptimeLimitGracePeriod) { 1071 TEST_P(AutomaticRebootManagerTest, InUptimeLimitGracePeriod) {
945 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1072 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
946 1073
947 // Verify that the device does not reboot immediately. 1074 // Verify that no reboot is requested and the device does not reboot
1075 // immediately.
1076 ExpectNoRebootRequest();
948 CreateAutomaticRebootManager(false); 1077 CreateAutomaticRebootManager(false);
1078 VerifyNoRebootRequested();
949 1079
950 // Verify that no grace period has started. 1080 // Verify that no grace period has started.
951 VerifyNoGracePeriod(); 1081 VerifyNoGracePeriod();
952 1082
953 // Set the uptime limit. Verify that the device does not reboot immediately. 1083 // Set the uptime limit. Verify that a reboot is requested but the device does
1084 // not reboot immediately.
1085 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
954 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 1086 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
955 1087
956 // Verify that a grace period has started. 1088 // Verify that a grace period has started.
957 VerifyGracePeriod(uptime_limit_); 1089 VerifyGracePeriod(uptime_limit_);
958 1090
959 // Verify that unless a non-kiosk-app session is in progress, the device 1091 // Verify that unless a non-kiosk-app session is in progress, the device
960 // eventually reboots. 1092 // eventually reboots.
961 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1093 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
962 is_logged_in_as_kiosk_app_); 1094 is_logged_in_as_kiosk_app_);
963 } 1095 }
964 1096
965 // Chrome is running. The current uptime is 10 days. 1097 // Chrome is running. The current uptime is 10 days.
966 // Verifies that when the uptime limit is set to 6 hours, the device reboots 1098 // Verifies that when the uptime limit is set to 6 hours, the device reboots
967 // immediately if no non-kiosk-app-session is in progress because the grace 1099 // immediately if no non-kiosk-app-session is in progress because the grace
968 // period ended after 6 + 24 hours of uptime. 1100 // period ended after 6 + 24 hours of uptime.
969 TEST_P(AutomaticRebootManagerTest, AfterUptimeLimitGracePeriod) { 1101 TEST_P(AutomaticRebootManagerTest, AfterUptimeLimitGracePeriod) {
970 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 1102 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
971 1103
972 // Verify that the device does not reboot immediately. 1104 // Verify that no reboot is requested and the device does not reboot
1105 // immediately.
1106 ExpectNoRebootRequest();
973 CreateAutomaticRebootManager(false); 1107 CreateAutomaticRebootManager(false);
1108 VerifyNoRebootRequested();
974 1109
975 // Verify that no grace period has started. 1110 // Verify that no grace period has started.
976 VerifyNoGracePeriod(); 1111 VerifyNoGracePeriod();
977 1112
978 // Set the uptime limit. Verify that unless a non-kiosk-app session is in 1113 // Set the uptime limit. Verify that a reboot is requested and unless a
979 // progress, the the device immediately reboots. 1114 // non-kiosk-app session is in progress, the the device immediately reboots.
1115 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
980 SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ || 1116 SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ ||
981 is_logged_in_as_kiosk_app_); 1117 is_logged_in_as_kiosk_app_);
982 1118
983 // Verify that if a non-kiosk-app session is in progress, the device does not 1119 // Verify that if a non-kiosk-app session is in progress, the device never
984 // reboot eventually. 1120 // reboots.
985 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1121 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
986 is_logged_in_as_kiosk_app_); 1122 is_logged_in_as_kiosk_app_);
987 } 1123 }
988 1124
989 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is 1125 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
990 // 6 hours. 1126 // 6 hours.
991 // Verifies that when the uptime limit is removed, the grace period is removed. 1127 // Verifies that when the uptime limit is removed, the grace period is removed.
992 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffBeforeGracePeriod) { 1128 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffBeforeGracePeriod) {
993 task_runner_->SetUptime(base::TimeDelta::FromHours(6)); 1129 task_runner_->SetUptime(base::TimeDelta::FromHours(6));
994 1130
995 // Verify that the device does not reboot immediately. 1131 // Verify that no reboot is requested and the device does not reboot
1132 // immediately.
1133 ExpectNoRebootRequest();
996 CreateAutomaticRebootManager(false); 1134 CreateAutomaticRebootManager(false);
1135 VerifyNoRebootRequested();
997 1136
998 // Set the uptime limit. Verify that the device does not reboot immediately. 1137 // Set the uptime limit. Verify that no reboot is requested and the device
1138 // does not reboot immediately.
999 SetUptimeLimit(base::TimeDelta::FromHours(12), false); 1139 SetUptimeLimit(base::TimeDelta::FromHours(12), false);
1000 1140
1001 // Verify that a grace period has been scheduled to start in the future. 1141 // Verify that a grace period has been scheduled to start in the future.
1002 VerifyGracePeriod(uptime_limit_); 1142 VerifyGracePeriod(uptime_limit_);
1003 1143
1004 // Fast forward the uptime by 1 hour. Verify that the device does not reboot 1144 // Fast forward the uptime by 1 hour. Verify that no reboot is requested and
1005 // immediately. 1145 // the device does not reboot immediately.
1006 FastForwardBy(base::TimeDelta::FromHours(1), false); 1146 FastForwardBy(base::TimeDelta::FromHours(1), false);
1007 1147
1008 // Remove the uptime limit. Verify that the device does not reboot 1148 // Remove the uptime limit. Verify that no reboot is requested and the device
1009 // immediately. 1149 // does not reboot immediately.
1010 SetUptimeLimit(base::TimeDelta(), false); 1150 SetUptimeLimit(base::TimeDelta(), false);
1011 1151
1012 // Verify that the grace period has been removed. 1152 // Verify that the grace period has been removed.
1013 VerifyNoGracePeriod(); 1153 VerifyNoGracePeriod();
1014 1154
1015 // Verify that the device does not reboot eventually. 1155 // Verify that a reboot is never requested and the device never reboots.
1016 FastForwardUntilNoTasksRemain(false); 1156 FastForwardUntilNoTasksRemain(false);
1017 } 1157 }
1018 1158
1019 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is 1159 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
1020 // 24 hours. 1160 // 24 hours.
1021 // Verifies that when the uptime limit is removed, the grace period is removed. 1161 // Verifies that when the uptime limit is removed, the grace period is removed.
1022 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffInGracePeriod) { 1162 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffInGracePeriod) {
1023 task_runner_->SetUptime(base::TimeDelta::FromHours(24)); 1163 task_runner_->SetUptime(base::TimeDelta::FromHours(24));
1024 1164
1025 // Verify that the device does not reboot immediately. 1165 // Verify that no reboot is requested and the device does not reboot
1166 // immediately.
1167 ExpectNoRebootRequest();
1026 CreateAutomaticRebootManager(false); 1168 CreateAutomaticRebootManager(false);
1169 VerifyNoRebootRequested();
1027 1170
1028 // Set the uptime limit. Verify that the device does not reboot immediately. 1171 // Set the uptime limit. Verify that a reboot is requested but the device does
1172 // not reboot immediately.
1173 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1029 SetUptimeLimit(base::TimeDelta::FromHours(12), false); 1174 SetUptimeLimit(base::TimeDelta::FromHours(12), false);
1030 1175
1031 // Verify that a grace period has started. 1176 // Verify that a grace period has started.
1032 VerifyGracePeriod(uptime_limit_); 1177 VerifyGracePeriod(uptime_limit_);
1033 1178
1034 // Fast forward the uptime by 20 seconds. Verify that the device does not 1179 // Fast forward the uptime by 20 seconds. Verify that the device does not
1035 // reboot immediately. 1180 // reboot immediately.
1036 FastForwardBy(base::TimeDelta::FromSeconds(20), false); 1181 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1037 1182
1038 // Remove the uptime limit. Verify that the device does not reboot 1183 // Remove the uptime limit. Verify that the device does not reboot
1039 // immediately. 1184 // immediately.
1040 SetUptimeLimit(base::TimeDelta(), false); 1185 SetUptimeLimit(base::TimeDelta(), false);
1041 1186
1042 // Verify that the grace period has been removed. 1187 // Verify that the grace period has been removed.
1043 VerifyNoGracePeriod(); 1188 VerifyNoGracePeriod();
1044 1189
1045 // Verify that the device does not reboot eventually. 1190 // Verify that the device never reboots.
1046 FastForwardUntilNoTasksRemain(false); 1191 FastForwardUntilNoTasksRemain(false);
1047 } 1192 }
1048 1193
1049 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is 1194 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
1050 // 6 hours. 1195 // 6 hours.
1051 // Verifies that when the uptime limit is extended to 24 hours, the grace period 1196 // Verifies that when the uptime limit is extended to 24 hours, the grace period
1052 // is rescheduled to start further in the future. 1197 // is rescheduled to start further in the future.
1053 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitBeforeGracePeriod) { 1198 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitBeforeGracePeriod) {
1054 task_runner_->SetUptime(base::TimeDelta::FromHours(6)); 1199 task_runner_->SetUptime(base::TimeDelta::FromHours(6));
1055 1200
1056 // Verify that the device does not reboot immediately. 1201 // Verify that no reboot is requested and the device does not reboot
1202 // immediately.
1203 ExpectNoRebootRequest();
1057 CreateAutomaticRebootManager(false); 1204 CreateAutomaticRebootManager(false);
1205 VerifyNoRebootRequested();
1058 1206
1059 // Set the uptime limit. Verify that the device does not reboot immediately. 1207 // Set the uptime limit. Verify that no reboot is requested and the device
1208 // does not reboot immediately.
1060 SetUptimeLimit(base::TimeDelta::FromHours(12), false); 1209 SetUptimeLimit(base::TimeDelta::FromHours(12), false);
1061 1210
1062 // Verify that a grace period has been scheduled to start in the future. 1211 // Verify that a grace period has been scheduled to start in the future.
1063 VerifyGracePeriod(uptime_limit_); 1212 VerifyGracePeriod(uptime_limit_);
1064 1213
1065 // Fast forward the uptime by 20 seconds. Verify that the device does not 1214 // Fast forward the uptime by 20 seconds. Verify that no reboot is requested
1066 // reboot immediately. 1215 // and the device does not reboot immediately.
1067 FastForwardBy(base::TimeDelta::FromSeconds(20), false); 1216 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1068 1217
1069 // Extend the uptime limit. Verify that the device does not reboot 1218 // Extend the uptime limit. Verify that no reboot is requested and the device
1070 // immediately. 1219 // does not reboot immediately.
1071 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 1220 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1072 1221
1073 // Verify that the grace period has been rescheduled to start further in the 1222 // Verify that the grace period has been rescheduled to start further in the
1074 // future. 1223 // future.
1075 VerifyGracePeriod(uptime_limit_); 1224 VerifyGracePeriod(uptime_limit_);
1076 1225
1077 // Verify that unless a non-kiosk-app session is in progress, the device 1226 // Verify that a reboot is requested eventually and unless a non-kiosk-app
1078 // eventually reboots. 1227 // session is in progress, the device eventually reboots.
1228 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1079 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1229 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1080 is_logged_in_as_kiosk_app_); 1230 is_logged_in_as_kiosk_app_);
1081 } 1231 }
1082 1232
1083 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is 1233 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
1084 // 18 hours. 1234 // 18 hours.
1085 // Verifies that when the uptime limit is extended to 24 hours, the grace period 1235 // Verifies that when the uptime limit is extended to 24 hours, the grace period
1086 // is rescheduled to start in the future. 1236 // is rescheduled to start in the future.
1087 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitInGracePeriod) { 1237 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitInGracePeriod) {
1088 task_runner_->SetUptime(base::TimeDelta::FromHours(18)); 1238 task_runner_->SetUptime(base::TimeDelta::FromHours(18));
1089 1239
1090 // Verify that the device does not reboot immediately. 1240 // Verify that no reboot is requested and the device does not reboot
1241 // immediately.
1242 ExpectNoRebootRequest();
1091 CreateAutomaticRebootManager(false); 1243 CreateAutomaticRebootManager(false);
1244 VerifyNoRebootRequested();
1092 1245
1093 // Set the uptime limit. Verify that the device does not reboot immediately. 1246 // Set the uptime limit. Verify that a reboot is requested but the device does
1247 // not reboot immediately.
1248 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1094 SetUptimeLimit(base::TimeDelta::FromHours(12), false); 1249 SetUptimeLimit(base::TimeDelta::FromHours(12), false);
1095 1250
1096 // Verify that a grace period has started. 1251 // Verify that a grace period has started.
1097 VerifyGracePeriod(uptime_limit_); 1252 VerifyGracePeriod(uptime_limit_);
1098 1253
1099 // Fast forward the uptime by 20 seconds. Verify that the device does not 1254 // Fast forward the uptime by 20 seconds. Verify that the device does not
1100 // reboot immediately. 1255 // reboot immediately.
1101 FastForwardBy(base::TimeDelta::FromSeconds(20), false); 1256 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1102 1257
1103 // Extend the uptime limit. Verify that the device does not reboot 1258 // Extend the uptime limit. Verify that the device does not reboot
1104 // immediately. 1259 // immediately.
1105 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 1260 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1106 1261
1107 // Verify that the grace period has been rescheduled to start in the future. 1262 // Verify that the grace period has been rescheduled to start in the future.
1108 VerifyGracePeriod(uptime_limit_); 1263 VerifyGracePeriod(uptime_limit_);
1109 1264
1110 // Verify that unless a non-kiosk-app session is in progress, the device 1265 // Verify that a reboot is requested again eventually and unless a
1111 // eventually reboots. 1266 // non-kiosk-app session is in progress, the device eventually reboots.
1267 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1112 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1268 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1113 is_logged_in_as_kiosk_app_); 1269 is_logged_in_as_kiosk_app_);
1114 } 1270 }
1115 1271
1116 // Chrome is running. The uptime limit is set to 18 hours. The current uptime is 1272 // Chrome is running. The uptime limit is set to 18 hours. The current uptime is
1117 // 12 hours. 1273 // 12 hours.
1118 // Verifies that when the uptime limit is shortened to 6 hours, the grace period 1274 // Verifies that when the uptime limit is shortened to 6 hours, the grace period
1119 // is rescheduled to have already started. 1275 // is rescheduled to have already started.
1120 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitBeforeToInGracePeriod) { 1276 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitBeforeToInGracePeriod) {
1121 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1277 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1122 1278
1123 // Verify that the device does not reboot immediately. 1279 // Verify that no reboot is requested and the device does not reboot
1280 // immediately.
1281 ExpectNoRebootRequest();
1124 CreateAutomaticRebootManager(false); 1282 CreateAutomaticRebootManager(false);
1283 VerifyNoRebootRequested();
1125 1284
1126 // Set the uptime limit. Verify that the device does not reboot immediately. 1285 // Set the uptime limit. Verify that no reboot is requested and the device
1286 // does not reboot immediately.
1127 SetUptimeLimit(base::TimeDelta::FromHours(18), false); 1287 SetUptimeLimit(base::TimeDelta::FromHours(18), false);
1128 1288
1129 // Verify that a grace period has been scheduled to start in the future. 1289 // Verify that a grace period has been scheduled to start in the future.
1130 VerifyGracePeriod(uptime_limit_); 1290 VerifyGracePeriod(uptime_limit_);
1131 1291
1132 // Fast forward the uptime by 20 seconds. Verify that the device does not 1292 // Fast forward the uptime by 20 seconds. Verify that no reboot is requested
1133 // reboot immediately. 1293 // and the device does not reboot immediately.
1134 FastForwardBy(base::TimeDelta::FromSeconds(20), false); 1294 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1135 1295
1136 // Shorten the uptime limit. Verify that the device does not reboot 1296 // Shorten the uptime limit. Verify that a reboot is requested but the device
1137 // immediately. 1297 // does not reboot immediately.
1298 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1138 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 1299 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1139 1300
1140 // Verify that the grace period has been rescheduled and has started already. 1301 // Verify that the grace period has been rescheduled and has started already.
1141 VerifyGracePeriod(uptime_limit_); 1302 VerifyGracePeriod(uptime_limit_);
1142 1303
1143 // Verify that unless a non-kiosk-app session is in progress, the device 1304 // Verify that unless a non-kiosk-app session is in progress, the device
1144 // eventually reboots. 1305 // eventually reboots.
1145 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1306 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1146 is_logged_in_as_kiosk_app_); 1307 is_logged_in_as_kiosk_app_);
1147 } 1308 }
1148 1309
1149 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is 1310 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is
1150 // 36 hours. 1311 // 36 hours.
1151 // Verifies that when the uptime limit is shortened to 18 hours, the grace 1312 // Verifies that when the uptime limit is shortened to 18 hours, the grace
1152 // period is rescheduled to have started earlier. 1313 // period is rescheduled to have started earlier.
1153 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToInGracePeriod) { 1314 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToInGracePeriod) {
1154 task_runner_->SetUptime(base::TimeDelta::FromHours(36)); 1315 task_runner_->SetUptime(base::TimeDelta::FromHours(36));
1155 1316
1156 // Verify that the device does not reboot immediately. 1317 // Verify that no reboot is requested and the device does not reboot
1318 // immediately.
1319 ExpectNoRebootRequest();
1157 CreateAutomaticRebootManager(false); 1320 CreateAutomaticRebootManager(false);
1321 VerifyNoRebootRequested();
1158 1322
1159 // Set the uptime limit. Verify that the device does not reboot immediately. 1323 // Set the uptime limit. Verify that a reboot is requested but the device does
1324 // not reboot immediately.
1325 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1160 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 1326 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1161 1327
1162 // Verify that a grace period has started. 1328 // Verify that a grace period has started.
1163 VerifyGracePeriod(uptime_limit_); 1329 VerifyGracePeriod(uptime_limit_);
1164 1330
1165 // Fast forward the uptime by 20 seconds. Verify that the device does not 1331 // Fast forward the uptime by 20 seconds. Verify that the device does not
1166 // reboot immediately. 1332 // reboot immediately.
1167 FastForwardBy(base::TimeDelta::FromSeconds(20), false); 1333 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1168 1334
1169 // Shorten the uptime limit. Verify that the device does not reboot 1335 // Shorten the uptime limit. Verify that a reboot is requested again but the
1170 // immediately. 1336 // device does not reboot immediately.
1337 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1171 SetUptimeLimit(base::TimeDelta::FromHours(18), false); 1338 SetUptimeLimit(base::TimeDelta::FromHours(18), false);
1172 1339
1173 // Verify that the grace period has been rescheduled to have started earlier. 1340 // Verify that the grace period has been rescheduled to have started earlier.
1174 VerifyGracePeriod(uptime_limit_); 1341 VerifyGracePeriod(uptime_limit_);
1175 1342
1176 // Verify that unless a non-kiosk-app session is in progress, the device 1343 // Verify that unless a non-kiosk-app session is in progress, the device
1177 // eventually reboots. 1344 // eventually reboots.
1178 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1345 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1179 is_logged_in_as_kiosk_app_); 1346 is_logged_in_as_kiosk_app_);
1180 } 1347 }
1181 1348
1182 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is 1349 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is
1183 // 36 hours. 1350 // 36 hours.
1184 // Verifies that when the uptime limit is shortened to 6 hours, the device 1351 // Verifies that when the uptime limit is shortened to 6 hours, the device
1185 // reboots immediately if no non-kiosk-app session is in progress because the 1352 // reboots immediately if no non-kiosk-app session is in progress because the
1186 // grace period ended after 6 + 24 hours of uptime. 1353 // grace period ended after 6 + 24 hours of uptime.
1187 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToAfterGracePeriod) { 1354 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToAfterGracePeriod) {
1188 task_runner_->SetUptime(base::TimeDelta::FromHours(36)); 1355 task_runner_->SetUptime(base::TimeDelta::FromHours(36));
1189 1356
1190 // Verify that the device does not reboot immediately. 1357 // Verify that no reboot is requested and the device does not reboot
1358 // immediately.
1359 ExpectNoRebootRequest();
1191 CreateAutomaticRebootManager(false); 1360 CreateAutomaticRebootManager(false);
1361 VerifyNoRebootRequested();
1192 1362
1193 // Set the uptime limit. Verify that the device does not reboot immediately. 1363 // Set the uptime limit. Verify that a reboot is requested but the device does
1364 // not reboot immediately.
1365 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1194 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 1366 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1195 1367
1196 // Verify that a grace period has started. 1368 // Verify that a grace period has started.
1197 VerifyGracePeriod(uptime_limit_); 1369 VerifyGracePeriod(uptime_limit_);
1198 1370
1199 // Fast forward the uptime by 20 seconds. Verify that the device does not 1371 // Fast forward the uptime by 20 seconds. Verify that the device does not
1200 // reboot immediately. 1372 // reboot immediately.
1201 FastForwardBy(base::TimeDelta::FromSeconds(20), false); 1373 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1202 1374
1203 // Shorten the uptime limit. Verify that unless a non-kiosk-app session is in 1375 // Shorten the uptime limit. Verify that a reboot is requested again and
1204 // progress, the the device immediately reboots. 1376 // unless a non-kiosk-app session is in progress, the the device immediately
1377 // reboots.
1378 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1205 SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ || 1379 SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ ||
1206 is_logged_in_as_kiosk_app_); 1380 is_logged_in_as_kiosk_app_);
1207 1381
1208 // Verify that if a non-kiosk-app session is in progress, the device does not 1382 // Verify that if a non-kiosk-app session is in progress, the device never
1209 // reboot eventually. 1383 // reboots.
1210 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1384 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1211 is_logged_in_as_kiosk_app_); 1385 is_logged_in_as_kiosk_app_);
1212 } 1386 }
1213 1387
1214 // Chrome is running. The current uptime is 12 hours. 1388 // Chrome is running. The current uptime is 12 hours.
1215 // Verifies that when an update is applied, the current uptime is persisted as 1389 // Verifies that when an update is applied, the current uptime is persisted as
1216 // the time at which a reboot became necessary. Further verifies that when the 1390 // the time at which a reboot became necessary. Further verifies that when the
1217 // policy to automatically reboot after an update is not enabled, no reboot 1391 // policy to automatically reboot after an update is not enabled, no reboot
1218 // occurs and no grace period is scheduled. 1392 // occurs and no grace period is scheduled.
1219 TEST_P(AutomaticRebootManagerTest, UpdateNoPolicy) { 1393 TEST_P(AutomaticRebootManagerTest, UpdateNoPolicy) {
1220 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1394 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1221 1395
1222 // Verify that the device does not reboot immediately. 1396 // Verify that no reboot is requested and the device does not reboot
1397 // immediately.
1398 ExpectNoRebootRequest();
1223 CreateAutomaticRebootManager(false); 1399 CreateAutomaticRebootManager(false);
1400 VerifyNoRebootRequested();
1224 1401
1225 // Verify that no grace period has started. 1402 // Verify that no grace period has started.
1226 VerifyNoGracePeriod(); 1403 VerifyNoGracePeriod();
1227 1404
1228 // Notify that an update has been applied and a reboot is necessary. Verify 1405 // Notify that an update has been applied and a reboot is necessary. Verify
1229 // that the device does not reboot immediately. 1406 // that no reboot is requested and the device does not reboot immediately.
1230 NotifyUpdateRebootNeeded(); 1407 NotifyUpdateRebootNeeded();
1231 1408
1232 // Verify that the current uptime has been persisted as the time at which a 1409 // Verify that the current uptime has been persisted as the time at which a
1233 // reboot became necessary. 1410 // reboot became necessary.
1234 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1411 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1235 &update_reboot_needed_uptime_)); 1412 &update_reboot_needed_uptime_));
1236 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1413 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1237 1414
1238 // Verify that no grace period has started. 1415 // Verify that no grace period has started.
1239 VerifyNoGracePeriod(); 1416 VerifyNoGracePeriod();
1240 1417
1241 // Verify that the device does not reboot eventually. 1418 // Verify that a reboot is never requested and the device never reboots.
1242 FastForwardUntilNoTasksRemain(false); 1419 FastForwardUntilNoTasksRemain(false);
1243 } 1420 }
1244 1421
1245 // Chrome is running. The current uptime is 12 hours. 1422 // Chrome is running. The current uptime is 12 hours.
1246 // Verifies that when an update is applied, the current uptime is persisted as 1423 // Verifies that when an update is applied, the current uptime is persisted as
1247 // the time at which a reboot became necessary. Further verifies that when the 1424 // the time at which a reboot became necessary. Further verifies that when the
1248 // policy to automatically reboot after an update is enabled, a reboot is 1425 // policy to automatically reboot after an update is enabled, a reboot is
1249 // requested and a grace period is started that will end 24 hours from now. 1426 // requested and a grace period is started that will end 24 hours from now.
1250 TEST_P(AutomaticRebootManagerTest, Update) { 1427 TEST_P(AutomaticRebootManagerTest, Update) {
1251 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1428 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1252 SetRebootAfterUpdate(true, false); 1429 SetRebootAfterUpdate(true, false);
1253 1430
1254 // Verify that the device does not reboot immediately. 1431 // Verify that no reboot is requested and the device does not reboot
1432 // immediately.
1433 ExpectNoRebootRequest();
1255 CreateAutomaticRebootManager(false); 1434 CreateAutomaticRebootManager(false);
1435 VerifyNoRebootRequested();
1256 1436
1257 // Verify that no grace period has started. 1437 // Verify that no grace period has started.
1258 VerifyNoGracePeriod(); 1438 VerifyNoGracePeriod();
1259 1439
1260 // Notify that an update has been applied and a reboot is necessary. Verify 1440 // Notify that an update has been applied and a reboot is necessary. Verify
1261 // that the device does not reboot immediately. 1441 // that a reboot is requested but the device does not reboot immediately.
1442 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1262 NotifyUpdateRebootNeeded(); 1443 NotifyUpdateRebootNeeded();
1263 1444
1264 // Verify that the current uptime has been persisted as the time at which a 1445 // Verify that the current uptime has been persisted as the time at which a
1265 // reboot became necessary. 1446 // reboot became necessary.
1266 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1447 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1267 &update_reboot_needed_uptime_)); 1448 &update_reboot_needed_uptime_));
1268 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1449 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1269 1450
1270 // Verify that a grace period has started. 1451 // Verify that a grace period has started.
1271 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); 1452 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1272 1453
1273 // Verify that unless a non-kiosk-app session is in progress, the device 1454 // Verify that unless a non-kiosk-app session is in progress, the device
1274 // eventually reboots. 1455 // eventually reboots.
1275 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1456 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1276 is_logged_in_as_kiosk_app_); 1457 is_logged_in_as_kiosk_app_);
1277 } 1458 }
1278 1459
1279 // Chrome is running. The current uptime is 12 hours. 1460 // Chrome is running. The current uptime is 12 hours.
1280 // Verifies that when Chrome is notified twice that an update has been applied, 1461 // Verifies that when Chrome is notified twice that an update has been applied,
1281 // the second notification is ignored and the uptime at which it occured does 1462 // the second notification is ignored and the uptime at which it occurred does
1282 // not get persisted as the time at which an update became necessary. 1463 // not get persisted as the time at which an update became necessary.
1283 TEST_P(AutomaticRebootManagerTest, UpdateAfterUpdate) { 1464 TEST_P(AutomaticRebootManagerTest, UpdateAfterUpdate) {
1284 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1465 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1285 SetRebootAfterUpdate(true, false); 1466 SetRebootAfterUpdate(true, false);
1286 1467
1287 // Verify that the device does not reboot immediately. 1468 // Verify that no reboot is requested and the device does not reboot
1469 // immediately.
1470 ExpectNoRebootRequest();
1288 CreateAutomaticRebootManager(false); 1471 CreateAutomaticRebootManager(false);
1472 VerifyNoRebootRequested();
1289 1473
1290 // Verify that no grace period has started. 1474 // Verify that no grace period has started.
1291 VerifyNoGracePeriod(); 1475 VerifyNoGracePeriod();
1292 1476
1293 // Notify that an update has been applied and a reboot is necessary. Verify 1477 // Notify that an update has been applied and a reboot is necessary. Verify
1294 // that the device does not reboot immediately. 1478 // that a reboot is requested but the device does not reboot immediately.
1479 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1295 NotifyUpdateRebootNeeded(); 1480 NotifyUpdateRebootNeeded();
1296 1481
1297 // Verify that the current uptime has been persisted as the time at which a 1482 // Verify that the current uptime has been persisted as the time at which a
1298 // reboot became necessary. 1483 // reboot became necessary.
1299 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1484 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1300 &update_reboot_needed_uptime_)); 1485 &update_reboot_needed_uptime_));
1301 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1486 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1302 1487
1303 // Verify that a grace period has started. 1488 // Verify that a grace period has started.
1304 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); 1489 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
(...skipping 14 matching lines...) Expand all
1319 EXPECT_EQ(update_reboot_needed_uptime_, new_update_reboot_needed_uptime); 1504 EXPECT_EQ(update_reboot_needed_uptime_, new_update_reboot_needed_uptime);
1320 1505
1321 // Verify that unless a non-kiosk-app session is in progress, the device 1506 // Verify that unless a non-kiosk-app session is in progress, the device
1322 // eventually reboots. 1507 // eventually reboots.
1323 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1508 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1324 is_logged_in_as_kiosk_app_); 1509 is_logged_in_as_kiosk_app_);
1325 } 1510 }
1326 1511
1327 // Chrome is running. The current uptime is 10 minutes. 1512 // Chrome is running. The current uptime is 10 minutes.
1328 // Verifies that when the policy to automatically reboot after an update is 1513 // Verifies that when the policy to automatically reboot after an update is
1329 // enabled, no reboot occurs a grace period is scheduled to begin after the 1514 // enabled, no reboot occurs and a grace period is scheduled to begin after the
1330 // minimum of 1 hour of uptime. Further verifies that when an update is applied, 1515 // minimum of 1 hour of uptime. Further verifies that when an update is applied,
1331 // the current uptime is persisted as the time at which a reboot became 1516 // the current uptime is persisted as the time at which a reboot became
1332 // necessary. 1517 // necessary.
1333 TEST_P(AutomaticRebootManagerTest, UpdateBeforeMinimumUptime) { 1518 TEST_P(AutomaticRebootManagerTest, UpdateBeforeMinimumUptime) {
1334 task_runner_->SetUptime(base::TimeDelta::FromMinutes(10)); 1519 task_runner_->SetUptime(base::TimeDelta::FromMinutes(10));
1335 SetRebootAfterUpdate(true, false); 1520 SetRebootAfterUpdate(true, false);
1336 1521
1337 // Verify that the device does not reboot immediately. 1522 // Verify that no reboot is requested and the device does not reboot
1523 // immediately.
1524 ExpectNoRebootRequest();
1338 CreateAutomaticRebootManager(false); 1525 CreateAutomaticRebootManager(false);
1526 VerifyNoRebootRequested();
1339 1527
1340 // Verify that no grace period has started. 1528 // Verify that no grace period has started.
1341 VerifyNoGracePeriod(); 1529 VerifyNoGracePeriod();
1342 1530
1343 // Notify that an update has been applied and a reboot is necessary. Verify 1531 // Notify that an update has been applied and a reboot is necessary. Verify
1344 // that the device does not reboot immediately. 1532 // that no reboot is requested and the device does not reboot immediately.
1345 NotifyUpdateRebootNeeded(); 1533 NotifyUpdateRebootNeeded();
1346 1534
1347 // Verify that the current uptime has been persisted as the time at which a 1535 // Verify that the current uptime has been persisted as the time at which a
1348 // reboot became necessary. 1536 // reboot became necessary.
1349 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1537 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1350 &update_reboot_needed_uptime_)); 1538 &update_reboot_needed_uptime_));
1351 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1539 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1352 1540
1353 // Verify that a grace period has been scheduled to begin in the future. 1541 // Verify that a grace period has been scheduled to begin in the future.
1354 VerifyGracePeriod(base::TimeDelta::FromHours(1)); 1542 VerifyGracePeriod(base::TimeDelta::FromHours(1));
1355 1543
1356 // Verify that unless a non-kiosk-app session is in progress, the device 1544 // Verify that a reboot is requested eventually and unless a non-kiosk-app
1357 // eventually reboots. 1545 // session is in progress, the device eventually reboots.
1546 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1358 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1547 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1359 is_logged_in_as_kiosk_app_); 1548 is_logged_in_as_kiosk_app_);
1360 } 1549 }
1361 1550
1362 // Chrome is running. An update was applied and a reboot became necessary to 1551 // Chrome is running. An update was applied and a reboot became necessary to
1363 // complete the update process after 6 hours of uptime. The current uptime is 1552 // complete the update process after 6 hours of uptime. The current uptime is
1364 // 12 hours. 1553 // 12 hours.
1365 // Verifies that when the policy to automatically reboot after an update is 1554 // Verifies that when the policy to automatically reboot after an update is
1366 // enabled, a reboot is requested and a grace period is started that will end 1555 // enabled, a reboot is requested and a grace period is started that will end
1367 // after 6 + 24 hours of uptime. 1556 // after 6 + 24 hours of uptime.
1368 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateInGracePeriod) { 1557 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateInGracePeriod) {
1369 task_runner_->SetUptime(base::TimeDelta::FromHours(6)); 1558 task_runner_->SetUptime(base::TimeDelta::FromHours(6));
1370 1559
1371 // Verify that the device does not reboot immediately. 1560 // Verify that no reboot is requested and the device does not reboot
1561 // immediately.
1562 ExpectNoRebootRequest();
1372 CreateAutomaticRebootManager(false); 1563 CreateAutomaticRebootManager(false);
1564 VerifyNoRebootRequested();
1373 1565
1374 // Notify that an update has been applied and a reboot is necessary. Verify 1566 // Notify that an update has been applied and a reboot is necessary. Verify
1375 // that the device does not reboot immediately. 1567 // that no reboot is requested and the device does not reboot immediately.
1376 NotifyUpdateRebootNeeded(); 1568 NotifyUpdateRebootNeeded();
1377 1569
1378 // Fast forward the uptime to 12 hours. Verify that the device does not reboot 1570 // Fast forward the uptime to 12 hours. Verify that no reboot is requested and
1379 // immediately. 1571 // the device does not reboot immediately.
1380 FastForwardBy(base::TimeDelta::FromHours(6), false); 1572 FastForwardBy(base::TimeDelta::FromHours(6), false);
1381 1573
1382 // Simulate user activity. 1574 // Simulate user activity.
1383 automatic_reboot_manager_->OnUserActivity(NULL); 1575 automatic_reboot_manager_->OnUserActivity(NULL);
1384 1576
1385 // Enable automatic reboot after an update has been applied. Verify that the 1577 // Enable automatic reboot after an update has been applied. Verify that a
1386 // device does not reboot immediately. 1578 // reboot is requested but the device does not reboot immediately.
1579 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1387 SetRebootAfterUpdate(true, false); 1580 SetRebootAfterUpdate(true, false);
1388 1581
1389 // Verify that a grace period has started. 1582 // Verify that a grace period has started.
1390 VerifyGracePeriod(base::TimeDelta::FromHours(6) + uptime_processing_delay_); 1583 VerifyGracePeriod(base::TimeDelta::FromHours(6) + uptime_processing_delay_);
1391 1584
1392 // Verify that unless a non-kiosk-app session is in progress, the device 1585 // Verify that unless a non-kiosk-app session is in progress, the device
1393 // eventually reboots. 1586 // eventually reboots.
1394 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1587 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1395 is_logged_in_as_kiosk_app_); 1588 is_logged_in_as_kiosk_app_);
1396 } 1589 }
1397 1590
1398 // Chrome is running. An update was applied and a reboot became necessary to 1591 // Chrome is running. An update was applied and a reboot became necessary to
1399 // complete the update process after 6 hours of uptime. The current uptime is 1592 // complete the update process after 6 hours of uptime. The current uptime is
1400 // 10 days. 1593 // 10 days.
1401 // Verifies that when the policy to automatically reboot after an update is 1594 // Verifies that when the policy to automatically reboot after an update is
1402 // enabled, the device reboots immediately if no non-kiosk-app session is in 1595 // enabled, the device reboots immediately if no non-kiosk-app session is in
1403 // progress because the grace period ended after 6 + 24 hours of uptime. 1596 // progress because the grace period ended after 6 + 24 hours of uptime.
1404 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateAfterGracePeriod) { 1597 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateAfterGracePeriod) {
1405 task_runner_->SetUptime(base::TimeDelta::FromHours(6)); 1598 task_runner_->SetUptime(base::TimeDelta::FromHours(6));
1406 1599
1407 // Verify that the device does not reboot immediately. 1600 // Verify that no reboot is requested and the device does not reboot
1601 // immediately.
1602 ExpectNoRebootRequest();
1408 CreateAutomaticRebootManager(false); 1603 CreateAutomaticRebootManager(false);
1604 VerifyNoRebootRequested();
1409 1605
1410 // Notify that an update has been applied and a reboot is necessary. Verify 1606 // Notify that an update has been applied and a reboot is necessary. Verify
1411 // that the device does not reboot immediately. 1607 // that no reboot is requested and the device does not reboot immediately.
1412 NotifyUpdateRebootNeeded(); 1608 NotifyUpdateRebootNeeded();
1413 1609
1414 // Fast forward the uptime to 12 hours. Verify that the device does not reboot 1610 // Fast forward the uptime to 12 hours. Verify that no reboot is requested and
1415 // immediately. 1611 // the device does not reboot immediately.
1416 FastForwardBy(base::TimeDelta::FromDays(10) - base::TimeDelta::FromHours(6), 1612 FastForwardBy(base::TimeDelta::FromDays(10) - base::TimeDelta::FromHours(6),
1417 false); 1613 false);
1418 1614
1419 // Simulate user activity. 1615 // Simulate user activity.
1420 automatic_reboot_manager_->OnUserActivity(NULL); 1616 automatic_reboot_manager_->OnUserActivity(NULL);
1421 1617
1422 // Enable automatic rebooting after an update has been applied. Verify that 1618 // Enable automatic rebooting after an update has been applied. Verify that
1423 // unless a non-kiosk-app session is in progress, the the device immediately 1619 // a reboot is requested and unless a non-kiosk-app session is in progress,
1424 // reboots. 1620 // the the device immediately reboots.
1621 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1425 SetRebootAfterUpdate(true, !is_user_logged_in_ || is_logged_in_as_kiosk_app_); 1622 SetRebootAfterUpdate(true, !is_user_logged_in_ || is_logged_in_as_kiosk_app_);
1426 1623
1427 // Verify that if a non-kiosk-app session is in progress, the device does not 1624 // Verify that if a non-kiosk-app session is in progress, the device never
1428 // reboot eventually. 1625 // reboots.
1429 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1626 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1430 is_logged_in_as_kiosk_app_); 1627 is_logged_in_as_kiosk_app_);
1431 } 1628 }
1432 1629
1433 // Chrome is running. An update was applied and a reboot became necessary to 1630 // Chrome is running. An update was applied and a reboot became necessary to
1434 // complete the update process after 6 hours of uptime. The policy to 1631 // complete the update process after 6 hours of uptime. The policy to
1435 // automatically reboot after an update is enabled. The current uptime is 1632 // automatically reboot after an update is enabled. The current uptime is
1436 // 6 hours 20 seconds. 1633 // 6 hours 20 seconds.
1437 // Verifies that when the policy to automatically reboot after an update is 1634 // Verifies that when the policy to automatically reboot after an update is
1438 // disabled, the reboot request and grace period are removed. 1635 // disabled, the reboot request and grace period are removed.
1439 TEST_P(AutomaticRebootManagerTest, PolicyOffAfterUpdate) { 1636 TEST_P(AutomaticRebootManagerTest, PolicyOffAfterUpdate) {
1440 task_runner_->SetUptime(base::TimeDelta::FromHours(6)); 1637 task_runner_->SetUptime(base::TimeDelta::FromHours(6));
1441 SetRebootAfterUpdate(true, false); 1638 SetRebootAfterUpdate(true, false);
1442 1639
1443 // Verify that the device does not reboot immediately. 1640 // Verify that no reboot is requested and the device does not reboot
1641 // immediately.
1642 ExpectNoRebootRequest();
1444 CreateAutomaticRebootManager(false); 1643 CreateAutomaticRebootManager(false);
1644 VerifyNoRebootRequested();
1445 1645
1446 // Notify that an update has been applied and a reboot is necessary. Verify 1646 // Notify that an update has been applied and a reboot is necessary. Verify
1447 // that the device does not reboot immediately. 1647 // that a reboot is requested but the device does not reboot immediately.
1648 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1448 NotifyUpdateRebootNeeded(); 1649 NotifyUpdateRebootNeeded();
1449 1650
1450 // Verify that a grace period has started. 1651 // Verify that a grace period has started.
1451 VerifyGracePeriod(task_runner_->Uptime() + uptime_processing_delay_); 1652 VerifyGracePeriod(task_runner_->Uptime() + uptime_processing_delay_);
1452 1653
1453 // Fast forward the uptime by 20 seconds. Verify that the device does not 1654 // Fast forward the uptime by 20 seconds. Verify that the device does not
1454 // reboot immediately. 1655 // reboot immediately.
1455 FastForwardBy(base::TimeDelta::FromSeconds(20), false); 1656 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1456 1657
1457 // Disable automatic rebooting after an update has been applied. Verify that 1658 // Disable automatic rebooting after an update has been applied. Verify that
1458 // the device does not reboot immediately. 1659 // no reboot is requested and the device does not reboot immediately.
1459 SetRebootAfterUpdate(false, false); 1660 SetRebootAfterUpdate(false, false);
1460 1661
1461 // Verify that the grace period has been removed. 1662 // Verify that the grace period has been removed.
1462 VerifyNoGracePeriod(); 1663 VerifyNoGracePeriod();
1463 1664
1464 // Verify that the device does not reboot eventually. 1665 // Verify that the device never reboots.
1465 FastForwardUntilNoTasksRemain(false); 1666 FastForwardUntilNoTasksRemain(false);
1466 } 1667 }
1467 1668
1468 // Chrome is running. The current uptime is not available. 1669 // Chrome is running. The current uptime is not available.
1469 // Verifies that even if an uptime limit is set, the policy to automatically 1670 // Verifies that even if an uptime limit is set, the policy to automatically
1470 // reboot after an update is enabled and an update has been applied, no reboot 1671 // reboot after an update is enabled and an update has been applied, no reboot
1471 // occurs and no grace period is scheduled. Further verifies that no time is 1672 // occurs and no grace period is scheduled. Further verifies that no time is
1472 // persisted as the time at which a reboot became necessary. 1673 // persisted as the time at which a reboot became necessary.
1473 TEST_P(AutomaticRebootManagerTest, NoUptime) { 1674 TEST_P(AutomaticRebootManagerTest, NoUptime) {
1474 // Verify that the device does not reboot immediately. 1675 // Verify that no reboot is requested and the device does not reboot
1676 // immediately.
1677 ExpectNoRebootRequest();
1475 CreateAutomaticRebootManager(false); 1678 CreateAutomaticRebootManager(false);
1679 VerifyNoRebootRequested();
1476 1680
1477 // Set the uptime limit. Verify that the device does not reboot immediately. 1681 // Set the uptime limit. Verify that no reboot is requested and the device
1682 // does not reboot immediately.
1478 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 1683 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1479 1684
1480 // Verify that no grace period has started. 1685 // Verify that no grace period has started.
1481 VerifyNoGracePeriod(); 1686 VerifyNoGracePeriod();
1482 1687
1483 // Enable automatic rebooting after an update has been applied. Verify that 1688 // Enable automatic rebooting after an update has been applied. Verify that
1484 // the device does not reboot immediately. 1689 // no reboot is requested and the device does not reboot immediately.
1485 SetRebootAfterUpdate(true, false); 1690 SetRebootAfterUpdate(true, false);
1486 1691
1487 // Verify that no grace period has started. 1692 // Verify that no grace period has started.
1488 VerifyNoGracePeriod(); 1693 VerifyNoGracePeriod();
1489 1694
1490 // Notify that an update has been applied and a reboot is necessary. Verify 1695 // Notify that an update has been applied and a reboot is necessary. Verify
1491 // that the device does not reboot immediately. 1696 // that no reboot is requested and the device does not reboot immediately.
1492 NotifyUpdateRebootNeeded(); 1697 NotifyUpdateRebootNeeded();
1493 1698
1494 // Verify that no time is persisted as the time at which a reboot became 1699 // Verify that no time is persisted as the time at which a reboot became
1495 // necessary. 1700 // necessary.
1496 EXPECT_FALSE(ReadUpdateRebootNeededUptimeFromFile( 1701 EXPECT_FALSE(ReadUpdateRebootNeededUptimeFromFile(
1497 &update_reboot_needed_uptime_)); 1702 &update_reboot_needed_uptime_));
1498 1703
1499 // Verify that no grace period has started. 1704 // Verify that no grace period has started.
1500 VerifyNoGracePeriod(); 1705 VerifyNoGracePeriod();
1501 1706
1502 // Verify that the device does not reboot eventually. 1707 // Verify that a reboot is never requested and the device never reboots.
1503 FastForwardUntilNoTasksRemain(false); 1708 FastForwardUntilNoTasksRemain(false);
1504 } 1709 }
1505 1710
1506 // Chrome is running. The policy to automatically reboot after an update is 1711 // Chrome is running. The policy to automatically reboot after an update is
1507 // enabled. The current uptime is 12 hours. 1712 // enabled. The current uptime is 12 hours.
1508 // Verifies that when an uptime limit of 6 hours is set, the availability of an 1713 // Verifies that when an uptime limit of 6 hours is set, the availability of an
1509 // update does not cause the grace period to be rescheduled. Further verifies 1714 // update does not cause the grace period to be rescheduled. Further verifies
1510 // that the current uptime is persisted as the time at which a reboot became 1715 // that the current uptime is persisted as the time at which a reboot became
1511 // necessary. 1716 // necessary.
1512 TEST_P(AutomaticRebootManagerTest, UptimeLimitBeforeUpdate) { 1717 TEST_P(AutomaticRebootManagerTest, UptimeLimitBeforeUpdate) {
1513 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1718 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1514 SetRebootAfterUpdate(true, false); 1719 SetRebootAfterUpdate(true, false);
1515 1720
1516 // Verify that the device does not reboot immediately. 1721 // Verify that no reboot is requested and the device does not reboot
1722 // immediately.
1723 ExpectNoRebootRequest();
1517 CreateAutomaticRebootManager(false); 1724 CreateAutomaticRebootManager(false);
1725 VerifyNoRebootRequested();
1518 1726
1519 // Set the uptime limit. Verify that the device does not reboot immediately. 1727 // Set the uptime limit. Verify that a reboot is requested but the device does
1728 // not reboot immediately.
1729 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1520 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 1730 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1521 1731
1522 // Verify that a grace period has been scheduled to start in the future. 1732 // Verify that a grace period has been scheduled to start in the future.
1523 VerifyGracePeriod(uptime_limit_); 1733 VerifyGracePeriod(uptime_limit_);
1524 1734
1525 // Fast forward the uptime by 20 seconds. Verify that the device does not 1735 // Fast forward the uptime by 20 seconds. Verify that the device does not
1526 // reboot immediately. 1736 // reboot immediately.
1527 FastForwardBy(base::TimeDelta::FromSeconds(20), false); 1737 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1528 1738
1529 // Notify that an update has been applied and a reboot is necessary. Verify 1739 // Notify that an update has been applied and a reboot is necessary. Verify
1530 // that the device does not reboot immediately. 1740 // that a reboot is requested again but the device does not reboot
1741 // immediately.
1742 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1531 NotifyUpdateRebootNeeded(); 1743 NotifyUpdateRebootNeeded();
1532 1744
1533 // Verify that the current uptime has been persisted as the time at which a 1745 // Verify that the current uptime has been persisted as the time at which a
1534 // reboot became necessary. 1746 // reboot became necessary.
1535 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1747 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1536 &update_reboot_needed_uptime_)); 1748 &update_reboot_needed_uptime_));
1537 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1749 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1538 1750
1539 // Verify that the grace period has not been rescheduled. 1751 // Verify that the grace period has not been rescheduled.
1540 VerifyGracePeriod(uptime_limit_); 1752 VerifyGracePeriod(uptime_limit_);
1541 1753
1542 // Verify that unless a non-kiosk-app session is in progress, the device 1754 // Verify that unless a non-kiosk-app session is in progress, the device
1543 // eventually reboots. 1755 // eventually reboots.
1544 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1756 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1545 is_logged_in_as_kiosk_app_); 1757 is_logged_in_as_kiosk_app_);
1546 } 1758 }
1547 1759
1548 // Chrome is running. The policy to automatically reboot after an update is 1760 // Chrome is running. The policy to automatically reboot after an update is
1549 // enabled. The current uptime is 12 hours. 1761 // enabled. The current uptime is 12 hours.
1550 // Verifies that when an uptime limit of 24 hours is set, the availability of an 1762 // Verifies that when an uptime limit of 24 hours is set, the availability of an
1551 // update causes the grace period to be rescheduled so that it ends 24 hours 1763 // update causes the grace period to be rescheduled so that it ends 24 hours
1552 // from now. Further verifies that the current uptime is persisted as the time 1764 // from now. Further verifies that the current uptime is persisted as the time
1553 // at which a reboot became necessary. 1765 // at which a reboot became necessary.
1554 TEST_P(AutomaticRebootManagerTest, UpdateBeforeUptimeLimit) { 1766 TEST_P(AutomaticRebootManagerTest, UpdateBeforeUptimeLimit) {
1555 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1767 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1556 SetRebootAfterUpdate(true, false); 1768 SetRebootAfterUpdate(true, false);
1557 1769
1558 // Verify that the device does not reboot immediately. 1770 // Verify that no reboot is requested and the device does not reboot
1771 // immediately.
1772 ExpectNoRebootRequest();
1559 CreateAutomaticRebootManager(false); 1773 CreateAutomaticRebootManager(false);
1774 VerifyNoRebootRequested();
1560 1775
1561 // Set the uptime limit. Verify that the device does not reboot immediately. 1776 // Set the uptime limit. Verify that no reboot is requested and the device
1777 // does not reboot immediately.
1562 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 1778 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1563 1779
1564 // Verify that a grace period has been scheduled to start in the future. 1780 // Verify that a grace period has been scheduled to start in the future.
1565 VerifyGracePeriod(uptime_limit_); 1781 VerifyGracePeriod(uptime_limit_);
1566 1782
1567 // Fast forward the uptime by 20 seconds. Verify that the device does not 1783 // Fast forward the uptime by 20 seconds. Verify that no reboot is requested
1568 // reboot immediately. 1784 // and the device does not reboot immediately.
1569 FastForwardBy(base::TimeDelta::FromSeconds(20), false); 1785 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1570 1786
1571 // Notify that an update has been applied and a reboot is necessary. Verify 1787 // Notify that an update has been applied and a reboot is necessary. Verify
1572 // that the device does not reboot immediately. 1788 // that a reboot is requested but the device does not reboot immediately.
1789 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1573 NotifyUpdateRebootNeeded(); 1790 NotifyUpdateRebootNeeded();
1574 1791
1575 // Verify that the current uptime has been persisted as the time at which a 1792 // Verify that the current uptime has been persisted as the time at which a
1576 // reboot became necessary. 1793 // reboot became necessary.
1577 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1794 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1578 &update_reboot_needed_uptime_)); 1795 &update_reboot_needed_uptime_));
1579 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1796 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1580 1797
1581 // Verify that the grace period has been rescheduled to start at the time that 1798 // Verify that the grace period has been rescheduled to start at the time that
1582 // the update became available. 1799 // the update became available.
1583 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); 1800 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1584 1801
1585 // Verify that unless a non-kiosk-app session is in progress, the device 1802 // Verify that unless a non-kiosk-app session is in progress, the device
1586 // eventually reboots. 1803 // eventually reboots.
1587 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1804 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1588 is_logged_in_as_kiosk_app_); 1805 is_logged_in_as_kiosk_app_);
1589 } 1806 }
1590 1807
1591 // Chrome is running. The uptime limit is set to 24 hours. An update was applied 1808 // Chrome is running. The uptime limit is set to 24 hours. An update was applied
1592 // and a reboot became necessary to complete the update process after 12 hours. 1809 // and a reboot became necessary to complete the update process after 12 hours.
1593 // The policy to automatically reboot after an update is enabled. The current 1810 // The policy to automatically reboot after an update is enabled. The current
1594 // uptime is 12 hours 20 seconds. 1811 // uptime is 12 hours 20 seconds.
1595 // Verifies that when the policy to reboot after an update is disabled, the 1812 // Verifies that when the policy to reboot after an update is disabled, the
1596 // grace period is rescheduled to start after 24 hours of uptime. Further 1813 // grace period is rescheduled to start after 12 hours of uptime. Further
1597 // verifies that when the uptime limit is removed, the grace period is removed. 1814 // verifies that when the uptime limit is removed, the grace period is removed.
1598 TEST_P(AutomaticRebootManagerTest, PolicyOffThenUptimeLimitOff) { 1815 TEST_P(AutomaticRebootManagerTest, PolicyOffThenUptimeLimitOff) {
1599 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1816 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1600 SetRebootAfterUpdate(true, false); 1817 SetRebootAfterUpdate(true, false);
1601 1818
1602 // Verify that the device does not reboot immediately. 1819 // Verify that no reboot is requested and the device does not reboot
1820 // immediately.
1821 ExpectNoRebootRequest();
1603 CreateAutomaticRebootManager(false); 1822 CreateAutomaticRebootManager(false);
1823 VerifyNoRebootRequested();
1604 1824
1605 // Set the uptime limit. Verify that the device does not reboot immediately. 1825 // Set the uptime limit. Verify that no reboot is requested and the device
1826 // does not reboot immediately.
1606 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 1827 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1607 1828
1608 // Verify that the grace period has started. 1829 // Verify that a grace period has been scheduled to start in the future.
1609 VerifyGracePeriod(uptime_limit_); 1830 VerifyGracePeriod(uptime_limit_);
1610 1831
1611 // Notify that an update has been applied and a reboot is necessary. Verify 1832 // Notify that an update has been applied and a reboot is necessary. Verify
1612 // that the device does not reboot immediately. 1833 // that a reboot is requested but the device does not reboot immediately.
1834 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1613 NotifyUpdateRebootNeeded(); 1835 NotifyUpdateRebootNeeded();
1614 1836
1615 // Verify that the current uptime has been persisted as the time at which a 1837 // Verify that the current uptime has been persisted as the time at which a
1616 // reboot became necessary. 1838 // reboot became necessary.
1617 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1839 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1618 &update_reboot_needed_uptime_)); 1840 &update_reboot_needed_uptime_));
1619 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1841 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1620 1842
1621 // Verify that a grace period has been rescheduled to end 24 hours from now. 1843 // Verify that a grace period has been rescheduled to end 24 hours from now.
1622 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); 1844 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
(...skipping 10 matching lines...) Expand all
1633 // of uptime. 1855 // of uptime.
1634 VerifyGracePeriod(uptime_limit_); 1856 VerifyGracePeriod(uptime_limit_);
1635 1857
1636 // Remove the uptime limit. Verify that the device does not reboot 1858 // Remove the uptime limit. Verify that the device does not reboot
1637 // immediately. 1859 // immediately.
1638 SetUptimeLimit(base::TimeDelta(), false); 1860 SetUptimeLimit(base::TimeDelta(), false);
1639 1861
1640 // Verify that the grace period has been removed. 1862 // Verify that the grace period has been removed.
1641 VerifyNoGracePeriod(); 1863 VerifyNoGracePeriod();
1642 1864
1643 // Verify that the device does not reboot eventually. 1865 // Verify that the device never reboots.
1644 FastForwardUntilNoTasksRemain(false); 1866 FastForwardUntilNoTasksRemain(false);
1645 } 1867 }
1646 1868
1647 // Chrome is running. The uptime limit is set to 6 hours. An update was applied 1869 // Chrome is running. The uptime limit is set to 6 hours. An update was applied
1648 // and a reboot became necessary to complete the update process after 12 hours. 1870 // and a reboot became necessary to complete the update process after 12 hours.
1649 // The policy to automatically reboot after an update is enabled. The current 1871 // The policy to automatically reboot after an update is enabled. The current
1650 // uptime is 12 hours 20 seconds. 1872 // uptime is 12 hours 20 seconds.
1651 // Verifies that when the uptime limit is removed, the grace period is 1873 // Verifies that when the uptime limit is removed, the grace period is
1652 // rescheduled to have started after 12 hours of uptime. Further verifies that 1874 // rescheduled to have started after 12 hours of uptime. Further verifies that
1653 // when the policy to reboot after an update is disabled, the reboot request and 1875 // when the policy to reboot after an update is disabled, the reboot request and
1654 // grace period are removed. 1876 // grace period are removed.
1655 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffThenPolicyOff) { 1877 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffThenPolicyOff) {
1656 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1878 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1657 SetRebootAfterUpdate(true, false); 1879 SetRebootAfterUpdate(true, false);
1658 1880
1659 // Verify that the device does not reboot immediately. 1881 // Verify that no reboot is requested and the device does not reboot
1882 // immediately.
1883 ExpectNoRebootRequest();
1660 CreateAutomaticRebootManager(false); 1884 CreateAutomaticRebootManager(false);
1885 VerifyNoRebootRequested();
1661 1886
1662 // Notify that an update has been applied and a reboot is necessary. Verify 1887 // Notify that an update has been applied and a reboot is necessary. Verify
1663 // that the device does not reboot immediately. 1888 // that a reboot is requested but the device does not reboot immediately.
1889 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1664 NotifyUpdateRebootNeeded(); 1890 NotifyUpdateRebootNeeded();
1665 1891
1666 // Verify that the current uptime has been persisted as the time at which a 1892 // Verify that the current uptime has been persisted as the time at which a
1667 // reboot became necessary. 1893 // reboot became necessary.
1668 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1894 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1669 &update_reboot_needed_uptime_)); 1895 &update_reboot_needed_uptime_));
1670 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1896 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1671 1897
1672 // Verify that the grace period has started. 1898 // Verify that the grace period has started.
1673 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); 1899 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1674 1900
1675 // Set the uptime limit. Verify that the device does not reboot immediately. 1901 // Set the uptime limit. Verify that a reboot is requested again but the
1902 // device does not reboot immediately.
1903 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1676 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 1904 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1677 1905
1678 // Verify that the grace period has been rescheduled to have started after 1906 // Verify that the grace period has been rescheduled to have started after
1679 // 6 hours of uptime. 1907 // 6 hours of uptime.
1680 VerifyGracePeriod(uptime_limit_); 1908 VerifyGracePeriod(uptime_limit_);
1681 1909
1682 // Fast forward the uptime by 20 seconds. Verify that the device does not 1910 // Fast forward the uptime by 20 seconds. Verify that the device does not
1683 // reboot immediately. 1911 // reboot immediately.
1684 FastForwardBy(base::TimeDelta::FromSeconds(20), false); 1912 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1685 1913
1686 // Remove the uptime limit. Verify that the device does not reboot 1914 // Remove the uptime limit. Verify that a reboot is requested again but the
1687 // immediately. 1915 // device does not reboot immediately.
1916 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1688 SetUptimeLimit(base::TimeDelta(), false); 1917 SetUptimeLimit(base::TimeDelta(), false);
1689 1918
1690 // Verify that a grace period has been rescheduled to have started after 12 1919 // Verify that a grace period has been rescheduled to have started after 12
1691 // hours of uptime. 1920 // hours of uptime.
1692 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); 1921 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1693 1922
1694 // Disable automatic reboot after an update has been applied. Verify that the 1923 // Disable automatic reboot after an update has been applied. Verify that the
1695 // device does not reboot immediately. 1924 // device does not reboot immediately.
1696 SetRebootAfterUpdate(false, false); 1925 SetRebootAfterUpdate(false, false);
1697 1926
1698 // Verify that the grace period has been removed. 1927 // Verify that the grace period has been removed.
1699 VerifyNoGracePeriod(); 1928 VerifyNoGracePeriod();
1700 1929
1701 // Verify that the device does not reboot eventually. 1930 // Verify that the device never reboots.
1702 FastForwardUntilNoTasksRemain(false); 1931 FastForwardUntilNoTasksRemain(false);
1703 } 1932 }
1704 1933
1705 // Chrome is running. The uptime limit is 6 hours. The current uptime is 1934 // Chrome is running. The uptime limit is 6 hours. The current uptime is
1706 // 29 hours 59 minutes 59 seconds. 1935 // 29 hours 59 minutes 59 seconds.
1707 // Verifies that if no non-kiosk-app session is in progress, the device reboots 1936 // Verifies that if no non-kiosk-app session is in progress, the device reboots
1708 // immediately when the grace period ends after 6 + 24 hours of uptime. 1937 // immediately when the grace period ends after 6 + 24 hours of uptime.
1709 TEST_P(AutomaticRebootManagerTest, GracePeriodEnd) { 1938 TEST_P(AutomaticRebootManagerTest, GracePeriodEnd) {
1710 task_runner_->SetUptime(base::TimeDelta::FromHours(29) + 1939 task_runner_->SetUptime(base::TimeDelta::FromHours(29) +
1711 base::TimeDelta::FromMinutes(59) + 1940 base::TimeDelta::FromMinutes(59) +
1712 base::TimeDelta::FromSeconds(59)); 1941 base::TimeDelta::FromSeconds(59));
1713 1942
1714 // Verify that the device does not reboot immediately. 1943 // Verify that no reboot is requested and the device does not reboot
1944 // immediately.
1945 ExpectNoRebootRequest();
1715 CreateAutomaticRebootManager(false); 1946 CreateAutomaticRebootManager(false);
1947 VerifyNoRebootRequested();
1716 1948
1717 // Set the uptime limit. Verify that the device does not reboot immediately. 1949 // Set the uptime limit. Verify that a reboot is requested but the device does
1950 // not reboot immediately.
1951 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1718 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 1952 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1719 1953
1720 // Verify that a grace period has started. 1954 // Verify that a grace period has started.
1721 VerifyGracePeriod(uptime_limit_); 1955 VerifyGracePeriod(uptime_limit_);
1722 1956
1723 // Fast forward the uptime by 1 second. Verify that unless a non-kiosk-app 1957 // Fast forward the uptime by 1 second. Verify that unless a non-kiosk-app
1724 // session is in progress, the the device immediately reboots. 1958 // session is in progress, the the device immediately reboots.
1725 FastForwardBy(base::TimeDelta::FromSeconds(1), !is_user_logged_in_ || 1959 FastForwardBy(base::TimeDelta::FromSeconds(1), !is_user_logged_in_ ||
1726 is_logged_in_as_kiosk_app_); 1960 is_logged_in_as_kiosk_app_);
1727 1961
1728 // Verify that if a non-kiosk-app session is in progress, the device does not 1962 // Verify that if a non-kiosk-app session is in progress, the device never
1729 // reboot eventually. 1963 // reboots.
1730 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1964 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1731 is_logged_in_as_kiosk_app_); 1965 is_logged_in_as_kiosk_app_);
1732 } 1966 }
1733 1967
1734 // Chrome is starting. The current uptime is 10 days. 1968 // Chrome is starting. The current uptime is 10 days.
1735 // Verifies that when no automatic reboot policy is enabled, no reboot occurs 1969 // Verifies that when no automatic reboot policy is enabled, no reboot occurs
1736 // and no grace period is scheduled. 1970 // and no grace period is scheduled.
1737 TEST_P(AutomaticRebootManagerTest, StartNoPolicy) { 1971 TEST_P(AutomaticRebootManagerTest, StartNoPolicy) {
1738 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 1972 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
1739 1973
1740 // Verify that the device does not reboot immediately. 1974 // Verify that no reboot is requested and the device does not reboot
1975 // immediately.
1976 ExpectNoRebootRequest();
1741 CreateAutomaticRebootManager(false); 1977 CreateAutomaticRebootManager(false);
1978 VerifyNoRebootRequested();
1742 1979
1743 // Verify that no grace period has started. 1980 // Verify that no grace period has started.
1744 VerifyNoGracePeriod(); 1981 VerifyNoGracePeriod();
1745 1982
1746 // Verify that the device does not reboot eventually. 1983 // Verify that a reboot is never requested and the device never reboots.
1747 FastForwardUntilNoTasksRemain(false); 1984 FastForwardUntilNoTasksRemain(false);
1748 } 1985 }
1749 1986
1750 // Chrome is starting. The uptime limit is set to 24 hours. The current uptime 1987 // Chrome is starting. The uptime limit is set to 24 hours. The current uptime
1751 // is 12 hours. 1988 // is 12 hours.
1752 // Verifies that no reboot occurs and a grace period is scheduled to begin after 1989 // Verifies that no reboot occurs and a grace period is scheduled to begin after
1753 // 24 hours of uptime. 1990 // 24 hours of uptime.
1754 TEST_P(AutomaticRebootManagerTest, StartBeforeUptimeLimitGracePeriod) { 1991 TEST_P(AutomaticRebootManagerTest, StartBeforeUptimeLimitGracePeriod) {
1755 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 1992 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1756 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1993 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1757 1994
1758 // Verify that the device does not reboot immediately. 1995 // Verify that no reboot is requested and the device does not reboot
1996 // immediately.
1997 ExpectNoRebootRequest();
1759 CreateAutomaticRebootManager(false); 1998 CreateAutomaticRebootManager(false);
1999 VerifyNoRebootRequested();
1760 2000
1761 // Verify that a grace period has been scheduled to start in the future. 2001 // Verify that a grace period has been scheduled to start in the future.
1762 VerifyGracePeriod(uptime_limit_); 2002 VerifyGracePeriod(uptime_limit_);
1763 2003
1764 // Verify that unless a non-kiosk-app session is in progress, the device 2004 // Verify that a reboot is requested eventually and unless a non-kiosk-app
1765 // eventually reboots. 2005 // session is in progress, the device eventually reboots.
2006 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1766 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 2007 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1767 is_logged_in_as_kiosk_app_); 2008 is_logged_in_as_kiosk_app_);
1768 } 2009 }
1769 2010
1770 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is 2011 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is
1771 // 10 days. 2012 // 10 days.
1772 // Verifies that if no non-kiosk-app session is in progress, the device reboots 2013 // Verifies that if no non-kiosk-app session is in progress, the device reboots
1773 // immediately because the grace period ended after 6 + 24 hours of uptime. 2014 // immediately because the grace period ended after 6 + 24 hours of uptime.
1774 TEST_P(AutomaticRebootManagerTest, StartAfterUptimeLimitGracePeriod) { 2015 TEST_P(AutomaticRebootManagerTest, StartAfterUptimeLimitGracePeriod) {
1775 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 2016 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1776 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 2017 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
1777 2018
1778 // Verify that unless a non-kiosk-app session is in progress, the the device 2019 // Verify that a reboot is requested and unless a non-kiosk-app session is in
1779 // immediately reboots. 2020 // progress, the the device immediately reboots.
2021 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1780 CreateAutomaticRebootManager(!is_user_logged_in_ || 2022 CreateAutomaticRebootManager(!is_user_logged_in_ ||
1781 is_logged_in_as_kiosk_app_); 2023 is_logged_in_as_kiosk_app_);
2024 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1782 2025
1783 // Verify that if a non-kiosk-app session is in progress, the device does not 2026 // Verify that if a non-kiosk-app session is in progress, the device never
1784 // reboot eventually. 2027 // reboots.
1785 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 2028 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1786 is_logged_in_as_kiosk_app_); 2029 is_logged_in_as_kiosk_app_);
1787 } 2030 }
1788 2031
1789 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is 2032 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is
1790 // 12 hours. 2033 // 12 hours.
1791 // Verifies that a reboot is requested and a grace period is started that will 2034 // Verifies that a reboot is requested and a grace period is started that will
1792 // end after 6 + 24 hours of uptime. 2035 // end after 6 + 24 hours of uptime.
1793 TEST_P(AutomaticRebootManagerTest, StartInUptimeLimitGracePeriod) { 2036 TEST_P(AutomaticRebootManagerTest, StartInUptimeLimitGracePeriod) {
1794 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 2037 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1795 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 2038 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1796 2039
1797 // Verify that the device does not reboot immediately. 2040 // Verify that a reboot is requested but the device does not reboot
2041 // immediately.
2042 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1798 CreateAutomaticRebootManager(false); 2043 CreateAutomaticRebootManager(false);
2044 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1799 2045
1800 // Verify that a grace period has started. 2046 // Verify that a grace period has started.
1801 VerifyGracePeriod(uptime_limit_); 2047 VerifyGracePeriod(uptime_limit_);
1802 2048
1803 // Verify that unless a non-kiosk-app session is in progress, the device 2049 // Verify that unless a non-kiosk-app session is in progress, the device
1804 // eventually reboots. 2050 // eventually reboots.
1805 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 2051 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1806 is_logged_in_as_kiosk_app_); 2052 is_logged_in_as_kiosk_app_);
1807 } 2053 }
1808 2054
1809 // Chrome is starting. An update was applied and a reboot became necessary to 2055 // Chrome is starting. An update was applied and a reboot became necessary to
1810 // complete the update process after 6 hours of uptime. The current uptime is 2056 // complete the update process after 6 hours of uptime. The current uptime is
1811 // 10 days. 2057 // 10 days.
1812 // Verifies that when the policy to automatically reboot after an update is 2058 // Verifies that when the policy to automatically reboot after an update is
1813 // enabled, the device reboots immediately if no non-kiosk-app session is in 2059 // enabled, the device reboots immediately if no non-kiosk-app session is in
1814 // progress because the grace period ended after 6 + 24 hours of uptime. 2060 // progress because the grace period ended after 6 + 24 hours of uptime.
1815 TEST_P(AutomaticRebootManagerTest, StartAfterUpdateGracePeriod) { 2061 TEST_P(AutomaticRebootManagerTest, StartAfterUpdateGracePeriod) {
1816 SetUpdateStatusNeedReboot(); 2062 SetUpdateStatusNeedReboot();
1817 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); 2063 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
1818 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 2064 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
1819 SetRebootAfterUpdate(true, false); 2065 SetRebootAfterUpdate(true, false);
1820 2066
1821 // Verify that unless a non-kiosk-app session is in progress, the device 2067 // Verify that a reboot is requested and unless a non-kiosk-app session is in
1822 // reboots immediately. 2068 // progress, the the device immediately reboots.
2069 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1823 CreateAutomaticRebootManager(!is_user_logged_in_ || 2070 CreateAutomaticRebootManager(!is_user_logged_in_ ||
1824 is_logged_in_as_kiosk_app_); 2071 is_logged_in_as_kiosk_app_);
2072 VerifyRebootRequested(
2073 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1825 2074
1826 // Verify that if a non-kiosk-app session is in progress, the device does not 2075 // Verify that if a non-kiosk-app session is in progress, the device never
1827 // reboot eventually. 2076 // reboots.
1828 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 2077 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1829 is_logged_in_as_kiosk_app_); 2078 is_logged_in_as_kiosk_app_);
1830 } 2079 }
1831 2080
1832 // Chrome is starting. An update was applied and a reboot became necessary to 2081 // Chrome is starting. An update was applied and a reboot became necessary to
1833 // complete the update process after 6 hours of uptime. The current uptime is 2082 // complete the update process after 6 hours of uptime. The current uptime is
1834 // 12 hours. 2083 // 12 hours.
1835 // Verifies that when the policy to automatically reboot after an update is 2084 // Verifies that when the policy to automatically reboot after an update is
1836 // enabled, a reboot is requested and a grace period is started that will end 2085 // enabled, a reboot is requested and a grace period is started that will end
1837 // after 6 + 24 hours of uptime. 2086 // after 6 + 24 hours of uptime.
1838 TEST_P(AutomaticRebootManagerTest, StartInUpdateGracePeriod) { 2087 TEST_P(AutomaticRebootManagerTest, StartInUpdateGracePeriod) {
1839 SetUpdateStatusNeedReboot(); 2088 SetUpdateStatusNeedReboot();
1840 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); 2089 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
1841 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 2090 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1842 SetRebootAfterUpdate(true, false); 2091 SetRebootAfterUpdate(true, false);
1843 2092
1844 // Verify that the device does not reboot immediately. 2093 // Verify that a reboot is requested but the device does not reboot
2094 // immediately.
2095 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1845 CreateAutomaticRebootManager(false); 2096 CreateAutomaticRebootManager(false);
2097 VerifyRebootRequested(
2098 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1846 2099
1847 // Verify that a grace period has started. 2100 // Verify that a grace period has started.
1848 VerifyGracePeriod(update_reboot_needed_uptime_); 2101 VerifyGracePeriod(update_reboot_needed_uptime_);
1849 2102
1850 // Verify that unless a non-kiosk-app session is in progress, the device 2103 // Verify that unless a non-kiosk-app session is in progress, the device
1851 // eventually reboots. 2104 // eventually reboots.
1852 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 2105 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1853 is_logged_in_as_kiosk_app_); 2106 is_logged_in_as_kiosk_app_);
1854 } 2107 }
1855 2108
1856 // Chrome is starting. An update was applied and a reboot became necessary to 2109 // Chrome is starting. An update was applied and a reboot became necessary to
1857 // complete the update process after 10 minutes of uptime. The current uptime is 2110 // complete the update process after 10 minutes of uptime. The current uptime is
1858 // 20 minutes. 2111 // 20 minutes.
1859 // Verifies that when the policy to automatically reboot after an update is 2112 // Verifies that when the policy to automatically reboot after an update is
1860 // enabled, no reboot occurs and a grace period is scheduled to begin after the 2113 // enabled, no reboot occurs and a grace period is scheduled to begin after the
1861 // minimum of 1 hour of uptime. 2114 // minimum of 1 hour of uptime.
1862 TEST_P(AutomaticRebootManagerTest, StartBeforeUpdateGracePeriod) { 2115 TEST_P(AutomaticRebootManagerTest, StartBeforeUpdateGracePeriod) {
1863 SetUpdateStatusNeedReboot(); 2116 SetUpdateStatusNeedReboot();
1864 SetUpdateRebootNeededUptime(base::TimeDelta::FromMinutes(10)); 2117 SetUpdateRebootNeededUptime(base::TimeDelta::FromMinutes(10));
1865 task_runner_->SetUptime(base::TimeDelta::FromMinutes(20)); 2118 task_runner_->SetUptime(base::TimeDelta::FromMinutes(20));
1866 SetRebootAfterUpdate(true, false); 2119 SetRebootAfterUpdate(true, false);
1867 2120
1868 // Verify that the device does not reboot immediately. 2121 // Verify that no reboot is requested and the device does not reboot
2122 // immediately.
2123 ExpectNoRebootRequest();
1869 CreateAutomaticRebootManager(false); 2124 CreateAutomaticRebootManager(false);
2125 VerifyNoRebootRequested();
1870 2126
1871 // Verify that a grace period has been scheduled to start in the future. 2127 // Verify that a grace period has been scheduled to start in the future.
1872 VerifyGracePeriod(base::TimeDelta::FromHours(1)); 2128 VerifyGracePeriod(base::TimeDelta::FromHours(1));
1873 2129
1874 // Verify that unless a non-kiosk-app session is in progress, the device 2130 // Verify that a reboot is requested eventually and unless a non-kiosk-app
1875 // eventually reboots. 2131 // session is in progress, the device eventually reboots.
2132 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1876 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 2133 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1877 is_logged_in_as_kiosk_app_); 2134 is_logged_in_as_kiosk_app_);
1878 } 2135 }
1879 2136
1880 // Chrome is starting. An update was applied and a reboot became necessary to 2137 // Chrome is starting. An update was applied and a reboot became necessary to
1881 // complete the update process after 6 hours of uptime. The current uptime is 2138 // complete the update process after 6 hours of uptime. The current uptime is
1882 // 10 days. 2139 // 10 days.
1883 // Verifies that when the policy to automatically reboot after an update is not 2140 // Verifies that when the policy to automatically reboot after an update is not
1884 // enabled, no reboot occurs and no grace period is scheduled. 2141 // enabled, no reboot occurs and no grace period is scheduled.
1885 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicy) { 2142 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicy) {
1886 SetUpdateStatusNeedReboot(); 2143 SetUpdateStatusNeedReboot();
1887 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); 2144 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
1888 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 2145 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
1889 2146
1890 // Verify that the device does not reboot immediately. 2147 // Verify that no reboot is requested and the device does not reboot
2148 // immediately.
2149 ExpectNoRebootRequest();
1891 CreateAutomaticRebootManager(false); 2150 CreateAutomaticRebootManager(false);
2151 VerifyNoRebootRequested();
1892 2152
1893 // Verify that no grace period has started. 2153 // Verify that no grace period has started.
1894 VerifyNoGracePeriod(); 2154 VerifyNoGracePeriod();
1895 2155
1896 // Verify that the device does not reboot eventually. 2156 // Verify that a reboot is never requested and the device never reboots.
1897 FastForwardUntilNoTasksRemain(false); 2157 FastForwardUntilNoTasksRemain(false);
1898 } 2158 }
1899 2159
1900 // Chrome is starting. An update was applied and a reboot became necessary to 2160 // Chrome is starting. An update was applied and a reboot became necessary to
1901 // complete the update process but the time at which this happened was lost. The 2161 // complete the update process but the time at which this happened was lost. The
1902 // current uptime is 10 days. 2162 // current uptime is 10 days.
1903 // Verifies that the current uptime is persisted as the time at which a reboot 2163 // Verifies that the current uptime is persisted as the time at which a reboot
1904 // became necessary. Further verifies that when the policy to automatically 2164 // became necessary. Further verifies that when the policy to automatically
1905 // reboot after an update is enabled, a reboot is requested and a grace period 2165 // reboot after an update is enabled, a reboot is requested and a grace period
1906 // is started that will end 24 hours from now. 2166 // is started that will end 24 hours from now.
1907 TEST_P(AutomaticRebootManagerTest, StartUpdateTimeLost) { 2167 TEST_P(AutomaticRebootManagerTest, StartUpdateTimeLost) {
1908 SetUpdateStatusNeedReboot(); 2168 SetUpdateStatusNeedReboot();
1909 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 2169 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
1910 SetRebootAfterUpdate(true, false); 2170 SetRebootAfterUpdate(true, false);
1911 2171
1912 // Verify that the device does not reboot immediately. 2172 // Verify that a reboot is requested but the device does not reboot
2173 // immediately.
2174 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1913 CreateAutomaticRebootManager(false); 2175 CreateAutomaticRebootManager(false);
2176 VerifyRebootRequested(
2177 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1914 2178
1915 // Verify that the current uptime has been persisted as the time at which a 2179 // Verify that the current uptime has been persisted as the time at which a
1916 // reboot became necessary. 2180 // reboot became necessary.
1917 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 2181 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1918 &update_reboot_needed_uptime_)); 2182 &update_reboot_needed_uptime_));
1919 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 2183 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1920 2184
1921 // Verify that a grace period has started. 2185 // Verify that a grace period has started.
1922 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); 2186 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1923 2187
1924 // Verify that unless a non-kiosk-app session is in progress, the device 2188 // Verify that unless a non-kiosk-app session is in progress, the device
1925 // eventually reboots. 2189 // eventually reboots.
1926 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 2190 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1927 is_logged_in_as_kiosk_app_); 2191 is_logged_in_as_kiosk_app_);
1928 } 2192 }
1929 2193
1930 // Chrome is starting. An update was applied and a reboot became necessary to 2194 // Chrome is starting. An update was applied and a reboot became necessary to
1931 // complete the update process but the time at which this happened was lost. The 2195 // complete the update process but the time at which this happened was lost. The
1932 // current uptime is 10 days. 2196 // current uptime is 10 days.
1933 // Verifies that the current uptime is persisted as the time at which a reboot 2197 // Verifies that the current uptime is persisted as the time at which a reboot
1934 // became necessary. Further verifies that when the policy to automatically 2198 // became necessary. Further verifies that when the policy to automatically
1935 // reboot after an update is not enabled, no reboot occurs and no grace period 2199 // reboot after an update is not enabled, no reboot occurs and no grace period
1936 // is scheduled. 2200 // is scheduled.
1937 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicyTimeLost) { 2201 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicyTimeLost) {
1938 SetUpdateStatusNeedReboot(); 2202 SetUpdateStatusNeedReboot();
1939 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 2203 task_runner_->SetUptime(base::TimeDelta::FromDays(10));
1940 2204
1941 // Verify that the device does not reboot immediately. 2205 // Verify that no reboot is requested and the device does not reboot
2206 // immediately.
2207 ExpectNoRebootRequest();
1942 CreateAutomaticRebootManager(false); 2208 CreateAutomaticRebootManager(false);
2209 VerifyNoRebootRequested();
1943 2210
1944 // Verify that the current uptime has been persisted as the time at which a 2211 // Verify that the current uptime has been persisted as the time at which a
1945 // reboot became necessary. 2212 // reboot became necessary.
1946 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 2213 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1947 &update_reboot_needed_uptime_)); 2214 &update_reboot_needed_uptime_));
1948 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 2215 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
1949 2216
1950 // Verify that no grace period has started. 2217 // Verify that no grace period has started.
1951 VerifyNoGracePeriod(); 2218 VerifyNoGracePeriod();
1952 2219
1953 // Verify that the device does not reboot eventually. 2220 // Verify that a reboot is never requested and the device never reboots.
1954 FastForwardUntilNoTasksRemain(false); 2221 FastForwardUntilNoTasksRemain(false);
1955 } 2222 }
1956 2223
1957 // Chrome is starting. No update has been applied. The current uptime is 2224 // Chrome is starting. No update has been applied. The current uptime is
1958 // 12 hours. 2225 // 12 hours.
1959 // Verifies that no time is persisted as the time at which a reboot became 2226 // Verifies that no time is persisted as the time at which a reboot became
1960 // necessary. Further verifies that no reboot occurs and no grace period is 2227 // necessary. Further verifies that no reboot occurs and no grace period is
1961 // scheduled. 2228 // scheduled.
1962 TEST_P(AutomaticRebootManagerTest, StartNoUpdate) { 2229 TEST_P(AutomaticRebootManagerTest, StartNoUpdate) {
1963 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 2230 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1964 SetRebootAfterUpdate(true, false); 2231 SetRebootAfterUpdate(true, false);
1965 2232
1966 // Verify that the device does not reboot immediately. 2233 // Verify that no reboot is requested and the device does not reboot
2234 // immediately.
2235 ExpectNoRebootRequest();
1967 CreateAutomaticRebootManager(false); 2236 CreateAutomaticRebootManager(false);
2237 VerifyNoRebootRequested();
1968 2238
1969 // Verify that no time is persisted as the time at which a reboot became 2239 // Verify that no time is persisted as the time at which a reboot became
1970 // necessary. 2240 // necessary.
1971 EXPECT_FALSE(ReadUpdateRebootNeededUptimeFromFile( 2241 EXPECT_FALSE(ReadUpdateRebootNeededUptimeFromFile(
1972 &update_reboot_needed_uptime_)); 2242 &update_reboot_needed_uptime_));
1973 2243
1974 // Verify that no grace period has started. 2244 // Verify that no grace period has started.
1975 VerifyNoGracePeriod(); 2245 VerifyNoGracePeriod();
1976 2246
1977 // Verify that the device does not reboot eventually. 2247 // Verify that a reboot is never requested and the device never reboots.
1978 FastForwardUntilNoTasksRemain(false); 2248 FastForwardUntilNoTasksRemain(false);
1979 } 2249 }
1980 2250
1981 // Chrome is starting. The uptime limit is set to 6 hours. Also, an update was 2251 // Chrome is starting. The uptime limit is set to 6 hours. Also, an update was
1982 // applied and a reboot became necessary to complete the update process after 2252 // applied and a reboot became necessary to complete the update process after
1983 // 8 hours of uptime. The current uptime is 12 hours. 2253 // 8 hours of uptime. The current uptime is 12 hours.
1984 // Verifies that when the policy to automatically reboot after an update is 2254 // Verifies that when the policy to automatically reboot after an update is
1985 // enabled, a reboot is requested and a grace period is started that will end 2255 // enabled, a reboot is requested and a grace period is started that will end
1986 // after 6 + 24 hours of uptime. 2256 // after 6 + 24 hours of uptime.
1987 TEST_P(AutomaticRebootManagerTest, StartUptimeLimitBeforeUpdate) { 2257 TEST_P(AutomaticRebootManagerTest, StartUptimeLimitBeforeUpdate) {
1988 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 2258 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1989 SetUpdateStatusNeedReboot(); 2259 SetUpdateStatusNeedReboot();
1990 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(8)); 2260 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(8));
1991 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 2261 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
1992 SetRebootAfterUpdate(true, false); 2262 SetRebootAfterUpdate(true, false);
1993 2263
1994 // Verify that the device does not reboot immediately. 2264 // Verify that a reboot is requested but the device does not reboot
2265 // immediately.
2266 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1995 CreateAutomaticRebootManager(false); 2267 CreateAutomaticRebootManager(false);
2268 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1996 2269
1997 // Verify that a grace period has started. 2270 // Verify that a grace period has started.
1998 VerifyGracePeriod(uptime_limit_); 2271 VerifyGracePeriod(uptime_limit_);
1999 2272
2000 // Verify that unless a non-kiosk-app session is in progress, the device 2273 // Verify that unless a non-kiosk-app session is in progress, the device
2001 // eventually reboots. 2274 // eventually reboots.
2002 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 2275 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2003 is_logged_in_as_kiosk_app_); 2276 is_logged_in_as_kiosk_app_);
2004 } 2277 }
2005 2278
2006 // Chrome is starting. The uptime limit is set to 8 hours. Also, an update was 2279 // Chrome is starting. The uptime limit is set to 8 hours. Also, an update was
2007 // applied and a reboot became necessary to complete the update process after 2280 // applied and a reboot became necessary to complete the update process after
2008 // 6 hours of uptime. The current uptime is 12 hours. 2281 // 6 hours of uptime. The current uptime is 12 hours.
2009 // Verifies that when the policy to automatically reboot after an update is 2282 // Verifies that when the policy to automatically reboot after an update is
2010 // enabled, a reboot is requested and a grace period is started that will end 2283 // enabled, a reboot is requested and a grace period is started that will end
2011 // after 6 + 24 hours of uptime. 2284 // after 6 + 24 hours of uptime.
2012 TEST_P(AutomaticRebootManagerTest, StartUpdateBeforeUptimeLimit) { 2285 TEST_P(AutomaticRebootManagerTest, StartUpdateBeforeUptimeLimit) {
2013 SetUptimeLimit(base::TimeDelta::FromHours(8), false); 2286 SetUptimeLimit(base::TimeDelta::FromHours(8), false);
2014 SetUpdateStatusNeedReboot(); 2287 SetUpdateStatusNeedReboot();
2015 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); 2288 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
2016 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 2289 task_runner_->SetUptime(base::TimeDelta::FromHours(12));
2017 SetRebootAfterUpdate(true, false); 2290 SetRebootAfterUpdate(true, false);
2018 2291
2019 // Verify that the device does not reboot immediately. 2292 // Verify that a reboot is requested but the device does not reboot
2293 // immediately.
2294 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2020 CreateAutomaticRebootManager(false); 2295 CreateAutomaticRebootManager(false);
2296 VerifyRebootRequested(
2297 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2021 2298
2022 // Verify that a grace period has started. 2299 // Verify that a grace period has started.
2023 VerifyGracePeriod(update_reboot_needed_uptime_); 2300 VerifyGracePeriod(update_reboot_needed_uptime_);
2024 2301
2025 // Verify that unless a non-kiosk-app session is in progress, the device 2302 // Verify that unless a non-kiosk-app session is in progress, the device
2026 // eventually reboots. 2303 // eventually reboots.
2027 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 2304 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2028 is_logged_in_as_kiosk_app_); 2305 is_logged_in_as_kiosk_app_);
2029 } 2306 }
2030 2307
2031 // Chrome is starting. The uptime limit is set to 6 hours. Also, an update was 2308 // Chrome is starting. The uptime limit is set to 6 hours. Also, an update was
2032 // applied and a reboot became necessary to complete the update process after 2309 // applied and a reboot became necessary to complete the update process after
2033 // 6 hours of uptime. The current uptime is not available. 2310 // 6 hours of uptime. The current uptime is not available.
2034 // Verifies that even if the policy to automatically reboot after an update is 2311 // Verifies that even if the policy to automatically reboot after an update is
2035 // enabled, no reboot occurs and no grace period is scheduled. 2312 // enabled, no reboot occurs and no grace period is scheduled.
2036 TEST_P(AutomaticRebootManagerTest, StartNoUptime) { 2313 TEST_P(AutomaticRebootManagerTest, StartNoUptime) {
2037 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 2314 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
2038 SetUpdateStatusNeedReboot(); 2315 SetUpdateStatusNeedReboot();
2039 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); 2316 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
2040 SetRebootAfterUpdate(true, false); 2317 SetRebootAfterUpdate(true, false);
2041 2318
2042 // Verify that the device does not reboot immediately. 2319 // Verify that no reboot is requested and the device does not reboot
2320 // immediately.
2321 ExpectNoRebootRequest();
2043 CreateAutomaticRebootManager(false); 2322 CreateAutomaticRebootManager(false);
2323 VerifyNoRebootRequested();
2044 2324
2045 // Verify that no grace period has started. 2325 // Verify that no grace period has started.
2046 VerifyNoGracePeriod(); 2326 VerifyNoGracePeriod();
2047 2327
2048 // Verify that the device does not reboot eventually. 2328 // Verify that a reboot is never requested and the device never reboots.
2049 FastForwardUntilNoTasksRemain(false); 2329 FastForwardUntilNoTasksRemain(false);
2050 } 2330 }
2051 2331
2052 INSTANTIATE_TEST_CASE_P( 2332 INSTANTIATE_TEST_CASE_P(
2053 AutomaticRebootManagerTestInstance, 2333 AutomaticRebootManagerTestInstance,
2054 AutomaticRebootManagerTest, 2334 AutomaticRebootManagerTest,
2055 ::testing::Values( 2335 ::testing::Values(
2056 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN, 2336 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN,
2057 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION, 2337 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION,
2058 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION)); 2338 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION));
2059 2339
2060 } // namespace system 2340 } // namespace system
2061 } // namespace chromeos 2341 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698