| 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/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/test/simple_test_clock.h" | 9 #include "base/test/simple_test_clock.h" |
| 10 #include "base/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | |
| 12 #include "base/time/clock.h" | 11 #include "base/time/clock.h" |
| 13 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_factory
.h" | 12 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_factory
.h" |
| 14 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 13 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| 15 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 14 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/test/base/testing_browser_process.h" | 17 #include "chrome/test/base/testing_browser_process.h" |
| 19 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 20 #include "components/pref_registry/pref_registry_syncable.h" | 19 #include "components/pref_registry/pref_registry_syncable.h" |
| 21 #include "components/prefs/pref_service.h" | 20 #include "components/prefs/pref_service.h" |
| 22 #include "components/prefs/testing_pref_service.h" | 21 #include "components/prefs/testing_pref_service.h" |
| 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 23 #include "extensions/browser/quota_service.h" | 23 #include "extensions/browser/quota_service.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| 27 using testing::Mock; | 27 using testing::Mock; |
| 28 using testing::Return; | 28 using testing::Return; |
| 29 using testing::Sequence; | 29 using testing::Sequence; |
| 30 using testing::_; | 30 using testing::_; |
| 31 | 31 |
| 32 namespace chromeos { | 32 namespace chromeos { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 46 | 46 |
| 47 void DestroyLimiter(); | 47 void DestroyLimiter(); |
| 48 void CreateLimiter(); | 48 void CreateLimiter(); |
| 49 | 49 |
| 50 void SetUpUserManager(); | 50 void SetUpUserManager(); |
| 51 | 51 |
| 52 const AccountId test_account_id_ = AccountId::FromUserEmail(kTestUser); | 52 const AccountId test_account_id_ = AccountId::FromUserEmail(kTestUser); |
| 53 | 53 |
| 54 TestingPrefServiceSimple* GetTestingLocalState(); | 54 TestingPrefServiceSimple* GetTestingLocalState(); |
| 55 | 55 |
| 56 content::TestBrowserThreadBundle thread_bundle_; |
| 56 extensions::QuotaService::ScopedDisablePurgeForTesting | 57 extensions::QuotaService::ScopedDisablePurgeForTesting |
| 57 disable_purge_for_testing_; | 58 disable_purge_for_testing_; |
| 58 | 59 |
| 59 scoped_refptr<base::TestSimpleTaskRunner> runner_; | 60 scoped_refptr<base::TestSimpleTaskRunner> runner_; |
| 60 base::ThreadTaskRunnerHandle runner_handle_; | |
| 61 | 61 |
| 62 MockUserManager* user_manager_; // Not owned. | 62 MockUserManager* user_manager_; // Not owned. |
| 63 ScopedUserManagerEnabler user_manager_enabler_; | 63 ScopedUserManagerEnabler user_manager_enabler_; |
| 64 | 64 |
| 65 std::unique_ptr<TestingProfile> profile_; | 65 std::unique_ptr<TestingProfile> profile_; |
| 66 base::SimpleTestClock clock_; | 66 base::SimpleTestClock clock_; |
| 67 | 67 |
| 68 SAMLOfflineSigninLimiter* limiter_; // Owned. | 68 SAMLOfflineSigninLimiter* limiter_; // Owned. |
| 69 | 69 |
| 70 TestingPrefServiceSimple testing_local_state_; | 70 TestingPrefServiceSimple testing_local_state_; |
| 71 | 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(SAMLOfflineSigninLimiterTest); | 72 DISALLOW_COPY_AND_ASSIGN(SAMLOfflineSigninLimiterTest); |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 SAMLOfflineSigninLimiterTest::SAMLOfflineSigninLimiterTest() | 75 SAMLOfflineSigninLimiterTest::SAMLOfflineSigninLimiterTest() |
| 76 : runner_(new base::TestSimpleTaskRunner), | 76 : runner_(new base::TestSimpleTaskRunner), |
| 77 runner_handle_(runner_), | |
| 78 user_manager_(new MockUserManager), | 77 user_manager_(new MockUserManager), |
| 79 user_manager_enabler_(user_manager_), | 78 user_manager_enabler_(user_manager_), |
| 80 limiter_(NULL) {} | 79 limiter_(NULL) {} |
| 81 | 80 |
| 82 SAMLOfflineSigninLimiterTest::~SAMLOfflineSigninLimiterTest() { | 81 SAMLOfflineSigninLimiterTest::~SAMLOfflineSigninLimiterTest() { |
| 83 DestroyLimiter(); | 82 DestroyLimiter(); |
| 84 Mock::VerifyAndClearExpectations(user_manager_); | 83 Mock::VerifyAndClearExpectations(user_manager_); |
| 85 EXPECT_CALL(*user_manager_, Shutdown()).Times(1); | 84 EXPECT_CALL(*user_manager_, Shutdown()).Times(1); |
| 86 EXPECT_CALL(*user_manager_, RemoveSessionStateObserver(_)).Times(1); | 85 EXPECT_CALL(*user_manager_, RemoveSessionStateObserver(_)).Times(1); |
| 87 profile_.reset(); | 86 profile_.reset(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 100 DestroyLimiter(); | 99 DestroyLimiter(); |
| 101 limiter_ = new SAMLOfflineSigninLimiter(profile_.get(), &clock_); | 100 limiter_ = new SAMLOfflineSigninLimiter(profile_.get(), &clock_); |
| 102 } | 101 } |
| 103 | 102 |
| 104 void SAMLOfflineSigninLimiterTest::SetUpUserManager() { | 103 void SAMLOfflineSigninLimiterTest::SetUpUserManager() { |
| 105 EXPECT_CALL(*user_manager_, GetLocalState()) | 104 EXPECT_CALL(*user_manager_, GetLocalState()) |
| 106 .WillRepeatedly(Return(GetTestingLocalState())); | 105 .WillRepeatedly(Return(GetTestingLocalState())); |
| 107 } | 106 } |
| 108 | 107 |
| 109 void SAMLOfflineSigninLimiterTest::SetUp() { | 108 void SAMLOfflineSigninLimiterTest::SetUp() { |
| 109 base::MessageLoop::current()->SetTaskRunner(runner_); |
| 110 profile_.reset(new TestingProfile); | 110 profile_.reset(new TestingProfile); |
| 111 | 111 |
| 112 SAMLOfflineSigninLimiterFactory::SetClockForTesting(&clock_); | 112 SAMLOfflineSigninLimiterFactory::SetClockForTesting(&clock_); |
| 113 user_manager_->AddUser(test_account_id_); | 113 user_manager_->AddUser(test_account_id_); |
| 114 profile_->set_profile_name(kTestUser); | 114 profile_->set_profile_name(kTestUser); |
| 115 clock_.Advance(base::TimeDelta::FromHours(1)); | 115 clock_.Advance(base::TimeDelta::FromHours(1)); |
| 116 | 116 |
| 117 user_manager_->RegisterPrefs(GetTestingLocalState()->registry()); | 117 user_manager_->RegisterPrefs(GetTestingLocalState()->registry()); |
| 118 SetUpUserManager(); | 118 SetUpUserManager(); |
| 119 } | 119 } |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) | 652 EXPECT_CALL(*user_manager_, SaveForceOnlineSignin(test_account_id_, true)) |
| 653 .Times(1); | 653 .Times(1); |
| 654 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); | 654 limiter_->SignedIn(UserContext::AUTH_FLOW_OFFLINE); |
| 655 | 655 |
| 656 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( | 656 const base::Time last_gaia_signin_time = base::Time::FromInternalValue( |
| 657 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); | 657 prefs->GetInt64(prefs::kSAMLLastGAIASignInTime)); |
| 658 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); | 658 EXPECT_EQ(gaia_signin_time, last_gaia_signin_time); |
| 659 } | 659 } |
| 660 | 660 |
| 661 } // namespace chromeos | 661 } // namespace chromeos |
| OLD | NEW |