Home | History | Annotate | Download | only in system
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
      6 
      7 #include <string>
      8 #include <utility>
      9 
     10 #include "ash/shell.h"
     11 #include "ash/test/test_shell_delegate.h"
     12 #include "base/compiler_specific.h"
     13 #include "base/file_util.h"
     14 #include "base/files/file_path.h"
     15 #include "base/files/scoped_temp_dir.h"
     16 #include "base/memory/ref_counted.h"
     17 #include "base/message_loop/message_loop.h"
     18 #include "base/path_service.h"
     19 #include "base/prefs/pref_registry_simple.h"
     20 #include "base/prefs/testing_pref_service.h"
     21 #include "base/run_loop.h"
     22 #include "base/single_thread_task_runner.h"
     23 #include "base/strings/string_number_conversions.h"
     24 #include "base/test/simple_test_tick_clock.h"
     25 #include "base/thread_task_runner_handle.h"
     26 #include "base/threading/sequenced_worker_pool.h"
     27 #include "base/time/tick_clock.h"
     28 #include "base/values.h"
     29 #include "chrome/browser/chrome_notification_types.h"
     30 #include "chrome/browser/chromeos/login/mock_user_manager.h"
     31 #include "chrome/browser/chromeos/login/user_manager.h"
     32 #include "chrome/common/pref_names.h"
     33 #include "chrome/test/base/testing_browser_process.h"
     34 #include "chromeos/chromeos_paths.h"
     35 #include "chromeos/dbus/dbus_thread_manager.h"
     36 #include "chromeos/dbus/fake_power_manager_client.h"
     37 #include "chromeos/dbus/fake_update_engine_client.h"
     38 #include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.h"
     39 #include "content/public/browser/browser_thread.h"
     40 #include "content/public/browser/notification_details.h"
     41 #include "content/public/browser/notification_service.h"
     42 #include "content/public/browser/notification_source.h"
     43 #include "content/public/test/test_browser_thread.h"
     44 #include "testing/gmock/include/gmock/gmock.h"
     45 #include "testing/gtest/include/gtest/gtest.h"
     46 #include "ui/message_center/message_center.h"
     47 
     48 using ::testing::ReturnPointee;
     49 
     50 namespace chromeos {
     51 namespace system {
     52 
     53 namespace {
     54 
     55 // A SingleThreadTaskRunner that mocks the current time and allows it to be
     56 // fast-forwarded. The current time in ticks is returned by Now(). The
     57 // corresponding device uptime is written to |uptime_file_|, providing a mock
     58 // for /proc/uptime.
     59 class MockTimeSingleThreadTaskRunner : public base::SingleThreadTaskRunner {
     60  public:
     61   MockTimeSingleThreadTaskRunner();
     62 
     63   // base::SingleThreadTaskRunner:
     64   virtual bool RunsTasksOnCurrentThread() const OVERRIDE;
     65   virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
     66                                const base::Closure& task,
     67                                base::TimeDelta delay) OVERRIDE;
     68   virtual bool PostNonNestableDelayedTask(
     69       const tracked_objects::Location& from_here,
     70       const base::Closure& task,
     71       base::TimeDelta delay) OVERRIDE;
     72 
     73   void SetUptimeFile(const base::FilePath& uptime_file);
     74   void SetUptime(const base::TimeDelta& uptime);
     75 
     76   const base::TimeDelta& Uptime() const;
     77   const base::TimeTicks& Now() const;
     78 
     79   void FastForwardBy(const base::TimeDelta& delta);
     80   void FastForwardUntilNoTasksRemain();
     81   void RunUntilIdle();
     82 
     83  private:
     84   // Strict weak temporal ordering of tasks.
     85   class TemporalOrder {
     86    public:
     87     bool operator()(
     88         const std::pair<base::TimeTicks, base::Closure>& first_task,
     89         const std::pair<base::TimeTicks, base::Closure>& second_task) const;
     90   };
     91 
     92   virtual ~MockTimeSingleThreadTaskRunner();
     93 
     94   base::FilePath uptime_file_;
     95   base::TimeDelta uptime_;
     96   base::TimeTicks now_;
     97   std::priority_queue<std::pair<base::TimeTicks, base::Closure>,
     98                       std::vector<std::pair<base::TimeTicks, base::Closure> >,
     99                       TemporalOrder> tasks_;
    100 
    101   DISALLOW_COPY_AND_ASSIGN(MockTimeSingleThreadTaskRunner);
    102 };
    103 
    104 class MockTimeTickClock : public base::TickClock {
    105  public:
    106   explicit MockTimeTickClock(
    107       scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner);
    108   virtual ~MockTimeTickClock();
    109 
    110   // base::TickClock:
    111   virtual base::TimeTicks NowTicks() OVERRIDE;
    112 
    113  private:
    114   scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_;
    115 
    116   DISALLOW_COPY_AND_ASSIGN(MockTimeTickClock);
    117 };
    118 
    119 }  // namespace
    120 
    121 class AutomaticRebootManagerBasicTest : public testing::Test {
    122  protected:
    123   typedef base::OneShotTimer<AutomaticRebootManager> Timer;
    124 
    125   AutomaticRebootManagerBasicTest();
    126   virtual ~AutomaticRebootManagerBasicTest();
    127 
    128   // testing::Test:
    129   virtual void SetUp() OVERRIDE;
    130   virtual void TearDown() OVERRIDE;
    131 
    132   void SetUpdateRebootNeededUptime(const base::TimeDelta& uptime);
    133   void SetRebootAfterUpdate(bool reboot_after_update, bool expect_reboot);
    134   void SetUptimeLimit(const base::TimeDelta& limit, bool expect_reboot);
    135   void NotifyUpdateRebootNeeded();
    136   void NotifyResumed(bool expect_reboot);
    137   void NotifyTerminating(bool expect_reboot);
    138 
    139   void FastForwardBy(const base::TimeDelta& delta, bool expect_reboot);
    140   void FastForwardUntilNoTasksRemain(bool expect_reboot);
    141 
    142   void CreateAutomaticRebootManager(bool expect_reboot);
    143 
    144   bool ReadUpdateRebootNeededUptimeFromFile(base::TimeDelta* uptime);
    145   void VerifyLoginScreenIdleTimerIsStopped() const;
    146   void VerifyNoGracePeriod() const;
    147   void VerifyGracePeriod(const base::TimeDelta& start_uptime) const;
    148 
    149   bool is_user_logged_in_;
    150   bool is_logged_in_as_kiosk_app_;
    151 
    152   // The uptime is read in the blocking thread pool and then processed on the
    153   // UI thread. This causes the UI thread to start processing the uptime when it
    154   // has increased by a small offset already. The offset is calculated and
    155   // stored in |uptime_processing_delay_| so that tests can accurately determine
    156   // the uptime seen by the UI thread.
    157   base::TimeDelta uptime_processing_delay_;
    158   base::TimeDelta update_reboot_needed_uptime_;
    159   base::TimeDelta uptime_limit_;
    160 
    161   scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner_;
    162 
    163   scoped_ptr<AutomaticRebootManager> automatic_reboot_manager_;
    164 
    165  protected:
    166   FakePowerManagerClient* power_manager_client_;  // Not owned.
    167   FakeUpdateEngineClient* update_engine_client_;  // Not owned.
    168 
    169   // Sets the status of |update_engine_client_| to NEED_REBOOT for tests.
    170   void SetUpdateStatusNeedReboot();
    171 
    172  private:
    173   void VerifyTimerIsStopped(const Timer* timer) const;
    174   void VerifyTimerIsRunning(const Timer* timer,
    175                             const base::TimeDelta& delay) const;
    176   void VerifyLoginScreenIdleTimerIsRunning() const;
    177 
    178   base::ScopedTempDir temp_dir_;
    179   base::FilePath update_reboot_needed_uptime_file_;
    180 
    181   bool reboot_after_update_;
    182 
    183   base::ThreadTaskRunnerHandle ui_thread_task_runner_handle_;
    184 
    185   TestingPrefServiceSimple local_state_;
    186   MockUserManager* mock_user_manager_;  // Not owned.
    187   ScopedUserManagerEnabler user_manager_enabler_;
    188 };
    189 
    190 enum AutomaticRebootManagerTestScenario {
    191   AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN,
    192   AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION,
    193   AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION,
    194 };
    195 
    196 // This class runs each test case three times:
    197 // * once while the login screen is being shown
    198 // * once while a kiosk app session is in progress
    199 // * once while a non-kiosk-app session is in progress
    200 class AutomaticRebootManagerTest
    201     : public AutomaticRebootManagerBasicTest,
    202       public testing::WithParamInterface<AutomaticRebootManagerTestScenario> {
    203  protected:
    204   AutomaticRebootManagerTest();
    205   virtual ~AutomaticRebootManagerTest();
    206 };
    207 
    208 void SaveUptimeToFile(const base::FilePath& path,
    209                       const base::TimeDelta& uptime) {
    210   if (path.empty() || uptime == base::TimeDelta())
    211     return;
    212 
    213   const std::string uptime_seconds = base::DoubleToString(uptime.InSecondsF());
    214   ASSERT_EQ(static_cast<int>(uptime_seconds.size()),
    215             file_util::WriteFile(path,
    216                                  uptime_seconds.c_str(),
    217                                  uptime_seconds.size()));
    218 }
    219 
    220 MockTimeSingleThreadTaskRunner::MockTimeSingleThreadTaskRunner() {
    221 }
    222 
    223 bool MockTimeSingleThreadTaskRunner::RunsTasksOnCurrentThread() const {
    224   return true;
    225 }
    226 
    227 bool MockTimeSingleThreadTaskRunner::PostDelayedTask(
    228     const tracked_objects::Location& from_here,
    229     const base::Closure& task,
    230     base::TimeDelta delay) {
    231   tasks_.push(std::pair<base::TimeTicks, base::Closure>(now_ + delay, task));
    232   return true;
    233 }
    234 
    235 bool MockTimeSingleThreadTaskRunner::PostNonNestableDelayedTask(
    236     const tracked_objects::Location& from_here,
    237     const base::Closure& task,
    238     base::TimeDelta delay) {
    239   NOTREACHED();
    240   return false;
    241 }
    242 
    243 void MockTimeSingleThreadTaskRunner::SetUptimeFile(
    244     const base::FilePath& uptime_file) {
    245   uptime_file_ = uptime_file;
    246   SaveUptimeToFile(uptime_file_, uptime_);
    247 }
    248 
    249 void MockTimeSingleThreadTaskRunner::SetUptime(const base::TimeDelta& uptime) {
    250   uptime_ = uptime;
    251   SaveUptimeToFile(uptime_file_, uptime_);
    252 }
    253 
    254 const base::TimeDelta& MockTimeSingleThreadTaskRunner::Uptime() const {
    255   return uptime_;
    256 }
    257 
    258 const base::TimeTicks& MockTimeSingleThreadTaskRunner::Now() const {
    259   return now_;
    260 }
    261 
    262 void MockTimeSingleThreadTaskRunner::FastForwardBy(
    263     const base::TimeDelta& delta) {
    264   const base::TimeTicks latest = now_ + delta;
    265   base::SequencedWorkerPool* blocking_pool =
    266       content::BrowserThread::GetBlockingPool();
    267   blocking_pool->FlushForTesting();
    268   while (!tasks_.empty() && tasks_.top().first <= latest) {
    269     uptime_ += tasks_.top().first - now_;
    270     SaveUptimeToFile(uptime_file_, uptime_);
    271     now_ = tasks_.top().first;
    272     base::Closure task = tasks_.top().second;
    273     tasks_.pop();
    274     task.Run();
    275     blocking_pool->FlushForTesting();
    276   }
    277   uptime_ += latest - now_;
    278   SaveUptimeToFile(uptime_file_, uptime_);
    279   now_ = latest;
    280 }
    281 
    282 void MockTimeSingleThreadTaskRunner::FastForwardUntilNoTasksRemain() {
    283   base::SequencedWorkerPool* blocking_pool =
    284       content::BrowserThread::GetBlockingPool();
    285   blocking_pool->FlushForTesting();
    286   while (!tasks_.empty()) {
    287     uptime_ += tasks_.top().first - now_;
    288     SaveUptimeToFile(uptime_file_, uptime_);
    289     now_ = tasks_.top().first;
    290     base::Closure task = tasks_.top().second;
    291     tasks_.pop();
    292     task.Run();
    293     blocking_pool->FlushForTesting();
    294   }
    295 }
    296 
    297 void MockTimeSingleThreadTaskRunner::RunUntilIdle() {
    298   base::SequencedWorkerPool* blocking_pool =
    299       content::BrowserThread::GetBlockingPool();
    300   blocking_pool->FlushForTesting();
    301   while (!tasks_.empty() && tasks_.top().first <= now_) {
    302     base::Closure task = tasks_.top().second;
    303     tasks_.pop();
    304     task.Run();
    305     blocking_pool->FlushForTesting();
    306   }
    307 }
    308 
    309 bool MockTimeSingleThreadTaskRunner::TemporalOrder::operator()(
    310     const std::pair<base::TimeTicks, base::Closure>& first_task,
    311     const std::pair<base::TimeTicks, base::Closure>& second_task) const {
    312   return first_task.first >= second_task.first;
    313 }
    314 
    315 MockTimeSingleThreadTaskRunner::~MockTimeSingleThreadTaskRunner() {
    316 }
    317 
    318 MockTimeTickClock::MockTimeTickClock(
    319     scoped_refptr<MockTimeSingleThreadTaskRunner> task_runner)
    320     : task_runner_(task_runner) {
    321 }
    322 
    323 MockTimeTickClock::~MockTimeTickClock() {
    324 }
    325 
    326 base::TimeTicks MockTimeTickClock::NowTicks() {
    327   return task_runner_->Now();
    328 }
    329 
    330 AutomaticRebootManagerBasicTest::AutomaticRebootManagerBasicTest()
    331     : is_user_logged_in_(false),
    332       is_logged_in_as_kiosk_app_(false),
    333       task_runner_(new MockTimeSingleThreadTaskRunner),
    334       power_manager_client_(NULL),
    335       update_engine_client_(NULL),
    336       reboot_after_update_(false),
    337       ui_thread_task_runner_handle_(task_runner_),
    338       mock_user_manager_(new MockUserManager),
    339       user_manager_enabler_(mock_user_manager_) {
    340 }
    341 
    342 AutomaticRebootManagerBasicTest::~AutomaticRebootManagerBasicTest() {
    343 }
    344 
    345 void AutomaticRebootManagerBasicTest::SetUp() {
    346   ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
    347   const base::FilePath& temp_dir = temp_dir_.path();
    348   const base::FilePath uptime_file = temp_dir.Append("uptime");
    349   task_runner_->SetUptimeFile(uptime_file);
    350   ASSERT_FALSE(file_util::WriteFile(uptime_file, NULL, 0));
    351   update_reboot_needed_uptime_file_ =
    352       temp_dir.Append("update_reboot_needed_uptime");
    353   ASSERT_FALSE(file_util::WriteFile(
    354       update_reboot_needed_uptime_file_, NULL, 0));
    355   ASSERT_TRUE(PathService::Override(chromeos::FILE_UPTIME, uptime_file));
    356   ASSERT_TRUE(PathService::Override(chromeos::FILE_UPDATE_REBOOT_NEEDED_UPTIME,
    357                                     update_reboot_needed_uptime_file_));
    358 
    359   TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
    360   AutomaticRebootManager::RegisterPrefs(local_state_.registry());
    361   MockDBusThreadManagerWithoutGMock* dbus_manager =
    362       new MockDBusThreadManagerWithoutGMock;
    363   DBusThreadManager::InitializeForTesting(dbus_manager);
    364   power_manager_client_ = dbus_manager->fake_power_manager_client();
    365   update_engine_client_ = dbus_manager->fake_update_engine_client();
    366 
    367   EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn())
    368      .WillRepeatedly(ReturnPointee(&is_user_logged_in_));
    369   EXPECT_CALL(*mock_user_manager_, IsLoggedInAsKioskApp())
    370      .WillRepeatedly(ReturnPointee(&is_logged_in_as_kiosk_app_));
    371 }
    372 
    373 void AutomaticRebootManagerBasicTest::TearDown() {
    374   // Let the AutomaticRebootManager, if any, unregister itself as an observer of
    375   // several subsystems.
    376   automatic_reboot_manager_.reset();
    377   task_runner_->RunUntilIdle();
    378 
    379   DBusThreadManager::Shutdown();
    380   TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
    381 }
    382 
    383 void AutomaticRebootManagerBasicTest::SetUpdateRebootNeededUptime(
    384     const base::TimeDelta& uptime) {
    385   update_reboot_needed_uptime_ = uptime;
    386   SaveUptimeToFile(update_reboot_needed_uptime_file_, uptime);
    387 }
    388 
    389 
    390 void AutomaticRebootManagerBasicTest::SetRebootAfterUpdate(
    391     bool reboot_after_update,
    392     bool expect_reboot) {
    393   reboot_after_update_ = reboot_after_update;
    394   local_state_.SetManagedPref(
    395       prefs::kRebootAfterUpdate,
    396       base::Value::CreateBooleanValue(reboot_after_update));
    397   task_runner_->RunUntilIdle();
    398   EXPECT_EQ(expect_reboot ? 1 : 0,
    399             power_manager_client_->request_restart_call_count());
    400 }
    401 
    402 void AutomaticRebootManagerBasicTest::SetUptimeLimit(
    403     const base::TimeDelta& limit,
    404     bool expect_reboot) {
    405   uptime_limit_ = limit;
    406   if (limit == base::TimeDelta()) {
    407     local_state_.RemoveManagedPref(prefs::kUptimeLimit);
    408   } else {
    409     local_state_.SetManagedPref(
    410         prefs::kUptimeLimit,
    411         base::Value::CreateIntegerValue(limit.InSeconds()));
    412   }
    413   task_runner_->RunUntilIdle();
    414   EXPECT_EQ(expect_reboot ? 1 : 0,
    415             power_manager_client_->request_restart_call_count());
    416 }
    417 
    418 void AutomaticRebootManagerBasicTest::NotifyUpdateRebootNeeded() {
    419   SetUpdateStatusNeedReboot();
    420   automatic_reboot_manager_->UpdateStatusChanged(
    421       update_engine_client_->GetLastStatus());
    422   task_runner_->RunUntilIdle();
    423   EXPECT_EQ(0, power_manager_client_->request_restart_call_count());
    424 }
    425 
    426 void AutomaticRebootManagerBasicTest::NotifyResumed(bool expect_reboot) {
    427   automatic_reboot_manager_->SystemResumed(base::TimeDelta::FromHours(1));
    428   task_runner_->RunUntilIdle();
    429   EXPECT_EQ(expect_reboot ? 1 : 0,
    430             power_manager_client_->request_restart_call_count());
    431 }
    432 
    433 void AutomaticRebootManagerBasicTest::NotifyTerminating(bool expect_reboot) {
    434   automatic_reboot_manager_->Observe(
    435       chrome::NOTIFICATION_APP_TERMINATING,
    436       content::Source<AutomaticRebootManagerBasicTest>(this),
    437       content::NotificationService::NoDetails());
    438   task_runner_->RunUntilIdle();
    439   EXPECT_EQ(expect_reboot ? 1 : 0,
    440             power_manager_client_->request_restart_call_count());
    441 }
    442 
    443 void AutomaticRebootManagerBasicTest::FastForwardBy(
    444     const base::TimeDelta& delta,
    445     bool expect_reboot) {
    446   task_runner_->FastForwardBy(delta);
    447   EXPECT_EQ(expect_reboot ? 1 : 0,
    448             power_manager_client_->request_restart_call_count());
    449 }
    450 
    451 void AutomaticRebootManagerBasicTest::FastForwardUntilNoTasksRemain(
    452     bool expect_reboot) {
    453   task_runner_->FastForwardUntilNoTasksRemain();
    454   EXPECT_EQ(expect_reboot ? 1 : 0,
    455             power_manager_client_->request_restart_call_count());
    456 }
    457 
    458 void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager(
    459     bool expect_reboot) {
    460   automatic_reboot_manager_.reset(new AutomaticRebootManager(
    461       scoped_ptr<base::TickClock>(new MockTimeTickClock(task_runner_))));
    462   task_runner_->RunUntilIdle();
    463   EXPECT_EQ(expect_reboot ? 1 : 0,
    464             power_manager_client_->request_restart_call_count());
    465 
    466   uptime_processing_delay_ =
    467       base::TimeTicks() - automatic_reboot_manager_->boot_time_ -
    468       task_runner_->Uptime();
    469   EXPECT_GE(uptime_processing_delay_, base::TimeDelta());
    470   EXPECT_LE(uptime_processing_delay_, base::TimeDelta::FromSeconds(1));
    471 
    472   if (is_user_logged_in_ || expect_reboot)
    473     VerifyLoginScreenIdleTimerIsStopped();
    474   else
    475     VerifyLoginScreenIdleTimerIsRunning();
    476 }
    477 
    478 bool AutomaticRebootManagerBasicTest::ReadUpdateRebootNeededUptimeFromFile(
    479     base::TimeDelta* uptime) {
    480   std::string contents;
    481   if (!file_util::ReadFileToString(update_reboot_needed_uptime_file_,
    482                                    &contents)) {
    483     return false;
    484   }
    485   double seconds;
    486   if (!base::StringToDouble(contents.substr(0, contents.find(' ')), &seconds) ||
    487       seconds < 0.0) {
    488     return false;
    489   }
    490   *uptime = base::TimeDelta::FromMilliseconds(seconds * 1000.0);
    491   return true;
    492 }
    493 
    494 void AutomaticRebootManagerBasicTest::
    495     VerifyLoginScreenIdleTimerIsStopped() const {
    496   VerifyTimerIsStopped(
    497       automatic_reboot_manager_->login_screen_idle_timer_.get());
    498 }
    499 
    500 void AutomaticRebootManagerBasicTest::VerifyNoGracePeriod() const {
    501   EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_);
    502   VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get());
    503   VerifyTimerIsStopped(automatic_reboot_manager_->grace_end_timer_.get());
    504 }
    505 
    506 void AutomaticRebootManagerBasicTest::VerifyGracePeriod(
    507     const base::TimeDelta& start_uptime) const {
    508   const base::TimeDelta start =
    509       start_uptime - task_runner_->Uptime() - uptime_processing_delay_;
    510   const base::TimeDelta end = start + base::TimeDelta::FromHours(24);
    511   if (start <= base::TimeDelta()) {
    512     EXPECT_TRUE(automatic_reboot_manager_->reboot_requested_);
    513     VerifyTimerIsStopped(automatic_reboot_manager_->grace_start_timer_.get());
    514     VerifyTimerIsRunning(automatic_reboot_manager_->grace_end_timer_.get(),
    515                          end);
    516   } else {
    517     EXPECT_FALSE(automatic_reboot_manager_->reboot_requested_);
    518     VerifyTimerIsRunning(automatic_reboot_manager_->grace_start_timer_.get(),
    519                          start);
    520     VerifyTimerIsRunning(automatic_reboot_manager_->grace_end_timer_.get(),
    521                          end);
    522   }
    523 }
    524 
    525 void AutomaticRebootManagerBasicTest::VerifyTimerIsStopped(
    526     const Timer* timer) const {
    527   if (timer)
    528     EXPECT_FALSE(timer->IsRunning());
    529 }
    530 
    531 void AutomaticRebootManagerBasicTest::VerifyTimerIsRunning(
    532     const Timer* timer,
    533     const base::TimeDelta& delay) const {
    534   ASSERT_TRUE(timer);
    535   EXPECT_TRUE(timer->IsRunning());
    536   EXPECT_EQ(delay.ToInternalValue(),
    537             timer->GetCurrentDelay().ToInternalValue());
    538 }
    539 
    540 void AutomaticRebootManagerBasicTest::
    541     VerifyLoginScreenIdleTimerIsRunning() const {
    542   VerifyTimerIsRunning(
    543       automatic_reboot_manager_->login_screen_idle_timer_.get(),
    544       base::TimeDelta::FromSeconds(60));
    545 }
    546 
    547 void AutomaticRebootManagerBasicTest::SetUpdateStatusNeedReboot() {
    548   UpdateEngineClient::Status client_status;
    549   client_status.status = UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT;
    550   update_engine_client_->set_default_status(client_status);
    551 }
    552 
    553 AutomaticRebootManagerTest::AutomaticRebootManagerTest() {
    554   switch (GetParam()) {
    555     case AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN:
    556       is_user_logged_in_ = false;
    557       is_logged_in_as_kiosk_app_ = false;
    558       break;
    559     case AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION:
    560       is_user_logged_in_ = true;
    561       is_logged_in_as_kiosk_app_ = true;
    562       break;
    563     case AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION:
    564       is_user_logged_in_ = true;
    565       is_logged_in_as_kiosk_app_ = false;
    566       break;
    567   }
    568 }
    569 
    570 AutomaticRebootManagerTest::~AutomaticRebootManagerTest() {
    571 }
    572 
    573 // Chrome is showing the login screen. The current uptime is 12 hours.
    574 // Verifies that the idle timer is running. Further verifies that when a kiosk
    575 // app session begins, the idle timer is stopped.
    576 TEST_F(AutomaticRebootManagerBasicTest, LoginStopsIdleTimer) {
    577   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
    578 
    579   // Verify that the device does not reboot immediately and the login screen
    580   // idle timer is started.
    581   CreateAutomaticRebootManager(false);
    582 
    583   // Notify that a kiosk app session has been started.
    584   is_user_logged_in_ = true;
    585   is_logged_in_as_kiosk_app_ = true;
    586   automatic_reboot_manager_->Observe(
    587       chrome::NOTIFICATION_LOGIN_USER_CHANGED,
    588       content::Source<AutomaticRebootManagerBasicTest>(this),
    589       content::NotificationService::NoDetails());
    590 
    591   // Verify that the login screen idle timer is stopped.
    592   VerifyLoginScreenIdleTimerIsStopped();
    593 
    594   // Verify that the device does not reboot eventually.
    595   FastForwardUntilNoTasksRemain(false);
    596 }
    597 
    598 // Chrome is showing the login screen. The current uptime is 12 hours.
    599 // Verifies that the idle timer is running. Further verifies that when a
    600 // non-kiosk-app session begins, the idle timer is stopped.
    601 TEST_F(AutomaticRebootManagerBasicTest, NonKioskLoginStopsIdleTimer) {
    602   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
    603 
    604   // Verify that the device does not reboot immediately and the login screen
    605   // idle timer is started.
    606   CreateAutomaticRebootManager(false);
    607 
    608   // Notify that a non-kiosk-app session has been started.
    609   is_user_logged_in_ = true;
    610   automatic_reboot_manager_->Observe(
    611       chrome::NOTIFICATION_LOGIN_USER_CHANGED,
    612       content::Source<AutomaticRebootManagerBasicTest>(this),
    613       content::NotificationService::NoDetails());
    614 
    615   // Verify that the login screen idle timer is stopped.
    616   VerifyLoginScreenIdleTimerIsStopped();
    617 
    618   // Verify that the device does not reboot eventually.
    619   FastForwardUntilNoTasksRemain(false);
    620 }
    621 
    622 // Chrome is showing the login screen. The uptime limit is 6 hours. The current
    623 // uptime is 12 hours.
    624 // Verifies that user activity prevents the device from rebooting. Further
    625 // verifies that when user activity ceases, the devices reboots.
    626 TEST_F(AutomaticRebootManagerBasicTest, UserActivityResetsIdleTimer) {
    627   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
    628 
    629   // Verify that the device does not reboot immediately and the login screen
    630   // idle timer is started.
    631   CreateAutomaticRebootManager(false);
    632 
    633   // Set the uptime limit. Verify that the device does not reboot immediately.
    634   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
    635 
    636   // Verify that a grace period has started.
    637   VerifyGracePeriod(uptime_limit_);
    638 
    639   // Fast forward the uptime by 25 minutes while simulating user activity every
    640   // 50 seconds.
    641   for (int i = 0; i < 30; ++i) {
    642     // Fast forward uptime by 50 seconds. Verify that the device does not reboot
    643     // immediately.
    644     FastForwardBy(base::TimeDelta::FromSeconds(50), false);
    645 
    646     // Simulate user activity.
    647     automatic_reboot_manager_->OnUserActivity(NULL);
    648   }
    649 
    650   // Fast forward the uptime by 60 seconds without simulating user activity.
    651   // Verify that the device reboots immediately.
    652   FastForwardBy(base::TimeDelta::FromSeconds(60), true);
    653 }
    654 
    655 // Chrome is running a kiosk app session. The current uptime is 10 days.
    656 // Verifies that when the device is suspended and then resumes, it does not
    657 // immediately reboot.
    658 TEST_F(AutomaticRebootManagerBasicTest, ResumeNoPolicy) {
    659   is_user_logged_in_ = true;
    660   is_logged_in_as_kiosk_app_ = true;
    661   task_runner_->SetUptime(base::TimeDelta::FromDays(10));
    662 
    663   // Verify that the device does not reboot immediately.
    664   CreateAutomaticRebootManager(false);
    665 
    666   // Verify that no grace period has started.
    667   VerifyNoGracePeriod();
    668 
    669   // Notify that the device has resumed from 1 hour of sleep. Verify that the
    670   // device does not reboot immediately.
    671   NotifyResumed(false);
    672 
    673   // Verify that the device does not reboot eventually.
    674   FastForwardUntilNoTasksRemain(false);
    675 }
    676 
    677 // Chrome is running a non-kiosk-app session. The current uptime is 10 days.
    678 // Verifies that when the device is suspended and then resumes, it does not
    679 // immediately reboot.
    680 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAppNoPolicy) {
    681   is_user_logged_in_ = true;
    682   task_runner_->SetUptime(base::TimeDelta::FromDays(10));
    683 
    684   // Verify that the device does not reboot immediately.
    685   CreateAutomaticRebootManager(false);
    686 
    687   // Verify that no grace period has started.
    688   VerifyNoGracePeriod();
    689 
    690   // Notify that the device has resumed from 1 hour of sleep. Verify that the
    691   // device does not reboot immediately.
    692   NotifyResumed(false);
    693 
    694   // Verify that the device does not reboot eventually.
    695   FastForwardUntilNoTasksRemain(false);
    696 }
    697 
    698 // Chrome is running a kiosk app session. The uptime limit is 24 hours. The
    699 // current uptime is 12 hours.
    700 // Verifies that when the device is suspended and then resumes, it does not
    701 // immediately reboot.
    702 TEST_F(AutomaticRebootManagerBasicTest, ResumeBeforeGracePeriod) {
    703   is_user_logged_in_ = true;
    704   is_logged_in_as_kiosk_app_ = true;
    705   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
    706 
    707   // Verify that the device does not reboot immediately.
    708   CreateAutomaticRebootManager(false);
    709 
    710   // Set the uptime limit. Verify that the device does not reboot immediately.
    711   SetUptimeLimit(base::TimeDelta::FromHours(24), false);
    712 
    713   // Verify that a grace period has been scheduled to start in the future.
    714   VerifyGracePeriod(uptime_limit_);
    715 
    716   // Notify that the device has resumed from 1 hour of sleep. Verify that the
    717   // device does not reboot immediately.
    718   NotifyResumed(false);
    719 
    720   // Verify that the device eventually reboots.
    721   FastForwardUntilNoTasksRemain(true);
    722 }
    723 
    724 // Chrome is running a non-kiosk-app session. The uptime limit is 24 hours. The
    725 // current uptime is 12 hours.
    726 // Verifies that when the device is suspended and then resumes, it does not
    727 // immediately reboot.
    728 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeBeforeGracePeriod) {
    729   is_user_logged_in_ = true;
    730   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
    731 
    732   // Verify that the device does not reboot immediately.
    733   CreateAutomaticRebootManager(false);
    734 
    735   // Set the uptime limit. Verify that the device does not reboot immediately.
    736   SetUptimeLimit(base::TimeDelta::FromHours(24), false);
    737 
    738   // Verify that a grace period has been scheduled to start in the future.
    739   VerifyGracePeriod(uptime_limit_);
    740 
    741   // Notify that the device has resumed from 1 hour of sleep. Verify that the
    742   // device does not reboot immediately.
    743   NotifyResumed(false);
    744 
    745   // Verify that the device does not reboot eventually.
    746   FastForwardUntilNoTasksRemain(false);
    747 }
    748 
    749 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The
    750 // current uptime is 12 hours.
    751 // Verifies that when the device is suspended and then resumes, it immediately
    752 // reboots.
    753 TEST_F(AutomaticRebootManagerBasicTest, ResumeInGracePeriod) {
    754   is_user_logged_in_ = true;
    755   is_logged_in_as_kiosk_app_ = true;
    756   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
    757 
    758   // Verify that the device does not reboot immediately.
    759   CreateAutomaticRebootManager(false);
    760 
    761   // Set the uptime limit. Verify that the device does not reboot immediately.
    762   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
    763 
    764   // Verify that a grace period has started.
    765   VerifyGracePeriod(uptime_limit_);
    766 
    767   // Notify that the device has resumed from 1 hour of sleep. Verify that the
    768   // device reboots immediately.
    769   NotifyResumed(true);
    770 }
    771 
    772 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The
    773 // current uptime is 12 hours.
    774 // Verifies that when the device is suspended and then resumes, it does not
    775 // immediately reboot.
    776 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeInGracePeriod) {
    777   is_user_logged_in_ = true;
    778   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
    779 
    780   // Verify that the device does not reboot immediately.
    781   CreateAutomaticRebootManager(false);
    782 
    783   // Set the uptime limit. Verify that the device does not reboot immediately.
    784   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
    785 
    786   // Verify that a grace period has started.
    787   VerifyGracePeriod(uptime_limit_);
    788 
    789   // Notify that the device has resumed from 1 hour of sleep. Verify that the
    790   // device does not reboot immediately.
    791   NotifyResumed(false);
    792 
    793   // Verify that the device does not reboot eventually.
    794   FastForwardUntilNoTasksRemain(false);
    795 }
    796 
    797 // Chrome is running a kiosk app session. The uptime limit is 6 hours. The
    798 // current uptime is 29 hours 30 minutes.
    799 // Verifies that when the device is suspended and then resumes, it immediately
    800 // reboots.
    801 TEST_F(AutomaticRebootManagerBasicTest, ResumeAfterGracePeriod) {
    802   is_user_logged_in_ = true;
    803   is_logged_in_as_kiosk_app_ = true;
    804   task_runner_->SetUptime(base::TimeDelta::FromHours(29) +
    805                           base::TimeDelta::FromMinutes(30));
    806 
    807   // Verify that the device does not reboot immediately.
    808   CreateAutomaticRebootManager(false);
    809 
    810   // Set the uptime limit. Verify that the device does not reboot immediately.
    811   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
    812 
    813   // Verify that a grace period has started.
    814   VerifyGracePeriod(uptime_limit_);
    815 
    816   // Notify that the device has resumed from 1 hour of sleep. Verify that the
    817   // device reboots immediately.
    818   NotifyResumed(true);
    819 }
    820 
    821 // Chrome is running a non-kiosk-app session. The uptime limit is 6 hours. The
    822 // current uptime is 29 hours 30 minutes.
    823 // Verifies that when the device is suspended and then resumes, it does not
    824 // immediately reboot.
    825 TEST_F(AutomaticRebootManagerBasicTest, NonKioskResumeAfterGracePeriod) {
    826   is_user_logged_in_ = true;
    827   task_runner_->SetUptime(base::TimeDelta::FromHours(29) +
    828                           base::TimeDelta::FromMinutes(30));
    829 
    830   // Verify that the device does not reboot immediately.
    831   CreateAutomaticRebootManager(false);
    832 
    833   // Set the uptime limit. Verify that the device does not reboot immediately.
    834   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
    835 
    836   // Verify that a grace period has started.
    837   VerifyGracePeriod(uptime_limit_);
    838 
    839   // Notify that the device has resumed from 1 hour of sleep. Verify that the
    840   // device does not reboot immediately.
    841   NotifyResumed(false);
    842 
    843   // Verify that the device does not reboot eventually.
    844   FastForwardUntilNoTasksRemain(false);
    845 }
    846 
    847 // Chrome is running. The current uptime is 10 days.
    848 // Verifies that when the browser terminates, the device does not immediately
    849 // reboot.
    850 TEST_P(AutomaticRebootManagerTest, TerminateNoPolicy) {
    851   task_runner_->SetUptime(base::TimeDelta::FromDays(10));
    852 
    853   // Verify that the device does not reboot immediately.
    854   CreateAutomaticRebootManager(false);
    855 
    856   // Verify that no grace period has started.
    857   VerifyNoGracePeriod();
    858 
    859   // Notify that the browser is terminating. Verify that the device does not
    860   // reboot immediately.
    861   NotifyTerminating(false);
    862 
    863   // Verify that the device does not reboot eventually.
    864   FastForwardUntilNoTasksRemain(false);
    865 }
    866 
    867 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is
    868 // 12 hours.
    869 // Verifies that when the browser terminates, it does not immediately reboot.
    870 TEST_P(AutomaticRebootManagerTest, TerminateBeforeGracePeriod) {
    871   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
    872 
    873   // Verify that the device does not reboot immediately.
    874   CreateAutomaticRebootManager(false);
    875 
    876   // Set the uptime limit. Verify that the device does not reboot immediately.
    877   SetUptimeLimit(base::TimeDelta::FromHours(24), false);
    878 
    879   // Verify that a grace period has been scheduled to start in the future.
    880   VerifyGracePeriod(uptime_limit_);
    881 
    882   // Notify that the browser is terminating. Verify that the device does not
    883   // reboot immediately.
    884   NotifyTerminating(false);
    885 
    886   // Verify that unless a non-kiosk-app session is in progress, the device
    887   // eventually reboots.
    888   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
    889                                 is_logged_in_as_kiosk_app_);
    890 }
    891 
    892 // Chrome is running. The uptime limit is set to 6 hours. The current uptime is
    893 // 12 hours.
    894 // Verifies that when the browser terminates, the device immediately reboots if
    895 // a kiosk app session is in progress.
    896 TEST_P(AutomaticRebootManagerTest, TerminateInGracePeriod) {
    897   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
    898 
    899   // Verify that the device does not reboot immediately.
    900   CreateAutomaticRebootManager(false);
    901 
    902   // Set the uptime limit. Verify that the device does not reboot immediately.
    903   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
    904 
    905   // Verify that a grace period has started.
    906   VerifyGracePeriod(uptime_limit_);
    907 
    908   // Notify that the browser is terminating. Verify that the device immediately
    909   // reboots if a kiosk app session is in progress.
    910   NotifyTerminating(is_logged_in_as_kiosk_app_);
    911 
    912   // Verify that if a non-kiosk-app session is in progress, the device does not
    913   // reboot eventually.
    914   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
    915                                 is_logged_in_as_kiosk_app_);
    916 }
    917 
    918 // Chrome is running. The current uptime is 12 hours.
    919 // Verifies that when the uptime limit is set to 24 hours, no reboot occurs and
    920 // a grace period is scheduled to begin after 24 hours of uptime.
    921 TEST_P(AutomaticRebootManagerTest, BeforeUptimeLimitGracePeriod) {
    922   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
    923 
    924   // Verify that the device does not reboot immediately.
    925   CreateAutomaticRebootManager(false);
    926 
    927   // Verify that no grace period has started.
    928   VerifyNoGracePeriod();
    929 
    930   // Set the uptime limit. Verify that the device does not reboot immediately.
    931   SetUptimeLimit(base::TimeDelta::FromHours(24), false);
    932 
    933   // Verify that a grace period has been scheduled to start in the future.
    934   VerifyGracePeriod(uptime_limit_);
    935 
    936   // Verify that unless a non-kiosk-app session is in progress, the device
    937   // eventually reboots.
    938   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
    939                                 is_logged_in_as_kiosk_app_);
    940 }
    941 
    942 // Chrome is running. The current uptime is 12 hours.
    943 // Verifies that when the uptime limit is set to 6 hours, a reboot is requested
    944 // and a grace period is started that will end after 6 + 24 hours of uptime.
    945 TEST_P(AutomaticRebootManagerTest, InUptimeLimitGracePeriod) {
    946   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
    947 
    948   // Verify that the device does not reboot immediately.
    949   CreateAutomaticRebootManager(false);
    950 
    951   // Verify that no grace period has started.
    952   VerifyNoGracePeriod();
    953 
    954   // Set the uptime limit. Verify that the device does not reboot immediately.
    955   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
    956 
    957   // Verify that a grace period has started.
    958   VerifyGracePeriod(uptime_limit_);
    959 
    960   // Verify that unless a non-kiosk-app session is in progress, the device
    961   // eventually reboots.
    962   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
    963                                 is_logged_in_as_kiosk_app_);
    964 }
    965 
    966 // Chrome is running. The current uptime is 10 days.
    967 // Verifies that when the uptime limit is set to 6 hours, the device reboots
    968 // immediately if no non-kiosk-app-session is in progress because the grace
    969 // period ended after 6 + 24 hours of uptime.
    970 TEST_P(AutomaticRebootManagerTest, AfterUptimeLimitGracePeriod) {
    971   task_runner_->SetUptime(base::TimeDelta::FromDays(10));
    972 
    973   // Verify that the device does not reboot immediately.
    974   CreateAutomaticRebootManager(false);
    975 
    976   // Verify that no grace period has started.
    977   VerifyNoGracePeriod();
    978 
    979   // Set the uptime limit. Verify that unless a non-kiosk-app session is in
    980   // progress, the the device immediately reboots.
    981   SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ ||
    982                                                 is_logged_in_as_kiosk_app_);
    983 
    984   // Verify that if a non-kiosk-app session is in progress, the device does not
    985   // reboot eventually.
    986   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
    987                                 is_logged_in_as_kiosk_app_);
    988 }
    989 
    990 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
    991 // 6 hours.
    992 // Verifies that when the uptime limit is removed, the grace period is removed.
    993 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffBeforeGracePeriod) {
    994   task_runner_->SetUptime(base::TimeDelta::FromHours(6));
    995 
    996   // Verify that the device does not reboot immediately.
    997   CreateAutomaticRebootManager(false);
    998 
    999   // Set the uptime limit. Verify that the device does not reboot immediately.
   1000   SetUptimeLimit(base::TimeDelta::FromHours(12), false);
   1001 
   1002   // Verify that a grace period has been scheduled to start in the future.
   1003   VerifyGracePeriod(uptime_limit_);
   1004 
   1005   // Fast forward the uptime by 1 hour. Verify that the device does not reboot
   1006   // immediately.
   1007   FastForwardBy(base::TimeDelta::FromHours(1), false);
   1008 
   1009   // Remove the uptime limit. Verify that the device does not reboot
   1010   // immediately.
   1011   SetUptimeLimit(base::TimeDelta(), false);
   1012 
   1013   // Verify that the grace period has been removed.
   1014   VerifyNoGracePeriod();
   1015 
   1016   // Verify that the device does not reboot eventually.
   1017   FastForwardUntilNoTasksRemain(false);
   1018 }
   1019 
   1020 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
   1021 // 24 hours.
   1022 // Verifies that when the uptime limit is removed, the grace period is removed.
   1023 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffInGracePeriod) {
   1024   task_runner_->SetUptime(base::TimeDelta::FromHours(24));
   1025 
   1026   // Verify that the device does not reboot immediately.
   1027   CreateAutomaticRebootManager(false);
   1028 
   1029   // Set the uptime limit. Verify that the device does not reboot immediately.
   1030   SetUptimeLimit(base::TimeDelta::FromHours(12), false);
   1031 
   1032   // Verify that a grace period has started.
   1033   VerifyGracePeriod(uptime_limit_);
   1034 
   1035   // Fast forward the uptime by 20 seconds. Verify that the device does not
   1036   // reboot immediately.
   1037   FastForwardBy(base::TimeDelta::FromSeconds(20), false);
   1038 
   1039   // Remove the uptime limit. Verify that the device does not reboot
   1040   // immediately.
   1041   SetUptimeLimit(base::TimeDelta(), false);
   1042 
   1043   // Verify that the grace period has been removed.
   1044   VerifyNoGracePeriod();
   1045 
   1046   // Verify that the device does not reboot eventually.
   1047   FastForwardUntilNoTasksRemain(false);
   1048 }
   1049 
   1050 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
   1051 // 6 hours.
   1052 // Verifies that when the uptime limit is extended to 24 hours, the grace period
   1053 // is rescheduled to start further in the future.
   1054 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitBeforeGracePeriod) {
   1055   task_runner_->SetUptime(base::TimeDelta::FromHours(6));
   1056 
   1057   // Verify that the device does not reboot immediately.
   1058   CreateAutomaticRebootManager(false);
   1059 
   1060   // Set the uptime limit. Verify that the device does not reboot immediately.
   1061   SetUptimeLimit(base::TimeDelta::FromHours(12), false);
   1062 
   1063   // Verify that a grace period has been scheduled to start in the future.
   1064   VerifyGracePeriod(uptime_limit_);
   1065 
   1066   // Fast forward the uptime by 20 seconds. Verify that the device does not
   1067   // reboot immediately.
   1068   FastForwardBy(base::TimeDelta::FromSeconds(20), false);
   1069 
   1070   // Extend the uptime limit. Verify that the device does not reboot
   1071   // immediately.
   1072   SetUptimeLimit(base::TimeDelta::FromHours(24), false);
   1073 
   1074   // Verify that the grace period has been rescheduled to start further in the
   1075   // future.
   1076   VerifyGracePeriod(uptime_limit_);
   1077 
   1078   // Verify that unless a non-kiosk-app session is in progress, the device
   1079   // eventually reboots.
   1080   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1081                                 is_logged_in_as_kiosk_app_);
   1082 }
   1083 
   1084 // Chrome is running. The uptime limit is set to 12 hours. The current uptime is
   1085 // 18 hours.
   1086 // Verifies that when the uptime limit is extended to 24 hours, the grace period
   1087 // is rescheduled to start in the future.
   1088 TEST_P(AutomaticRebootManagerTest, ExtendUptimeLimitInGracePeriod) {
   1089   task_runner_->SetUptime(base::TimeDelta::FromHours(18));
   1090 
   1091   // Verify that the device does not reboot immediately.
   1092   CreateAutomaticRebootManager(false);
   1093 
   1094   // Set the uptime limit. Verify that the device does not reboot immediately.
   1095   SetUptimeLimit(base::TimeDelta::FromHours(12), false);
   1096 
   1097   // Verify that a grace period has started.
   1098   VerifyGracePeriod(uptime_limit_);
   1099 
   1100   // Fast forward the uptime by 20 seconds. Verify that the device does not
   1101   // reboot immediately.
   1102   FastForwardBy(base::TimeDelta::FromSeconds(20), false);
   1103 
   1104   // Extend the uptime limit. Verify that the device does not reboot
   1105   // immediately.
   1106   SetUptimeLimit(base::TimeDelta::FromHours(24), false);
   1107 
   1108   // Verify that the grace period has been rescheduled to start in the future.
   1109   VerifyGracePeriod(uptime_limit_);
   1110 
   1111   // Verify that unless a non-kiosk-app session is in progress, the device
   1112   // eventually reboots.
   1113   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1114                                 is_logged_in_as_kiosk_app_);
   1115 }
   1116 
   1117 // Chrome is running. The uptime limit is set to 18 hours. The current uptime is
   1118 // 12 hours.
   1119 // Verifies that when the uptime limit is shortened to 6 hours, the grace period
   1120 // is rescheduled to have already started.
   1121 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitBeforeToInGracePeriod) {
   1122   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
   1123 
   1124   // Verify that the device does not reboot immediately.
   1125   CreateAutomaticRebootManager(false);
   1126 
   1127   // Set the uptime limit. Verify that the device does not reboot immediately.
   1128   SetUptimeLimit(base::TimeDelta::FromHours(18), false);
   1129 
   1130   // Verify that a grace period has been scheduled to start in the future.
   1131   VerifyGracePeriod(uptime_limit_);
   1132 
   1133   // Fast forward the uptime by 20 seconds. Verify that the device does not
   1134   // reboot immediately.
   1135   FastForwardBy(base::TimeDelta::FromSeconds(20), false);
   1136 
   1137   // Shorten the uptime limit. Verify that the device does not reboot
   1138   // immediately.
   1139   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
   1140 
   1141   // Verify that the grace period has been rescheduled and has started already.
   1142   VerifyGracePeriod(uptime_limit_);
   1143 
   1144   // Verify that unless a non-kiosk-app session is in progress, the device
   1145   // eventually reboots.
   1146   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1147                                 is_logged_in_as_kiosk_app_);
   1148 }
   1149 
   1150 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is
   1151 // 36 hours.
   1152 // Verifies that when the uptime limit is shortened to 18 hours, the grace
   1153 // period is rescheduled to have started earlier.
   1154 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToInGracePeriod) {
   1155   task_runner_->SetUptime(base::TimeDelta::FromHours(36));
   1156 
   1157   // Verify that the device does not reboot immediately.
   1158   CreateAutomaticRebootManager(false);
   1159 
   1160   // Set the uptime limit. Verify that the device does not reboot immediately.
   1161   SetUptimeLimit(base::TimeDelta::FromHours(24), false);
   1162 
   1163   // Verify that a grace period has started.
   1164   VerifyGracePeriod(uptime_limit_);
   1165 
   1166   // Fast forward the uptime by 20 seconds. Verify that the device does not
   1167   // reboot immediately.
   1168   FastForwardBy(base::TimeDelta::FromSeconds(20), false);
   1169 
   1170   // Shorten the uptime limit. Verify that the device does not reboot
   1171   // immediately.
   1172   SetUptimeLimit(base::TimeDelta::FromHours(18), false);
   1173 
   1174   // Verify that the grace period has been rescheduled to have started earlier.
   1175   VerifyGracePeriod(uptime_limit_);
   1176 
   1177   // Verify that unless a non-kiosk-app session is in progress, the device
   1178   // eventually reboots.
   1179   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1180                                 is_logged_in_as_kiosk_app_);
   1181 }
   1182 
   1183 // Chrome is running. The uptime limit is set to 24 hours. The current uptime is
   1184 // 36 hours.
   1185 // Verifies that when the uptime limit is shortened to 6 hours, the device
   1186 // reboots immediately if no non-kiosk-app session is in progress because the
   1187 // grace period ended after 6 + 24 hours of uptime.
   1188 TEST_P(AutomaticRebootManagerTest, ShortenUptimeLimitInToAfterGracePeriod) {
   1189   task_runner_->SetUptime(base::TimeDelta::FromHours(36));
   1190 
   1191   // Verify that the device does not reboot immediately.
   1192   CreateAutomaticRebootManager(false);
   1193 
   1194   // Set the uptime limit. Verify that the device does not reboot immediately.
   1195   SetUptimeLimit(base::TimeDelta::FromHours(24), false);
   1196 
   1197   // Verify that a grace period has started.
   1198   VerifyGracePeriod(uptime_limit_);
   1199 
   1200   // Fast forward the uptime by 20 seconds. Verify that the device does not
   1201   // reboot immediately.
   1202   FastForwardBy(base::TimeDelta::FromSeconds(20), false);
   1203 
   1204   // Shorten the uptime limit. Verify that unless a non-kiosk-app session is in
   1205   // progress, the the device immediately reboots.
   1206   SetUptimeLimit(base::TimeDelta::FromHours(6), !is_user_logged_in_ ||
   1207                                                 is_logged_in_as_kiosk_app_);
   1208 
   1209   // Verify that if a non-kiosk-app session is in progress, the device does not
   1210   // reboot eventually.
   1211   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1212                                 is_logged_in_as_kiosk_app_);
   1213 }
   1214 
   1215 // Chrome is running. The current uptime is 12 hours.
   1216 // Verifies that when an update is applied, the current uptime is persisted as
   1217 // the time at which a reboot became necessary. Further verifies that when the
   1218 // policy to automatically reboot after an update is not enabled, no reboot
   1219 // occurs and no grace period is scheduled.
   1220 TEST_P(AutomaticRebootManagerTest, UpdateNoPolicy) {
   1221   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
   1222 
   1223   // Verify that the device does not reboot immediately.
   1224   CreateAutomaticRebootManager(false);
   1225 
   1226   // Verify that no grace period has started.
   1227   VerifyNoGracePeriod();
   1228 
   1229   // Notify that an update has been applied and a reboot is necessary. Verify
   1230   // that the device does not reboot immediately.
   1231   NotifyUpdateRebootNeeded();
   1232 
   1233   // Verify that the current uptime has been persisted as the time at which a
   1234   // reboot became necessary.
   1235   EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
   1236       &update_reboot_needed_uptime_));
   1237   EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
   1238 
   1239   // Verify that no grace period has started.
   1240   VerifyNoGracePeriod();
   1241 
   1242   // Verify that the device does not reboot eventually.
   1243   FastForwardUntilNoTasksRemain(false);
   1244 }
   1245 
   1246 // Chrome is running. The current uptime is 12 hours.
   1247 // Verifies that when an update is applied, the current uptime is persisted as
   1248 // the time at which a reboot became necessary. Further verifies that when the
   1249 // policy to automatically reboot after an update is enabled, a reboot is
   1250 // requested and a grace period is started that will end 24 hours from now.
   1251 TEST_P(AutomaticRebootManagerTest, Update) {
   1252   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
   1253   SetRebootAfterUpdate(true, false);
   1254 
   1255   // Verify that the device does not reboot immediately.
   1256   CreateAutomaticRebootManager(false);
   1257 
   1258   // Verify that no grace period has started.
   1259   VerifyNoGracePeriod();
   1260 
   1261   // Notify that an update has been applied and a reboot is necessary. Verify
   1262   // that the device does not reboot immediately.
   1263   NotifyUpdateRebootNeeded();
   1264 
   1265   // Verify that the current uptime has been persisted as the time at which a
   1266   // reboot became necessary.
   1267   EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
   1268       &update_reboot_needed_uptime_));
   1269   EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
   1270 
   1271   // Verify that a grace period has started.
   1272   VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
   1273 
   1274   // Verify that unless a non-kiosk-app session is in progress, the device
   1275   // eventually reboots.
   1276   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1277                                 is_logged_in_as_kiosk_app_);
   1278 }
   1279 
   1280 // Chrome is running. The current uptime is 12 hours.
   1281 // Verifies that when Chrome is notified twice that an update has been applied,
   1282 // the second notification is ignored and the uptime at which it occured does
   1283 // not get persisted as the time at which an update became necessary.
   1284 TEST_P(AutomaticRebootManagerTest, UpdateAfterUpdate) {
   1285   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
   1286   SetRebootAfterUpdate(true, false);
   1287 
   1288   // Verify that the device does not reboot immediately.
   1289   CreateAutomaticRebootManager(false);
   1290 
   1291   // Verify that no grace period has started.
   1292   VerifyNoGracePeriod();
   1293 
   1294   // Notify that an update has been applied and a reboot is necessary. Verify
   1295   // that the device does not reboot immediately.
   1296   NotifyUpdateRebootNeeded();
   1297 
   1298   // Verify that the current uptime has been persisted as the time at which a
   1299   // reboot became necessary.
   1300   EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
   1301       &update_reboot_needed_uptime_));
   1302   EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
   1303 
   1304   // Verify that a grace period has started.
   1305   VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
   1306 
   1307   // Fast forward the uptime by 20 seconds. Verify that the device does not
   1308   // reboot immediately.
   1309   FastForwardBy(base::TimeDelta::FromSeconds(20), false);
   1310 
   1311   // Notify that an update has been applied and a reboot is necessary. Verify
   1312   // that the device does not reboot immediately.
   1313   NotifyUpdateRebootNeeded();
   1314 
   1315   // Verify that the previously persisted time at which a reboot became
   1316   // necessary has not been overwritten.
   1317   base::TimeDelta new_update_reboot_needed_uptime;
   1318   EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
   1319       &new_update_reboot_needed_uptime));
   1320   EXPECT_EQ(update_reboot_needed_uptime_, new_update_reboot_needed_uptime);
   1321 
   1322   // Verify that unless a non-kiosk-app session is in progress, the device
   1323   // eventually reboots.
   1324   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1325                                 is_logged_in_as_kiosk_app_);
   1326 }
   1327 
   1328 // Chrome is running. The current uptime is 10 minutes.
   1329 // Verifies that when the policy to automatically reboot after an update is
   1330 // enabled, no reboot occurs a grace period is scheduled to begin after the
   1331 // minimum of 1 hour of uptime. Further verifies that when an update is applied,
   1332 // the current uptime is persisted as the time at which a reboot became
   1333 // necessary.
   1334 TEST_P(AutomaticRebootManagerTest, UpdateBeforeMinimumUptime) {
   1335   task_runner_->SetUptime(base::TimeDelta::FromMinutes(10));
   1336   SetRebootAfterUpdate(true, false);
   1337 
   1338   // Verify that the device does not reboot immediately.
   1339   CreateAutomaticRebootManager(false);
   1340 
   1341   // Verify that no grace period has started.
   1342   VerifyNoGracePeriod();
   1343 
   1344   // Notify that an update has been applied and a reboot is necessary. Verify
   1345   // that the device does not reboot immediately.
   1346   NotifyUpdateRebootNeeded();
   1347 
   1348   // Verify that the current uptime has been persisted as the time at which a
   1349   // reboot became necessary.
   1350   EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
   1351       &update_reboot_needed_uptime_));
   1352   EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
   1353 
   1354   // Verify that a grace period has been scheduled to begin in the future.
   1355   VerifyGracePeriod(base::TimeDelta::FromHours(1));
   1356 
   1357   // Verify that unless a non-kiosk-app session is in progress, the device
   1358   // eventually reboots.
   1359   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1360                                 is_logged_in_as_kiosk_app_);
   1361 }
   1362 
   1363 // Chrome is running. An update was applied and a reboot became necessary to
   1364 // complete the update process after 6 hours of uptime. The current uptime is
   1365 // 12 hours.
   1366 // Verifies that when the policy to automatically reboot after an update is
   1367 // enabled, a reboot is requested and a grace period is started that will end
   1368 // after 6 + 24 hours of uptime.
   1369 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateInGracePeriod) {
   1370   task_runner_->SetUptime(base::TimeDelta::FromHours(6));
   1371 
   1372   // Verify that the device does not reboot immediately.
   1373   CreateAutomaticRebootManager(false);
   1374 
   1375   // Notify that an update has been applied and a reboot is necessary. Verify
   1376   // that the device does not reboot immediately.
   1377   NotifyUpdateRebootNeeded();
   1378 
   1379   // Fast forward the uptime to 12 hours. Verify that the device does not reboot
   1380   // immediately.
   1381   FastForwardBy(base::TimeDelta::FromHours(6), false);
   1382 
   1383   // Simulate user activity.
   1384   automatic_reboot_manager_->OnUserActivity(NULL);
   1385 
   1386   // Enable automatic reboot after an update has been applied. Verify that the
   1387   // device does not reboot immediately.
   1388   SetRebootAfterUpdate(true, false);
   1389 
   1390   // Verify that a grace period has started.
   1391   VerifyGracePeriod(base::TimeDelta::FromHours(6) + uptime_processing_delay_);
   1392 
   1393   // Verify that unless a non-kiosk-app session is in progress, the device
   1394   // eventually reboots.
   1395   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1396                                 is_logged_in_as_kiosk_app_);
   1397 }
   1398 
   1399 // Chrome is running. An update was applied and a reboot became necessary to
   1400 // complete the update process after 6 hours of uptime. The current uptime is
   1401 // 10 days.
   1402 // Verifies that when the policy to automatically reboot after an update is
   1403 // enabled, the device reboots immediately if no non-kiosk-app session is in
   1404 // progress because the grace period ended after 6 + 24 hours of uptime.
   1405 TEST_P(AutomaticRebootManagerTest, PolicyAfterUpdateAfterGracePeriod) {
   1406   task_runner_->SetUptime(base::TimeDelta::FromHours(6));
   1407 
   1408   // Verify that the device does not reboot immediately.
   1409   CreateAutomaticRebootManager(false);
   1410 
   1411   // Notify that an update has been applied and a reboot is necessary. Verify
   1412   // that the device does not reboot immediately.
   1413   NotifyUpdateRebootNeeded();
   1414 
   1415   // Fast forward the uptime to 12 hours. Verify that the device does not reboot
   1416   // immediately.
   1417   FastForwardBy(base::TimeDelta::FromDays(10) - base::TimeDelta::FromHours(6),
   1418                 false);
   1419 
   1420   // Simulate user activity.
   1421   automatic_reboot_manager_->OnUserActivity(NULL);
   1422 
   1423   // Enable automatic rebooting after an update has been applied. Verify that
   1424   // unless a non-kiosk-app session is in progress, the the device immediately
   1425   // reboots.
   1426   SetRebootAfterUpdate(true, !is_user_logged_in_ || is_logged_in_as_kiosk_app_);
   1427 
   1428   // Verify that if a non-kiosk-app session is in progress, the device does not
   1429   // reboot eventually.
   1430   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1431                                 is_logged_in_as_kiosk_app_);
   1432 }
   1433 
   1434 // Chrome is running. An update was applied and a reboot became necessary to
   1435 // complete the update process after 6 hours of uptime. The policy to
   1436 // automatically reboot after an update is enabled. The current uptime is
   1437 // 6 hours 20 seconds.
   1438 // Verifies that when the policy to automatically reboot after an update is
   1439 // disabled, the reboot request and grace period are removed.
   1440 TEST_P(AutomaticRebootManagerTest, PolicyOffAfterUpdate) {
   1441   task_runner_->SetUptime(base::TimeDelta::FromHours(6));
   1442   SetRebootAfterUpdate(true, false);
   1443 
   1444   // Verify that the device does not reboot immediately.
   1445   CreateAutomaticRebootManager(false);
   1446 
   1447   // Notify that an update has been applied and a reboot is necessary. Verify
   1448   // that the device does not reboot immediately.
   1449   NotifyUpdateRebootNeeded();
   1450 
   1451   // Verify that a grace period has started.
   1452   VerifyGracePeriod(task_runner_->Uptime() + uptime_processing_delay_);
   1453 
   1454   // Fast forward the uptime by 20 seconds. Verify that the device does not
   1455   // reboot immediately.
   1456   FastForwardBy(base::TimeDelta::FromSeconds(20), false);
   1457 
   1458   // Disable automatic rebooting after an update has been applied. Verify that
   1459   // the device does not reboot immediately.
   1460   SetRebootAfterUpdate(false, false);
   1461 
   1462   // Verify that the grace period has been removed.
   1463   VerifyNoGracePeriod();
   1464 
   1465   // Verify that the device does not reboot eventually.
   1466   FastForwardUntilNoTasksRemain(false);
   1467 }
   1468 
   1469 // Chrome is running. The current uptime is not available.
   1470 // Verifies that even if an uptime limit is set, the policy to automatically
   1471 // reboot after an update is enabled and an update has been applied, no reboot
   1472 // occurs and no grace period is scheduled. Further verifies that no time is
   1473 // persisted as the time at which a reboot became necessary.
   1474 TEST_P(AutomaticRebootManagerTest, NoUptime) {
   1475   // Verify that the device does not reboot immediately.
   1476   CreateAutomaticRebootManager(false);
   1477 
   1478   // Set the uptime limit. Verify that the device does not reboot immediately.
   1479   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
   1480 
   1481   // Verify that no grace period has started.
   1482   VerifyNoGracePeriod();
   1483 
   1484   // Enable automatic rebooting after an update has been applied. Verify that
   1485   // the device does not reboot immediately.
   1486   SetRebootAfterUpdate(true, false);
   1487 
   1488   // Verify that no grace period has started.
   1489   VerifyNoGracePeriod();
   1490 
   1491   // Notify that an update has been applied and a reboot is necessary. Verify
   1492   // that the device does not reboot immediately.
   1493   NotifyUpdateRebootNeeded();
   1494 
   1495   // Verify that no time is persisted as the time at which a reboot became
   1496   // necessary.
   1497   EXPECT_FALSE(ReadUpdateRebootNeededUptimeFromFile(
   1498       &update_reboot_needed_uptime_));
   1499 
   1500   // Verify that no grace period has started.
   1501   VerifyNoGracePeriod();
   1502 
   1503   // Verify that the device does not reboot eventually.
   1504   FastForwardUntilNoTasksRemain(false);
   1505 }
   1506 
   1507 // Chrome is running. The policy to automatically reboot after an update is
   1508 // enabled. The current uptime is 12 hours.
   1509 // Verifies that when an uptime limit of 6 hours is set, the availability of an
   1510 // update does not cause the grace period to be rescheduled. Further verifies
   1511 // that the current uptime is persisted as the time at which a reboot became
   1512 // necessary.
   1513 TEST_P(AutomaticRebootManagerTest, UptimeLimitBeforeUpdate) {
   1514   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
   1515   SetRebootAfterUpdate(true, false);
   1516 
   1517   // Verify that the device does not reboot immediately.
   1518   CreateAutomaticRebootManager(false);
   1519 
   1520   // Set the uptime limit. Verify that the device does not reboot immediately.
   1521   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
   1522 
   1523   // Verify that a grace period has been scheduled to start in the future.
   1524   VerifyGracePeriod(uptime_limit_);
   1525 
   1526   // Fast forward the uptime by 20 seconds. Verify that the device does not
   1527   // reboot immediately.
   1528   FastForwardBy(base::TimeDelta::FromSeconds(20), false);
   1529 
   1530   // Notify that an update has been applied and a reboot is necessary. Verify
   1531   // that the device does not reboot immediately.
   1532   NotifyUpdateRebootNeeded();
   1533 
   1534   // Verify that the current uptime has been persisted as the time at which a
   1535   // reboot became necessary.
   1536   EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
   1537       &update_reboot_needed_uptime_));
   1538   EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
   1539 
   1540   // Verify that the grace period has not been rescheduled.
   1541   VerifyGracePeriod(uptime_limit_);
   1542 
   1543   // Verify that unless a non-kiosk-app session is in progress, the device
   1544   // eventually reboots.
   1545   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1546                                 is_logged_in_as_kiosk_app_);
   1547 }
   1548 
   1549 // Chrome is running. The policy to automatically reboot after an update is
   1550 // enabled. The current uptime is 12 hours.
   1551 // Verifies that when an uptime limit of 24 hours is set, the availability of an
   1552 // update causes the grace period to be rescheduled so that it ends 24 hours
   1553 // from now. Further verifies that the current uptime is persisted as the time
   1554 // at which a reboot became necessary.
   1555 TEST_P(AutomaticRebootManagerTest, UpdateBeforeUptimeLimit) {
   1556   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
   1557   SetRebootAfterUpdate(true, false);
   1558 
   1559   // Verify that the device does not reboot immediately.
   1560   CreateAutomaticRebootManager(false);
   1561 
   1562   // Set the uptime limit. Verify that the device does not reboot immediately.
   1563   SetUptimeLimit(base::TimeDelta::FromHours(24), false);
   1564 
   1565   // Verify that a grace period has been scheduled to start in the future.
   1566   VerifyGracePeriod(uptime_limit_);
   1567 
   1568   // Fast forward the uptime by 20 seconds. Verify that the device does not
   1569   // reboot immediately.
   1570   FastForwardBy(base::TimeDelta::FromSeconds(20), false);
   1571 
   1572   // Notify that an update has been applied and a reboot is necessary. Verify
   1573   // that the device does not reboot immediately.
   1574   NotifyUpdateRebootNeeded();
   1575 
   1576   // Verify that the current uptime has been persisted as the time at which a
   1577   // reboot became necessary.
   1578   EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
   1579       &update_reboot_needed_uptime_));
   1580   EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
   1581 
   1582   // Verify that the grace period has been rescheduled to start at the time that
   1583   // the update became available.
   1584   VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
   1585 
   1586   // Verify that unless a non-kiosk-app session is in progress, the device
   1587   // eventually reboots.
   1588   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1589                                 is_logged_in_as_kiosk_app_);
   1590 }
   1591 
   1592 // Chrome is running. The uptime limit is set to 24 hours. An update was applied
   1593 // and a reboot became necessary to complete the update process after 12 hours.
   1594 // The policy to automatically reboot after an update is enabled. The current
   1595 // uptime is 12 hours 20 seconds.
   1596 // Verifies that when the policy to reboot after an update is disabled, the
   1597 // grace period is rescheduled to start after 24 hours of uptime. Further
   1598 // verifies that when the uptime limit is removed, the grace period is removed.
   1599 TEST_P(AutomaticRebootManagerTest, PolicyOffThenUptimeLimitOff) {
   1600   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
   1601   SetRebootAfterUpdate(true, false);
   1602 
   1603   // Verify that the device does not reboot immediately.
   1604   CreateAutomaticRebootManager(false);
   1605 
   1606   // Set the uptime limit. Verify that the device does not reboot immediately.
   1607   SetUptimeLimit(base::TimeDelta::FromHours(24), false);
   1608 
   1609   // Verify that the grace period has started.
   1610   VerifyGracePeriod(uptime_limit_);
   1611 
   1612   // Notify that an update has been applied and a reboot is necessary. Verify
   1613   // that the device does not reboot immediately.
   1614   NotifyUpdateRebootNeeded();
   1615 
   1616   // Verify that the current uptime has been persisted as the time at which a
   1617   // reboot became necessary.
   1618   EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
   1619       &update_reboot_needed_uptime_));
   1620   EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
   1621 
   1622   // Verify that a grace period has been rescheduled to end 24 hours from now.
   1623   VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
   1624 
   1625   // Fast forward the uptime by 20 seconds. Verify that the device does not
   1626   // reboot immediately.
   1627   FastForwardBy(base::TimeDelta::FromSeconds(20), false);
   1628 
   1629   // Disable automatic reboot after an update has been applied. Verify that the
   1630   // device does not reboot immediately.
   1631   SetRebootAfterUpdate(false, false);
   1632 
   1633   // Verify that the grace period has been rescheduled to start after 24 hours
   1634   // of uptime.
   1635   VerifyGracePeriod(uptime_limit_);
   1636 
   1637   // Remove the uptime limit. Verify that the device does not reboot
   1638   // immediately.
   1639   SetUptimeLimit(base::TimeDelta(), false);
   1640 
   1641   // Verify that the grace period has been removed.
   1642   VerifyNoGracePeriod();
   1643 
   1644   // Verify that the device does not reboot eventually.
   1645   FastForwardUntilNoTasksRemain(false);
   1646 }
   1647 
   1648 // Chrome is running. The uptime limit is set to 6 hours. An update was applied
   1649 // and a reboot became necessary to complete the update process after 12 hours.
   1650 // The policy to automatically reboot after an update is enabled. The current
   1651 // uptime is 12 hours 20 seconds.
   1652 // Verifies that when the uptime limit is removed, the grace period is
   1653 // rescheduled to have started after 12 hours of uptime. Further verifies that
   1654 // when the policy to reboot after an update is disabled, the reboot request and
   1655 // grace period are removed.
   1656 TEST_P(AutomaticRebootManagerTest, UptimeLimitOffThenPolicyOff) {
   1657   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
   1658   SetRebootAfterUpdate(true, false);
   1659 
   1660   // Verify that the device does not reboot immediately.
   1661   CreateAutomaticRebootManager(false);
   1662 
   1663   // Notify that an update has been applied and a reboot is necessary. Verify
   1664   // that the device does not reboot immediately.
   1665   NotifyUpdateRebootNeeded();
   1666 
   1667   // Verify that the current uptime has been persisted as the time at which a
   1668   // reboot became necessary.
   1669   EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
   1670       &update_reboot_needed_uptime_));
   1671   EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
   1672 
   1673   // Verify that the grace period has started.
   1674   VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
   1675 
   1676   // Set the uptime limit. Verify that the device does not reboot immediately.
   1677   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
   1678 
   1679   // Verify that the grace period has been rescheduled to have started after
   1680   // 6 hours of uptime.
   1681   VerifyGracePeriod(uptime_limit_);
   1682 
   1683   // Fast forward the uptime by 20 seconds. Verify that the device does not
   1684   // reboot immediately.
   1685   FastForwardBy(base::TimeDelta::FromSeconds(20), false);
   1686 
   1687   // Remove the uptime limit. Verify that the device does not reboot
   1688   // immediately.
   1689   SetUptimeLimit(base::TimeDelta(), false);
   1690 
   1691   // Verify that a grace period has been rescheduled to have started after 12
   1692   // hours of uptime.
   1693   VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
   1694 
   1695   // Disable automatic reboot after an update has been applied. Verify that the
   1696   // device does not reboot immediately.
   1697   SetRebootAfterUpdate(false, false);
   1698 
   1699   // Verify that the grace period has been removed.
   1700   VerifyNoGracePeriod();
   1701 
   1702   // Verify that the device does not reboot eventually.
   1703   FastForwardUntilNoTasksRemain(false);
   1704 }
   1705 
   1706 // Chrome is running. The uptime limit is 6 hours. The current uptime is
   1707 // 29 hours 59 minutes 59 seconds.
   1708 // Verifies that if no non-kiosk-app session is in progress, the device reboots
   1709 // immediately when the grace period ends after 6 + 24 hours of uptime.
   1710 TEST_P(AutomaticRebootManagerTest, GracePeriodEnd) {
   1711   task_runner_->SetUptime(base::TimeDelta::FromHours(29) +
   1712                           base::TimeDelta::FromMinutes(59) +
   1713                           base::TimeDelta::FromSeconds(59));
   1714 
   1715   // Verify that the device does not reboot immediately.
   1716   CreateAutomaticRebootManager(false);
   1717 
   1718   // Set the uptime limit. Verify that the device does not reboot immediately.
   1719   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
   1720 
   1721   // Verify that a grace period has started.
   1722   VerifyGracePeriod(uptime_limit_);
   1723 
   1724   // Fast forward the uptime by 1 second. Verify that unless a non-kiosk-app
   1725   // session is in progress, the the device immediately reboots.
   1726   FastForwardBy(base::TimeDelta::FromSeconds(1), !is_user_logged_in_ ||
   1727                                                  is_logged_in_as_kiosk_app_);
   1728 
   1729   // Verify that if a non-kiosk-app session is in progress, the device does not
   1730   // reboot eventually.
   1731   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1732                                 is_logged_in_as_kiosk_app_);
   1733 }
   1734 
   1735 // Chrome is starting. The current uptime is 10 days.
   1736 // Verifies that when no automatic reboot policy is enabled, no reboot occurs
   1737 // and no grace period is scheduled.
   1738 TEST_P(AutomaticRebootManagerTest, StartNoPolicy) {
   1739   task_runner_->SetUptime(base::TimeDelta::FromDays(10));
   1740 
   1741   // Verify that the device does not reboot immediately.
   1742   CreateAutomaticRebootManager(false);
   1743 
   1744   // Verify that no grace period has started.
   1745   VerifyNoGracePeriod();
   1746 
   1747   // Verify that the device does not reboot eventually.
   1748   FastForwardUntilNoTasksRemain(false);
   1749 }
   1750 
   1751 // Chrome is starting. The uptime limit is set to 24 hours. The current uptime
   1752 // is 12 hours.
   1753 // Verifies that no reboot occurs and a grace period is scheduled to begin after
   1754 // 24 hours of uptime.
   1755 TEST_P(AutomaticRebootManagerTest, StartBeforeUptimeLimitGracePeriod) {
   1756   SetUptimeLimit(base::TimeDelta::FromHours(24), false);
   1757   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
   1758 
   1759   // Verify that the device does not reboot immediately.
   1760   CreateAutomaticRebootManager(false);
   1761 
   1762   // Verify that a grace period has been scheduled to start in the future.
   1763   VerifyGracePeriod(uptime_limit_);
   1764 
   1765   // Verify that unless a non-kiosk-app session is in progress, the device
   1766   // eventually reboots.
   1767   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1768                                 is_logged_in_as_kiosk_app_);
   1769 }
   1770 
   1771 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is
   1772 // 10 days.
   1773 // Verifies that if no non-kiosk-app session is in progress, the device reboots
   1774 // immediately because the grace period ended after 6 + 24 hours of uptime.
   1775 TEST_P(AutomaticRebootManagerTest, StartAfterUptimeLimitGracePeriod) {
   1776   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
   1777   task_runner_->SetUptime(base::TimeDelta::FromDays(10));
   1778 
   1779   // Verify that unless a non-kiosk-app session is in progress, the the device
   1780   // immediately reboots.
   1781   CreateAutomaticRebootManager(!is_user_logged_in_ ||
   1782                                is_logged_in_as_kiosk_app_);
   1783 
   1784   // Verify that if a non-kiosk-app session is in progress, the device does not
   1785   // reboot eventually.
   1786   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1787                                 is_logged_in_as_kiosk_app_);
   1788 }
   1789 
   1790 // Chrome is starting. The uptime limit is set to 6 hours. The current uptime is
   1791 // 12 hours.
   1792 // Verifies that a reboot is requested and a grace period is started that will
   1793 // end after 6 + 24 hours of uptime.
   1794 TEST_P(AutomaticRebootManagerTest, StartInUptimeLimitGracePeriod) {
   1795   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
   1796   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
   1797 
   1798   // Verify that the device does not reboot immediately.
   1799   CreateAutomaticRebootManager(false);
   1800 
   1801   // Verify that a grace period has started.
   1802   VerifyGracePeriod(uptime_limit_);
   1803 
   1804   // Verify that unless a non-kiosk-app session is in progress, the device
   1805   // eventually reboots.
   1806   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1807                                 is_logged_in_as_kiosk_app_);
   1808 }
   1809 
   1810 // Chrome is starting. An update was applied and a reboot became necessary to
   1811 // complete the update process after 6 hours of uptime. The current uptime is
   1812 // 10 days.
   1813 // Verifies that when the policy to automatically reboot after an update is
   1814 // enabled, the device reboots immediately if no non-kiosk-app session is in
   1815 // progress because the grace period ended after 6 + 24 hours of uptime.
   1816 TEST_P(AutomaticRebootManagerTest, StartAfterUpdateGracePeriod) {
   1817   SetUpdateStatusNeedReboot();
   1818   SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
   1819   task_runner_->SetUptime(base::TimeDelta::FromDays(10));
   1820   SetRebootAfterUpdate(true, false);
   1821 
   1822   // Verify that unless a non-kiosk-app session is in progress, the device
   1823   // reboots immediately.
   1824   CreateAutomaticRebootManager(!is_user_logged_in_ ||
   1825                                is_logged_in_as_kiosk_app_);
   1826 
   1827   // Verify that if a non-kiosk-app session is in progress, the device does not
   1828   // reboot eventually.
   1829   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1830                                 is_logged_in_as_kiosk_app_);
   1831 }
   1832 
   1833 // Chrome is starting. An update was applied and a reboot became necessary to
   1834 // complete the update process after 6 hours of uptime. The current uptime is
   1835 // 12 hours.
   1836 // Verifies that when the policy to automatically reboot after an update is
   1837 // enabled, a reboot is requested and a grace period is started that will end
   1838 // after 6 + 24 hours of uptime.
   1839 TEST_P(AutomaticRebootManagerTest, StartInUpdateGracePeriod) {
   1840   SetUpdateStatusNeedReboot();
   1841   SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
   1842   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
   1843   SetRebootAfterUpdate(true, false);
   1844 
   1845   // Verify that the device does not reboot immediately.
   1846   CreateAutomaticRebootManager(false);
   1847 
   1848   // Verify that a grace period has started.
   1849   VerifyGracePeriod(update_reboot_needed_uptime_);
   1850 
   1851   // Verify that unless a non-kiosk-app session is in progress, the device
   1852   // eventually reboots.
   1853   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1854                                 is_logged_in_as_kiosk_app_);
   1855 }
   1856 
   1857 // Chrome is starting. An update was applied and a reboot became necessary to
   1858 // complete the update process after 10 minutes of uptime. The current uptime is
   1859 // 20 minutes.
   1860 // Verifies that when the policy to automatically reboot after an update is
   1861 // enabled, no reboot occurs and a grace period is scheduled to begin after the
   1862 // minimum of 1 hour of uptime.
   1863 TEST_P(AutomaticRebootManagerTest, StartBeforeUpdateGracePeriod) {
   1864   SetUpdateStatusNeedReboot();
   1865   SetUpdateRebootNeededUptime(base::TimeDelta::FromMinutes(10));
   1866   task_runner_->SetUptime(base::TimeDelta::FromMinutes(20));
   1867   SetRebootAfterUpdate(true, false);
   1868 
   1869   // Verify that the device does not reboot immediately.
   1870   CreateAutomaticRebootManager(false);
   1871 
   1872   // Verify that a grace period has been scheduled to start in the future.
   1873   VerifyGracePeriod(base::TimeDelta::FromHours(1));
   1874 
   1875   // Verify that unless a non-kiosk-app session is in progress, the device
   1876   // eventually reboots.
   1877   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1878                                 is_logged_in_as_kiosk_app_);
   1879 }
   1880 
   1881 // Chrome is starting. An update was applied and a reboot became necessary to
   1882 // complete the update process after 6 hours of uptime. The current uptime is
   1883 // 10 days.
   1884 // Verifies that when the policy to automatically reboot after an update is not
   1885 // enabled, no reboot occurs and no grace period is scheduled.
   1886 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicy) {
   1887   SetUpdateStatusNeedReboot();
   1888   SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
   1889   task_runner_->SetUptime(base::TimeDelta::FromDays(10));
   1890 
   1891   // Verify that the device does not reboot immediately.
   1892   CreateAutomaticRebootManager(false);
   1893 
   1894   // Verify that no grace period has started.
   1895   VerifyNoGracePeriod();
   1896 
   1897   // Verify that the device does not reboot eventually.
   1898   FastForwardUntilNoTasksRemain(false);
   1899 }
   1900 
   1901 // Chrome is starting. An update was applied and a reboot became necessary to
   1902 // complete the update process but the time at which this happened was lost. The
   1903 // current uptime is 10 days.
   1904 // Verifies that the current uptime is persisted as the time at which a reboot
   1905 // became necessary. Further verifies that when the policy to automatically
   1906 // reboot after an update is enabled, a reboot is requested and a grace period
   1907 // is started that will end 24 hours from now.
   1908 TEST_P(AutomaticRebootManagerTest, StartUpdateTimeLost) {
   1909   SetUpdateStatusNeedReboot();
   1910   task_runner_->SetUptime(base::TimeDelta::FromDays(10));
   1911   SetRebootAfterUpdate(true, false);
   1912 
   1913   // Verify that the device does not reboot immediately.
   1914   CreateAutomaticRebootManager(false);
   1915 
   1916   // Verify that the current uptime has been persisted as the time at which a
   1917   // reboot became necessary.
   1918   EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
   1919       &update_reboot_needed_uptime_));
   1920   EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
   1921 
   1922   // Verify that a grace period has started.
   1923   VerifyGracePeriod(update_reboot_needed_uptime_ + uptime_processing_delay_);
   1924 
   1925   // Verify that unless a non-kiosk-app session is in progress, the device
   1926   // eventually reboots.
   1927   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   1928                                 is_logged_in_as_kiosk_app_);
   1929 }
   1930 
   1931 // Chrome is starting. An update was applied and a reboot became necessary to
   1932 // complete the update process but the time at which this happened was lost. The
   1933 // current uptime is 10 days.
   1934 // Verifies that the current uptime is persisted as the time at which a reboot
   1935 // became necessary. Further verifies that when the policy to automatically
   1936 // reboot after an update is not enabled, no reboot occurs and no grace period
   1937 // is scheduled.
   1938 TEST_P(AutomaticRebootManagerTest, StartUpdateNoPolicyTimeLost) {
   1939   SetUpdateStatusNeedReboot();
   1940   task_runner_->SetUptime(base::TimeDelta::FromDays(10));
   1941 
   1942   // Verify that the device does not reboot immediately.
   1943   CreateAutomaticRebootManager(false);
   1944 
   1945   // Verify that the current uptime has been persisted as the time at which a
   1946   // reboot became necessary.
   1947   EXPECT_TRUE(ReadUpdateRebootNeededUptimeFromFile(
   1948       &update_reboot_needed_uptime_));
   1949   EXPECT_EQ(task_runner_->Uptime(), update_reboot_needed_uptime_);
   1950 
   1951   // Verify that no grace period has started.
   1952   VerifyNoGracePeriod();
   1953 
   1954   // Verify that the device does not reboot eventually.
   1955   FastForwardUntilNoTasksRemain(false);
   1956 }
   1957 
   1958 // Chrome is starting. No update has been applied. The current uptime is
   1959 // 12 hours.
   1960 // Verifies that no time is persisted as the time at which a reboot became
   1961 // necessary. Further verifies that no reboot occurs and no grace period is
   1962 // scheduled.
   1963 TEST_P(AutomaticRebootManagerTest, StartNoUpdate) {
   1964   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
   1965   SetRebootAfterUpdate(true, false);
   1966 
   1967   // Verify that the device does not reboot immediately.
   1968   CreateAutomaticRebootManager(false);
   1969 
   1970   // Verify that no time is persisted as the time at which a reboot became
   1971   // necessary.
   1972   EXPECT_FALSE(ReadUpdateRebootNeededUptimeFromFile(
   1973       &update_reboot_needed_uptime_));
   1974 
   1975   // Verify that no grace period has started.
   1976   VerifyNoGracePeriod();
   1977 
   1978   // Verify that the device does not reboot eventually.
   1979   FastForwardUntilNoTasksRemain(false);
   1980 }
   1981 
   1982 // Chrome is starting. The uptime limit is set to 6 hours. Also, an update was
   1983 // applied and a reboot became necessary to complete the update process after
   1984 // 8 hours of uptime. The current uptime is 12 hours.
   1985 // Verifies that when the policy to automatically reboot after an update is
   1986 // enabled, a reboot is requested and a grace period is started that will end
   1987 // after 6 + 24 hours of uptime.
   1988 TEST_P(AutomaticRebootManagerTest, StartUptimeLimitBeforeUpdate) {
   1989   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
   1990   SetUpdateStatusNeedReboot();
   1991   SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(8));
   1992   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
   1993   SetRebootAfterUpdate(true, false);
   1994 
   1995   // Verify that the device does not reboot immediately.
   1996   CreateAutomaticRebootManager(false);
   1997 
   1998   // Verify that a grace period has started.
   1999   VerifyGracePeriod(uptime_limit_);
   2000 
   2001   // Verify that unless a non-kiosk-app session is in progress, the device
   2002   // eventually reboots.
   2003   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   2004                                 is_logged_in_as_kiosk_app_);
   2005 }
   2006 
   2007 // Chrome is starting. The uptime limit is set to 8 hours. Also, an update was
   2008 // applied and a reboot became necessary to complete the update process after
   2009 // 6 hours of uptime. The current uptime is 12 hours.
   2010 // Verifies that when the policy to automatically reboot after an update is
   2011 // enabled, a reboot is requested and a grace period is started that will end
   2012 // after 6 + 24 hours of uptime.
   2013 TEST_P(AutomaticRebootManagerTest, StartUpdateBeforeUptimeLimit) {
   2014   SetUptimeLimit(base::TimeDelta::FromHours(8), false);
   2015   SetUpdateStatusNeedReboot();
   2016   SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
   2017   task_runner_->SetUptime(base::TimeDelta::FromHours(12));
   2018   SetRebootAfterUpdate(true, false);
   2019 
   2020   // Verify that the device does not reboot immediately.
   2021   CreateAutomaticRebootManager(false);
   2022 
   2023   // Verify that a grace period has started.
   2024   VerifyGracePeriod(update_reboot_needed_uptime_);
   2025 
   2026   // Verify that unless a non-kiosk-app session is in progress, the device
   2027   // eventually reboots.
   2028   FastForwardUntilNoTasksRemain(!is_user_logged_in_ ||
   2029                                 is_logged_in_as_kiosk_app_);
   2030 }
   2031 
   2032 // Chrome is starting. The uptime limit is set to 6 hours. Also, an update was
   2033 // applied and a reboot became necessary to complete the update process after
   2034 // 6 hours of uptime. The current uptime is not available.
   2035 // Verifies that even if the policy to automatically reboot after an update is
   2036 // enabled, no reboot occurs and no grace period is scheduled.
   2037 TEST_P(AutomaticRebootManagerTest, StartNoUptime) {
   2038   SetUptimeLimit(base::TimeDelta::FromHours(6), false);
   2039   SetUpdateStatusNeedReboot();
   2040   SetUpdateRebootNeededUptime(base::TimeDelta::FromHours(6));
   2041   SetRebootAfterUpdate(true, false);
   2042 
   2043   // Verify that the device does not reboot immediately.
   2044   CreateAutomaticRebootManager(false);
   2045 
   2046   // Verify that no grace period has started.
   2047   VerifyNoGracePeriod();
   2048 
   2049   // Verify that the device does not reboot eventually.
   2050   FastForwardUntilNoTasksRemain(false);
   2051 }
   2052 
   2053 INSTANTIATE_TEST_CASE_P(
   2054     AutomaticRebootManagerTestInstance,
   2055     AutomaticRebootManagerTest,
   2056     ::testing::Values(
   2057         AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN,
   2058         AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION,
   2059         AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION));
   2060 
   2061 }  // namespace system
   2062 }  // namespace chromeos
   2063