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

Side by Side Diff: chrome/browser/chromeos/session_length_limiter_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698