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

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

Powered by Google App Engine
This is Rietveld 408576698