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

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

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

Powered by Google App Engine
This is Rietveld 408576698