OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/session_length_limiter.h" | 5 #include "chrome/browser/chromeos/session_length_limiter.h" |
6 | 6 |
| 7 #include <queue> |
| 8 #include <utility> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/callback.h" |
7 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/location.h" |
| 14 #include "base/logging.h" |
8 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/testing_pref_service.h" | 17 #include "base/prefs/testing_pref_service.h" |
| 18 #include "base/single_thread_task_runner.h" |
11 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
12 #include "base/test/test_mock_time_task_runner.h" | |
13 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
14 #include "base/values.h" | 21 #include "base/values.h" |
15 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
16 #include "chrome/test/base/testing_browser_process.h" | 23 #include "chrome/test/base/testing_browser_process.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
19 | 26 |
20 using ::testing::Invoke; | 27 using ::testing::Invoke; |
21 using ::testing::Mock; | 28 using ::testing::Mock; |
22 using ::testing::NiceMock; | 29 using ::testing::NiceMock; |
23 | 30 |
24 namespace chromeos { | 31 namespace chromeos { |
25 | 32 |
26 namespace { | 33 namespace { |
27 | 34 |
28 class MockSessionLengthLimiterDelegate : public SessionLengthLimiter::Delegate { | 35 class MockSessionLengthLimiterDelegate : public SessionLengthLimiter::Delegate { |
29 public: | 36 public: |
30 MOCK_CONST_METHOD0(GetCurrentTime, const base::TimeTicks(void)); | 37 MOCK_CONST_METHOD0(GetCurrentTime, const base::TimeTicks(void)); |
31 MOCK_METHOD0(StopSession, void(void)); | 38 MOCK_METHOD0(StopSession, void(void)); |
32 }; | 39 }; |
33 | 40 |
| 41 // A SingleThreadTaskRunner that mocks the current time and allows it to be |
| 42 // fast-forwarded. |
| 43 class MockTimeSingleThreadTaskRunner : public base::SingleThreadTaskRunner { |
| 44 public: |
| 45 MockTimeSingleThreadTaskRunner(); |
| 46 |
| 47 // base::SingleThreadTaskRunner: |
| 48 virtual bool RunsTasksOnCurrentThread() const override; |
| 49 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 50 const base::Closure& task, |
| 51 base::TimeDelta delay) override; |
| 52 virtual bool PostNonNestableDelayedTask( |
| 53 const tracked_objects::Location& from_here, |
| 54 const base::Closure& task, |
| 55 base::TimeDelta delay) override; |
| 56 |
| 57 const base::TimeTicks& GetCurrentTime() const; |
| 58 |
| 59 void FastForwardBy(const base::TimeDelta& time_delta); |
| 60 void FastForwardUntilNoTasksRemain(); |
| 61 |
| 62 private: |
| 63 // Strict weak temporal ordering of tasks. |
| 64 class TemporalOrder { |
| 65 public: |
| 66 bool operator()( |
| 67 const std::pair<base::TimeTicks, base::Closure>& first_task, |
| 68 const std::pair<base::TimeTicks, base::Closure>& second_task) const; |
| 69 }; |
| 70 |
| 71 virtual ~MockTimeSingleThreadTaskRunner(); |
| 72 |
| 73 base::TimeTicks now_; |
| 74 std::priority_queue<std::pair<base::TimeTicks, base::Closure>, |
| 75 std::vector<std::pair<base::TimeTicks, base::Closure> >, |
| 76 TemporalOrder> tasks_; |
| 77 }; |
| 78 |
34 } // namespace | 79 } // namespace |
35 | 80 |
36 class SessionLengthLimiterTest : public testing::Test { | 81 class SessionLengthLimiterTest : public testing::Test { |
37 protected: | 82 protected: |
38 SessionLengthLimiterTest(); | 83 SessionLengthLimiterTest(); |
39 | 84 |
40 // testing::Test: | 85 // testing::Test: |
41 virtual void SetUp() override; | 86 virtual void SetUp() override; |
42 virtual void TearDown() override; | 87 virtual void TearDown() override; |
43 | 88 |
(...skipping 18 matching lines...) Expand all Loading... |
62 | 107 |
63 void ExpectStopSession(); | 108 void ExpectStopSession(); |
64 void SaveSessionStopTime(); | 109 void SaveSessionStopTime(); |
65 | 110 |
66 // Clears the session state by resetting |user_activity_| and | 111 // Clears the session state by resetting |user_activity_| and |
67 // |session_start_time_| and creates a new SessionLengthLimiter. | 112 // |session_start_time_| and creates a new SessionLengthLimiter. |
68 void CreateSessionLengthLimiter(bool browser_restarted); | 113 void CreateSessionLengthLimiter(bool browser_restarted); |
69 | 114 |
70 void DestroySessionLengthLimiter(); | 115 void DestroySessionLengthLimiter(); |
71 | 116 |
72 scoped_refptr<base::TestMockTimeTaskRunner> runner_; | 117 scoped_refptr<MockTimeSingleThreadTaskRunner> runner_; |
73 base::TimeTicks session_start_time_; | 118 base::TimeTicks session_start_time_; |
74 base::TimeTicks session_stop_time_; | 119 base::TimeTicks session_stop_time_; |
75 | 120 |
76 private: | 121 private: |
77 TestingPrefServiceSimple local_state_; | 122 TestingPrefServiceSimple local_state_; |
78 bool user_activity_seen_; | 123 bool user_activity_seen_; |
79 | 124 |
80 MockSessionLengthLimiterDelegate* delegate_; // Owned by | 125 MockSessionLengthLimiterDelegate* delegate_; // Owned by |
81 // session_length_limiter_. | 126 // session_length_limiter_. |
82 scoped_ptr<SessionLengthLimiter> session_length_limiter_; | 127 scoped_ptr<SessionLengthLimiter> session_length_limiter_; |
83 }; | 128 }; |
84 | 129 |
| 130 MockTimeSingleThreadTaskRunner::MockTimeSingleThreadTaskRunner() |
| 131 : now_(base::TimeTicks::FromInternalValue(1000)) { |
| 132 } |
| 133 |
| 134 bool MockTimeSingleThreadTaskRunner::RunsTasksOnCurrentThread() const { |
| 135 return true; |
| 136 } |
| 137 |
| 138 bool MockTimeSingleThreadTaskRunner::PostDelayedTask( |
| 139 const tracked_objects::Location& from_here, |
| 140 const base::Closure& task, |
| 141 base::TimeDelta delay) { |
| 142 tasks_.push(std::pair<base::TimeTicks, base::Closure>(now_ + delay, task)); |
| 143 return true; |
| 144 } |
| 145 |
| 146 bool MockTimeSingleThreadTaskRunner::PostNonNestableDelayedTask( |
| 147 const tracked_objects::Location& from_here, |
| 148 const base::Closure& task, |
| 149 base::TimeDelta delay) { |
| 150 NOTREACHED(); |
| 151 return false; |
| 152 } |
| 153 |
| 154 const base::TimeTicks& MockTimeSingleThreadTaskRunner::GetCurrentTime() const { |
| 155 return now_; |
| 156 } |
| 157 |
| 158 void MockTimeSingleThreadTaskRunner::FastForwardBy( |
| 159 const base::TimeDelta& time_delta) { |
| 160 const base::TimeTicks latest = now_ + time_delta; |
| 161 while (!tasks_.empty() && tasks_.top().first <= latest) { |
| 162 now_ = tasks_.top().first; |
| 163 base::Closure task = tasks_.top().second; |
| 164 tasks_.pop(); |
| 165 task.Run(); |
| 166 } |
| 167 now_ = latest; |
| 168 } |
| 169 |
| 170 void MockTimeSingleThreadTaskRunner::FastForwardUntilNoTasksRemain() { |
| 171 while (!tasks_.empty()) { |
| 172 now_ = tasks_.top().first; |
| 173 base::Closure task = tasks_.top().second; |
| 174 tasks_.pop(); |
| 175 task.Run(); |
| 176 } |
| 177 } |
| 178 |
| 179 bool MockTimeSingleThreadTaskRunner::TemporalOrder::operator()( |
| 180 const std::pair<base::TimeTicks, base::Closure>& first_task, |
| 181 const std::pair<base::TimeTicks, base::Closure>& second_task) const { |
| 182 return first_task.first > second_task.first; |
| 183 } |
| 184 |
| 185 MockTimeSingleThreadTaskRunner::~MockTimeSingleThreadTaskRunner() { |
| 186 } |
| 187 |
85 SessionLengthLimiterTest::SessionLengthLimiterTest() | 188 SessionLengthLimiterTest::SessionLengthLimiterTest() |
86 : user_activity_seen_(false), | 189 : user_activity_seen_(false), |
87 delegate_(NULL) { | 190 delegate_(NULL) { |
88 } | 191 } |
89 | 192 |
90 void SessionLengthLimiterTest::SetUp() { | 193 void SessionLengthLimiterTest::SetUp() { |
91 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); | 194 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); |
92 SessionLengthLimiter::RegisterPrefs(local_state_.registry()); | 195 SessionLengthLimiter::RegisterPrefs(local_state_.registry()); |
93 runner_ = new base::TestMockTimeTaskRunner; | 196 runner_ = new MockTimeSingleThreadTaskRunner; |
94 runner_->FastForwardBy(base::TimeDelta::FromInternalValue(1000)); | |
95 } | 197 } |
96 | 198 |
97 void SessionLengthLimiterTest::TearDown() { | 199 void SessionLengthLimiterTest::TearDown() { |
98 session_length_limiter_.reset(); | 200 session_length_limiter_.reset(); |
99 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); | 201 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); |
100 } | 202 } |
101 | 203 |
102 void SessionLengthLimiterTest::SetSessionUserActivitySeenPref( | 204 void SessionLengthLimiterTest::SetSessionUserActivitySeenPref( |
103 bool user_activity_seen) { | 205 bool user_activity_seen) { |
104 local_state_.SetUserPref(prefs::kSessionUserActivitySeen, | 206 local_state_.SetUserPref(prefs::kSessionUserActivitySeen, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 if (session_length_limiter_) | 267 if (session_length_limiter_) |
166 session_length_limiter_->OnUserActivity(NULL); | 268 session_length_limiter_->OnUserActivity(NULL); |
167 UpdateSessionStartTimeIfWaitingForUserActivity(); | 269 UpdateSessionStartTimeIfWaitingForUserActivity(); |
168 user_activity_seen_ = true; | 270 user_activity_seen_ = true; |
169 } | 271 } |
170 | 272 |
171 void SessionLengthLimiterTest:: | 273 void SessionLengthLimiterTest:: |
172 UpdateSessionStartTimeIfWaitingForUserActivity() { | 274 UpdateSessionStartTimeIfWaitingForUserActivity() { |
173 if (!user_activity_seen_ && | 275 if (!user_activity_seen_ && |
174 local_state_.GetBoolean(prefs::kSessionWaitForInitialUserActivity)) { | 276 local_state_.GetBoolean(prefs::kSessionWaitForInitialUserActivity)) { |
175 session_start_time_ = runner_->GetCurrentMockTime(); | 277 session_start_time_ = runner_->GetCurrentTime(); |
176 } | 278 } |
177 } | 279 } |
178 | 280 |
179 void SessionLengthLimiterTest::ExpectStopSession() { | 281 void SessionLengthLimiterTest::ExpectStopSession() { |
180 Mock::VerifyAndClearExpectations(delegate_); | 282 Mock::VerifyAndClearExpectations(delegate_); |
181 EXPECT_CALL(*delegate_, StopSession()) | 283 EXPECT_CALL(*delegate_, StopSession()) |
182 .Times(1) | 284 .Times(1) |
183 .WillOnce(Invoke(this, &SessionLengthLimiterTest::SaveSessionStopTime)); | 285 .WillOnce(Invoke(this, &SessionLengthLimiterTest::SaveSessionStopTime)); |
184 } | 286 } |
185 | 287 |
186 void SessionLengthLimiterTest::SaveSessionStopTime() { | 288 void SessionLengthLimiterTest::SaveSessionStopTime() { |
187 session_stop_time_ = runner_->GetCurrentMockTime(); | 289 session_stop_time_ = runner_->GetCurrentTime(); |
188 } | 290 } |
189 | 291 |
190 void SessionLengthLimiterTest::CreateSessionLengthLimiter( | 292 void SessionLengthLimiterTest::CreateSessionLengthLimiter( |
191 bool browser_restarted) { | 293 bool browser_restarted) { |
192 user_activity_seen_ = false; | 294 user_activity_seen_ = false; |
193 session_start_time_ = runner_->GetCurrentMockTime(); | 295 session_start_time_ = runner_->GetCurrentTime(); |
194 | 296 |
195 EXPECT_FALSE(delegate_); | 297 EXPECT_FALSE(delegate_); |
196 delegate_ = new NiceMock<MockSessionLengthLimiterDelegate>; | 298 delegate_ = new NiceMock<MockSessionLengthLimiterDelegate>; |
197 ON_CALL(*delegate_, GetCurrentTime()) | 299 ON_CALL(*delegate_, GetCurrentTime()) |
198 .WillByDefault(Invoke( | 300 .WillByDefault(Invoke(runner_.get(), |
199 runner_.get(), &base::TestMockTimeTaskRunner::GetCurrentMockTime)); | 301 &MockTimeSingleThreadTaskRunner::GetCurrentTime)); |
200 EXPECT_CALL(*delegate_, StopSession()).Times(0); | 302 EXPECT_CALL(*delegate_, StopSession()).Times(0); |
201 session_length_limiter_.reset( | 303 session_length_limiter_.reset( |
202 new SessionLengthLimiter(delegate_, browser_restarted)); | 304 new SessionLengthLimiter(delegate_, browser_restarted)); |
203 } | 305 } |
204 | 306 |
205 void SessionLengthLimiterTest::DestroySessionLengthLimiter() { | 307 void SessionLengthLimiterTest::DestroySessionLengthLimiter() { |
206 session_length_limiter_.reset(); | 308 session_length_limiter_.reset(); |
207 delegate_ = NULL; | 309 delegate_ = NULL; |
208 } | 310 } |
209 | 311 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 SetSessionUserActivitySeenPref(true); | 380 SetSessionUserActivitySeenPref(true); |
279 ClearSessionStartTimePref(); | 381 ClearSessionStartTimePref(); |
280 CreateSessionLengthLimiter(false); | 382 CreateSessionLengthLimiter(false); |
281 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); | 383 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); |
282 EXPECT_FALSE(IsSessionStartTimePrefSet()); | 384 EXPECT_FALSE(IsSessionStartTimePrefSet()); |
283 DestroySessionLengthLimiter(); | 385 DestroySessionLengthLimiter(); |
284 | 386 |
285 // Pref indicating user activity not set. Session start time in the future. | 387 // Pref indicating user activity not set. Session start time in the future. |
286 ClearSessionUserActivitySeenPref(); | 388 ClearSessionUserActivitySeenPref(); |
287 SetSessionStartTimePref( | 389 SetSessionStartTimePref( |
288 runner_->GetCurrentMockTime() + base::TimeDelta::FromHours(2)); | 390 runner_->GetCurrentTime() + base::TimeDelta::FromHours(2)); |
289 CreateSessionLengthLimiter(false); | 391 CreateSessionLengthLimiter(false); |
290 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); | 392 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); |
291 EXPECT_FALSE(IsSessionStartTimePrefSet()); | 393 EXPECT_FALSE(IsSessionStartTimePrefSet()); |
292 DestroySessionLengthLimiter(); | 394 DestroySessionLengthLimiter(); |
293 | 395 |
294 // Pref indicating user activity set. Session start time in the future. | 396 // Pref indicating user activity set. Session start time in the future. |
295 SetSessionUserActivitySeenPref(true); | 397 SetSessionUserActivitySeenPref(true); |
296 SetSessionStartTimePref( | 398 SetSessionStartTimePref( |
297 runner_->GetCurrentMockTime() + base::TimeDelta::FromHours(2)); | 399 runner_->GetCurrentTime() + base::TimeDelta::FromHours(2)); |
298 CreateSessionLengthLimiter(false); | 400 CreateSessionLengthLimiter(false); |
299 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); | 401 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); |
300 EXPECT_FALSE(IsSessionStartTimePrefSet()); | 402 EXPECT_FALSE(IsSessionStartTimePrefSet()); |
301 DestroySessionLengthLimiter(); | 403 DestroySessionLengthLimiter(); |
302 | 404 |
303 // Pref indicating user activity not set. Session start time valid. | 405 // Pref indicating user activity not set. Session start time valid. |
304 ClearSessionUserActivitySeenPref(); | 406 ClearSessionUserActivitySeenPref(); |
305 SetSessionStartTimePref( | 407 SetSessionStartTimePref( |
306 runner_->GetCurrentMockTime() - base::TimeDelta::FromHours(2)); | 408 runner_->GetCurrentTime() - base::TimeDelta::FromHours(2)); |
307 CreateSessionLengthLimiter(false); | 409 CreateSessionLengthLimiter(false); |
308 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); | 410 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); |
309 EXPECT_FALSE(IsSessionStartTimePrefSet()); | 411 EXPECT_FALSE(IsSessionStartTimePrefSet()); |
310 DestroySessionLengthLimiter(); | 412 DestroySessionLengthLimiter(); |
311 | 413 |
312 // Pref indicating user activity set. Session start time valid. | 414 // Pref indicating user activity set. Session start time valid. |
313 SetSessionUserActivitySeenPref(true); | 415 SetSessionUserActivitySeenPref(true); |
314 SetSessionStartTimePref( | 416 SetSessionStartTimePref( |
315 runner_->GetCurrentMockTime() - base::TimeDelta::FromHours(2)); | 417 runner_->GetCurrentTime() - base::TimeDelta::FromHours(2)); |
316 CreateSessionLengthLimiter(false); | 418 CreateSessionLengthLimiter(false); |
317 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); | 419 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); |
318 EXPECT_FALSE(IsSessionStartTimePrefSet()); | 420 EXPECT_FALSE(IsSessionStartTimePrefSet()); |
319 DestroySessionLengthLimiter(); | 421 DestroySessionLengthLimiter(); |
320 } | 422 } |
321 | 423 |
322 // Verifies that when not instructed to wait for initial user activity, local | 424 // Verifies that when not instructed to wait for initial user activity, local |
323 // state is correctly updated during restart after a crash: | 425 // state is correctly updated during restart after a crash: |
324 // * If no valid session start time is found in local state, the session start | 426 // * If no valid session start time is found in local state, the session start |
325 // time is set and the pref indicating user activity is cleared. | 427 // time is set and the pref indicating user activity is cleared. |
(...skipping 12 matching lines...) Expand all Loading... |
338 SetSessionUserActivitySeenPref(true); | 440 SetSessionUserActivitySeenPref(true); |
339 ClearSessionStartTimePref(); | 441 ClearSessionStartTimePref(); |
340 CreateSessionLengthLimiter(true); | 442 CreateSessionLengthLimiter(true); |
341 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); | 443 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); |
342 EXPECT_EQ(session_start_time_, GetSessionStartTimePref()); | 444 EXPECT_EQ(session_start_time_, GetSessionStartTimePref()); |
343 DestroySessionLengthLimiter(); | 445 DestroySessionLengthLimiter(); |
344 | 446 |
345 // Pref indicating user activity not set. Session start time in the future. | 447 // Pref indicating user activity not set. Session start time in the future. |
346 ClearSessionUserActivitySeenPref(); | 448 ClearSessionUserActivitySeenPref(); |
347 SetSessionStartTimePref( | 449 SetSessionStartTimePref( |
348 runner_->GetCurrentMockTime() + base::TimeDelta::FromHours(2)); | 450 runner_->GetCurrentTime() + base::TimeDelta::FromHours(2)); |
349 CreateSessionLengthLimiter(true); | 451 CreateSessionLengthLimiter(true); |
350 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); | 452 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); |
351 EXPECT_EQ(session_start_time_, GetSessionStartTimePref()); | 453 EXPECT_EQ(session_start_time_, GetSessionStartTimePref()); |
352 DestroySessionLengthLimiter(); | 454 DestroySessionLengthLimiter(); |
353 | 455 |
354 // Pref indicating user activity set. Session start time in the future. | 456 // Pref indicating user activity set. Session start time in the future. |
355 SetSessionUserActivitySeenPref(true); | 457 SetSessionUserActivitySeenPref(true); |
356 SetSessionStartTimePref( | 458 SetSessionStartTimePref( |
357 runner_->GetCurrentMockTime() + base::TimeDelta::FromHours(2)); | 459 runner_->GetCurrentTime() + base::TimeDelta::FromHours(2)); |
358 CreateSessionLengthLimiter(true); | 460 CreateSessionLengthLimiter(true); |
359 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); | 461 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); |
360 EXPECT_EQ(session_start_time_, GetSessionStartTimePref()); | 462 EXPECT_EQ(session_start_time_, GetSessionStartTimePref()); |
361 DestroySessionLengthLimiter(); | 463 DestroySessionLengthLimiter(); |
362 | 464 |
363 const base::TimeTicks stored_session_start_time = | 465 const base::TimeTicks stored_session_start_time = |
364 runner_->GetCurrentMockTime() - base::TimeDelta::FromHours(2); | 466 runner_->GetCurrentTime() - base::TimeDelta::FromHours(2); |
365 | 467 |
366 // Pref indicating user activity not set. Session start time valid. | 468 // Pref indicating user activity not set. Session start time valid. |
367 ClearSessionUserActivitySeenPref(); | 469 ClearSessionUserActivitySeenPref(); |
368 SetSessionStartTimePref(stored_session_start_time); | 470 SetSessionStartTimePref(stored_session_start_time); |
369 CreateSessionLengthLimiter(true); | 471 CreateSessionLengthLimiter(true); |
370 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); | 472 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); |
371 EXPECT_EQ(stored_session_start_time, GetSessionStartTimePref()); | 473 EXPECT_EQ(stored_session_start_time, GetSessionStartTimePref()); |
372 DestroySessionLengthLimiter(); | 474 DestroySessionLengthLimiter(); |
373 | 475 |
374 // Pref indicating user activity set. Session start time valid. | 476 // Pref indicating user activity set. Session start time valid. |
(...skipping 27 matching lines...) Expand all Loading... |
402 SetSessionUserActivitySeenPref(true); | 504 SetSessionUserActivitySeenPref(true); |
403 ClearSessionStartTimePref(); | 505 ClearSessionStartTimePref(); |
404 CreateSessionLengthLimiter(true); | 506 CreateSessionLengthLimiter(true); |
405 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); | 507 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); |
406 EXPECT_FALSE(IsSessionStartTimePrefSet()); | 508 EXPECT_FALSE(IsSessionStartTimePrefSet()); |
407 DestroySessionLengthLimiter(); | 509 DestroySessionLengthLimiter(); |
408 | 510 |
409 // Pref indicating user activity not set. Session start time in the future. | 511 // Pref indicating user activity not set. Session start time in the future. |
410 ClearSessionUserActivitySeenPref(); | 512 ClearSessionUserActivitySeenPref(); |
411 SetSessionStartTimePref( | 513 SetSessionStartTimePref( |
412 runner_->GetCurrentMockTime() + base::TimeDelta::FromHours(2)); | 514 runner_->GetCurrentTime() + base::TimeDelta::FromHours(2)); |
413 CreateSessionLengthLimiter(true); | 515 CreateSessionLengthLimiter(true); |
414 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); | 516 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); |
415 EXPECT_FALSE(IsSessionStartTimePrefSet()); | 517 EXPECT_FALSE(IsSessionStartTimePrefSet()); |
416 DestroySessionLengthLimiter(); | 518 DestroySessionLengthLimiter(); |
417 | 519 |
418 // Pref indicating user activity set. Session start time in the future. | 520 // Pref indicating user activity set. Session start time in the future. |
419 SetSessionUserActivitySeenPref(true); | 521 SetSessionUserActivitySeenPref(true); |
420 SetSessionStartTimePref( | 522 SetSessionStartTimePref( |
421 runner_->GetCurrentMockTime() + base::TimeDelta::FromHours(2)); | 523 runner_->GetCurrentTime() + base::TimeDelta::FromHours(2)); |
422 CreateSessionLengthLimiter(true); | 524 CreateSessionLengthLimiter(true); |
423 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); | 525 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); |
424 EXPECT_FALSE(IsSessionStartTimePrefSet()); | 526 EXPECT_FALSE(IsSessionStartTimePrefSet()); |
425 DestroySessionLengthLimiter(); | 527 DestroySessionLengthLimiter(); |
426 | 528 |
427 const base::TimeTicks stored_session_start_time = | 529 const base::TimeTicks stored_session_start_time = |
428 runner_->GetCurrentMockTime() - base::TimeDelta::FromHours(2); | 530 runner_->GetCurrentTime() - base::TimeDelta::FromHours(2); |
429 | 531 |
430 // Pref indicating user activity not set. Session start time valid. | 532 // Pref indicating user activity not set. Session start time valid. |
431 ClearSessionUserActivitySeenPref(); | 533 ClearSessionUserActivitySeenPref(); |
432 SetSessionStartTimePref(stored_session_start_time); | 534 SetSessionStartTimePref(stored_session_start_time); |
433 CreateSessionLengthLimiter(true); | 535 CreateSessionLengthLimiter(true); |
434 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); | 536 EXPECT_FALSE(IsSessionUserActivitySeenPrefSet()); |
435 EXPECT_EQ(stored_session_start_time, GetSessionStartTimePref()); | 537 EXPECT_EQ(stored_session_start_time, GetSessionStartTimePref()); |
436 DestroySessionLengthLimiter(); | 538 DestroySessionLengthLimiter(); |
437 | 539 |
438 // Pref indicating user activity set. Session start time valid. | 540 // Pref indicating user activity set. Session start time valid. |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 runner_->FastForwardBy(base::TimeDelta::FromSeconds(50)); | 841 runner_->FastForwardBy(base::TimeDelta::FromSeconds(50)); |
740 | 842 |
741 // Remove the session length limit. | 843 // Remove the session length limit. |
742 ClearSessionLengthLimitPref(); | 844 ClearSessionLengthLimitPref(); |
743 | 845 |
744 // Verify that no timer fires to terminate the session. | 846 // Verify that no timer fires to terminate the session. |
745 runner_->FastForwardUntilNoTasksRemain(); | 847 runner_->FastForwardUntilNoTasksRemain(); |
746 } | 848 } |
747 | 849 |
748 } // namespace chromeos | 850 } // namespace chromeos |
OLD | NEW |