Chromium Code Reviews| 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/prefs/testing_pref_service.h" |
| 10 #include "base/test/simple_test_clock.h" | 10 #include "base/test/simple_test_clock.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 ~SAMLOfflineSigninLimiterTest() override; | 39 ~SAMLOfflineSigninLimiterTest() override; |
| 40 | 40 |
| 41 // testing::Test: | 41 // testing::Test: |
| 42 void SetUp() override; | 42 void SetUp() override; |
| 43 void TearDown() override; | 43 void TearDown() override; |
| 44 | 44 |
| 45 void DestroyLimiter(); | 45 void DestroyLimiter(); |
| 46 void CreateLimiter(); | 46 void CreateLimiter(); |
| 47 | 47 |
| 48 void SetUpUserManager(); | 48 void SetUpUserManager(); |
| 49 | |
| 50 const AccountId test_account_id_; | |
|
achuithb
2015/10/23 00:08:50
in-class member initialization
Alexander Alekseev
2015/10/23 09:11:21
Done.
| |
| 51 | |
| 49 TestingPrefServiceSimple* GetTestingLocalState(); | 52 TestingPrefServiceSimple* GetTestingLocalState(); |
| 50 | 53 |
| 51 scoped_refptr<base::TestSimpleTaskRunner> runner_; | 54 scoped_refptr<base::TestSimpleTaskRunner> runner_; |
| 52 base::ThreadTaskRunnerHandle runner_handle_; | 55 base::ThreadTaskRunnerHandle runner_handle_; |
| 53 | 56 |
| 54 MockUserManager* user_manager_; // Not owned. | 57 MockUserManager* user_manager_; // Not owned. |
| 55 ScopedUserManagerEnabler user_manager_enabler_; | 58 ScopedUserManagerEnabler user_manager_enabler_; |
| 56 | 59 |
| 57 scoped_ptr<TestingProfile> profile_; | 60 scoped_ptr<TestingProfile> profile_; |
| 58 base::SimpleTestClock clock_; | 61 base::SimpleTestClock clock_; |
| 59 | 62 |
| 60 SAMLOfflineSigninLimiter* limiter_; // Owned. | 63 SAMLOfflineSigninLimiter* limiter_; // Owned. |
| 61 | 64 |
| 62 TestingPrefServiceSimple testing_local_state_; | 65 TestingPrefServiceSimple testing_local_state_; |
| 63 | 66 |
| 64 DISALLOW_COPY_AND_ASSIGN(SAMLOfflineSigninLimiterTest); | 67 DISALLOW_COPY_AND_ASSIGN(SAMLOfflineSigninLimiterTest); |
| 65 }; | 68 }; |
| 66 | 69 |
| 67 SAMLOfflineSigninLimiterTest::SAMLOfflineSigninLimiterTest() | 70 SAMLOfflineSigninLimiterTest::SAMLOfflineSigninLimiterTest() |
| 68 : runner_(new base::TestSimpleTaskRunner), | 71 : test_account_id_(AccountId::FromUserEmail(kTestUser)), |
| 72 runner_(new base::TestSimpleTaskRunner), | |
| 69 runner_handle_(runner_), | 73 runner_handle_(runner_), |
| 70 user_manager_(new MockUserManager), | 74 user_manager_(new MockUserManager), |
| 71 user_manager_enabler_(user_manager_), | 75 user_manager_enabler_(user_manager_), |
| 72 limiter_(NULL) { | 76 limiter_(NULL) {} |
| 73 } | |
| 74 | 77 |
| 75 SAMLOfflineSigninLimiterTest::~SAMLOfflineSigninLimiterTest() { | 78 SAMLOfflineSigninLimiterTest::~SAMLOfflineSigninLimiterTest() { |
| 76 DestroyLimiter(); | 79 DestroyLimiter(); |
| 77 Mock::VerifyAndClearExpectations(user_manager_); | 80 Mock::VerifyAndClearExpectations(user_manager_); |
| 78 EXPECT_CALL(*user_manager_, Shutdown()).Times(1); | 81 EXPECT_CALL(*user_manager_, Shutdown()).Times(1); |
| 79 EXPECT_CALL(*user_manager_, RemoveSessionStateObserver(_)).Times(1); | 82 EXPECT_CALL(*user_manager_, RemoveSessionStateObserver(_)).Times(1); |
| 80 profile_.reset(); | 83 profile_.reset(); |
| 81 TestingBrowserProcess::DeleteInstance(); | 84 TestingBrowserProcess::DeleteInstance(); |
| 82 } | 85 } |
| 83 | 86 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 96 | 99 |
| 97 void SAMLOfflineSigninLimiterTest::SetUpUserManager() { | 100 void SAMLOfflineSigninLimiterTest::SetUpUserManager() { |
| 98 EXPECT_CALL(*user_manager_, GetLocalState()) | 101 EXPECT_CALL(*user_manager_, GetLocalState()) |
| 99 .WillRepeatedly(Return(GetTestingLocalState())); | 102 .WillRepeatedly(Return(GetTestingLocalState())); |
| 100 } | 103 } |
| 101 | 104 |
| 102 void SAMLOfflineSigninLimiterTest::SetUp() { | 105 void SAMLOfflineSigninLimiterTest::SetUp() { |
| 103 profile_.reset(new TestingProfile); | 106 profile_.reset(new TestingProfile); |
| 104 | 107 |
| 105 SAMLOfflineSigninLimiterFactory::SetClockForTesting(&clock_); | 108 SAMLOfflineSigninLimiterFactory::SetClockForTesting(&clock_); |
| 106 user_manager_->AddUser(kTestUser); | 109 user_manager_->AddUser(test_account_id_); |
| 107 profile_->set_profile_name(kTestUser); | 110 profile_->set_profile_name(kTestUser); |
| 108 clock_.Advance(base::TimeDelta::FromHours(1)); | 111 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 109 | 112 |
| 110 user_manager_->RegisterPrefs(GetTestingLocalState()->registry()); | 113 user_manager_->RegisterPrefs(GetTestingLocalState()->registry()); |
| 111 SetUpUserManager(); | 114 SetUpUserManager(); |
| 112 } | 115 } |
| 113 | 116 |
| 114 TestingPrefServiceSimple* SAMLOfflineSigninLimiterTest::GetTestingLocalState() { | 117 TestingPrefServiceSimple* SAMLOfflineSigninLimiterTest::GetTestingLocalState() { |
| 115 return &testing_local_state_; | 118 return &testing_local_state_; |
| 116 } | 119 } |
| 117 | 120 |
| 118 void SAMLOfflineSigninLimiterTest::TearDown() { | 121 void SAMLOfflineSigninLimiterTest::TearDown() { |
| 119 SAMLOfflineSigninLimiterFactory::SetClockForTesting(NULL); | 122 SAMLOfflineSigninLimiterFactory::SetClockForTesting(NULL); |
| 120 } | 123 } |
| 121 | 124 |
| 122 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLDefaultLimit) { | 125 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLDefaultLimit) { |
| 123 PrefService* prefs = profile_->GetPrefs(); | 126 PrefService* prefs = profile_->GetPrefs(); |
| 124 | 127 |
| 125 // Set the time of last login with SAML. | 128 // Set the time of last login with SAML. |
| 126 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 129 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 127 clock_.Now().ToInternalValue()); | 130 clock_.Now().ToInternalValue()); |
| 128 | 131 |
| 129 // Authenticate against GAIA without SAML. Verify that the flag enforcing | 132 // Authenticate against GAIA without SAML. Verify that the flag enforcing |
| 130 // online login and the time of last login with SAML are cleared. | 133 // online login and the time of last login with SAML are cleared. |
| 131 CreateLimiter(); | 134 CreateLimiter(); |
| 132 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 135 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 133 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 136 .Times(1); |
| 137 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 138 .Times(0); | |
| 134 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | 139 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
| 135 | 140 |
| 136 const PrefService::Preference* pref = | 141 const PrefService::Preference* pref = |
| 137 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 142 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 138 ASSERT_TRUE(pref); | 143 ASSERT_TRUE(pref); |
| 139 EXPECT_FALSE(pref->HasUserSetting()); | 144 EXPECT_FALSE(pref->HasUserSetting()); |
| 140 | 145 |
| 141 // Verify that no timer is running. | 146 // Verify that no timer is running. |
| 142 EXPECT_FALSE(runner_->HasPendingTask()); | 147 EXPECT_FALSE(runner_->HasPendingTask()); |
| 143 | 148 |
| 144 // Log out. Verify that the flag enforcing online login is not set. | 149 // Log out. Verify that the flag enforcing online login is not set. |
| 145 DestroyLimiter(); | 150 DestroyLimiter(); |
| 146 | 151 |
| 147 // Authenticate offline. Verify that the flag enforcing online login is not | 152 // Authenticate offline. Verify that the flag enforcing online login is not |
| 148 // changed and the time of last login with SAML is not set. | 153 // changed and the time of last login with SAML is not set. |
| 149 CreateLimiter(); | 154 CreateLimiter(); |
| 150 Mock::VerifyAndClearExpectations(user_manager_); | 155 Mock::VerifyAndClearExpectations(user_manager_); |
| 151 SetUpUserManager(); | 156 SetUpUserManager(); |
| 152 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 157 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 153 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 158 .Times(0); |
| 159 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 160 .Times(0); | |
| 154 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 161 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 155 | 162 |
| 156 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 163 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 157 ASSERT_TRUE(pref); | 164 ASSERT_TRUE(pref); |
| 158 EXPECT_FALSE(pref->HasUserSetting()); | 165 EXPECT_FALSE(pref->HasUserSetting()); |
| 159 | 166 |
| 160 // Verify that no timer is running. | 167 // Verify that no timer is running. |
| 161 EXPECT_FALSE(runner_->HasPendingTask()); | 168 EXPECT_FALSE(runner_->HasPendingTask()); |
| 162 } | 169 } |
| 163 | 170 |
| 164 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLNoLimit) { | 171 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLNoLimit) { |
| 165 PrefService* prefs = profile_->GetPrefs(); | 172 PrefService* prefs = profile_->GetPrefs(); |
| 166 | 173 |
| 167 // Remove the time limit. | 174 // Remove the time limit. |
| 168 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); | 175 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); |
| 169 | 176 |
| 170 // Set the time of last login with SAML. | 177 // Set the time of last login with SAML. |
| 171 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 178 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 172 clock_.Now().ToInternalValue()); | 179 clock_.Now().ToInternalValue()); |
| 173 | 180 |
| 174 // Authenticate against GAIA without SAML. Verify that the flag enforcing | 181 // Authenticate against GAIA without SAML. Verify that the flag enforcing |
| 175 // online login and the time of last login with SAML are cleared. | 182 // online login and the time of last login with SAML are cleared. |
| 176 CreateLimiter(); | 183 CreateLimiter(); |
| 177 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 184 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 178 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 185 .Times(1); |
| 186 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 187 .Times(0); | |
| 179 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | 188 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
| 180 | 189 |
| 181 const PrefService::Preference* pref = | 190 const PrefService::Preference* pref = |
| 182 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 191 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 183 ASSERT_TRUE(pref); | 192 ASSERT_TRUE(pref); |
| 184 EXPECT_FALSE(pref->HasUserSetting()); | 193 EXPECT_FALSE(pref->HasUserSetting()); |
| 185 | 194 |
| 186 // Verify that no timer is running. | 195 // Verify that no timer is running. |
| 187 EXPECT_FALSE(runner_->HasPendingTask()); | 196 EXPECT_FALSE(runner_->HasPendingTask()); |
| 188 | 197 |
| 189 // Log out. Verify that the flag enforcing online login is not set. | 198 // Log out. Verify that the flag enforcing online login is not set. |
| 190 DestroyLimiter(); | 199 DestroyLimiter(); |
| 191 | 200 |
| 192 // Authenticate offline. Verify that the flag enforcing online login is not | 201 // Authenticate offline. Verify that the flag enforcing online login is not |
| 193 // changed and the time of last login with SAML is not set. | 202 // changed and the time of last login with SAML is not set. |
| 194 CreateLimiter(); | 203 CreateLimiter(); |
| 195 Mock::VerifyAndClearExpectations(user_manager_); | 204 Mock::VerifyAndClearExpectations(user_manager_); |
| 196 SetUpUserManager(); | 205 SetUpUserManager(); |
| 197 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 206 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 198 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 207 .Times(0); |
| 208 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 209 .Times(0); | |
| 199 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 210 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 200 | 211 |
| 201 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 212 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 202 ASSERT_TRUE(pref); | 213 ASSERT_TRUE(pref); |
| 203 EXPECT_FALSE(pref->HasUserSetting()); | 214 EXPECT_FALSE(pref->HasUserSetting()); |
| 204 | 215 |
| 205 // Verify that no timer is running. | 216 // Verify that no timer is running. |
| 206 EXPECT_FALSE(runner_->HasPendingTask()); | 217 EXPECT_FALSE(runner_->HasPendingTask()); |
| 207 } | 218 } |
| 208 | 219 |
| 209 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLZeroLimit) { | 220 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLZeroLimit) { |
| 210 PrefService* prefs = profile_->GetPrefs(); | 221 PrefService* prefs = profile_->GetPrefs(); |
| 211 | 222 |
| 212 // Set a zero time limit. | 223 // Set a zero time limit. |
| 213 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); | 224 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); |
| 214 | 225 |
| 215 // Set the time of last login with SAML. | 226 // Set the time of last login with SAML. |
| 216 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 227 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 217 clock_.Now().ToInternalValue()); | 228 clock_.Now().ToInternalValue()); |
| 218 | 229 |
| 219 // Authenticate against GAIA without SAML. Verify that the flag enforcing | 230 // Authenticate against GAIA without SAML. Verify that the flag enforcing |
| 220 // online login and the time of last login with SAML are cleared. | 231 // online login and the time of last login with SAML are cleared. |
| 221 CreateLimiter(); | 232 CreateLimiter(); |
| 222 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 233 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 223 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 234 .Times(1); |
| 235 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 236 .Times(0); | |
| 224 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | 237 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
| 225 | 238 |
| 226 const PrefService::Preference* pref = | 239 const PrefService::Preference* pref = |
| 227 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 240 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 228 ASSERT_TRUE(pref); | 241 ASSERT_TRUE(pref); |
| 229 EXPECT_FALSE(pref->HasUserSetting()); | 242 EXPECT_FALSE(pref->HasUserSetting()); |
| 230 | 243 |
| 231 // Verify that no timer is running. | 244 // Verify that no timer is running. |
| 232 EXPECT_FALSE(runner_->HasPendingTask()); | 245 EXPECT_FALSE(runner_->HasPendingTask()); |
| 233 | 246 |
| 234 // Log out. Verify that the flag enforcing online login is not set. | 247 // Log out. Verify that the flag enforcing online login is not set. |
| 235 DestroyLimiter(); | 248 DestroyLimiter(); |
| 236 | 249 |
| 237 // Authenticate offline. Verify that the flag enforcing online login is not | 250 // Authenticate offline. Verify that the flag enforcing online login is not |
| 238 // changed and the time of last login with SAML is not set. | 251 // changed and the time of last login with SAML is not set. |
| 239 CreateLimiter(); | 252 CreateLimiter(); |
| 240 Mock::VerifyAndClearExpectations(user_manager_); | 253 Mock::VerifyAndClearExpectations(user_manager_); |
| 241 SetUpUserManager(); | 254 SetUpUserManager(); |
| 242 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 255 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 243 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 256 .Times(0); |
| 257 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 258 .Times(0); | |
| 244 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 259 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 245 | 260 |
| 246 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 261 pref = prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 247 ASSERT_TRUE(pref); | 262 ASSERT_TRUE(pref); |
| 248 EXPECT_FALSE(pref->HasUserSetting()); | 263 EXPECT_FALSE(pref->HasUserSetting()); |
| 249 | 264 |
| 250 // Verify that no timer is running. | 265 // Verify that no timer is running. |
| 251 EXPECT_FALSE(runner_->HasPendingTask()); | 266 EXPECT_FALSE(runner_->HasPendingTask()); |
| 252 } | 267 } |
| 253 | 268 |
| 254 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLSetLimitWhileLoggedIn) { | 269 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLSetLimitWhileLoggedIn) { |
| 255 PrefService* prefs = profile_->GetPrefs(); | 270 PrefService* prefs = profile_->GetPrefs(); |
| 256 | 271 |
| 257 // Remove the time limit. | 272 // Remove the time limit. |
| 258 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); | 273 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); |
| 259 | 274 |
| 260 // Set the time of last login with SAML. | 275 // Set the time of last login with SAML. |
| 261 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 276 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 262 clock_.Now().ToInternalValue()); | 277 clock_.Now().ToInternalValue()); |
| 263 | 278 |
| 264 // Authenticate against GAIA without SAML. Verify that the flag enforcing | 279 // Authenticate against GAIA without SAML. Verify that the flag enforcing |
| 265 // online login and the time of last login with SAML are cleared. | 280 // online login and the time of last login with SAML are cleared. |
| 266 CreateLimiter(); | 281 CreateLimiter(); |
| 267 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 282 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 268 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 283 .Times(1); |
| 284 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 285 .Times(0); | |
| 269 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | 286 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
| 270 | 287 |
| 271 const PrefService::Preference* pref = | 288 const PrefService::Preference* pref = |
| 272 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 289 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 273 ASSERT_TRUE(pref); | 290 ASSERT_TRUE(pref); |
| 274 EXPECT_FALSE(pref->HasUserSetting()); | 291 EXPECT_FALSE(pref->HasUserSetting()); |
| 275 | 292 |
| 276 // Verify that no timer is running. | 293 // Verify that no timer is running. |
| 277 EXPECT_FALSE(runner_->HasPendingTask()); | 294 EXPECT_FALSE(runner_->HasPendingTask()); |
| 278 | 295 |
| 279 // Set a zero time limit. | 296 // Set a zero time limit. |
| 280 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); | 297 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); |
| 281 | 298 |
| 282 // Verify that no timer is running. | 299 // Verify that no timer is running. |
| 283 EXPECT_FALSE(runner_->HasPendingTask()); | 300 EXPECT_FALSE(runner_->HasPendingTask()); |
| 284 } | 301 } |
| 285 | 302 |
| 286 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLRemoveLimitWhileLoggedIn) { | 303 TEST_F(SAMLOfflineSigninLimiterTest, NoSAMLRemoveLimitWhileLoggedIn) { |
| 287 PrefService* prefs = profile_->GetPrefs(); | 304 PrefService* prefs = profile_->GetPrefs(); |
| 288 | 305 |
| 289 // Set the time of last login with SAML. | 306 // Set the time of last login with SAML. |
| 290 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 307 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 291 clock_.Now().ToInternalValue()); | 308 clock_.Now().ToInternalValue()); |
| 292 | 309 |
| 293 // Authenticate against GAIA without SAML. Verify that the flag enforcing | 310 // Authenticate against GAIA without SAML. Verify that the flag enforcing |
| 294 // online login and the time of last login with SAML are cleared. | 311 // online login and the time of last login with SAML are cleared. |
| 295 CreateLimiter(); | 312 CreateLimiter(); |
| 296 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 313 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 297 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 314 .Times(1); |
| 315 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 316 .Times(0); | |
| 298 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | 317 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
| 299 | 318 |
| 300 const PrefService::Preference* pref = | 319 const PrefService::Preference* pref = |
| 301 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 320 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 302 ASSERT_TRUE(pref); | 321 ASSERT_TRUE(pref); |
| 303 EXPECT_FALSE(pref->HasUserSetting()); | 322 EXPECT_FALSE(pref->HasUserSetting()); |
| 304 | 323 |
| 305 // Verify that no timer is running. | 324 // Verify that no timer is running. |
| 306 EXPECT_FALSE(runner_->HasPendingTask()); | 325 EXPECT_FALSE(runner_->HasPendingTask()); |
| 307 | 326 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 318 // Set the time of last login with SAML. | 337 // Set the time of last login with SAML. |
| 319 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 338 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 320 clock_.Now().ToInternalValue()); | 339 clock_.Now().ToInternalValue()); |
| 321 | 340 |
| 322 // Advance time by four weeks. | 341 // Advance time by four weeks. |
| 323 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. | 342 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. |
| 324 | 343 |
| 325 // Authenticate against GAIA without SAML. Verify that the flag enforcing | 344 // Authenticate against GAIA without SAML. Verify that the flag enforcing |
| 326 // online login and the time of last login with SAML are cleared. | 345 // online login and the time of last login with SAML are cleared. |
| 327 CreateLimiter(); | 346 CreateLimiter(); |
| 328 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 347 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 329 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 348 .Times(1); |
| 349 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 350 .Times(0); | |
| 330 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | 351 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); |
| 331 | 352 |
| 332 const PrefService::Preference* pref = | 353 const PrefService::Preference* pref = |
| 333 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); | 354 prefs->FindPreference(prefs::kSAMLLastGAIASignInTime); |
| 334 ASSERT_TRUE(pref); | 355 ASSERT_TRUE(pref); |
| 335 EXPECT_FALSE(pref->HasUserSetting()); | 356 EXPECT_FALSE(pref->HasUserSetting()); |
| 336 | 357 |
| 337 // Verify that no timer is running. | 358 // Verify that no timer is running. |
| 338 EXPECT_FALSE(runner_->HasPendingTask()); | 359 EXPECT_FALSE(runner_->HasPendingTask()); |
| 339 } | 360 } |
| 340 | 361 |
| 341 TEST_F(SAMLOfflineSigninLimiterTest, SAMLDefaultLimit) { | 362 TEST_F(SAMLOfflineSigninLimiterTest, SAMLDefaultLimit) { |
| 342 PrefService* prefs = profile_->GetPrefs(); | 363 PrefService* prefs = profile_->GetPrefs(); |
| 343 | 364 |
| 344 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 365 // 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. | 366 // login is cleared and the time of last login with SAML is set. |
| 346 CreateLimiter(); | 367 CreateLimiter(); |
| 347 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 368 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 348 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 369 .Times(1); |
| 370 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 371 .Times(0); | |
| 349 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 372 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 350 | 373 |
| 351 base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 374 base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 352 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 375 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 353 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 376 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 354 | 377 |
| 355 // Verify that the timer is running. | 378 // Verify that the timer is running. |
| 356 EXPECT_TRUE(runner_->HasPendingTask()); | 379 EXPECT_TRUE(runner_->HasPendingTask()); |
| 357 | 380 |
| 358 // Log out. Verify that the flag enforcing online login is not set. | 381 // Log out. Verify that the flag enforcing online login is not set. |
| 359 DestroyLimiter(); | 382 DestroyLimiter(); |
| 360 | 383 |
| 361 // Advance time by an hour. | 384 // Advance time by an hour. |
| 362 clock_.Advance(base::TimeDelta::FromHours(1)); | 385 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 363 | 386 |
| 364 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 387 // 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. | 388 // login is cleared and the time of last login with SAML is updated. |
| 366 CreateLimiter(); | 389 CreateLimiter(); |
| 367 Mock::VerifyAndClearExpectations(user_manager_); | 390 Mock::VerifyAndClearExpectations(user_manager_); |
| 368 SetUpUserManager(); | 391 SetUpUserManager(); |
| 369 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 392 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 370 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 393 .Times(1); |
| 394 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 395 .Times(0); | |
| 371 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 396 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 372 | 397 |
| 373 last_gaia_signin_time = base::Time::FromInternalValue( | 398 last_gaia_signin_time = base::Time::FromInternalValue( |
| 374 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 399 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 375 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 400 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 376 | 401 |
| 377 // Verify that the timer is running. | 402 // Verify that the timer is running. |
| 378 EXPECT_TRUE(runner_->HasPendingTask()); | 403 EXPECT_TRUE(runner_->HasPendingTask()); |
| 379 | 404 |
| 380 // Log out. Verify that the flag enforcing online login is not set. | 405 // Log out. Verify that the flag enforcing online login is not set. |
| 381 DestroyLimiter(); | 406 DestroyLimiter(); |
| 382 | 407 |
| 383 // Advance time by an hour. | 408 // Advance time by an hour. |
| 384 const base::Time gaia_signin_time = clock_.Now(); | 409 const base::Time gaia_signin_time = clock_.Now(); |
| 385 clock_.Advance(base::TimeDelta::FromHours(1)); | 410 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 386 | 411 |
| 387 // Authenticate offline. Verify that the flag enforcing online login and the | 412 // Authenticate offline. Verify that the flag enforcing online login and the |
| 388 // time of last login with SAML are not changed. | 413 // time of last login with SAML are not changed. |
| 389 CreateLimiter(); | 414 CreateLimiter(); |
| 390 Mock::VerifyAndClearExpectations(user_manager_); | 415 Mock::VerifyAndClearExpectations(user_manager_); |
| 391 SetUpUserManager(); | 416 SetUpUserManager(); |
| 392 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 417 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 393 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 418 .Times(0); |
| 419 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 420 .Times(0); | |
| 394 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 421 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 395 | 422 |
| 396 last_gaia_signin_time = base::Time::FromInternalValue( | 423 last_gaia_signin_time = base::Time::FromInternalValue( |
| 397 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 424 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 398 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); | 425 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); |
| 399 | 426 |
| 400 // Verify that the timer is running. | 427 // Verify that the timer is running. |
| 401 EXPECT_TRUE(runner_->HasPendingTask()); | 428 EXPECT_TRUE(runner_->HasPendingTask()); |
| 402 | 429 |
| 403 // Advance time by four weeks. | 430 // Advance time by four weeks. |
| 404 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. | 431 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. |
| 405 | 432 |
| 406 // Allow the timer to fire. Verify that the flag enforcing online login is | 433 // Allow the timer to fire. Verify that the flag enforcing online login is |
| 407 // set. | 434 // set. |
| 408 Mock::VerifyAndClearExpectations(user_manager_); | 435 Mock::VerifyAndClearExpectations(user_manager_); |
| 409 SetUpUserManager(); | 436 SetUpUserManager(); |
| 410 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 437 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 411 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1); | 438 .Times(0); |
| 439 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 440 .Times(1); | |
| 412 runner_->RunPendingTasks(); | 441 runner_->RunPendingTasks(); |
| 413 } | 442 } |
| 414 | 443 |
| 415 TEST_F(SAMLOfflineSigninLimiterTest, SAMLNoLimit) { | 444 TEST_F(SAMLOfflineSigninLimiterTest, SAMLNoLimit) { |
| 416 PrefService* prefs = profile_->GetPrefs(); | 445 PrefService* prefs = profile_->GetPrefs(); |
| 417 | 446 |
| 418 // Remove the time limit. | 447 // Remove the time limit. |
| 419 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); | 448 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); |
| 420 | 449 |
| 421 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 450 // 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. | 451 // login is cleared and the time of last login with SAML is set. |
| 423 CreateLimiter(); | 452 CreateLimiter(); |
| 424 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 453 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 425 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 454 .Times(1); |
| 455 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 456 .Times(0); | |
| 426 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 457 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 427 | 458 |
| 428 base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 459 base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 429 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 460 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 430 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 461 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 431 | 462 |
| 432 // Verify that no timer is running. | 463 // Verify that no timer is running. |
| 433 EXPECT_FALSE(runner_->HasPendingTask()); | 464 EXPECT_FALSE(runner_->HasPendingTask()); |
| 434 | 465 |
| 435 // Log out. Verify that the flag enforcing online login is not set. | 466 // Log out. Verify that the flag enforcing online login is not set. |
| 436 DestroyLimiter(); | 467 DestroyLimiter(); |
| 437 | 468 |
| 438 // Advance time by an hour. | 469 // Advance time by an hour. |
| 439 clock_.Advance(base::TimeDelta::FromHours(1)); | 470 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 440 | 471 |
| 441 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 472 // 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. | 473 // login is cleared and the time of last login with SAML is updated. |
| 443 CreateLimiter(); | 474 CreateLimiter(); |
| 444 Mock::VerifyAndClearExpectations(user_manager_); | 475 Mock::VerifyAndClearExpectations(user_manager_); |
| 445 SetUpUserManager(); | 476 SetUpUserManager(); |
| 446 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 477 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 447 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 478 .Times(1); |
| 479 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 480 .Times(0); | |
| 448 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 481 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 449 | 482 |
| 450 last_gaia_signin_time = base::Time::FromInternalValue( | 483 last_gaia_signin_time = base::Time::FromInternalValue( |
| 451 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 484 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 452 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 485 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 453 | 486 |
| 454 // Verify that no timer is running. | 487 // Verify that no timer is running. |
| 455 EXPECT_FALSE(runner_->HasPendingTask()); | 488 EXPECT_FALSE(runner_->HasPendingTask()); |
| 456 | 489 |
| 457 // Log out. Verify that the flag enforcing online login is not set. | 490 // Log out. Verify that the flag enforcing online login is not set. |
| 458 DestroyLimiter(); | 491 DestroyLimiter(); |
| 459 | 492 |
| 460 // Advance time by an hour. | 493 // Advance time by an hour. |
| 461 const base::Time gaia_signin_time = clock_.Now(); | 494 const base::Time gaia_signin_time = clock_.Now(); |
| 462 clock_.Advance(base::TimeDelta::FromHours(1)); | 495 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 463 | 496 |
| 464 // Authenticate offline. Verify that the flag enforcing online login and the | 497 // Authenticate offline. Verify that the flag enforcing online login and the |
| 465 // time of last login with SAML are not changed. | 498 // time of last login with SAML are not changed. |
| 466 CreateLimiter(); | 499 CreateLimiter(); |
| 467 Mock::VerifyAndClearExpectations(user_manager_); | 500 Mock::VerifyAndClearExpectations(user_manager_); |
| 468 SetUpUserManager(); | 501 SetUpUserManager(); |
| 469 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 502 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 470 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 503 .Times(0); |
| 504 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 505 .Times(0); | |
| 471 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 506 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 472 | 507 |
| 473 last_gaia_signin_time = base::Time::FromInternalValue( | 508 last_gaia_signin_time = base::Time::FromInternalValue( |
| 474 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 509 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 475 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); | 510 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); |
| 476 | 511 |
| 477 // Verify that no timer is running. | 512 // Verify that no timer is running. |
| 478 EXPECT_FALSE(runner_->HasPendingTask()); | 513 EXPECT_FALSE(runner_->HasPendingTask()); |
| 479 } | 514 } |
| 480 | 515 |
| 481 TEST_F(SAMLOfflineSigninLimiterTest, SAMLZeroLimit) { | 516 TEST_F(SAMLOfflineSigninLimiterTest, SAMLZeroLimit) { |
| 482 PrefService* prefs = profile_->GetPrefs(); | 517 PrefService* prefs = profile_->GetPrefs(); |
| 483 | 518 |
| 484 // Set a zero time limit. | 519 // Set a zero time limit. |
| 485 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); | 520 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); |
| 486 | 521 |
| 487 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 522 // 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 | 523 // login is cleared and then set immediately. Also verify that the time of |
| 489 // last login with SAML is set. | 524 // last login with SAML is set. |
| 490 CreateLimiter(); | 525 CreateLimiter(); |
| 491 Sequence sequence; | 526 Sequence sequence; |
| 492 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)) | 527 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 493 .Times(1) | 528 .Times(1) |
| 494 .InSequence(sequence); | 529 .InSequence(sequence); |
| 495 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)) | 530 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) |
| 496 .Times(1) | 531 .Times(1) |
| 497 .InSequence(sequence); | 532 .InSequence(sequence); |
| 498 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 533 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 499 | 534 |
| 500 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 535 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 501 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 536 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 502 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 537 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 503 } | 538 } |
| 504 | 539 |
| 505 TEST_F(SAMLOfflineSigninLimiterTest, SAMLSetLimitWhileLoggedIn) { | 540 TEST_F(SAMLOfflineSigninLimiterTest, SAMLSetLimitWhileLoggedIn) { |
| 506 PrefService* prefs = profile_->GetPrefs(); | 541 PrefService* prefs = profile_->GetPrefs(); |
| 507 | 542 |
| 508 // Remove the time limit. | 543 // Remove the time limit. |
| 509 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); | 544 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); |
| 510 | 545 |
| 511 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 546 // 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. | 547 // login is cleared and the time of last login with SAML is set. |
| 513 CreateLimiter(); | 548 CreateLimiter(); |
| 514 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 549 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 515 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 550 .Times(1); |
| 551 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 552 .Times(0); | |
| 516 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 553 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 517 | 554 |
| 518 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 555 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 519 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 556 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 520 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 557 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 521 | 558 |
| 522 // Verify that no timer is running. | 559 // Verify that no timer is running. |
| 523 EXPECT_FALSE(runner_->HasPendingTask()); | 560 EXPECT_FALSE(runner_->HasPendingTask()); |
| 524 | 561 |
| 525 // Set a zero time limit. Verify that the flag enforcing online login is set. | 562 // Set a zero time limit. Verify that the flag enforcing online login is set. |
| 526 Mock::VerifyAndClearExpectations(user_manager_); | 563 Mock::VerifyAndClearExpectations(user_manager_); |
| 527 SetUpUserManager(); | 564 SetUpUserManager(); |
| 528 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 565 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 529 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1); | 566 .Times(0); |
| 567 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 568 .Times(1); | |
| 530 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); | 569 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, 0); |
| 531 } | 570 } |
| 532 | 571 |
| 533 TEST_F(SAMLOfflineSigninLimiterTest, SAMLRemoveLimit) { | 572 TEST_F(SAMLOfflineSigninLimiterTest, SAMLRemoveLimit) { |
| 534 PrefService* prefs = profile_->GetPrefs(); | 573 PrefService* prefs = profile_->GetPrefs(); |
| 535 | 574 |
| 536 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 575 // 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. | 576 // login is cleared and the time of last login with SAML is set. |
| 538 CreateLimiter(); | 577 CreateLimiter(); |
| 539 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 578 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 540 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 579 .Times(1); |
| 580 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 581 .Times(0); | |
| 541 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 582 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 542 | 583 |
| 543 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 584 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 544 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 585 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 545 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 586 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 546 | 587 |
| 547 // Verify that the timer is running. | 588 // Verify that the timer is running. |
| 548 EXPECT_TRUE(runner_->HasPendingTask()); | 589 EXPECT_TRUE(runner_->HasPendingTask()); |
| 549 | 590 |
| 550 // Remove the time limit. | 591 // Remove the time limit. |
| 551 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); | 592 prefs->SetInteger(prefs::kSAMLOfflineSigninTimeLimit, -1); |
| 552 | 593 |
| 553 // Allow the timer to fire. Verify that the flag enforcing online login is not | 594 // Allow the timer to fire. Verify that the flag enforcing online login is not |
| 554 // changed. | 595 // changed. |
| 555 Mock::VerifyAndClearExpectations(user_manager_); | 596 Mock::VerifyAndClearExpectations(user_manager_); |
| 556 SetUpUserManager(); | 597 SetUpUserManager(); |
| 557 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 598 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 558 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 599 .Times(0); |
| 600 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 601 .Times(0); | |
| 559 runner_->RunUntilIdle(); | 602 runner_->RunUntilIdle(); |
| 560 } | 603 } |
| 561 | 604 |
| 562 TEST_F(SAMLOfflineSigninLimiterTest, SAMLLogInWithExpiredLimit) { | 605 TEST_F(SAMLOfflineSigninLimiterTest, SAMLLogInWithExpiredLimit) { |
| 563 PrefService* prefs = profile_->GetPrefs(); | 606 PrefService* prefs = profile_->GetPrefs(); |
| 564 | 607 |
| 565 // Set the time of last login with SAML. | 608 // Set the time of last login with SAML. |
| 566 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 609 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 567 clock_.Now().ToInternalValue()); | 610 clock_.Now().ToInternalValue()); |
| 568 | 611 |
| 569 // Advance time by four weeks. | 612 // Advance time by four weeks. |
| 570 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. | 613 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. |
| 571 | 614 |
| 572 // Authenticate against GAIA with SAML. Verify that the flag enforcing online | 615 // 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. | 616 // login is cleared and the time of last login with SAML is updated. |
| 574 CreateLimiter(); | 617 CreateLimiter(); |
| 575 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(1); | 618 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 576 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(0); | 619 .Times(1); |
| 620 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 621 .Times(0); | |
| 577 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); | 622 limiter_->SignedIn(UserContext::AUTH_FLOW_GAIA_WITH_SAML); |
| 578 | 623 |
| 579 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 624 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 580 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 625 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 581 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); | 626 EXPECT_EQ(clock_.Now(), last_gaia_signin_time); |
| 582 | 627 |
| 583 // Verify that the timer is running. | 628 // Verify that the timer is running. |
| 584 EXPECT_TRUE(runner_->HasPendingTask()); | 629 EXPECT_TRUE(runner_->HasPendingTask()); |
| 585 } | 630 } |
| 586 | 631 |
| 587 TEST_F(SAMLOfflineSigninLimiterTest, SAMLLogInOfflineWithExpiredLimit) { | 632 TEST_F(SAMLOfflineSigninLimiterTest, SAMLLogInOfflineWithExpiredLimit) { |
| 588 PrefService* prefs = profile_->GetPrefs(); | 633 PrefService* prefs = profile_->GetPrefs(); |
| 589 | 634 |
| 590 // Set the time of last login with SAML. | 635 // Set the time of last login with SAML. |
| 591 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 636 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 592 clock_.Now().ToInternalValue()); | 637 clock_.Now().ToInternalValue()); |
| 593 | 638 |
| 594 // Advance time by four weeks. | 639 // Advance time by four weeks. |
| 595 const base::Time gaia_signin_time = clock_.Now(); | 640 const base::Time gaia_signin_time = clock_.Now(); |
| 596 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. | 641 clock_.Advance(base::TimeDelta::FromDays(28)); // 4 weeks. |
| 597 | 642 |
| 598 // Authenticate offline. Verify that the flag enforcing online login is | 643 // Authenticate offline. Verify that the flag enforcing online login is |
| 599 // set and the time of last login with SAML is not changed. | 644 // set and the time of last login with SAML is not changed. |
| 600 CreateLimiter(); | 645 CreateLimiter(); |
| 601 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, false)).Times(0); | 646 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, false)) |
| 602 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(kTestUser, true)).Times(1); | 647 .Times(0); |
| 648 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | |
| 649 .Times(1); | |
| 603 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 650 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 604 | 651 |
| 605 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 652 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 606 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 653 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 607 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); | 654 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); |
| 608 } | 655 } |
| 609 | 656 |
| 610 } // namespace chromeos | 657 } // namespace chromeos |
| OLD | NEW |