Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments. merge to ToT. Murder a DB thread and more TestBrowserThreads. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/memory/ref_counted.h" 5 #include "base/memory/ref_counted.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/signin/signin_manager.h" 21 #include "chrome/browser/signin/signin_manager.h"
22 #include "chrome/browser/signin/signin_manager_factory.h" 22 #include "chrome/browser/signin/signin_manager_factory.h"
23 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/test/base/testing_browser_process.h" 24 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_pref_service_syncable.h" 25 #include "chrome/test/base/testing_pref_service_syncable.h"
26 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
27 #include "content/public/browser/browser_context.h" 27 #include "content/public/browser/browser_context.h"
28 #include "content/public/browser/notification_details.h" 28 #include "content/public/browser/notification_details.h"
29 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/notification_source.h" 30 #include "content/public/browser/notification_source.h"
31 #include "content/public/test/test_browser_thread.h" 31 #include "content/public/test/test_browser_thread_bundle.h"
32 #include "google_apis/gaia/gaia_constants.h" 32 #include "google_apis/gaia/gaia_constants.h"
33 #include "google_apis/gaia/google_service_auth_error.h" 33 #include "google_apis/gaia/google_service_auth_error.h"
34 #include "net/http/http_status_code.h" 34 #include "net/http/http_status_code.h"
35 #include "net/url_request/test_url_fetcher_factory.h" 35 #include "net/url_request/test_url_fetcher_factory.h"
36 #include "net/url_request/url_request_context_getter.h" 36 #include "net/url_request/url_request_context_getter.h"
37 #include "net/url_request/url_request_status.h" 37 #include "net/url_request/url_request_status.h"
38 #include "testing/gmock/include/gmock/gmock.h" 38 #include "testing/gmock/include/gmock/gmock.h"
39 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
40 40
41 #if defined(OS_ANDROID) 41 #if defined(OS_ANDROID)
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 134
135 private: 135 private:
136 FetchOAuth2TokenCallback pending_callback_; 136 FetchOAuth2TokenCallback pending_callback_;
137 }; 137 };
138 138
139 #endif 139 #endif
140 140
141 class UserPolicySigninServiceTest : public testing::Test { 141 class UserPolicySigninServiceTest : public testing::Test {
142 public: 142 public:
143 UserPolicySigninServiceTest() 143 UserPolicySigninServiceTest()
144 : loop_(base::MessageLoop::TYPE_IO), 144 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
145 ui_thread_(content::BrowserThread::UI, &loop_),
146 file_thread_(content::BrowserThread::FILE, &loop_),
147 io_thread_(content::BrowserThread::IO, &loop_),
148 register_completed_(false) {} 145 register_completed_(false) {}
149 146
150 MOCK_METHOD1(OnPolicyRefresh, void(bool)); 147 MOCK_METHOD1(OnPolicyRefresh, void(bool));
151 148
152 void OnRegisterCompleted(scoped_ptr<CloudPolicyClient> client) { 149 void OnRegisterCompleted(scoped_ptr<CloudPolicyClient> client) {
153 register_completed_ = true; 150 register_completed_ = true;
154 created_client_.swap(client); 151 created_client_.swap(client);
155 } 152 }
156 153
157 void RegisterPolicyClientWithCallback(UserPolicySigninService* service) { 154 void RegisterPolicyClientWithCallback(UserPolicySigninService* service) {
(...skipping 22 matching lines...) Expand all
180 local_state_.get(), system_request_context); 177 local_state_.get(), system_request_context);
181 178
182 // Create a testing profile with cloud-policy-on-signin enabled, and bring 179 // Create a testing profile with cloud-policy-on-signin enabled, and bring
183 // up a UserCloudPolicyManager with a MockUserCloudPolicyStore. 180 // up a UserCloudPolicyManager with a MockUserCloudPolicyStore.
184 scoped_ptr<TestingPrefServiceSyncable> prefs( 181 scoped_ptr<TestingPrefServiceSyncable> prefs(
185 new TestingPrefServiceSyncable()); 182 new TestingPrefServiceSyncable());
186 chrome::RegisterUserProfilePrefs(prefs->registry()); 183 chrome::RegisterUserProfilePrefs(prefs->registry());
187 TestingProfile::Builder builder; 184 TestingProfile::Builder builder;
188 builder.SetPrefService(scoped_ptr<PrefServiceSyncable>(prefs.Pass())); 185 builder.SetPrefService(scoped_ptr<PrefServiceSyncable>(prefs.Pass()));
189 profile_ = builder.Build().Pass(); 186 profile_ = builder.Build().Pass();
190 profile_->CreateRequestContext();
191 187
192 mock_store_ = new MockUserCloudPolicyStore(); 188 mock_store_ = new MockUserCloudPolicyStore();
193 EXPECT_CALL(*mock_store_, Load()).Times(AnyNumber()); 189 EXPECT_CALL(*mock_store_, Load()).Times(AnyNumber());
194 manager_.reset(new UserCloudPolicyManager( 190 manager_.reset(new UserCloudPolicyManager(
195 profile_.get(), scoped_ptr<UserCloudPolicyStore>(mock_store_))); 191 profile_.get(), scoped_ptr<UserCloudPolicyStore>(mock_store_)));
196 signin_manager_ = static_cast<SigninManagerFake*>( 192 signin_manager_ = static_cast<SigninManagerFake*>(
197 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( 193 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
198 profile_.get(), SigninManagerFake::Build)); 194 profile_.get(), SigninManagerFake::Build));
199 195
200 #if defined(OS_ANDROID) 196 #if defined(OS_ANDROID)
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } 330 }
335 331
336 scoped_ptr<TestingProfile> profile_; 332 scoped_ptr<TestingProfile> profile_;
337 // Weak pointer to a MockUserCloudPolicyStore - lifetime is managed by the 333 // Weak pointer to a MockUserCloudPolicyStore - lifetime is managed by the
338 // UserCloudPolicyManager. 334 // UserCloudPolicyManager.
339 MockUserCloudPolicyStore* mock_store_; 335 MockUserCloudPolicyStore* mock_store_;
340 scoped_ptr<UserCloudPolicyManager> manager_; 336 scoped_ptr<UserCloudPolicyManager> manager_;
341 337
342 // BrowserPolicyConnector and UrlFetcherFactory want to initialize and free 338 // BrowserPolicyConnector and UrlFetcherFactory want to initialize and free
343 // various components asynchronously via tasks, so create fake threads here. 339 // various components asynchronously via tasks, so create fake threads here.
344 base::MessageLoop loop_; 340 content::TestBrowserThreadBundle thread_bundle_;
345 content::TestBrowserThread ui_thread_;
346 content::TestBrowserThread file_thread_;
347 content::TestBrowserThread io_thread_;
348 341
349 net::TestURLFetcherFactory url_factory_; 342 net::TestURLFetcherFactory url_factory_;
350 343
351 SigninManagerFake* signin_manager_; 344 SigninManagerFake* signin_manager_;
352 #if defined(OS_ANDROID) 345 #if defined(OS_ANDROID)
353 FakeProfileOAuth2TokenService* token_service_; // Not owned. 346 FakeProfileOAuth2TokenService* token_service_; // Not owned.
354 #endif 347 #endif
355 348
356 // Used in conjunction with OnRegisterCompleted() to test client registration 349 // Used in conjunction with OnRegisterCompleted() to test client registration
357 // callbacks. 350 // callbacks.
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 base::RunLoop().RunUntilIdle(); 795 base::RunLoop().RunUntilIdle();
803 EXPECT_FALSE(manager_->IsClientRegistered()); 796 EXPECT_FALSE(manager_->IsClientRegistered());
804 #if !defined(OS_ANDROID) 797 #if !defined(OS_ANDROID)
805 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); 798 EXPECT_FALSE(signin_manager_->IsSignoutProhibited());
806 #endif 799 #endif
807 } 800 }
808 801
809 } // namespace 802 } // namespace
810 803
811 } // namespace policy 804 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698