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" |
| 7 #include "chrome/browser/policy/browser_policy_connector.h" |
6 #include "chrome/browser/policy/mock_cloud_policy_store.h" | 8 #include "chrome/browser/policy/mock_cloud_policy_store.h" |
7 #include "chrome/browser/policy/user_cloud_policy_manager.h" | 9 #include "chrome/browser/policy/user_cloud_policy_manager.h" |
8 #include "chrome/browser/policy/user_policy_signin_service.h" | 10 #include "chrome/browser/policy/user_policy_signin_service.h" |
9 #include "chrome/browser/policy/user_policy_signin_service_factory.h" | 11 #include "chrome/browser/policy/user_policy_signin_service_factory.h" |
10 #include "chrome/browser/prefs/browser_prefs.h" | 12 #include "chrome/browser/prefs/browser_prefs.h" |
11 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
12 #include "chrome/browser/signin/signin_manager.h" | 14 #include "chrome/browser/signin/signin_manager.h" |
13 #include "chrome/browser/signin/signin_manager_factory.h" | 15 #include "chrome/browser/signin/signin_manager_factory.h" |
14 #include "chrome/browser/signin/signin_manager_fake.h" | 16 #include "chrome/browser/signin/signin_manager_fake.h" |
15 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
17 #include "chrome/test/base/testing_browser_process.h" | 19 #include "chrome/test/base/testing_browser_process.h" |
18 #include "chrome/test/base/testing_pref_service.h" | 20 #include "chrome/test/base/testing_pref_service.h" |
19 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
20 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
21 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
23 #include "content/public/test/test_browser_thread.h" | 25 #include "content/public/test/test_browser_thread.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
26 | 28 |
27 using testing::_; | |
28 using testing::Return; | |
29 | |
30 namespace policy { | 29 namespace policy { |
31 | 30 |
32 namespace { | 31 namespace { |
33 | 32 |
34 class UserPolicySigninServiceTest : public testing::Test { | 33 class UserPolicySigninServiceTest : public testing::Test { |
35 public: | 34 public: |
36 UserPolicySigninServiceTest() | 35 UserPolicySigninServiceTest() |
37 : loop_(MessageLoop::TYPE_UI), | 36 : loop_(MessageLoop::TYPE_UI), |
38 ui_thread_(content::BrowserThread::UI, &loop_) { | 37 ui_thread_(content::BrowserThread::UI, &loop_), |
39 } | 38 file_thread_(content::BrowserThread::FILE, &loop_) {} |
40 | 39 |
41 virtual void SetUp() OVERRIDE { | 40 virtual void SetUp() OVERRIDE { |
| 41 g_browser_process->browser_policy_connector()->Init(); |
| 42 |
42 local_state_.reset(new TestingPrefService); | 43 local_state_.reset(new TestingPrefService); |
43 chrome::RegisterLocalState(local_state_.get()); | 44 chrome::RegisterLocalState(local_state_.get()); |
44 static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState( | 45 static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState( |
45 local_state_.get()); | 46 local_state_.get()); |
46 | 47 |
47 // Create a UserCloudPolicyManager with a MockCloudPolicyStore, and build a | 48 // Create a UserCloudPolicyManager with a MockCloudPolicyStore, and build a |
48 // TestingProfile that uses it. | 49 // TestingProfile that uses it. |
49 mock_store_ = new MockCloudPolicyStore(); | 50 mock_store_ = new MockCloudPolicyStore(); |
50 mock_store_->NotifyStoreLoaded(); | 51 mock_store_->NotifyStoreLoaded(); |
51 EXPECT_CALL(*mock_store_, Load()); | 52 EXPECT_CALL(*mock_store_, Load()); |
52 scoped_ptr<UserCloudPolicyManager> manager(new UserCloudPolicyManager( | 53 scoped_ptr<UserCloudPolicyManager> manager(new UserCloudPolicyManager( |
53 scoped_ptr<CloudPolicyStore>(mock_store_), false)); | 54 scoped_ptr<CloudPolicyStore>(mock_store_), false)); |
54 TestingProfile::Builder builder; | 55 TestingProfile::Builder builder; |
55 builder.SetUserCloudPolicyManager(manager.Pass()); | 56 builder.SetUserCloudPolicyManager(manager.Pass()); |
56 profile_ = builder.Build().Pass(); | 57 profile_ = builder.Build().Pass(); |
57 profile_->GetPrefs()->SetBoolean(prefs::kLoadCloudPolicyOnSignin, true); | 58 profile_->GetPrefs()->SetBoolean(prefs::kLoadCloudPolicyOnSignin, true); |
58 SigninManagerFactory::GetInstance()->SetTestingFactory( | 59 SigninManagerFactory::GetInstance()->SetTestingFactory( |
59 profile_.get(), FakeSigninManager::Build); | 60 profile_.get(), FakeSigninManager::Build); |
60 | 61 |
61 // Make sure the UserPolicySigninService is created. | 62 // Make sure the UserPolicySigninService is created. |
62 UserPolicySigninServiceFactory::GetForProfile(profile_.get()); | 63 UserPolicySigninServiceFactory::GetForProfile(profile_.get()); |
63 } | 64 } |
64 | 65 |
65 virtual void TearDown() OVERRIDE { | 66 virtual void TearDown() OVERRIDE { |
66 // Free the profile before we clear out the browser prefs. | 67 // Free the profile before we clear out the browser prefs. |
67 profile_.reset(); | 68 profile_.reset(); |
68 static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState(NULL); | 69 TestingBrowserProcess* testing_browser_process = |
| 70 static_cast<TestingBrowserProcess*>(g_browser_process); |
| 71 testing_browser_process->SetLocalState(NULL); |
69 local_state_.reset(); | 72 local_state_.reset(); |
| 73 testing_browser_process->SetBrowserPolicyConnector(NULL); |
| 74 base::RunLoop run_loop; |
| 75 run_loop.RunUntilIdle(); |
70 } | 76 } |
71 | 77 |
72 | |
73 scoped_ptr<TestingProfile> profile_; | 78 scoped_ptr<TestingProfile> profile_; |
74 // Weak pointer to a MockCloudPolicyStore - lifetime is managed by the | 79 // Weak pointer to a MockCloudPolicyStore - lifetime is managed by the |
75 // UserCloudPolicyManager. | 80 // UserCloudPolicyManager. |
76 MockCloudPolicyStore* mock_store_; | 81 MockCloudPolicyStore* mock_store_; |
77 | 82 |
78 // BrowserPolicyConnector wants to initialize various components | 83 // BrowserPolicyConnector wants to initialize various components |
79 // asynchronously via tasks, so create a fake thread here. | 84 // asynchronously via tasks, so create a fake thread here. |
80 MessageLoop loop_; | 85 MessageLoop loop_; |
81 content::TestBrowserThread ui_thread_; | 86 content::TestBrowserThread ui_thread_; |
| 87 content::TestBrowserThread file_thread_; |
82 | 88 |
83 scoped_ptr<TestingPrefService> local_state_; | 89 scoped_ptr<TestingPrefService> local_state_; |
84 }; | 90 }; |
85 | 91 |
86 TEST_F(UserPolicySigninServiceTest, InitWhileSignedOut) { | 92 TEST_F(UserPolicySigninServiceTest, InitWhileSignedOut) { |
87 // Make sure user is not signed in. | 93 // Make sure user is not signed in. |
88 ASSERT_TRUE(SigninManagerFactory::GetForProfile(profile_.get())-> | 94 ASSERT_TRUE(SigninManagerFactory::GetForProfile(profile_.get())-> |
89 GetAuthenticatedUsername().empty()); | 95 GetAuthenticatedUsername().empty()); |
90 | 96 |
91 // Let the SigninService know that the profile has been created. | 97 // Let the SigninService know that the profile has been created. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // Now sign out. | 158 // Now sign out. |
153 SigninManagerFactory::GetForProfile(profile_.get())->SignOut(); | 159 SigninManagerFactory::GetForProfile(profile_.get())->SignOut(); |
154 | 160 |
155 // UserCloudPolicyManager should be shut down. | 161 // UserCloudPolicyManager should be shut down. |
156 ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); | 162 ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service()); |
157 } | 163 } |
158 | 164 |
159 } // namespace | 165 } // namespace |
160 | 166 |
161 } // namespace policy | 167 } // namespace policy |
OLD | NEW |