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

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

Issue 823143004: Add TestMockTimeTaskRunner in base/test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update year in copyright notice. Rebase. Created 5 years, 11 months 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/session_length_limiter_unittest.cc ('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>
9 8
10 #include "ash/shell.h" 9 #include "ash/shell.h"
11 #include "ash/test/test_shell_delegate.h" 10 #include "ash/test/test_shell_delegate.h"
12 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
15 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
16 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
17 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
18 #include "base/path_service.h" 17 #include "base/path_service.h"
19 #include "base/prefs/pref_registry_simple.h" 18 #include "base/prefs/pref_registry_simple.h"
20 #include "base/prefs/testing_pref_service.h" 19 #include "base/prefs/testing_pref_service.h"
21 #include "base/run_loop.h" 20 #include "base/run_loop.h"
22 #include "base/single_thread_task_runner.h"
23 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
24 #include "base/test/simple_test_tick_clock.h" 22 #include "base/test/simple_test_tick_clock.h"
23 #include "base/test/test_mock_time_task_runner.h"
25 #include "base/thread_task_runner_handle.h" 24 #include "base/thread_task_runner_handle.h"
26 #include "base/threading/sequenced_worker_pool.h" 25 #include "base/threading/sequenced_worker_pool.h"
27 #include "base/time/tick_clock.h" 26 #include "base/time/tick_clock.h"
28 #include "base/values.h" 27 #include "base/values.h"
29 #include "chrome/browser/chrome_notification_types.h" 28 #include "chrome/browser/chrome_notification_types.h"
30 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" 29 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
31 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 30 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
32 #include "chrome/browser/chromeos/system/automatic_reboot_manager_observer.h" 31 #include "chrome/browser/chromeos/system/automatic_reboot_manager_observer.h"
33 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
34 #include "chrome/test/base/testing_browser_process.h" 33 #include "chrome/test/base/testing_browser_process.h"
(...skipping 13 matching lines...) Expand all
48 using ::testing::_; 47 using ::testing::_;
49 using ::testing::Invoke; 48 using ::testing::Invoke;
50 using ::testing::Mock; 49 using ::testing::Mock;
51 using ::testing::ReturnPointee; 50 using ::testing::ReturnPointee;
52 51
53 namespace chromeos { 52 namespace chromeos {
54 namespace system { 53 namespace system {
55 54
56 namespace { 55 namespace {
57 56
58 // A SingleThreadTaskRunner that mocks the current time and allows it to be 57 // Provides a mock device uptime that follows the given |tick_clock_| with a
59 // fast-forwarded. The current time in ticks is returned by Now(). The 58 // configurable offset. The mock uptime can also be written to |uptime_file_|,
60 // corresponding device uptime is written to |uptime_file_|, providing a mock 59 // thusly allowing to mock /proc/uptime.
61 // for /proc/uptime. 60 class MockUptimeProvider {
62 class MockTimeSingleThreadTaskRunner : public base::SingleThreadTaskRunner {
63 public: 61 public:
64 MockTimeSingleThreadTaskRunner(); 62 explicit MockUptimeProvider(scoped_ptr<base::TickClock> tick_clock);
65 63
66 // base::SingleThreadTaskRunner: 64 void WriteUptimeToFile();
67 virtual bool RunsTasksOnCurrentThread() const override;
68 virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
69 const base::Closure& task,
70 base::TimeDelta delay) override;
71 virtual bool PostNonNestableDelayedTask(
72 const tracked_objects::Location& from_here,
73 const base::Closure& task,
74 base::TimeDelta delay) override;
75 65
76 void SetUptimeFile(const base::FilePath& uptime_file); 66 // Adjusts the offset so that the current mock uptime will be |uptime|.
77 void SetUptime(const base::TimeDelta& uptime); 67 void SetUptime(const base::TimeDelta& uptime);
78 68
79 const base::TimeDelta& Uptime() const; 69 void set_uptime_file_path(const base::FilePath& uptime_file_path) {
80 const base::TimeTicks& Now() const; 70 uptime_file_path_ = uptime_file_path;
71 }
81 72
82 void FastForwardBy(const base::TimeDelta& delta); 73 base::TimeDelta uptime() const {
83 void FastForwardUntilNoTasksRemain(); 74 return tick_clock_->NowTicks() - base::TimeTicks() + uptime_offset_;
84 void RunUntilIdle(); 75 }
85 76
86 private: 77 private:
87 // Strict weak temporal ordering of tasks. 78 scoped_ptr<base::TickClock> tick_clock_;
88 class TemporalOrder {
89 public:
90 bool operator()(
91 const std::pair<base::TimeTicks, base::Closure>& first_task,
92 const std::pair<base::TimeTicks, base::Closure>& second_task) const;
93 };
94 79
95 virtual ~MockTimeSingleThreadTaskRunner(); 80 base::FilePath uptime_file_path_;
81 base::TimeDelta uptime_offset_;
96 82
97 base::FilePath uptime_file_; 83 DISALLOW_COPY_AND_ASSIGN(MockUptimeProvider);
98 base::TimeDelta uptime_;
99 base::TimeTicks now_;
100 std::priority_queue<std::pair<base::TimeTicks, base::Closure>,
101 std::vector<std::pair<base::TimeTicks, base::Closure> >,
102 TemporalOrder> tasks_;
103
104 DISALLOW_COPY_AND_ASSIGN(MockTimeSingleThreadTaskRunner);
105 }; 84 };
106 85
107 class MockTimeTickClock : public base::TickClock { 86 class TestAutomaticRebootManagerTaskRunner
87 : public base::TestMockTimeTaskRunner {
108 public: 88 public:
109 explicit MockTimeTickClock( 89 TestAutomaticRebootManagerTaskRunner();
110 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner);
111 virtual ~MockTimeTickClock();
112 90
113 // base::TickClock: 91 MockUptimeProvider* uptime_provider() const {
114 virtual base::TimeTicks NowTicks() override; 92 return uptime_provider_.get();
93 }
115 94
116 private: 95 private:
117 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_; 96 ~TestAutomaticRebootManagerTaskRunner() override;
118 97
119 DISALLOW_COPY_AND_ASSIGN(MockTimeTickClock); 98 // base::TestMockTimeTaskRunner:
99 void OnBeforeSelectingTask() override;
100 void OnAfterTimePassed() override;
101 void OnAfterTaskRun() override;
102
103 scoped_ptr<MockUptimeProvider> uptime_provider_;
104
105 DISALLOW_COPY_AND_ASSIGN(TestAutomaticRebootManagerTaskRunner);
120 }; 106 };
121 107
122 class MockAutomaticRebootManagerObserver 108 class MockAutomaticRebootManagerObserver
123 : public AutomaticRebootManagerObserver { 109 : public AutomaticRebootManagerObserver {
124 public: 110 public:
125 MockAutomaticRebootManagerObserver(); 111 MockAutomaticRebootManagerObserver();
126 ~MockAutomaticRebootManagerObserver() override; 112 ~MockAutomaticRebootManagerObserver() override;
127 113
128 void Init(AutomaticRebootManager* automatic_reboot_manger); 114 void Init(AutomaticRebootManager* automatic_reboot_manger);
129 115
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 bool ReadUpdateRebootNeededUptimeFromFile(base::TimeDelta* uptime); 156 bool ReadUpdateRebootNeededUptimeFromFile(base::TimeDelta* uptime);
171 void VerifyRebootRequested(AutomaticRebootManagerObserver::Reason reason); 157 void VerifyRebootRequested(AutomaticRebootManagerObserver::Reason reason);
172 void VerifyNoRebootRequested() const; 158 void VerifyNoRebootRequested() const;
173 void VerifyLoginScreenIdleTimerIsStopped() const; 159 void VerifyLoginScreenIdleTimerIsStopped() const;
174 void VerifyNoGracePeriod() const; 160 void VerifyNoGracePeriod() const;
175 void VerifyGracePeriod(const base::TimeDelta& start_uptime) const; 161 void VerifyGracePeriod(const base::TimeDelta& start_uptime) const;
176 162
177 // Sets the status of |update_engine_client_| to NEED_REBOOT for tests. 163 // Sets the status of |update_engine_client_| to NEED_REBOOT for tests.
178 void SetUpdateStatusNeedReboot(); 164 void SetUpdateStatusNeedReboot();
179 165
166 MockUptimeProvider* uptime_provider() const {
167 return task_runner_->uptime_provider();
168 }
169
180 bool is_user_logged_in_; 170 bool is_user_logged_in_;
181 bool is_logged_in_as_kiosk_app_; 171 bool is_logged_in_as_kiosk_app_;
182 172
183 // The uptime is read in the blocking thread pool and then processed on the 173 // The uptime is read in the blocking thread pool and then processed on the
184 // UI thread. This causes the UI thread to start processing the uptime when it 174 // UI thread. This causes the UI thread to start processing the uptime when it
185 // has increased by a small offset already. The offset is calculated and 175 // has increased by a small offset already. The offset is calculated and
186 // stored in |uptime_processing_delay_| so that tests can accurately determine 176 // stored in |uptime_processing_delay_| so that tests can accurately determine
187 // the uptime seen by the UI thread. 177 // the uptime seen by the UI thread.
188 base::TimeDelta uptime_processing_delay_; 178 base::TimeDelta uptime_processing_delay_;
189 base::TimeDelta update_reboot_needed_uptime_; 179 base::TimeDelta update_reboot_needed_uptime_;
190 base::TimeDelta uptime_limit_; 180 base::TimeDelta uptime_limit_;
191 181
192 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_; 182 scoped_refptr<TestAutomaticRebootManagerTaskRunner> task_runner_;
193 183
194 MockAutomaticRebootManagerObserver automatic_reboot_manager_observer_; 184 MockAutomaticRebootManagerObserver automatic_reboot_manager_observer_;
195 scoped_ptr<AutomaticRebootManager> automatic_reboot_manager_; 185 scoped_ptr<AutomaticRebootManager> automatic_reboot_manager_;
196 186
197 private: 187 private:
198 void VerifyTimerIsStopped(const Timer* timer) const; 188 void VerifyTimerIsStopped(const Timer* timer) const;
199 void VerifyTimerIsRunning(const Timer* timer, 189 void VerifyTimerIsRunning(const Timer* timer,
200 const base::TimeDelta& delay) const; 190 const base::TimeDelta& delay) const;
201 void VerifyLoginScreenIdleTimerIsRunning() const; 191 void VerifyLoginScreenIdleTimerIsRunning() const;
202 192
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 const base::TimeDelta& uptime) { 227 const base::TimeDelta& uptime) {
238 if (path.empty() || uptime == base::TimeDelta()) 228 if (path.empty() || uptime == base::TimeDelta())
239 return; 229 return;
240 230
241 const std::string uptime_seconds = base::DoubleToString(uptime.InSecondsF()); 231 const std::string uptime_seconds = base::DoubleToString(uptime.InSecondsF());
242 ASSERT_EQ(static_cast<int>(uptime_seconds.size()), 232 ASSERT_EQ(static_cast<int>(uptime_seconds.size()),
243 base::WriteFile(path, uptime_seconds.c_str(), 233 base::WriteFile(path, uptime_seconds.c_str(),
244 uptime_seconds.size())); 234 uptime_seconds.size()));
245 } 235 }
246 236
247 MockTimeSingleThreadTaskRunner::MockTimeSingleThreadTaskRunner() { 237 MockUptimeProvider::MockUptimeProvider(scoped_ptr<base::TickClock> tick_clock)
238 : tick_clock_(tick_clock.Pass()) {
248 } 239 }
249 240
250 bool MockTimeSingleThreadTaskRunner::RunsTasksOnCurrentThread() const { 241 void MockUptimeProvider::WriteUptimeToFile() {
251 return true; 242 SaveUptimeToFile(uptime_file_path_, uptime());
252 } 243 }
253 244
254 bool MockTimeSingleThreadTaskRunner::PostDelayedTask( 245 void MockUptimeProvider::SetUptime(const base::TimeDelta& uptime) {
255 const tracked_objects::Location& from_here, 246 uptime_offset_ = uptime - (tick_clock_->NowTicks() - base::TimeTicks());
256 const base::Closure& task, 247 WriteUptimeToFile();
257 base::TimeDelta delay) {
258 tasks_.push(std::pair<base::TimeTicks, base::Closure>(now_ + delay, task));
259 return true;
260 } 248 }
261 249
262 bool MockTimeSingleThreadTaskRunner::PostNonNestableDelayedTask( 250 TestAutomaticRebootManagerTaskRunner::TestAutomaticRebootManagerTaskRunner()
263 const tracked_objects::Location& from_here, 251 : uptime_provider_(new MockUptimeProvider(GetMockTickClock())) {
264 const base::Closure& task,
265 base::TimeDelta delay) {
266 NOTREACHED();
267 return false;
268 } 252 }
269 253
270 void MockTimeSingleThreadTaskRunner::SetUptimeFile( 254 TestAutomaticRebootManagerTaskRunner::~TestAutomaticRebootManagerTaskRunner() {
271 const base::FilePath& uptime_file) {
272 uptime_file_ = uptime_file;
273 SaveUptimeToFile(uptime_file_, uptime_);
274 } 255 }
275 256
276 void MockTimeSingleThreadTaskRunner::SetUptime(const base::TimeDelta& uptime) { 257 void TestAutomaticRebootManagerTaskRunner::OnBeforeSelectingTask() {
277 uptime_ = uptime;
278 SaveUptimeToFile(uptime_file_, uptime_);
279 }
280
281 const base::TimeDelta& MockTimeSingleThreadTaskRunner::Uptime() const {
282 return uptime_;
283 }
284
285 const base::TimeTicks& MockTimeSingleThreadTaskRunner::Now() const {
286 return now_;
287 }
288
289 void MockTimeSingleThreadTaskRunner::FastForwardBy(
290 const base::TimeDelta& delta) {
291 const base::TimeTicks latest = now_ + delta;
292 base::SequencedWorkerPool* blocking_pool = 258 base::SequencedWorkerPool* blocking_pool =
293 content::BrowserThread::GetBlockingPool(); 259 content::BrowserThread::GetBlockingPool();
294 blocking_pool->FlushForTesting(); 260 blocking_pool->FlushForTesting();
295 while (!tasks_.empty() && tasks_.top().first <= latest) {
296 uptime_ += tasks_.top().first - now_;
297 SaveUptimeToFile(uptime_file_, uptime_);
298 now_ = tasks_.top().first;
299 base::Closure task = tasks_.top().second;
300 tasks_.pop();
301 task.Run();
302 blocking_pool->FlushForTesting();
303 }
304 uptime_ += latest - now_;
305 SaveUptimeToFile(uptime_file_, uptime_);
306 now_ = latest;
307 } 261 }
308 262
309 void MockTimeSingleThreadTaskRunner::FastForwardUntilNoTasksRemain() { 263 void TestAutomaticRebootManagerTaskRunner::OnAfterTimePassed() {
264 uptime_provider_->WriteUptimeToFile();
265 }
266
267 void TestAutomaticRebootManagerTaskRunner::OnAfterTaskRun() {
310 base::SequencedWorkerPool* blocking_pool = 268 base::SequencedWorkerPool* blocking_pool =
311 content::BrowserThread::GetBlockingPool(); 269 content::BrowserThread::GetBlockingPool();
312 blocking_pool->FlushForTesting(); 270 blocking_pool->FlushForTesting();
313 while (!tasks_.empty()) {
314 uptime_ += tasks_.top().first - now_;
315 SaveUptimeToFile(uptime_file_, uptime_);
316 now_ = tasks_.top().first;
317 base::Closure task = tasks_.top().second;
318 tasks_.pop();
319 task.Run();
320 blocking_pool->FlushForTesting();
321 }
322 }
323
324 void MockTimeSingleThreadTaskRunner::RunUntilIdle() {
325 base::SequencedWorkerPool* blocking_pool =
326 content::BrowserThread::GetBlockingPool();
327 blocking_pool->FlushForTesting();
328 while (!tasks_.empty() && tasks_.top().first <= now_) {
329 base::Closure task = tasks_.top().second;
330 tasks_.pop();
331 task.Run();
332 blocking_pool->FlushForTesting();
333 }
334 }
335
336 bool MockTimeSingleThreadTaskRunner::TemporalOrder::operator()(
337 const std::pair<base::TimeTicks, base::Closure>& first_task,
338 const std::pair<base::TimeTicks, base::Closure>& second_task) const {
339 return first_task.first > second_task.first;
340 }
341
342 MockTimeSingleThreadTaskRunner::~MockTimeSingleThreadTaskRunner() {
343 }
344
345 MockTimeTickClock::MockTimeTickClock(
346 scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner)
347 : task_runner_(task_runner) {
348 }
349
350 MockTimeTickClock::~MockTimeTickClock() {
351 }
352
353 base::TimeTicks MockTimeTickClock::NowTicks() {
354 return task_runner_->Now();
355 } 271 }
356 272
357 MockAutomaticRebootManagerObserver::MockAutomaticRebootManagerObserver() 273 MockAutomaticRebootManagerObserver::MockAutomaticRebootManagerObserver()
358 : automatic_reboot_manger_(nullptr) { 274 : automatic_reboot_manger_(nullptr) {
359 ON_CALL(*this, WillDestroyAutomaticRebootManager()) 275 ON_CALL(*this, WillDestroyAutomaticRebootManager())
360 .WillByDefault( 276 .WillByDefault(
361 Invoke(this, 277 Invoke(this,
362 &MockAutomaticRebootManagerObserver::StopObserving)); 278 &MockAutomaticRebootManagerObserver::StopObserving));
363 } 279 }
364 280
(...skipping 11 matching lines...) Expand all
376 292
377 void MockAutomaticRebootManagerObserver::StopObserving() { 293 void MockAutomaticRebootManagerObserver::StopObserving() {
378 ASSERT_TRUE(automatic_reboot_manger_); 294 ASSERT_TRUE(automatic_reboot_manger_);
379 automatic_reboot_manger_->RemoveObserver(this); 295 automatic_reboot_manger_->RemoveObserver(this);
380 automatic_reboot_manger_ = nullptr; 296 automatic_reboot_manger_ = nullptr;
381 } 297 }
382 298
383 AutomaticRebootManagerBasicTest::AutomaticRebootManagerBasicTest() 299 AutomaticRebootManagerBasicTest::AutomaticRebootManagerBasicTest()
384 : is_user_logged_in_(false), 300 : is_user_logged_in_(false),
385 is_logged_in_as_kiosk_app_(false), 301 is_logged_in_as_kiosk_app_(false),
386 task_runner_(new MockTimeSingleThreadTaskRunner), 302 task_runner_(new TestAutomaticRebootManagerTaskRunner),
387 reboot_after_update_(false), 303 reboot_after_update_(false),
388 ui_thread_task_runner_handle_(task_runner_), 304 ui_thread_task_runner_handle_(task_runner_),
389 mock_user_manager_(new MockUserManager), 305 mock_user_manager_(new MockUserManager),
390 user_manager_enabler_(mock_user_manager_), 306 user_manager_enabler_(mock_user_manager_),
391 power_manager_client_(NULL), 307 power_manager_client_(NULL),
392 update_engine_client_(NULL) { 308 update_engine_client_(NULL) {
393 } 309 }
394 310
395 AutomaticRebootManagerBasicTest::~AutomaticRebootManagerBasicTest() { 311 AutomaticRebootManagerBasicTest::~AutomaticRebootManagerBasicTest() {
396 } 312 }
397 313
398 void AutomaticRebootManagerBasicTest::SetUp() { 314 void AutomaticRebootManagerBasicTest::SetUp() {
399 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 315 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
400 const base::FilePath& temp_dir = temp_dir_.path(); 316 const base::FilePath& temp_dir = temp_dir_.path();
401 const base::FilePath uptime_file = temp_dir.Append("uptime"); 317 const base::FilePath uptime_file = temp_dir.Append("uptime");
402 task_runner_->SetUptimeFile(uptime_file); 318 uptime_provider()->set_uptime_file_path(uptime_file);
403 ASSERT_FALSE(base::WriteFile(uptime_file, NULL, 0)); 319 ASSERT_FALSE(base::WriteFile(uptime_file, NULL, 0));
404 update_reboot_needed_uptime_file_ = 320 update_reboot_needed_uptime_file_ =
405 temp_dir.Append("update_reboot_needed_uptime"); 321 temp_dir.Append("update_reboot_needed_uptime");
406 ASSERT_FALSE(base::WriteFile(update_reboot_needed_uptime_file_, NULL, 0)); 322 ASSERT_FALSE(base::WriteFile(update_reboot_needed_uptime_file_, NULL, 0));
407 ASSERT_TRUE(PathService::Override(chromeos::FILE_UPTIME, uptime_file)); 323 ASSERT_TRUE(PathService::Override(chromeos::FILE_UPTIME, uptime_file));
408 ASSERT_TRUE(PathService::Override(chromeos::FILE_UPDATE_REBOOT_NEEDED_UPTIME, 324 ASSERT_TRUE(PathService::Override(chromeos::FILE_UPDATE_REBOOT_NEEDED_UPTIME,
409 update_reboot_needed_uptime_file_)); 325 update_reboot_needed_uptime_file_));
410 326
411 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); 327 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
412 AutomaticRebootManager::RegisterPrefs(local_state_.registry()); 328 AutomaticRebootManager::RegisterPrefs(local_state_.registry());
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 Mock::VerifyAndClearExpectations(&automatic_reboot_manager_observer_); 447 Mock::VerifyAndClearExpectations(&automatic_reboot_manager_observer_);
532 EXPECT_CALL(automatic_reboot_manager_observer_, 448 EXPECT_CALL(automatic_reboot_manager_observer_,
533 WillDestroyAutomaticRebootManager()).Times(0); 449 WillDestroyAutomaticRebootManager()).Times(0);
534 EXPECT_CALL(automatic_reboot_manager_observer_, 450 EXPECT_CALL(automatic_reboot_manager_observer_,
535 OnRebootRequested(_)).Times(0); 451 OnRebootRequested(_)).Times(0);
536 } 452 }
537 453
538 void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager( 454 void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager(
539 bool expect_reboot) { 455 bool expect_reboot) {
540 automatic_reboot_manager_.reset(new AutomaticRebootManager( 456 automatic_reboot_manager_.reset(new AutomaticRebootManager(
541 scoped_ptr<base::TickClock>(new MockTimeTickClock(task_runner_)))); 457 scoped_ptr<base::TickClock>(task_runner_->GetMockTickClock())));
542 automatic_reboot_manager_observer_.Init(automatic_reboot_manager_.get()); 458 automatic_reboot_manager_observer_.Init(automatic_reboot_manager_.get());
543 task_runner_->RunUntilIdle(); 459 task_runner_->RunUntilIdle();
544 EXPECT_EQ(expect_reboot ? 1 : 0, 460 EXPECT_EQ(expect_reboot ? 1 : 0,
545 power_manager_client_->num_request_restart_calls()); 461 power_manager_client_->num_request_restart_calls());
546 462
547 uptime_processing_delay_ = 463 uptime_processing_delay_ =
548 base::TimeTicks() - automatic_reboot_manager_->boot_time_ - 464 base::TimeTicks() - automatic_reboot_manager_->boot_time_ -
549 task_runner_->Uptime(); 465 uptime_provider()->uptime();
550 EXPECT_GE(uptime_processing_delay_, base::TimeDelta()); 466 EXPECT_GE(uptime_processing_delay_, base::TimeDelta());
551 EXPECT_LE(uptime_processing_delay_, base::TimeDelta::FromSeconds(1)); 467 EXPECT_LE(uptime_processing_delay_, base::TimeDelta::FromSeconds(1));
552 468
553 if (is_user_logged_in_ || expect_reboot) 469 if (is_user_logged_in_ || expect_reboot)
554 VerifyLoginScreenIdleTimerIsStopped(); 470 VerifyLoginScreenIdleTimerIsStopped();
555 else 471 else
556 VerifyLoginScreenIdleTimerIsRunning(); 472 VerifyLoginScreenIdleTimerIsRunning();
557 } 473 }
558 474
559 bool AutomaticRebootManagerBasicTest::ReadUpdateRebootNeededUptimeFromFile( 475 bool AutomaticRebootManagerBasicTest::ReadUpdateRebootNeededUptimeFromFile(
(...skipping 29 matching lines...) Expand all
589 505
590 void AutomaticRebootManagerBasicTest::VerifyNoGracePeriod() const { 506 void AutomaticRebootManagerBasicTest::VerifyNoGracePeriod() const {
591 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_); 507 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_);
592 VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get()); 508 VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get());
593 VerifyTimerIsStopped(automatic_reboot_manager_->grace_end_timer_.get()); 509 VerifyTimerIsStopped(automatic_reboot_manager_->grace_end_timer_.get());
594 } 510 }
595 511
596 void AutomaticRebootManagerBasicTest::VerifyGracePeriod( 512 void AutomaticRebootManagerBasicTest::VerifyGracePeriod(
597 const base::TimeDelta& start_uptime) const { 513 const base::TimeDelta& start_uptime) const {
598 const base::TimeDelta start = 514 const base::TimeDelta start =
599 start_uptime - task_runner_->Uptime() - uptime_processing_delay_; 515 start_uptime - uptime_provider()->uptime() - uptime_processing_delay_;
600 const base::TimeDelta end = start + base::TimeDelta::FromHours(24); 516 const base::TimeDelta end = start + base::TimeDelta::FromHours(24);
601 if (start <= base::TimeDelta()) { 517 if (start <= base::TimeDelta()) {
602 EXPECT_TRUE(automatic_reboot_manager_->reboot_requested_); 518 EXPECT_TRUE(automatic_reboot_manager_->reboot_requested_);
603 VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get()); 519 VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get());
604 VerifyTimerIsRunning(automatic_reboot_manager_->grace_end_timer_.get(), 520 VerifyTimerIsRunning(automatic_reboot_manager_->grace_end_timer_.get(),
605 end); 521 end);
606 } else { 522 } else {
607 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_); 523 EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_);
608 VerifyTimerIsRunning(automatic_reboot_manager_->grace_start_timer_.get(), 524 VerifyTimerIsRunning(automatic_reboot_manager_->grace_start_timer_.get(),
609 start); 525 start);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 } 573 }
658 } 574 }
659 575
660 AutomaticRebootManagerTest::~AutomaticRebootManagerTest() { 576 AutomaticRebootManagerTest::~AutomaticRebootManagerTest() {
661 } 577 }
662 578
663 // Chrome is showing the login screen. The current uptime is 12 hours. 579 // Chrome is showing the login screen. The current uptime is 12 hours.
664 // Verifies that the idle timer is running. Further verifies that when a kiosk 580 // Verifies that the idle timer is running. Further verifies that when a kiosk
665 // app session begins, the idle timer is stopped. 581 // app session begins, the idle timer is stopped.
666 TEST_F(AutomaticRebootManagerBasicTest, LoginStopsIdleTimer) { 582 TEST_F(AutomaticRebootManagerBasicTest, LoginStopsIdleTimer) {
667 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 583 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
668 584
669 // Verify that no reboot is requested, the device does not reboot immediately 585 // Verify that no reboot is requested, the device does not reboot immediately
670 // and the login screen idle timer is started. 586 // and the login screen idle timer is started.
671 ExpectNoRebootRequest(); 587 ExpectNoRebootRequest();
672 CreateAutomaticRebootManager(false); 588 CreateAutomaticRebootManager(false);
673 VerifyNoRebootRequested(); 589 VerifyNoRebootRequested();
674 590
675 // Notify that a kiosk app session has been started. 591 // Notify that a kiosk app session has been started.
676 is_user_logged_in_ = true; 592 is_user_logged_in_ = true;
677 is_logged_in_as_kiosk_app_ = true; 593 is_logged_in_as_kiosk_app_ = true;
678 automatic_reboot_manager_->Observe( 594 automatic_reboot_manager_->Observe(
679 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 595 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
680 content::Source<AutomaticRebootManagerBasicTest>(this), 596 content::Source<AutomaticRebootManagerBasicTest>(this),
681 content::NotificationService::NoDetails()); 597 content::NotificationService::NoDetails());
682 598
683 // Verify that the login screen idle timer is stopped. 599 // Verify that the login screen idle timer is stopped.
684 VerifyLoginScreenIdleTimerIsStopped(); 600 VerifyLoginScreenIdleTimerIsStopped();
685 601
686 // Verify that a reboot is never requested and the device never reboots. 602 // Verify that a reboot is never requested and the device never reboots.
687 FastForwardUntilNoTasksRemain(false); 603 FastForwardUntilNoTasksRemain(false);
688 } 604 }
689 605
690 // Chrome is showing the login screen. The current uptime is 12 hours. 606 // Chrome is showing the login screen. The current uptime is 12 hours.
691 // Verifies that the idle timer is running. Further verifies that when a 607 // Verifies that the idle timer is running. Further verifies that when a
692 // non-kiosk-app session begins, the idle timer is stopped. 608 // non-kiosk-app session begins, the idle timer is stopped.
693 TEST_F(AutomaticRebootManagerBasicTest, NonKioskLoginStopsIdleTimer) { 609 TEST_F(AutomaticRebootManagerBasicTest, NonKioskLoginStopsIdleTimer) {
694 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 610 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
695 611
696 // Verify that no reboot is requested, the device does not reboot immediately 612 // Verify that no reboot is requested, the device does not reboot immediately
697 // and the login screen idle timer is started. 613 // and the login screen idle timer is started.
698 ExpectNoRebootRequest(); 614 ExpectNoRebootRequest();
699 CreateAutomaticRebootManager(false); 615 CreateAutomaticRebootManager(false);
700 VerifyNoRebootRequested(); 616 VerifyNoRebootRequested();
701 617
702 // Notify that a non-kiosk-app session has been started. 618 // Notify that a non-kiosk-app session has been started.
703 is_user_logged_in_ = true; 619 is_user_logged_in_ = true;
704 automatic_reboot_manager_->Observe( 620 automatic_reboot_manager_->Observe(
705 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 621 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
706 content::Source<AutomaticRebootManagerBasicTest>(this), 622 content::Source<AutomaticRebootManagerBasicTest>(this),
707 content::NotificationService::NoDetails()); 623 content::NotificationService::NoDetails());
708 624
709 // Verify that the login screen idle timer is stopped. 625 // Verify that the login screen idle timer is stopped.
710 VerifyLoginScreenIdleTimerIsStopped(); 626 VerifyLoginScreenIdleTimerIsStopped();
711 627
712 // Verify that a reboot is never requested and the device never reboots. 628 // Verify that a reboot is never requested and the device never reboots.
713 FastForwardUntilNoTasksRemain(false); 629 FastForwardUntilNoTasksRemain(false);
714 } 630 }
715 631
716 // Chrome is showing the login screen. The uptime limit is 6 hours. The current 632 // Chrome is showing the login screen. The uptime limit is 6 hours. The current
717 // uptime is 12 hours. 633 // uptime is 12 hours.
718 // Verifies that user activity prevents the device from rebooting. Further 634 // Verifies that user activity prevents the device from rebooting. Further
719 // verifies that when user activity ceases, the devices reboots. 635 // verifies that when user activity ceases, the devices reboots.
720 TEST_F(AutomaticRebootManagerBasicTest, UserActivityResetsIdleTimer) { 636 TEST_F(AutomaticRebootManagerBasicTest, UserActivityResetsIdleTimer) {
721 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 637 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
722 638
723 // Verify that no reboot is requested, the device does not reboot immediately 639 // Verify that no reboot is requested, the device does not reboot immediately
724 // and the login screen idle timer is started. 640 // and the login screen idle timer is started.
725 ExpectNoRebootRequest(); 641 ExpectNoRebootRequest();
726 CreateAutomaticRebootManager(false); 642 CreateAutomaticRebootManager(false);
727 VerifyNoRebootRequested(); 643 VerifyNoRebootRequested();
728 644
729 // Set the uptime limit. Verify that a reboot is requested but the device does 645 // Set the uptime limit. Verify that a reboot is requested but the device does
730 // not reboot immediately. 646 // not reboot immediately.
731 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 647 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
(...skipping 17 matching lines...) Expand all
749 // Verify that the device reboots immediately. 665 // Verify that the device reboots immediately.
750 FastForwardBy(base::TimeDelta::FromSeconds(60), true); 666 FastForwardBy(base::TimeDelta::FromSeconds(60), true);
751 } 667 }
752 668
753 // Chrome is running a kiosk app session. The current uptime is 10 days. 669 // Chrome is running a kiosk app session. The current uptime is 10 days.
754 // Verifies that when the device is suspended and then resumes, it does not 670 // Verifies that when the device is suspended and then resumes, it does not
755 // immediately reboot. 671 // immediately reboot.
756 TEST_F(AutomaticRebootManagerBasicTest, ResumeNoPolicy) { 672 TEST_F(AutomaticRebootManagerBasicTest, ResumeNoPolicy) {
757 is_user_logged_in_ = true; 673 is_user_logged_in_ = true;
758 is_logged_in_as_kiosk_app_ = true; 674 is_logged_in_as_kiosk_app_ = true;
759 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 675 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
760 676
761 // Verify that no reboot is requested and the device does not reboot 677 // Verify that no reboot is requested and the device does not reboot
762 // immediately. 678 // immediately.
763 ExpectNoRebootRequest(); 679 ExpectNoRebootRequest();
764 CreateAutomaticRebootManager(false); 680 CreateAutomaticRebootManager(false);
765 VerifyNoRebootRequested(); 681 VerifyNoRebootRequested();
766 682
767 // Verify that no grace period has started. 683 // Verify that no grace period has started.
768 VerifyNoGracePeriod(); 684 VerifyNoGracePeriod();
769 685
770 // Notify that the device has resumed from 1 hour of sleep. Verify that no 686 // Notify that the device has resumed from 1 hour of sleep. Verify that no
771 // reboot is requested and the device does not reboot immediately. 687 // reboot is requested and the device does not reboot immediately.
772 NotifyResumed(false); 688 NotifyResumed(false);
773 689
774 // Verify that a reboot is never requested and the device never reboots. 690 // Verify that a reboot is never requested and the device never reboots.
775 FastForwardUntilNoTasksRemain(false); 691 FastForwardUntilNoTasksRemain(false);
776 } 692 }
777 693
778 // Chrome is running a non-kiosk-app session. The current uptime is 10 days. 694 // Chrome is running a non-kiosk-app session. The current uptime is 10 days.
779 // Verifies that when the device is suspended and then resumes, it does not 695 // Verifies that when the device is suspended and then resumes, it does not
780 // immediately reboot. 696 // immediately reboot.
781 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAppNoPolicy) { 697 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAppNoPolicy) {
782 is_user_logged_in_ = true; 698 is_user_logged_in_ = true;
783 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 699 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
784 700
785 // Verify that no reboot is requested and the device does not reboot 701 // Verify that no reboot is requested and the device does not reboot
786 // immediately. 702 // immediately.
787 ExpectNoRebootRequest(); 703 ExpectNoRebootRequest();
788 CreateAutomaticRebootManager(false); 704 CreateAutomaticRebootManager(false);
789 VerifyNoRebootRequested(); 705 VerifyNoRebootRequested();
790 706
791 // Verify that no grace period has started. 707 // Verify that no grace period has started.
792 VerifyNoGracePeriod(); 708 VerifyNoGracePeriod();
793 709
794 // Notify that the device has resumed from 1 hour of sleep. Verify that no 710 // Notify that the device has resumed from 1 hour of sleep. Verify that no
795 // reboot is requested and the device does not reboot immediately. 711 // reboot is requested and the device does not reboot immediately.
796 NotifyResumed(false); 712 NotifyResumed(false);
797 713
798 // Verify that a reboot is never requested and the device never reboots. 714 // Verify that a reboot is never requested and the device never reboots.
799 FastForwardUntilNoTasksRemain(false); 715 FastForwardUntilNoTasksRemain(false);
800 } 716 }
801 717
802 // Chrome is running a kiosk app session. The uptime limit is 24 hours. The 718 // Chrome is running a kiosk app session. The uptime limit is 24 hours. The
803 // current uptime is 12 hours. 719 // current uptime is 12 hours.
804 // Verifies that when the device is suspended and then resumes, it does not 720 // Verifies that when the device is suspended and then resumes, it does not
805 // immediately reboot. 721 // immediately reboot.
806 TEST_F(AutomaticRebootManagerBasicTest, ResumeBeforeGracePeriod) { 722 TEST_F(AutomaticRebootManagerBasicTest, ResumeBeforeGracePeriod) {
807 is_user_logged_in_ = true; 723 is_user_logged_in_ = true;
808 is_logged_in_as_kiosk_app_ = true; 724 is_logged_in_as_kiosk_app_ = true;
809 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 725 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
810 726
811 // Verify that no reboot is requested and the device does not reboot 727 // Verify that no reboot is requested and the device does not reboot
812 // immediately. 728 // immediately.
813 ExpectNoRebootRequest(); 729 ExpectNoRebootRequest();
814 CreateAutomaticRebootManager(false); 730 CreateAutomaticRebootManager(false);
815 VerifyNoRebootRequested(); 731 VerifyNoRebootRequested();
816 732
817 // Set the uptime limit. Verify that no reboot is requested and the device 733 // Set the uptime limit. Verify that no reboot is requested and the device
818 // does not reboot immediately. 734 // does not reboot immediately.
819 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 735 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
820 736
821 // Verify that a grace period has been scheduled to start in the future. 737 // Verify that a grace period has been scheduled to start in the future.
822 VerifyGracePeriod(uptime_limit_); 738 VerifyGracePeriod(uptime_limit_);
823 739
824 // Notify that the device has resumed from 1 hour of sleep. Verify that no 740 // Notify that the device has resumed from 1 hour of sleep. Verify that no
825 // reboot is requested and the device does not reboot immediately. 741 // reboot is requested and the device does not reboot immediately.
826 NotifyResumed(false); 742 NotifyResumed(false);
827 743
828 // Verify a reboot is requested and the device reboots eventually. 744 // Verify a reboot is requested and the device reboots eventually.
829 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 745 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
830 FastForwardUntilNoTasksRemain(true); 746 FastForwardUntilNoTasksRemain(true);
831 } 747 }
832 748
833 // Chrome is running a non-kiosk-app session. The uptime limit is 24 hours. The 749 // Chrome is running a non-kiosk-app session. The uptime limit is 24 hours. The
834 // current uptime is 12 hours. 750 // current uptime is 12 hours.
835 // Verifies that when the device is suspended and then resumes, it does not 751 // Verifies that when the device is suspended and then resumes, it does not
836 // immediately reboot. 752 // immediately reboot.
837 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeBeforeGracePeriod) { 753 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeBeforeGracePeriod) {
838 is_user_logged_in_ = true; 754 is_user_logged_in_ = true;
839 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 755 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
840 756
841 // Verify that no reboot is requested and the device does not reboot 757 // Verify that no reboot is requested and the device does not reboot
842 // immediately. 758 // immediately.
843 ExpectNoRebootRequest(); 759 ExpectNoRebootRequest();
844 CreateAutomaticRebootManager(false); 760 CreateAutomaticRebootManager(false);
845 VerifyNoRebootRequested(); 761 VerifyNoRebootRequested();
846 762
847 // Set the uptime limit. Verify that no reboot is requested and the device 763 // Set the uptime limit. Verify that no reboot is requested and the device
848 // does not reboot immediately. 764 // does not reboot immediately.
849 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 765 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
(...skipping 10 matching lines...) Expand all
860 FastForwardUntilNoTasksRemain(false); 776 FastForwardUntilNoTasksRemain(false);
861 } 777 }
862 778
863 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The 779 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The
864 // current uptime is 12 hours. 780 // current uptime is 12 hours.
865 // Verifies that when the device is suspended and then resumes, it immediately 781 // Verifies that when the device is suspended and then resumes, it immediately
866 // reboots. 782 // reboots.
867 TEST_F(AutomaticRebootManagerBasicTest, ResumeInGracePeriod) { 783 TEST_F(AutomaticRebootManagerBasicTest, ResumeInGracePeriod) {
868 is_user_logged_in_ = true; 784 is_user_logged_in_ = true;
869 is_logged_in_as_kiosk_app_ = true; 785 is_logged_in_as_kiosk_app_ = true;
870 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 786 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
871 787
872 // Verify that no reboot is requested and the device does not reboot 788 // Verify that no reboot is requested and the device does not reboot
873 // immediately. 789 // immediately.
874 ExpectNoRebootRequest(); 790 ExpectNoRebootRequest();
875 CreateAutomaticRebootManager(false); 791 CreateAutomaticRebootManager(false);
876 VerifyNoRebootRequested(); 792 VerifyNoRebootRequested();
877 793
878 // Set the uptime limit. Verify that a reboot is requested but the device does 794 // Set the uptime limit. Verify that a reboot is requested but the device does
879 // not reboot immediately. 795 // not reboot immediately.
880 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 796 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
881 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 797 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
882 798
883 // Verify that a grace period has started. 799 // Verify that a grace period has started.
884 VerifyGracePeriod(uptime_limit_); 800 VerifyGracePeriod(uptime_limit_);
885 801
886 // Notify that the device has resumed from 1 hour of sleep. Verify that the 802 // Notify that the device has resumed from 1 hour of sleep. Verify that the
887 // device reboots immediately. 803 // device reboots immediately.
888 NotifyResumed(true); 804 NotifyResumed(true);
889 } 805 }
890 806
891 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The 807 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The
892 // current uptime is 12 hours. 808 // current uptime is 12 hours.
893 // Verifies that when the device is suspended and then resumes, it does not 809 // Verifies that when the device is suspended and then resumes, it does not
894 // immediately reboot. 810 // immediately reboot.
895 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeInGracePeriod) { 811 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeInGracePeriod) {
896 is_user_logged_in_ = true; 812 is_user_logged_in_ = true;
897 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 813 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
898 814
899 // Verify that no reboot is requested and the device does not reboot 815 // Verify that no reboot is requested and the device does not reboot
900 // immediately. 816 // immediately.
901 ExpectNoRebootRequest(); 817 ExpectNoRebootRequest();
902 CreateAutomaticRebootManager(false); 818 CreateAutomaticRebootManager(false);
903 VerifyNoRebootRequested(); 819 VerifyNoRebootRequested();
904 820
905 // Set the uptime limit. Verify that a reboot is requested but the device does 821 // Set the uptime limit. Verify that a reboot is requested but the device does
906 // not reboot immediately. 822 // not reboot immediately.
907 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 823 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
(...skipping 10 matching lines...) Expand all
918 FastForwardUntilNoTasksRemain(false); 834 FastForwardUntilNoTasksRemain(false);
919 } 835 }
920 836
921 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The 837 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The
922 // current uptime is 29 hours 30 minutes. 838 // current uptime is 29 hours 30 minutes.
923 // Verifies that when the device is suspended and then resumes, it immediately 839 // Verifies that when the device is suspended and then resumes, it immediately
924 // reboots. 840 // reboots.
925 TEST_F(AutomaticRebootManagerBasicTest, ResumeAfterGracePeriod) { 841 TEST_F(AutomaticRebootManagerBasicTest, ResumeAfterGracePeriod) {
926 is_user_logged_in_ = true; 842 is_user_logged_in_ = true;
927 is_logged_in_as_kiosk_app_ = true; 843 is_logged_in_as_kiosk_app_ = true;
928 task_runner_->SetUptime(base::TimeDelta::FromHours(29) + 844 uptime_provider()->SetUptime(base::TimeDelta::FromHours(29) +
929 base::TimeDelta::FromMinutes(30)); 845 base::TimeDelta::FromMinutes(30));
930 846
931 // Verify that no reboot is requested and the device does not reboot 847 // Verify that no reboot is requested and the device does not reboot
932 // immediately. 848 // immediately.
933 ExpectNoRebootRequest(); 849 ExpectNoRebootRequest();
934 CreateAutomaticRebootManager(false); 850 CreateAutomaticRebootManager(false);
935 VerifyNoRebootRequested(); 851 VerifyNoRebootRequested();
936 852
937 // Set the uptime limit. Verify that a reboot is requested but the device does 853 // Set the uptime limit. Verify that a reboot is requested but the device does
938 // not reboot immediately. 854 // not reboot immediately.
939 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 855 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
940 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 856 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
941 857
942 // Verify that a grace period has started. 858 // Verify that a grace period has started.
943 VerifyGracePeriod(uptime_limit_); 859 VerifyGracePeriod(uptime_limit_);
944 860
945 // Notify that the device has resumed from 1 hour of sleep. Verify that the 861 // Notify that the device has resumed from 1 hour of sleep. Verify that the
946 // device reboots immediately. 862 // device reboots immediately.
947 NotifyResumed(true); 863 NotifyResumed(true);
948 } 864 }
949 865
950 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The 866 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The
951 // current uptime is 29 hours 30 minutes. 867 // current uptime is 29 hours 30 minutes.
952 // Verifies that when the device is suspended and then resumes, it does not 868 // Verifies that when the device is suspended and then resumes, it does not
953 // immediately reboot. 869 // immediately reboot.
954 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAfterGracePeriod) { 870 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAfterGracePeriod) {
955 is_user_logged_in_ = true; 871 is_user_logged_in_ = true;
956 task_runner_->SetUptime(base::TimeDelta::FromHours(29) + 872 uptime_provider()->SetUptime(base::TimeDelta::FromHours(29) +
957 base::TimeDelta::FromMinutes(30)); 873 base::TimeDelta::FromMinutes(30));
958 874
959 // Verify that no reboot is requested and the device does not reboot 875 // Verify that no reboot is requested and the device does not reboot
960 // immediately. 876 // immediately.
961 ExpectNoRebootRequest(); 877 ExpectNoRebootRequest();
962 CreateAutomaticRebootManager(false); 878 CreateAutomaticRebootManager(false);
963 VerifyNoRebootRequested(); 879 VerifyNoRebootRequested();
964 880
965 // Set the uptime limit. Verify that a reboot is requested but the device does 881 // Set the uptime limit. Verify that a reboot is requested but the device does
966 // not reboot immediately. 882 // not reboot immediately.
967 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 883 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
968 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 884 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
969 885
970 // Verify that a grace period has started. 886 // Verify that a grace period has started.
971 VerifyGracePeriod(uptime_limit_); 887 VerifyGracePeriod(uptime_limit_);
972 888
973 // Notify that the device has resumed from 1 hour of sleep. Verify that the 889 // Notify that the device has resumed from 1 hour of sleep. Verify that the
974 // device does not reboot immediately. 890 // device does not reboot immediately.
975 NotifyResumed(false); 891 NotifyResumed(false);
976 892
977 // Verify that the device never reboots. 893 // Verify that the device never reboots.
978 FastForwardUntilNoTasksRemain(false); 894 FastForwardUntilNoTasksRemain(false);
979 } 895 }
980 896
981 // Chrome is running. The current uptime is 10 days. 897 // Chrome is running. The current uptime is 10 days.
982 // Verifies that when the browser terminates, the device does not immediately 898 // Verifies that when the browser terminates, the device does not immediately
983 // reboot. 899 // reboot.
984 TEST_P(AutomaticRebootManagerTest, TerminateNoPolicy) { 900 TEST_P(AutomaticRebootManagerTest, TerminateNoPolicy) {
985 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 901 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
986 902
987 // Verify that no reboot is requested and the device does not reboot 903 // Verify that no reboot is requested and the device does not reboot
988 // immediately. 904 // immediately.
989 ExpectNoRebootRequest(); 905 ExpectNoRebootRequest();
990 CreateAutomaticRebootManager(false); 906 CreateAutomaticRebootManager(false);
991 VerifyNoRebootRequested(); 907 VerifyNoRebootRequested();
992 908
993 // Verify that no grace period has started. 909 // Verify that no grace period has started.
994 VerifyNoGracePeriod(); 910 VerifyNoGracePeriod();
995 911
996 // Notify that the browser is terminating. Verify that no reboot is requested 912 // Notify that the browser is terminating. Verify that no reboot is requested
997 // and the device does not reboot immediately. 913 // and the device does not reboot immediately.
998 NotifyTerminating(false); 914 NotifyTerminating(false);
999 915
1000 // Verify that a reboot is never requested and the device never reboots. 916 // Verify that a reboot is never requested and the device never reboots.
1001 FastForwardUntilNoTasksRemain(false); 917 FastForwardUntilNoTasksRemain(false);
1002 } 918 }
1003 919
1004 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is 920 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is
1005 // 12 hours. 921 // 12 hours.
1006 // Verifies that when the browser terminates, it does not immediately reboot. 922 // Verifies that when the browser terminates, it does not immediately reboot.
1007 TEST_P(AutomaticRebootManagerTest, TerminateBeforeGracePeriod) { 923 TEST_P(AutomaticRebootManagerTest, TerminateBeforeGracePeriod) {
1008 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 924 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1009 925
1010 // Verify that no reboot is requested and the device does not reboot 926 // Verify that no reboot is requested and the device does not reboot
1011 // immediately. 927 // immediately.
1012 ExpectNoRebootRequest(); 928 ExpectNoRebootRequest();
1013 CreateAutomaticRebootManager(false); 929 CreateAutomaticRebootManager(false);
1014 VerifyNoRebootRequested(); 930 VerifyNoRebootRequested();
1015 931
1016 // Set the uptime limit. Verify that no reboot is requested and the device 932 // Set the uptime limit. Verify that no reboot is requested and the device
1017 // does not reboot immediately. 933 // does not reboot immediately.
1018 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 934 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
(...skipping 10 matching lines...) Expand all
1029 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 945 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1030 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 946 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1031 is_logged_in_as_kiosk_app_); 947 is_logged_in_as_kiosk_app_);
1032 } 948 }
1033 949
1034 // Chrome is running. The uptime limit is set to 6 hours. The current uptime is 950 // Chrome is running. The uptime limit is set to 6 hours. The current uptime is
1035 // 12 hours. 951 // 12 hours.
1036 // Verifies that when the browser terminates, the device immediately reboots if 952 // Verifies that when the browser terminates, the device immediately reboots if
1037 // a kiosk app session is in progress. 953 // a kiosk app session is in progress.
1038 TEST_P(AutomaticRebootManagerTest, TerminateInGracePeriod) { 954 TEST_P(AutomaticRebootManagerTest, TerminateInGracePeriod) {
1039 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 955 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1040 956
1041 // Verify that no reboot is requested and the device does not reboot 957 // Verify that no reboot is requested and the device does not reboot
1042 // immediately. 958 // immediately.
1043 ExpectNoRebootRequest(); 959 ExpectNoRebootRequest();
1044 CreateAutomaticRebootManager(false); 960 CreateAutomaticRebootManager(false);
1045 VerifyNoRebootRequested(); 961 VerifyNoRebootRequested();
1046 962
1047 // Set the uptime limit. Verify that a reboot is requested but the device does 963 // Set the uptime limit. Verify that a reboot is requested but the device does
1048 // not reboot immediately. 964 // not reboot immediately.
1049 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 965 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1050 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 966 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1051 967
1052 // Verify that a grace period has started. 968 // Verify that a grace period has started.
1053 VerifyGracePeriod(uptime_limit_); 969 VerifyGracePeriod(uptime_limit_);
1054 970
1055 // Notify that the browser is terminating. Verify that the device immediately 971 // Notify that the browser is terminating. Verify that the device immediately
1056 // reboots if a kiosk app session is in progress. 972 // reboots if a kiosk app session is in progress.
1057 NotifyTerminating(is_logged_in_as_kiosk_app_); 973 NotifyTerminating(is_logged_in_as_kiosk_app_);
1058 974
1059 // Verify that if a non-kiosk-app session is in progress, the device never 975 // Verify that if a non-kiosk-app session is in progress, the device never
1060 // reboots. 976 // reboots.
1061 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 977 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1062 is_logged_in_as_kiosk_app_); 978 is_logged_in_as_kiosk_app_);
1063 } 979 }
1064 980
1065 // Chrome is running. The current uptime is 12 hours. 981 // Chrome is running. The current uptime is 12 hours.
1066 // Verifies that when the uptime limit is set to 24 hours, no reboot occurs and 982 // Verifies that when the uptime limit is set to 24 hours, no reboot occurs and
1067 // a grace period is scheduled to begin after 24 hours of uptime. 983 // a grace period is scheduled to begin after 24 hours of uptime.
1068 TEST_P(AutomaticRebootManagerTest, BeforeUptimeLimitGracePeriod) { 984 TEST_P(AutomaticRebootManagerTest, BeforeUptimeLimitGracePeriod) {
1069 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 985 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1070 986
1071 // Verify that no reboot is requested and the device does not reboot 987 // Verify that no reboot is requested and the device does not reboot
1072 // immediately. 988 // immediately.
1073 ExpectNoRebootRequest(); 989 ExpectNoRebootRequest();
1074 CreateAutomaticRebootManager(false); 990 CreateAutomaticRebootManager(false);
1075 VerifyNoRebootRequested(); 991 VerifyNoRebootRequested();
1076 992
1077 // Verify that no grace period has started. 993 // Verify that no grace period has started.
1078 VerifyNoGracePeriod(); 994 VerifyNoGracePeriod();
1079 995
1080 // Set the uptime limit. Verify that no reboot is requested and the device 996 // Set the uptime limit. Verify that no reboot is requested and the device
1081 // does not reboot immediately. 997 // does not reboot immediately.
1082 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 998 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1083 999
1084 // Verify that a grace period has been scheduled to start in the future. 1000 // Verify that a grace period has been scheduled to start in the future.
1085 VerifyGracePeriod(uptime_limit_); 1001 VerifyGracePeriod(uptime_limit_);
1086 1002
1087 // Verify that a reboot is requested eventually and unless a non-kiosk-app 1003 // Verify that a reboot is requested eventually and unless a non-kiosk-app
1088 // session is in progress, the device eventually reboots. 1004 // session is in progress, the device eventually reboots.
1089 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1005 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1090 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1006 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1091 is_logged_in_as_kiosk_app_); 1007 is_logged_in_as_kiosk_app_);
1092 } 1008 }
1093 1009
1094 // Chrome is running. The current uptime is 12 hours. 1010 // Chrome is running. The current uptime is 12 hours.
1095 // Verifies that when the uptime limit is set to 6 hours, a reboot is requested 1011 // Verifies that when the uptime limit is set to 6 hours, a reboot is requested
1096 // and a grace period is started that will end after 6 + 24 hours of uptime. 1012 // and a grace period is started that will end after 6 + 24 hours of uptime.
1097 TEST_P(AutomaticRebootManagerTest, InUptimeLimitGracePeriod) { 1013 TEST_P(AutomaticRebootManagerTest, InUptimeLimitGracePeriod) {
1098 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1014 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1099 1015
1100 // Verify that no reboot is requested and the device does not reboot 1016 // Verify that no reboot is requested and the device does not reboot
1101 // immediately. 1017 // immediately.
1102 ExpectNoRebootRequest(); 1018 ExpectNoRebootRequest();
1103 CreateAutomaticRebootManager(false); 1019 CreateAutomaticRebootManager(false);
1104 VerifyNoRebootRequested(); 1020 VerifyNoRebootRequested();
1105 1021
1106 // Verify that no grace period has started. 1022 // Verify that no grace period has started.
1107 VerifyNoGracePeriod(); 1023 VerifyNoGracePeriod();
1108 1024
1109 // Set the uptime limit. Verify that a reboot is requested but the device does 1025 // Set the uptime limit. Verify that a reboot is requested but the device does
1110 // not reboot immediately. 1026 // not reboot immediately.
1111 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1027 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1112 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 1028 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1113 1029
1114 // Verify that a grace period has started. 1030 // Verify that a grace period has started.
1115 VerifyGracePeriod(uptime_limit_); 1031 VerifyGracePeriod(uptime_limit_);
1116 1032
1117 // Verify that unless a non-kiosk-app session is in progress, the device 1033 // Verify that unless a non-kiosk-app session is in progress, the device
1118 // eventually reboots. 1034 // eventually reboots.
1119 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1035 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1120 is_logged_in_as_kiosk_app_); 1036 is_logged_in_as_kiosk_app_);
1121 } 1037 }
1122 1038
1123 // Chrome is running. The current uptime is 10 days. 1039 // Chrome is running. The current uptime is 10 days.
1124 // Verifies that when the uptime limit is set to 6 hours, the device reboots 1040 // Verifies that when the uptime limit is set to 6 hours, the device reboots
1125 // immediately if no non-kiosk-app-session is in progress because the grace 1041 // immediately if no non-kiosk-app-session is in progress because the grace
1126 // period ended after 6 + 24 hours of uptime. 1042 // period ended after 6 + 24 hours of uptime.
1127 TEST_P(AutomaticRebootManagerTest, AfterUptimeLimitGracePeriod) { 1043 TEST_P(AutomaticRebootManagerTest, AfterUptimeLimitGracePeriod) {
1128 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 1044 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
1129 1045
1130 // Verify that no reboot is requested and the device does not reboot 1046 // Verify that no reboot is requested and the device does not reboot
1131 // immediately. 1047 // immediately.
1132 ExpectNoRebootRequest(); 1048 ExpectNoRebootRequest();
1133 CreateAutomaticRebootManager(false); 1049 CreateAutomaticRebootManager(false);
1134 VerifyNoRebootRequested(); 1050 VerifyNoRebootRequested();
1135 1051
1136 // Verify that no grace period has started. 1052 // Verify that no grace period has started.
1137 VerifyNoGracePeriod(); 1053 VerifyNoGracePeriod();
1138 1054
1139 // Set the uptime limit. Verify that a reboot is requested and unless a 1055 // Set the uptime limit. Verify that a reboot is requested and unless a
1140 // non-kiosk-app session is in progress, the the device immediately reboots. 1056 // non-kiosk-app session is in progress, the the device immediately reboots.
1141 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1057 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1142 SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ || 1058 SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ ||
1143 is_logged_in_as_kiosk_app_); 1059 is_logged_in_as_kiosk_app_);
1144 1060
1145 // Verify that if a non-kiosk-app session is in progress, the device never 1061 // Verify that if a non-kiosk-app session is in progress, the device never
1146 // reboots. 1062 // reboots.
1147 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1063 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1148 is_logged_in_as_kiosk_app_); 1064 is_logged_in_as_kiosk_app_);
1149 } 1065 }
1150 1066
1151 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is 1067 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
1152 // 6 hours. 1068 // 6 hours.
1153 // Verifies that when the uptime limit is removed, the grace period is removed. 1069 // Verifies that when the uptime limit is removed, the grace period is removed.
1154 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffBeforeGracePeriod) { 1070 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffBeforeGracePeriod) {
1155 task_runner_->SetUptime(base::TimeDelta::FromHours(6)); 1071 uptime_provider()->SetUptime(base::TimeDelta::FromHours(6));
1156 1072
1157 // Verify that no reboot is requested and the device does not reboot 1073 // Verify that no reboot is requested and the device does not reboot
1158 // immediately. 1074 // immediately.
1159 ExpectNoRebootRequest(); 1075 ExpectNoRebootRequest();
1160 CreateAutomaticRebootManager(false); 1076 CreateAutomaticRebootManager(false);
1161 VerifyNoRebootRequested(); 1077 VerifyNoRebootRequested();
1162 1078
1163 // Set the uptime limit. Verify that no reboot is requested and the device 1079 // Set the uptime limit. Verify that no reboot is requested and the device
1164 // does not reboot immediately. 1080 // does not reboot immediately.
1165 SetUptimeLimit(base::TimeDelta::FromHours(12), false); 1081 SetUptimeLimit(base::TimeDelta::FromHours(12), false);
(...skipping 13 matching lines...) Expand all
1179 VerifyNoGracePeriod(); 1095 VerifyNoGracePeriod();
1180 1096
1181 // Verify that a reboot is never requested and the device never reboots. 1097 // Verify that a reboot is never requested and the device never reboots.
1182 FastForwardUntilNoTasksRemain(false); 1098 FastForwardUntilNoTasksRemain(false);
1183 } 1099 }
1184 1100
1185 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is 1101 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
1186 // 24 hours. 1102 // 24 hours.
1187 // Verifies that when the uptime limit is removed, the grace period is removed. 1103 // Verifies that when the uptime limit is removed, the grace period is removed.
1188 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffInGracePeriod) { 1104 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffInGracePeriod) {
1189 task_runner_->SetUptime(base::TimeDelta::FromHours(24)); 1105 uptime_provider()->SetUptime(base::TimeDelta::FromHours(24));
1190 1106
1191 // Verify that no reboot is requested and the device does not reboot 1107 // Verify that no reboot is requested and the device does not reboot
1192 // immediately. 1108 // immediately.
1193 ExpectNoRebootRequest(); 1109 ExpectNoRebootRequest();
1194 CreateAutomaticRebootManager(false); 1110 CreateAutomaticRebootManager(false);
1195 VerifyNoRebootRequested(); 1111 VerifyNoRebootRequested();
1196 1112
1197 // Set the uptime limit. Verify that a reboot is requested but the device does 1113 // Set the uptime limit. Verify that a reboot is requested but the device does
1198 // not reboot immediately. 1114 // not reboot immediately.
1199 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1115 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
(...skipping 15 matching lines...) Expand all
1215 1131
1216 // Verify that the device never reboots. 1132 // Verify that the device never reboots.
1217 FastForwardUntilNoTasksRemain(false); 1133 FastForwardUntilNoTasksRemain(false);
1218 } 1134 }
1219 1135
1220 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is 1136 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
1221 // 6 hours. 1137 // 6 hours.
1222 // Verifies that when the uptime limit is extended to 24 hours, the grace period 1138 // Verifies that when the uptime limit is extended to 24 hours, the grace period
1223 // is rescheduled to start further in the future. 1139 // is rescheduled to start further in the future.
1224 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitBeforeGracePeriod) { 1140 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitBeforeGracePeriod) {
1225 task_runner_->SetUptime(base::TimeDelta::FromHours(6)); 1141 uptime_provider()->SetUptime(base::TimeDelta::FromHours(6));
1226 1142
1227 // Verify that no reboot is requested and the device does not reboot 1143 // Verify that no reboot is requested and the device does not reboot
1228 // immediately. 1144 // immediately.
1229 ExpectNoRebootRequest(); 1145 ExpectNoRebootRequest();
1230 CreateAutomaticRebootManager(false); 1146 CreateAutomaticRebootManager(false);
1231 VerifyNoRebootRequested(); 1147 VerifyNoRebootRequested();
1232 1148
1233 // Set the uptime limit. Verify that no reboot is requested and the device 1149 // Set the uptime limit. Verify that no reboot is requested and the device
1234 // does not reboot immediately. 1150 // does not reboot immediately.
1235 SetUptimeLimit(base::TimeDelta::FromHours(12), false); 1151 SetUptimeLimit(base::TimeDelta::FromHours(12), false);
(...skipping 18 matching lines...) Expand all
1254 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1170 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1255 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1171 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1256 is_logged_in_as_kiosk_app_); 1172 is_logged_in_as_kiosk_app_);
1257 } 1173 }
1258 1174
1259 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is 1175 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
1260 // 18 hours. 1176 // 18 hours.
1261 // Verifies that when the uptime limit is extended to 24 hours, the grace period 1177 // Verifies that when the uptime limit is extended to 24 hours, the grace period
1262 // is rescheduled to start in the future. 1178 // is rescheduled to start in the future.
1263 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitInGracePeriod) { 1179 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitInGracePeriod) {
1264 task_runner_->SetUptime(base::TimeDelta::FromHours(18)); 1180 uptime_provider()->SetUptime(base::TimeDelta::FromHours(18));
1265 1181
1266 // Verify that no reboot is requested and the device does not reboot 1182 // Verify that no reboot is requested and the device does not reboot
1267 // immediately. 1183 // immediately.
1268 ExpectNoRebootRequest(); 1184 ExpectNoRebootRequest();
1269 CreateAutomaticRebootManager(false); 1185 CreateAutomaticRebootManager(false);
1270 VerifyNoRebootRequested(); 1186 VerifyNoRebootRequested();
1271 1187
1272 // Set the uptime limit. Verify that a reboot is requested but the device does 1188 // Set the uptime limit. Verify that a reboot is requested but the device does
1273 // not reboot immediately. 1189 // not reboot immediately.
1274 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1190 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
(...skipping 18 matching lines...) Expand all
1293 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1209 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1294 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1210 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1295 is_logged_in_as_kiosk_app_); 1211 is_logged_in_as_kiosk_app_);
1296 } 1212 }
1297 1213
1298 // Chrome is running. The uptime limit is set to 18 hours. The current uptime is 1214 // Chrome is running. The uptime limit is set to 18 hours. The current uptime is
1299 // 12 hours. 1215 // 12 hours.
1300 // Verifies that when the uptime limit is shortened to 6 hours, the grace period 1216 // Verifies that when the uptime limit is shortened to 6 hours, the grace period
1301 // is rescheduled to have already started. 1217 // is rescheduled to have already started.
1302 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitBeforeToInGracePeriod) { 1218 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitBeforeToInGracePeriod) {
1303 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1219 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1304 1220
1305 // Verify that no reboot is requested and the device does not reboot 1221 // Verify that no reboot is requested and the device does not reboot
1306 // immediately. 1222 // immediately.
1307 ExpectNoRebootRequest(); 1223 ExpectNoRebootRequest();
1308 CreateAutomaticRebootManager(false); 1224 CreateAutomaticRebootManager(false);
1309 VerifyNoRebootRequested(); 1225 VerifyNoRebootRequested();
1310 1226
1311 // Set the uptime limit. Verify that no reboot is requested and the device 1227 // Set the uptime limit. Verify that no reboot is requested and the device
1312 // does not reboot immediately. 1228 // does not reboot immediately.
1313 SetUptimeLimit(base::TimeDelta::FromHours(18), false); 1229 SetUptimeLimit(base::TimeDelta::FromHours(18), false);
(...skipping 17 matching lines...) Expand all
1331 // eventually reboots. 1247 // eventually reboots.
1332 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1248 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1333 is_logged_in_as_kiosk_app_); 1249 is_logged_in_as_kiosk_app_);
1334 } 1250 }
1335 1251
1336 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is 1252 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is
1337 // 36 hours. 1253 // 36 hours.
1338 // Verifies that when the uptime limit is shortened to 18 hours, the grace 1254 // Verifies that when the uptime limit is shortened to 18 hours, the grace
1339 // period is rescheduled to have started earlier. 1255 // period is rescheduled to have started earlier.
1340 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToInGracePeriod) { 1256 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToInGracePeriod) {
1341 task_runner_->SetUptime(base::TimeDelta::FromHours(36)); 1257 uptime_provider()->SetUptime(base::TimeDelta::FromHours(36));
1342 1258
1343 // Verify that no reboot is requested and the device does not reboot 1259 // Verify that no reboot is requested and the device does not reboot
1344 // immediately. 1260 // immediately.
1345 ExpectNoRebootRequest(); 1261 ExpectNoRebootRequest();
1346 CreateAutomaticRebootManager(false); 1262 CreateAutomaticRebootManager(false);
1347 VerifyNoRebootRequested(); 1263 VerifyNoRebootRequested();
1348 1264
1349 // Set the uptime limit. Verify that a reboot is requested but the device does 1265 // Set the uptime limit. Verify that a reboot is requested but the device does
1350 // not reboot immediately. 1266 // not reboot immediately.
1351 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1267 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
(...skipping 19 matching lines...) Expand all
1371 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1287 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1372 is_logged_in_as_kiosk_app_); 1288 is_logged_in_as_kiosk_app_);
1373 } 1289 }
1374 1290
1375 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is 1291 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is
1376 // 36 hours. 1292 // 36 hours.
1377 // Verifies that when the uptime limit is shortened to 6 hours, the device 1293 // Verifies that when the uptime limit is shortened to 6 hours, the device
1378 // reboots immediately if no non-kiosk-app session is in progress because the 1294 // reboots immediately if no non-kiosk-app session is in progress because the
1379 // grace period ended after 6 + 24 hours of uptime. 1295 // grace period ended after 6 + 24 hours of uptime.
1380 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToAfterGracePeriod) { 1296 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToAfterGracePeriod) {
1381 task_runner_->SetUptime(base::TimeDelta::FromHours(36)); 1297 uptime_provider()->SetUptime(base::TimeDelta::FromHours(36));
1382 1298
1383 // Verify that no reboot is requested and the device does not reboot 1299 // Verify that no reboot is requested and the device does not reboot
1384 // immediately. 1300 // immediately.
1385 ExpectNoRebootRequest(); 1301 ExpectNoRebootRequest();
1386 CreateAutomaticRebootManager(false); 1302 CreateAutomaticRebootManager(false);
1387 VerifyNoRebootRequested(); 1303 VerifyNoRebootRequested();
1388 1304
1389 // Set the uptime limit. Verify that a reboot is requested but the device does 1305 // Set the uptime limit. Verify that a reboot is requested but the device does
1390 // not reboot immediately. 1306 // not reboot immediately.
1391 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1307 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
(...skipping 18 matching lines...) Expand all
1410 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1326 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1411 is_logged_in_as_kiosk_app_); 1327 is_logged_in_as_kiosk_app_);
1412 } 1328 }
1413 1329
1414 // Chrome is running. The current uptime is 12 hours. 1330 // Chrome is running. The current uptime is 12 hours.
1415 // Verifies that when an update is applied, the current uptime is persisted as 1331 // Verifies that when an update is applied, the current uptime is persisted as
1416 // the time at which a reboot became necessary. Further verifies that when the 1332 // the time at which a reboot became necessary. Further verifies that when the
1417 // policy to automatically reboot after an update is not enabled, no reboot 1333 // policy to automatically reboot after an update is not enabled, no reboot
1418 // occurs and no grace period is scheduled. 1334 // occurs and no grace period is scheduled.
1419 TEST_P(AutomaticRebootManagerTest, UpdateNoPolicy) { 1335 TEST_P(AutomaticRebootManagerTest, UpdateNoPolicy) {
1420 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1336 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1421 1337
1422 // Verify that no reboot is requested and the device does not reboot 1338 // Verify that no reboot is requested and the device does not reboot
1423 // immediately. 1339 // immediately.
1424 ExpectNoRebootRequest(); 1340 ExpectNoRebootRequest();
1425 CreateAutomaticRebootManager(false); 1341 CreateAutomaticRebootManager(false);
1426 VerifyNoRebootRequested(); 1342 VerifyNoRebootRequested();
1427 1343
1428 // Verify that no grace period has started. 1344 // Verify that no grace period has started.
1429 VerifyNoGracePeriod(); 1345 VerifyNoGracePeriod();
1430 1346
1431 // Notify that an update has been applied and a reboot is necessary. Verify 1347 // Notify that an update has been applied and a reboot is necessary. Verify
1432 // that no reboot is requested and the device does not reboot immediately. 1348 // that no reboot is requested and the device does not reboot immediately.
1433 NotifyUpdateRebootNeeded(); 1349 NotifyUpdateRebootNeeded();
1434 1350
1435 // Verify that the current uptime has been persisted as the time at which a 1351 // Verify that the current uptime has been persisted as the time at which a
1436 // reboot became necessary. 1352 // reboot became necessary.
1437 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1353 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1438 &update_reboot_needed_uptime_)); 1354 &update_reboot_needed_uptime_));
1439 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1355 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1440 1356
1441 // Verify that no grace period has started. 1357 // Verify that no grace period has started.
1442 VerifyNoGracePeriod(); 1358 VerifyNoGracePeriod();
1443 1359
1444 // Verify that a reboot is never requested and the device never reboots. 1360 // Verify that a reboot is never requested and the device never reboots.
1445 FastForwardUntilNoTasksRemain(false); 1361 FastForwardUntilNoTasksRemain(false);
1446 } 1362 }
1447 1363
1448 // Chrome is running. The current uptime is 12 hours. 1364 // Chrome is running. The current uptime is 12 hours.
1449 // Verifies that when an update is applied, the current uptime is persisted as 1365 // Verifies that when an update is applied, the current uptime is persisted as
1450 // the time at which a reboot became necessary. Further verifies that when the 1366 // the time at which a reboot became necessary. Further verifies that when the
1451 // policy to automatically reboot after an update is enabled, a reboot is 1367 // policy to automatically reboot after an update is enabled, a reboot is
1452 // requested and a grace period is started that will end 24 hours from now. 1368 // requested and a grace period is started that will end 24 hours from now.
1453 TEST_P(AutomaticRebootManagerTest, Update) { 1369 TEST_P(AutomaticRebootManagerTest, Update) {
1454 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1370 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1455 SetRebootAfterUpdate(true, false); 1371 SetRebootAfterUpdate(true, false);
1456 1372
1457 // Verify that no reboot is requested and the device does not reboot 1373 // Verify that no reboot is requested and the device does not reboot
1458 // immediately. 1374 // immediately.
1459 ExpectNoRebootRequest(); 1375 ExpectNoRebootRequest();
1460 CreateAutomaticRebootManager(false); 1376 CreateAutomaticRebootManager(false);
1461 VerifyNoRebootRequested(); 1377 VerifyNoRebootRequested();
1462 1378
1463 // Verify that no grace period has started. 1379 // Verify that no grace period has started.
1464 VerifyNoGracePeriod(); 1380 VerifyNoGracePeriod();
1465 1381
1466 // Notify that an update has been applied and a reboot is necessary. Verify 1382 // Notify that an update has been applied and a reboot is necessary. Verify
1467 // that a reboot is requested but the device does not reboot immediately. 1383 // that a reboot is requested but the device does not reboot immediately.
1468 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 1384 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1469 NotifyUpdateRebootNeeded(); 1385 NotifyUpdateRebootNeeded();
1470 1386
1471 // Verify that the current uptime has been persisted as the time at which a 1387 // Verify that the current uptime has been persisted as the time at which a
1472 // reboot became necessary. 1388 // reboot became necessary.
1473 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1389 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1474 &update_reboot_needed_uptime_)); 1390 &update_reboot_needed_uptime_));
1475 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1391 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1476 1392
1477 // Verify that a grace period has started. 1393 // Verify that a grace period has started.
1478 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); 1394 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1479 1395
1480 // Verify that unless a non-kiosk-app session is in progress, the device 1396 // Verify that unless a non-kiosk-app session is in progress, the device
1481 // eventually reboots. 1397 // eventually reboots.
1482 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1398 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1483 is_logged_in_as_kiosk_app_); 1399 is_logged_in_as_kiosk_app_);
1484 } 1400 }
1485 1401
1486 // Chrome is running. The current uptime is 12 hours. 1402 // Chrome is running. The current uptime is 12 hours.
1487 // Verifies that when Chrome is notified twice that an update has been applied, 1403 // Verifies that when Chrome is notified twice that an update has been applied,
1488 // the second notification is ignored and the uptime at which it occurred does 1404 // the second notification is ignored and the uptime at which it occurred does
1489 // not get persisted as the time at which an update became necessary. 1405 // not get persisted as the time at which an update became necessary.
1490 TEST_P(AutomaticRebootManagerTest, UpdateAfterUpdate) { 1406 TEST_P(AutomaticRebootManagerTest, UpdateAfterUpdate) {
1491 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1407 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1492 SetRebootAfterUpdate(true, false); 1408 SetRebootAfterUpdate(true, false);
1493 1409
1494 // Verify that no reboot is requested and the device does not reboot 1410 // Verify that no reboot is requested and the device does not reboot
1495 // immediately. 1411 // immediately.
1496 ExpectNoRebootRequest(); 1412 ExpectNoRebootRequest();
1497 CreateAutomaticRebootManager(false); 1413 CreateAutomaticRebootManager(false);
1498 VerifyNoRebootRequested(); 1414 VerifyNoRebootRequested();
1499 1415
1500 // Verify that no grace period has started. 1416 // Verify that no grace period has started.
1501 VerifyNoGracePeriod(); 1417 VerifyNoGracePeriod();
1502 1418
1503 // Notify that an update has been applied and a reboot is necessary. Verify 1419 // Notify that an update has been applied and a reboot is necessary. Verify
1504 // that a reboot is requested but the device does not reboot immediately. 1420 // that a reboot is requested but the device does not reboot immediately.
1505 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 1421 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1506 NotifyUpdateRebootNeeded(); 1422 NotifyUpdateRebootNeeded();
1507 1423
1508 // Verify that the current uptime has been persisted as the time at which a 1424 // Verify that the current uptime has been persisted as the time at which a
1509 // reboot became necessary. 1425 // reboot became necessary.
1510 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1426 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1511 &update_reboot_needed_uptime_)); 1427 &update_reboot_needed_uptime_));
1512 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1428 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1513 1429
1514 // Verify that a grace period has started. 1430 // Verify that a grace period has started.
1515 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); 1431 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1516 1432
1517 // Fast forward the uptime by 20 seconds. Verify that the device does not 1433 // Fast forward the uptime by 20 seconds. Verify that the device does not
1518 // reboot immediately. 1434 // reboot immediately.
1519 FastForwardBy(base::TimeDelta::FromSeconds(20), false); 1435 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1520 1436
1521 // Notify that an update has been applied and a reboot is necessary. Verify 1437 // Notify that an update has been applied and a reboot is necessary. Verify
1522 // that the device does not reboot immediately. 1438 // that the device does not reboot immediately.
(...skipping 12 matching lines...) Expand all
1535 is_logged_in_as_kiosk_app_); 1451 is_logged_in_as_kiosk_app_);
1536 } 1452 }
1537 1453
1538 // Chrome is running. The current uptime is 10 minutes. 1454 // Chrome is running. The current uptime is 10 minutes.
1539 // Verifies that when the policy to automatically reboot after an update is 1455 // Verifies that when the policy to automatically reboot after an update is
1540 // enabled, no reboot occurs and a grace period is scheduled to begin after the 1456 // enabled, no reboot occurs and a grace period is scheduled to begin after the
1541 // minimum of 1 hour of uptime. Further verifies that when an update is applied, 1457 // minimum of 1 hour of uptime. Further verifies that when an update is applied,
1542 // the current uptime is persisted as the time at which a reboot became 1458 // the current uptime is persisted as the time at which a reboot became
1543 // necessary. 1459 // necessary.
1544 TEST_P(AutomaticRebootManagerTest, UpdateBeforeMinimumUptime) { 1460 TEST_P(AutomaticRebootManagerTest, UpdateBeforeMinimumUptime) {
1545 task_runner_->SetUptime(base::TimeDelta::FromMinutes(10)); 1461 uptime_provider()->SetUptime(base::TimeDelta::FromMinutes(10));
1546 SetRebootAfterUpdate(true, false); 1462 SetRebootAfterUpdate(true, false);
1547 1463
1548 // Verify that no reboot is requested and the device does not reboot 1464 // Verify that no reboot is requested and the device does not reboot
1549 // immediately. 1465 // immediately.
1550 ExpectNoRebootRequest(); 1466 ExpectNoRebootRequest();
1551 CreateAutomaticRebootManager(false); 1467 CreateAutomaticRebootManager(false);
1552 VerifyNoRebootRequested(); 1468 VerifyNoRebootRequested();
1553 1469
1554 // Verify that no grace period has started. 1470 // Verify that no grace period has started.
1555 VerifyNoGracePeriod(); 1471 VerifyNoGracePeriod();
1556 1472
1557 // Notify that an update has been applied and a reboot is necessary. Verify 1473 // Notify that an update has been applied and a reboot is necessary. Verify
1558 // that no reboot is requested and the device does not reboot immediately. 1474 // that no reboot is requested and the device does not reboot immediately.
1559 NotifyUpdateRebootNeeded(); 1475 NotifyUpdateRebootNeeded();
1560 1476
1561 // Verify that the current uptime has been persisted as the time at which a 1477 // Verify that the current uptime has been persisted as the time at which a
1562 // reboot became necessary. 1478 // reboot became necessary.
1563 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1479 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1564 &update_reboot_needed_uptime_)); 1480 &update_reboot_needed_uptime_));
1565 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1481 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1566 1482
1567 // Verify that a grace period has been scheduled to begin in the future. 1483 // Verify that a grace period has been scheduled to begin in the future.
1568 VerifyGracePeriod(base::TimeDelta::FromHours(1)); 1484 VerifyGracePeriod(base::TimeDelta::FromHours(1));
1569 1485
1570 // Verify that a reboot is requested eventually and unless a non-kiosk-app 1486 // Verify that a reboot is requested eventually and unless a non-kiosk-app
1571 // session is in progress, the device eventually reboots. 1487 // session is in progress, the device eventually reboots.
1572 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 1488 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1573 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1489 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1574 is_logged_in_as_kiosk_app_); 1490 is_logged_in_as_kiosk_app_);
1575 } 1491 }
1576 1492
1577 // Chrome is running. An update was applied and a reboot became necessary to 1493 // Chrome is running. An update was applied and a reboot became necessary to
1578 // complete the update process after 6 hours of uptime. The current uptime is 1494 // complete the update process after 6 hours of uptime. The current uptime is
1579 // 12 hours. 1495 // 12 hours.
1580 // Verifies that when the policy to automatically reboot after an update is 1496 // Verifies that when the policy to automatically reboot after an update is
1581 // enabled, a reboot is requested and a grace period is started that will end 1497 // enabled, a reboot is requested and a grace period is started that will end
1582 // after 6 + 24 hours of uptime. 1498 // after 6 + 24 hours of uptime.
1583 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateInGracePeriod) { 1499 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateInGracePeriod) {
1584 task_runner_->SetUptime(base::TimeDelta::FromHours(6)); 1500 uptime_provider()->SetUptime(base::TimeDelta::FromHours(6));
1585 1501
1586 // Verify that no reboot is requested and the device does not reboot 1502 // Verify that no reboot is requested and the device does not reboot
1587 // immediately. 1503 // immediately.
1588 ExpectNoRebootRequest(); 1504 ExpectNoRebootRequest();
1589 CreateAutomaticRebootManager(false); 1505 CreateAutomaticRebootManager(false);
1590 VerifyNoRebootRequested(); 1506 VerifyNoRebootRequested();
1591 1507
1592 // Notify that an update has been applied and a reboot is necessary. Verify 1508 // Notify that an update has been applied and a reboot is necessary. Verify
1593 // that no reboot is requested and the device does not reboot immediately. 1509 // that no reboot is requested and the device does not reboot immediately.
1594 NotifyUpdateRebootNeeded(); 1510 NotifyUpdateRebootNeeded();
(...skipping 19 matching lines...) Expand all
1614 is_logged_in_as_kiosk_app_); 1530 is_logged_in_as_kiosk_app_);
1615 } 1531 }
1616 1532
1617 // Chrome is running. An update was applied and a reboot became necessary to 1533 // Chrome is running. An update was applied and a reboot became necessary to
1618 // complete the update process after 6 hours of uptime. The current uptime is 1534 // complete the update process after 6 hours of uptime. The current uptime is
1619 // 10 days. 1535 // 10 days.
1620 // Verifies that when the policy to automatically reboot after an update is 1536 // Verifies that when the policy to automatically reboot after an update is
1621 // enabled, the device reboots immediately if no non-kiosk-app session is in 1537 // enabled, the device reboots immediately if no non-kiosk-app session is in
1622 // progress because the grace period ended after 6 + 24 hours of uptime. 1538 // progress because the grace period ended after 6 + 24 hours of uptime.
1623 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateAfterGracePeriod) { 1539 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateAfterGracePeriod) {
1624 task_runner_->SetUptime(base::TimeDelta::FromHours(6)); 1540 uptime_provider()->SetUptime(base::TimeDelta::FromHours(6));
1625 1541
1626 // Verify that no reboot is requested and the device does not reboot 1542 // Verify that no reboot is requested and the device does not reboot
1627 // immediately. 1543 // immediately.
1628 ExpectNoRebootRequest(); 1544 ExpectNoRebootRequest();
1629 CreateAutomaticRebootManager(false); 1545 CreateAutomaticRebootManager(false);
1630 VerifyNoRebootRequested(); 1546 VerifyNoRebootRequested();
1631 1547
1632 // Notify that an update has been applied and a reboot is necessary. Verify 1548 // Notify that an update has been applied and a reboot is necessary. Verify
1633 // that no reboot is requested and the device does not reboot immediately. 1549 // that no reboot is requested and the device does not reboot immediately.
1634 NotifyUpdateRebootNeeded(); 1550 NotifyUpdateRebootNeeded();
(...skipping 18 matching lines...) Expand all
1653 is_logged_in_as_kiosk_app_); 1569 is_logged_in_as_kiosk_app_);
1654 } 1570 }
1655 1571
1656 // Chrome is running. An update was applied and a reboot became necessary to 1572 // Chrome is running. An update was applied and a reboot became necessary to
1657 // complete the update process after 6 hours of uptime. The policy to 1573 // complete the update process after 6 hours of uptime. The policy to
1658 // automatically reboot after an update is enabled. The current uptime is 1574 // automatically reboot after an update is enabled. The current uptime is
1659 // 6 hours 20 seconds. 1575 // 6 hours 20 seconds.
1660 // Verifies that when the policy to automatically reboot after an update is 1576 // Verifies that when the policy to automatically reboot after an update is
1661 // disabled, the reboot request and grace period are removed. 1577 // disabled, the reboot request and grace period are removed.
1662 TEST_P(AutomaticRebootManagerTest, PolicyOffAfterUpdate) { 1578 TEST_P(AutomaticRebootManagerTest, PolicyOffAfterUpdate) {
1663 task_runner_->SetUptime(base::TimeDelta::FromHours(6)); 1579 uptime_provider()->SetUptime(base::TimeDelta::FromHours(6));
1664 SetRebootAfterUpdate(true, false); 1580 SetRebootAfterUpdate(true, false);
1665 1581
1666 // Verify that no reboot is requested and the device does not reboot 1582 // Verify that no reboot is requested and the device does not reboot
1667 // immediately. 1583 // immediately.
1668 ExpectNoRebootRequest(); 1584 ExpectNoRebootRequest();
1669 CreateAutomaticRebootManager(false); 1585 CreateAutomaticRebootManager(false);
1670 VerifyNoRebootRequested(); 1586 VerifyNoRebootRequested();
1671 1587
1672 // Notify that an update has been applied and a reboot is necessary. Verify 1588 // Notify that an update has been applied and a reboot is necessary. Verify
1673 // that a reboot is requested but the device does not reboot immediately. 1589 // that a reboot is requested but the device does not reboot immediately.
1674 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 1590 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1675 NotifyUpdateRebootNeeded(); 1591 NotifyUpdateRebootNeeded();
1676 1592
1677 // Verify that a grace period has started. 1593 // Verify that a grace period has started.
1678 VerifyGracePeriod(task_runner_->Uptime() + uptime_processing_delay_); 1594 VerifyGracePeriod(uptime_provider()->uptime() + uptime_processing_delay_);
1679 1595
1680 // Fast forward the uptime by 20 seconds. Verify that the device does not 1596 // Fast forward the uptime by 20 seconds. Verify that the device does not
1681 // reboot immediately. 1597 // reboot immediately.
1682 FastForwardBy(base::TimeDelta::FromSeconds(20), false); 1598 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1683 1599
1684 // Disable automatic rebooting after an update has been applied. Verify that 1600 // Disable automatic rebooting after an update has been applied. Verify that
1685 // no reboot is requested and the device does not reboot immediately. 1601 // no reboot is requested and the device does not reboot immediately.
1686 SetRebootAfterUpdate(false, false); 1602 SetRebootAfterUpdate(false, false);
1687 1603
1688 // Verify that the grace period has been removed. 1604 // Verify that the grace period has been removed.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1734 FastForwardUntilNoTasksRemain(false); 1650 FastForwardUntilNoTasksRemain(false);
1735 } 1651 }
1736 1652
1737 // Chrome is running. The policy to automatically reboot after an update is 1653 // Chrome is running. The policy to automatically reboot after an update is
1738 // enabled. The current uptime is 12 hours. 1654 // enabled. The current uptime is 12 hours.
1739 // Verifies that when an uptime limit of 6 hours is set, the availability of an 1655 // Verifies that when an uptime limit of 6 hours is set, the availability of an
1740 // update does not cause the grace period to be rescheduled. Further verifies 1656 // update does not cause the grace period to be rescheduled. Further verifies
1741 // that the current uptime is persisted as the time at which a reboot became 1657 // that the current uptime is persisted as the time at which a reboot became
1742 // necessary. 1658 // necessary.
1743 TEST_P(AutomaticRebootManagerTest, UptimeLimitBeforeUpdate) { 1659 TEST_P(AutomaticRebootManagerTest, UptimeLimitBeforeUpdate) {
1744 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1660 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1745 SetRebootAfterUpdate(true, false); 1661 SetRebootAfterUpdate(true, false);
1746 1662
1747 // Verify that no reboot is requested and the device does not reboot 1663 // Verify that no reboot is requested and the device does not reboot
1748 // immediately. 1664 // immediately.
1749 ExpectNoRebootRequest(); 1665 ExpectNoRebootRequest();
1750 CreateAutomaticRebootManager(false); 1666 CreateAutomaticRebootManager(false);
1751 VerifyNoRebootRequested(); 1667 VerifyNoRebootRequested();
1752 1668
1753 // Set the uptime limit. Verify that a reboot is requested but the device does 1669 // Set the uptime limit. Verify that a reboot is requested but the device does
1754 // not reboot immediately. 1670 // not reboot immediately.
(...skipping 10 matching lines...) Expand all
1765 // Notify that an update has been applied and a reboot is necessary. Verify 1681 // Notify that an update has been applied and a reboot is necessary. Verify
1766 // that a reboot is requested again but the device does not reboot 1682 // that a reboot is requested again but the device does not reboot
1767 // immediately. 1683 // immediately.
1768 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1684 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1769 NotifyUpdateRebootNeeded(); 1685 NotifyUpdateRebootNeeded();
1770 1686
1771 // Verify that the current uptime has been persisted as the time at which a 1687 // Verify that the current uptime has been persisted as the time at which a
1772 // reboot became necessary. 1688 // reboot became necessary.
1773 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1689 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1774 &update_reboot_needed_uptime_)); 1690 &update_reboot_needed_uptime_));
1775 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1691 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1776 1692
1777 // Verify that the grace period has not been rescheduled. 1693 // Verify that the grace period has not been rescheduled.
1778 VerifyGracePeriod(uptime_limit_); 1694 VerifyGracePeriod(uptime_limit_);
1779 1695
1780 // Verify that unless a non-kiosk-app session is in progress, the device 1696 // Verify that unless a non-kiosk-app session is in progress, the device
1781 // eventually reboots. 1697 // eventually reboots.
1782 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1698 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1783 is_logged_in_as_kiosk_app_); 1699 is_logged_in_as_kiosk_app_);
1784 } 1700 }
1785 1701
1786 // Chrome is running. The policy to automatically reboot after an update is 1702 // Chrome is running. The policy to automatically reboot after an update is
1787 // enabled. The current uptime is 12 hours. 1703 // enabled. The current uptime is 12 hours.
1788 // Verifies that when an uptime limit of 24 hours is set, the availability of an 1704 // Verifies that when an uptime limit of 24 hours is set, the availability of an
1789 // update causes the grace period to be rescheduled so that it ends 24 hours 1705 // update causes the grace period to be rescheduled so that it ends 24 hours
1790 // from now. Further verifies that the current uptime is persisted as the time 1706 // from now. Further verifies that the current uptime is persisted as the time
1791 // at which a reboot became necessary. 1707 // at which a reboot became necessary.
1792 TEST_P(AutomaticRebootManagerTest, UpdateBeforeUptimeLimit) { 1708 TEST_P(AutomaticRebootManagerTest, UpdateBeforeUptimeLimit) {
1793 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1709 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1794 SetRebootAfterUpdate(true, false); 1710 SetRebootAfterUpdate(true, false);
1795 1711
1796 // Verify that no reboot is requested and the device does not reboot 1712 // Verify that no reboot is requested and the device does not reboot
1797 // immediately. 1713 // immediately.
1798 ExpectNoRebootRequest(); 1714 ExpectNoRebootRequest();
1799 CreateAutomaticRebootManager(false); 1715 CreateAutomaticRebootManager(false);
1800 VerifyNoRebootRequested(); 1716 VerifyNoRebootRequested();
1801 1717
1802 // Set the uptime limit. Verify that no reboot is requested and the device 1718 // Set the uptime limit. Verify that no reboot is requested and the device
1803 // does not reboot immediately. 1719 // does not reboot immediately.
1804 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 1720 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1805 1721
1806 // Verify that a grace period has been scheduled to start in the future. 1722 // Verify that a grace period has been scheduled to start in the future.
1807 VerifyGracePeriod(uptime_limit_); 1723 VerifyGracePeriod(uptime_limit_);
1808 1724
1809 // Fast forward the uptime by 20 seconds. Verify that no reboot is requested 1725 // Fast forward the uptime by 20 seconds. Verify that no reboot is requested
1810 // and the device does not reboot immediately. 1726 // and the device does not reboot immediately.
1811 FastForwardBy(base::TimeDelta::FromSeconds(20), false); 1727 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1812 1728
1813 // Notify that an update has been applied and a reboot is necessary. Verify 1729 // Notify that an update has been applied and a reboot is necessary. Verify
1814 // that a reboot is requested but the device does not reboot immediately. 1730 // that a reboot is requested but the device does not reboot immediately.
1815 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 1731 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1816 NotifyUpdateRebootNeeded(); 1732 NotifyUpdateRebootNeeded();
1817 1733
1818 // Verify that the current uptime has been persisted as the time at which a 1734 // Verify that the current uptime has been persisted as the time at which a
1819 // reboot became necessary. 1735 // reboot became necessary.
1820 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1736 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1821 &update_reboot_needed_uptime_)); 1737 &update_reboot_needed_uptime_));
1822 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1738 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1823 1739
1824 // Verify that the grace period has been rescheduled to start at the time that 1740 // Verify that the grace period has been rescheduled to start at the time that
1825 // the update became available. 1741 // the update became available.
1826 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); 1742 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1827 1743
1828 // Verify that unless a non-kiosk-app session is in progress, the device 1744 // Verify that unless a non-kiosk-app session is in progress, the device
1829 // eventually reboots. 1745 // eventually reboots.
1830 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1746 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1831 is_logged_in_as_kiosk_app_); 1747 is_logged_in_as_kiosk_app_);
1832 } 1748 }
1833 1749
1834 // Chrome is running. The uptime limit is set to 24 hours. An update was applied 1750 // Chrome is running. The uptime limit is set to 24 hours. An update was applied
1835 // and a reboot became necessary to complete the update process after 12 hours. 1751 // and a reboot became necessary to complete the update process after 12 hours.
1836 // The policy to automatically reboot after an update is enabled. The current 1752 // The policy to automatically reboot after an update is enabled. The current
1837 // uptime is 12 hours 20 seconds. 1753 // uptime is 12 hours 20 seconds.
1838 // Verifies that when the policy to reboot after an update is disabled, the 1754 // Verifies that when the policy to reboot after an update is disabled, the
1839 // grace period is rescheduled to start after 12 hours of uptime. Further 1755 // grace period is rescheduled to start after 12 hours of uptime. Further
1840 // verifies that when the uptime limit is removed, the grace period is removed. 1756 // verifies that when the uptime limit is removed, the grace period is removed.
1841 TEST_P(AutomaticRebootManagerTest, PolicyOffThenUptimeLimitOff) { 1757 TEST_P(AutomaticRebootManagerTest, PolicyOffThenUptimeLimitOff) {
1842 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1758 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1843 SetRebootAfterUpdate(true, false); 1759 SetRebootAfterUpdate(true, false);
1844 1760
1845 // Verify that no reboot is requested and the device does not reboot 1761 // Verify that no reboot is requested and the device does not reboot
1846 // immediately. 1762 // immediately.
1847 ExpectNoRebootRequest(); 1763 ExpectNoRebootRequest();
1848 CreateAutomaticRebootManager(false); 1764 CreateAutomaticRebootManager(false);
1849 VerifyNoRebootRequested(); 1765 VerifyNoRebootRequested();
1850 1766
1851 // Set the uptime limit. Verify that no reboot is requested and the device 1767 // Set the uptime limit. Verify that no reboot is requested and the device
1852 // does not reboot immediately. 1768 // does not reboot immediately.
1853 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 1769 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
1854 1770
1855 // Verify that a grace period has been scheduled to start in the future. 1771 // Verify that a grace period has been scheduled to start in the future.
1856 VerifyGracePeriod(uptime_limit_); 1772 VerifyGracePeriod(uptime_limit_);
1857 1773
1858 // Notify that an update has been applied and a reboot is necessary. Verify 1774 // Notify that an update has been applied and a reboot is necessary. Verify
1859 // that a reboot is requested but the device does not reboot immediately. 1775 // that a reboot is requested but the device does not reboot immediately.
1860 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 1776 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1861 NotifyUpdateRebootNeeded(); 1777 NotifyUpdateRebootNeeded();
1862 1778
1863 // Verify that the current uptime has been persisted as the time at which a 1779 // Verify that the current uptime has been persisted as the time at which a
1864 // reboot became necessary. 1780 // reboot became necessary.
1865 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1781 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1866 &update_reboot_needed_uptime_)); 1782 &update_reboot_needed_uptime_));
1867 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1783 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1868 1784
1869 // Verify that a grace period has been rescheduled to end 24 hours from now. 1785 // Verify that a grace period has been rescheduled to end 24 hours from now.
1870 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); 1786 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1871 1787
1872 // Fast forward the uptime by 20 seconds. Verify that the device does not 1788 // Fast forward the uptime by 20 seconds. Verify that the device does not
1873 // reboot immediately. 1789 // reboot immediately.
1874 FastForwardBy(base::TimeDelta::FromSeconds(20), false); 1790 FastForwardBy(base::TimeDelta::FromSeconds(20), false);
1875 1791
1876 // Disable automatic reboot after an update has been applied. Verify that the 1792 // Disable automatic reboot after an update has been applied. Verify that the
1877 // device does not reboot immediately. 1793 // device does not reboot immediately.
(...skipping 16 matching lines...) Expand all
1894 1810
1895 // Chrome is running. The uptime limit is set to 6 hours. An update was applied 1811 // Chrome is running. The uptime limit is set to 6 hours. An update was applied
1896 // and a reboot became necessary to complete the update process after 12 hours. 1812 // and a reboot became necessary to complete the update process after 12 hours.
1897 // The policy to automatically reboot after an update is enabled. The current 1813 // The policy to automatically reboot after an update is enabled. The current
1898 // uptime is 12 hours 20 seconds. 1814 // uptime is 12 hours 20 seconds.
1899 // Verifies that when the uptime limit is removed, the grace period is 1815 // Verifies that when the uptime limit is removed, the grace period is
1900 // rescheduled to have started after 12 hours of uptime. Further verifies that 1816 // rescheduled to have started after 12 hours of uptime. Further verifies that
1901 // when the policy to reboot after an update is disabled, the reboot request and 1817 // when the policy to reboot after an update is disabled, the reboot request and
1902 // grace period are removed. 1818 // grace period are removed.
1903 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffThenPolicyOff) { 1819 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffThenPolicyOff) {
1904 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1820 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
1905 SetRebootAfterUpdate(true, false); 1821 SetRebootAfterUpdate(true, false);
1906 1822
1907 // Verify that no reboot is requested and the device does not reboot 1823 // Verify that no reboot is requested and the device does not reboot
1908 // immediately. 1824 // immediately.
1909 ExpectNoRebootRequest(); 1825 ExpectNoRebootRequest();
1910 CreateAutomaticRebootManager(false); 1826 CreateAutomaticRebootManager(false);
1911 VerifyNoRebootRequested(); 1827 VerifyNoRebootRequested();
1912 1828
1913 // Notify that an update has been applied and a reboot is necessary. Verify 1829 // Notify that an update has been applied and a reboot is necessary. Verify
1914 // that a reboot is requested but the device does not reboot immediately. 1830 // that a reboot is requested but the device does not reboot immediately.
1915 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 1831 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
1916 NotifyUpdateRebootNeeded(); 1832 NotifyUpdateRebootNeeded();
1917 1833
1918 // Verify that the current uptime has been persisted as the time at which a 1834 // Verify that the current uptime has been persisted as the time at which a
1919 // reboot became necessary. 1835 // reboot became necessary.
1920 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 1836 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
1921 &update_reboot_needed_uptime_)); 1837 &update_reboot_needed_uptime_));
1922 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 1838 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
1923 1839
1924 // Verify that the grace period has started. 1840 // Verify that the grace period has started.
1925 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); 1841 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
1926 1842
1927 // Set the uptime limit. Verify that a reboot is requested again but the 1843 // Set the uptime limit. Verify that a reboot is requested again but the
1928 // device does not reboot immediately. 1844 // device does not reboot immediately.
1929 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1845 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
1930 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 1846 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
1931 1847
1932 // Verify that the grace period has been rescheduled to have started after 1848 // Verify that the grace period has been rescheduled to have started after
(...skipping 22 matching lines...) Expand all
1955 1871
1956 // Verify that the device never reboots. 1872 // Verify that the device never reboots.
1957 FastForwardUntilNoTasksRemain(false); 1873 FastForwardUntilNoTasksRemain(false);
1958 } 1874 }
1959 1875
1960 // Chrome is running. The uptime limit is 6 hours. The current uptime is 1876 // Chrome is running. The uptime limit is 6 hours. The current uptime is
1961 // 29 hours 59 minutes 59 seconds. 1877 // 29 hours 59 minutes 59 seconds.
1962 // Verifies that if no non-kiosk-app session is in progress, the device reboots 1878 // Verifies that if no non-kiosk-app session is in progress, the device reboots
1963 // immediately when the grace period ends after 6 + 24 hours of uptime. 1879 // immediately when the grace period ends after 6 + 24 hours of uptime.
1964 TEST_P(AutomaticRebootManagerTest, GracePeriodEnd) { 1880 TEST_P(AutomaticRebootManagerTest, GracePeriodEnd) {
1965 task_runner_->SetUptime(base::TimeDelta::FromHours(29) + 1881 uptime_provider()->SetUptime(base::TimeDelta::FromHours(29) +
1966 base::TimeDelta::FromMinutes(59) + 1882 base::TimeDelta::FromMinutes(59) +
1967 base::TimeDelta::FromSeconds(59)); 1883 base::TimeDelta::FromSeconds(59));
1968 1884
1969 // Verify that no reboot is requested and the device does not reboot 1885 // Verify that no reboot is requested and the device does not reboot
1970 // immediately. 1886 // immediately.
1971 ExpectNoRebootRequest(); 1887 ExpectNoRebootRequest();
1972 CreateAutomaticRebootManager(false); 1888 CreateAutomaticRebootManager(false);
1973 VerifyNoRebootRequested(); 1889 VerifyNoRebootRequested();
1974 1890
1975 // Set the uptime limit. Verify that a reboot is requested but the device does 1891 // Set the uptime limit. Verify that a reboot is requested but the device does
(...skipping 12 matching lines...) Expand all
1988 // Verify that if a non-kiosk-app session is in progress, the device never 1904 // Verify that if a non-kiosk-app session is in progress, the device never
1989 // reboots. 1905 // reboots.
1990 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1906 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
1991 is_logged_in_as_kiosk_app_); 1907 is_logged_in_as_kiosk_app_);
1992 } 1908 }
1993 1909
1994 // Chrome is starting. The current uptime is 10 days. 1910 // Chrome is starting. The current uptime is 10 days.
1995 // Verifies that when no automatic reboot policy is enabled, no reboot occurs 1911 // Verifies that when no automatic reboot policy is enabled, no reboot occurs
1996 // and no grace period is scheduled. 1912 // and no grace period is scheduled.
1997 TEST_P(AutomaticRebootManagerTest, StartNoPolicy) { 1913 TEST_P(AutomaticRebootManagerTest, StartNoPolicy) {
1998 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 1914 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
1999 1915
2000 // Verify that no reboot is requested and the device does not reboot 1916 // Verify that no reboot is requested and the device does not reboot
2001 // immediately. 1917 // immediately.
2002 ExpectNoRebootRequest(); 1918 ExpectNoRebootRequest();
2003 CreateAutomaticRebootManager(false); 1919 CreateAutomaticRebootManager(false);
2004 VerifyNoRebootRequested(); 1920 VerifyNoRebootRequested();
2005 1921
2006 // Verify that no grace period has started. 1922 // Verify that no grace period has started.
2007 VerifyNoGracePeriod(); 1923 VerifyNoGracePeriod();
2008 1924
2009 // Verify that a reboot is never requested and the device never reboots. 1925 // Verify that a reboot is never requested and the device never reboots.
2010 FastForwardUntilNoTasksRemain(false); 1926 FastForwardUntilNoTasksRemain(false);
2011 } 1927 }
2012 1928
2013 // Chrome is starting. The uptime limit is set to 24 hours. The current uptime 1929 // Chrome is starting. The uptime limit is set to 24 hours. The current uptime
2014 // is 12 hours. 1930 // is 12 hours.
2015 // Verifies that no reboot occurs and a grace period is scheduled to begin after 1931 // Verifies that no reboot occurs and a grace period is scheduled to begin after
2016 // 24 hours of uptime. 1932 // 24 hours of uptime.
2017 TEST_P(AutomaticRebootManagerTest, StartBeforeUptimeLimitGracePeriod) { 1933 TEST_P(AutomaticRebootManagerTest, StartBeforeUptimeLimitGracePeriod) {
2018 SetUptimeLimit(base::TimeDelta::FromHours(24), false); 1934 SetUptimeLimit(base::TimeDelta::FromHours(24), false);
2019 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1935 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
2020 1936
2021 // Verify that no reboot is requested and the device does not reboot 1937 // Verify that no reboot is requested and the device does not reboot
2022 // immediately. 1938 // immediately.
2023 ExpectNoRebootRequest(); 1939 ExpectNoRebootRequest();
2024 CreateAutomaticRebootManager(false); 1940 CreateAutomaticRebootManager(false);
2025 VerifyNoRebootRequested(); 1941 VerifyNoRebootRequested();
2026 1942
2027 // Verify that a grace period has been scheduled to start in the future. 1943 // Verify that a grace period has been scheduled to start in the future.
2028 VerifyGracePeriod(uptime_limit_); 1944 VerifyGracePeriod(uptime_limit_);
2029 1945
2030 // Verify that a reboot is requested eventually and unless a non-kiosk-app 1946 // Verify that a reboot is requested eventually and unless a non-kiosk-app
2031 // session is in progress, the device eventually reboots. 1947 // session is in progress, the device eventually reboots.
2032 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1948 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
2033 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1949 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2034 is_logged_in_as_kiosk_app_); 1950 is_logged_in_as_kiosk_app_);
2035 } 1951 }
2036 1952
2037 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is 1953 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is
2038 // 10 days. 1954 // 10 days.
2039 // Verifies that if no non-kiosk-app session is in progress, the device reboots 1955 // Verifies that if no non-kiosk-app session is in progress, the device reboots
2040 // immediately because the grace period ended after 6 + 24 hours of uptime. 1956 // immediately because the grace period ended after 6 + 24 hours of uptime.
2041 TEST_P(AutomaticRebootManagerTest, StartAfterUptimeLimitGracePeriod) { 1957 TEST_P(AutomaticRebootManagerTest, StartAfterUptimeLimitGracePeriod) {
2042 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 1958 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
2043 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 1959 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
2044 1960
2045 // Verify that a reboot is requested and unless a non-kiosk-app session is in 1961 // Verify that a reboot is requested and unless a non-kiosk-app session is in
2046 // progress, the the device immediately reboots. 1962 // progress, the the device immediately reboots.
2047 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1963 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
2048 CreateAutomaticRebootManager(!is_user_logged_in_ || 1964 CreateAutomaticRebootManager(!is_user_logged_in_ ||
2049 is_logged_in_as_kiosk_app_); 1965 is_logged_in_as_kiosk_app_);
2050 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1966 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
2051 1967
2052 // Verify that if a non-kiosk-app session is in progress, the device never 1968 // Verify that if a non-kiosk-app session is in progress, the device never
2053 // reboots. 1969 // reboots.
2054 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1970 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2055 is_logged_in_as_kiosk_app_); 1971 is_logged_in_as_kiosk_app_);
2056 } 1972 }
2057 1973
2058 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is 1974 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is
2059 // 12 hours. 1975 // 12 hours.
2060 // Verifies that a reboot is requested and a grace period is started that will 1976 // Verifies that a reboot is requested and a grace period is started that will
2061 // end after 6 + 24 hours of uptime. 1977 // end after 6 + 24 hours of uptime.
2062 TEST_P(AutomaticRebootManagerTest, StartInUptimeLimitGracePeriod) { 1978 TEST_P(AutomaticRebootManagerTest, StartInUptimeLimitGracePeriod) {
2063 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 1979 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
2064 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 1980 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
2065 1981
2066 // Verify that a reboot is requested but the device does not reboot 1982 // Verify that a reboot is requested but the device does not reboot
2067 // immediately. 1983 // immediately.
2068 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1984 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
2069 CreateAutomaticRebootManager(false); 1985 CreateAutomaticRebootManager(false);
2070 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 1986 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
2071 1987
2072 // Verify that a grace period has started. 1988 // Verify that a grace period has started.
2073 VerifyGracePeriod(uptime_limit_); 1989 VerifyGracePeriod(uptime_limit_);
2074 1990
2075 // Verify that unless a non-kiosk-app session is in progress, the device 1991 // Verify that unless a non-kiosk-app session is in progress, the device
2076 // eventually reboots. 1992 // eventually reboots.
2077 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 1993 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2078 is_logged_in_as_kiosk_app_); 1994 is_logged_in_as_kiosk_app_);
2079 } 1995 }
2080 1996
2081 // Chrome is starting. An update was applied and a reboot became necessary to 1997 // Chrome is starting. An update was applied and a reboot became necessary to
2082 // complete the update process after 6 hours of uptime. The current uptime is 1998 // complete the update process after 6 hours of uptime. The current uptime is
2083 // 10 days. 1999 // 10 days.
2084 // Verifies that when the policy to automatically reboot after an update is 2000 // Verifies that when the policy to automatically reboot after an update is
2085 // enabled, the device reboots immediately if no non-kiosk-app session is in 2001 // enabled, the device reboots immediately if no non-kiosk-app session is in
2086 // progress because the grace period ended after 6 + 24 hours of uptime. 2002 // progress because the grace period ended after 6 + 24 hours of uptime.
2087 TEST_P(AutomaticRebootManagerTest, StartAfterUpdateGracePeriod) { 2003 TEST_P(AutomaticRebootManagerTest, StartAfterUpdateGracePeriod) {
2088 SetUpdateStatusNeedReboot(); 2004 SetUpdateStatusNeedReboot();
2089 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); 2005 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
2090 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 2006 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
2091 SetRebootAfterUpdate(true, false); 2007 SetRebootAfterUpdate(true, false);
2092 2008
2093 // Verify that a reboot is requested and unless a non-kiosk-app session is in 2009 // Verify that a reboot is requested and unless a non-kiosk-app session is in
2094 // progress, the the device immediately reboots. 2010 // progress, the the device immediately reboots.
2095 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 2011 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2096 CreateAutomaticRebootManager(!is_user_logged_in_ || 2012 CreateAutomaticRebootManager(!is_user_logged_in_ ||
2097 is_logged_in_as_kiosk_app_); 2013 is_logged_in_as_kiosk_app_);
2098 VerifyRebootRequested( 2014 VerifyRebootRequested(
2099 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 2015 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2100 2016
2101 // Verify that if a non-kiosk-app session is in progress, the device never 2017 // Verify that if a non-kiosk-app session is in progress, the device never
2102 // reboots. 2018 // reboots.
2103 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 2019 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2104 is_logged_in_as_kiosk_app_); 2020 is_logged_in_as_kiosk_app_);
2105 } 2021 }
2106 2022
2107 // Chrome is starting. An update was applied and a reboot became necessary to 2023 // Chrome is starting. An update was applied and a reboot became necessary to
2108 // complete the update process after 6 hours of uptime. The current uptime is 2024 // complete the update process after 6 hours of uptime. The current uptime is
2109 // 12 hours. 2025 // 12 hours.
2110 // Verifies that when the policy to automatically reboot after an update is 2026 // Verifies that when the policy to automatically reboot after an update is
2111 // enabled, a reboot is requested and a grace period is started that will end 2027 // enabled, a reboot is requested and a grace period is started that will end
2112 // after 6 + 24 hours of uptime. 2028 // after 6 + 24 hours of uptime.
2113 TEST_P(AutomaticRebootManagerTest, StartInUpdateGracePeriod) { 2029 TEST_P(AutomaticRebootManagerTest, StartInUpdateGracePeriod) {
2114 SetUpdateStatusNeedReboot(); 2030 SetUpdateStatusNeedReboot();
2115 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); 2031 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
2116 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 2032 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
2117 SetRebootAfterUpdate(true, false); 2033 SetRebootAfterUpdate(true, false);
2118 2034
2119 // Verify that a reboot is requested but the device does not reboot 2035 // Verify that a reboot is requested but the device does not reboot
2120 // immediately. 2036 // immediately.
2121 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 2037 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2122 CreateAutomaticRebootManager(false); 2038 CreateAutomaticRebootManager(false);
2123 VerifyRebootRequested( 2039 VerifyRebootRequested(
2124 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 2040 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2125 2041
2126 // Verify that a grace period has started. 2042 // Verify that a grace period has started.
2127 VerifyGracePeriod(update_reboot_needed_uptime_); 2043 VerifyGracePeriod(update_reboot_needed_uptime_);
2128 2044
2129 // Verify that unless a non-kiosk-app session is in progress, the device 2045 // Verify that unless a non-kiosk-app session is in progress, the device
2130 // eventually reboots. 2046 // eventually reboots.
2131 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 2047 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2132 is_logged_in_as_kiosk_app_); 2048 is_logged_in_as_kiosk_app_);
2133 } 2049 }
2134 2050
2135 // Chrome is starting. An update was applied and a reboot became necessary to 2051 // Chrome is starting. An update was applied and a reboot became necessary to
2136 // complete the update process after 10 minutes of uptime. The current uptime is 2052 // complete the update process after 10 minutes of uptime. The current uptime is
2137 // 20 minutes. 2053 // 20 minutes.
2138 // Verifies that when the policy to automatically reboot after an update is 2054 // Verifies that when the policy to automatically reboot after an update is
2139 // enabled, no reboot occurs and a grace period is scheduled to begin after the 2055 // enabled, no reboot occurs and a grace period is scheduled to begin after the
2140 // minimum of 1 hour of uptime. 2056 // minimum of 1 hour of uptime.
2141 TEST_P(AutomaticRebootManagerTest, StartBeforeUpdateGracePeriod) { 2057 TEST_P(AutomaticRebootManagerTest, StartBeforeUpdateGracePeriod) {
2142 SetUpdateStatusNeedReboot(); 2058 SetUpdateStatusNeedReboot();
2143 SetUpdateRebootNeededUptime(base::TimeDelta::FromMinutes(10)); 2059 SetUpdateRebootNeededUptime(base::TimeDelta::FromMinutes(10));
2144 task_runner_->SetUptime(base::TimeDelta::FromMinutes(20)); 2060 uptime_provider()->SetUptime(base::TimeDelta::FromMinutes(20));
2145 SetRebootAfterUpdate(true, false); 2061 SetRebootAfterUpdate(true, false);
2146 2062
2147 // Verify that no reboot is requested and the device does not reboot 2063 // Verify that no reboot is requested and the device does not reboot
2148 // immediately. 2064 // immediately.
2149 ExpectNoRebootRequest(); 2065 ExpectNoRebootRequest();
2150 CreateAutomaticRebootManager(false); 2066 CreateAutomaticRebootManager(false);
2151 VerifyNoRebootRequested(); 2067 VerifyNoRebootRequested();
2152 2068
2153 // Verify that a grace period has been scheduled to start in the future. 2069 // Verify that a grace period has been scheduled to start in the future.
2154 VerifyGracePeriod(base::TimeDelta::FromHours(1)); 2070 VerifyGracePeriod(base::TimeDelta::FromHours(1));
2155 2071
2156 // Verify that a reboot is requested eventually and unless a non-kiosk-app 2072 // Verify that a reboot is requested eventually and unless a non-kiosk-app
2157 // session is in progress, the device eventually reboots. 2073 // session is in progress, the device eventually reboots.
2158 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 2074 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2159 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 2075 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2160 is_logged_in_as_kiosk_app_); 2076 is_logged_in_as_kiosk_app_);
2161 } 2077 }
2162 2078
2163 // Chrome is starting. An update was applied and a reboot became necessary to 2079 // Chrome is starting. An update was applied and a reboot became necessary to
2164 // complete the update process after 6 hours of uptime. The current uptime is 2080 // complete the update process after 6 hours of uptime. The current uptime is
2165 // 10 days. 2081 // 10 days.
2166 // Verifies that when the policy to automatically reboot after an update is not 2082 // Verifies that when the policy to automatically reboot after an update is not
2167 // enabled, no reboot occurs and no grace period is scheduled. 2083 // enabled, no reboot occurs and no grace period is scheduled.
2168 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicy) { 2084 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicy) {
2169 SetUpdateStatusNeedReboot(); 2085 SetUpdateStatusNeedReboot();
2170 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); 2086 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
2171 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 2087 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
2172 2088
2173 // Verify that no reboot is requested and the device does not reboot 2089 // Verify that no reboot is requested and the device does not reboot
2174 // immediately. 2090 // immediately.
2175 ExpectNoRebootRequest(); 2091 ExpectNoRebootRequest();
2176 CreateAutomaticRebootManager(false); 2092 CreateAutomaticRebootManager(false);
2177 VerifyNoRebootRequested(); 2093 VerifyNoRebootRequested();
2178 2094
2179 // Verify that no grace period has started. 2095 // Verify that no grace period has started.
2180 VerifyNoGracePeriod(); 2096 VerifyNoGracePeriod();
2181 2097
2182 // Verify that a reboot is never requested and the device never reboots. 2098 // Verify that a reboot is never requested and the device never reboots.
2183 FastForwardUntilNoTasksRemain(false); 2099 FastForwardUntilNoTasksRemain(false);
2184 } 2100 }
2185 2101
2186 // Chrome is starting. An update was applied and a reboot became necessary to 2102 // Chrome is starting. An update was applied and a reboot became necessary to
2187 // complete the update process but the time at which this happened was lost. The 2103 // complete the update process but the time at which this happened was lost. The
2188 // current uptime is 10 days. 2104 // current uptime is 10 days.
2189 // Verifies that the current uptime is persisted as the time at which a reboot 2105 // Verifies that the current uptime is persisted as the time at which a reboot
2190 // became necessary. Further verifies that when the policy to automatically 2106 // became necessary. Further verifies that when the policy to automatically
2191 // reboot after an update is enabled, a reboot is requested and a grace period 2107 // reboot after an update is enabled, a reboot is requested and a grace period
2192 // is started that will end 24 hours from now. 2108 // is started that will end 24 hours from now.
2193 TEST_P(AutomaticRebootManagerTest, StartUpdateTimeLost) { 2109 TEST_P(AutomaticRebootManagerTest, StartUpdateTimeLost) {
2194 SetUpdateStatusNeedReboot(); 2110 SetUpdateStatusNeedReboot();
2195 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 2111 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
2196 SetRebootAfterUpdate(true, false); 2112 SetRebootAfterUpdate(true, false);
2197 2113
2198 // Verify that a reboot is requested but the device does not reboot 2114 // Verify that a reboot is requested but the device does not reboot
2199 // immediately. 2115 // immediately.
2200 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 2116 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2201 CreateAutomaticRebootManager(false); 2117 CreateAutomaticRebootManager(false);
2202 VerifyRebootRequested( 2118 VerifyRebootRequested(
2203 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 2119 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2204 2120
2205 // Verify that the current uptime has been persisted as the time at which a 2121 // Verify that the current uptime has been persisted as the time at which a
2206 // reboot became necessary. 2122 // reboot became necessary.
2207 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 2123 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
2208 &update_reboot_needed_uptime_)); 2124 &update_reboot_needed_uptime_));
2209 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 2125 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
2210 2126
2211 // Verify that a grace period has started. 2127 // Verify that a grace period has started.
2212 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_); 2128 VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
2213 2129
2214 // Verify that unless a non-kiosk-app session is in progress, the device 2130 // Verify that unless a non-kiosk-app session is in progress, the device
2215 // eventually reboots. 2131 // eventually reboots.
2216 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 2132 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2217 is_logged_in_as_kiosk_app_); 2133 is_logged_in_as_kiosk_app_);
2218 } 2134 }
2219 2135
2220 // Chrome is starting. An update was applied and a reboot became necessary to 2136 // Chrome is starting. An update was applied and a reboot became necessary to
2221 // complete the update process but the time at which this happened was lost. The 2137 // complete the update process but the time at which this happened was lost. The
2222 // current uptime is 10 days. 2138 // current uptime is 10 days.
2223 // Verifies that the current uptime is persisted as the time at which a reboot 2139 // Verifies that the current uptime is persisted as the time at which a reboot
2224 // became necessary. Further verifies that when the policy to automatically 2140 // became necessary. Further verifies that when the policy to automatically
2225 // reboot after an update is not enabled, no reboot occurs and no grace period 2141 // reboot after an update is not enabled, no reboot occurs and no grace period
2226 // is scheduled. 2142 // is scheduled.
2227 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicyTimeLost) { 2143 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicyTimeLost) {
2228 SetUpdateStatusNeedReboot(); 2144 SetUpdateStatusNeedReboot();
2229 task_runner_->SetUptime(base::TimeDelta::FromDays(10)); 2145 uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
2230 2146
2231 // Verify that no reboot is requested and the device does not reboot 2147 // Verify that no reboot is requested and the device does not reboot
2232 // immediately. 2148 // immediately.
2233 ExpectNoRebootRequest(); 2149 ExpectNoRebootRequest();
2234 CreateAutomaticRebootManager(false); 2150 CreateAutomaticRebootManager(false);
2235 VerifyNoRebootRequested(); 2151 VerifyNoRebootRequested();
2236 2152
2237 // Verify that the current uptime has been persisted as the time at which a 2153 // Verify that the current uptime has been persisted as the time at which a
2238 // reboot became necessary. 2154 // reboot became necessary.
2239 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile( 2155 EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
2240 &update_reboot_needed_uptime_)); 2156 &update_reboot_needed_uptime_));
2241 EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_); 2157 EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
2242 2158
2243 // Verify that no grace period has started. 2159 // Verify that no grace period has started.
2244 VerifyNoGracePeriod(); 2160 VerifyNoGracePeriod();
2245 2161
2246 // Verify that a reboot is never requested and the device never reboots. 2162 // Verify that a reboot is never requested and the device never reboots.
2247 FastForwardUntilNoTasksRemain(false); 2163 FastForwardUntilNoTasksRemain(false);
2248 } 2164 }
2249 2165
2250 // Chrome is starting. No update has been applied. The current uptime is 2166 // Chrome is starting. No update has been applied. The current uptime is
2251 // 12 hours. 2167 // 12 hours.
2252 // Verifies that no time is persisted as the time at which a reboot became 2168 // Verifies that no time is persisted as the time at which a reboot became
2253 // necessary. Further verifies that no reboot occurs and no grace period is 2169 // necessary. Further verifies that no reboot occurs and no grace period is
2254 // scheduled. 2170 // scheduled.
2255 TEST_P(AutomaticRebootManagerTest, StartNoUpdate) { 2171 TEST_P(AutomaticRebootManagerTest, StartNoUpdate) {
2256 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 2172 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
2257 SetRebootAfterUpdate(true, false); 2173 SetRebootAfterUpdate(true, false);
2258 2174
2259 // Verify that no reboot is requested and the device does not reboot 2175 // Verify that no reboot is requested and the device does not reboot
2260 // immediately. 2176 // immediately.
2261 ExpectNoRebootRequest(); 2177 ExpectNoRebootRequest();
2262 CreateAutomaticRebootManager(false); 2178 CreateAutomaticRebootManager(false);
2263 VerifyNoRebootRequested(); 2179 VerifyNoRebootRequested();
2264 2180
2265 // Verify that no time is persisted as the time at which a reboot became 2181 // Verify that no time is persisted as the time at which a reboot became
2266 // necessary. 2182 // necessary.
(...skipping 10 matching lines...) Expand all
2277 // Chrome is starting. The uptime limit is set to 6 hours. Also, an update was 2193 // Chrome is starting. The uptime limit is set to 6 hours. Also, an update was
2278 // applied and a reboot became necessary to complete the update process after 2194 // applied and a reboot became necessary to complete the update process after
2279 // 8 hours of uptime. The current uptime is 12 hours. 2195 // 8 hours of uptime. The current uptime is 12 hours.
2280 // Verifies that when the policy to automatically reboot after an update is 2196 // Verifies that when the policy to automatically reboot after an update is
2281 // enabled, a reboot is requested and a grace period is started that will end 2197 // enabled, a reboot is requested and a grace period is started that will end
2282 // after 6 + 24 hours of uptime. 2198 // after 6 + 24 hours of uptime.
2283 TEST_P(AutomaticRebootManagerTest, StartUptimeLimitBeforeUpdate) { 2199 TEST_P(AutomaticRebootManagerTest, StartUptimeLimitBeforeUpdate) {
2284 SetUptimeLimit(base::TimeDelta::FromHours(6), false); 2200 SetUptimeLimit(base::TimeDelta::FromHours(6), false);
2285 SetUpdateStatusNeedReboot(); 2201 SetUpdateStatusNeedReboot();
2286 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(8)); 2202 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(8));
2287 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 2203 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
2288 SetRebootAfterUpdate(true, false); 2204 SetRebootAfterUpdate(true, false);
2289 2205
2290 // Verify that a reboot is requested but the device does not reboot 2206 // Verify that a reboot is requested but the device does not reboot
2291 // immediately. 2207 // immediately.
2292 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 2208 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
2293 CreateAutomaticRebootManager(false); 2209 CreateAutomaticRebootManager(false);
2294 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC); 2210 VerifyRebootRequested(AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC);
2295 2211
2296 // Verify that a grace period has started. 2212 // Verify that a grace period has started.
2297 VerifyGracePeriod(uptime_limit_); 2213 VerifyGracePeriod(uptime_limit_);
2298 2214
2299 // Verify that unless a non-kiosk-app session is in progress, the device 2215 // Verify that unless a non-kiosk-app session is in progress, the device
2300 // eventually reboots. 2216 // eventually reboots.
2301 FastForwardUntilNoTasksRemain(!is_user_logged_in_ || 2217 FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
2302 is_logged_in_as_kiosk_app_); 2218 is_logged_in_as_kiosk_app_);
2303 } 2219 }
2304 2220
2305 // Chrome is starting. The uptime limit is set to 8 hours. Also, an update was 2221 // Chrome is starting. The uptime limit is set to 8 hours. Also, an update was
2306 // applied and a reboot became necessary to complete the update process after 2222 // applied and a reboot became necessary to complete the update process after
2307 // 6 hours of uptime. The current uptime is 12 hours. 2223 // 6 hours of uptime. The current uptime is 12 hours.
2308 // Verifies that when the policy to automatically reboot after an update is 2224 // Verifies that when the policy to automatically reboot after an update is
2309 // enabled, a reboot is requested and a grace period is started that will end 2225 // enabled, a reboot is requested and a grace period is started that will end
2310 // after 6 + 24 hours of uptime. 2226 // after 6 + 24 hours of uptime.
2311 TEST_P(AutomaticRebootManagerTest, StartUpdateBeforeUptimeLimit) { 2227 TEST_P(AutomaticRebootManagerTest, StartUpdateBeforeUptimeLimit) {
2312 SetUptimeLimit(base::TimeDelta::FromHours(8), false); 2228 SetUptimeLimit(base::TimeDelta::FromHours(8), false);
2313 SetUpdateStatusNeedReboot(); 2229 SetUpdateStatusNeedReboot();
2314 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6)); 2230 SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
2315 task_runner_->SetUptime(base::TimeDelta::FromHours(12)); 2231 uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
2316 SetRebootAfterUpdate(true, false); 2232 SetRebootAfterUpdate(true, false);
2317 2233
2318 // Verify that a reboot is requested but the device does not reboot 2234 // Verify that a reboot is requested but the device does not reboot
2319 // immediately. 2235 // immediately.
2320 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 2236 ExpectRebootRequest(AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2321 CreateAutomaticRebootManager(false); 2237 CreateAutomaticRebootManager(false);
2322 VerifyRebootRequested( 2238 VerifyRebootRequested(
2323 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE); 2239 AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE);
2324 2240
2325 // Verify that a grace period has started. 2241 // Verify that a grace period has started.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2358 INSTANTIATE_TEST_CASE_P( 2274 INSTANTIATE_TEST_CASE_P(
2359 AutomaticRebootManagerTestInstance, 2275 AutomaticRebootManagerTestInstance,
2360 AutomaticRebootManagerTest, 2276 AutomaticRebootManagerTest,
2361 ::testing::Values( 2277 ::testing::Values(
2362 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN, 2278 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN,
2363 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION, 2279 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION,
2364 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION)); 2280 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION));
2365 2281
2366 } // namespace system 2282 } // namespace system
2367 } // namespace chromeos 2283 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/session_length_limiter_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698