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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "chrome/browser/policy/browser_policy_connector.h" | 9 #include "chrome/browser/policy/browser_policy_connector.h" |
10 #include "chrome/browser/policy/cloud_policy_constants.h" | 10 #include "chrome/browser/policy/cloud_policy_constants.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 chrome::RegisterUserPrefs(prefs.get(), prefs->registry()); | 103 chrome::RegisterUserPrefs(prefs.get(), prefs->registry()); |
104 TestingProfile::Builder builder; | 104 TestingProfile::Builder builder; |
105 builder.SetPrefService(scoped_ptr<PrefServiceSyncable>(prefs.Pass())); | 105 builder.SetPrefService(scoped_ptr<PrefServiceSyncable>(prefs.Pass())); |
106 profile_ = builder.Build().Pass(); | 106 profile_ = builder.Build().Pass(); |
107 profile_->CreateRequestContext(); | 107 profile_->CreateRequestContext(); |
108 | 108 |
109 mock_store_ = new MockUserCloudPolicyStore(); | 109 mock_store_ = new MockUserCloudPolicyStore(); |
110 EXPECT_CALL(*mock_store_, Load()).Times(AnyNumber()); | 110 EXPECT_CALL(*mock_store_, Load()).Times(AnyNumber()); |
111 manager_.reset(new UserCloudPolicyManager( | 111 manager_.reset(new UserCloudPolicyManager( |
112 profile_.get(), scoped_ptr<UserCloudPolicyStore>(mock_store_))); | 112 profile_.get(), scoped_ptr<UserCloudPolicyStore>(mock_store_))); |
113 SigninManagerFactory::GetInstance()->SetTestingFactory( | 113 signin_manager_ = static_cast<FakeSigninManager*>( |
114 profile_.get(), FakeSigninManager::Build); | 114 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
| 115 profile_.get(), FakeSigninManager::Build)); |
115 | 116 |
116 // Make sure the UserPolicySigninService is created. | 117 // Make sure the UserPolicySigninService is created. |
117 UserPolicySigninServiceFactory::GetForProfile(profile_.get()); | 118 UserPolicySigninServiceFactory::GetForProfile(profile_.get()); |
118 Mock::VerifyAndClearExpectations(mock_store_); | 119 Mock::VerifyAndClearExpectations(mock_store_); |
119 url_factory_.set_remove_fetcher_on_delete(true); | 120 url_factory_.set_remove_fetcher_on_delete(true); |
120 } | 121 } |
121 | 122 |
122 virtual void TearDown() OVERRIDE { | 123 virtual void TearDown() OVERRIDE { |
123 // Free the profile before we clear out the browser prefs. | 124 // Free the profile before we clear out the browser prefs. |
124 profile_.reset(); | 125 profile_.reset(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 241 |
241 // BrowserPolicyConnector and UrlFetcherFactory want to initialize and free | 242 // BrowserPolicyConnector and UrlFetcherFactory want to initialize and free |
242 // various components asynchronously via tasks, so create fake threads here. | 243 // various components asynchronously via tasks, so create fake threads here. |
243 MessageLoop loop_; | 244 MessageLoop loop_; |
244 content::TestBrowserThread ui_thread_; | 245 content::TestBrowserThread ui_thread_; |
245 content::TestBrowserThread file_thread_; | 246 content::TestBrowserThread file_thread_; |
246 content::TestBrowserThread io_thread_; | 247 content::TestBrowserThread io_thread_; |
247 | 248 |
248 net::TestURLFetcherFactory url_factory_; | 249 net::TestURLFetcherFactory url_factory_; |
249 | 250 |
| 251 FakeSigninManager* signin_manager_; |
| 252 |
250 // Used in conjunction with OnRegisterCompleted() to test client registration | 253 // Used in conjunction with OnRegisterCompleted() to test client registration |
251 // callbacks. | 254 // callbacks. |
252 scoped_ptr<CloudPolicyClient> created_client_; | 255 scoped_ptr<CloudPolicyClient> created_client_; |
253 | 256 |
254 // True if OnRegisterCompleted() was called. | 257 // True if OnRegisterCompleted() was called. |
255 bool register_completed_; | 258 bool register_completed_; |
256 | 259 |
257 // Weak ptr to the MockDeviceManagementService (object is owned by the | 260 // Weak ptr to the MockDeviceManagementService (object is owned by the |
258 // BrowserPolicyConnector). | 261 // BrowserPolicyConnector). |
259 MockDeviceManagementService* device_management_service_; | 262 MockDeviceManagementService* device_management_service_; |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 ASSERT_TRUE(manager_->core()->service()); | 619 ASSERT_TRUE(manager_->core()->service()); |
617 } | 620 } |
618 | 621 |
619 TEST_F(UserPolicySigninServiceTest, FetchPolicySuccess) { | 622 TEST_F(UserPolicySigninServiceTest, FetchPolicySuccess) { |
620 TestSuccessfulSignin(); | 623 TestSuccessfulSignin(); |
621 } | 624 } |
622 | 625 |
623 TEST_F(UserPolicySigninServiceTest, SignOutThenSignInAgain) { | 626 TEST_F(UserPolicySigninServiceTest, SignOutThenSignInAgain) { |
624 TestSuccessfulSignin(); | 627 TestSuccessfulSignin(); |
625 | 628 |
626 // Now sign out. | 629 signin_manager_->ForceSignOut(); |
627 SigninManagerFactory::GetForProfile(profile_.get())->SignOut(); | |
628 ASSERT_FALSE(manager_->core()->service()); | 630 ASSERT_FALSE(manager_->core()->service()); |
629 | 631 |
630 // Now sign in again. | 632 // Now sign in again. |
631 TestSuccessfulSignin(); | 633 TestSuccessfulSignin(); |
632 } | 634 } |
633 | 635 |
634 } // namespace | 636 } // namespace |
635 | 637 |
636 } // namespace policy | 638 } // namespace policy |
OLD | NEW |