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