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/prefs/testing_pref_service.h"
10 #include "base/test/simple_test_clock.h"
11 #include "base/test/test_simple_task_runner.h"
12 #include "base/thread_task_runner_handle.h"
13 #include "base/time/clock.h"
14 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_factory.h"
15 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/pref_names.h"
19 #include "chrome/test/base/testing_browser_process.h"
20 #include "chrome/test/base/testing_profile.h"
21 #include "components/pref_registry/pref_registry_syncable.h"
22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h"
26 using testing::Return
;
27 using testing::Sequence
;
33 const char kTestUser
[] = "user@example.com";
36 class SAMLOfflineSigninLimiterTest
: public testing::Test
{
38 SAMLOfflineSigninLimiterTest();
39 ~SAMLOfflineSigninLimiterTest() override
;
42 void SetUp() override
;
43 void TearDown() override
;
45 void DestroyLimiter();
48 void SetUpUserManager();
49 TestingPrefServiceSimple
* GetTestingLocalState();
51 scoped_refptr
<base::TestSimpleTaskRunner
> runner_
;
52 base::ThreadTaskRunnerHandle runner_handle_
;
54 MockUserManager
* user_manager_
; // Not owned.
55 ScopedUserManagerEnabler user_manager_enabler_
;
57 scoped_ptr
<TestingProfile
> profile_
;
58 base::SimpleTestClock clock_
;
60 SAMLOfflineSigninLimiter
* limiter_
; // Owned.
62 TestingPrefServiceSimple testing_local_state_
;
64 DISALLOW_COPY_AND_ASSIGN(SAMLOfflineSigninLimiterTest
);
67 SAMLOfflineSigninLimiterTest::SAMLOfflineSigninLimiterTest()
68 : runner_(new base::TestSimpleTaskRunner
),
69 runner_handle_(runner_
),
70 user_manager_(new MockUserManager
),
71 user_manager_enabler_(user_manager_
),
75 SAMLOfflineSigninLimiterTest::~SAMLOfflineSigninLimiterTest() {
77 Mock::VerifyAndClearExpectations(user_manager_
);
78 EXPECT_CALL(*user_manager_
, Shutdown()).Times(1);
79 EXPECT_CALL(*user_manager_
, RemoveSessionStateObserver(_
)).Times(1);
81 TestingBrowserProcess::DeleteInstance();
84 void SAMLOfflineSigninLimiterTest::DestroyLimiter() {
92 void SAMLOfflineSigninLimiterTest::CreateLimiter() {
94 limiter_
= new SAMLOfflineSigninLimiter(profile_
.get(), &clock_
);
97 void SAMLOfflineSigninLimiterTest::SetUpUserManager() {
98 EXPECT_CALL(*user_manager_
, GetLocalState())
99 .WillRepeatedly(Return(GetTestingLocalState()));
102 void SAMLOfflineSigninLimiterTest::SetUp() {
103 profile_
.reset(new TestingProfile
);
105 SAMLOfflineSigninLimiterFactory::SetClockForTesting(&clock_
);
106 user_manager_
->AddUser(kTestUser
);
107 profile_
->set_profile_name(kTestUser
);
108 clock_
.Advance(base::TimeDelta::FromHours(1));
110 user_manager_
->RegisterPrefs(GetTestingLocalState()->registry());
114 TestingPrefServiceSimple
* SAMLOfflineSigninLimiterTest::GetTestingLocalState() {
115 return &testing_local_state_
;
118 void SAMLOfflineSigninLimiterTest::TearDown() {
119 SAMLOfflineSigninLimiterFactory::SetClockForTesting(NULL
);
122 TEST_F(SAMLOfflineSigninLimiterTest
, NoSAMLDefaultLimit
) {
123 PrefService
* prefs
= profile_
->GetPrefs();
125 // Set the time of last login with SAML.
126 prefs
->SetInt64(prefs::kSAMLLastGAIASignInTime
,
127 clock_
.Now().ToInternalValue());
129 // Authenticate against GAIA without SAML. Verify that the flag enforcing
130 // online login and the time of last login with SAML are cleared.
132 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(1);
133 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
134 limiter_
->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML
);
136 const PrefService::Preference
* pref
=
137 prefs
->FindPreference(prefs::kSAMLLastGAIASignInTime
);
139 EXPECT_FALSE(pref
->HasUserSetting());
141 // Verify that no timer is running.
142 EXPECT_FALSE(runner_
->HasPendingTask());
144 // Log out. Verify that the flag enforcing online login is not set.
147 // Authenticate offline. Verify that the flag enforcing online login is not
148 // changed and the time of last login with SAML is not set.
150 Mock::VerifyAndClearExpectations(user_manager_
);
152 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(0);
153 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
154 limiter_
->SignedIn(UserContext::AUTH_FLOW_OFFLINE
);
156 pref
= prefs
->FindPreference(prefs::kSAMLLastGAIASignInTime
);
158 EXPECT_FALSE(pref
->HasUserSetting());
160 // Verify that no timer is running.
161 EXPECT_FALSE(runner_
->HasPendingTask());
164 TEST_F(SAMLOfflineSigninLimiterTest
, NoSAMLNoLimit
) {
165 PrefService
* prefs
= profile_
->GetPrefs();
167 // Remove the time limit.
168 prefs
->SetInteger(prefs::kSAMLOfflineSigninTimeLimit
, -1);
170 // Set the time of last login with SAML.
171 prefs
->SetInt64(prefs::kSAMLLastGAIASignInTime
,
172 clock_
.Now().ToInternalValue());
174 // Authenticate against GAIA without SAML. Verify that the flag enforcing
175 // online login and the time of last login with SAML are cleared.
177 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(1);
178 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
179 limiter_
->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML
);
181 const PrefService::Preference
* pref
=
182 prefs
->FindPreference(prefs::kSAMLLastGAIASignInTime
);
184 EXPECT_FALSE(pref
->HasUserSetting());
186 // Verify that no timer is running.
187 EXPECT_FALSE(runner_
->HasPendingTask());
189 // Log out. Verify that the flag enforcing online login is not set.
192 // Authenticate offline. Verify that the flag enforcing online login is not
193 // changed and the time of last login with SAML is not set.
195 Mock::VerifyAndClearExpectations(user_manager_
);
197 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(0);
198 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
199 limiter_
->SignedIn(UserContext::AUTH_FLOW_OFFLINE
);
201 pref
= prefs
->FindPreference(prefs::kSAMLLastGAIASignInTime
);
203 EXPECT_FALSE(pref
->HasUserSetting());
205 // Verify that no timer is running.
206 EXPECT_FALSE(runner_
->HasPendingTask());
209 TEST_F(SAMLOfflineSigninLimiterTest
, NoSAMLZeroLimit
) {
210 PrefService
* prefs
= profile_
->GetPrefs();
212 // Set a zero time limit.
213 prefs
->SetInteger(prefs::kSAMLOfflineSigninTimeLimit
, 0);
215 // Set the time of last login with SAML.
216 prefs
->SetInt64(prefs::kSAMLLastGAIASignInTime
,
217 clock_
.Now().ToInternalValue());
219 // Authenticate against GAIA without SAML. Verify that the flag enforcing
220 // online login and the time of last login with SAML are cleared.
222 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(1);
223 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
224 limiter_
->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML
);
226 const PrefService::Preference
* pref
=
227 prefs
->FindPreference(prefs::kSAMLLastGAIASignInTime
);
229 EXPECT_FALSE(pref
->HasUserSetting());
231 // Verify that no timer is running.
232 EXPECT_FALSE(runner_
->HasPendingTask());
234 // Log out. Verify that the flag enforcing online login is not set.
237 // Authenticate offline. Verify that the flag enforcing online login is not
238 // changed and the time of last login with SAML is not set.
240 Mock::VerifyAndClearExpectations(user_manager_
);
242 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(0);
243 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
244 limiter_
->SignedIn(UserContext::AUTH_FLOW_OFFLINE
);
246 pref
= prefs
->FindPreference(prefs::kSAMLLastGAIASignInTime
);
248 EXPECT_FALSE(pref
->HasUserSetting());
250 // Verify that no timer is running.
251 EXPECT_FALSE(runner_
->HasPendingTask());
254 TEST_F(SAMLOfflineSigninLimiterTest
, NoSAMLSetLimitWhileLoggedIn
) {
255 PrefService
* prefs
= profile_
->GetPrefs();
257 // Remove the time limit.
258 prefs
->SetInteger(prefs::kSAMLOfflineSigninTimeLimit
, -1);
260 // Set the time of last login with SAML.
261 prefs
->SetInt64(prefs::kSAMLLastGAIASignInTime
,
262 clock_
.Now().ToInternalValue());
264 // Authenticate against GAIA without SAML. Verify that the flag enforcing
265 // online login and the time of last login with SAML are cleared.
267 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(1);
268 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
269 limiter_
->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML
);
271 const PrefService::Preference
* pref
=
272 prefs
->FindPreference(prefs::kSAMLLastGAIASignInTime
);
274 EXPECT_FALSE(pref
->HasUserSetting());
276 // Verify that no timer is running.
277 EXPECT_FALSE(runner_
->HasPendingTask());
279 // Set a zero time limit.
280 prefs
->SetInteger(prefs::kSAMLOfflineSigninTimeLimit
, 0);
282 // Verify that no timer is running.
283 EXPECT_FALSE(runner_
->HasPendingTask());
286 TEST_F(SAMLOfflineSigninLimiterTest
, NoSAMLRemoveLimitWhileLoggedIn
) {
287 PrefService
* prefs
= profile_
->GetPrefs();
289 // Set the time of last login with SAML.
290 prefs
->SetInt64(prefs::kSAMLLastGAIASignInTime
,
291 clock_
.Now().ToInternalValue());
293 // Authenticate against GAIA without SAML. Verify that the flag enforcing
294 // online login and the time of last login with SAML are cleared.
296 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(1);
297 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
298 limiter_
->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML
);
300 const PrefService::Preference
* pref
=
301 prefs
->FindPreference(prefs::kSAMLLastGAIASignInTime
);
303 EXPECT_FALSE(pref
->HasUserSetting());
305 // Verify that no timer is running.
306 EXPECT_FALSE(runner_
->HasPendingTask());
308 // Remove the time limit.
309 prefs
->SetInteger(prefs::kSAMLOfflineSigninTimeLimit
, -1);
311 // Verify that no timer is running.
312 EXPECT_FALSE(runner_
->HasPendingTask());
315 TEST_F(SAMLOfflineSigninLimiterTest
, NoSAMLLogInWithExpiredLimit
) {
316 PrefService
* prefs
= profile_
->GetPrefs();
318 // Set the time of last login with SAML.
319 prefs
->SetInt64(prefs::kSAMLLastGAIASignInTime
,
320 clock_
.Now().ToInternalValue());
322 // Advance time by four weeks.
323 clock_
.Advance(base::TimeDelta::FromDays(28)); // 4 weeks.
325 // Authenticate against GAIA without SAML. Verify that the flag enforcing
326 // online login and the time of last login with SAML are cleared.
328 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(1);
329 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
330 limiter_
->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML
);
332 const PrefService::Preference
* pref
=
333 prefs
->FindPreference(prefs::kSAMLLastGAIASignInTime
);
335 EXPECT_FALSE(pref
->HasUserSetting());
337 // Verify that no timer is running.
338 EXPECT_FALSE(runner_
->HasPendingTask());
341 TEST_F(SAMLOfflineSigninLimiterTest
, SAMLDefaultLimit
) {
342 PrefService
* prefs
= profile_
->GetPrefs();
344 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
345 // login is cleared and the time of last login with SAML is set.
347 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(1);
348 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
349 limiter_
->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML
);
351 base::Time last_gaia_signin_time
= base::Time::FromInternalValue(
352 prefs
->GetInt64(prefs::kSAMLLastGAIASignInTime
));
353 EXPECT_EQ(clock_
.Now(), last_gaia_signin_time
);
355 // Verify that the timer is running.
356 EXPECT_TRUE(runner_
->HasPendingTask());
358 // Log out. Verify that the flag enforcing online login is not set.
361 // Advance time by an hour.
362 clock_
.Advance(base::TimeDelta::FromHours(1));
364 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
365 // login is cleared and the time of last login with SAML is updated.
367 Mock::VerifyAndClearExpectations(user_manager_
);
369 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(1);
370 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
371 limiter_
->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML
);
373 last_gaia_signin_time
= base::Time::FromInternalValue(
374 prefs
->GetInt64(prefs::kSAMLLastGAIASignInTime
));
375 EXPECT_EQ(clock_
.Now(), last_gaia_signin_time
);
377 // Verify that the timer is running.
378 EXPECT_TRUE(runner_
->HasPendingTask());
380 // Log out. Verify that the flag enforcing online login is not set.
383 // Advance time by an hour.
384 const base::Time gaia_signin_time
= clock_
.Now();
385 clock_
.Advance(base::TimeDelta::FromHours(1));
387 // Authenticate offline. Verify that the flag enforcing online login and the
388 // time of last login with SAML are not changed.
390 Mock::VerifyAndClearExpectations(user_manager_
);
392 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(0);
393 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
394 limiter_
->SignedIn(UserContext::AUTH_FLOW_OFFLINE
);
396 last_gaia_signin_time
= base::Time::FromInternalValue(
397 prefs
->GetInt64(prefs::kSAMLLastGAIASignInTime
));
398 EXPECT_EQ(gaia_signin_time
, last_gaia_signin_time
);
400 // Verify that the timer is running.
401 EXPECT_TRUE(runner_
->HasPendingTask());
403 // Advance time by four weeks.
404 clock_
.Advance(base::TimeDelta::FromDays(28)); // 4 weeks.
406 // Allow the timer to fire. Verify that the flag enforcing online login is
408 Mock::VerifyAndClearExpectations(user_manager_
);
410 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(0);
411 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(1);
412 runner_
->RunPendingTasks();
415 TEST_F(SAMLOfflineSigninLimiterTest
, SAMLNoLimit
) {
416 PrefService
* prefs
= profile_
->GetPrefs();
418 // Remove the time limit.
419 prefs
->SetInteger(prefs::kSAMLOfflineSigninTimeLimit
, -1);
421 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
422 // login is cleared and the time of last login with SAML is set.
424 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(1);
425 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
426 limiter_
->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML
);
428 base::Time last_gaia_signin_time
= base::Time::FromInternalValue(
429 prefs
->GetInt64(prefs::kSAMLLastGAIASignInTime
));
430 EXPECT_EQ(clock_
.Now(), last_gaia_signin_time
);
432 // Verify that no timer is running.
433 EXPECT_FALSE(runner_
->HasPendingTask());
435 // Log out. Verify that the flag enforcing online login is not set.
438 // Advance time by an hour.
439 clock_
.Advance(base::TimeDelta::FromHours(1));
441 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
442 // login is cleared and the time of last login with SAML is updated.
444 Mock::VerifyAndClearExpectations(user_manager_
);
446 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(1);
447 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
448 limiter_
->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML
);
450 last_gaia_signin_time
= base::Time::FromInternalValue(
451 prefs
->GetInt64(prefs::kSAMLLastGAIASignInTime
));
452 EXPECT_EQ(clock_
.Now(), last_gaia_signin_time
);
454 // Verify that no timer is running.
455 EXPECT_FALSE(runner_
->HasPendingTask());
457 // Log out. Verify that the flag enforcing online login is not set.
460 // Advance time by an hour.
461 const base::Time gaia_signin_time
= clock_
.Now();
462 clock_
.Advance(base::TimeDelta::FromHours(1));
464 // Authenticate offline. Verify that the flag enforcing online login and the
465 // time of last login with SAML are not changed.
467 Mock::VerifyAndClearExpectations(user_manager_
);
469 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(0);
470 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
471 limiter_
->SignedIn(UserContext::AUTH_FLOW_OFFLINE
);
473 last_gaia_signin_time
= base::Time::FromInternalValue(
474 prefs
->GetInt64(prefs::kSAMLLastGAIASignInTime
));
475 EXPECT_EQ(gaia_signin_time
, last_gaia_signin_time
);
477 // Verify that no timer is running.
478 EXPECT_FALSE(runner_
->HasPendingTask());
481 TEST_F(SAMLOfflineSigninLimiterTest
, SAMLZeroLimit
) {
482 PrefService
* prefs
= profile_
->GetPrefs();
484 // Set a zero time limit.
485 prefs
->SetInteger(prefs::kSAMLOfflineSigninTimeLimit
, 0);
487 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
488 // login is cleared and then set immediately. Also verify that the time of
489 // last login with SAML is set.
492 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false))
494 .InSequence(sequence
);
495 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true))
497 .InSequence(sequence
);
498 limiter_
->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML
);
500 const base::Time last_gaia_signin_time
= base::Time::FromInternalValue(
501 prefs
->GetInt64(prefs::kSAMLLastGAIASignInTime
));
502 EXPECT_EQ(clock_
.Now(), last_gaia_signin_time
);
505 TEST_F(SAMLOfflineSigninLimiterTest
, SAMLSetLimitWhileLoggedIn
) {
506 PrefService
* prefs
= profile_
->GetPrefs();
508 // Remove the time limit.
509 prefs
->SetInteger(prefs::kSAMLOfflineSigninTimeLimit
, -1);
511 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
512 // login is cleared and the time of last login with SAML is set.
514 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(1);
515 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
516 limiter_
->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML
);
518 const base::Time last_gaia_signin_time
= base::Time::FromInternalValue(
519 prefs
->GetInt64(prefs::kSAMLLastGAIASignInTime
));
520 EXPECT_EQ(clock_
.Now(), last_gaia_signin_time
);
522 // Verify that no timer is running.
523 EXPECT_FALSE(runner_
->HasPendingTask());
525 // Set a zero time limit. Verify that the flag enforcing online login is set.
526 Mock::VerifyAndClearExpectations(user_manager_
);
528 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(0);
529 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(1);
530 prefs
->SetInteger(prefs::kSAMLOfflineSigninTimeLimit
, 0);
533 TEST_F(SAMLOfflineSigninLimiterTest
, SAMLRemoveLimit
) {
534 PrefService
* prefs
= profile_
->GetPrefs();
536 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
537 // login is cleared and the time of last login with SAML is set.
539 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(1);
540 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
541 limiter_
->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML
);
543 const base::Time last_gaia_signin_time
= base::Time::FromInternalValue(
544 prefs
->GetInt64(prefs::kSAMLLastGAIASignInTime
));
545 EXPECT_EQ(clock_
.Now(), last_gaia_signin_time
);
547 // Verify that the timer is running.
548 EXPECT_TRUE(runner_
->HasPendingTask());
550 // Remove the time limit.
551 prefs
->SetInteger(prefs::kSAMLOfflineSigninTimeLimit
, -1);
553 // Allow the timer to fire. Verify that the flag enforcing online login is not
555 Mock::VerifyAndClearExpectations(user_manager_
);
557 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(0);
558 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
559 runner_
->RunUntilIdle();
562 TEST_F(SAMLOfflineSigninLimiterTest
, SAMLLogInWithExpiredLimit
) {
563 PrefService
* prefs
= profile_
->GetPrefs();
565 // Set the time of last login with SAML.
566 prefs
->SetInt64(prefs::kSAMLLastGAIASignInTime
,
567 clock_
.Now().ToInternalValue());
569 // Advance time by four weeks.
570 clock_
.Advance(base::TimeDelta::FromDays(28)); // 4 weeks.
572 // Authenticate against GAIA with SAML. Verify that the flag enforcing online
573 // login is cleared and the time of last login with SAML is updated.
575 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(1);
576 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(0);
577 limiter_
->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML
);
579 const base::Time last_gaia_signin_time
= base::Time::FromInternalValue(
580 prefs
->GetInt64(prefs::kSAMLLastGAIASignInTime
));
581 EXPECT_EQ(clock_
.Now(), last_gaia_signin_time
);
583 // Verify that the timer is running.
584 EXPECT_TRUE(runner_
->HasPendingTask());
587 TEST_F(SAMLOfflineSigninLimiterTest
, SAMLLogInOfflineWithExpiredLimit
) {
588 PrefService
* prefs
= profile_
->GetPrefs();
590 // Set the time of last login with SAML.
591 prefs
->SetInt64(prefs::kSAMLLastGAIASignInTime
,
592 clock_
.Now().ToInternalValue());
594 // Advance time by four weeks.
595 const base::Time gaia_signin_time
= clock_
.Now();
596 clock_
.Advance(base::TimeDelta::FromDays(28)); // 4 weeks.
598 // Authenticate offline. Verify that the flag enforcing online login is
599 // set and the time of last login with SAML is not changed.
601 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, false)).Times(0);
602 EXPECT_CALL(*user_manager_
, SaveForceOnlineSignin(kTestUser
, true)).Times(1);
603 limiter_
->SignedIn(UserContext::AUTH_FLOW_OFFLINE
);
605 const base::Time last_gaia_signin_time
= base::Time::FromInternalValue(
606 prefs
->GetInt64(prefs::kSAMLLastGAIASignInTime
));
607 EXPECT_EQ(gaia_signin_time
, last_gaia_signin_time
);
610 } // namespace chromeos