ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / login / saml / saml_offline_signin_limiter_unittest.cc
blob79695897ac8703bd7eca1f3c18dac134b368f6c1
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h"
7 #include "base/memory/ref_counted.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/test/simple_test_clock.h"
10 #include "base/test/test_simple_task_runner.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "base/time/clock.h"
13 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_factory.h"
14 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
15 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/pref_names.h"
18 #include "chrome/test/base/testing_profile.h"
19 #include "components/pref_registry/pref_registry_syncable.h"
20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h"
23 using testing::Mock;
24 using testing::ReturnRef;
25 using testing::Sequence;
27 namespace chromeos {
29 namespace {
30 const char kTestUser[] = "user@example.com";
33 class SAMLOfflineSigninLimiterTest : public testing::Test {
34 protected:
35 SAMLOfflineSigninLimiterTest();
36 ~SAMLOfflineSigninLimiterTest() override;
38 // testing::Test:
39 void SetUp() override;
40 void TearDown() override;
42 void DestroyLimiter();
43 void CreateLimiter();
45 scoped_refptr<base::TestSimpleTaskRunner> runner_;
46 base::ThreadTaskRunnerHandle runner_handle_;
48 MockUserManager* user_manager_; // Not owned.
49 ScopedUserManagerEnabler user_manager_enabler_;
51 scoped_ptr<TestingProfile> profile_;
52 base::SimpleTestClock clock_;
54 SAMLOfflineSigninLimiter* limiter_; // Owned.
56 DISALLOW_COPY_AND_ASSIGN(SAMLOfflineSigninLimiterTest);
59 SAMLOfflineSigninLimiterTest::SAMLOfflineSigninLimiterTest()
60 : runner_(new base::TestSimpleTaskRunner),
61 runner_handle_(runner_),
62 user_manager_(new MockUserManager),
63 user_manager_enabler_(user_manager_),
64 limiter_(NULL) {
67 SAMLOfflineSigninLimiterTest::~SAMLOfflineSigninLimiterTest() {
68 DestroyLimiter();
69 Mock::VerifyAndClearExpectations(user_manager_);
70 EXPECT_CALL(*user_manager_, Shutdown()).Times(1);
73 void SAMLOfflineSigninLimiterTest::DestroyLimiter() {
74 if (limiter_) {
75 limiter_->Shutdown();
76 delete limiter_;
77 limiter_ = NULL;
81 void SAMLOfflineSigninLimiterTest::CreateLimiter() {
82 DestroyLimiter();
83 limiter_ = new SAMLOfflineSigninLimiter(profile_.get(), &clock_);
86 void SAMLOfflineSigninLimiterTest::SetUp() {
87 profile_.reset(new TestingProfile);
89 SAMLOfflineSigninLimiterFactory::SetClockForTesting(&clock_);
90 user_manager_->AddUser(kTestUser);
91 profile_->set_profile_name(kTestUser);
92 clock_.Advance(base::TimeDelta::FromHours(1));
95 void SAMLOfflineSigninLimiterTest::TearDown() {
96 SAMLOfflineSigninLimiterFactory::SetClockForTesting(NULL);
99 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLDefaultLimit) {
100 PrefService* prefs = profile_->GetPrefs();
102 // Set the time of last login with SAML.
103 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
104 clock_.Now().ToInternalValue());
106 // Authenticate against GAIA without SAML. Verify that the flag enforcing
107 // online login and the time of last login with SAML are cleared.
108 CreateLimiter();
109 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
110 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
111 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
113 const PrefService::Preference* pref =
114 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
115 ASSERT_TRUE(pref);
116 EXPECT_FALSE(pref->HasUserSetting());
118 // Verify that no timer is running.
119 EXPECT_FALSE(runner_->HasPendingTask());
121 // Log out. Verify that the flag enforcing online login is not set.
122 DestroyLimiter();
124 // Authenticate offline. Verify that the flag enforcing online login is not
125 // changed and the time of last login with SAML is not set.
126 CreateLimiter();
127 Mock::VerifyAndClearExpectations(user_manager_);
128 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
129 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
130 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE);
132 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
133 ASSERT_TRUE(pref);
134 EXPECT_FALSE(pref->HasUserSetting());
136 // Verify that no timer is running.
137 EXPECT_FALSE(runner_->HasPendingTask());
140 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLNoLimit) {
141 PrefService* prefs = profile_->GetPrefs();
143 // Remove the time limit.
144 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1);
146 // Set the time of last login with SAML.
147 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
148 clock_.Now().ToInternalValue());
150 // Authenticate against GAIA without SAML. Verify that the flag enforcing
151 // online login and the time of last login with SAML are cleared.
152 CreateLimiter();
153 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
154 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
155 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
157 const PrefService::Preference* pref =
158 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
159 ASSERT_TRUE(pref);
160 EXPECT_FALSE(pref->HasUserSetting());
162 // Verify that no timer is running.
163 EXPECT_FALSE(runner_->HasPendingTask());
165 // Log out. Verify that the flag enforcing online login is not set.
166 DestroyLimiter();
168 // Authenticate offline. Verify that the flag enforcing online login is not
169 // changed and the time of last login with SAML is not set.
170 CreateLimiter();
171 Mock::VerifyAndClearExpectations(user_manager_);
172 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
173 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
174 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE);
176 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
177 ASSERT_TRUE(pref);
178 EXPECT_FALSE(pref->HasUserSetting());
180 // Verify that no timer is running.
181 EXPECT_FALSE(runner_->HasPendingTask());
184 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLZeroLimit) {
185 PrefService* prefs = profile_->GetPrefs();
187 // Set a zero time limit.
188 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0);
190 // Set the time of last login with SAML.
191 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
192 clock_.Now().ToInternalValue());
194 // Authenticate against GAIA without SAML. Verify that the flag enforcing
195 // online login and the time of last login with SAML are cleared.
196 CreateLimiter();
197 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
198 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
199 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
201 const PrefService::Preference* pref =
202 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
203 ASSERT_TRUE(pref);
204 EXPECT_FALSE(pref->HasUserSetting());
206 // Verify that no timer is running.
207 EXPECT_FALSE(runner_->HasPendingTask());
209 // Log out. Verify that the flag enforcing online login is not set.
210 DestroyLimiter();
212 // Authenticate offline. Verify that the flag enforcing online login is not
213 // changed and the time of last login with SAML is not set.
214 CreateLimiter();
215 Mock::VerifyAndClearExpectations(user_manager_);
216 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
217 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
218 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE);
220 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
221 ASSERT_TRUE(pref);
222 EXPECT_FALSE(pref->HasUserSetting());
224 // Verify that no timer is running.
225 EXPECT_FALSE(runner_->HasPendingTask());
228 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLSetLimitWhileLoggedIn) {
229 PrefService* prefs = profile_->GetPrefs();
231 // Remove the time limit.
232 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1);
234 // Set the time of last login with SAML.
235 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
236 clock_.Now().ToInternalValue());
238 // Authenticate against GAIA without SAML. Verify that the flag enforcing
239 // online login and the time of last login with SAML are cleared.
240 CreateLimiter();
241 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
242 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
243 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
245 const PrefService::Preference* pref =
246 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
247 ASSERT_TRUE(pref);
248 EXPECT_FALSE(pref->HasUserSetting());
250 // Verify that no timer is running.
251 EXPECT_FALSE(runner_->HasPendingTask());
253 // Set a zero time limit.
254 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0);
256 // Verify that no timer is running.
257 EXPECT_FALSE(runner_->HasPendingTask());
260 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLRemoveLimitWhileLoggedIn) {
261 PrefService* prefs = profile_->GetPrefs();
263 // Set the time of last login with SAML.
264 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
265 clock_.Now().ToInternalValue());
267 // Authenticate against GAIA without SAML. Verify that the flag enforcing
268 // online login and the time of last login with SAML are cleared.
269 CreateLimiter();
270 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
271 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
272 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
274 const PrefService::Preference* pref =
275 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
276 ASSERT_TRUE(pref);
277 EXPECT_FALSE(pref->HasUserSetting());
279 // Verify that no timer is running.
280 EXPECT_FALSE(runner_->HasPendingTask());
282 // Remove the time limit.
283 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1);
285 // Verify that no timer is running.
286 EXPECT_FALSE(runner_->HasPendingTask());
289 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLLogInWithExpiredLimit) {
290 PrefService* prefs = profile_->GetPrefs();
292 // Set the time of last login with SAML.
293 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
294 clock_.Now().ToInternalValue());
296 // Advance time by four weeks.
297 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks.
299 // Authenticate against GAIA without SAML. Verify that the flag enforcing
300 // online login and the time of last login with SAML are cleared.
301 CreateLimiter();
302 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
303 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
304 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
306 const PrefService::Preference* pref =
307 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime);
308 ASSERT_TRUE(pref);
309 EXPECT_FALSE(pref->HasUserSetting());
311 // Verify that no timer is running.
312 EXPECT_FALSE(runner_->HasPendingTask());
315 TEST_F(SAMLOfflineSigninLimiterTest, SAMLDefaultLimit) {
316 PrefService* prefs = profile_->GetPrefs();
318 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
319 // login is cleared and the time of last login with SAML is set.
320 CreateLimiter();
321 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
322 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
323 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
325 base::Time last_gaia_signin_time = base::Time::FromInternalValue(
326 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
327 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
329 // Verify that the timer is running.
330 EXPECT_TRUE(runner_->HasPendingTask());
332 // Log out. Verify that the flag enforcing online login is not set.
333 DestroyLimiter();
335 // Advance time by an hour.
336 clock_.Advance(base::TimeDelta::FromHours(1));
338 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
339 // login is cleared and the time of last login with SAML is updated.
340 CreateLimiter();
341 Mock::VerifyAndClearExpectations(user_manager_);
342 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
343 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
344 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
346 last_gaia_signin_time = base::Time::FromInternalValue(
347 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
348 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
350 // Verify that the timer is running.
351 EXPECT_TRUE(runner_->HasPendingTask());
353 // Log out. Verify that the flag enforcing online login is not set.
354 DestroyLimiter();
356 // Advance time by an hour.
357 const base::Time gaia_signin_time = clock_.Now();
358 clock_.Advance(base::TimeDelta::FromHours(1));
360 // Authenticate offline. Verify that the flag enforcing online login and the
361 // time of last login with SAML are not changed.
362 CreateLimiter();
363 Mock::VerifyAndClearExpectations(user_manager_);
364 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
365 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
366 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE);
368 last_gaia_signin_time = base::Time::FromInternalValue(
369 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
370 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time);
372 // Verify that the timer is running.
373 EXPECT_TRUE(runner_->HasPendingTask());
375 // Advance time by four weeks.
376 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks.
378 // Allow the timer to fire. Verify that the flag enforcing online login is
379 // set.
380 Mock::VerifyAndClearExpectations(user_manager_);
381 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
382 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1);
383 runner_->RunPendingTasks();
386 TEST_F(SAMLOfflineSigninLimiterTest, SAMLNoLimit) {
387 PrefService* prefs = profile_->GetPrefs();
389 // Remove the time limit.
390 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1);
392 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
393 // login is cleared and the time of last login with SAML is set.
394 CreateLimiter();
395 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
396 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
397 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
399 base::Time last_gaia_signin_time = base::Time::FromInternalValue(
400 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
401 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
403 // Verify that no timer is running.
404 EXPECT_FALSE(runner_->HasPendingTask());
406 // Log out. Verify that the flag enforcing online login is not set.
407 DestroyLimiter();
409 // Advance time by an hour.
410 clock_.Advance(base::TimeDelta::FromHours(1));
412 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
413 // login is cleared and the time of last login with SAML is updated.
414 CreateLimiter();
415 Mock::VerifyAndClearExpectations(user_manager_);
416 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
417 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
418 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
420 last_gaia_signin_time = base::Time::FromInternalValue(
421 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
422 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
424 // Verify that no timer is running.
425 EXPECT_FALSE(runner_->HasPendingTask());
427 // Log out. Verify that the flag enforcing online login is not set.
428 DestroyLimiter();
430 // Advance time by an hour.
431 const base::Time gaia_signin_time = clock_.Now();
432 clock_.Advance(base::TimeDelta::FromHours(1));
434 // Authenticate offline. Verify that the flag enforcing online login and the
435 // time of last login with SAML are not changed.
436 CreateLimiter();
437 Mock::VerifyAndClearExpectations(user_manager_);
438 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
439 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
440 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE);
442 last_gaia_signin_time = base::Time::FromInternalValue(
443 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
444 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time);
446 // Verify that no timer is running.
447 EXPECT_FALSE(runner_->HasPendingTask());
450 TEST_F(SAMLOfflineSigninLimiterTest, SAMLZeroLimit) {
451 PrefService* prefs = profile_->GetPrefs();
453 // Set a zero time limit.
454 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0);
456 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
457 // login is cleared and then set immediately. Also verify that the time of
458 // last login with SAML is set.
459 CreateLimiter();
460 Sequence sequence;
461 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false))
462 .Times(1)
463 .InSequence(sequence);
464 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true))
465 .Times(1)
466 .InSequence(sequence);
467 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
469 const base::Time last_gaia_signin_time = base::Time::FromInternalValue(
470 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
471 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
474 TEST_F(SAMLOfflineSigninLimiterTest, SAMLSetLimitWhileLoggedIn) {
475 PrefService* prefs = profile_->GetPrefs();
477 // Remove the time limit.
478 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1);
480 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
481 // login is cleared and the time of last login with SAML is set.
482 CreateLimiter();
483 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
484 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
485 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
487 const base::Time last_gaia_signin_time = base::Time::FromInternalValue(
488 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
489 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
491 // Verify that no timer is running.
492 EXPECT_FALSE(runner_->HasPendingTask());
494 // Set a zero time limit. Verify that the flag enforcing online login is set.
495 Mock::VerifyAndClearExpectations(user_manager_);
496 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
497 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1);
498 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0);
501 TEST_F(SAMLOfflineSigninLimiterTest, SAMLRemoveLimit) {
502 PrefService* prefs = profile_->GetPrefs();
504 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
505 // login is cleared and the time of last login with SAML is set.
506 CreateLimiter();
507 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
508 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
509 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
511 const base::Time last_gaia_signin_time = base::Time::FromInternalValue(
512 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
513 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
515 // Verify that the timer is running.
516 EXPECT_TRUE(runner_->HasPendingTask());
518 // Remove the time limit.
519 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1);
521 // Allow the timer to fire. Verify that the flag enforcing online login is not
522 // changed.
523 Mock::VerifyAndClearExpectations(user_manager_);
524 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
525 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
526 runner_->RunUntilIdle();
529 TEST_F(SAMLOfflineSigninLimiterTest, SAMLLogInWithExpiredLimit) {
530 PrefService* prefs = profile_->GetPrefs();
532 // Set the time of last login with SAML.
533 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
534 clock_.Now().ToInternalValue());
536 // Advance time by four weeks.
537 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks.
539 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
540 // login is cleared and the time of last login with SAML is updated.
541 CreateLimiter();
542 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1);
543 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0);
544 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML);
546 const base::Time last_gaia_signin_time = base::Time::FromInternalValue(
547 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
548 EXPECT_EQ(clock_.Now(), last_gaia_signin_time);
550 // Verify that the timer is running.
551 EXPECT_TRUE(runner_->HasPendingTask());
554 TEST_F(SAMLOfflineSigninLimiterTest, SAMLLogInOfflineWithExpiredLimit) {
555 PrefService* prefs = profile_->GetPrefs();
557 // Set the time of last login with SAML.
558 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime,
559 clock_.Now().ToInternalValue());
561 // Advance time by four weeks.
562 const base::Time gaia_signin_time = clock_.Now();
563 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks.
565 // Authenticate offline. Verify that the flag enforcing online login is
566 // set and the time of last login with SAML is not changed.
567 CreateLimiter();
568 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0);
569 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1);
570 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE);
572 const base::Time last_gaia_signin_time = base::Time::FromInternalValue(
573 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime));
574 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time);
577 } // namespace chromeos