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

Side by Side Diff: chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_unittest.cc

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix InstantNTP test. 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 "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 15 matching lines...) Expand all
26 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 26 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
27 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" 27 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
28 #include "chrome/browser/prefs/browser_prefs.h" 28 #include "chrome/browser/prefs/browser_prefs.h"
29 #include "chrome/browser/prefs/pref_service_syncable.h" 29 #include "chrome/browser/prefs/pref_service_syncable.h"
30 #include "chrome/browser/signin/token_service.h" 30 #include "chrome/browser/signin/token_service.h"
31 #include "chrome/browser/signin/token_service_factory.h" 31 #include "chrome/browser/signin/token_service_factory.h"
32 #include "chrome/common/chrome_constants.h" 32 #include "chrome/common/chrome_constants.h"
33 #include "chrome/test/base/testing_browser_process.h" 33 #include "chrome/test/base/testing_browser_process.h"
34 #include "chrome/test/base/testing_profile.h" 34 #include "chrome/test/base/testing_profile.h"
35 #include "chrome/test/base/testing_profile_manager.h" 35 #include "chrome/test/base/testing_profile_manager.h"
36 #include "content/public/test/test_browser_thread.h" 36 #include "content/public/test/test_browser_thread_bundle.h"
37 #include "google_apis/gaia/gaia_auth_consumer.h" 37 #include "google_apis/gaia/gaia_auth_consumer.h"
38 #include "google_apis/gaia/gaia_urls.h" 38 #include "google_apis/gaia/gaia_urls.h"
39 #include "net/url_request/test_url_fetcher_factory.h" 39 #include "net/url_request/test_url_fetcher_factory.h"
40 #include "net/url_request/url_fetcher_delegate.h" 40 #include "net/url_request/url_fetcher_delegate.h"
41 #include "net/url_request/url_request_context_getter.h" 41 #include "net/url_request/url_request_context_getter.h"
42 #include "net/url_request/url_request_status.h" 42 #include "net/url_request/url_request_status.h"
43 #include "policy/policy_constants.h" 43 #include "policy/policy_constants.h"
44 #include "testing/gmock/include/gmock/gmock.h" 44 #include "testing/gmock/include/gmock/gmock.h"
45 #include "testing/gtest/include/gtest/gtest.h" 45 #include "testing/gtest/include/gtest/gtest.h"
46 46
(...skipping 21 matching lines...) Expand all
68 "{" 68 "{"
69 " \"access_token\": \"5678\"," 69 " \"access_token\": \"5678\","
70 " \"expires_in\": 3600" 70 " \"expires_in\": 3600"
71 "}"; 71 "}";
72 72
73 } // namespace 73 } // namespace
74 74
75 class UserCloudPolicyManagerChromeOSTest : public testing::Test { 75 class UserCloudPolicyManagerChromeOSTest : public testing::Test {
76 protected: 76 protected:
77 UserCloudPolicyManagerChromeOSTest() 77 UserCloudPolicyManagerChromeOSTest()
78 : ui_thread_(content::BrowserThread::UI, &loop_), 78 : store_(NULL),
79 io_thread_(content::BrowserThread::IO, &loop_),
80 store_(NULL),
81 profile_(NULL), 79 profile_(NULL),
82 signin_profile_(NULL) {} 80 signin_profile_(NULL) {}
83 81
84 virtual void SetUp() OVERRIDE { 82 virtual void SetUp() OVERRIDE {
85 // The initialization path that blocks on the initial policy fetch requires 83 // The initialization path that blocks on the initial policy fetch requires
86 // a signin Profile to use its URLRequestContext. 84 // a signin Profile to use its URLRequestContext.
87 profile_manager_.reset( 85 profile_manager_.reset(
88 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 86 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
89 ASSERT_TRUE(profile_manager_->SetUp()); 87 ASSERT_TRUE(profile_manager_->SetUp());
90 profile_ = profile_manager_->CreateTestingProfile( 88 profile_ = profile_manager_->CreateTestingProfile(
91 chrome::kInitialProfile, scoped_ptr<PrefServiceSyncable>(), 89 chrome::kInitialProfile, scoped_ptr<PrefServiceSyncable>(),
92 UTF8ToUTF16("testing_profile"), 0); 90 UTF8ToUTF16("testing_profile"), 0);
93 signin_profile_ = profile_manager_->CreateTestingProfile("signin_profile"); 91 signin_profile_ = profile_manager_->CreateTestingProfile(kSigninProfile);
94 signin_profile_->set_incognito(true); 92 signin_profile_->set_incognito(true);
95 // Usually the signin Profile and the main Profile are separate, but since 93 // Usually the signin Profile and the main Profile are separate, but since
96 // the signin Profile is an OTR Profile then for this test it suffices to 94 // the signin Profile is an OTR Profile then for this test it suffices to
97 // attach it to the main Profile. 95 // attach it to the main Profile.
98 profile_->SetOffTheRecordProfile(signin_profile_); 96 profile_->SetOffTheRecordProfile(signin_profile_);
99 signin_profile_->SetOriginalProfile(profile_); 97 signin_profile_->SetOriginalProfile(profile_);
100 signin_profile_->CreateRequestContext();
101 ASSERT_EQ(signin_profile_, chromeos::ProfileHelper::GetSigninProfile()); 98 ASSERT_EQ(signin_profile_, chromeos::ProfileHelper::GetSigninProfile());
102 99
103 chrome::RegisterLocalState(prefs_.registry()); 100 chrome::RegisterLocalState(prefs_.registry());
104 101
105 // Set up a policy map for testing. 102 // Set up a policy map for testing.
106 policy_map_.Set("HomepageLocation", 103 policy_map_.Set("HomepageLocation",
107 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 104 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
108 base::Value::CreateStringValue("http://chromium.org"), 105 base::Value::CreateStringValue("http://chromium.org"),
109 NULL); 106 NULL);
110 expected_bundle_.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 107 expected_bundle_.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
(...skipping 18 matching lines...) Expand all
129 126
130 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _)) 127 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _))
131 .Times(AnyNumber()); 128 .Times(AnyNumber());
132 } 129 }
133 130
134 virtual void TearDown() OVERRIDE { 131 virtual void TearDown() OVERRIDE {
135 if (manager_) { 132 if (manager_) {
136 manager_->RemoveObserver(&observer_); 133 manager_->RemoveObserver(&observer_);
137 manager_->Shutdown(); 134 manager_->Shutdown();
138 } 135 }
139 signin_profile_->ResetRequestContext(); 136 signin_profile_ = NULL;
137 profile_ = NULL;
138 profile_manager_->DeleteTestingProfile(kSigninProfile);
139 profile_manager_->DeleteTestingProfile(chrome::kInitialProfile);
140 } 140 }
141 141
142 void CreateManager(bool wait_for_fetch) { 142 void CreateManager(bool wait_for_fetch) {
143 store_ = new MockCloudPolicyStore(); 143 store_ = new MockCloudPolicyStore();
144 EXPECT_CALL(*store_, Load()); 144 EXPECT_CALL(*store_, Load());
145 manager_.reset(new UserCloudPolicyManagerChromeOS( 145 manager_.reset(new UserCloudPolicyManagerChromeOS(
146 scoped_ptr<CloudPolicyStore>(store_), 146 scoped_ptr<CloudPolicyStore>(store_),
147 scoped_ptr<ResourceCache>(), 147 scoped_ptr<ResourceCache>(),
148 wait_for_fetch)); 148 wait_for_fetch));
149 manager_->Init(); 149 manager_->Init();
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 // Notifying that the store is has cached the fetched policy completes the 258 // Notifying that the store is has cached the fetched policy completes the
259 // process, and initializes the manager. 259 // process, and initializes the manager.
260 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); 260 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get()));
261 store_->policy_map_.CopyFrom(policy_map_); 261 store_->policy_map_.CopyFrom(policy_map_);
262 store_->NotifyStoreLoaded(); 262 store_->NotifyStoreLoaded();
263 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 263 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
264 Mock::VerifyAndClearExpectations(&observer_); 264 Mock::VerifyAndClearExpectations(&observer_);
265 EXPECT_TRUE(manager_->policies().Equals(expected_bundle_)); 265 EXPECT_TRUE(manager_->policies().Equals(expected_bundle_));
266 } 266 }
267 267
268 // Required by the refresh scheduler that's created by the manager. 268 // Required by the refresh scheduler that's created by the manager and
269 base::MessageLoop loop_; 269 // for the cleanup of URLRequestContextGetter in the |signin_profile_|.
270 content::TestBrowserThread ui_thread_; 270 content::TestBrowserThreadBundle thread_bundle_;
271 // Required to cleanup the URLRequestContextGetter of the |signin_profile_|.
272 content::TestBrowserThread io_thread_;
273 271
274 // Convenience policy objects. 272 // Convenience policy objects.
275 em::PolicyData policy_data_; 273 em::PolicyData policy_data_;
276 em::DeviceManagementResponse register_blob_; 274 em::DeviceManagementResponse register_blob_;
277 em::DeviceManagementResponse policy_blob_; 275 em::DeviceManagementResponse policy_blob_;
278 PolicyMap policy_map_; 276 PolicyMap policy_map_;
279 PolicyBundle expected_bundle_; 277 PolicyBundle expected_bundle_;
280 278
281 // Policy infrastructure. 279 // Policy infrastructure.
282 net::TestURLFetcherFactory test_url_fetcher_factory_; 280 net::TestURLFetcherFactory test_url_fetcher_factory_;
283 TestingPrefServiceSimple prefs_; 281 TestingPrefServiceSimple prefs_;
284 MockConfigurationPolicyObserver observer_; 282 MockConfigurationPolicyObserver observer_;
285 MockDeviceManagementService device_management_service_; 283 MockDeviceManagementService device_management_service_;
286 MockCloudPolicyStore* store_; 284 MockCloudPolicyStore* store_;
287 scoped_ptr<UserCloudPolicyManagerChromeOS> manager_; 285 scoped_ptr<UserCloudPolicyManagerChromeOS> manager_;
288 scoped_ptr<UserCloudPolicyTokenForwarder> token_forwarder_; 286 scoped_ptr<UserCloudPolicyTokenForwarder> token_forwarder_;
289 287
290 // Required by ProfileHelper to get the signin Profile context. 288 // Required by ProfileHelper to get the signin Profile context.
291 scoped_ptr<TestingProfileManager> profile_manager_; 289 scoped_ptr<TestingProfileManager> profile_manager_;
292 TestingProfile* profile_; 290 TestingProfile* profile_;
293 TestingProfile* signin_profile_; 291 TestingProfile* signin_profile_;
294 292
293 static const char kSigninProfile[];
294
295 private: 295 private:
296 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerChromeOSTest); 296 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerChromeOSTest);
297 }; 297 };
298 298
299 const char UserCloudPolicyManagerChromeOSTest::kSigninProfile[] =
300 "signin_profile";
301
299 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFirstFetch) { 302 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFirstFetch) {
300 // Tests the initialization of a manager whose Profile is waiting for the 303 // Tests the initialization of a manager whose Profile is waiting for the
301 // initial fetch, when the policy cache is empty. 304 // initial fetch, when the policy cache is empty.
302 ASSERT_NO_FATAL_FAILURE(CreateManager(true)); 305 ASSERT_NO_FATAL_FAILURE(CreateManager(true));
303 306
304 // Initialize the CloudPolicyService without any stored data. 307 // Initialize the CloudPolicyService without any stored data.
305 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 308 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
306 store_->NotifyStoreLoaded(); 309 store_->NotifyStoreLoaded();
307 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 310 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
308 EXPECT_FALSE(manager_->core()->client()->is_registered()); 311 EXPECT_FALSE(manager_->core()->client()->is_registered());
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 514
512 // The refresh scheduler takes care of the initial fetch for unmanaged users. 515 // The refresh scheduler takes care of the initial fetch for unmanaged users.
513 // It posts a delayed task with 0ms delay in this case, so spinning the loop 516 // It posts a delayed task with 0ms delay in this case, so spinning the loop
514 // issues the initial fetch. 517 // issues the initial fetch.
515 base::RunLoop loop; 518 base::RunLoop loop;
516 FetchPolicy( 519 FetchPolicy(
517 base::Bind(&base::RunLoop::RunUntilIdle, base::Unretained(&loop))); 520 base::Bind(&base::RunLoop::RunUntilIdle, base::Unretained(&loop)));
518 } 521 }
519 522
520 } // namespace policy 523 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698