OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h" | 5 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 | 393 |
394 void AutomaticRebootManagerBasicTest::SetRebootAfterUpdate( | 394 void AutomaticRebootManagerBasicTest::SetRebootAfterUpdate( |
395 bool reboot_after_update, | 395 bool reboot_after_update, |
396 bool expect_reboot) { | 396 bool expect_reboot) { |
397 reboot_after_update_ = reboot_after_update; | 397 reboot_after_update_ = reboot_after_update; |
398 local_state_.SetManagedPref( | 398 local_state_.SetManagedPref( |
399 prefs::kRebootAfterUpdate, | 399 prefs::kRebootAfterUpdate, |
400 base::Value::CreateBooleanValue(reboot_after_update)); | 400 base::Value::CreateBooleanValue(reboot_after_update)); |
401 task_runner_->RunUntilIdle(); | 401 task_runner_->RunUntilIdle(); |
402 EXPECT_EQ(expect_reboot ? 1 : 0, | 402 EXPECT_EQ(expect_reboot ? 1 : 0, |
403 power_manager_client_->request_restart_call_count()); | 403 power_manager_client_->num_request_restart_calls()); |
404 } | 404 } |
405 | 405 |
406 void AutomaticRebootManagerBasicTest::SetUptimeLimit( | 406 void AutomaticRebootManagerBasicTest::SetUptimeLimit( |
407 const base::TimeDelta& limit, | 407 const base::TimeDelta& limit, |
408 bool expect_reboot) { | 408 bool expect_reboot) { |
409 uptime_limit_ = limit; | 409 uptime_limit_ = limit; |
410 if (limit == base::TimeDelta()) { | 410 if (limit == base::TimeDelta()) { |
411 local_state_.RemoveManagedPref(prefs::kUptimeLimit); | 411 local_state_.RemoveManagedPref(prefs::kUptimeLimit); |
412 } else { | 412 } else { |
413 local_state_.SetManagedPref( | 413 local_state_.SetManagedPref( |
414 prefs::kUptimeLimit, | 414 prefs::kUptimeLimit, |
415 base::Value::CreateIntegerValue(limit.InSeconds())); | 415 base::Value::CreateIntegerValue(limit.InSeconds())); |
416 } | 416 } |
417 task_runner_->RunUntilIdle(); | 417 task_runner_->RunUntilIdle(); |
418 EXPECT_EQ(expect_reboot ? 1 : 0, | 418 EXPECT_EQ(expect_reboot ? 1 : 0, |
419 power_manager_client_->request_restart_call_count()); | 419 power_manager_client_->num_request_restart_calls()); |
420 } | 420 } |
421 | 421 |
422 void AutomaticRebootManagerBasicTest::NotifyUpdateRebootNeeded() { | 422 void AutomaticRebootManagerBasicTest::NotifyUpdateRebootNeeded() { |
423 SetUpdateStatusNeedReboot(); | 423 SetUpdateStatusNeedReboot(); |
424 automatic_reboot_manager_->UpdateStatusChanged( | 424 automatic_reboot_manager_->UpdateStatusChanged( |
425 update_engine_client_->GetLastStatus()); | 425 update_engine_client_->GetLastStatus()); |
426 task_runner_->RunUntilIdle(); | 426 task_runner_->RunUntilIdle(); |
427 EXPECT_EQ(0, power_manager_client_->request_restart_call_count()); | 427 EXPECT_EQ(0, power_manager_client_->num_request_restart_calls()); |
428 } | 428 } |
429 | 429 |
430 void AutomaticRebootManagerBasicTest::NotifyResumed(bool expect_reboot) { | 430 void AutomaticRebootManagerBasicTest::NotifyResumed(bool expect_reboot) { |
431 automatic_reboot_manager_->SystemResumed(base::TimeDelta::FromHours(1)); | 431 automatic_reboot_manager_->SystemResumed(base::TimeDelta::FromHours(1)); |
432 task_runner_->RunUntilIdle(); | 432 task_runner_->RunUntilIdle(); |
433 EXPECT_EQ(expect_reboot ? 1 : 0, | 433 EXPECT_EQ(expect_reboot ? 1 : 0, |
434 power_manager_client_->request_restart_call_count()); | 434 power_manager_client_->num_request_restart_calls()); |
435 } | 435 } |
436 | 436 |
437 void AutomaticRebootManagerBasicTest::NotifyTerminating(bool expect_reboot) { | 437 void AutomaticRebootManagerBasicTest::NotifyTerminating(bool expect_reboot) { |
438 automatic_reboot_manager_->Observe( | 438 automatic_reboot_manager_->Observe( |
439 chrome::NOTIFICATION_APP_TERMINATING, | 439 chrome::NOTIFICATION_APP_TERMINATING, |
440 content::Source<AutomaticRebootManagerBasicTest>(this), | 440 content::Source<AutomaticRebootManagerBasicTest>(this), |
441 content::NotificationService::NoDetails()); | 441 content::NotificationService::NoDetails()); |
442 task_runner_->RunUntilIdle(); | 442 task_runner_->RunUntilIdle(); |
443 EXPECT_EQ(expect_reboot ? 1 : 0, | 443 EXPECT_EQ(expect_reboot ? 1 : 0, |
444 power_manager_client_->request_restart_call_count()); | 444 power_manager_client_->num_request_restart_calls()); |
445 } | 445 } |
446 | 446 |
447 void AutomaticRebootManagerBasicTest::FastForwardBy( | 447 void AutomaticRebootManagerBasicTest::FastForwardBy( |
448 const base::TimeDelta& delta, | 448 const base::TimeDelta& delta, |
449 bool expect_reboot) { | 449 bool expect_reboot) { |
450 task_runner_->FastForwardBy(delta); | 450 task_runner_->FastForwardBy(delta); |
451 EXPECT_EQ(expect_reboot ? 1 : 0, | 451 EXPECT_EQ(expect_reboot ? 1 : 0, |
452 power_manager_client_->request_restart_call_count()); | 452 power_manager_client_->num_request_restart_calls()); |
453 } | 453 } |
454 | 454 |
455 void AutomaticRebootManagerBasicTest::FastForwardUntilNoTasksRemain( | 455 void AutomaticRebootManagerBasicTest::FastForwardUntilNoTasksRemain( |
456 bool expect_reboot) { | 456 bool expect_reboot) { |
457 task_runner_->FastForwardUntilNoTasksRemain(); | 457 task_runner_->FastForwardUntilNoTasksRemain(); |
458 EXPECT_EQ(expect_reboot ? 1 : 0, | 458 EXPECT_EQ(expect_reboot ? 1 : 0, |
459 power_manager_client_->request_restart_call_count()); | 459 power_manager_client_->num_request_restart_calls()); |
460 } | 460 } |
461 | 461 |
462 void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager( | 462 void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager( |
463 bool expect_reboot) { | 463 bool expect_reboot) { |
464 automatic_reboot_manager_.reset(new AutomaticRebootManager( | 464 automatic_reboot_manager_.reset(new AutomaticRebootManager( |
465 scoped_ptr<base::TickClock>(new MockTimeTickClock(task_runner_)))); | 465 scoped_ptr<base::TickClock>(new MockTimeTickClock(task_runner_)))); |
466 task_runner_->RunUntilIdle(); | 466 task_runner_->RunUntilIdle(); |
467 EXPECT_EQ(expect_reboot ? 1 : 0, | 467 EXPECT_EQ(expect_reboot ? 1 : 0, |
468 power_manager_client_->request_restart_call_count()); | 468 power_manager_client_->num_request_restart_calls()); |
469 | 469 |
470 uptime_processing_delay_ = | 470 uptime_processing_delay_ = |
471 base::TimeTicks() - automatic_reboot_manager_->boot_time_ - | 471 base::TimeTicks() - automatic_reboot_manager_->boot_time_ - |
472 task_runner_->Uptime(); | 472 task_runner_->Uptime(); |
473 EXPECT_GE(uptime_processing_delay_, base::TimeDelta()); | 473 EXPECT_GE(uptime_processing_delay_, base::TimeDelta()); |
474 EXPECT_LE(uptime_processing_delay_, base::TimeDelta::FromSeconds(1)); | 474 EXPECT_LE(uptime_processing_delay_, base::TimeDelta::FromSeconds(1)); |
475 | 475 |
476 if (is_user_logged_in_ || expect_reboot) | 476 if (is_user_logged_in_ || expect_reboot) |
477 VerifyLoginScreenIdleTimerIsStopped(); | 477 VerifyLoginScreenIdleTimerIsStopped(); |
478 else | 478 else |
(...skipping 1577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2056 INSTANTIATE_TEST_CASE_P( | 2056 INSTANTIATE_TEST_CASE_P( |
2057 AutomaticRebootManagerTestInstance, | 2057 AutomaticRebootManagerTestInstance, |
2058 AutomaticRebootManagerTest, | 2058 AutomaticRebootManagerTest, |
2059 ::testing::Values( | 2059 ::testing::Values( |
2060 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN, | 2060 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN, |
2061 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION, | 2061 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION, |
2062 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION)); | 2062 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION)); |
2063 | 2063 |
2064 } // namespace system | 2064 } // namespace system |
2065 } // namespace chromeos | 2065 } // namespace chromeos |
OLD | NEW |