OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, | 233 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, |
234 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread) | 234 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread) |
235 : TokenWebData(ui_thread, db_thread) {} | 235 : TokenWebData(ui_thread, db_thread) {} |
236 | 236 |
237 bool IsDatabaseLoaded() override { return true; } | 237 bool IsDatabaseLoaded() override { return true; } |
238 | 238 |
239 AutofillWebDataService::Handle GetAllTokens( | 239 AutofillWebDataService::Handle GetAllTokens( |
240 WebDataServiceConsumer* consumer) override { | 240 WebDataServiceConsumer* consumer) override { |
241 // TODO(tim): It would be nice if WebDataService was injected on | 241 // TODO(tim): It would be nice if WebDataService was injected on |
242 // construction of ProfileOAuth2TokenService rather than fetched by | 242 // construction of ProfileOAuth2TokenService rather than fetched by |
243 // Initialize so that this isn't necessary (we could pass a NULL service). | 243 // Initialize so that this isn't necessary (we could pass a null service). |
244 // We currently do return it via EXPECT_CALLs, but without depending on | 244 // We currently do return it via EXPECT_CALLs, but without depending on |
245 // order-of-initialization (which seems way more fragile) we can't tell | 245 // order-of-initialization (which seems way more fragile) we can't tell |
246 // which component is asking at what time, and some components in these | 246 // which component is asking at what time, and some components in these |
247 // Autofill tests require a WebDataService. | 247 // Autofill tests require a WebDataService. |
248 return 0; | 248 return 0; |
249 } | 249 } |
250 | 250 |
251 private: | 251 private: |
252 ~TokenWebDataServiceFake() override {} | 252 ~TokenWebDataServiceFake() override {} |
253 | 253 |
254 DISALLOW_COPY_AND_ASSIGN(TokenWebDataServiceFake); | 254 DISALLOW_COPY_AND_ASSIGN(TokenWebDataServiceFake); |
255 }; | 255 }; |
256 | 256 |
257 class WebDataServiceFake : public AutofillWebDataService { | 257 class WebDataServiceFake : public AutofillWebDataService { |
258 public: | 258 public: |
259 WebDataServiceFake( | 259 WebDataServiceFake( |
260 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, | 260 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, |
261 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread) | 261 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread) |
262 : AutofillWebDataService(ui_thread, db_thread), | 262 : AutofillWebDataService(ui_thread, db_thread), |
263 web_database_(NULL), | 263 web_database_(nullptr), |
264 autocomplete_syncable_service_(NULL), | 264 autocomplete_syncable_service_(nullptr), |
265 autofill_profile_syncable_service_(NULL), | 265 autofill_profile_syncable_service_(nullptr), |
266 syncable_service_created_or_destroyed_( | 266 syncable_service_created_or_destroyed_( |
267 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 267 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
268 base::WaitableEvent::InitialState::NOT_SIGNALED), | 268 base::WaitableEvent::InitialState::NOT_SIGNALED), |
269 db_thread_(db_thread), | 269 db_thread_(db_thread), |
270 ui_thread_(ui_thread) {} | 270 ui_thread_(ui_thread) {} |
271 | 271 |
272 void SetDatabase(WebDatabase* web_database) { web_database_ = web_database; } | 272 void SetDatabase(WebDatabase* web_database) { web_database_ = web_database; } |
273 | 273 |
274 void StartSyncableService() { | 274 void StartSyncableService() { |
275 // The |autofill_profile_syncable_service_| must be constructed on the DB | 275 // The |autofill_profile_syncable_service_| must be constructed on the DB |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 autocomplete_syncable_service_ = | 343 autocomplete_syncable_service_ = |
344 AutocompleteSyncableService::FromWebDataService(this); | 344 AutocompleteSyncableService::FromWebDataService(this); |
345 autofill_profile_syncable_service_ = | 345 autofill_profile_syncable_service_ = |
346 AutofillProfileSyncableService::FromWebDataService(this); | 346 AutofillProfileSyncableService::FromWebDataService(this); |
347 | 347 |
348 syncable_service_created_or_destroyed_.Signal(); | 348 syncable_service_created_or_destroyed_.Signal(); |
349 } | 349 } |
350 | 350 |
351 void DestroySyncableService() { | 351 void DestroySyncableService() { |
352 ASSERT_TRUE(db_thread_->RunsTasksOnCurrentThread()); | 352 ASSERT_TRUE(db_thread_->RunsTasksOnCurrentThread()); |
353 autocomplete_syncable_service_ = NULL; | 353 autocomplete_syncable_service_ = nullptr; |
354 autofill_profile_syncable_service_ = NULL; | 354 autofill_profile_syncable_service_ = nullptr; |
355 backend_.reset(); | 355 backend_.reset(); |
356 syncable_service_created_or_destroyed_.Signal(); | 356 syncable_service_created_or_destroyed_.Signal(); |
357 } | 357 } |
358 | 358 |
359 WebDatabase* web_database_; | 359 WebDatabase* web_database_; |
360 AutocompleteSyncableService* autocomplete_syncable_service_; | 360 AutocompleteSyncableService* autocomplete_syncable_service_; |
361 AutofillProfileSyncableService* autofill_profile_syncable_service_; | 361 AutofillProfileSyncableService* autofill_profile_syncable_service_; |
362 std::unique_ptr<autofill::AutofillWebDataBackend> backend_; | 362 std::unique_ptr<autofill::AutofillWebDataBackend> backend_; |
363 | 363 |
364 WaitableEvent syncable_service_created_or_destroyed_; | 364 WaitableEvent syncable_service_created_or_destroyed_; |
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1432 .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true))); | 1432 .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true))); |
1433 | 1433 |
1434 std::vector<AutofillProfile> sync_profiles; | 1434 std::vector<AutofillProfile> sync_profiles; |
1435 sync_profiles.push_back(sync_profile); | 1435 sync_profiles.push_back(sync_profile); |
1436 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); | 1436 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
1437 EXPECT_CALL(personal_data_manager(), Refresh()); | 1437 EXPECT_CALL(personal_data_manager(), Refresh()); |
1438 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); | 1438 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); |
1439 ASSERT_TRUE(add_autofill.success()); | 1439 ASSERT_TRUE(add_autofill.success()); |
1440 | 1440 |
1441 AutofillProfileChange change(AutofillProfileChange::REMOVE, | 1441 AutofillProfileChange change(AutofillProfileChange::REMOVE, |
1442 sync_profile.guid(), NULL); | 1442 sync_profile.guid(), nullptr); |
1443 web_data_service()->OnAutofillProfileChanged(change); | 1443 web_data_service()->OnAutofillProfileChanged(change); |
1444 | 1444 |
1445 std::vector<AutofillProfile> new_sync_profiles; | 1445 std::vector<AutofillProfile> new_sync_profiles; |
1446 ASSERT_TRUE( | 1446 ASSERT_TRUE( |
1447 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); | 1447 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); |
1448 ASSERT_EQ(0U, new_sync_profiles.size()); | 1448 ASSERT_EQ(0U, new_sync_profiles.size()); |
1449 } | 1449 } |
1450 | 1450 |
1451 TEST_F(ProfileSyncServiceAutofillTest, ServerChangeRace) { | 1451 TEST_F(ProfileSyncServiceAutofillTest, ServerChangeRace) { |
1452 // Once for MergeDataAndStartSyncing() and twice for ProcessSyncChanges(), via | 1452 // Once for MergeDataAndStartSyncing() and twice for ProcessSyncChanges(), via |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1500 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
1501 EXPECT_EQ(3U, sync_entries.size()); | 1501 EXPECT_EQ(3U, sync_entries.size()); |
1502 EXPECT_EQ(0U, sync_profiles.size()); | 1502 EXPECT_EQ(0U, sync_profiles.size()); |
1503 for (size_t i = 0; i < sync_entries.size(); i++) { | 1503 for (size_t i = 0; i < sync_entries.size(); i++) { |
1504 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() << ", " | 1504 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() << ", " |
1505 << sync_entries[i].key().value(); | 1505 << sync_entries[i].key().value(); |
1506 } | 1506 } |
1507 } | 1507 } |
1508 | 1508 |
1509 } // namespace browser_sync | 1509 } // namespace browser_sync |
OLD | NEW |