| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/supervised_user/legacy/supervised_user_registration_uti
lity.h" | 5 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti
lity.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } // namespace | 90 } // namespace |
| 91 | 91 |
| 92 class SupervisedUserRegistrationUtilityTest : public ::testing::Test { | 92 class SupervisedUserRegistrationUtilityTest : public ::testing::Test { |
| 93 public: | 93 public: |
| 94 SupervisedUserRegistrationUtilityTest(); | 94 SupervisedUserRegistrationUtilityTest(); |
| 95 ~SupervisedUserRegistrationUtilityTest() override; | 95 ~SupervisedUserRegistrationUtilityTest() override; |
| 96 | 96 |
| 97 void TearDown() override; | 97 void TearDown() override; |
| 98 | 98 |
| 99 protected: | 99 protected: |
| 100 scoped_ptr<SyncChangeProcessor> CreateChangeProcessor(); | 100 std::unique_ptr<SyncChangeProcessor> CreateChangeProcessor(); |
| 101 scoped_ptr<SyncErrorFactory> CreateErrorFactory(); | 101 std::unique_ptr<SyncErrorFactory> CreateErrorFactory(); |
| 102 SyncData CreateRemoteData(const std::string& id, const std::string& name); | 102 SyncData CreateRemoteData(const std::string& id, const std::string& name); |
| 103 | 103 |
| 104 SyncMergeResult StartInitialSync(); | 104 SyncMergeResult StartInitialSync(); |
| 105 | 105 |
| 106 SupervisedUserRegistrationUtility::RegistrationCallback | 106 SupervisedUserRegistrationUtility::RegistrationCallback |
| 107 GetRegistrationCallback(); | 107 GetRegistrationCallback(); |
| 108 | 108 |
| 109 SupervisedUserRegistrationUtility* GetRegistrationUtility(); | 109 SupervisedUserRegistrationUtility* GetRegistrationUtility(); |
| 110 | 110 |
| 111 void Acknowledge(); | 111 void Acknowledge(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 123 | 123 |
| 124 private: | 124 private: |
| 125 void OnSupervisedUserRegistered(const GoogleServiceAuthError& error, | 125 void OnSupervisedUserRegistered(const GoogleServiceAuthError& error, |
| 126 const std::string& token); | 126 const std::string& token); |
| 127 | 127 |
| 128 base::MessageLoop message_loop_; | 128 base::MessageLoop message_loop_; |
| 129 base::RunLoop run_loop_; | 129 base::RunLoop run_loop_; |
| 130 TestingProfile profile_; | 130 TestingProfile profile_; |
| 131 SupervisedUserSyncService* service_; | 131 SupervisedUserSyncService* service_; |
| 132 SupervisedUserSharedSettingsService* shared_settings_service_; | 132 SupervisedUserSharedSettingsService* shared_settings_service_; |
| 133 scoped_ptr<SupervisedUserRegistrationUtility> registration_utility_; | 133 std::unique_ptr<SupervisedUserRegistrationUtility> registration_utility_; |
| 134 | 134 |
| 135 // Owned by the SupervisedUserSyncService. | 135 // Owned by the SupervisedUserSyncService. |
| 136 MockChangeProcessor* change_processor_; | 136 MockChangeProcessor* change_processor_; |
| 137 | 137 |
| 138 // A unique ID for creating "remote" Sync data. | 138 // A unique ID for creating "remote" Sync data. |
| 139 int64_t sync_data_id_; | 139 int64_t sync_data_id_; |
| 140 | 140 |
| 141 // Whether OnSupervisedUserRegistered has been called. | 141 // Whether OnSupervisedUserRegistered has been called. |
| 142 bool received_callback_; | 142 bool received_callback_; |
| 143 | 143 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 162 | 162 |
| 163 SupervisedUserRegistrationUtilityTest:: | 163 SupervisedUserRegistrationUtilityTest:: |
| 164 ~SupervisedUserRegistrationUtilityTest() { | 164 ~SupervisedUserRegistrationUtilityTest() { |
| 165 EXPECT_FALSE(weak_ptr_factory_.HasWeakPtrs()); | 165 EXPECT_FALSE(weak_ptr_factory_.HasWeakPtrs()); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void SupervisedUserRegistrationUtilityTest::TearDown() { | 168 void SupervisedUserRegistrationUtilityTest::TearDown() { |
| 169 content::RunAllBlockingPoolTasksUntilIdle(); | 169 content::RunAllBlockingPoolTasksUntilIdle(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 scoped_ptr<SyncChangeProcessor> | 172 std::unique_ptr<SyncChangeProcessor> |
| 173 SupervisedUserRegistrationUtilityTest::CreateChangeProcessor() { | 173 SupervisedUserRegistrationUtilityTest::CreateChangeProcessor() { |
| 174 EXPECT_FALSE(change_processor_); | 174 EXPECT_FALSE(change_processor_); |
| 175 change_processor_ = new MockChangeProcessor(); | 175 change_processor_ = new MockChangeProcessor(); |
| 176 return scoped_ptr<SyncChangeProcessor>(change_processor_); | 176 return std::unique_ptr<SyncChangeProcessor>(change_processor_); |
| 177 } | 177 } |
| 178 | 178 |
| 179 scoped_ptr<SyncErrorFactory> | 179 std::unique_ptr<SyncErrorFactory> |
| 180 SupervisedUserRegistrationUtilityTest::CreateErrorFactory() { | 180 SupervisedUserRegistrationUtilityTest::CreateErrorFactory() { |
| 181 return scoped_ptr<SyncErrorFactory>(new syncer::SyncErrorFactoryMock()); | 181 return std::unique_ptr<SyncErrorFactory>(new syncer::SyncErrorFactoryMock()); |
| 182 } | 182 } |
| 183 | 183 |
| 184 SyncMergeResult SupervisedUserRegistrationUtilityTest::StartInitialSync() { | 184 SyncMergeResult SupervisedUserRegistrationUtilityTest::StartInitialSync() { |
| 185 SyncDataList initial_sync_data; | 185 SyncDataList initial_sync_data; |
| 186 SyncMergeResult result = | 186 SyncMergeResult result = |
| 187 service()->MergeDataAndStartSyncing(SUPERVISED_USERS, | 187 service()->MergeDataAndStartSyncing(SUPERVISED_USERS, |
| 188 initial_sync_data, | 188 initial_sync_data, |
| 189 CreateChangeProcessor(), | 189 CreateChangeProcessor(), |
| 190 CreateErrorFactory()); | 190 CreateErrorFactory()); |
| 191 EXPECT_FALSE(result.error().IsSet()); | 191 EXPECT_FALSE(result.error().IsSet()); |
| 192 return result; | 192 return result; |
| 193 } | 193 } |
| 194 | 194 |
| 195 SupervisedUserRegistrationUtility::RegistrationCallback | 195 SupervisedUserRegistrationUtility::RegistrationCallback |
| 196 SupervisedUserRegistrationUtilityTest::GetRegistrationCallback() { | 196 SupervisedUserRegistrationUtilityTest::GetRegistrationCallback() { |
| 197 return base::Bind( | 197 return base::Bind( |
| 198 &SupervisedUserRegistrationUtilityTest::OnSupervisedUserRegistered, | 198 &SupervisedUserRegistrationUtilityTest::OnSupervisedUserRegistered, |
| 199 weak_ptr_factory_.GetWeakPtr()); | 199 weak_ptr_factory_.GetWeakPtr()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 SupervisedUserRegistrationUtility* | 202 SupervisedUserRegistrationUtility* |
| 203 SupervisedUserRegistrationUtilityTest::GetRegistrationUtility() { | 203 SupervisedUserRegistrationUtilityTest::GetRegistrationUtility() { |
| 204 if (registration_utility_.get()) | 204 if (registration_utility_.get()) |
| 205 return registration_utility_.get(); | 205 return registration_utility_.get(); |
| 206 | 206 |
| 207 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher( | 207 std::unique_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher( |
| 208 new MockSupervisedUserRefreshTokenFetcher); | 208 new MockSupervisedUserRefreshTokenFetcher); |
| 209 registration_utility_.reset(SupervisedUserRegistrationUtility::CreateImpl( | 209 registration_utility_.reset(SupervisedUserRegistrationUtility::CreateImpl( |
| 210 prefs(), std::move(token_fetcher), service(), shared_settings_service())); | 210 prefs(), std::move(token_fetcher), service(), shared_settings_service())); |
| 211 return registration_utility_.get(); | 211 return registration_utility_.get(); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void SupervisedUserRegistrationUtilityTest::Acknowledge() { | 214 void SupervisedUserRegistrationUtilityTest::Acknowledge() { |
| 215 SyncChangeList new_changes; | 215 SyncChangeList new_changes; |
| 216 for (const SyncChange& sync_change : change_processor()->changes()) { | 216 for (const SyncChange& sync_change : change_processor()->changes()) { |
| 217 EXPECT_EQ(SyncChange::ACTION_ADD, sync_change.change_type()); | 217 EXPECT_EQ(SyncChange::ACTION_ADD, sync_change.change_type()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(), | 292 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(), |
| 293 SupervisedUserRegistrationInfo(base::ASCIIToUTF16("Mike"), 17), | 293 SupervisedUserRegistrationInfo(base::ASCIIToUTF16("Mike"), 17), |
| 294 GetRegistrationCallback()); | 294 GetRegistrationCallback()); |
| 295 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kSupervisedUsers)->size()); | 295 EXPECT_EQ(1u, prefs()->GetDictionary(prefs::kSupervisedUsers)->size()); |
| 296 service()->StopSyncing(SUPERVISED_USERS); | 296 service()->StopSyncing(SUPERVISED_USERS); |
| 297 EXPECT_EQ(0u, prefs()->GetDictionary(prefs::kSupervisedUsers)->size()); | 297 EXPECT_EQ(0u, prefs()->GetDictionary(prefs::kSupervisedUsers)->size()); |
| 298 EXPECT_TRUE(received_callback()); | 298 EXPECT_TRUE(received_callback()); |
| 299 EXPECT_EQ(GoogleServiceAuthError::REQUEST_CANCELED, error().state()); | 299 EXPECT_EQ(GoogleServiceAuthError::REQUEST_CANCELED, error().state()); |
| 300 EXPECT_EQ(std::string(), token()); | 300 EXPECT_EQ(std::string(), token()); |
| 301 } | 301 } |
| OLD | NEW |