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

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

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