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

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

Issue 316863002: Rename "managed (mode|user)" to "supervised user" (part 1) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 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" 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" 14 #include "chrome/browser/managed_mode/managed_user_shared_settings_service_facto ry.h"
15 #include "chrome/browser/managed_mode/managed_user_sync_service.h" 15 #include "chrome/browser/managed_mode/managed_user_sync_service.h"
16 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" 16 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "chrome/test/base/testing_pref_service_syncable.h" 18 #include "chrome/test/base/testing_pref_service_syncable.h"
19 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "google_apis/gaia/google_service_auth_error.h" 21 #include "google_apis/gaia/google_service_auth_error.h"
22 #include "sync/api/attachments/attachment_id.h" 22 #include "sync/api/attachments/attachment_id.h"
23 #include "sync/api/attachments/attachment_service_proxy_for_test.h" 23 #include "sync/api/attachments/attachment_service_proxy_for_test.h"
24 #include "sync/api/sync_change.h" 24 #include "sync/api/sync_change.h"
25 #include "sync/api/sync_error_factory_mock.h" 25 #include "sync/api/sync_error_factory_mock.h"
26 #include "sync/protocol/sync.pb.h" 26 #include "sync/protocol/sync.pb.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 28
29 using sync_pb::ManagedUserSpecifics; 29 using sync_pb::ManagedUserSpecifics;
30 using syncer::MANAGED_USERS; 30 using syncer::SUPERVISED_USERS;
31 using syncer::SyncChange; 31 using syncer::SyncChange;
32 using syncer::SyncChangeList; 32 using syncer::SyncChangeList;
33 using syncer::SyncChangeProcessor; 33 using syncer::SyncChangeProcessor;
34 using syncer::SyncData; 34 using syncer::SyncData;
35 using syncer::SyncDataList; 35 using syncer::SyncDataList;
36 using syncer::SyncError; 36 using syncer::SyncError;
37 using syncer::SyncErrorFactory; 37 using syncer::SyncErrorFactory;
38 using syncer::SyncMergeResult; 38 using syncer::SyncMergeResult;
39 39
40 namespace { 40 namespace {
41 41
42 const char kManagedUserToken[] = "managedusertoken"; 42 const char kSupervisedUserToken[] = "supervisedusertoken";
43 43
44 class MockChangeProcessor : public SyncChangeProcessor { 44 class MockChangeProcessor : public SyncChangeProcessor {
45 public: 45 public:
46 MockChangeProcessor() {} 46 MockChangeProcessor() {}
47 virtual ~MockChangeProcessor() {} 47 virtual ~MockChangeProcessor() {}
48 48
49 // SyncChangeProcessor implementation: 49 // SyncChangeProcessor implementation:
50 virtual SyncError ProcessSyncChanges( 50 virtual SyncError ProcessSyncChanges(
51 const tracked_objects::Location& from_here, 51 const tracked_objects::Location& from_here,
52 const SyncChangeList& change_list) OVERRIDE; 52 const SyncChangeList& change_list) OVERRIDE;
(...skipping 20 matching lines...) Expand all
73 : public ManagedUserRefreshTokenFetcher { 73 : public ManagedUserRefreshTokenFetcher {
74 public: 74 public:
75 MockManagedUserRefreshTokenFetcher() {} 75 MockManagedUserRefreshTokenFetcher() {}
76 virtual ~MockManagedUserRefreshTokenFetcher() {} 76 virtual ~MockManagedUserRefreshTokenFetcher() {}
77 77
78 // ManagedUserRefreshTokenFetcher implementation: 78 // ManagedUserRefreshTokenFetcher implementation:
79 virtual void Start(const std::string& managed_user_id, 79 virtual void Start(const std::string& managed_user_id,
80 const std::string& device_name, 80 const std::string& device_name,
81 const TokenCallback& callback) OVERRIDE { 81 const TokenCallback& callback) OVERRIDE {
82 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); 82 GoogleServiceAuthError error(GoogleServiceAuthError::NONE);
83 callback.Run(error, kManagedUserToken); 83 callback.Run(error, kSupervisedUserToken);
84 } 84 }
85 }; 85 };
86 86
87 } // namespace 87 } // namespace
88 88
89 class ManagedUserRegistrationUtilityTest : public ::testing::Test { 89 class ManagedUserRegistrationUtilityTest : public ::testing::Test {
90 public: 90 public:
91 ManagedUserRegistrationUtilityTest(); 91 ManagedUserRegistrationUtilityTest();
92 virtual ~ManagedUserRegistrationUtilityTest(); 92 virtual ~ManagedUserRegistrationUtilityTest();
93 93
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 173 }
174 174
175 scoped_ptr<SyncErrorFactory> 175 scoped_ptr<SyncErrorFactory>
176 ManagedUserRegistrationUtilityTest::CreateErrorFactory() { 176 ManagedUserRegistrationUtilityTest::CreateErrorFactory() {
177 return scoped_ptr<SyncErrorFactory>(new syncer::SyncErrorFactoryMock()); 177 return scoped_ptr<SyncErrorFactory>(new syncer::SyncErrorFactoryMock());
178 } 178 }
179 179
180 SyncMergeResult ManagedUserRegistrationUtilityTest::StartInitialSync() { 180 SyncMergeResult ManagedUserRegistrationUtilityTest::StartInitialSync() {
181 SyncDataList initial_sync_data; 181 SyncDataList initial_sync_data;
182 SyncMergeResult result = 182 SyncMergeResult result =
183 service()->MergeDataAndStartSyncing(MANAGED_USERS, 183 service()->MergeDataAndStartSyncing(SUPERVISED_USERS,
184 initial_sync_data, 184 initial_sync_data,
185 CreateChangeProcessor(), 185 CreateChangeProcessor(),
186 CreateErrorFactory()); 186 CreateErrorFactory());
187 EXPECT_FALSE(result.error().IsSet()); 187 EXPECT_FALSE(result.error().IsSet());
188 return result; 188 return result;
189 } 189 }
190 190
191 ManagedUserRegistrationUtility::RegistrationCallback 191 ManagedUserRegistrationUtility::RegistrationCallback
192 ManagedUserRegistrationUtilityTest::GetRegistrationCallback() { 192 ManagedUserRegistrationUtilityTest::GetRegistrationCallback() {
193 return base::Bind( 193 return base::Bind(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 token_ = token; 242 token_ = token;
243 run_loop_.Quit(); 243 run_loop_.Quit();
244 } 244 }
245 245
246 TEST_F(ManagedUserRegistrationUtilityTest, Register) { 246 TEST_F(ManagedUserRegistrationUtilityTest, Register) {
247 StartInitialSync(); 247 StartInitialSync();
248 GetRegistrationUtility()->Register( 248 GetRegistrationUtility()->Register(
249 ManagedUserRegistrationUtility::GenerateNewManagedUserId(), 249 ManagedUserRegistrationUtility::GenerateNewManagedUserId(),
250 ManagedUserRegistrationInfo(base::ASCIIToUTF16("Dug"), 0), 250 ManagedUserRegistrationInfo(base::ASCIIToUTF16("Dug"), 0),
251 GetRegistrationCallback()); 251 GetRegistrationCallback());
252 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); 252 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kSupervisedUsers)->size());
253 Acknowledge(); 253 Acknowledge();
254 254
255 EXPECT_TRUE(received_callback()); 255 EXPECT_TRUE(received_callback());
256 EXPECT_EQ(GoogleServiceAuthError::NONE, error().state()); 256 EXPECT_EQ(GoogleServiceAuthError::NONE, error().state());
257 EXPECT_FALSE(token().empty()); 257 EXPECT_FALSE(token().empty());
258 } 258 }
259 259
260 TEST_F(ManagedUserRegistrationUtilityTest, RegisterBeforeInitialSync) { 260 TEST_F(ManagedUserRegistrationUtilityTest, RegisterBeforeInitialSync) {
261 GetRegistrationUtility()->Register( 261 GetRegistrationUtility()->Register(
262 ManagedUserRegistrationUtility::GenerateNewManagedUserId(), 262 ManagedUserRegistrationUtility::GenerateNewManagedUserId(),
263 ManagedUserRegistrationInfo(base::ASCIIToUTF16("Nemo"), 5), 263 ManagedUserRegistrationInfo(base::ASCIIToUTF16("Nemo"), 5),
264 GetRegistrationCallback()); 264 GetRegistrationCallback());
265 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); 265 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kSupervisedUsers)->size());
266 StartInitialSync(); 266 StartInitialSync();
267 Acknowledge(); 267 Acknowledge();
268 268
269 EXPECT_TRUE(received_callback()); 269 EXPECT_TRUE(received_callback());
270 EXPECT_EQ(GoogleServiceAuthError::NONE, error().state()); 270 EXPECT_EQ(GoogleServiceAuthError::NONE, error().state());
271 EXPECT_FALSE(token().empty()); 271 EXPECT_FALSE(token().empty());
272 } 272 }
273 273
274 TEST_F(ManagedUserRegistrationUtilityTest, SyncServiceShutdownBeforeRegFinish) { 274 TEST_F(ManagedUserRegistrationUtilityTest, SyncServiceShutdownBeforeRegFinish) {
275 StartInitialSync(); 275 StartInitialSync();
276 GetRegistrationUtility()->Register( 276 GetRegistrationUtility()->Register(
277 ManagedUserRegistrationUtility::GenerateNewManagedUserId(), 277 ManagedUserRegistrationUtility::GenerateNewManagedUserId(),
278 ManagedUserRegistrationInfo(base::ASCIIToUTF16("Remy"), 12), 278 ManagedUserRegistrationInfo(base::ASCIIToUTF16("Remy"), 12),
279 GetRegistrationCallback()); 279 GetRegistrationCallback());
280 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); 280 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kSupervisedUsers)->size());
281 service()->Shutdown(); 281 service()->Shutdown();
282 EXPECT_EQ(0u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); 282 EXPECT_EQ(0u, prefs()->GetDictionary(prefs::kSupervisedUsers)->size());
283 EXPECT_TRUE(received_callback()); 283 EXPECT_TRUE(received_callback());
284 EXPECT_EQ(GoogleServiceAuthError::REQUEST_CANCELED, error().state()); 284 EXPECT_EQ(GoogleServiceAuthError::REQUEST_CANCELED, error().state());
285 EXPECT_EQ(std::string(), token()); 285 EXPECT_EQ(std::string(), token());
286 } 286 }
287 287
288 TEST_F(ManagedUserRegistrationUtilityTest, StopSyncingBeforeRegFinish) { 288 TEST_F(ManagedUserRegistrationUtilityTest, StopSyncingBeforeRegFinish) {
289 StartInitialSync(); 289 StartInitialSync();
290 GetRegistrationUtility()->Register( 290 GetRegistrationUtility()->Register(
291 ManagedUserRegistrationUtility::GenerateNewManagedUserId(), 291 ManagedUserRegistrationUtility::GenerateNewManagedUserId(),
292 ManagedUserRegistrationInfo(base::ASCIIToUTF16("Mike"), 17), 292 ManagedUserRegistrationInfo(base::ASCIIToUTF16("Mike"), 17),
293 GetRegistrationCallback()); 293 GetRegistrationCallback());
294 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); 294 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kSupervisedUsers)->size());
295 service()->StopSyncing(MANAGED_USERS); 295 service()->StopSyncing(SUPERVISED_USERS);
296 EXPECT_EQ(0u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); 296 EXPECT_EQ(0u, prefs()->GetDictionary(prefs::kSupervisedUsers)->size());
297 EXPECT_TRUE(received_callback()); 297 EXPECT_TRUE(received_callback());
298 EXPECT_EQ(GoogleServiceAuthError::REQUEST_CANCELED, error().state()); 298 EXPECT_EQ(GoogleServiceAuthError::REQUEST_CANCELED, error().state());
299 EXPECT_EQ(std::string(), token()); 299 EXPECT_EQ(std::string(), token());
300 } 300 }
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