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

Side by Side Diff: chrome/browser/managed_mode/managed_user_registration_utility_unittest.cc

Issue 147083016: Add avatar syncing for supervised users. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync Created 6 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/prefs/scoped_user_pref_update.h" 7 #include "base/prefs/scoped_user_pref_update.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
11 #include "chrome/browser/managed_mode/managed_user_refresh_token_fetcher.h" 11 #include "chrome/browser/managed_mode/managed_user_refresh_token_fetcher.h"
12 #include "chrome/browser/managed_mode/managed_user_registration_utility.h" 12 #include "chrome/browser/managed_mode/managed_user_registration_utility.h"
13 #include "chrome/browser/managed_mode/managed_user_shared_settings_service.h"
14 #include "chrome/browser/managed_mode/managed_user_shared_settings_service_facto ry.h"
13 #include "chrome/browser/managed_mode/managed_user_sync_service.h" 15 #include "chrome/browser/managed_mode/managed_user_sync_service.h"
14 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" 16 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h"
15 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/testing_pref_service_syncable.h" 18 #include "chrome/test/base/testing_pref_service_syncable.h"
17 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
18 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
19 #include "google_apis/gaia/google_service_auth_error.h" 21 #include "google_apis/gaia/google_service_auth_error.h"
20 #include "sync/api/sync_change.h" 22 #include "sync/api/sync_change.h"
21 #include "sync/api/sync_error_factory_mock.h" 23 #include "sync/api/sync_error_factory_mock.h"
22 #include "sync/protocol/sync.pb.h" 24 #include "sync/protocol/sync.pb.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 100
99 ManagedUserRegistrationUtility::RegistrationCallback 101 ManagedUserRegistrationUtility::RegistrationCallback
100 GetRegistrationCallback(); 102 GetRegistrationCallback();
101 103
102 ManagedUserRegistrationUtility* GetRegistrationUtility(); 104 ManagedUserRegistrationUtility* GetRegistrationUtility();
103 105
104 void Acknowledge(); 106 void Acknowledge();
105 107
106 PrefService* prefs() { return profile_.GetTestingPrefService(); } 108 PrefService* prefs() { return profile_.GetTestingPrefService(); }
107 ManagedUserSyncService* service() { return service_; } 109 ManagedUserSyncService* service() { return service_; }
110 ManagedUserSharedSettingsService* shared_settings_service() {
111 return shared_settings_service_;
112 }
108 MockChangeProcessor* change_processor() { return change_processor_; } 113 MockChangeProcessor* change_processor() { return change_processor_; }
109 114
110 bool received_callback() const { return received_callback_; } 115 bool received_callback() const { return received_callback_; }
111 const GoogleServiceAuthError& error() const { return error_; } 116 const GoogleServiceAuthError& error() const { return error_; }
112 const std::string& token() const { return token_; } 117 const std::string& token() const { return token_; }
113 118
114 private: 119 private:
115 void OnManagedUserRegistered(const GoogleServiceAuthError& error, 120 void OnManagedUserRegistered(const GoogleServiceAuthError& error,
116 const std::string& token); 121 const std::string& token);
117 122
118 base::MessageLoop message_loop_; 123 base::MessageLoop message_loop_;
119 base::RunLoop run_loop_; 124 base::RunLoop run_loop_;
120 TestingProfile profile_; 125 TestingProfile profile_;
121 ManagedUserSyncService* service_; 126 ManagedUserSyncService* service_;
127 ManagedUserSharedSettingsService* shared_settings_service_;
122 scoped_ptr<ManagedUserRegistrationUtility> registration_utility_; 128 scoped_ptr<ManagedUserRegistrationUtility> registration_utility_;
123 129
124 // Owned by the ManagedUserSyncService. 130 // Owned by the ManagedUserSyncService.
125 MockChangeProcessor* change_processor_; 131 MockChangeProcessor* change_processor_;
126 132
127 // A unique ID for creating "remote" Sync data. 133 // A unique ID for creating "remote" Sync data.
128 int64 sync_data_id_; 134 int64 sync_data_id_;
129 135
130 // Whether OnManagedUserRegistered has been called. 136 // Whether OnManagedUserRegistered has been called.
131 bool received_callback_; 137 bool received_callback_;
132 138
133 // Hold the registration result (either an error, or a token). 139 // Hold the registration result (either an error, or a token).
134 GoogleServiceAuthError error_; 140 GoogleServiceAuthError error_;
135 std::string token_; 141 std::string token_;
136 142
137 base::WeakPtrFactory<ManagedUserRegistrationUtilityTest> weak_ptr_factory_; 143 base::WeakPtrFactory<ManagedUserRegistrationUtilityTest> weak_ptr_factory_;
138 }; 144 };
139 145
140 ManagedUserRegistrationUtilityTest::ManagedUserRegistrationUtilityTest() 146 ManagedUserRegistrationUtilityTest::ManagedUserRegistrationUtilityTest()
141 : change_processor_(NULL), 147 : change_processor_(NULL),
142 sync_data_id_(0), 148 sync_data_id_(0),
143 received_callback_(false), 149 received_callback_(false),
144 error_(GoogleServiceAuthError::NUM_STATES), 150 error_(GoogleServiceAuthError::NUM_STATES),
145 weak_ptr_factory_(this) { 151 weak_ptr_factory_(this) {
146 service_ = ManagedUserSyncServiceFactory::GetForProfile(&profile_); 152 service_ = ManagedUserSyncServiceFactory::GetForProfile(&profile_);
153 shared_settings_service_ =
154 ManagedUserSharedSettingsServiceFactory::GetForBrowserContext(&profile_);
147 } 155 }
148 156
149 ManagedUserRegistrationUtilityTest::~ManagedUserRegistrationUtilityTest() { 157 ManagedUserRegistrationUtilityTest::~ManagedUserRegistrationUtilityTest() {
150 EXPECT_FALSE(weak_ptr_factory_.HasWeakPtrs()); 158 EXPECT_FALSE(weak_ptr_factory_.HasWeakPtrs());
151 } 159 }
152 160
153 void ManagedUserRegistrationUtilityTest::TearDown() { 161 void ManagedUserRegistrationUtilityTest::TearDown() {
154 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 162 content::BrowserThread::GetBlockingPool()->FlushForTesting();
155 base::RunLoop().RunUntilIdle(); 163 base::RunLoop().RunUntilIdle();
156 } 164 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 ManagedUserRegistrationUtility* 196 ManagedUserRegistrationUtility*
189 ManagedUserRegistrationUtilityTest::GetRegistrationUtility() { 197 ManagedUserRegistrationUtilityTest::GetRegistrationUtility() {
190 if (registration_utility_.get()) 198 if (registration_utility_.get())
191 return registration_utility_.get(); 199 return registration_utility_.get();
192 200
193 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher( 201 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher(
194 new MockManagedUserRefreshTokenFetcher); 202 new MockManagedUserRefreshTokenFetcher);
195 registration_utility_.reset( 203 registration_utility_.reset(
196 ManagedUserRegistrationUtility::CreateImpl(prefs(), 204 ManagedUserRegistrationUtility::CreateImpl(prefs(),
197 token_fetcher.Pass(), 205 token_fetcher.Pass(),
198 service())); 206 service(),
207 shared_settings_service()));
199 return registration_utility_.get(); 208 return registration_utility_.get();
200 } 209 }
201 210
202 void ManagedUserRegistrationUtilityTest::Acknowledge() { 211 void ManagedUserRegistrationUtilityTest::Acknowledge() {
203 SyncChangeList new_changes; 212 SyncChangeList new_changes;
204 const SyncChangeList& changes = change_processor()->changes(); 213 const SyncChangeList& changes = change_processor()->changes();
205 for (SyncChangeList::const_iterator it = changes.begin(); it != changes.end(); 214 for (SyncChangeList::const_iterator it = changes.begin(); it != changes.end();
206 ++it) { 215 ++it) {
207 EXPECT_EQ(SyncChange::ACTION_ADD, it->change_type()); 216 EXPECT_EQ(SyncChange::ACTION_ADD, it->change_type());
208 ::sync_pb::EntitySpecifics specifics = it->sync_data().GetSpecifics(); 217 ::sync_pb::EntitySpecifics specifics = it->sync_data().GetSpecifics();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 ManagedUserRegistrationUtility::GenerateNewManagedUserId(), 285 ManagedUserRegistrationUtility::GenerateNewManagedUserId(),
277 ManagedUserRegistrationInfo(base::ASCIIToUTF16("Mike"), 17), 286 ManagedUserRegistrationInfo(base::ASCIIToUTF16("Mike"), 17),
278 GetRegistrationCallback()); 287 GetRegistrationCallback());
279 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); 288 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kManagedUsers)->size());
280 service()->StopSyncing(MANAGED_USERS); 289 service()->StopSyncing(MANAGED_USERS);
281 EXPECT_EQ(0u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); 290 EXPECT_EQ(0u, prefs()->GetDictionary(prefs::kManagedUsers)->size());
282 EXPECT_TRUE(received_callback()); 291 EXPECT_TRUE(received_callback());
283 EXPECT_EQ(GoogleServiceAuthError::REQUEST_CANCELED, error().state()); 292 EXPECT_EQ(GoogleServiceAuthError::REQUEST_CANCELED, error().state());
284 EXPECT_EQ(std::string(), token()); 293 EXPECT_EQ(std::string(), token());
285 } 294 }
OLDNEW
« no previous file with comments | « chrome/browser/managed_mode/managed_user_registration_utility.cc ('k') | chrome/browser/managed_mode/managed_user_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698