| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "chrome/browser/policy/browser_policy_connector.h" | 7 #include "chrome/browser/policy/browser_policy_connector.h" |
| 8 #include "chrome/browser/policy/mock_cloud_policy_store.h" | 8 #include "chrome/browser/policy/mock_user_cloud_policy_store.h" |
| 9 #include "chrome/browser/policy/user_cloud_policy_manager.h" | 9 #include "chrome/browser/policy/user_cloud_policy_manager.h" |
| 10 #include "chrome/browser/policy/user_policy_signin_service.h" | 10 #include "chrome/browser/policy/user_policy_signin_service.h" |
| 11 #include "chrome/browser/policy/user_policy_signin_service_factory.h" | 11 #include "chrome/browser/policy/user_policy_signin_service_factory.h" |
| 12 #include "chrome/browser/prefs/browser_prefs.h" | 12 #include "chrome/browser/prefs/browser_prefs.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/signin/signin_manager.h" | 14 #include "chrome/browser/signin/signin_manager.h" |
| 15 #include "chrome/browser/signin/signin_manager_factory.h" | 15 #include "chrome/browser/signin/signin_manager_factory.h" |
| 16 #include "chrome/browser/signin/signin_manager_fake.h" | 16 #include "chrome/browser/signin/signin_manager_fake.h" |
| 17 #include "chrome/browser/signin/token_service.h" | 17 #include "chrome/browser/signin/token_service.h" |
| 18 #include "chrome/browser/signin/token_service_factory.h" | 18 #include "chrome/browser/signin/token_service_factory.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
| 22 #include "chrome/test/base/testing_pref_service.h" | 22 #include "chrome/test/base/testing_pref_service.h" |
| 23 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 24 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
| 25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
| 27 #include "content/public/test/test_browser_thread.h" | 27 #include "content/public/test/test_browser_thread.h" |
| 28 #include "google_apis/gaia/gaia_constants.h" | 28 #include "google_apis/gaia/gaia_constants.h" |
| 29 #include "net/url_request/test_url_fetcher_factory.h" | 29 #include "net/url_request/test_url_fetcher_factory.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 32 |
| 33 using testing::AnyNumber; |
| 34 using testing::Mock; |
| 35 |
| 33 namespace policy { | 36 namespace policy { |
| 34 | 37 |
| 35 namespace { | 38 namespace { |
| 36 | 39 |
| 37 class UserPolicySigninServiceTest : public testing::Test { | 40 class UserPolicySigninServiceTest : public testing::Test { |
| 38 public: | 41 public: |
| 39 UserPolicySigninServiceTest() | 42 UserPolicySigninServiceTest() |
| 40 : loop_(MessageLoop::TYPE_UI), | 43 : loop_(MessageLoop::TYPE_UI), |
| 41 ui_thread_(content::BrowserThread::UI, &loop_), | 44 ui_thread_(content::BrowserThread::UI, &loop_), |
| 42 file_thread_(content::BrowserThread::FILE, &loop_), | 45 file_thread_(content::BrowserThread::FILE, &loop_), |
| 43 io_thread_(content::BrowserThread::IO, &loop_) {} | 46 io_thread_(content::BrowserThread::IO, &loop_) {} |
| 44 | 47 |
| 45 virtual void SetUp() OVERRIDE { | 48 virtual void SetUp() OVERRIDE { |
| 46 g_browser_process->browser_policy_connector()->Init(); | 49 g_browser_process->browser_policy_connector()->Init(); |
| 47 | 50 |
| 48 local_state_.reset(new TestingPrefService); | 51 local_state_.reset(new TestingPrefService); |
| 49 chrome::RegisterLocalState(local_state_.get()); | 52 chrome::RegisterLocalState(local_state_.get()); |
| 50 static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState( | 53 static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState( |
| 51 local_state_.get()); | 54 local_state_.get()); |
| 52 | 55 |
| 53 // Create a UserCloudPolicyManager with a MockCloudPolicyStore, and build a | 56 // Create a testing profile and bring up a UserCloudPolicyManager with a |
| 54 // TestingProfile that uses it. | 57 // MockUserCloudPolicyStore. |
| 55 mock_store_ = new MockCloudPolicyStore(); | 58 profile_.reset(new TestingProfile()); |
| 56 scoped_ptr<UserCloudPolicyManager> manager(new UserCloudPolicyManager( | |
| 57 scoped_ptr<CloudPolicyStore>(mock_store_), false)); | |
| 58 TestingProfile::Builder builder; | |
| 59 builder.SetUserCloudPolicyManager(manager.Pass()); | |
| 60 profile_ = builder.Build().Pass(); | |
| 61 profile_->CreateRequestContext(); | 59 profile_->CreateRequestContext(); |
| 62 profile_->GetPrefs()->SetBoolean(prefs::kLoadCloudPolicyOnSignin, true); | 60 profile_->GetPrefs()->SetBoolean(prefs::kLoadCloudPolicyOnSignin, true); |
| 61 |
| 62 mock_store_ = new MockUserCloudPolicyStore(); |
| 63 EXPECT_CALL(*mock_store_, Load()).Times(AnyNumber()); |
| 64 manager_.reset(new UserCloudPolicyManager( |
| 65 profile_.get(), scoped_ptr<UserCloudPolicyStore>(mock_store_))); |
| 63 SigninManagerFactory::GetInstance()->SetTestingFactory( | 66 SigninManagerFactory::GetInstance()->SetTestingFactory( |
| 64 profile_.get(), FakeSigninManager::Build); | 67 profile_.get(), FakeSigninManager::Build); |
| 65 | 68 |
| 66 // Make sure the UserPolicySigninService is created. | 69 // Make sure the UserPolicySigninService is created. |
| 67 UserPolicySigninServiceFactory::GetForProfile(profile_.get()); | 70 UserPolicySigninServiceFactory::GetForProfile(profile_.get()); |
| 68 testing::Mock::VerifyAndClearExpectations(mock_store_); | 71 testing::Mock::VerifyAndClearExpectations(mock_store_); |
| 69 } | 72 } |
| 70 | 73 |
| 71 virtual void TearDown() OVERRIDE { | 74 virtual void TearDown() OVERRIDE { |
| 72 // Free the profile before we clear out the browser prefs. | 75 // Free the profile before we clear out the browser prefs. |
| 73 profile_.reset(); | 76 profile_.reset(); |
| 74 TestingBrowserProcess* testing_browser_process = | 77 TestingBrowserProcess* testing_browser_process = |
| 75 static_cast<TestingBrowserProcess*>(g_browser_process); | 78 static_cast<TestingBrowserProcess*>(g_browser_process); |
| 76 testing_browser_process->SetLocalState(NULL); | 79 testing_browser_process->SetLocalState(NULL); |
| 77 local_state_.reset(); | 80 local_state_.reset(); |
| 78 testing_browser_process->SetBrowserPolicyConnector(NULL); | 81 testing_browser_process->SetBrowserPolicyConnector(NULL); |
| 79 base::RunLoop run_loop; | 82 base::RunLoop run_loop; |
| 80 run_loop.RunUntilIdle(); | 83 run_loop.RunUntilIdle(); |
| 81 } | 84 } |
| 82 | 85 |
| 83 bool IsRequestActive() { | 86 bool IsRequestActive() { |
| 84 return url_factory_.GetFetcherByID(0); | 87 return url_factory_.GetFetcherByID(0); |
| 85 } | 88 } |
| 86 | 89 |
| 87 scoped_ptr<TestingProfile> profile_; | 90 scoped_ptr<TestingProfile> profile_; |
| 88 // Weak pointer to a MockCloudPolicyStore - lifetime is managed by the | 91 // Weak pointer to a MockUserCloudPolicyStore - lifetime is managed by the |
| 89 // UserCloudPolicyManager. | 92 // UserCloudPolicyManager. |
| 90 MockCloudPolicyStore* mock_store_; | 93 MockUserCloudPolicyStore* mock_store_; |
| 94 scoped_ptr<UserCloudPolicyManager> manager_; |
| 91 | 95 |
| 92 // BrowserPolicyConnector and UrlFetcherFactory want to initialize and free | 96 // BrowserPolicyConnector and UrlFetcherFactory want to initialize and free |
| 93 // various components asynchronously via tasks, so create fake threads here. | 97 // various components asynchronously via tasks, so create fake threads here. |
| 94 MessageLoop loop_; | 98 MessageLoop loop_; |
| 95 content::TestBrowserThread ui_thread_; | 99 content::TestBrowserThread ui_thread_; |
| 96 content::TestBrowserThread file_thread_; | 100 content::TestBrowserThread file_thread_; |
| 97 content::TestBrowserThread io_thread_; | 101 content::TestBrowserThread io_thread_; |
| 98 | 102 |
| 99 net::TestURLFetcherFactory url_factory_; | 103 net::TestURLFetcherFactory url_factory_; |
| 100 | 104 |
| 101 scoped_ptr<TestingPrefService> local_state_; | 105 scoped_ptr<TestingPrefService> local_state_; |
| 102 }; | 106 }; |
| 103 | 107 |
| 104 TEST_F(UserPolicySigninServiceTest, InitWhileSignedOut) { | 108 TEST_F(UserPolicySigninServiceTest, InitWhileSignedOut) { |
| 105 EXPECT_CALL(*mock_store_, Clear()); | 109 EXPECT_CALL(*mock_store_, Clear()); |
| 106 // Make sure user is not signed in. | 110 // Make sure user is not signed in. |
| 107 ASSERT_TRUE(SigninManagerFactory::GetForProfile(profile_.get())-> | 111 ASSERT_TRUE(SigninManagerFactory::GetForProfile(profile_.get())-> |
| 108 GetAuthenticatedUsername().empty()); | 112 GetAuthenticatedUsername().empty()); |
| 109 | 113 |
| 110 // Let the SigninService know that the profile has been created. | 114 // Let the SigninService know that the profile has been created. |
| 111 content::NotificationService::current()->Notify( | 115 content::NotificationService::current()->Notify( |
| 112 chrome::NOTIFICATION_PROFILE_ADDED, | 116 chrome::NOTIFICATION_PROFILE_ADDED, |
| 113 content::Source<Profile>(profile_.get()), | 117 content::Source<Profile>(profile_.get()), |
| 114 content::NotificationService::NoDetails()); | 118 content::NotificationService::NoDetails()); |
| 115 | 119 |
| 116 // UserCloudPolicyManager should not be initialized. | 120 // UserCloudPolicyManager should not be initialized. |
| 117 ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 121 ASSERT_FALSE(manager_->cloud_policy_service()); |
| 118 } | 122 } |
| 119 | 123 |
| 120 TEST_F(UserPolicySigninServiceTest, InitWhileSignedIn) { | 124 TEST_F(UserPolicySigninServiceTest, InitWhileSignedIn) { |
| 121 // Set the user as signed in. | 125 // Set the user as signed in. |
| 122 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 126 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
| 123 "testuser@test.com"); | 127 "testuser@test.com"); |
| 124 | 128 |
| 125 // Let the SigninService know that the profile has been created. | 129 // Let the SigninService know that the profile has been created. |
| 126 content::NotificationService::current()->Notify( | 130 content::NotificationService::current()->Notify( |
| 127 chrome::NOTIFICATION_PROFILE_ADDED, | 131 chrome::NOTIFICATION_PROFILE_ADDED, |
| 128 content::Source<Profile>(profile_.get()), | 132 content::Source<Profile>(profile_.get()), |
| 129 content::NotificationService::NoDetails()); | 133 content::NotificationService::NoDetails()); |
| 130 | 134 |
| 131 // UserCloudPolicyManager should be initialized. | 135 // UserCloudPolicyManager should be initialized. |
| 132 ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 136 ASSERT_TRUE(manager_->cloud_policy_service()); |
| 133 | 137 |
| 134 // Complete initialization of the store. | 138 // Complete initialization of the store. |
| 135 mock_store_->NotifyStoreLoaded(); | 139 mock_store_->NotifyStoreLoaded(); |
| 136 | 140 |
| 137 // No oauth access token yet, so client registration should be deferred. | 141 // No oauth access token yet, so client registration should be deferred. |
| 138 ASSERT_FALSE(IsRequestActive()); | 142 ASSERT_FALSE(IsRequestActive()); |
| 139 | 143 |
| 140 // Make oauth token available. | 144 // Make oauth token available. |
| 141 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 145 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
| 142 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token"); | 146 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token"); |
| 143 | 147 |
| 144 // Client registration should be in progress since we now have an oauth token. | 148 // Client registration should be in progress since we now have an oauth token. |
| 145 ASSERT_TRUE(IsRequestActive()); | 149 ASSERT_TRUE(IsRequestActive()); |
| 146 } | 150 } |
| 147 | 151 |
| 148 TEST_F(UserPolicySigninServiceTest, SignInAfterInit) { | 152 TEST_F(UserPolicySigninServiceTest, SignInAfterInit) { |
| 149 EXPECT_CALL(*mock_store_, Clear()); | 153 EXPECT_CALL(*mock_store_, Clear()); |
| 150 // Let the SigninService know that the profile has been created. | 154 // Let the SigninService know that the profile has been created. |
| 151 content::NotificationService::current()->Notify( | 155 content::NotificationService::current()->Notify( |
| 152 chrome::NOTIFICATION_PROFILE_ADDED, | 156 chrome::NOTIFICATION_PROFILE_ADDED, |
| 153 content::Source<Profile>(profile_.get()), | 157 content::Source<Profile>(profile_.get()), |
| 154 content::NotificationService::NoDetails()); | 158 content::NotificationService::NoDetails()); |
| 155 | 159 |
| 156 // UserCloudPolicyManager should not be initialized since there is no | 160 // UserCloudPolicyManager should not be initialized since there is no |
| 157 // signed-in user. | 161 // signed-in user. |
| 158 ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 162 ASSERT_FALSE(manager_->cloud_policy_service()); |
| 159 | 163 |
| 160 // Now sign in the user. | 164 // Now sign in the user. |
| 161 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 165 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
| 162 "testuser@test.com"); | 166 "testuser@test.com"); |
| 163 | 167 |
| 164 // Complete initialization of the store. | 168 // Complete initialization of the store. |
| 165 mock_store_->NotifyStoreLoaded(); | 169 mock_store_->NotifyStoreLoaded(); |
| 166 | 170 |
| 167 // Make oauth token available. | 171 // Make oauth token available. |
| 168 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 172 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
| 169 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token"); | 173 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token"); |
| 170 | 174 |
| 171 // UserCloudPolicyManager should be initialized. | 175 // UserCloudPolicyManager should be initialized. |
| 172 ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 176 ASSERT_TRUE(manager_->cloud_policy_service()); |
| 173 | 177 |
| 174 // Client registration should be in progress since we have an oauth token. | 178 // Client registration should be in progress since we have an oauth token. |
| 175 ASSERT_TRUE(IsRequestActive()); | 179 ASSERT_TRUE(IsRequestActive()); |
| 176 } | 180 } |
| 177 | 181 |
| 178 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) { | 182 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) { |
| 179 EXPECT_CALL(*mock_store_, Clear()); | 183 EXPECT_CALL(*mock_store_, Clear()); |
| 180 // Let the SigninService know that the profile has been created. | 184 // Let the SigninService know that the profile has been created. |
| 181 content::NotificationService::current()->Notify( | 185 content::NotificationService::current()->Notify( |
| 182 chrome::NOTIFICATION_PROFILE_ADDED, | 186 chrome::NOTIFICATION_PROFILE_ADDED, |
| 183 content::Source<Profile>(profile_.get()), | 187 content::Source<Profile>(profile_.get()), |
| 184 content::NotificationService::NoDetails()); | 188 content::NotificationService::NoDetails()); |
| 185 | 189 |
| 186 // UserCloudPolicyManager should not be initialized since there is no | 190 // UserCloudPolicyManager should not be initialized since there is no |
| 187 // signed-in user. | 191 // signed-in user. |
| 188 ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 192 ASSERT_FALSE(manager_->cloud_policy_service()); |
| 189 | 193 |
| 190 // Now sign in the user. | 194 // Now sign in the user. |
| 191 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 195 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
| 192 "testuser@test.com"); | 196 "testuser@test.com"); |
| 193 | 197 |
| 194 // Make oauth token available. | 198 // Make oauth token available. |
| 195 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 199 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
| 196 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token"); | 200 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token"); |
| 197 | 201 |
| 198 // UserCloudPolicyManager should be initialized. | 202 // UserCloudPolicyManager should be initialized. |
| 199 ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 203 ASSERT_TRUE(manager_->cloud_policy_service()); |
| 200 | 204 |
| 201 // Client registration should not be in progress since the store is not | 205 // Client registration should not be in progress since the store is not |
| 202 // yet initialized. | 206 // yet initialized. |
| 203 ASSERT_FALSE(IsRequestActive()); | 207 ASSERT_FALSE(IsRequestActive()); |
| 204 | 208 |
| 205 // Complete initialization of the store with no policy (unregistered client). | 209 // Complete initialization of the store with no policy (unregistered client). |
| 206 mock_store_->NotifyStoreLoaded(); | 210 mock_store_->NotifyStoreLoaded(); |
| 207 | 211 |
| 208 // Client registration should be in progress since we have an oauth token. | 212 // Client registration should be in progress since we have an oauth token. |
| 209 ASSERT_TRUE(IsRequestActive()); | 213 ASSERT_TRUE(IsRequestActive()); |
| 210 } | 214 } |
| 211 | 215 |
| 212 TEST_F(UserPolicySigninServiceTest, RegisteredClient) { | 216 TEST_F(UserPolicySigninServiceTest, RegisteredClient) { |
| 213 EXPECT_CALL(*mock_store_, Clear()); | 217 EXPECT_CALL(*mock_store_, Clear()); |
| 214 // Let the SigninService know that the profile has been created. | 218 // Let the SigninService know that the profile has been created. |
| 215 content::NotificationService::current()->Notify( | 219 content::NotificationService::current()->Notify( |
| 216 chrome::NOTIFICATION_PROFILE_ADDED, | 220 chrome::NOTIFICATION_PROFILE_ADDED, |
| 217 content::Source<Profile>(profile_.get()), | 221 content::Source<Profile>(profile_.get()), |
| 218 content::NotificationService::NoDetails()); | 222 content::NotificationService::NoDetails()); |
| 219 | 223 |
| 220 // UserCloudPolicyManager should not be initialized since there is no | 224 // UserCloudPolicyManager should not be initialized since there is no |
| 221 // signed-in user. | 225 // signed-in user. |
| 222 ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 226 ASSERT_FALSE(manager_->cloud_policy_service()); |
| 223 | 227 |
| 224 // Now sign in the user. | 228 // Now sign in the user. |
| 225 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 229 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
| 226 "testuser@test.com"); | 230 "testuser@test.com"); |
| 227 | 231 |
| 228 // Make oauth token available. | 232 // Make oauth token available. |
| 229 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 233 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
| 230 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token"); | 234 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token"); |
| 231 | 235 |
| 232 // UserCloudPolicyManager should be initialized. | 236 // UserCloudPolicyManager should be initialized. |
| 233 ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 237 ASSERT_TRUE(manager_->cloud_policy_service()); |
| 234 | 238 |
| 235 // Client registration should not be in progress since the store is not | 239 // Client registration should not be in progress since the store is not |
| 236 // yet initialized. | 240 // yet initialized. |
| 237 ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->IsClientRegistered()); | 241 ASSERT_FALSE(manager_->IsClientRegistered()); |
| 238 ASSERT_FALSE(IsRequestActive()); | 242 ASSERT_FALSE(IsRequestActive()); |
| 239 | 243 |
| 240 mock_store_->policy_.reset(new enterprise_management::PolicyData()); | 244 mock_store_->policy_.reset(new enterprise_management::PolicyData()); |
| 241 mock_store_->policy_->set_request_token("fake token"); | 245 mock_store_->policy_->set_request_token("fake token"); |
| 242 mock_store_->policy_->set_device_id("fake client id"); | 246 mock_store_->policy_->set_device_id("fake client id"); |
| 243 | 247 |
| 244 // Complete initialization of the store. | 248 // Complete initialization of the store. |
| 245 mock_store_->NotifyStoreLoaded(); | 249 mock_store_->NotifyStoreLoaded(); |
| 246 | 250 |
| 247 // Client registration should not be in progress since the client should be | 251 // Client registration should not be in progress since the client should be |
| 248 // already registered. | 252 // already registered. |
| 249 ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->IsClientRegistered()); | 253 ASSERT_TRUE(manager_->IsClientRegistered()); |
| 250 ASSERT_FALSE(IsRequestActive()); | 254 ASSERT_FALSE(IsRequestActive()); |
| 251 } | 255 } |
| 252 | 256 |
| 253 TEST_F(UserPolicySigninServiceTest, SignOutAfterInit) { | 257 TEST_F(UserPolicySigninServiceTest, SignOutAfterInit) { |
| 254 EXPECT_CALL(*mock_store_, Clear()); | 258 EXPECT_CALL(*mock_store_, Clear()); |
| 255 // Set the user as signed in. | 259 // Set the user as signed in. |
| 256 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 260 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
| 257 "testuser@test.com"); | 261 "testuser@test.com"); |
| 258 | 262 |
| 259 // Let the SigninService know that the profile has been created. | 263 // Let the SigninService know that the profile has been created. |
| 260 content::NotificationService::current()->Notify( | 264 content::NotificationService::current()->Notify( |
| 261 chrome::NOTIFICATION_PROFILE_ADDED, | 265 chrome::NOTIFICATION_PROFILE_ADDED, |
| 262 content::Source<Profile>(profile_.get()), | 266 content::Source<Profile>(profile_.get()), |
| 263 content::NotificationService::NoDetails()); | 267 content::NotificationService::NoDetails()); |
| 264 | 268 |
| 265 // UserCloudPolicyManager should be initialized. | 269 // UserCloudPolicyManager should be initialized. |
| 266 ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 270 ASSERT_TRUE(manager_->cloud_policy_service()); |
| 267 | 271 |
| 268 // Now sign out. | 272 // Now sign out. |
| 269 SigninManagerFactory::GetForProfile(profile_.get())->SignOut(); | 273 SigninManagerFactory::GetForProfile(profile_.get())->SignOut(); |
| 270 | 274 |
| 271 // UserCloudPolicyManager should be shut down. | 275 // UserCloudPolicyManager should be shut down. |
| 272 ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 276 ASSERT_FALSE(manager_->cloud_policy_service()); |
| 273 } | 277 } |
| 274 | 278 |
| 275 } // namespace | 279 } // namespace |
| 276 | 280 |
| 277 } // namespace policy | 281 } // namespace policy |
| OLD | NEW |