| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/login/saml/saml_offline_signin_limiter.h" | 5 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/prefs/testing_pref_service.h" |
| 9 #include "base/test/simple_test_clock.h" | 10 #include "base/test/simple_test_clock.h" |
| 10 #include "base/test/test_simple_task_runner.h" | 11 #include "base/test/test_simple_task_runner.h" |
| 11 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 12 #include "base/time/clock.h" | 13 #include "base/time/clock.h" |
| 13 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_factory
.h" | 14 #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/mock_user_manager.h" |
| 15 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/test/base/testing_browser_process.h" | 19 #include "chrome/test/base/testing_browser_process.h" |
| 19 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 20 #include "components/pref_registry/pref_registry_syncable.h" | 21 #include "components/pref_registry/pref_registry_syncable.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 using testing::Mock; | 25 using testing::Mock; |
| 25 using testing::ReturnRef; | 26 using testing::Return; |
| 26 using testing::Sequence; | 27 using testing::Sequence; |
| 27 using testing::_; | 28 using testing::_; |
| 28 | 29 |
| 29 namespace chromeos { | 30 namespace chromeos { |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 const char kTestUser[] = "user@example.com"; | 33 const char kTestUser[] = "user@example.com"; |
| 33 } | 34 } |
| 34 | 35 |
| 35 class SAMLOfflineSigninLimiterTest : public testing::Test { | 36 class SAMLOfflineSigninLimiterTest : public testing::Test { |
| 36 protected: | 37 protected: |
| 37 SAMLOfflineSigninLimiterTest(); | 38 SAMLOfflineSigninLimiterTest(); |
| 38 ~SAMLOfflineSigninLimiterTest() override; | 39 ~SAMLOfflineSigninLimiterTest() override; |
| 39 | 40 |
| 40 // testing::Test: | 41 // testing::Test: |
| 41 void SetUp() override; | 42 void SetUp() override; |
| 42 void TearDown() override; | 43 void TearDown() override; |
| 43 | 44 |
| 44 void DestroyLimiter(); | 45 void DestroyLimiter(); |
| 45 void CreateLimiter(); | 46 void CreateLimiter(); |
| 46 | 47 |
| 48 void SetUpUserManager(); |
| 49 TestingPrefServiceSimple* GetTestingLocalState(); |
| 50 |
| 47 scoped_refptr<base::TestSimpleTaskRunner> runner_; | 51 scoped_refptr<base::TestSimpleTaskRunner> runner_; |
| 48 base::ThreadTaskRunnerHandle runner_handle_; | 52 base::ThreadTaskRunnerHandle runner_handle_; |
| 49 | 53 |
| 50 MockUserManager* user_manager_; // Not owned. | 54 MockUserManager* user_manager_; // Not owned. |
| 51 ScopedUserManagerEnabler user_manager_enabler_; | 55 ScopedUserManagerEnabler user_manager_enabler_; |
| 52 | 56 |
| 53 scoped_ptr<TestingProfile> profile_; | 57 scoped_ptr<TestingProfile> profile_; |
| 54 base::SimpleTestClock clock_; | 58 base::SimpleTestClock clock_; |
| 55 | 59 |
| 56 SAMLOfflineSigninLimiter* limiter_; // Owned. | 60 SAMLOfflineSigninLimiter* limiter_; // Owned. |
| 57 | 61 |
| 62 TestingPrefServiceSimple testing_local_state_; |
| 63 |
| 58 DISALLOW_COPY_AND_ASSIGN(SAMLOfflineSigninLimiterTest); | 64 DISALLOW_COPY_AND_ASSIGN(SAMLOfflineSigninLimiterTest); |
| 59 }; | 65 }; |
| 60 | 66 |
| 61 SAMLOfflineSigninLimiterTest::SAMLOfflineSigninLimiterTest() | 67 SAMLOfflineSigninLimiterTest::SAMLOfflineSigninLimiterTest() |
| 62 : runner_(new base::TestSimpleTaskRunner), | 68 : runner_(new base::TestSimpleTaskRunner), |
| 63 runner_handle_(runner_), | 69 runner_handle_(runner_), |
| 64 user_manager_(new MockUserManager), | 70 user_manager_(new MockUserManager), |
| 65 user_manager_enabler_(user_manager_), | 71 user_manager_enabler_(user_manager_), |
| 66 limiter_(NULL) { | 72 limiter_(NULL) { |
| 67 } | 73 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 81 delete limiter_; | 87 delete limiter_; |
| 82 limiter_ = NULL; | 88 limiter_ = NULL; |
| 83 } | 89 } |
| 84 } | 90 } |
| 85 | 91 |
| 86 void SAMLOfflineSigninLimiterTest::CreateLimiter() { | 92 void SAMLOfflineSigninLimiterTest::CreateLimiter() { |
| 87 DestroyLimiter(); | 93 DestroyLimiter(); |
| 88 limiter_ = new SAMLOfflineSigninLimiter(profile_.get(), &clock_); | 94 limiter_ = new SAMLOfflineSigninLimiter(profile_.get(), &clock_); |
| 89 } | 95 } |
| 90 | 96 |
| 97 void SAMLOfflineSigninLimiterTest::SetUpUserManager() { |
| 98 EXPECT_CALL(*user_manager_, GetLocalState()) |
| 99 .WillRepeatedly(Return(GetTestingLocalState())); |
| 100 } |
| 101 |
| 91 void SAMLOfflineSigninLimiterTest::SetUp() { | 102 void SAMLOfflineSigninLimiterTest::SetUp() { |
| 92 profile_.reset(new TestingProfile); | 103 profile_.reset(new TestingProfile); |
| 93 | 104 |
| 94 SAMLOfflineSigninLimiterFactory::SetClockForTesting(&clock_); | 105 SAMLOfflineSigninLimiterFactory::SetClockForTesting(&clock_); |
| 95 user_manager_->AddUser(kTestUser); | 106 user_manager_->AddUser(kTestUser); |
| 96 profile_->set_profile_name(kTestUser); | 107 profile_->set_profile_name(kTestUser); |
| 97 clock_.Advance(base::TimeDelta::FromHours(1)); | 108 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 109 |
| 110 user_manager_->RegisterPrefs(GetTestingLocalState()->registry()); |
| 111 SetUpUserManager(); |
| 112 } |
| 113 |
| 114 TestingPrefServiceSimple* SAMLOfflineSigninLimiterTest::GetTestingLocalState() { |
| 115 return &testing_local_state_; |
| 98 } | 116 } |
| 99 | 117 |
| 100 void SAMLOfflineSigninLimiterTest::TearDown() { | 118 void SAMLOfflineSigninLimiterTest::TearDown() { |
| 101 SAMLOfflineSigninLimiterFactory::SetClockForTesting(NULL); | 119 SAMLOfflineSigninLimiterFactory::SetClockForTesting(NULL); |
| 102 } | 120 } |
| 103 | 121 |
| 104 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLDefaultLimit) { | 122 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLDefaultLimit) { |
| 105 PrefService* prefs = profile_->GetPrefs(); | 123 PrefService* prefs = profile_->GetPrefs(); |
| 106 | 124 |
| 107 // Set the time of last login with SAML. | 125 // Set the time of last login with SAML. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 123 // Verify that no timer is running. | 141 // Verify that no timer is running. |
| 124 EXPECT_FALSE(runner_->HasPendingTask()); | 142 EXPECT_FALSE(runner_->HasPendingTask()); |
| 125 | 143 |
| 126 // Log out. Verify that the flag enforcing online login is not set. | 144 // Log out. Verify that the flag enforcing online login is not set. |
| 127 DestroyLimiter(); | 145 DestroyLimiter(); |
| 128 | 146 |
| 129 // Authenticate offline. Verify that the flag enforcing online login is not | 147 // Authenticate offline. Verify that the flag enforcing online login is not |
| 130 // changed and the time of last login with SAML is not set. | 148 // changed and the time of last login with SAML is not set. |
| 131 CreateLimiter(); | 149 CreateLimiter(); |
| 132 Mock::VerifyAndClearExpectations(user_manager_); | 150 Mock::VerifyAndClearExpectations(user_manager_); |
| 151 SetUpUserManager(); |
| 133 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 152 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 134 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 153 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 135 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 154 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 136 | 155 |
| 137 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 156 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 138 ASSERT_TRUE(pref); | 157 ASSERT_TRUE(pref); |
| 139 EXPECT_FALSE(pref->HasUserSetting()); | 158 EXPECT_FALSE(pref->HasUserSetting()); |
| 140 | 159 |
| 141 // Verify that no timer is running. | 160 // Verify that no timer is running. |
| 142 EXPECT_FALSE(runner_->HasPendingTask()); | 161 EXPECT_FALSE(runner_->HasPendingTask()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 167 // Verify that no timer is running. | 186 // Verify that no timer is running. |
| 168 EXPECT_FALSE(runner_->HasPendingTask()); | 187 EXPECT_FALSE(runner_->HasPendingTask()); |
| 169 | 188 |
| 170 // Log out. Verify that the flag enforcing online login is not set. | 189 // Log out. Verify that the flag enforcing online login is not set. |
| 171 DestroyLimiter(); | 190 DestroyLimiter(); |
| 172 | 191 |
| 173 // Authenticate offline. Verify that the flag enforcing online login is not | 192 // Authenticate offline. Verify that the flag enforcing online login is not |
| 174 // changed and the time of last login with SAML is not set. | 193 // changed and the time of last login with SAML is not set. |
| 175 CreateLimiter(); | 194 CreateLimiter(); |
| 176 Mock::VerifyAndClearExpectations(user_manager_); | 195 Mock::VerifyAndClearExpectations(user_manager_); |
| 196 SetUpUserManager(); |
| 177 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 197 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 178 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 198 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 179 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 199 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 180 | 200 |
| 181 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 201 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 182 ASSERT_TRUE(pref); | 202 ASSERT_TRUE(pref); |
| 183 EXPECT_FALSE(pref->HasUserSetting()); | 203 EXPECT_FALSE(pref->HasUserSetting()); |
| 184 | 204 |
| 185 // Verify that no timer is running. | 205 // Verify that no timer is running. |
| 186 EXPECT_FALSE(runner_->HasPendingTask()); | 206 EXPECT_FALSE(runner_->HasPendingTask()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 211 // Verify that no timer is running. | 231 // Verify that no timer is running. |
| 212 EXPECT_FALSE(runner_->HasPendingTask()); | 232 EXPECT_FALSE(runner_->HasPendingTask()); |
| 213 | 233 |
| 214 // Log out. Verify that the flag enforcing online login is not set. | 234 // Log out. Verify that the flag enforcing online login is not set. |
| 215 DestroyLimiter(); | 235 DestroyLimiter(); |
| 216 | 236 |
| 217 // Authenticate offline. Verify that the flag enforcing online login is not | 237 // Authenticate offline. Verify that the flag enforcing online login is not |
| 218 // changed and the time of last login with SAML is not set. | 238 // changed and the time of last login with SAML is not set. |
| 219 CreateLimiter(); | 239 CreateLimiter(); |
| 220 Mock::VerifyAndClearExpectations(user_manager_); | 240 Mock::VerifyAndClearExpectations(user_manager_); |
| 241 SetUpUserManager(); |
| 221 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 242 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 222 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 243 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 223 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 244 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 224 | 245 |
| 225 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 246 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 226 ASSERT_TRUE(pref); | 247 ASSERT_TRUE(pref); |
| 227 EXPECT_FALSE(pref->HasUserSetting()); | 248 EXPECT_FALSE(pref->HasUserSetting()); |
| 228 | 249 |
| 229 // Verify that no timer is running. | 250 // Verify that no timer is running. |
| 230 EXPECT_FALSE(runner_->HasPendingTask()); | 251 EXPECT_FALSE(runner_->HasPendingTask()); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 // Log out. Verify that the flag enforcing online login is not set. | 358 // Log out. Verify that the flag enforcing online login is not set. |
| 338 DestroyLimiter(); | 359 DestroyLimiter(); |
| 339 | 360 |
| 340 // Advance time by an hour. | 361 // Advance time by an hour. |
| 341 clock_.Advance(base::TimeDelta::FromHours(1)); | 362 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 342 | 363 |
| 343 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 364 // Authenticate against GAIA with SAML. Verify that the flag enforcing online |
| 344 // login is cleared and the time of last login with SAML is updated. | 365 // login is cleared and the time of last login with SAML is updated. |
| 345 CreateLimiter(); | 366 CreateLimiter(); |
| 346 Mock::VerifyAndClearExpectations(user_manager_); | 367 Mock::VerifyAndClearExpectations(user_manager_); |
| 368 SetUpUserManager(); |
| 347 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 369 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 348 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 370 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 349 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 371 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 350 | 372 |
| 351 last_gaia_signin_time = base::Time::FromInternalValue( | 373 last_gaia_signin_time = base::Time::FromInternalValue( |
| 352 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 374 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 353 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 375 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 354 | 376 |
| 355 // Verify that the timer is running. | 377 // Verify that the timer is running. |
| 356 EXPECT_TRUE(runner_->HasPendingTask()); | 378 EXPECT_TRUE(runner_->HasPendingTask()); |
| 357 | 379 |
| 358 // Log out. Verify that the flag enforcing online login is not set. | 380 // Log out. Verify that the flag enforcing online login is not set. |
| 359 DestroyLimiter(); | 381 DestroyLimiter(); |
| 360 | 382 |
| 361 // Advance time by an hour. | 383 // Advance time by an hour. |
| 362 const base::Time gaia_signin_time = clock_.Now(); | 384 const base::Time gaia_signin_time = clock_.Now(); |
| 363 clock_.Advance(base::TimeDelta::FromHours(1)); | 385 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 364 | 386 |
| 365 // Authenticate offline. Verify that the flag enforcing online login and the | 387 // Authenticate offline. Verify that the flag enforcing online login and the |
| 366 // time of last login with SAML are not changed. | 388 // time of last login with SAML are not changed. |
| 367 CreateLimiter(); | 389 CreateLimiter(); |
| 368 Mock::VerifyAndClearExpectations(user_manager_); | 390 Mock::VerifyAndClearExpectations(user_manager_); |
| 391 SetUpUserManager(); |
| 369 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 392 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 370 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 393 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 371 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 394 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 372 | 395 |
| 373 last_gaia_signin_time = base::Time::FromInternalValue( | 396 last_gaia_signin_time = base::Time::FromInternalValue( |
| 374 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 397 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 375 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); | 398 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); |
| 376 | 399 |
| 377 // Verify that the timer is running. | 400 // Verify that the timer is running. |
| 378 EXPECT_TRUE(runner_->HasPendingTask()); | 401 EXPECT_TRUE(runner_->HasPendingTask()); |
| 379 | 402 |
| 380 // Advance time by four weeks. | 403 // Advance time by four weeks. |
| 381 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. | 404 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. |
| 382 | 405 |
| 383 // Allow the timer to fire. Verify that the flag enforcing online login is | 406 // Allow the timer to fire. Verify that the flag enforcing online login is |
| 384 // set. | 407 // set. |
| 385 Mock::VerifyAndClearExpectations(user_manager_); | 408 Mock::VerifyAndClearExpectations(user_manager_); |
| 409 SetUpUserManager(); |
| 386 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 410 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 387 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1); | 411 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1); |
| 388 runner_->RunPendingTasks(); | 412 runner_->RunPendingTasks(); |
| 389 } | 413 } |
| 390 | 414 |
| 391 TEST_F(SAMLOfflineSigninLimiterTest, SAMLNoLimit) { | 415 TEST_F(SAMLOfflineSigninLimiterTest, SAMLNoLimit) { |
| 392 PrefService* prefs = profile_->GetPrefs(); | 416 PrefService* prefs = profile_->GetPrefs(); |
| 393 | 417 |
| 394 // Remove the time limit. | 418 // Remove the time limit. |
| 395 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); | 419 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 411 // Log out. Verify that the flag enforcing online login is not set. | 435 // Log out. Verify that the flag enforcing online login is not set. |
| 412 DestroyLimiter(); | 436 DestroyLimiter(); |
| 413 | 437 |
| 414 // Advance time by an hour. | 438 // Advance time by an hour. |
| 415 clock_.Advance(base::TimeDelta::FromHours(1)); | 439 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 416 | 440 |
| 417 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 441 // Authenticate against GAIA with SAML. Verify that the flag enforcing online |
| 418 // login is cleared and the time of last login with SAML is updated. | 442 // login is cleared and the time of last login with SAML is updated. |
| 419 CreateLimiter(); | 443 CreateLimiter(); |
| 420 Mock::VerifyAndClearExpectations(user_manager_); | 444 Mock::VerifyAndClearExpectations(user_manager_); |
| 445 SetUpUserManager(); |
| 421 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 446 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 422 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 447 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 423 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 448 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 424 | 449 |
| 425 last_gaia_signin_time = base::Time::FromInternalValue( | 450 last_gaia_signin_time = base::Time::FromInternalValue( |
| 426 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 451 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 427 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 452 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 428 | 453 |
| 429 // Verify that no timer is running. | 454 // Verify that no timer is running. |
| 430 EXPECT_FALSE(runner_->HasPendingTask()); | 455 EXPECT_FALSE(runner_->HasPendingTask()); |
| 431 | 456 |
| 432 // Log out. Verify that the flag enforcing online login is not set. | 457 // Log out. Verify that the flag enforcing online login is not set. |
| 433 DestroyLimiter(); | 458 DestroyLimiter(); |
| 434 | 459 |
| 435 // Advance time by an hour. | 460 // Advance time by an hour. |
| 436 const base::Time gaia_signin_time = clock_.Now(); | 461 const base::Time gaia_signin_time = clock_.Now(); |
| 437 clock_.Advance(base::TimeDelta::FromHours(1)); | 462 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 438 | 463 |
| 439 // Authenticate offline. Verify that the flag enforcing online login and the | 464 // Authenticate offline. Verify that the flag enforcing online login and the |
| 440 // time of last login with SAML are not changed. | 465 // time of last login with SAML are not changed. |
| 441 CreateLimiter(); | 466 CreateLimiter(); |
| 442 Mock::VerifyAndClearExpectations(user_manager_); | 467 Mock::VerifyAndClearExpectations(user_manager_); |
| 468 SetUpUserManager(); |
| 443 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 469 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 444 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 470 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 445 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 471 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 446 | 472 |
| 447 last_gaia_signin_time = base::Time::FromInternalValue( | 473 last_gaia_signin_time = base::Time::FromInternalValue( |
| 448 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 474 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 449 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); | 475 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); |
| 450 | 476 |
| 451 // Verify that no timer is running. | 477 // Verify that no timer is running. |
| 452 EXPECT_FALSE(runner_->HasPendingTask()); | 478 EXPECT_FALSE(runner_->HasPendingTask()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 | 517 |
| 492 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 518 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 493 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 519 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 494 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 520 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 495 | 521 |
| 496 // Verify that no timer is running. | 522 // Verify that no timer is running. |
| 497 EXPECT_FALSE(runner_->HasPendingTask()); | 523 EXPECT_FALSE(runner_->HasPendingTask()); |
| 498 | 524 |
| 499 // Set a zero time limit. Verify that the flag enforcing online login is set. | 525 // Set a zero time limit. Verify that the flag enforcing online login is set. |
| 500 Mock::VerifyAndClearExpectations(user_manager_); | 526 Mock::VerifyAndClearExpectations(user_manager_); |
| 527 SetUpUserManager(); |
| 501 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 528 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 502 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1); | 529 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1); |
| 503 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); | 530 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); |
| 504 } | 531 } |
| 505 | 532 |
| 506 TEST_F(SAMLOfflineSigninLimiterTest, SAMLRemoveLimit) { | 533 TEST_F(SAMLOfflineSigninLimiterTest, SAMLRemoveLimit) { |
| 507 PrefService* prefs = profile_->GetPrefs(); | 534 PrefService* prefs = profile_->GetPrefs(); |
| 508 | 535 |
| 509 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 536 // Authenticate against GAIA with SAML. Verify that the flag enforcing online |
| 510 // login is cleared and the time of last login with SAML is set. | 537 // login is cleared and the time of last login with SAML is set. |
| 511 CreateLimiter(); | 538 CreateLimiter(); |
| 512 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 539 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); |
| 513 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 540 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 514 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 541 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 515 | 542 |
| 516 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 543 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 517 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 544 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 518 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 545 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 519 | 546 |
| 520 // Verify that the timer is running. | 547 // Verify that the timer is running. |
| 521 EXPECT_TRUE(runner_->HasPendingTask()); | 548 EXPECT_TRUE(runner_->HasPendingTask()); |
| 522 | 549 |
| 523 // Remove the time limit. | 550 // Remove the time limit. |
| 524 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); | 551 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); |
| 525 | 552 |
| 526 // Allow the timer to fire. Verify that the flag enforcing online login is not | 553 // Allow the timer to fire. Verify that the flag enforcing online login is not |
| 527 // changed. | 554 // changed. |
| 528 Mock::VerifyAndClearExpectations(user_manager_); | 555 Mock::VerifyAndClearExpectations(user_manager_); |
| 556 SetUpUserManager(); |
| 529 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 557 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 530 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 558 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); |
| 531 runner_->RunUntilIdle(); | 559 runner_->RunUntilIdle(); |
| 532 } | 560 } |
| 533 | 561 |
| 534 TEST_F(SAMLOfflineSigninLimiterTest, SAMLLogInWithExpiredLimit) { | 562 TEST_F(SAMLOfflineSigninLimiterTest, SAMLLogInWithExpiredLimit) { |
| 535 PrefService* prefs = profile_->GetPrefs(); | 563 PrefService* prefs = profile_->GetPrefs(); |
| 536 | 564 |
| 537 // Set the time of last login with SAML. | 565 // Set the time of last login with SAML. |
| 538 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 566 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 601 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); |
| 574 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1); | 602 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1); |
| 575 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 603 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 576 | 604 |
| 577 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 605 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 578 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 606 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 579 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); | 607 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); |
| 580 } | 608 } |
| 581 | 609 |
| 582 } // namespace chromeos | 610 } // namespace chromeos |
| OLD | NEW |