This source file includes following definitions.
- SaveUptimeToFile
- RunsTasksOnCurrentThread
- PostDelayedTask
- PostNonNestableDelayedTask
- SetUptimeFile
- SetUptime
- Uptime
- Now
- FastForwardBy
- FastForwardUntilNoTasksRemain
- RunUntilIdle
- NowTicks
- user_manager_enabler_
- SetUp
- TearDown
- SetUpdateRebootNeededUptime
- SetRebootAfterUpdate
- SetUptimeLimit
- NotifyUpdateRebootNeeded
- NotifyResumed
- NotifyTerminating
- FastForwardBy
- FastForwardUntilNoTasksRemain
- CreateAutomaticRebootManager
- ReadUpdateRebootNeededUptimeFromFile
- VerifyLoginScreenIdleTimerIsStopped
- VerifyNoGracePeriod
- VerifyGracePeriod
- VerifyTimerIsStopped
- VerifyTimerIsRunning
- VerifyLoginScreenIdleTimerIsRunning
- SetUpdateStatusNeedReboot
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
#include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
#include <string>
#include <utility>
#include "ash/shell.h"
#include "ash/test/test_shell_delegate.h"
#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#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/thread_task_runner_handle.h"
#include "base/threading/sequenced_worker_pool.h"
#include "base/time/tick_clock.h"
#include "base/values.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/mock_user_manager.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chromeos/chromeos_paths.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_dbus_thread_manager.h"
#include "chromeos/dbus/fake_power_manager_client.h"
#include "chromeos/dbus/fake_update_engine_client.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "content/public/test/test_browser_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/message_center/message_center.h"
using ::testing::ReturnPointee;
namespace chromeos {
namespace system {
namespace {
class MockTimeSingleThreadTaskRunner : public base::SingleThreadTaskRunner {
public:
MockTimeSingleThreadTaskRunner();
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);
const base::TimeDelta& Uptime() const;
const base::TimeTicks& Now() const;
void FastForwardBy(const base::TimeDelta& delta);
void FastForwardUntilNoTasksRemain();
void RunUntilIdle();
private:
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 MockTimeTickClock : public base::TickClock {
public:
explicit MockTimeTickClock(
scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner);
virtual ~MockTimeTickClock();
virtual base::TimeTicks NowTicks() OVERRIDE;
private:
scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_;
DISALLOW_COPY_AND_ASSIGN(MockTimeTickClock);
};
}
class AutomaticRebootManagerBasicTest : public testing::Test {
protected:
typedef base::OneShotTimer<AutomaticRebootManager> Timer;
AutomaticRebootManagerBasicTest();
virtual ~AutomaticRebootManagerBasicTest();
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
void SetUpdateRebootNeededUptime(const base::TimeDelta& uptime);
void SetRebootAfterUpdate(bool reboot_after_update, bool expect_reboot);
void SetUptimeLimit(const base::TimeDelta& limit, bool expect_reboot);
void NotifyUpdateRebootNeeded();
void NotifyResumed(bool expect_reboot);
void NotifyTerminating(bool expect_reboot);
void FastForwardBy(const base::TimeDelta& delta, bool expect_reboot);
void FastForwardUntilNoTasksRemain(bool expect_reboot);
void CreateAutomaticRebootManager(bool expect_reboot);
bool ReadUpdateRebootNeededUptimeFromFile(base::TimeDelta* uptime);
void VerifyLoginScreenIdleTimerIsStopped() const;
void VerifyNoGracePeriod() const;
void VerifyGracePeriod(const base::TimeDelta& start_uptime) const;
bool is_user_logged_in_;
bool is_logged_in_as_kiosk_app_;
base::TimeDelta uptime_processing_delay_;
base::TimeDelta update_reboot_needed_uptime_;
base::TimeDelta uptime_limit_;
scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_;
scoped_ptr<AutomaticRebootManager> automatic_reboot_manager_;
protected:
FakePowerManagerClient* power_manager_client_;
FakeUpdateEngineClient* update_engine_client_;
void SetUpdateStatusNeedReboot();
private:
void VerifyTimerIsStopped(const Timer* timer) const;
void VerifyTimerIsRunning(const Timer* timer,
const base::TimeDelta& delay) const;
void VerifyLoginScreenIdleTimerIsRunning() const;
base::ScopedTempDir temp_dir_;
base::FilePath update_reboot_needed_uptime_file_;
bool reboot_after_update_;
base::ThreadTaskRunnerHandle ui_thread_task_runner_handle_;
TestingPrefServiceSimple local_state_;
MockUserManager* mock_user_manager_;
ScopedUserManagerEnabler user_manager_enabler_;
};
enum AutomaticRebootManagerTestScenario {
AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN,
AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION,
AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION,
};
class AutomaticRebootManagerTest
: public AutomaticRebootManagerBasicTest,
public testing::WithParamInterface<AutomaticRebootManagerTestScenario> {
protected:
AutomaticRebootManagerTest();
virtual ~AutomaticRebootManagerTest();
};
void SaveUptimeToFile(const base::FilePath& path,
const base::TimeDelta& uptime) {
if (path.empty() || uptime == base::TimeDelta())
return;
const std::string uptime_seconds = base::DoubleToString(uptime.InSecondsF());
ASSERT_EQ(static_cast<int>(uptime_seconds.size()),
base::WriteFile(path, uptime_seconds.c_str(),
uptime_seconds.size()));
}
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();
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();
}
AutomaticRebootManagerBasicTest::AutomaticRebootManagerBasicTest()
: is_user_logged_in_(false),
is_logged_in_as_kiosk_app_(false),
task_runner_(new MockTimeSingleThreadTaskRunner),
power_manager_client_(NULL),
update_engine_client_(NULL),
reboot_after_update_(false),
ui_thread_task_runner_handle_(task_runner_),
mock_user_manager_(new MockUserManager),
user_manager_enabler_(mock_user_manager_) {
}
AutomaticRebootManagerBasicTest::~AutomaticRebootManagerBasicTest() {
}
void AutomaticRebootManagerBasicTest::SetUp() {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
const base::FilePath& temp_dir = temp_dir_.path();
const base::FilePath uptime_file = temp_dir.Append("uptime");
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");
ASSERT_FALSE(base::WriteFile(update_reboot_needed_uptime_file_, NULL, 0));
ASSERT_TRUE(PathService::Override(chromeos::FILE_UPTIME, uptime_file));
ASSERT_TRUE(PathService::Override(chromeos::FILE_UPDATE_REBOOT_NEEDED_UPTIME,
update_reboot_needed_uptime_file_));
TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
AutomaticRebootManager::RegisterPrefs(local_state_.registry());
FakeDBusThreadManager* dbus_manager = new FakeDBusThreadManager;
power_manager_client_ = new FakePowerManagerClient;
dbus_manager->SetPowerManagerClient(
scoped_ptr<PowerManagerClient>(power_manager_client_));
update_engine_client_ = new FakeUpdateEngineClient;
dbus_manager->SetUpdateEngineClient(
scoped_ptr<UpdateEngineClient>(update_engine_client_));
DBusThreadManager::InitializeForTesting(dbus_manager);
EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn())
.WillRepeatedly(ReturnPointee(&is_user_logged_in_));
EXPECT_CALL(*mock_user_manager_, IsLoggedInAsKioskApp())
.WillRepeatedly(ReturnPointee(&is_logged_in_as_kiosk_app_));
}
void AutomaticRebootManagerBasicTest::TearDown() {
automatic_reboot_manager_.reset();
task_runner_->RunUntilIdle();
DBusThreadManager::Shutdown();
TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
}
void AutomaticRebootManagerBasicTest::SetUpdateRebootNeededUptime(
const base::TimeDelta& uptime) {
update_reboot_needed_uptime_ = uptime;
SaveUptimeToFile(update_reboot_needed_uptime_file_, uptime);
}
void AutomaticRebootManagerBasicTest::SetRebootAfterUpdate(
bool reboot_after_update,
bool expect_reboot) {
reboot_after_update_ = reboot_after_update;
local_state_.SetManagedPref(
prefs::kRebootAfterUpdate,
base::Value::CreateBooleanValue(reboot_after_update));
task_runner_->RunUntilIdle();
EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->num_request_restart_calls());
}
void AutomaticRebootManagerBasicTest::SetUptimeLimit(
const base::TimeDelta& limit,
bool expect_reboot) {
uptime_limit_ = limit;
if (limit == base::TimeDelta()) {
local_state_.RemoveManagedPref(prefs::kUptimeLimit);
} else {
local_state_.SetManagedPref(
prefs::kUptimeLimit,
base::Value::CreateIntegerValue(limit.InSeconds()));
}
task_runner_->RunUntilIdle();
EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->num_request_restart_calls());
}
void AutomaticRebootManagerBasicTest::NotifyUpdateRebootNeeded() {
SetUpdateStatusNeedReboot();
automatic_reboot_manager_->UpdateStatusChanged(
update_engine_client_->GetLastStatus());
task_runner_->RunUntilIdle();
EXPECT_EQ(0, power_manager_client_->num_request_restart_calls());
}
void AutomaticRebootManagerBasicTest::NotifyResumed(bool expect_reboot) {
automatic_reboot_manager_->SystemResumed(base::TimeDelta::FromHours(1));
task_runner_->RunUntilIdle();
EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->num_request_restart_calls());
}
void AutomaticRebootManagerBasicTest::NotifyTerminating(bool expect_reboot) {
automatic_reboot_manager_->Observe(
chrome::NOTIFICATION_APP_TERMINATING,
content::Source<AutomaticRebootManagerBasicTest>(this),
content::NotificationService::NoDetails());
task_runner_->RunUntilIdle();
EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->num_request_restart_calls());
}
void AutomaticRebootManagerBasicTest::FastForwardBy(
const base::TimeDelta& delta,
bool expect_reboot) {
task_runner_->FastForwardBy(delta);
EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->num_request_restart_calls());
}
void AutomaticRebootManagerBasicTest::FastForwardUntilNoTasksRemain(
bool expect_reboot) {
task_runner_->FastForwardUntilNoTasksRemain();
EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->num_request_restart_calls());
}
void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager(
bool expect_reboot) {
automatic_reboot_manager_.reset(new AutomaticRebootManager(
scoped_ptr<base::TickClock>(new MockTimeTickClock(task_runner_))));
task_runner_->RunUntilIdle();
EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->num_request_restart_calls());
uptime_processing_delay_ =
base::TimeTicks() - automatic_reboot_manager_->boot_time_ -
task_runner_->Uptime();
EXPECT_GE(uptime_processing_delay_, base::TimeDelta());
EXPECT_LE(uptime_processing_delay_, base::TimeDelta::FromSeconds(1));
if (is_user_logged_in_ || expect_reboot)
VerifyLoginScreenIdleTimerIsStopped();
else
VerifyLoginScreenIdleTimerIsRunning();
}
bool AutomaticRebootManagerBasicTest::ReadUpdateRebootNeededUptimeFromFile(
base::TimeDelta* uptime) {
std::string contents;
if (!base::ReadFileToString(update_reboot_needed_uptime_file_, &contents)) {
return false;
}
double seconds;
if (!base::StringToDouble(contents.substr(0, contents.find(' ')), &seconds) ||
seconds < 0.0) {
return false;
}
*uptime = base::TimeDelta::FromMilliseconds(seconds * 1000.0);
return true;
}
void AutomaticRebootManagerBasicTest::
VerifyLoginScreenIdleTimerIsStopped() const {
VerifyTimerIsStopped(
automatic_reboot_manager_->login_screen_idle_timer_.get());
}
void AutomaticRebootManagerBasicTest::VerifyNoGracePeriod() const {
EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_);
VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get());
VerifyTimerIsStopped(automatic_reboot_manager_->grace_end_timer_.get());
}
void AutomaticRebootManagerBasicTest::VerifyGracePeriod(
const base::TimeDelta& start_uptime) const {
const base::TimeDelta start =
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_);
VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get());
VerifyTimerIsRunning(automatic_reboot_manager_->grace_end_timer_.get(),
end);
} else {
EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_);
VerifyTimerIsRunning(automatic_reboot_manager_->grace_start_timer_.get(),
start);
VerifyTimerIsRunning(automatic_reboot_manager_->grace_end_timer_.get(),
end);
}
}
void AutomaticRebootManagerBasicTest::VerifyTimerIsStopped(
const Timer* timer) const {
if (timer)
EXPECT_FALSE(timer->IsRunning());
}
void AutomaticRebootManagerBasicTest::VerifyTimerIsRunning(
const Timer* timer,
const base::TimeDelta& delay) const {
ASSERT_TRUE(timer);
EXPECT_TRUE(timer->IsRunning());
EXPECT_EQ(delay.ToInternalValue(),
timer->GetCurrentDelay().ToInternalValue());
}
void AutomaticRebootManagerBasicTest::
VerifyLoginScreenIdleTimerIsRunning() const {
VerifyTimerIsRunning(
automatic_reboot_manager_->login_screen_idle_timer_.get(),
base::TimeDelta::FromSeconds(60));
}
void AutomaticRebootManagerBasicTest::SetUpdateStatusNeedReboot() {
UpdateEngineClient::Status client_status;
client_status.status = UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT;
update_engine_client_->set_default_status(client_status);
}
AutomaticRebootManagerTest::AutomaticRebootManagerTest() {
switch (GetParam()) {
case AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN:
is_user_logged_in_ = false;
is_logged_in_as_kiosk_app_ = false;
break;
case AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION:
is_user_logged_in_ = true;
is_logged_in_as_kiosk_app_ = true;
break;
case AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION:
is_user_logged_in_ = true;
is_logged_in_as_kiosk_app_ = false;
break;
}
}
AutomaticRebootManagerTest::~AutomaticRebootManagerTest() {
}
TEST_F(AutomaticRebootManagerBasicTest, LoginStopsIdleTimer) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
CreateAutomaticRebootManager(false);
is_user_logged_in_ = true;
is_logged_in_as_kiosk_app_ = true;
automatic_reboot_manager_->Observe(
chrome::NOTIFICATION_LOGIN_USER_CHANGED,
content::Source<AutomaticRebootManagerBasicTest>(this),
content::NotificationService::NoDetails());
VerifyLoginScreenIdleTimerIsStopped();
FastForwardUntilNoTasksRemain(false);
}
TEST_F(AutomaticRebootManagerBasicTest, NonKioskLoginStopsIdleTimer) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
CreateAutomaticRebootManager(false);
is_user_logged_in_ = true;
automatic_reboot_manager_->Observe(
chrome::NOTIFICATION_LOGIN_USER_CHANGED,
content::Source<AutomaticRebootManagerBasicTest>(this),
content::NotificationService::NoDetails());
VerifyLoginScreenIdleTimerIsStopped();
FastForwardUntilNoTasksRemain(false);
}
TEST_F(AutomaticRebootManagerBasicTest, UserActivityResetsIdleTimer) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
VerifyGracePeriod(uptime_limit_);
for (int i = 0; i < 30; ++i) {
FastForwardBy(base::TimeDelta::FromSeconds(50), false);
automatic_reboot_manager_->OnUserActivity(NULL);
}
FastForwardBy(base::TimeDelta::FromSeconds(60), true);
}
TEST_F(AutomaticRebootManagerBasicTest, ResumeNoPolicy) {
is_user_logged_in_ = true;
is_logged_in_as_kiosk_app_ = true;
task_runner_->SetUptime(base::TimeDelta::FromDays(10));
CreateAutomaticRebootManager(false);
VerifyNoGracePeriod();
NotifyResumed(false);
FastForwardUntilNoTasksRemain(false);
}
TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAppNoPolicy) {
is_user_logged_in_ = true;
task_runner_->SetUptime(base::TimeDelta::FromDays(10));
CreateAutomaticRebootManager(false);
VerifyNoGracePeriod();
NotifyResumed(false);
FastForwardUntilNoTasksRemain(false);
}
TEST_F(AutomaticRebootManagerBasicTest, ResumeBeforeGracePeriod) {
is_user_logged_in_ = true;
is_logged_in_as_kiosk_app_ = true;
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(24), false);
VerifyGracePeriod(uptime_limit_);
NotifyResumed(false);
FastForwardUntilNoTasksRemain(true);
}
TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeBeforeGracePeriod) {
is_user_logged_in_ = true;
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(24), false);
VerifyGracePeriod(uptime_limit_);
NotifyResumed(false);
FastForwardUntilNoTasksRemain(false);
}
TEST_F(AutomaticRebootManagerBasicTest, ResumeInGracePeriod) {
is_user_logged_in_ = true;
is_logged_in_as_kiosk_app_ = true;
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
VerifyGracePeriod(uptime_limit_);
NotifyResumed(true);
}
TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeInGracePeriod) {
is_user_logged_in_ = true;
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
VerifyGracePeriod(uptime_limit_);
NotifyResumed(false);
FastForwardUntilNoTasksRemain(false);
}
TEST_F(AutomaticRebootManagerBasicTest, ResumeAfterGracePeriod) {
is_user_logged_in_ = true;
is_logged_in_as_kiosk_app_ = true;
task_runner_->SetUptime(base::TimeDelta::FromHours(29) +
base::TimeDelta::FromMinutes(30));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
VerifyGracePeriod(uptime_limit_);
NotifyResumed(true);
}
TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAfterGracePeriod) {
is_user_logged_in_ = true;
task_runner_->SetUptime(base::TimeDelta::FromHours(29) +
base::TimeDelta::FromMinutes(30));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
VerifyGracePeriod(uptime_limit_);
NotifyResumed(false);
FastForwardUntilNoTasksRemain(false);
}
TEST_P(AutomaticRebootManagerTest, TerminateNoPolicy) {
task_runner_->SetUptime(base::TimeDelta::FromDays(10));
CreateAutomaticRebootManager(false);
VerifyNoGracePeriod();
NotifyTerminating(false);
FastForwardUntilNoTasksRemain(false);
}
TEST_P(AutomaticRebootManagerTest, TerminateBeforeGracePeriod) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(24), false);
VerifyGracePeriod(uptime_limit_);
NotifyTerminating(false);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, TerminateInGracePeriod) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
VerifyGracePeriod(uptime_limit_);
NotifyTerminating(is_logged_in_as_kiosk_app_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, BeforeUptimeLimitGracePeriod) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
CreateAutomaticRebootManager(false);
VerifyNoGracePeriod();
SetUptimeLimit(base::TimeDelta::FromHours(24), false);
VerifyGracePeriod(uptime_limit_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, InUptimeLimitGracePeriod) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
CreateAutomaticRebootManager(false);
VerifyNoGracePeriod();
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
VerifyGracePeriod(uptime_limit_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, AfterUptimeLimitGracePeriod) {
task_runner_->SetUptime(base::TimeDelta::FromDays(10));
CreateAutomaticRebootManager(false);
VerifyNoGracePeriod();
SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, UptimeLimitOffBeforeGracePeriod) {
task_runner_->SetUptime(base::TimeDelta::FromHours(6));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(12), false);
VerifyGracePeriod(uptime_limit_);
FastForwardBy(base::TimeDelta::FromHours(1), false);
SetUptimeLimit(base::TimeDelta(), false);
VerifyNoGracePeriod();
FastForwardUntilNoTasksRemain(false);
}
TEST_P(AutomaticRebootManagerTest, UptimeLimitOffInGracePeriod) {
task_runner_->SetUptime(base::TimeDelta::FromHours(24));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(12), false);
VerifyGracePeriod(uptime_limit_);
FastForwardBy(base::TimeDelta::FromSeconds(20), false);
SetUptimeLimit(base::TimeDelta(), false);
VerifyNoGracePeriod();
FastForwardUntilNoTasksRemain(false);
}
TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitBeforeGracePeriod) {
task_runner_->SetUptime(base::TimeDelta::FromHours(6));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(12), false);
VerifyGracePeriod(uptime_limit_);
FastForwardBy(base::TimeDelta::FromSeconds(20), false);
SetUptimeLimit(base::TimeDelta::FromHours(24), false);
VerifyGracePeriod(uptime_limit_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitInGracePeriod) {
task_runner_->SetUptime(base::TimeDelta::FromHours(18));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(12), false);
VerifyGracePeriod(uptime_limit_);
FastForwardBy(base::TimeDelta::FromSeconds(20), false);
SetUptimeLimit(base::TimeDelta::FromHours(24), false);
VerifyGracePeriod(uptime_limit_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitBeforeToInGracePeriod) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(18), false);
VerifyGracePeriod(uptime_limit_);
FastForwardBy(base::TimeDelta::FromSeconds(20), false);
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
VerifyGracePeriod(uptime_limit_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToInGracePeriod) {
task_runner_->SetUptime(base::TimeDelta::FromHours(36));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(24), false);
VerifyGracePeriod(uptime_limit_);
FastForwardBy(base::TimeDelta::FromSeconds(20), false);
SetUptimeLimit(base::TimeDelta::FromHours(18), false);
VerifyGracePeriod(uptime_limit_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToAfterGracePeriod) {
task_runner_->SetUptime(base::TimeDelta::FromHours(36));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(24), false);
VerifyGracePeriod(uptime_limit_);
FastForwardBy(base::TimeDelta::FromSeconds(20), false);
SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, UpdateNoPolicy) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
CreateAutomaticRebootManager(false);
VerifyNoGracePeriod();
NotifyUpdateRebootNeeded();
EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
&update_reboot_needed_uptime_));
EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
VerifyNoGracePeriod();
FastForwardUntilNoTasksRemain(false);
}
TEST_P(AutomaticRebootManagerTest, Update) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(false);
VerifyNoGracePeriod();
NotifyUpdateRebootNeeded();
EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
&update_reboot_needed_uptime_));
EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, UpdateAfterUpdate) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(false);
VerifyNoGracePeriod();
NotifyUpdateRebootNeeded();
EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
&update_reboot_needed_uptime_));
EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
FastForwardBy(base::TimeDelta::FromSeconds(20), false);
NotifyUpdateRebootNeeded();
base::TimeDelta new_update_reboot_needed_uptime;
EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
&new_update_reboot_needed_uptime));
EXPECT_EQ(update_reboot_needed_uptime_, new_update_reboot_needed_uptime);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, UpdateBeforeMinimumUptime) {
task_runner_->SetUptime(base::TimeDelta::FromMinutes(10));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(false);
VerifyNoGracePeriod();
NotifyUpdateRebootNeeded();
EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
&update_reboot_needed_uptime_));
EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
VerifyGracePeriod(base::TimeDelta::FromHours(1));
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateInGracePeriod) {
task_runner_->SetUptime(base::TimeDelta::FromHours(6));
CreateAutomaticRebootManager(false);
NotifyUpdateRebootNeeded();
FastForwardBy(base::TimeDelta::FromHours(6), false);
automatic_reboot_manager_->OnUserActivity(NULL);
SetRebootAfterUpdate(true, false);
VerifyGracePeriod(base::TimeDelta::FromHours(6) + uptime_processing_delay_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateAfterGracePeriod) {
task_runner_->SetUptime(base::TimeDelta::FromHours(6));
CreateAutomaticRebootManager(false);
NotifyUpdateRebootNeeded();
FastForwardBy(base::TimeDelta::FromDays(10) - base::TimeDelta::FromHours(6),
false);
automatic_reboot_manager_->OnUserActivity(NULL);
SetRebootAfterUpdate(true, !is_user_logged_in_ || is_logged_in_as_kiosk_app_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, PolicyOffAfterUpdate) {
task_runner_->SetUptime(base::TimeDelta::FromHours(6));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(false);
NotifyUpdateRebootNeeded();
VerifyGracePeriod(task_runner_->Uptime() + uptime_processing_delay_);
FastForwardBy(base::TimeDelta::FromSeconds(20), false);
SetRebootAfterUpdate(false, false);
VerifyNoGracePeriod();
FastForwardUntilNoTasksRemain(false);
}
TEST_P(AutomaticRebootManagerTest, NoUptime) {
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
VerifyNoGracePeriod();
SetRebootAfterUpdate(true, false);
VerifyNoGracePeriod();
NotifyUpdateRebootNeeded();
EXPECT_FALSE(ReadUpdateRebootNeededUptimeFromFile(
&update_reboot_needed_uptime_));
VerifyNoGracePeriod();
FastForwardUntilNoTasksRemain(false);
}
TEST_P(AutomaticRebootManagerTest, UptimeLimitBeforeUpdate) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
VerifyGracePeriod(uptime_limit_);
FastForwardBy(base::TimeDelta::FromSeconds(20), false);
NotifyUpdateRebootNeeded();
EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
&update_reboot_needed_uptime_));
EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
VerifyGracePeriod(uptime_limit_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, UpdateBeforeUptimeLimit) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(24), false);
VerifyGracePeriod(uptime_limit_);
FastForwardBy(base::TimeDelta::FromSeconds(20), false);
NotifyUpdateRebootNeeded();
EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
&update_reboot_needed_uptime_));
EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, PolicyOffThenUptimeLimitOff) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(24), false);
VerifyGracePeriod(uptime_limit_);
NotifyUpdateRebootNeeded();
EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
&update_reboot_needed_uptime_));
EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
FastForwardBy(base::TimeDelta::FromSeconds(20), false);
SetRebootAfterUpdate(false, false);
VerifyGracePeriod(uptime_limit_);
SetUptimeLimit(base::TimeDelta(), false);
VerifyNoGracePeriod();
FastForwardUntilNoTasksRemain(false);
}
TEST_P(AutomaticRebootManagerTest, UptimeLimitOffThenPolicyOff) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(false);
NotifyUpdateRebootNeeded();
EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
&update_reboot_needed_uptime_));
EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
VerifyGracePeriod(uptime_limit_);
FastForwardBy(base::TimeDelta::FromSeconds(20), false);
SetUptimeLimit(base::TimeDelta(), false);
VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
SetRebootAfterUpdate(false, false);
VerifyNoGracePeriod();
FastForwardUntilNoTasksRemain(false);
}
TEST_P(AutomaticRebootManagerTest, GracePeriodEnd) {
task_runner_->SetUptime(base::TimeDelta::FromHours(29) +
base::TimeDelta::FromMinutes(59) +
base::TimeDelta::FromSeconds(59));
CreateAutomaticRebootManager(false);
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
VerifyGracePeriod(uptime_limit_);
FastForwardBy(base::TimeDelta::FromSeconds(1), !is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, StartNoPolicy) {
task_runner_->SetUptime(base::TimeDelta::FromDays(10));
CreateAutomaticRebootManager(false);
VerifyNoGracePeriod();
FastForwardUntilNoTasksRemain(false);
}
TEST_P(AutomaticRebootManagerTest, StartBeforeUptimeLimitGracePeriod) {
SetUptimeLimit(base::TimeDelta::FromHours(24), false);
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
CreateAutomaticRebootManager(false);
VerifyGracePeriod(uptime_limit_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, StartAfterUptimeLimitGracePeriod) {
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
task_runner_->SetUptime(base::TimeDelta::FromDays(10));
CreateAutomaticRebootManager(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, StartInUptimeLimitGracePeriod) {
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
CreateAutomaticRebootManager(false);
VerifyGracePeriod(uptime_limit_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, StartAfterUpdateGracePeriod) {
SetUpdateStatusNeedReboot();
SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
task_runner_->SetUptime(base::TimeDelta::FromDays(10));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, StartInUpdateGracePeriod) {
SetUpdateStatusNeedReboot();
SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(false);
VerifyGracePeriod(update_reboot_needed_uptime_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, StartBeforeUpdateGracePeriod) {
SetUpdateStatusNeedReboot();
SetUpdateRebootNeededUptime(base::TimeDelta::FromMinutes(10));
task_runner_->SetUptime(base::TimeDelta::FromMinutes(20));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(false);
VerifyGracePeriod(base::TimeDelta::FromHours(1));
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicy) {
SetUpdateStatusNeedReboot();
SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
task_runner_->SetUptime(base::TimeDelta::FromDays(10));
CreateAutomaticRebootManager(false);
VerifyNoGracePeriod();
FastForwardUntilNoTasksRemain(false);
}
TEST_P(AutomaticRebootManagerTest, StartUpdateTimeLost) {
SetUpdateStatusNeedReboot();
task_runner_->SetUptime(base::TimeDelta::FromDays(10));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(false);
EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
&update_reboot_needed_uptime_));
EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicyTimeLost) {
SetUpdateStatusNeedReboot();
task_runner_->SetUptime(base::TimeDelta::FromDays(10));
CreateAutomaticRebootManager(false);
EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
&update_reboot_needed_uptime_));
EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
VerifyNoGracePeriod();
FastForwardUntilNoTasksRemain(false);
}
TEST_P(AutomaticRebootManagerTest, StartNoUpdate) {
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(false);
EXPECT_FALSE(ReadUpdateRebootNeededUptimeFromFile(
&update_reboot_needed_uptime_));
VerifyNoGracePeriod();
FastForwardUntilNoTasksRemain(false);
}
TEST_P(AutomaticRebootManagerTest, StartUptimeLimitBeforeUpdate) {
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
SetUpdateStatusNeedReboot();
SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(8));
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(false);
VerifyGracePeriod(uptime_limit_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, StartUpdateBeforeUptimeLimit) {
SetUptimeLimit(base::TimeDelta::FromHours(8), false);
SetUpdateStatusNeedReboot();
SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
task_runner_->SetUptime(base::TimeDelta::FromHours(12));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(false);
VerifyGracePeriod(update_reboot_needed_uptime_);
FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
is_logged_in_as_kiosk_app_);
}
TEST_P(AutomaticRebootManagerTest, StartNoUptime) {
SetUptimeLimit(base::TimeDelta::FromHours(6), false);
SetUpdateStatusNeedReboot();
SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
SetRebootAfterUpdate(true, false);
CreateAutomaticRebootManager(false);
VerifyNoGracePeriod();
FastForwardUntilNoTasksRemain(false);
}
INSTANTIATE_TEST_CASE_P(
AutomaticRebootManagerTestInstance,
AutomaticRebootManagerTest,
::testing::Values(
AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN,
AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION,
AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION));
}
}