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

Side by Side Diff: chrome/browser/chromeos/system/automatic_reboot_manager_unittest.cc

Issue 899863002: Add support in TestMockTimeTaskRunner for vending out mock Time and mock Clocks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Start ticks from 0, some tests depend on this. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h" 5 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/test/test_shell_delegate.h" 10 #include "ash/test/test_shell_delegate.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 void WriteUptimeToFile(); 68 void WriteUptimeToFile();
69 69
70 // Adjusts the offset so that the current mock uptime will be |uptime|. 70 // Adjusts the offset so that the current mock uptime will be |uptime|.
71 void SetUptime(const base::TimeDelta& uptime); 71 void SetUptime(const base::TimeDelta& uptime);
72 72
73 void set_uptime_file_path(const base::FilePath& uptime_file_path) { 73 void set_uptime_file_path(const base::FilePath& uptime_file_path) {
74 uptime_file_path_ = uptime_file_path; 74 uptime_file_path_ = uptime_file_path;
75 } 75 }
76 76
77 base::TimeDelta uptime() const { 77 base::TimeDelta uptime() const {
78 return mock_time_task_runner_->GetCurrentMockTime() - base::TimeTicks() + 78 return mock_time_task_runner_->NowTicks() - base::TimeTicks() +
79 uptime_offset_; 79 uptime_offset_;
80 } 80 }
81 81
82 private: 82 private:
83 base::TestMockTimeTaskRunner* mock_time_task_runner_; 83 base::TestMockTimeTaskRunner* mock_time_task_runner_;
84 84
85 base::FilePath uptime_file_path_; 85 base::FilePath uptime_file_path_;
86 base::TimeDelta uptime_offset_; 86 base::TimeDelta uptime_offset_;
87 87
88 DISALLOW_COPY_AND_ASSIGN(MockUptimeProvider); 88 DISALLOW_COPY_AND_ASSIGN(MockUptimeProvider);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 MockUptimeProvider::MockUptimeProvider( 242 MockUptimeProvider::MockUptimeProvider(
243 base::TestMockTimeTaskRunner* mock_time_task_runner) 243 base::TestMockTimeTaskRunner* mock_time_task_runner)
244 : mock_time_task_runner_(mock_time_task_runner) { 244 : mock_time_task_runner_(mock_time_task_runner) {
245 } 245 }
246 246
247 void MockUptimeProvider::WriteUptimeToFile() { 247 void MockUptimeProvider::WriteUptimeToFile() {
248 SaveUptimeToFile(uptime_file_path_, uptime()); 248 SaveUptimeToFile(uptime_file_path_, uptime());
249 } 249 }
250 250
251 void MockUptimeProvider::SetUptime(const base::TimeDelta& uptime) { 251 void MockUptimeProvider::SetUptime(const base::TimeDelta& uptime) {
252 uptime_offset_ = uptime - (mock_time_task_runner_->GetCurrentMockTime() - 252 uptime_offset_ =
253 base::TimeTicks()); 253 uptime - (mock_time_task_runner_->NowTicks() - base::TimeTicks());
254 WriteUptimeToFile(); 254 WriteUptimeToFile();
255 } 255 }
256 256
257 TestAutomaticRebootManagerTaskRunner::TestAutomaticRebootManagerTaskRunner() 257 TestAutomaticRebootManagerTaskRunner::TestAutomaticRebootManagerTaskRunner()
258 : uptime_provider_(new MockUptimeProvider(this)) { 258 : uptime_provider_(new MockUptimeProvider(this)) {
259 } 259 }
260 260
261 TestAutomaticRebootManagerTaskRunner::~TestAutomaticRebootManagerTaskRunner() { 261 TestAutomaticRebootManagerTaskRunner::~TestAutomaticRebootManagerTaskRunner() {
262 } 262 }
263 263
(...skipping 2017 matching lines...) Expand 10 before | Expand all | Expand 10 after
2281 INSTANTIATE_TEST_CASE_P( 2281 INSTANTIATE_TEST_CASE_P(
2282 AutomaticRebootManagerTestInstance, 2282 AutomaticRebootManagerTestInstance,
2283 AutomaticRebootManagerTest, 2283 AutomaticRebootManagerTest,
2284 ::testing::Values( 2284 ::testing::Values(
2285 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN, 2285 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_LOGIN_SCREEN,
2286 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION, 2286 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_KIOSK_APP_SESSION,
2287 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION)); 2287 AUTOMATIC_REBOOT_MANAGER_TEST_SCENARIO_NON_KIOSK_APP_SESSION));
2288 2288
2289 } // namespace system 2289 } // namespace system
2290 } // namespace chromeos 2290 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698