| OLD | NEW |
| 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/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
| 10 #include "chrome/browser/managed_mode/managed_user_refresh_token_fetcher.h" | 10 #include "chrome/browser/managed_mode/managed_user_refresh_token_fetcher.h" |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 received_callback_ = true; | 224 received_callback_ = true; |
| 225 error_ = error; | 225 error_ = error; |
| 226 token_ = token; | 226 token_ = token; |
| 227 run_loop_.Quit(); | 227 run_loop_.Quit(); |
| 228 } | 228 } |
| 229 | 229 |
| 230 TEST_F(ManagedUserRegistrationUtilityTest, Register) { | 230 TEST_F(ManagedUserRegistrationUtilityTest, Register) { |
| 231 StartInitialSync(); | 231 StartInitialSync(); |
| 232 GetRegistrationUtility()->Register( | 232 GetRegistrationUtility()->Register( |
| 233 ManagedUserRegistrationUtility::GenerateNewManagedUserId(), | 233 ManagedUserRegistrationUtility::GenerateNewManagedUserId(), |
| 234 false, |
| 234 ManagedUserRegistrationInfo(ASCIIToUTF16("Dug"), 0), | 235 ManagedUserRegistrationInfo(ASCIIToUTF16("Dug"), 0), |
| 235 GetRegistrationCallback()); | 236 GetRegistrationCallback()); |
| 236 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); | 237 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); |
| 237 Acknowledge(); | 238 Acknowledge(); |
| 238 | 239 |
| 239 EXPECT_TRUE(received_callback()); | 240 EXPECT_TRUE(received_callback()); |
| 240 EXPECT_EQ(GoogleServiceAuthError::NONE, error().state()); | 241 EXPECT_EQ(GoogleServiceAuthError::NONE, error().state()); |
| 241 EXPECT_FALSE(token().empty()); | 242 EXPECT_FALSE(token().empty()); |
| 242 } | 243 } |
| 243 | 244 |
| 244 TEST_F(ManagedUserRegistrationUtilityTest, RegisterBeforeInitialSync) { | 245 TEST_F(ManagedUserRegistrationUtilityTest, RegisterBeforeInitialSync) { |
| 245 GetRegistrationUtility()->Register( | 246 GetRegistrationUtility()->Register( |
| 246 ManagedUserRegistrationUtility::GenerateNewManagedUserId(), | 247 ManagedUserRegistrationUtility::GenerateNewManagedUserId(), |
| 248 false, |
| 247 ManagedUserRegistrationInfo(ASCIIToUTF16("Nemo"), 5), | 249 ManagedUserRegistrationInfo(ASCIIToUTF16("Nemo"), 5), |
| 248 GetRegistrationCallback()); | 250 GetRegistrationCallback()); |
| 249 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); | 251 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); |
| 250 StartInitialSync(); | 252 StartInitialSync(); |
| 251 Acknowledge(); | 253 Acknowledge(); |
| 252 | 254 |
| 253 EXPECT_TRUE(received_callback()); | 255 EXPECT_TRUE(received_callback()); |
| 254 EXPECT_EQ(GoogleServiceAuthError::NONE, error().state()); | 256 EXPECT_EQ(GoogleServiceAuthError::NONE, error().state()); |
| 255 EXPECT_FALSE(token().empty()); | 257 EXPECT_FALSE(token().empty()); |
| 256 } | 258 } |
| 257 | 259 |
| 258 TEST_F(ManagedUserRegistrationUtilityTest, SyncServiceShutdownBeforeRegFinish) { | 260 TEST_F(ManagedUserRegistrationUtilityTest, SyncServiceShutdownBeforeRegFinish) { |
| 259 StartInitialSync(); | 261 StartInitialSync(); |
| 260 GetRegistrationUtility()->Register( | 262 GetRegistrationUtility()->Register( |
| 261 ManagedUserRegistrationUtility::GenerateNewManagedUserId(), | 263 ManagedUserRegistrationUtility::GenerateNewManagedUserId(), |
| 264 false, |
| 262 ManagedUserRegistrationInfo(ASCIIToUTF16("Remy"), 12), | 265 ManagedUserRegistrationInfo(ASCIIToUTF16("Remy"), 12), |
| 263 GetRegistrationCallback()); | 266 GetRegistrationCallback()); |
| 264 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); | 267 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); |
| 265 service()->Shutdown(); | 268 service()->Shutdown(); |
| 266 EXPECT_EQ(0u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); | 269 EXPECT_EQ(0u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); |
| 267 EXPECT_TRUE(received_callback()); | 270 EXPECT_TRUE(received_callback()); |
| 268 EXPECT_EQ(GoogleServiceAuthError::REQUEST_CANCELED, error().state()); | 271 EXPECT_EQ(GoogleServiceAuthError::REQUEST_CANCELED, error().state()); |
| 269 EXPECT_EQ(std::string(), token()); | 272 EXPECT_EQ(std::string(), token()); |
| 270 } | 273 } |
| 271 | 274 |
| 272 TEST_F(ManagedUserRegistrationUtilityTest, StopSyncingBeforeRegFinish) { | 275 TEST_F(ManagedUserRegistrationUtilityTest, StopSyncingBeforeRegFinish) { |
| 273 StartInitialSync(); | 276 StartInitialSync(); |
| 274 GetRegistrationUtility()->Register( | 277 GetRegistrationUtility()->Register( |
| 275 ManagedUserRegistrationUtility::GenerateNewManagedUserId(), | 278 ManagedUserRegistrationUtility::GenerateNewManagedUserId(), |
| 279 false, |
| 276 ManagedUserRegistrationInfo(ASCIIToUTF16("Mike"), 17), | 280 ManagedUserRegistrationInfo(ASCIIToUTF16("Mike"), 17), |
| 277 GetRegistrationCallback()); | 281 GetRegistrationCallback()); |
| 278 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); | 282 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); |
| 279 service()->StopSyncing(MANAGED_USERS); | 283 service()->StopSyncing(MANAGED_USERS); |
| 280 EXPECT_EQ(0u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); | 284 EXPECT_EQ(0u, prefs()->GetDictionary(prefs::kManagedUsers)->size()); |
| 281 EXPECT_TRUE(received_callback()); | 285 EXPECT_TRUE(received_callback()); |
| 282 EXPECT_EQ(GoogleServiceAuthError::REQUEST_CANCELED, error().state()); | 286 EXPECT_EQ(GoogleServiceAuthError::REQUEST_CANCELED, error().state()); |
| 283 EXPECT_EQ(std::string(), token()); | 287 EXPECT_EQ(std::string(), token()); |
| 284 } | 288 } |
| OLD | NEW |