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/webdata/autofill_change.h" | 44 #include "chrome/browser/webdata/autofill_change.h" |
44 #include "chrome/browser/webdata/autofill_entry.h" | 45 #include "chrome/browser/webdata/autofill_entry.h" |
45 #include "chrome/browser/webdata/autofill_table.h" | 46 #include "chrome/browser/webdata/autofill_table.h" |
46 #include "chrome/browser/webdata/web_database.h" | 47 #include "chrome/browser/webdata/web_database.h" |
47 #include "chrome/common/chrome_notification_types.h" | 48 #include "chrome/common/chrome_notification_types.h" |
48 #include "chrome/common/net/gaia/gaia_constants.h" | 49 #include "chrome/common/net/gaia/gaia_constants.h" |
49 #include "chrome/test/sync/engine/test_id_factory.h" | 50 #include "chrome/test/sync/engine/test_id_factory.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); |
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, |
dhollowa
2011/09/01 20:17:49
nit: s/ */* /
GeorgeY
2011/09/02 04:34:12
Done. and in other places in this file
| |
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 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 bool AddAutofillSyncNode(const AutofillProfile& profile) { | 362 bool AddAutofillSyncNode(const AutofillProfile& profile) { |
356 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); | 363 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); |
357 sync_api::ReadNode autofill_root(&trans); | 364 sync_api::ReadNode autofill_root(&trans); |
358 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag)) | 365 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag)) |
359 return false; | 366 return false; |
360 sync_api::WriteNode node(&trans); | 367 sync_api::WriteNode node(&trans); |
361 std::string tag = profile.guid(); | 368 std::string tag = profile.guid(); |
362 if (!node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE, | 369 if (!node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE, |
363 autofill_root, tag)) | 370 autofill_root, tag)) |
364 return false; | 371 return false; |
365 AutofillProfileChangeProcessor::WriteAutofillProfile(profile, &node); | 372 sync_pb::EntitySpecifics specifics; |
373 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics); | |
374 sync_pb::AutofillProfileSpecifics* profile_specifics = | |
375 specifics.MutableExtension(sync_pb::autofill_profile); | |
376 node.SetAutofillProfileSpecifics(*profile_specifics); | |
366 return true; | 377 return true; |
367 } | 378 } |
368 | 379 |
369 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries, | 380 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries, |
370 std::vector<AutofillProfile>* profiles) { | 381 std::vector<AutofillProfile>* profiles) { |
371 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); | 382 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); |
372 sync_api::ReadNode autofill_root(&trans); | 383 sync_api::ReadNode autofill_root(&trans); |
373 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillTag)) | 384 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillTag)) |
374 return false; | 385 return false; |
375 | 386 |
(...skipping 11 matching lines...) Expand all Loading... | |
387 std::vector<base::Time> timestamps; | 398 std::vector<base::Time> timestamps; |
388 int timestamps_count = autofill.usage_timestamp_size(); | 399 int timestamps_count = autofill.usage_timestamp_size(); |
389 for (int i = 0; i < timestamps_count; ++i) { | 400 for (int i = 0; i < timestamps_count; ++i) { |
390 timestamps.push_back(Time::FromInternalValue( | 401 timestamps.push_back(Time::FromInternalValue( |
391 autofill.usage_timestamp(i))); | 402 autofill.usage_timestamp(i))); |
392 } | 403 } |
393 entries->push_back(AutofillEntry(key, timestamps)); | 404 entries->push_back(AutofillEntry(key, timestamps)); |
394 } else if (autofill.has_profile()) { | 405 } else if (autofill.has_profile()) { |
395 AutofillProfile p; | 406 AutofillProfile p; |
396 p.set_guid(autofill.profile().guid()); | 407 p.set_guid(autofill.profile().guid()); |
397 AutofillProfileModelAssociator::OverwriteProfileWithServerData(&p, | 408 AutofillProfileSyncableService::OverwriteProfileWithServerData(&p, |
398 autofill.profile()); | 409 autofill.profile()); |
399 profiles->push_back(p); | 410 profiles->push_back(p); |
400 } | 411 } |
401 child_id = child_node.GetSuccessorId(); | 412 child_id = child_node.GetSuccessorId(); |
402 } | 413 } |
403 return true; | 414 return true; |
404 } | 415 } |
405 | 416 |
406 bool GetAutofillProfilesFromSyncDBUnderProfileNode( | 417 bool GetAutofillProfilesFromSyncDBUnderProfileNode( |
407 std::vector<AutofillProfile>* profiles) { | 418 std::vector<AutofillProfile>* profiles) { |
408 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); | 419 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); |
409 sync_api::ReadNode autofill_root(&trans); | 420 sync_api::ReadNode autofill_root(&trans); |
410 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag)) | 421 if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag)) |
411 return false; | 422 return false; |
412 | 423 |
413 int64 child_id = autofill_root.GetFirstChildId(); | 424 int64 child_id = autofill_root.GetFirstChildId(); |
414 while (child_id != sync_api::kInvalidId) { | 425 while (child_id != sync_api::kInvalidId) { |
415 sync_api::ReadNode child_node(&trans); | 426 sync_api::ReadNode child_node(&trans); |
416 if (!child_node.InitByIdLookup(child_id)) | 427 if (!child_node.InitByIdLookup(child_id)) |
417 return false; | 428 return false; |
418 | 429 |
419 const sync_pb::AutofillProfileSpecifics& autofill( | 430 const sync_pb::AutofillProfileSpecifics& autofill( |
420 child_node.GetAutofillProfileSpecifics()); | 431 child_node.GetAutofillProfileSpecifics()); |
421 AutofillProfile p; | 432 AutofillProfile p; |
422 p.set_guid(autofill.guid()); | 433 p.set_guid(autofill.guid()); |
423 AutofillProfileModelAssociator::OverwriteProfileWithServerData(&p, | 434 AutofillProfileSyncableService::OverwriteProfileWithServerData(&p, |
424 autofill); | 435 autofill); |
425 profiles->push_back(p); | 436 profiles->push_back(p); |
426 child_id = child_node.GetSuccessorId(); | 437 child_id = child_node.GetSuccessorId(); |
427 } | 438 } |
428 return true; | 439 return true; |
429 } | 440 } |
430 | 441 |
431 void SetIdleChangeProcessorExpectations() { | 442 void SetIdleChangeProcessorExpectations() { |
432 EXPECT_CALL(autofill_table_, RemoveFormElement(_, _)).Times(0); | 443 EXPECT_CALL(autofill_table_, RemoveFormElement(_, _)).Times(0); |
433 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)).Times(0); | 444 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)).Times(0); |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1079 std::vector<AutofillEntry> sync_entries; | 1090 std::vector<AutofillEntry> sync_entries; |
1080 std::vector<AutofillProfile> sync_profiles; | 1091 std::vector<AutofillProfile> sync_profiles; |
1081 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1092 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
1082 EXPECT_EQ(3U, sync_entries.size()); | 1093 EXPECT_EQ(3U, sync_entries.size()); |
1083 EXPECT_EQ(0U, sync_profiles.size()); | 1094 EXPECT_EQ(0U, sync_profiles.size()); |
1084 for (size_t i = 0; i < sync_entries.size(); i++) { | 1095 for (size_t i = 0; i < sync_entries.size(); i++) { |
1085 VLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1096 VLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
1086 << ", " << sync_entries[i].key().value(); | 1097 << ", " << sync_entries[i].key().value(); |
1087 } | 1098 } |
1088 } | 1099 } |
OLD | NEW |