OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/string16.h" | 15 #include "base/string16.h" |
16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
17 #include "base/task.h" | 17 #include "base/task.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "base/tracked.h" | 19 #include "base/tracked.h" |
20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
21 #include "chrome/browser/autofill/autofill_common_test.h" | 21 #include "chrome/browser/autofill/autofill_common_test.h" |
22 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" | 22 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" |
23 #include "chrome/browser/sync/engine/model_changing_syncer_command.h" | 23 #include "chrome/browser/sync/engine/model_changing_syncer_command.h" |
24 #include "chrome/browser/sync/glue/autofill_change_processor.h" | 24 #include "chrome/browser/sync/glue/autofill_change_processor.h" |
25 #include "chrome/browser/sync/glue/autofill_data_type_controller.h" | 25 #include "chrome/browser/sync/glue/autofill_data_type_controller.h" |
26 #include "chrome/browser/sync/glue/autofill_model_associator.h" | 26 #include "chrome/browser/sync/glue/autofill_model_associator.h" |
27 #include "chrome/browser/sync/glue/autofill_profile_change_processor.h" | |
28 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h" | 27 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h" |
29 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" | 28 #include "chrome/browser/sync/glue/autofill_profile_syncable_service.h" |
30 #include "chrome/browser/sync/glue/data_type_controller.h" | 29 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 30 #include "chrome/browser/sync/glue/generic_change_processor.h" |
| 31 #include "chrome/browser/sync/glue/syncable_service_adapter.h" |
31 #include "chrome/browser/sync/internal_api/read_node.h" | 32 #include "chrome/browser/sync/internal_api/read_node.h" |
32 #include "chrome/browser/sync/internal_api/read_transaction.h" | 33 #include "chrome/browser/sync/internal_api/read_transaction.h" |
33 #include "chrome/browser/sync/internal_api/write_node.h" | 34 #include "chrome/browser/sync/internal_api/write_node.h" |
34 #include "chrome/browser/sync/internal_api/write_transaction.h" | 35 #include "chrome/browser/sync/internal_api/write_transaction.h" |
35 #include "chrome/browser/sync/profile_sync_factory.h" | 36 #include "chrome/browser/sync/profile_sync_factory.h" |
36 #include "chrome/browser/sync/profile_sync_service.h" | 37 #include "chrome/browser/sync/profile_sync_service.h" |
37 #include "chrome/browser/sync/profile_sync_test_util.h" | 38 #include "chrome/browser/sync/profile_sync_test_util.h" |
38 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 39 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
39 #include "chrome/browser/sync/syncable/directory_manager.h" | 40 #include "chrome/browser/sync/syncable/directory_manager.h" |
40 #include "chrome/browser/sync/syncable/model_type.h" | 41 #include "chrome/browser/sync/syncable/model_type.h" |
41 #include "chrome/browser/sync/syncable/syncable.h" | 42 #include "chrome/browser/sync/syncable/syncable.h" |
42 #include "chrome/browser/sync/test_profile_sync_service.h" | 43 #include "chrome/browser/sync/test_profile_sync_service.h" |
43 #include "chrome/browser/sync/test/engine/test_id_factory.h" | 44 #include "chrome/browser/sync/test/engine/test_id_factory.h" |
44 #include "chrome/browser/webdata/autofill_change.h" | 45 #include "chrome/browser/webdata/autofill_change.h" |
45 #include "chrome/browser/webdata/autofill_entry.h" | 46 #include "chrome/browser/webdata/autofill_entry.h" |
46 #include "chrome/browser/webdata/autofill_table.h" | 47 #include "chrome/browser/webdata/autofill_table.h" |
47 #include "chrome/browser/webdata/web_database.h" | 48 #include "chrome/browser/webdata/web_database.h" |
48 #include "chrome/common/chrome_notification_types.h" | 49 #include "chrome/common/chrome_notification_types.h" |
49 #include "chrome/common/net/gaia/gaia_constants.h" | 50 #include "chrome/common/net/gaia/gaia_constants.h" |
50 #include "content/browser/browser_thread.h" | 51 #include "content/browser/browser_thread.h" |
51 #include "content/common/notification_source.h" | 52 #include "content/common/notification_source.h" |
52 #include "testing/gmock/include/gmock/gmock.h" | 53 #include "testing/gmock/include/gmock/gmock.h" |
53 | 54 |
54 using base::Time; | 55 using base::Time; |
55 using base::WaitableEvent; | 56 using base::WaitableEvent; |
56 using browser_sync::AutofillChangeProcessor; | 57 using browser_sync::AutofillChangeProcessor; |
57 using browser_sync::AutofillDataTypeController; | 58 using browser_sync::AutofillDataTypeController; |
58 using browser_sync::AutofillModelAssociator; | 59 using browser_sync::AutofillModelAssociator; |
59 using browser_sync::AutofillProfileChangeProcessor; | |
60 using browser_sync::AutofillProfileDataTypeController; | 60 using browser_sync::AutofillProfileDataTypeController; |
61 using browser_sync::AutofillProfileModelAssociator; | 61 using browser_sync::AutofillProfileSyncableService; |
62 using browser_sync::DataTypeController; | 62 using browser_sync::DataTypeController; |
| 63 using browser_sync::GenericChangeProcessor; |
| 64 using browser_sync::SyncableServiceAdapter; |
63 using browser_sync::GROUP_DB; | 65 using browser_sync::GROUP_DB; |
64 using browser_sync::kAutofillTag; | 66 using browser_sync::kAutofillTag; |
65 using browser_sync::SyncBackendHostForProfileSyncTest; | 67 using browser_sync::SyncBackendHostForProfileSyncTest; |
66 using browser_sync::UnrecoverableErrorHandler; | 68 using browser_sync::UnrecoverableErrorHandler; |
67 using syncable::CREATE_NEW_UPDATE_ITEM; | 69 using syncable::CREATE_NEW_UPDATE_ITEM; |
68 using syncable::AUTOFILL; | 70 using syncable::AUTOFILL; |
69 using syncable::BASE_VERSION; | 71 using syncable::BASE_VERSION; |
70 using syncable::CREATE; | 72 using syncable::CREATE; |
71 using syncable::GET_BY_SERVER_TAG; | 73 using syncable::GET_BY_SERVER_TAG; |
72 using syncable::INVALID; | 74 using syncable::INVALID; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 AutofillChangeProcessor* change_processor = | 173 AutofillChangeProcessor* change_processor = |
172 new AutofillChangeProcessor(model_associator, wd, pdm, dtc); | 174 new AutofillChangeProcessor(model_associator, wd, pdm, dtc); |
173 return ProfileSyncFactory::SyncComponents(model_associator, | 175 return ProfileSyncFactory::SyncComponents(model_associator, |
174 change_processor); | 176 change_processor); |
175 } | 177 } |
176 | 178 |
177 ACTION_P4(MakeAutofillProfileSyncComponents, service, wd, pdm, dtc) { | 179 ACTION_P4(MakeAutofillProfileSyncComponents, service, wd, pdm, dtc) { |
178 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 180 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
179 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) | 181 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) |
180 return ProfileSyncFactory::SyncComponents(NULL, NULL); | 182 return ProfileSyncFactory::SyncComponents(NULL, NULL); |
181 AutofillProfileModelAssociator* model_associator = | 183 AutofillProfileSyncableService* sync_service = |
182 new AutofillProfileModelAssociator(service, wd, pdm); | 184 new AutofillProfileSyncableService(wd, pdm, service->profile()); |
183 AutofillProfileChangeProcessor* change_processor = | 185 sync_api::UserShare* user_share = service->GetUserShare(); |
184 new AutofillProfileChangeProcessor(model_associator, wd, pdm, dtc); | 186 GenericChangeProcessor* change_processor = |
185 return ProfileSyncFactory::SyncComponents(model_associator, | 187 new GenericChangeProcessor(sync_service, dtc, user_share); |
| 188 SyncableServiceAdapter* sync_service_adapter = |
| 189 new SyncableServiceAdapter(syncable::AUTOFILL_PROFILE, |
| 190 sync_service, |
| 191 change_processor); |
| 192 return ProfileSyncFactory::SyncComponents(sync_service_adapter, |
186 change_processor); | 193 change_processor); |
187 } | 194 } |
188 | 195 |
189 class AbstractAutofillFactory { | 196 class AbstractAutofillFactory { |
190 public: | 197 public: |
191 virtual AutofillDataTypeController* CreateDataTypeController( | 198 virtual AutofillDataTypeController* CreateDataTypeController( |
192 ProfileSyncFactory *factory, | 199 ProfileSyncFactory* factory, |
193 ProfileMock* profile, | 200 ProfileMock* profile, |
194 ProfileSyncService* service) = 0; | 201 ProfileSyncService* service) = 0; |
195 virtual void SetExpectation(ProfileSyncFactoryMock* factory, | 202 virtual void SetExpectation(ProfileSyncFactoryMock* factory, |
196 ProfileSyncService* service, | 203 ProfileSyncService* service, |
197 WebDatabase* wd, | 204 WebDatabase* wd, |
198 PersonalDataManager* pdm, | 205 PersonalDataManager* pdm, |
199 DataTypeController* dtc) = 0; | 206 DataTypeController* dtc) = 0; |
200 virtual ~AbstractAutofillFactory() {} | 207 virtual ~AbstractAutofillFactory() {} |
201 }; | 208 }; |
202 | 209 |
203 class AutofillEntryFactory : public AbstractAutofillFactory { | 210 class AutofillEntryFactory : public AbstractAutofillFactory { |
204 public: | 211 public: |
205 browser_sync::AutofillDataTypeController* CreateDataTypeController( | 212 browser_sync::AutofillDataTypeController* CreateDataTypeController( |
206 ProfileSyncFactory *factory, | 213 ProfileSyncFactory* factory, |
207 ProfileMock* profile, | 214 ProfileMock* profile, |
208 ProfileSyncService* service) { | 215 ProfileSyncService* service) { |
209 return new AutofillDataTypeController(factory, | 216 return new AutofillDataTypeController(factory, |
210 profile); | 217 profile); |
211 } | 218 } |
212 | 219 |
213 void SetExpectation(ProfileSyncFactoryMock* factory, | 220 void SetExpectation(ProfileSyncFactoryMock* factory, |
214 ProfileSyncService* service, | 221 ProfileSyncService* service, |
215 WebDatabase* wd, | 222 WebDatabase* wd, |
216 PersonalDataManager* pdm, | 223 PersonalDataManager* pdm, |
217 DataTypeController* dtc) { | 224 DataTypeController* dtc) { |
218 EXPECT_CALL(*factory, CreateAutofillSyncComponents(_,_,_,_)). | 225 EXPECT_CALL(*factory, CreateAutofillSyncComponents(_,_,_,_)). |
219 WillOnce(MakeAutofillSyncComponents(service, wd, pdm, dtc)); | 226 WillOnce(MakeAutofillSyncComponents(service, wd, pdm, dtc)); |
220 } | 227 } |
221 }; | 228 }; |
222 | 229 |
223 class AutofillProfileFactory : public AbstractAutofillFactory { | 230 class AutofillProfileFactory : public AbstractAutofillFactory { |
224 public: | 231 public: |
225 browser_sync::AutofillDataTypeController* CreateDataTypeController( | 232 browser_sync::AutofillDataTypeController* CreateDataTypeController( |
226 ProfileSyncFactory *factory, | 233 ProfileSyncFactory* factory, |
227 ProfileMock* profile, | 234 ProfileMock* profile, |
228 ProfileSyncService* service) { | 235 ProfileSyncService* service) { |
229 return new AutofillProfileDataTypeController(factory, | 236 return new AutofillProfileDataTypeController(factory, |
230 profile); | 237 profile); |
231 } | 238 } |
232 | 239 |
233 void SetExpectation(ProfileSyncFactoryMock* factory, | 240 void SetExpectation(ProfileSyncFactoryMock* factory, |
234 ProfileSyncService* service, | 241 ProfileSyncService* service, |
235 WebDatabase* wd, | 242 WebDatabase* wd, |
236 PersonalDataManager* pdm, | 243 PersonalDataManager* pdm, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 service_.get(), | 314 service_.get(), |
308 web_database_.get(), | 315 web_database_.get(), |
309 personal_data_manager_.get(), | 316 personal_data_manager_.get(), |
310 data_type_controller); | 317 data_type_controller); |
311 | 318 |
312 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). | 319 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). |
313 WillOnce(ReturnNewDataTypeManager()); | 320 WillOnce(ReturnNewDataTypeManager()); |
314 | 321 |
315 EXPECT_CALL(profile_, GetWebDataService(_)). | 322 EXPECT_CALL(profile_, GetWebDataService(_)). |
316 // TokenService::Initialize | 323 // TokenService::Initialize |
317 WillOnce(Return(web_data_service_.get())). | |
318 // AutofillDataTypeController::StartModels() | 324 // AutofillDataTypeController::StartModels() |
319 WillOnce(Return(web_data_service_.get())); | 325 // In some tests: |
| 326 // AutofillProfileSyncableService::AutofillProfileSyncableService() |
| 327 WillRepeatedly(Return(web_data_service_.get())); |
320 | 328 |
321 EXPECT_CALL(profile_, GetPersonalDataManager()). | 329 EXPECT_CALL(profile_, GetPersonalDataManager()). |
322 WillRepeatedly(Return(personal_data_manager_.get())); | 330 WillRepeatedly(Return(personal_data_manager_.get())); |
323 | 331 |
324 EXPECT_CALL(*personal_data_manager_, IsDataLoaded()). | 332 EXPECT_CALL(*personal_data_manager_, IsDataLoaded()). |
325 WillRepeatedly(Return(true)); | 333 WillRepeatedly(Return(true)); |
326 | 334 |
327 // We need tokens to get the tests going | 335 // We need tokens to get the tests going |
328 token_service_.IssueAuthTokenForTest( | 336 token_service_.IssueAuthTokenForTest( |
329 GaiaConstants::kSyncService, "token"); | 337 GaiaConstants::kSyncService, "token"); |
(...skipping 25 matching lines...) Expand all Loading... |
355 bool AddAutofillSyncNode(const AutofillProfile& profile) { | 363 bool AddAutofillSyncNode(const AutofillProfile& profile) { |
356 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); | 364 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); |
357 sync_api::ReadNode autofill_root(&trans); | 365 sync_api::ReadNode autofill_root(&trans); |
358 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag)) | 366 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag)) |
359 return false; | 367 return false; |
360 sync_api::WriteNode node(&trans); | 368 sync_api::WriteNode node(&trans); |
361 std::string tag = profile.guid(); | 369 std::string tag = profile.guid(); |
362 if (!node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE, | 370 if (!node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE, |
363 autofill_root, tag)) | 371 autofill_root, tag)) |
364 return false; | 372 return false; |
365 AutofillProfileChangeProcessor::WriteAutofillProfile(profile, &node); | 373 sync_pb::EntitySpecifics specifics; |
| 374 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics); |
| 375 sync_pb::AutofillProfileSpecifics* profile_specifics = |
| 376 specifics.MutableExtension(sync_pb::autofill_profile); |
| 377 node.SetAutofillProfileSpecifics(*profile_specifics); |
366 return true; | 378 return true; |
367 } | 379 } |
368 | 380 |
369 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries, | 381 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries, |
370 std::vector<AutofillProfile>* profiles) { | 382 std::vector<AutofillProfile>* profiles) { |
371 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); | 383 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); |
372 sync_api::ReadNode autofill_root(&trans); | 384 sync_api::ReadNode autofill_root(&trans); |
373 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillTag)) | 385 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillTag)) |
374 return false; | 386 return false; |
375 | 387 |
(...skipping 11 matching lines...) Expand all Loading... |
387 std::vector<base::Time> timestamps; | 399 std::vector<base::Time> timestamps; |
388 int timestamps_count = autofill.usage_timestamp_size(); | 400 int timestamps_count = autofill.usage_timestamp_size(); |
389 for (int i = 0; i < timestamps_count; ++i) { | 401 for (int i = 0; i < timestamps_count; ++i) { |
390 timestamps.push_back(Time::FromInternalValue( | 402 timestamps.push_back(Time::FromInternalValue( |
391 autofill.usage_timestamp(i))); | 403 autofill.usage_timestamp(i))); |
392 } | 404 } |
393 entries->push_back(AutofillEntry(key, timestamps)); | 405 entries->push_back(AutofillEntry(key, timestamps)); |
394 } else if (autofill.has_profile()) { | 406 } else if (autofill.has_profile()) { |
395 AutofillProfile p; | 407 AutofillProfile p; |
396 p.set_guid(autofill.profile().guid()); | 408 p.set_guid(autofill.profile().guid()); |
397 AutofillProfileModelAssociator::OverwriteProfileWithServerData(&p, | 409 AutofillProfileSyncableService::OverwriteProfileWithServerData( |
398 autofill.profile()); | 410 autofill.profile(), &p); |
399 profiles->push_back(p); | 411 profiles->push_back(p); |
400 } | 412 } |
401 child_id = child_node.GetSuccessorId(); | 413 child_id = child_node.GetSuccessorId(); |
402 } | 414 } |
403 return true; | 415 return true; |
404 } | 416 } |
405 | 417 |
406 bool GetAutofillProfilesFromSyncDBUnderProfileNode( | 418 bool GetAutofillProfilesFromSyncDBUnderProfileNode( |
407 std::vector<AutofillProfile>* profiles) { | 419 std::vector<AutofillProfile>* profiles) { |
408 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); | 420 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); |
409 sync_api::ReadNode autofill_root(&trans); | 421 sync_api::ReadNode autofill_root(&trans); |
410 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag)) | 422 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag)) |
411 return false; | 423 return false; |
412 | 424 |
413 int64 child_id = autofill_root.GetFirstChildId(); | 425 int64 child_id = autofill_root.GetFirstChildId(); |
414 while (child_id != sync_api::kInvalidId) { | 426 while (child_id != sync_api::kInvalidId) { |
415 sync_api::ReadNode child_node(&trans); | 427 sync_api::ReadNode child_node(&trans); |
416 if (!child_node.InitByIdLookup(child_id)) | 428 if (!child_node.InitByIdLookup(child_id)) |
417 return false; | 429 return false; |
418 | 430 |
419 const sync_pb::AutofillProfileSpecifics& autofill( | 431 const sync_pb::AutofillProfileSpecifics& autofill( |
420 child_node.GetAutofillProfileSpecifics()); | 432 child_node.GetAutofillProfileSpecifics()); |
421 AutofillProfile p; | 433 AutofillProfile p; |
422 p.set_guid(autofill.guid()); | 434 p.set_guid(autofill.guid()); |
423 AutofillProfileModelAssociator::OverwriteProfileWithServerData(&p, | 435 AutofillProfileSyncableService::OverwriteProfileWithServerData( |
424 autofill); | 436 autofill, &p); |
425 profiles->push_back(p); | 437 profiles->push_back(p); |
426 child_id = child_node.GetSuccessorId(); | 438 child_id = child_node.GetSuccessorId(); |
427 } | 439 } |
428 return true; | 440 return true; |
429 } | 441 } |
430 | 442 |
431 void SetIdleChangeProcessorExpectations() { | 443 void SetIdleChangeProcessorExpectations() { |
432 EXPECT_CALL(autofill_table_, RemoveFormElement(_, _)).Times(0); | 444 EXPECT_CALL(autofill_table_, RemoveFormElement(_, _)).Times(0); |
433 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)).Times(0); | 445 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)).Times(0); |
434 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(_)).Times(0); | 446 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(_)).Times(0); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 bool success_; | 503 bool success_; |
492 }; | 504 }; |
493 | 505 |
494 // Overload write transaction to use custom NotifyTransactionComplete | 506 // Overload write transaction to use custom NotifyTransactionComplete |
495 static const bool kLoggingInfo = true; | 507 static const bool kLoggingInfo = true; |
496 class WriteTransactionTest: public WriteTransaction { | 508 class WriteTransactionTest: public WriteTransaction { |
497 public: | 509 public: |
498 WriteTransactionTest(const tracked_objects::Location& from_here, | 510 WriteTransactionTest(const tracked_objects::Location& from_here, |
499 WriterTag writer, | 511 WriterTag writer, |
500 const syncable::ScopedDirLookup& directory, | 512 const syncable::ScopedDirLookup& directory, |
501 scoped_ptr<WaitableEvent> *wait_for_syncapi) | 513 scoped_ptr<WaitableEvent>* wait_for_syncapi) |
502 : WriteTransaction(from_here, writer, directory), | 514 : WriteTransaction(from_here, writer, directory), |
503 wait_for_syncapi_(wait_for_syncapi) { } | 515 wait_for_syncapi_(wait_for_syncapi) { } |
504 | 516 |
505 virtual void NotifyTransactionComplete(syncable::ModelTypeBitSet types) { | 517 virtual void NotifyTransactionComplete(syncable::ModelTypeBitSet types) { |
506 // This is where we differ. Force a thread change here, giving another | 518 // This is where we differ. Force a thread change here, giving another |
507 // thread a chance to create a WriteTransaction | 519 // thread a chance to create a WriteTransaction |
508 (*wait_for_syncapi_)->Wait(); | 520 (*wait_for_syncapi_)->Wait(); |
509 | 521 |
510 WriteTransaction::NotifyTransactionComplete(types); | 522 WriteTransaction::NotifyTransactionComplete(types); |
511 } | 523 } |
512 | 524 |
513 private: | 525 private: |
514 scoped_ptr<WaitableEvent> *wait_for_syncapi_; | 526 scoped_ptr<WaitableEvent>* wait_for_syncapi_; |
515 }; | 527 }; |
516 | 528 |
517 // Our fake server updater. Needs the RefCountedThreadSafe inheritance so we can | 529 // Our fake server updater. Needs the RefCountedThreadSafe inheritance so we can |
518 // post tasks with it. | 530 // post tasks with it. |
519 class FakeServerUpdater: public base::RefCountedThreadSafe<FakeServerUpdater> { | 531 class FakeServerUpdater: public base::RefCountedThreadSafe<FakeServerUpdater> { |
520 public: | 532 public: |
521 FakeServerUpdater(TestProfileSyncService *service, | 533 FakeServerUpdater(TestProfileSyncService* service, |
522 scoped_ptr<WaitableEvent> *wait_for_start, | 534 scoped_ptr<WaitableEvent>* wait_for_start, |
523 scoped_ptr<WaitableEvent> *wait_for_syncapi) | 535 scoped_ptr<WaitableEvent>* wait_for_syncapi) |
524 : entry_(ProfileSyncServiceAutofillTest::MakeAutofillEntry("0", "0", 0)), | 536 : entry_(ProfileSyncServiceAutofillTest::MakeAutofillEntry("0", "0", 0)), |
525 service_(service), | 537 service_(service), |
526 wait_for_start_(wait_for_start), | 538 wait_for_start_(wait_for_start), |
527 wait_for_syncapi_(wait_for_syncapi), | 539 wait_for_syncapi_(wait_for_syncapi), |
528 is_finished_(false, false) { } | 540 is_finished_(false, false) { } |
529 | 541 |
530 void Update() { | 542 void Update() { |
531 // This gets called in a modelsafeworker thread. | 543 // This gets called in a modelsafeworker thread. |
532 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 544 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
533 | 545 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 item.Put(syncable::ID, server_item_id); | 584 item.Put(syncable::ID, server_item_id); |
573 syncable::Id new_predecessor; | 585 syncable::Id new_predecessor; |
574 ASSERT_TRUE(item.PutPredecessor(new_predecessor)); | 586 ASSERT_TRUE(item.PutPredecessor(new_predecessor)); |
575 } | 587 } |
576 VLOG(1) << "FakeServerUpdater finishing."; | 588 VLOG(1) << "FakeServerUpdater finishing."; |
577 is_finished_.Signal(); | 589 is_finished_.Signal(); |
578 } | 590 } |
579 | 591 |
580 void CreateNewEntry(const AutofillEntry& entry) { | 592 void CreateNewEntry(const AutofillEntry& entry) { |
581 entry_ = entry; | 593 entry_ = entry; |
582 scoped_ptr<Callback0::Type> c(NewCallback((FakeServerUpdater *)this, | 594 scoped_ptr<Callback0::Type> c(NewCallback((FakeServerUpdater*)this, |
583 &FakeServerUpdater::Update)); | 595 &FakeServerUpdater::Update)); |
584 ASSERT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 596 ASSERT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
585 if (!BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 597 if (!BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
586 NewRunnableMethod(this, &FakeServerUpdater::Update))) { | 598 NewRunnableMethod(this, &FakeServerUpdater::Update))) { |
587 NOTREACHED() << "Failed to post task to the db thread."; | 599 NOTREACHED() << "Failed to post task to the db thread."; |
588 return; | 600 return; |
589 } | 601 } |
590 } | 602 } |
591 | 603 |
592 void CreateNewEntryAndWait(const AutofillEntry& entry) { | 604 void CreateNewEntryAndWait(const AutofillEntry& entry) { |
593 entry_ = entry; | 605 entry_ = entry; |
594 scoped_ptr<Callback0::Type> c(NewCallback((FakeServerUpdater *)this, | 606 scoped_ptr<Callback0::Type> c(NewCallback((FakeServerUpdater*)this, |
595 &FakeServerUpdater::Update)); | 607 &FakeServerUpdater::Update)); |
596 ASSERT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 608 ASSERT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
597 is_finished_.Reset(); | 609 is_finished_.Reset(); |
598 if (!BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 610 if (!BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
599 NewRunnableMethod(this, &FakeServerUpdater::Update))) { | 611 NewRunnableMethod(this, &FakeServerUpdater::Update))) { |
600 NOTREACHED() << "Failed to post task to the db thread."; | 612 NOTREACHED() << "Failed to post task to the db thread."; |
601 return; | 613 return; |
602 } | 614 } |
603 is_finished_.Wait(); | 615 is_finished_.Wait(); |
604 } | 616 } |
605 | 617 |
606 private: | 618 private: |
607 friend class base::RefCountedThreadSafe<FakeServerUpdater>; | 619 friend class base::RefCountedThreadSafe<FakeServerUpdater>; |
608 ~FakeServerUpdater() { } | 620 ~FakeServerUpdater() { } |
609 | 621 |
610 AutofillEntry entry_; | 622 AutofillEntry entry_; |
611 TestProfileSyncService *service_; | 623 TestProfileSyncService* service_; |
612 scoped_ptr<WaitableEvent> *wait_for_start_; | 624 scoped_ptr<WaitableEvent>* wait_for_start_; |
613 scoped_ptr<WaitableEvent> *wait_for_syncapi_; | 625 scoped_ptr<WaitableEvent>* wait_for_syncapi_; |
614 WaitableEvent is_finished_; | 626 WaitableEvent is_finished_; |
615 syncable::Id parent_id_; | 627 syncable::Id parent_id_; |
616 }; | 628 }; |
617 | 629 |
618 // TODO(skrul): Test abort startup. | 630 // TODO(skrul): Test abort startup. |
619 // TODO(skrul): Test processing of cloud changes. | 631 // TODO(skrul): Test processing of cloud changes. |
620 // TODO(tim): Add autofill data type controller test, and a case to cover | 632 // TODO(tim): Add autofill data type controller test, and a case to cover |
621 // waiting for the PersonalDataManager. | 633 // waiting for the PersonalDataManager. |
622 TEST_F(ProfileSyncServiceAutofillTest, FailModelAssociation) { | 634 TEST_F(ProfileSyncServiceAutofillTest, FailModelAssociation) { |
623 // Don't create the root autofill node so startup fails. | 635 // Don't create the root autofill node so startup fails. |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 std::vector<AutofillEntry> sync_entries; | 1091 std::vector<AutofillEntry> sync_entries; |
1080 std::vector<AutofillProfile> sync_profiles; | 1092 std::vector<AutofillProfile> sync_profiles; |
1081 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1093 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
1082 EXPECT_EQ(3U, sync_entries.size()); | 1094 EXPECT_EQ(3U, sync_entries.size()); |
1083 EXPECT_EQ(0U, sync_profiles.size()); | 1095 EXPECT_EQ(0U, sync_profiles.size()); |
1084 for (size_t i = 0; i < sync_entries.size(); i++) { | 1096 for (size_t i = 0; i < sync_entries.size(); i++) { |
1085 VLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1097 VLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
1086 << ", " << sync_entries[i].key().value(); | 1098 << ", " << sync_entries[i].key().value(); |
1087 } | 1099 } |
1088 } | 1100 } |
OLD | NEW |