| Index: chrome/browser/chromeos/system/automatic_reboot_manager_unittest.cc
|
| diff --git a/chrome/browser/chromeos/system/automatic_reboot_manager_unittest.cc b/chrome/browser/chromeos/system/automatic_reboot_manager_unittest.cc
|
| index ba045ad40271422bae3fc3261ed8cc3499c345a9..4f00912050303c7250eacb231c04ef53c71f5c73 100644
|
| --- a/chrome/browser/chromeos/system/automatic_reboot_manager_unittest.cc
|
| +++ b/chrome/browser/chromeos/system/automatic_reboot_manager_unittest.cc
|
| @@ -5,6 +5,7 @@
|
| #include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
|
|
|
| #include <string>
|
| +#include <utility>
|
|
|
| #include "ash/shell.h"
|
| #include "ash/test/test_shell_delegate.h"
|
| @@ -18,9 +19,9 @@
|
| #include "base/prefs/pref_registry_simple.h"
|
| #include "base/prefs/testing_pref_service.h"
|
| #include "base/run_loop.h"
|
| +#include "base/single_thread_task_runner.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/test/simple_test_tick_clock.h"
|
| -#include "base/test/test_mock_time_task_runner.h"
|
| #include "base/thread_task_runner_handle.h"
|
| #include "base/threading/sequenced_worker_pool.h"
|
| #include "base/time/tick_clock.h"
|
| @@ -54,55 +55,68 @@
|
|
|
| namespace {
|
|
|
| -// Provides a mock device uptime that follows the given |tick_clock_| with a
|
| -// configurable offset. The mock uptime can also be written to |uptime_file_|,
|
| -// thusly allowing to mock /proc/uptime.
|
| -class MockUptimeProvider {
|
| +// A SingleThreadTaskRunner that mocks the current time and allows it to be
|
| +// fast-forwarded. The current time in ticks is returned by Now(). The
|
| +// corresponding device uptime is written to |uptime_file_|, providing a mock
|
| +// for /proc/uptime.
|
| +class MockTimeSingleThreadTaskRunner : public base::SingleThreadTaskRunner {
|
| public:
|
| - explicit MockUptimeProvider(scoped_ptr<base::TickClock> tick_clock);
|
| -
|
| - void WriteUptimeToFile();
|
| -
|
| - // Adjusts the offset so that the current mock uptime will be |uptime|.
|
| + MockTimeSingleThreadTaskRunner();
|
| +
|
| + // base::SingleThreadTaskRunner:
|
| + virtual bool RunsTasksOnCurrentThread() const override;
|
| + virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
|
| + const base::Closure& task,
|
| + base::TimeDelta delay) override;
|
| + virtual bool PostNonNestableDelayedTask(
|
| + const tracked_objects::Location& from_here,
|
| + const base::Closure& task,
|
| + base::TimeDelta delay) override;
|
| +
|
| + void SetUptimeFile(const base::FilePath& uptime_file);
|
| void SetUptime(const base::TimeDelta& uptime);
|
|
|
| - void set_uptime_file_path(const base::FilePath& uptime_file_path) {
|
| - uptime_file_path_ = uptime_file_path;
|
| - }
|
| -
|
| - base::TimeDelta uptime() const {
|
| - return tick_clock_->NowTicks() - base::TimeTicks() + uptime_offset_;
|
| - }
|
| + const base::TimeDelta& Uptime() const;
|
| + const base::TimeTicks& Now() const;
|
| +
|
| + void FastForwardBy(const base::TimeDelta& delta);
|
| + void FastForwardUntilNoTasksRemain();
|
| + void RunUntilIdle();
|
|
|
| private:
|
| - scoped_ptr<base::TickClock> tick_clock_;
|
| -
|
| - base::FilePath uptime_file_path_;
|
| - base::TimeDelta uptime_offset_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(MockUptimeProvider);
|
| + // Strict weak temporal ordering of tasks.
|
| + class TemporalOrder {
|
| + public:
|
| + bool operator()(
|
| + const std::pair<base::TimeTicks, base::Closure>& first_task,
|
| + const std::pair<base::TimeTicks, base::Closure>& second_task) const;
|
| + };
|
| +
|
| + virtual ~MockTimeSingleThreadTaskRunner();
|
| +
|
| + base::FilePath uptime_file_;
|
| + base::TimeDelta uptime_;
|
| + base::TimeTicks now_;
|
| + std::priority_queue<std::pair<base::TimeTicks, base::Closure>,
|
| + std::vector<std::pair<base::TimeTicks, base::Closure> >,
|
| + TemporalOrder> tasks_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(MockTimeSingleThreadTaskRunner);
|
| };
|
|
|
| -class TestAutomaticRebootManagerTaskRunner
|
| - : public base::TestMockTimeTaskRunner {
|
| +class MockTimeTickClock : public base::TickClock {
|
| public:
|
| - TestAutomaticRebootManagerTaskRunner();
|
| -
|
| - MockUptimeProvider* uptime_provider() const {
|
| - return uptime_provider_.get();
|
| - }
|
| + explicit MockTimeTickClock(
|
| + scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner);
|
| + virtual ~MockTimeTickClock();
|
| +
|
| + // base::TickClock:
|
| + virtual base::TimeTicks NowTicks() override;
|
|
|
| private:
|
| - ~TestAutomaticRebootManagerTaskRunner() override;
|
| -
|
| - // base::TestMockTimeTaskRunner:
|
| - void OnBeforeSelectingTask() override;
|
| - void OnAfterTimePassed() override;
|
| - void OnAfterTaskRun() override;
|
| -
|
| - scoped_ptr<MockUptimeProvider> uptime_provider_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(TestAutomaticRebootManagerTaskRunner);
|
| + scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(MockTimeTickClock);
|
| };
|
|
|
| class MockAutomaticRebootManagerObserver
|
| @@ -162,10 +176,6 @@
|
|
|
| // Sets the status of |update_engine_client_| to NEED_REBOOT for tests.
|
| void SetUpdateStatusNeedReboot();
|
| -
|
| - MockUptimeProvider* uptime_provider() const {
|
| - return task_runner_->uptime_provider();
|
| - }
|
|
|
| bool is_user_logged_in_;
|
| bool is_logged_in_as_kiosk_app_;
|
| @@ -179,7 +189,7 @@
|
| base::TimeDelta update_reboot_needed_uptime_;
|
| base::TimeDelta uptime_limit_;
|
|
|
| - scoped_refptr<TestAutomaticRebootManagerTaskRunner> task_runner_;
|
| + scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_;
|
|
|
| MockAutomaticRebootManagerObserver automatic_reboot_manager_observer_;
|
| scoped_ptr<AutomaticRebootManager> automatic_reboot_manager_;
|
| @@ -234,40 +244,114 @@
|
| uptime_seconds.size()));
|
| }
|
|
|
| -MockUptimeProvider::MockUptimeProvider(scoped_ptr<base::TickClock> tick_clock)
|
| - : tick_clock_(tick_clock.Pass()) {
|
| -}
|
| -
|
| -void MockUptimeProvider::WriteUptimeToFile() {
|
| - SaveUptimeToFile(uptime_file_path_, uptime());
|
| -}
|
| -
|
| -void MockUptimeProvider::SetUptime(const base::TimeDelta& uptime) {
|
| - uptime_offset_ = uptime - (tick_clock_->NowTicks() - base::TimeTicks());
|
| - WriteUptimeToFile();
|
| -}
|
| -
|
| -TestAutomaticRebootManagerTaskRunner::TestAutomaticRebootManagerTaskRunner()
|
| - : uptime_provider_(new MockUptimeProvider(GetMockTickClock())) {
|
| -}
|
| -
|
| -TestAutomaticRebootManagerTaskRunner::~TestAutomaticRebootManagerTaskRunner() {
|
| -}
|
| -
|
| -void TestAutomaticRebootManagerTaskRunner::OnBeforeSelectingTask() {
|
| +MockTimeSingleThreadTaskRunner::MockTimeSingleThreadTaskRunner() {
|
| +}
|
| +
|
| +bool MockTimeSingleThreadTaskRunner::RunsTasksOnCurrentThread() const {
|
| + return true;
|
| +}
|
| +
|
| +bool MockTimeSingleThreadTaskRunner::PostDelayedTask(
|
| + const tracked_objects::Location& from_here,
|
| + const base::Closure& task,
|
| + base::TimeDelta delay) {
|
| + tasks_.push(std::pair<base::TimeTicks, base::Closure>(now_ + delay, task));
|
| + return true;
|
| +}
|
| +
|
| +bool MockTimeSingleThreadTaskRunner::PostNonNestableDelayedTask(
|
| + const tracked_objects::Location& from_here,
|
| + const base::Closure& task,
|
| + base::TimeDelta delay) {
|
| + NOTREACHED();
|
| + return false;
|
| +}
|
| +
|
| +void MockTimeSingleThreadTaskRunner::SetUptimeFile(
|
| + const base::FilePath& uptime_file) {
|
| + uptime_file_ = uptime_file;
|
| + SaveUptimeToFile(uptime_file_, uptime_);
|
| +}
|
| +
|
| +void MockTimeSingleThreadTaskRunner::SetUptime(const base::TimeDelta& uptime) {
|
| + uptime_ = uptime;
|
| + SaveUptimeToFile(uptime_file_, uptime_);
|
| +}
|
| +
|
| +const base::TimeDelta& MockTimeSingleThreadTaskRunner::Uptime() const {
|
| + return uptime_;
|
| +}
|
| +
|
| +const base::TimeTicks& MockTimeSingleThreadTaskRunner::Now() const {
|
| + return now_;
|
| +}
|
| +
|
| +void MockTimeSingleThreadTaskRunner::FastForwardBy(
|
| + const base::TimeDelta& delta) {
|
| + const base::TimeTicks latest = now_ + delta;
|
| base::SequencedWorkerPool* blocking_pool =
|
| content::BrowserThread::GetBlockingPool();
|
| blocking_pool->FlushForTesting();
|
| -}
|
| -
|
| -void TestAutomaticRebootManagerTaskRunner::OnAfterTimePassed() {
|
| - uptime_provider_->WriteUptimeToFile();
|
| -}
|
| -
|
| -void TestAutomaticRebootManagerTaskRunner::OnAfterTaskRun() {
|
| + while (!tasks_.empty() && tasks_.top().first <= latest) {
|
| + uptime_ += tasks_.top().first - now_;
|
| + SaveUptimeToFile(uptime_file_, uptime_);
|
| + now_ = tasks_.top().first;
|
| + base::Closure task = tasks_.top().second;
|
| + tasks_.pop();
|
| + task.Run();
|
| + blocking_pool->FlushForTesting();
|
| + }
|
| + uptime_ += latest - now_;
|
| + SaveUptimeToFile(uptime_file_, uptime_);
|
| + now_ = latest;
|
| +}
|
| +
|
| +void MockTimeSingleThreadTaskRunner::FastForwardUntilNoTasksRemain() {
|
| base::SequencedWorkerPool* blocking_pool =
|
| content::BrowserThread::GetBlockingPool();
|
| blocking_pool->FlushForTesting();
|
| + while (!tasks_.empty()) {
|
| + uptime_ += tasks_.top().first - now_;
|
| + SaveUptimeToFile(uptime_file_, uptime_);
|
| + now_ = tasks_.top().first;
|
| + base::Closure task = tasks_.top().second;
|
| + tasks_.pop();
|
| + task.Run();
|
| + blocking_pool->FlushForTesting();
|
| + }
|
| +}
|
| +
|
| +void MockTimeSingleThreadTaskRunner::RunUntilIdle() {
|
| + base::SequencedWorkerPool* blocking_pool =
|
| + content::BrowserThread::GetBlockingPool();
|
| + blocking_pool->FlushForTesting();
|
| + while (!tasks_.empty() && tasks_.top().first <= now_) {
|
| + base::Closure task = tasks_.top().second;
|
| + tasks_.pop();
|
| + task.Run();
|
| + blocking_pool->FlushForTesting();
|
| + }
|
| +}
|
| +
|
| +bool MockTimeSingleThreadTaskRunner::TemporalOrder::operator()(
|
| + const std::pair<base::TimeTicks, base::Closure>& first_task,
|
| + const std::pair<base::TimeTicks, base::Closure>& second_task) const {
|
| + return first_task.first > second_task.first;
|
| +}
|
| +
|
| +MockTimeSingleThreadTaskRunner::~MockTimeSingleThreadTaskRunner() {
|
| +}
|
| +
|
| +MockTimeTickClock::MockTimeTickClock(
|
| + scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner)
|
| + : task_runner_(task_runner) {
|
| +}
|
| +
|
| +MockTimeTickClock::~MockTimeTickClock() {
|
| +}
|
| +
|
| +base::TimeTicks MockTimeTickClock::NowTicks() {
|
| + return task_runner_->Now();
|
| }
|
|
|
| MockAutomaticRebootManagerObserver::MockAutomaticRebootManagerObserver()
|
| @@ -299,7 +383,7 @@
|
| AutomaticRebootManagerBasicTest::AutomaticRebootManagerBasicTest()
|
| : is_user_logged_in_(false),
|
| is_logged_in_as_kiosk_app_(false),
|
| - task_runner_(new TestAutomaticRebootManagerTaskRunner),
|
| + task_runner_(new MockTimeSingleThreadTaskRunner),
|
| reboot_after_update_(false),
|
| ui_thread_task_runner_handle_(task_runner_),
|
| mock_user_manager_(new MockUserManager),
|
| @@ -315,7 +399,7 @@
|
| ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| const base::FilePath& temp_dir = temp_dir_.path();
|
| const base::FilePath uptime_file = temp_dir.Append("uptime");
|
| - uptime_provider()->set_uptime_file_path(uptime_file);
|
| + task_runner_->SetUptimeFile(uptime_file);
|
| ASSERT_FALSE(base::WriteFile(uptime_file, NULL, 0));
|
| update_reboot_needed_uptime_file_ =
|
| temp_dir.Append("update_reboot_needed_uptime");
|
| @@ -454,7 +538,7 @@
|
| void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager(
|
| bool expect_reboot) {
|
| automatic_reboot_manager_.reset(new AutomaticRebootManager(
|
| - scoped_ptr<base::TickClock>(task_runner_->GetMockTickClock())));
|
| + scoped_ptr<base::TickClock>(new MockTimeTickClock(task_runner_))));
|
| automatic_reboot_manager_observer_.Init(automatic_reboot_manager_.get());
|
| task_runner_->RunUntilIdle();
|
| EXPECT_EQ(expect_reboot ? 1 : 0,
|
| @@ -462,7 +546,7 @@
|
|
|
| uptime_processing_delay_ =
|
| base::TimeTicks() - automatic_reboot_manager_->boot_time_ -
|
| - uptime_provider()->uptime();
|
| + task_runner_->Uptime();
|
| EXPECT_GE(uptime_processing_delay_, base::TimeDelta());
|
| EXPECT_LE(uptime_processing_delay_, base::TimeDelta::FromSeconds(1));
|
|
|
| @@ -512,7 +596,7 @@
|
| void AutomaticRebootManagerBasicTest::VerifyGracePeriod(
|
| const base::TimeDelta& start_uptime) const {
|
| const base::TimeDelta start =
|
| - start_uptime - uptime_provider()->uptime() - uptime_processing_delay_;
|
| + start_uptime - task_runner_->Uptime() - uptime_processing_delay_;
|
| const base::TimeDelta end = start + base::TimeDelta::FromHours(24);
|
| if (start <= base::TimeDelta()) {
|
| EXPECT_TRUE(automatic_reboot_manager_->reboot_requested_);
|
| @@ -580,7 +664,7 @@
|
| // Verifies that the idle timer is running. Further verifies that when a kiosk
|
| // app session begins, the idle timer is stopped.
|
| TEST_F(AutomaticRebootManagerBasicTest, LoginStopsIdleTimer) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
|
|
| // Verify that no reboot is requested, the device does not reboot immediately
|
| // and the login screen idle timer is started.
|
| @@ -607,7 +691,7 @@
|
| // Verifies that the idle timer is running. Further verifies that when a
|
| // non-kiosk-app session begins, the idle timer is stopped.
|
| TEST_F(AutomaticRebootManagerBasicTest, NonKioskLoginStopsIdleTimer) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
|
|
| // Verify that no reboot is requested, the device does not reboot immediately
|
| // and the login screen idle timer is started.
|
| @@ -634,7 +718,7 @@
|
| // Verifies that user activity prevents the device from rebooting. Further
|
| // verifies that when user activity ceases, the devices reboots.
|
| TEST_F(AutomaticRebootManagerBasicTest, UserActivityResetsIdleTimer) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
|
|
| // Verify that no reboot is requested, the device does not reboot immediately
|
| // and the login screen idle timer is started.
|
| @@ -672,7 +756,7 @@
|
| TEST_F(AutomaticRebootManagerBasicTest, ResumeNoPolicy) {
|
| is_user_logged_in_ = true;
|
| is_logged_in_as_kiosk_app_ = true;
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
|
| + task_runner_->SetUptime(base::TimeDelta::FromDays(10));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -696,7 +780,7 @@
|
| // immediately reboot.
|
| TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAppNoPolicy) {
|
| is_user_logged_in_ = true;
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
|
| + task_runner_->SetUptime(base::TimeDelta::FromDays(10));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -722,7 +806,7 @@
|
| TEST_F(AutomaticRebootManagerBasicTest, ResumeBeforeGracePeriod) {
|
| is_user_logged_in_ = true;
|
| is_logged_in_as_kiosk_app_ = true;
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -752,7 +836,7 @@
|
| // immediately reboot.
|
| TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeBeforeGracePeriod) {
|
| is_user_logged_in_ = true;
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -783,7 +867,7 @@
|
| TEST_F(AutomaticRebootManagerBasicTest, ResumeInGracePeriod) {
|
| is_user_logged_in_ = true;
|
| is_logged_in_as_kiosk_app_ = true;
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -810,7 +894,7 @@
|
| // immediately reboot.
|
| TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeInGracePeriod) {
|
| is_user_logged_in_ = true;
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -841,7 +925,7 @@
|
| TEST_F(AutomaticRebootManagerBasicTest, ResumeAfterGracePeriod) {
|
| is_user_logged_in_ = true;
|
| is_logged_in_as_kiosk_app_ = true;
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(29) +
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(29) +
|
| base::TimeDelta::FromMinutes(30));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| @@ -869,7 +953,7 @@
|
| // immediately reboot.
|
| TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAfterGracePeriod) {
|
| is_user_logged_in_ = true;
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(29) +
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(29) +
|
| base::TimeDelta::FromMinutes(30));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| @@ -898,7 +982,7 @@
|
| // Verifies that when the browser terminates, the device does not immediately
|
| // reboot.
|
| TEST_P(AutomaticRebootManagerTest, TerminateNoPolicy) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
|
| + task_runner_->SetUptime(base::TimeDelta::FromDays(10));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -921,7 +1005,7 @@
|
| // 12 hours.
|
| // Verifies that when the browser terminates, it does not immediately reboot.
|
| TEST_P(AutomaticRebootManagerTest, TerminateBeforeGracePeriod) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -952,7 +1036,7 @@
|
| // Verifies that when the browser terminates, the device immediately reboots if
|
| // a kiosk app session is in progress.
|
| TEST_P(AutomaticRebootManagerTest, TerminateInGracePeriod) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -982,7 +1066,7 @@
|
| // Verifies that when the uptime limit is set to 24 hours, no reboot occurs and
|
| // a grace period is scheduled to begin after 24 hours of uptime.
|
| TEST_P(AutomaticRebootManagerTest, BeforeUptimeLimitGracePeriod) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -1011,7 +1095,7 @@
|
| // Verifies that when the uptime limit is set to 6 hours, a reboot is requested
|
| // and a grace period is started that will end after 6 + 24 hours of uptime.
|
| TEST_P(AutomaticRebootManagerTest, InUptimeLimitGracePeriod) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -1041,7 +1125,7 @@
|
| // immediately if no non-kiosk-app-session is in progress because the grace
|
| // period ended after 6 + 24 hours of uptime.
|
| TEST_P(AutomaticRebootManagerTest, AfterUptimeLimitGracePeriod) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
|
| + task_runner_->SetUptime(base::TimeDelta::FromDays(10));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -1068,7 +1152,7 @@
|
| // 6 hours.
|
| // Verifies that when the uptime limit is removed, the grace period is removed.
|
| TEST_P(AutomaticRebootManagerTest, UptimeLimitOffBeforeGracePeriod) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(6));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(6));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -1102,7 +1186,7 @@
|
| // 24 hours.
|
| // Verifies that when the uptime limit is removed, the grace period is removed.
|
| TEST_P(AutomaticRebootManagerTest, UptimeLimitOffInGracePeriod) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(24));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(24));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -1138,7 +1222,7 @@
|
| // Verifies that when the uptime limit is extended to 24 hours, the grace period
|
| // is rescheduled to start further in the future.
|
| TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitBeforeGracePeriod) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(6));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(6));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -1177,7 +1261,7 @@
|
| // Verifies that when the uptime limit is extended to 24 hours, the grace period
|
| // is rescheduled to start in the future.
|
| TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitInGracePeriod) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(18));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(18));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -1216,7 +1300,7 @@
|
| // Verifies that when the uptime limit is shortened to 6 hours, the grace period
|
| // is rescheduled to have already started.
|
| TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitBeforeToInGracePeriod) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -1254,7 +1338,7 @@
|
| // Verifies that when the uptime limit is shortened to 18 hours, the grace
|
| // period is rescheduled to have started earlier.
|
| TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToInGracePeriod) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(36));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(36));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -1294,7 +1378,7 @@
|
| // reboots immediately if no non-kiosk-app session is in progress because the
|
| // grace period ended after 6 + 24 hours of uptime.
|
| TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToAfterGracePeriod) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(36));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(36));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -1333,7 +1417,7 @@
|
| // policy to automatically reboot after an update is not enabled, no reboot
|
| // occurs and no grace period is scheduled.
|
| TEST_P(AutomaticRebootManagerTest, UpdateNoPolicy) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -1352,7 +1436,7 @@
|
| // reboot became necessary.
|
| EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
|
| &update_reboot_needed_uptime_));
|
| - EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
|
| + EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
|
|
|
| // Verify that no grace period has started.
|
| VerifyNoGracePeriod();
|
| @@ -1367,7 +1451,7 @@
|
| // policy to automatically reboot after an update is enabled, a reboot is
|
| // requested and a grace period is started that will end 24 hours from now.
|
| TEST_P(AutomaticRebootManagerTest, Update) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
| SetRebootAfterUpdate(true, false);
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| @@ -1388,7 +1472,7 @@
|
| // reboot became necessary.
|
| EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
|
| &update_reboot_needed_uptime_));
|
| - EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
|
| + EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
|
|
|
| // Verify that a grace period has started.
|
| VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
|
| @@ -1404,7 +1488,7 @@
|
| // the second notification is ignored and the uptime at which it occurred does
|
| // not get persisted as the time at which an update became necessary.
|
| TEST_P(AutomaticRebootManagerTest, UpdateAfterUpdate) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
| SetRebootAfterUpdate(true, false);
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| @@ -1425,7 +1509,7 @@
|
| // reboot became necessary.
|
| EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
|
| &update_reboot_needed_uptime_));
|
| - EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
|
| + EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
|
|
|
| // Verify that a grace period has started.
|
| VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
|
| @@ -1458,7 +1542,7 @@
|
| // the current uptime is persisted as the time at which a reboot became
|
| // necessary.
|
| TEST_P(AutomaticRebootManagerTest, UpdateBeforeMinimumUptime) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromMinutes(10));
|
| + task_runner_->SetUptime(base::TimeDelta::FromMinutes(10));
|
| SetRebootAfterUpdate(true, false);
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| @@ -1478,7 +1562,7 @@
|
| // reboot became necessary.
|
| EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
|
| &update_reboot_needed_uptime_));
|
| - EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
|
| + EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
|
|
|
| // Verify that a grace period has been scheduled to begin in the future.
|
| VerifyGracePeriod(base::TimeDelta::FromHours(1));
|
| @@ -1497,7 +1581,7 @@
|
| // enabled, a reboot is requested and a grace period is started that will end
|
| // after 6 + 24 hours of uptime.
|
| TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateInGracePeriod) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(6));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(6));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -1537,7 +1621,7 @@
|
| // enabled, the device reboots immediately if no non-kiosk-app session is in
|
| // progress because the grace period ended after 6 + 24 hours of uptime.
|
| TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateAfterGracePeriod) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(6));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(6));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -1576,7 +1660,7 @@
|
| // Verifies that when the policy to automatically reboot after an update is
|
| // disabled, the reboot request and grace period are removed.
|
| TEST_P(AutomaticRebootManagerTest, PolicyOffAfterUpdate) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(6));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(6));
|
| SetRebootAfterUpdate(true, false);
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| @@ -1591,7 +1675,7 @@
|
| NotifyUpdateRebootNeeded();
|
|
|
| // Verify that a grace period has started.
|
| - VerifyGracePeriod(uptime_provider()->uptime() + uptime_processing_delay_);
|
| + VerifyGracePeriod(task_runner_->Uptime() + uptime_processing_delay_);
|
|
|
| // Fast forward the uptime by 20 seconds. Verify that the device does not
|
| // reboot immediately.
|
| @@ -1657,7 +1741,7 @@
|
| // that the current uptime is persisted as the time at which a reboot became
|
| // necessary.
|
| TEST_P(AutomaticRebootManagerTest, UptimeLimitBeforeUpdate) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
| SetRebootAfterUpdate(true, false);
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| @@ -1688,7 +1772,7 @@
|
| // reboot became necessary.
|
| EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
|
| &update_reboot_needed_uptime_));
|
| - EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
|
| + EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
|
|
|
| // Verify that the grace period has not been rescheduled.
|
| VerifyGracePeriod(uptime_limit_);
|
| @@ -1706,7 +1790,7 @@
|
| // from now. Further verifies that the current uptime is persisted as the time
|
| // at which a reboot became necessary.
|
| TEST_P(AutomaticRebootManagerTest, UpdateBeforeUptimeLimit) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
| SetRebootAfterUpdate(true, false);
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| @@ -1735,7 +1819,7 @@
|
| // reboot became necessary.
|
| EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
|
| &update_reboot_needed_uptime_));
|
| - EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
|
| + EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
|
|
|
| // Verify that the grace period has been rescheduled to start at the time that
|
| // the update became available.
|
| @@ -1755,7 +1839,7 @@
|
| // grace period is rescheduled to start after 12 hours of uptime. Further
|
| // verifies that when the uptime limit is removed, the grace period is removed.
|
| TEST_P(AutomaticRebootManagerTest, PolicyOffThenUptimeLimitOff) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
| SetRebootAfterUpdate(true, false);
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| @@ -1780,7 +1864,7 @@
|
| // reboot became necessary.
|
| EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
|
| &update_reboot_needed_uptime_));
|
| - EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
|
| + EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
|
|
|
| // Verify that a grace period has been rescheduled to end 24 hours from now.
|
| VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
|
| @@ -1817,7 +1901,7 @@
|
| // when the policy to reboot after an update is disabled, the reboot request and
|
| // grace period are removed.
|
| TEST_P(AutomaticRebootManagerTest, UptimeLimitOffThenPolicyOff) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
| SetRebootAfterUpdate(true, false);
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| @@ -1835,7 +1919,7 @@
|
| // reboot became necessary.
|
| EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
|
| &update_reboot_needed_uptime_));
|
| - EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
|
| + EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
|
|
|
| // Verify that the grace period has started.
|
| VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
|
| @@ -1878,7 +1962,7 @@
|
| // Verifies that if no non-kiosk-app session is in progress, the device reboots
|
| // immediately when the grace period ends after 6 + 24 hours of uptime.
|
| TEST_P(AutomaticRebootManagerTest, GracePeriodEnd) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(29) +
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(29) +
|
| base::TimeDelta::FromMinutes(59) +
|
| base::TimeDelta::FromSeconds(59));
|
|
|
| @@ -1911,7 +1995,7 @@
|
| // Verifies that when no automatic reboot policy is enabled, no reboot occurs
|
| // and no grace period is scheduled.
|
| TEST_P(AutomaticRebootManagerTest, StartNoPolicy) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
|
| + task_runner_->SetUptime(base::TimeDelta::FromDays(10));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -1932,7 +2016,7 @@
|
| // 24 hours of uptime.
|
| TEST_P(AutomaticRebootManagerTest, StartBeforeUptimeLimitGracePeriod) {
|
| SetUptimeLimit(base::TimeDelta::FromHours(24), false);
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -1956,7 +2040,7 @@
|
| // immediately because the grace period ended after 6 + 24 hours of uptime.
|
| TEST_P(AutomaticRebootManagerTest, StartAfterUptimeLimitGracePeriod) {
|
| SetUptimeLimit(base::TimeDelta::FromHours(6), false);
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
|
| + task_runner_->SetUptime(base::TimeDelta::FromDays(10));
|
|
|
| // Verify that a reboot is requested and unless a non-kiosk-app session is in
|
| // progress, the the device immediately reboots.
|
| @@ -1977,7 +2061,7 @@
|
| // end after 6 + 24 hours of uptime.
|
| TEST_P(AutomaticRebootManagerTest, StartInUptimeLimitGracePeriod) {
|
| SetUptimeLimit(base::TimeDelta::FromHours(6), false);
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
|
|
| // Verify that a reboot is requested but the device does not reboot
|
| // immediately.
|
| @@ -2003,7 +2087,7 @@
|
| TEST_P(AutomaticRebootManagerTest, StartAfterUpdateGracePeriod) {
|
| SetUpdateStatusNeedReboot();
|
| SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
|
| + task_runner_->SetUptime(base::TimeDelta::FromDays(10));
|
| SetRebootAfterUpdate(true, false);
|
|
|
| // Verify that a reboot is requested and unless a non-kiosk-app session is in
|
| @@ -2029,7 +2113,7 @@
|
| TEST_P(AutomaticRebootManagerTest, StartInUpdateGracePeriod) {
|
| SetUpdateStatusNeedReboot();
|
| SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
| SetRebootAfterUpdate(true, false);
|
|
|
| // Verify that a reboot is requested but the device does not reboot
|
| @@ -2057,7 +2141,7 @@
|
| TEST_P(AutomaticRebootManagerTest, StartBeforeUpdateGracePeriod) {
|
| SetUpdateStatusNeedReboot();
|
| SetUpdateRebootNeededUptime(base::TimeDelta::FromMinutes(10));
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromMinutes(20));
|
| + task_runner_->SetUptime(base::TimeDelta::FromMinutes(20));
|
| SetRebootAfterUpdate(true, false);
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| @@ -2084,7 +2168,7 @@
|
| TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicy) {
|
| SetUpdateStatusNeedReboot();
|
| SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
|
| + task_runner_->SetUptime(base::TimeDelta::FromDays(10));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -2108,7 +2192,7 @@
|
| // is started that will end 24 hours from now.
|
| TEST_P(AutomaticRebootManagerTest, StartUpdateTimeLost) {
|
| SetUpdateStatusNeedReboot();
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
|
| + task_runner_->SetUptime(base::TimeDelta::FromDays(10));
|
| SetRebootAfterUpdate(true, false);
|
|
|
| // Verify that a reboot is requested but the device does not reboot
|
| @@ -2122,7 +2206,7 @@
|
| // reboot became necessary.
|
| EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
|
| &update_reboot_needed_uptime_));
|
| - EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
|
| + EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
|
|
|
| // Verify that a grace period has started.
|
| VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
|
| @@ -2142,7 +2226,7 @@
|
| // is scheduled.
|
| TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicyTimeLost) {
|
| SetUpdateStatusNeedReboot();
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromDays(10));
|
| + task_runner_->SetUptime(base::TimeDelta::FromDays(10));
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| // immediately.
|
| @@ -2154,7 +2238,7 @@
|
| // reboot became necessary.
|
| EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
|
| &update_reboot_needed_uptime_));
|
| - EXPECT_EQ(uptime_provider()->uptime(), update_reboot_needed_uptime_);
|
| + EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
|
|
|
| // Verify that no grace period has started.
|
| VerifyNoGracePeriod();
|
| @@ -2169,7 +2253,7 @@
|
| // necessary. Further verifies that no reboot occurs and no grace period is
|
| // scheduled.
|
| TEST_P(AutomaticRebootManagerTest, StartNoUpdate) {
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
| SetRebootAfterUpdate(true, false);
|
|
|
| // Verify that no reboot is requested and the device does not reboot
|
| @@ -2200,7 +2284,7 @@
|
| SetUptimeLimit(base::TimeDelta::FromHours(6), false);
|
| SetUpdateStatusNeedReboot();
|
| SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(8));
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
| SetRebootAfterUpdate(true, false);
|
|
|
| // Verify that a reboot is requested but the device does not reboot
|
| @@ -2228,7 +2312,7 @@
|
| SetUptimeLimit(base::TimeDelta::FromHours(8), false);
|
| SetUpdateStatusNeedReboot();
|
| SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
|
| - uptime_provider()->SetUptime(base::TimeDelta::FromHours(12));
|
| + task_runner_->SetUptime(base::TimeDelta::FromHours(12));
|
| SetRebootAfterUpdate(true, false);
|
|
|
| // Verify that a reboot is requested but the device does not reboot
|
|
|