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 "chrome/browser/policy/mock_cloud_policy_store.h" | 6 #include "chrome/browser/policy/mock_cloud_policy_store.h" |
7 #include "chrome/browser/policy/user_cloud_policy_manager.h" | 7 #include "chrome/browser/policy/user_cloud_policy_manager.h" |
8 #include "chrome/browser/policy/user_policy_signin_service.h" | 8 #include "chrome/browser/policy/user_policy_signin_service.h" |
9 #include "chrome/browser/policy/user_policy_signin_service_factory.h" | 9 #include "chrome/browser/policy/user_policy_signin_service_factory.h" |
10 #include "chrome/browser/prefs/browser_prefs.h" | 10 #include "chrome/browser/prefs/browser_prefs.h" |
11 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
12 #include "chrome/browser/signin/signin_manager.h" | 12 #include "chrome/browser/signin/signin_manager.h" |
13 #include "chrome/browser/signin/signin_manager_factory.h" | 13 #include "chrome/browser/signin/signin_manager_factory.h" |
14 #include "chrome/browser/signin/signin_manager_fake.h" | 14 #include "chrome/browser/signin/signin_manager_fake.h" |
| 15 #include "chrome/browser/signin/token_service.h" |
| 16 #include "chrome/browser/signin/token_service_factory.h" |
15 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/net/gaia/gaia_constants.h" |
16 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
17 #include "chrome/test/base/testing_browser_process.h" | 20 #include "chrome/test/base/testing_browser_process.h" |
18 #include "chrome/test/base/testing_pref_service.h" | 21 #include "chrome/test/base/testing_pref_service.h" |
19 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
20 #include "content/public/browser/notification_details.h" | 23 #include "content/public/browser/notification_details.h" |
21 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
23 #include "content/public/test/test_browser_thread.h" | 26 #include "content/public/test/test_browser_thread.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 21 matching lines...) Expand all Loading... |
47 // Create a UserCloudPolicyManager with a MockCloudPolicyStore, and build a | 50 // Create a UserCloudPolicyManager with a MockCloudPolicyStore, and build a |
48 // TestingProfile that uses it. | 51 // TestingProfile that uses it. |
49 mock_store_ = new MockCloudPolicyStore(); | 52 mock_store_ = new MockCloudPolicyStore(); |
50 mock_store_->NotifyStoreLoaded(); | 53 mock_store_->NotifyStoreLoaded(); |
51 EXPECT_CALL(*mock_store_, Load()); | 54 EXPECT_CALL(*mock_store_, Load()); |
52 scoped_ptr<UserCloudPolicyManager> manager(new UserCloudPolicyManager( | 55 scoped_ptr<UserCloudPolicyManager> manager(new UserCloudPolicyManager( |
53 scoped_ptr<CloudPolicyStore>(mock_store_), false)); | 56 scoped_ptr<CloudPolicyStore>(mock_store_), false)); |
54 TestingProfile::Builder builder; | 57 TestingProfile::Builder builder; |
55 builder.SetUserCloudPolicyManager(manager.Pass()); | 58 builder.SetUserCloudPolicyManager(manager.Pass()); |
56 profile_ = builder.Build().Pass(); | 59 profile_ = builder.Build().Pass(); |
| 60 profile_->CreateRequestContext(); |
57 profile_->GetPrefs()->SetBoolean(prefs::kLoadCloudPolicyOnSignin, true); | 61 profile_->GetPrefs()->SetBoolean(prefs::kLoadCloudPolicyOnSignin, true); |
58 SigninManagerFactory::GetInstance()->SetTestingFactory( | 62 SigninManagerFactory::GetInstance()->SetTestingFactory( |
59 profile_.get(), FakeSigninManager::Build); | 63 profile_.get(), FakeSigninManager::Build); |
60 | 64 |
61 // Make sure the UserPolicySigninService is created. | 65 // Make sure the UserPolicySigninService is created. |
62 UserPolicySigninServiceFactory::GetForProfile(profile_.get()); | 66 UserPolicySigninServiceFactory::GetForProfile(profile_.get()); |
63 } | 67 } |
64 | 68 |
65 virtual void TearDown() OVERRIDE { | 69 virtual void TearDown() OVERRIDE { |
66 // Free the profile before we clear out the browser prefs. | 70 // Free the profile before we clear out the browser prefs. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // Let the SigninService know that the profile has been created. | 110 // Let the SigninService know that the profile has been created. |
107 content::NotificationService::current()->Notify( | 111 content::NotificationService::current()->Notify( |
108 chrome::NOTIFICATION_PROFILE_ADDED, | 112 chrome::NOTIFICATION_PROFILE_ADDED, |
109 content::Source<Profile>(profile_.get()), | 113 content::Source<Profile>(profile_.get()), |
110 content::NotificationService::NoDetails()); | 114 content::NotificationService::NoDetails()); |
111 | 115 |
112 // UserCloudPolicyManager should be initialized. | 116 // UserCloudPolicyManager should be initialized. |
113 ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 117 ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); |
114 } | 118 } |
115 | 119 |
116 // TODO(atwilson): Enable test for signing in once it is possible to use a | 120 TEST_F(UserPolicySigninServiceTest, SignInAfterInit) { |
117 // mock TokenService (http://crbug.com/138618). | |
118 TEST_F(UserPolicySigninServiceTest, DISABLED_SignInAfterInit) { | |
119 // Let the SigninService know that the profile has been created. | 121 // Let the SigninService know that the profile has been created. |
120 content::NotificationService::current()->Notify( | 122 content::NotificationService::current()->Notify( |
121 chrome::NOTIFICATION_PROFILE_ADDED, | 123 chrome::NOTIFICATION_PROFILE_ADDED, |
122 content::Source<Profile>(profile_.get()), | 124 content::Source<Profile>(profile_.get()), |
123 content::NotificationService::NoDetails()); | 125 content::NotificationService::NoDetails()); |
124 | 126 |
125 // UserCloudPolicyManager should not be initialized. | 127 // UserCloudPolicyManager should not be initialized. |
126 ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 128 ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); |
127 | 129 |
128 // Now sign in the user. | 130 // Now sign in the user. |
129 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 131 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
130 "testuser@test.com"); | 132 "testuser@test.com"); |
131 | 133 |
132 // Make oauth token available (needs MockTokenService - see TODO above). | 134 // Make oauth token available. |
| 135 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
| 136 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token"); |
133 | 137 |
134 // UserCloudPolicyManager should be initialized. | 138 // UserCloudPolicyManager should be initialized. |
135 ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 139 ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); |
136 } | 140 } |
137 | 141 |
138 TEST_F(UserPolicySigninServiceTest, SignOutAfterInit) { | 142 TEST_F(UserPolicySigninServiceTest, SignOutAfterInit) { |
139 // Set the user as signed in. | 143 // Set the user as signed in. |
140 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 144 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
141 "testuser@test.com"); | 145 "testuser@test.com"); |
142 | 146 |
143 // Let the SigninService know that the profile has been created. | 147 // Let the SigninService know that the profile has been created. |
144 content::NotificationService::current()->Notify( | 148 content::NotificationService::current()->Notify( |
145 chrome::NOTIFICATION_PROFILE_ADDED, | 149 chrome::NOTIFICATION_PROFILE_ADDED, |
146 content::Source<Profile>(profile_.get()), | 150 content::Source<Profile>(profile_.get()), |
147 content::NotificationService::NoDetails()); | 151 content::NotificationService::NoDetails()); |
148 | 152 |
149 // UserCloudPolicyManager should be initialized. | 153 // UserCloudPolicyManager should be initialized. |
150 ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 154 ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); |
151 | 155 |
152 // Now sign out. | 156 // Now sign out. |
153 SigninManagerFactory::GetForProfile(profile_.get())->SignOut(); | 157 SigninManagerFactory::GetForProfile(profile_.get())->SignOut(); |
154 | 158 |
155 // UserCloudPolicyManager should be shut down. | 159 // UserCloudPolicyManager should be shut down. |
156 ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 160 ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); |
157 } | 161 } |
158 | 162 |
159 } // namespace | 163 } // namespace |
160 | 164 |
161 } // namespace policy | 165 } // namespace policy |
OLD | NEW |