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 20 matching lines...) Expand all Loading... |
31 #include "components/autofill/core/browser/personal_data_manager.h" | 31 #include "components/autofill/core/browser/personal_data_manager.h" |
32 #include "components/autofill/core/browser/webdata/autocomplete_syncable_service
.h" | 32 #include "components/autofill/core/browser/webdata/autocomplete_syncable_service
.h" |
33 #include "components/autofill/core/browser/webdata/autofill_change.h" | 33 #include "components/autofill/core/browser/webdata/autofill_change.h" |
34 #include "components/autofill/core/browser/webdata/autofill_data_type_controller
.h" | 34 #include "components/autofill/core/browser/webdata/autofill_data_type_controller
.h" |
35 #include "components/autofill/core/browser/webdata/autofill_entry.h" | 35 #include "components/autofill/core/browser/webdata/autofill_entry.h" |
36 #include "components/autofill/core/browser/webdata/autofill_profile_data_type_co
ntroller.h" | 36 #include "components/autofill/core/browser/webdata/autofill_profile_data_type_co
ntroller.h" |
37 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_ser
vice.h" | 37 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_ser
vice.h" |
38 #include "components/autofill/core/browser/webdata/autofill_table.h" | 38 #include "components/autofill/core/browser/webdata/autofill_table.h" |
39 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 39 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
40 #include "components/autofill/core/common/autofill_pref_names.h" | 40 #include "components/autofill/core/common/autofill_pref_names.h" |
41 #include "components/browser_sync/browser/abstract_profile_sync_service_test.h" | 41 #include "components/browser_sync/abstract_profile_sync_service_test.h" |
42 #include "components/browser_sync/browser/profile_sync_service.h" | 42 #include "components/browser_sync/profile_sync_service.h" |
43 #include "components/browser_sync/browser/test_profile_sync_service.h" | 43 #include "components/browser_sync/test_profile_sync_service.h" |
44 #include "components/sync/base/model_type.h" | 44 #include "components/sync/base/model_type.h" |
45 #include "components/sync/core/data_type_debug_info_listener.h" | 45 #include "components/sync/core/data_type_debug_info_listener.h" |
46 #include "components/sync/core/read_node.h" | 46 #include "components/sync/core/read_node.h" |
47 #include "components/sync/core/read_transaction.h" | 47 #include "components/sync/core/read_transaction.h" |
48 #include "components/sync/core/write_node.h" | 48 #include "components/sync/core/write_node.h" |
49 #include "components/sync/core/write_transaction.h" | 49 #include "components/sync/core/write_transaction.h" |
50 #include "components/sync/driver/data_type_controller.h" | 50 #include "components/sync/driver/data_type_controller.h" |
51 #include "components/sync/driver/data_type_manager_impl.h" | 51 #include "components/sync/driver/data_type_manager_impl.h" |
52 #include "components/sync/driver/sync_api_component_factory_mock.h" | 52 #include "components/sync/driver/sync_api_component_factory_mock.h" |
53 #include "components/sync/protocol/autofill_specifics.pb.h" | 53 #include "components/sync/protocol/autofill_specifics.pb.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 MOCK_METHOD1(GetAllAutofillEntries, | 145 MOCK_METHOD1(GetAllAutofillEntries, |
146 bool(std::vector<AutofillEntry>* entries)); // NOLINT | 146 bool(std::vector<AutofillEntry>* entries)); // NOLINT |
147 MOCK_METHOD4(GetAutofillTimestamps, | 147 MOCK_METHOD4(GetAutofillTimestamps, |
148 bool(const base::string16& name, // NOLINT | 148 bool(const base::string16& name, // NOLINT |
149 const base::string16& value, | 149 const base::string16& value, |
150 Time* date_created, | 150 Time* date_created, |
151 Time* date_last_used)); | 151 Time* date_last_used)); |
152 MOCK_METHOD1(UpdateAutofillEntries, | 152 MOCK_METHOD1(UpdateAutofillEntries, |
153 bool(const std::vector<AutofillEntry>&)); // NOLINT | 153 bool(const std::vector<AutofillEntry>&)); // NOLINT |
154 MOCK_METHOD1(GetAutofillProfiles, | 154 MOCK_METHOD1(GetAutofillProfiles, |
155 bool(std::vector<AutofillProfile*>*)); // NOLINT | 155 bool(std::vector<AutofillProfile*>*)); // NOLINT |
156 MOCK_METHOD1(UpdateAutofillProfile, | 156 MOCK_METHOD1(UpdateAutofillProfile, bool(const AutofillProfile&)); // NOLINT |
157 bool(const AutofillProfile&)); // NOLINT | 157 MOCK_METHOD1(AddAutofillProfile, bool(const AutofillProfile&)); // NOLINT |
158 MOCK_METHOD1(AddAutofillProfile, | 158 MOCK_METHOD1(RemoveAutofillProfile, bool(const std::string&)); // NOLINT |
159 bool(const AutofillProfile&)); // NOLINT | |
160 MOCK_METHOD1(RemoveAutofillProfile, | |
161 bool(const std::string&)); // NOLINT | |
162 }; | 159 }; |
163 | 160 |
164 MATCHER_P(MatchProfiles, profile, "") { | 161 MATCHER_P(MatchProfiles, profile, "") { |
165 return (profile.Compare(arg) == 0); | 162 return (profile.Compare(arg) == 0); |
166 } | 163 } |
167 | 164 |
168 class WebDatabaseFake : public WebDatabase { | 165 class WebDatabaseFake : public WebDatabase { |
169 public: | 166 public: |
170 explicit WebDatabaseFake(AutofillTable* autofill_table) { | 167 explicit WebDatabaseFake(AutofillTable* autofill_table) { |
171 AddTable(autofill_table); | 168 AddTable(autofill_table); |
(...skipping 30 matching lines...) Expand all Loading... |
202 | 199 |
203 private: | 200 private: |
204 WebDatabase* web_database_; | 201 WebDatabase* web_database_; |
205 base::Closure on_changed_; | 202 base::Closure on_changed_; |
206 base::Callback<void(syncer::ModelType)> on_sync_started_; | 203 base::Callback<void(syncer::ModelType)> on_sync_started_; |
207 const scoped_refptr<base::SequencedTaskRunner> ui_thread_; | 204 const scoped_refptr<base::SequencedTaskRunner> ui_thread_; |
208 }; | 205 }; |
209 | 206 |
210 class ProfileSyncServiceAutofillTest; | 207 class ProfileSyncServiceAutofillTest; |
211 | 208 |
212 template<class AutofillProfile> | 209 template <class AutofillProfile> |
213 syncer::ModelType GetModelType() { | 210 syncer::ModelType GetModelType() { |
214 return syncer::UNSPECIFIED; | 211 return syncer::UNSPECIFIED; |
215 } | 212 } |
216 | 213 |
217 template<> | 214 template <> |
218 syncer::ModelType GetModelType<AutofillEntry>() { | 215 syncer::ModelType GetModelType<AutofillEntry>() { |
219 return AUTOFILL; | 216 return AUTOFILL; |
220 } | 217 } |
221 | 218 |
222 template<> | 219 template <> |
223 syncer::ModelType GetModelType<AutofillProfile>() { | 220 syncer::ModelType GetModelType<AutofillProfile>() { |
224 return AUTOFILL_PROFILE; | 221 return AUTOFILL_PROFILE; |
225 } | 222 } |
226 | 223 |
227 class TokenWebDataServiceFake : public TokenWebData { | 224 class TokenWebDataServiceFake : public TokenWebData { |
228 public: | 225 public: |
229 TokenWebDataServiceFake( | 226 TokenWebDataServiceFake( |
230 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, | 227 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, |
231 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread) | 228 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread) |
232 : TokenWebData(ui_thread, db_thread) {} | 229 : TokenWebData(ui_thread, db_thread) {} |
(...skipping 26 matching lines...) Expand all Loading... |
259 : AutofillWebDataService(ui_thread, db_thread), | 256 : AutofillWebDataService(ui_thread, db_thread), |
260 web_database_(NULL), | 257 web_database_(NULL), |
261 autocomplete_syncable_service_(NULL), | 258 autocomplete_syncable_service_(NULL), |
262 autofill_profile_syncable_service_(NULL), | 259 autofill_profile_syncable_service_(NULL), |
263 syncable_service_created_or_destroyed_( | 260 syncable_service_created_or_destroyed_( |
264 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 261 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
265 base::WaitableEvent::InitialState::NOT_SIGNALED), | 262 base::WaitableEvent::InitialState::NOT_SIGNALED), |
266 db_thread_(db_thread), | 263 db_thread_(db_thread), |
267 ui_thread_(ui_thread) {} | 264 ui_thread_(ui_thread) {} |
268 | 265 |
269 void SetDatabase(WebDatabase* web_database) { | 266 void SetDatabase(WebDatabase* web_database) { web_database_ = web_database; } |
270 web_database_ = web_database; | |
271 } | |
272 | 267 |
273 void StartSyncableService() { | 268 void StartSyncableService() { |
274 // The |autofill_profile_syncable_service_| must be constructed on the DB | 269 // The |autofill_profile_syncable_service_| must be constructed on the DB |
275 // thread. | 270 // thread. |
276 const base::Closure& on_changed_callback = base::Bind( | 271 const base::Closure& on_changed_callback = |
277 &WebDataServiceFake::NotifyAutofillMultipleChangedOnUIThread, | 272 base::Bind(&WebDataServiceFake::NotifyAutofillMultipleChangedOnUIThread, |
278 AsWeakPtr()); | 273 AsWeakPtr()); |
279 const base::Callback<void(syncer::ModelType)> on_sync_started_callback = | 274 const base::Callback<void(syncer::ModelType)> on_sync_started_callback = |
280 base::Bind(&WebDataServiceFake::NotifySyncStartedOnUIThread, | 275 base::Bind(&WebDataServiceFake::NotifySyncStartedOnUIThread, |
281 AsWeakPtr()); | 276 AsWeakPtr()); |
282 | 277 |
283 db_thread_->PostTask(FROM_HERE, | 278 db_thread_->PostTask(FROM_HERE, |
284 base::Bind(&WebDataServiceFake::CreateSyncableService, | 279 base::Bind(&WebDataServiceFake::CreateSyncableService, |
285 base::Unretained(this), on_changed_callback, | 280 base::Unretained(this), on_changed_callback, |
286 on_sync_started_callback)); | 281 on_sync_started_callback)); |
287 syncable_service_created_or_destroyed_.Wait(); | 282 syncable_service_created_or_destroyed_.Wait(); |
288 } | 283 } |
(...skipping 10 matching lines...) Expand all Loading... |
299 bool IsDatabaseLoaded() override { return true; } | 294 bool IsDatabaseLoaded() override { return true; } |
300 | 295 |
301 WebDatabase* GetDatabase() override { return web_database_; } | 296 WebDatabase* GetDatabase() override { return web_database_; } |
302 | 297 |
303 void OnAutofillEntriesChanged(const AutofillChangeList& changes) { | 298 void OnAutofillEntriesChanged(const AutofillChangeList& changes) { |
304 WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, | 299 WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, |
305 base::WaitableEvent::InitialState::NOT_SIGNALED); | 300 base::WaitableEvent::InitialState::NOT_SIGNALED); |
306 | 301 |
307 base::Closure notify_cb = | 302 base::Closure notify_cb = |
308 base::Bind(&AutocompleteSyncableService::AutofillEntriesChanged, | 303 base::Bind(&AutocompleteSyncableService::AutofillEntriesChanged, |
309 base::Unretained(autocomplete_syncable_service_), | 304 base::Unretained(autocomplete_syncable_service_), changes); |
310 changes); | |
311 db_thread_->PostTask(FROM_HERE, | 305 db_thread_->PostTask(FROM_HERE, |
312 base::Bind(&RunAndSignal, notify_cb, &event)); | 306 base::Bind(&RunAndSignal, notify_cb, &event)); |
313 event.Wait(); | 307 event.Wait(); |
314 } | 308 } |
315 | 309 |
316 void OnAutofillProfileChanged(const AutofillProfileChange& changes) { | 310 void OnAutofillProfileChanged(const AutofillProfileChange& changes) { |
317 WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, | 311 WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, |
318 base::WaitableEvent::InitialState::NOT_SIGNALED); | 312 base::WaitableEvent::InitialState::NOT_SIGNALED); |
319 | 313 |
320 base::Closure notify_cb = | 314 base::Closure notify_cb = base::Bind( |
321 base::Bind(&AutocompleteSyncableService::AutofillProfileChanged, | 315 &AutocompleteSyncableService::AutofillProfileChanged, |
322 base::Unretained(autofill_profile_syncable_service_), | 316 base::Unretained(autofill_profile_syncable_service_), changes); |
323 changes); | |
324 db_thread_->PostTask(FROM_HERE, | 317 db_thread_->PostTask(FROM_HERE, |
325 base::Bind(&RunAndSignal, notify_cb, &event)); | 318 base::Bind(&RunAndSignal, notify_cb, &event)); |
326 event.Wait(); | 319 event.Wait(); |
327 } | 320 } |
328 | 321 |
329 private: | 322 private: |
330 ~WebDataServiceFake() override {} | 323 ~WebDataServiceFake() override {} |
331 | 324 |
332 void CreateSyncableService( | 325 void CreateSyncableService( |
333 const base::Closure& on_changed_callback, | 326 const base::Closure& on_changed_callback, |
(...skipping 30 matching lines...) Expand all Loading... |
364 | 357 |
365 WaitableEvent syncable_service_created_or_destroyed_; | 358 WaitableEvent syncable_service_created_or_destroyed_; |
366 | 359 |
367 const scoped_refptr<base::SingleThreadTaskRunner> db_thread_; | 360 const scoped_refptr<base::SingleThreadTaskRunner> db_thread_; |
368 const scoped_refptr<base::SingleThreadTaskRunner> ui_thread_; | 361 const scoped_refptr<base::SingleThreadTaskRunner> ui_thread_; |
369 | 362 |
370 DISALLOW_COPY_AND_ASSIGN(WebDataServiceFake); | 363 DISALLOW_COPY_AND_ASSIGN(WebDataServiceFake); |
371 }; | 364 }; |
372 | 365 |
373 ACTION_P(ReturnNewDataTypeManagerWithDebugListener, debug_listener) { | 366 ACTION_P(ReturnNewDataTypeManagerWithDebugListener, debug_listener) { |
374 return new sync_driver::DataTypeManagerImpl( | 367 return new sync_driver::DataTypeManagerImpl(debug_listener, arg1, arg2, arg3, |
375 debug_listener, | 368 arg4); |
376 arg1, | |
377 arg2, | |
378 arg3, | |
379 arg4); | |
380 } | 369 } |
381 | 370 |
382 class MockPersonalDataManager : public PersonalDataManager { | 371 class MockPersonalDataManager : public PersonalDataManager { |
383 public: | 372 public: |
384 MockPersonalDataManager() : PersonalDataManager("en-US") {} | 373 MockPersonalDataManager() : PersonalDataManager("en-US") {} |
385 MOCK_CONST_METHOD0(IsDataLoaded, bool()); | 374 MOCK_CONST_METHOD0(IsDataLoaded, bool()); |
386 MOCK_METHOD0(LoadProfiles, void()); | 375 MOCK_METHOD0(LoadProfiles, void()); |
387 MOCK_METHOD0(LoadCreditCards, void()); | 376 MOCK_METHOD0(LoadCreditCards, void()); |
388 MOCK_METHOD0(Refresh, void()); | 377 MOCK_METHOD0(Refresh, void()); |
389 }; | 378 }; |
390 | 379 |
391 template <class T> class AddAutofillHelper; | 380 template <class T> |
| 381 class AddAutofillHelper; |
392 | 382 |
393 class ProfileSyncServiceAutofillTest | 383 class ProfileSyncServiceAutofillTest |
394 : public AbstractProfileSyncServiceTest, | 384 : public AbstractProfileSyncServiceTest, |
395 public syncer::DataTypeDebugInfoListener { | 385 public syncer::DataTypeDebugInfoListener { |
396 public: | 386 public: |
397 // DataTypeDebugInfoListener implementation. | 387 // DataTypeDebugInfoListener implementation. |
398 void OnDataTypeConfigureComplete(const std::vector< | 388 void OnDataTypeConfigureComplete( |
399 syncer::DataTypeConfigurationStats>& configuration_stats) override { | 389 const std::vector<syncer::DataTypeConfigurationStats>& |
| 390 configuration_stats) override { |
400 ASSERT_EQ(1u, configuration_stats.size()); | 391 ASSERT_EQ(1u, configuration_stats.size()); |
401 association_stats_ = configuration_stats[0].association_stats; | 392 association_stats_ = configuration_stats[0].association_stats; |
402 } | 393 } |
403 | 394 |
404 protected: | 395 protected: |
405 ProfileSyncServiceAutofillTest() : debug_ptr_factory_(this) { | 396 ProfileSyncServiceAutofillTest() : debug_ptr_factory_(this) { |
406 autofill::CountryNames::SetLocaleString("en-US"); | 397 autofill::CountryNames::SetLocaleString("en-US"); |
407 RegisterAutofillPrefs( | 398 RegisterAutofillPrefs( |
408 profile_sync_service_bundle()->pref_service()->registry()); | 399 profile_sync_service_bundle()->pref_service()->registry()); |
409 | 400 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 base::RunLoop().Run(); | 486 base::RunLoop().Run(); |
496 | 487 |
497 // It's possible this test triggered an unrecoverable error, in which case | 488 // It's possible this test triggered an unrecoverable error, in which case |
498 // we can't get the sync count. | 489 // we can't get the sync count. |
499 if (sync_service()->IsSyncActive()) { | 490 if (sync_service()->IsSyncActive()) { |
500 EXPECT_EQ(GetSyncCount(type), | 491 EXPECT_EQ(GetSyncCount(type), |
501 association_stats_.num_sync_items_after_association); | 492 association_stats_.num_sync_items_after_association); |
502 } | 493 } |
503 EXPECT_EQ(association_stats_.num_sync_items_after_association, | 494 EXPECT_EQ(association_stats_.num_sync_items_after_association, |
504 association_stats_.num_sync_items_before_association + | 495 association_stats_.num_sync_items_before_association + |
505 association_stats_.num_sync_items_added - | 496 association_stats_.num_sync_items_added - |
506 association_stats_.num_sync_items_deleted); | 497 association_stats_.num_sync_items_deleted); |
507 } | 498 } |
508 | 499 |
509 bool AddAutofillSyncNode(const AutofillEntry& entry) { | 500 bool AddAutofillSyncNode(const AutofillEntry& entry) { |
510 syncer::WriteTransaction trans(FROM_HERE, sync_service()->GetUserShare()); | 501 syncer::WriteTransaction trans(FROM_HERE, sync_service()->GetUserShare()); |
511 syncer::WriteNode node(&trans); | 502 syncer::WriteNode node(&trans); |
512 std::string tag = AutocompleteSyncableService::KeyToTag( | 503 std::string tag = AutocompleteSyncableService::KeyToTag( |
513 base::UTF16ToUTF8(entry.key().name()), | 504 base::UTF16ToUTF8(entry.key().name()), |
514 base::UTF16ToUTF8(entry.key().value())); | 505 base::UTF16ToUTF8(entry.key().value())); |
515 syncer::WriteNode::InitUniqueByCreationResult result = | 506 syncer::WriteNode::InitUniqueByCreationResult result = |
516 node.InitUniqueByCreation(AUTOFILL, tag); | 507 node.InitUniqueByCreation(AUTOFILL, tag); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 return false; | 544 return false; |
554 | 545 |
555 const sync_pb::AutofillSpecifics& autofill( | 546 const sync_pb::AutofillSpecifics& autofill( |
556 child_node.GetEntitySpecifics().autofill()); | 547 child_node.GetEntitySpecifics().autofill()); |
557 if (autofill.has_value()) { | 548 if (autofill.has_value()) { |
558 AutofillKey key(base::UTF8ToUTF16(autofill.name()), | 549 AutofillKey key(base::UTF8ToUTF16(autofill.name()), |
559 base::UTF8ToUTF16(autofill.value())); | 550 base::UTF8ToUTF16(autofill.value())); |
560 std::vector<Time> timestamps; | 551 std::vector<Time> timestamps; |
561 int timestamps_count = autofill.usage_timestamp_size(); | 552 int timestamps_count = autofill.usage_timestamp_size(); |
562 for (int i = 0; i < timestamps_count; ++i) { | 553 for (int i = 0; i < timestamps_count; ++i) { |
563 timestamps.push_back(Time::FromInternalValue( | 554 timestamps.push_back( |
564 autofill.usage_timestamp(i))); | 555 Time::FromInternalValue(autofill.usage_timestamp(i))); |
565 } | 556 } |
566 entries->push_back( | 557 entries->push_back( |
567 AutofillEntry(key, timestamps.front(), timestamps.back())); | 558 AutofillEntry(key, timestamps.front(), timestamps.back())); |
568 } else if (autofill.has_profile()) { | 559 } else if (autofill.has_profile()) { |
569 AutofillProfile p; | 560 AutofillProfile p; |
570 p.set_guid(autofill.profile().guid()); | 561 p.set_guid(autofill.profile().guid()); |
571 AutofillProfileSyncableService::OverwriteProfileWithServerData( | 562 AutofillProfileSyncableService::OverwriteProfileWithServerData( |
572 autofill.profile(), &p); | 563 autofill.profile(), &p); |
573 profiles->push_back(p); | 564 profiles->push_back(p); |
574 } | 565 } |
(...skipping 11 matching lines...) Expand all Loading... |
586 } | 577 } |
587 | 578 |
588 int64_t child_id = autofill_root.GetFirstChildId(); | 579 int64_t child_id = autofill_root.GetFirstChildId(); |
589 while (child_id != syncer::kInvalidId) { | 580 while (child_id != syncer::kInvalidId) { |
590 syncer::ReadNode child_node(&trans); | 581 syncer::ReadNode child_node(&trans); |
591 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) | 582 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) |
592 return false; | 583 return false; |
593 | 584 |
594 const sync_pb::AutofillProfileSpecifics& autofill( | 585 const sync_pb::AutofillProfileSpecifics& autofill( |
595 child_node.GetEntitySpecifics().autofill_profile()); | 586 child_node.GetEntitySpecifics().autofill_profile()); |
596 AutofillProfile p; | 587 AutofillProfile p; |
597 p.set_guid(autofill.guid()); | 588 p.set_guid(autofill.guid()); |
598 AutofillProfileSyncableService::OverwriteProfileWithServerData(autofill, | 589 AutofillProfileSyncableService::OverwriteProfileWithServerData(autofill, |
599 &p); | 590 &p); |
600 profiles->push_back(p); | 591 profiles->push_back(p); |
601 child_id = child_node.GetSuccessorId(); | 592 child_id = child_node.GetSuccessorId(); |
602 } | 593 } |
603 return true; | 594 return true; |
604 } | 595 } |
605 | 596 |
606 void SetIdleChangeProcessorExpectations() { | 597 void SetIdleChangeProcessorExpectations() { |
607 EXPECT_CALL(autofill_table_, RemoveFormElement(_, _)).Times(0); | 598 EXPECT_CALL(autofill_table_, RemoveFormElement(_, _)).Times(0); |
608 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _, _)).Times(0); | 599 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _, _)).Times(0); |
609 | 600 |
610 // Only permit UpdateAutofillEntries() to be called with an empty list. | 601 // Only permit UpdateAutofillEntries() to be called with an empty list. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 | 658 |
668 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceAutofillTest); | 659 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceAutofillTest); |
669 }; | 660 }; |
670 | 661 |
671 template <class T> | 662 template <class T> |
672 class AddAutofillHelper { | 663 class AddAutofillHelper { |
673 public: | 664 public: |
674 AddAutofillHelper(ProfileSyncServiceAutofillTest* test, | 665 AddAutofillHelper(ProfileSyncServiceAutofillTest* test, |
675 const std::vector<T>& entries) | 666 const std::vector<T>& entries) |
676 : callback_(base::Bind(&AddAutofillHelper::AddAutofillCallback, | 667 : callback_(base::Bind(&AddAutofillHelper::AddAutofillCallback, |
677 base::Unretained(this), test, entries)), | 668 base::Unretained(this), |
678 success_(false) { | 669 test, |
679 } | 670 entries)), |
| 671 success_(false) {} |
680 | 672 |
681 const base::Closure& callback() const { return callback_; } | 673 const base::Closure& callback() const { return callback_; } |
682 bool success() { return success_; } | 674 bool success() { return success_; } |
683 | 675 |
684 private: | 676 private: |
685 void AddAutofillCallback(ProfileSyncServiceAutofillTest* test, | 677 void AddAutofillCallback(ProfileSyncServiceAutofillTest* test, |
686 const std::vector<T>& entries) { | 678 const std::vector<T>& entries) { |
687 if (!test->CreateRoot(GetModelType<T>())) | 679 if (!test->CreateRoot(GetModelType<T>())) |
688 return; | 680 return; |
689 | 681 |
690 for (size_t i = 0; i < entries.size(); ++i) { | 682 for (size_t i = 0; i < entries.size(); ++i) { |
691 if (!test->AddAutofillSyncNode(entries[i])) | 683 if (!test->AddAutofillSyncNode(entries[i])) |
692 return; | 684 return; |
693 } | 685 } |
694 success_ = true; | 686 success_ = true; |
695 } | 687 } |
696 | 688 |
697 base::Closure callback_; | 689 base::Closure callback_; |
698 bool success_; | 690 bool success_; |
699 }; | 691 }; |
700 | 692 |
701 // Overload write transaction to use custom NotifyTransactionComplete | 693 // Overload write transaction to use custom NotifyTransactionComplete |
702 class WriteTransactionTest: public WriteTransaction { | 694 class WriteTransactionTest : public WriteTransaction { |
703 public: | 695 public: |
704 WriteTransactionTest(const tracked_objects::Location& from_here, | 696 WriteTransactionTest(const tracked_objects::Location& from_here, |
705 WriterTag writer, | 697 WriterTag writer, |
706 syncer::syncable::Directory* directory, | 698 syncer::syncable::Directory* directory, |
707 WaitableEvent* wait_for_syncapi) | 699 WaitableEvent* wait_for_syncapi) |
708 : WriteTransaction(from_here, writer, directory), | 700 : WriteTransaction(from_here, writer, directory), |
709 wait_for_syncapi_(wait_for_syncapi) {} | 701 wait_for_syncapi_(wait_for_syncapi) {} |
710 | 702 |
711 void NotifyTransactionComplete(syncer::ModelTypeSet types) override { | 703 void NotifyTransactionComplete(syncer::ModelTypeSet types) override { |
712 // This is where we differ. Force a thread change here, giving another | 704 // This is where we differ. Force a thread change here, giving another |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 void CreateNewEntry(const AutofillEntry& entry) { | 780 void CreateNewEntry(const AutofillEntry& entry) { |
789 entry_ = entry; | 781 entry_ = entry; |
790 ASSERT_FALSE(db_thread_->RunsTasksOnCurrentThread()); | 782 ASSERT_FALSE(db_thread_->RunsTasksOnCurrentThread()); |
791 if (!db_thread_->PostTask(FROM_HERE, | 783 if (!db_thread_->PostTask(FROM_HERE, |
792 base::Bind(&FakeServerUpdater::Update, this))) { | 784 base::Bind(&FakeServerUpdater::Update, this))) { |
793 NOTREACHED() << "Failed to post task to the db thread."; | 785 NOTREACHED() << "Failed to post task to the db thread."; |
794 return; | 786 return; |
795 } | 787 } |
796 } | 788 } |
797 | 789 |
798 void WaitForUpdateCompletion() { | 790 void WaitForUpdateCompletion() { is_finished_.Wait(); } |
799 is_finished_.Wait(); | |
800 } | |
801 | 791 |
802 private: | 792 private: |
803 friend class base::RefCountedThreadSafe<FakeServerUpdater>; | 793 friend class base::RefCountedThreadSafe<FakeServerUpdater>; |
804 ~FakeServerUpdater() { } | 794 ~FakeServerUpdater() {} |
805 | 795 |
806 AutofillEntry entry_; | 796 AutofillEntry entry_; |
807 TestProfileSyncService* service_; | 797 TestProfileSyncService* service_; |
808 WaitableEvent* const wait_for_start_; | 798 WaitableEvent* const wait_for_start_; |
809 WaitableEvent* const wait_for_syncapi_; | 799 WaitableEvent* const wait_for_syncapi_; |
810 WaitableEvent is_finished_; | 800 WaitableEvent is_finished_; |
811 syncer::syncable::Id parent_id_; | 801 syncer::syncable::Id parent_id_; |
812 scoped_refptr<base::SequencedTaskRunner> db_thread_; | 802 scoped_refptr<base::SequencedTaskRunner> db_thread_; |
813 | 803 |
814 DISALLOW_COPY_AND_ASSIGN(FakeServerUpdater); | 804 DISALLOW_COPY_AND_ASSIGN(FakeServerUpdater); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 ASSERT_EQ(1U, entries.size()); | 845 ASSERT_EQ(1U, entries.size()); |
856 EXPECT_TRUE(entries[0] == sync_entries[0]); | 846 EXPECT_TRUE(entries[0] == sync_entries[0]); |
857 EXPECT_EQ(0U, sync_profiles.size()); | 847 EXPECT_EQ(0U, sync_profiles.size()); |
858 } | 848 } |
859 | 849 |
860 TEST_F(ProfileSyncServiceAutofillTest, HasProfileEmptySync) { | 850 TEST_F(ProfileSyncServiceAutofillTest, HasProfileEmptySync) { |
861 std::vector<AutofillProfile*> profiles; | 851 std::vector<AutofillProfile*> profiles; |
862 std::vector<AutofillProfile> expected_profiles; | 852 std::vector<AutofillProfile> expected_profiles; |
863 // Owned by GetAutofillProfiles caller. | 853 // Owned by GetAutofillProfiles caller. |
864 AutofillProfile* profile0 = new AutofillProfile; | 854 AutofillProfile* profile0 = new AutofillProfile; |
865 autofill::test::SetProfileInfoWithGuid(profile0, | 855 autofill::test::SetProfileInfoWithGuid( |
866 "54B3F9AA-335E-4F71-A27D-719C41564230", "Billing", | 856 profile0, "54B3F9AA-335E-4F71-A27D-719C41564230", "Billing", "Mitchell", |
867 "Mitchell", "Morrison", | 857 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
868 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 858 "Hollywood", "CA", "91601", "US", "12345678910"); |
869 "91601", "US", "12345678910"); | |
870 profiles.push_back(profile0); | 859 profiles.push_back(profile0); |
871 expected_profiles.push_back(*profile0); | 860 expected_profiles.push_back(*profile0); |
872 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) | 861 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
873 .WillOnce(DoAll(SetArgumentPointee<0>(profiles), Return(true))); | 862 .WillOnce(DoAll(SetArgumentPointee<0>(profiles), Return(true))); |
874 EXPECT_CALL(personal_data_manager(), Refresh()); | 863 EXPECT_CALL(personal_data_manager(), Refresh()); |
875 SetIdleChangeProcessorExpectations(); | 864 SetIdleChangeProcessorExpectations(); |
876 CreateRootHelper create_root(this, AUTOFILL_PROFILE); | 865 CreateRootHelper create_root(this, AUTOFILL_PROFILE); |
877 StartSyncService(create_root.callback(), false, AUTOFILL_PROFILE); | 866 StartSyncService(create_root.callback(), false, AUTOFILL_PROFILE); |
878 ASSERT_TRUE(create_root.success()); | 867 ASSERT_TRUE(create_root.success()); |
879 std::vector<AutofillProfile> sync_profiles; | 868 std::vector<AutofillProfile> sync_profiles; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 EXPECT_CALL(personal_data_manager(), Refresh()); | 912 EXPECT_CALL(personal_data_manager(), Refresh()); |
924 StartSyncService(add_autofill.callback(), false, AUTOFILL); | 913 StartSyncService(add_autofill.callback(), false, AUTOFILL); |
925 ASSERT_TRUE(add_autofill.success()); | 914 ASSERT_TRUE(add_autofill.success()); |
926 | 915 |
927 std::set<AutofillEntry> expected_entries; | 916 std::set<AutofillEntry> expected_entries; |
928 expected_entries.insert(native_entry); | 917 expected_entries.insert(native_entry); |
929 expected_entries.insert(sync_entry); | 918 expected_entries.insert(sync_entry); |
930 | 919 |
931 std::vector<AutofillEntry> new_sync_entries; | 920 std::vector<AutofillEntry> new_sync_entries; |
932 std::vector<AutofillProfile> new_sync_profiles; | 921 std::vector<AutofillProfile> new_sync_profiles; |
933 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, | 922 ASSERT_TRUE( |
934 &new_sync_profiles)); | 923 GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); |
935 std::set<AutofillEntry> new_sync_entries_set(new_sync_entries.begin(), | 924 std::set<AutofillEntry> new_sync_entries_set(new_sync_entries.begin(), |
936 new_sync_entries.end()); | 925 new_sync_entries.end()); |
937 | 926 |
938 EXPECT_TRUE(expected_entries == new_sync_entries_set); | 927 EXPECT_TRUE(expected_entries == new_sync_entries_set); |
939 } | 928 } |
940 | 929 |
941 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeEntry) { | 930 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeEntry) { |
942 AutofillEntry native_entry(MakeAutofillEntry("merge", "entry", 1)); | 931 AutofillEntry native_entry(MakeAutofillEntry("merge", "entry", 1)); |
943 AutofillEntry sync_entry(MakeAutofillEntry("merge", "entry", 2)); | 932 AutofillEntry sync_entry(MakeAutofillEntry("merge", "entry", 2)); |
944 AutofillEntry merged_entry(MakeAutofillEntry("merge", "entry", 1, 2)); | 933 AutofillEntry merged_entry(MakeAutofillEntry("merge", "entry", 1, 2)); |
945 | 934 |
946 std::vector<AutofillEntry> native_entries; | 935 std::vector<AutofillEntry> native_entries; |
947 native_entries.push_back(native_entry); | 936 native_entries.push_back(native_entry); |
948 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) | 937 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) |
949 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); | 938 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); |
950 | 939 |
951 std::vector<AutofillEntry> sync_entries; | 940 std::vector<AutofillEntry> sync_entries; |
952 sync_entries.push_back(sync_entry); | 941 sync_entries.push_back(sync_entry); |
953 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries); | 942 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries); |
954 | 943 |
955 EXPECT_CALL(autofill_table(), | 944 EXPECT_CALL(autofill_table(), |
956 UpdateAutofillEntries(ElementsAre(merged_entry))) | 945 UpdateAutofillEntries(ElementsAre(merged_entry))) |
957 .WillOnce(Return(true)); | 946 .WillOnce(Return(true)); |
958 EXPECT_CALL(personal_data_manager(), Refresh()); | 947 EXPECT_CALL(personal_data_manager(), Refresh()); |
959 StartSyncService(add_autofill.callback(), false, AUTOFILL); | 948 StartSyncService(add_autofill.callback(), false, AUTOFILL); |
960 ASSERT_TRUE(add_autofill.success()); | 949 ASSERT_TRUE(add_autofill.success()); |
961 | 950 |
962 std::vector<AutofillEntry> new_sync_entries; | 951 std::vector<AutofillEntry> new_sync_entries; |
963 std::vector<AutofillProfile> new_sync_profiles; | 952 std::vector<AutofillProfile> new_sync_profiles; |
964 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, | 953 ASSERT_TRUE( |
965 &new_sync_profiles)); | 954 GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); |
966 ASSERT_EQ(1U, new_sync_entries.size()); | 955 ASSERT_EQ(1U, new_sync_entries.size()); |
967 EXPECT_TRUE(merged_entry == new_sync_entries[0]); | 956 EXPECT_TRUE(merged_entry == new_sync_entries[0]); |
968 } | 957 } |
969 | 958 |
970 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfile) { | 959 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfile) { |
971 AutofillProfile sync_profile; | 960 AutofillProfile sync_profile; |
972 autofill::test::SetProfileInfoWithGuid(&sync_profile, | 961 autofill::test::SetProfileInfoWithGuid( |
973 "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", | 962 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
974 "Mitchell", "Morrison", | 963 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", |
975 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 964 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
976 "91601", "US", "12345678910"); | |
977 | 965 |
978 AutofillProfile* native_profile = new AutofillProfile; | 966 AutofillProfile* native_profile = new AutofillProfile; |
979 autofill::test::SetProfileInfoWithGuid(native_profile, | 967 autofill::test::SetProfileInfoWithGuid( |
980 "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", "Alicia", "Saenz", | 968 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
981 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", | 969 "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", |
982 "32801", "US", "19482937549"); | 970 "Orlando", "FL", "32801", "US", "19482937549"); |
983 | 971 |
984 std::vector<AutofillProfile*> native_profiles; | 972 std::vector<AutofillProfile*> native_profiles; |
985 native_profiles.push_back(native_profile); | 973 native_profiles.push_back(native_profile); |
986 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) | 974 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
987 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); | 975 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
988 | 976 |
989 std::vector<AutofillProfile> sync_profiles; | 977 std::vector<AutofillProfile> sync_profiles; |
990 sync_profiles.push_back(sync_profile); | 978 sync_profiles.push_back(sync_profile); |
991 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); | 979 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
992 | 980 |
993 EXPECT_CALL(autofill_table(), | 981 EXPECT_CALL(autofill_table(), |
994 UpdateAutofillProfile(MatchProfiles(sync_profile))) | 982 UpdateAutofillProfile(MatchProfiles(sync_profile))) |
995 .WillOnce(Return(true)); | 983 .WillOnce(Return(true)); |
996 EXPECT_CALL(personal_data_manager(), Refresh()); | 984 EXPECT_CALL(personal_data_manager(), Refresh()); |
997 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); | 985 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); |
998 ASSERT_TRUE(add_autofill.success()); | 986 ASSERT_TRUE(add_autofill.success()); |
999 | 987 |
1000 std::vector<AutofillProfile> new_sync_profiles; | 988 std::vector<AutofillProfile> new_sync_profiles; |
1001 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( | 989 ASSERT_TRUE( |
1002 &new_sync_profiles)); | 990 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); |
1003 ASSERT_EQ(1U, new_sync_profiles.size()); | 991 ASSERT_EQ(1U, new_sync_profiles.size()); |
1004 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0])); | 992 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0])); |
1005 } | 993 } |
1006 | 994 |
1007 // Tests that a sync with a new native profile that matches a more recent new | 995 // Tests that a sync with a new native profile that matches a more recent new |
1008 // sync profile but with less information results in the native profile being | 996 // sync profile but with less information results in the native profile being |
1009 // deleted and replaced by the sync profile with merged usage stats. | 997 // deleted and replaced by the sync profile with merged usage stats. |
1010 TEST_F( | 998 TEST_F( |
1011 ProfileSyncServiceAutofillTest, | 999 ProfileSyncServiceAutofillTest, |
1012 HasNativeHasSyncMergeSimilarProfileCombine_SyncHasMoreInfoAndMoreRecent) { | 1000 HasNativeHasSyncMergeSimilarProfileCombine_SyncHasMoreInfoAndMoreRecent) { |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 // The two profiles should be kept. | 1216 // The two profiles should be kept. |
1229 ASSERT_EQ(2U, new_sync_profiles.size()); | 1217 ASSERT_EQ(2U, new_sync_profiles.size()); |
1230 } | 1218 } |
1231 | 1219 |
1232 // Tests that a new native profile that is the same as a new sync profile except | 1220 // Tests that a new native profile that is the same as a new sync profile except |
1233 // with different GUIDs results in the native profile being deleted and replaced | 1221 // with different GUIDs results in the native profile being deleted and replaced |
1234 // by the sync profile. | 1222 // by the sync profile. |
1235 TEST_F(ProfileSyncServiceAutofillTest, MergeProfileWithDifferentGuid) { | 1223 TEST_F(ProfileSyncServiceAutofillTest, MergeProfileWithDifferentGuid) { |
1236 AutofillProfile sync_profile; | 1224 AutofillProfile sync_profile; |
1237 | 1225 |
1238 autofill::test::SetProfileInfoWithGuid(&sync_profile, | 1226 autofill::test::SetProfileInfoWithGuid( |
1239 "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", | 1227 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
1240 "Mitchell", "Morrison", | 1228 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", |
1241 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 1229 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
1242 "91601", "US", "12345678910"); | |
1243 sync_profile.set_use_count(20); | 1230 sync_profile.set_use_count(20); |
1244 sync_profile.set_use_date(base::Time::FromTimeT(1234)); | 1231 sync_profile.set_use_date(base::Time::FromTimeT(1234)); |
1245 | 1232 |
1246 std::string native_guid = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; | 1233 std::string native_guid = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; |
1247 AutofillProfile* native_profile = new AutofillProfile; | 1234 AutofillProfile* native_profile = new AutofillProfile; |
1248 autofill::test::SetProfileInfoWithGuid(native_profile, | 1235 autofill::test::SetProfileInfoWithGuid( |
1249 native_guid.c_str(), "Billing", | 1236 native_profile, native_guid.c_str(), "Billing", "Mitchell", "Morrison", |
1250 "Mitchell", "Morrison", | |
1251 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 1237 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
1252 "91601", "US", "12345678910"); | 1238 "91601", "US", "12345678910"); |
1253 native_profile->set_use_count(5); | 1239 native_profile->set_use_count(5); |
1254 native_profile->set_use_date(base::Time::FromTimeT(4321)); | 1240 native_profile->set_use_date(base::Time::FromTimeT(4321)); |
1255 | 1241 |
1256 std::vector<AutofillProfile*> native_profiles; | 1242 std::vector<AutofillProfile*> native_profiles; |
1257 native_profiles.push_back(native_profile); | 1243 native_profiles.push_back(native_profile); |
1258 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) | 1244 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
1259 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); | 1245 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
1260 | 1246 |
1261 std::vector<AutofillProfile> sync_profiles; | 1247 std::vector<AutofillProfile> sync_profiles; |
1262 sync_profiles.push_back(sync_profile); | 1248 sync_profiles.push_back(sync_profile); |
1263 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); | 1249 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
1264 | 1250 |
1265 EXPECT_CALL(autofill_table(), AddAutofillProfile(_)).WillOnce(Return(true)); | 1251 EXPECT_CALL(autofill_table(), AddAutofillProfile(_)).WillOnce(Return(true)); |
1266 EXPECT_CALL(autofill_table(), RemoveAutofillProfile(native_guid)) | 1252 EXPECT_CALL(autofill_table(), RemoveAutofillProfile(native_guid)) |
1267 .WillOnce(Return(true)); | 1253 .WillOnce(Return(true)); |
1268 EXPECT_CALL(personal_data_manager(), Refresh()); | 1254 EXPECT_CALL(personal_data_manager(), Refresh()); |
1269 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); | 1255 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); |
1270 ASSERT_TRUE(add_autofill.success()); | 1256 ASSERT_TRUE(add_autofill.success()); |
1271 | 1257 |
1272 std::vector<AutofillProfile> new_sync_profiles; | 1258 std::vector<AutofillProfile> new_sync_profiles; |
1273 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( | 1259 ASSERT_TRUE( |
1274 &new_sync_profiles)); | 1260 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); |
1275 // Check that the profiles were merged. | 1261 // Check that the profiles were merged. |
1276 ASSERT_EQ(1U, new_sync_profiles.size()); | 1262 ASSERT_EQ(1U, new_sync_profiles.size()); |
1277 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0])); | 1263 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0])); |
1278 // Check that the sync guid was kept. | 1264 // Check that the sync guid was kept. |
1279 EXPECT_EQ(sync_profile.guid(), new_sync_profiles[0].guid()); | 1265 EXPECT_EQ(sync_profile.guid(), new_sync_profiles[0].guid()); |
1280 // Check that the sync profile use count was kept. | 1266 // Check that the sync profile use count was kept. |
1281 EXPECT_EQ(20U, new_sync_profiles[0].use_count()); | 1267 EXPECT_EQ(20U, new_sync_profiles[0].use_count()); |
1282 // Check that the sync profile use date was kept. | 1268 // Check that the sync profile use date was kept. |
1283 EXPECT_EQ(base::Time::FromTimeT(1234), new_sync_profiles[0].use_date()); | 1269 EXPECT_EQ(base::Time::FromTimeT(1234), new_sync_profiles[0].use_date()); |
1284 } | 1270 } |
(...skipping 14 matching lines...) Expand all Loading... |
1299 SetArgumentPointee<3>(added_entry.date_last_used()), | 1285 SetArgumentPointee<3>(added_entry.date_last_used()), |
1300 Return(true))); | 1286 Return(true))); |
1301 | 1287 |
1302 AutofillChangeList changes; | 1288 AutofillChangeList changes; |
1303 changes.push_back(AutofillChange(AutofillChange::ADD, added_entry.key())); | 1289 changes.push_back(AutofillChange(AutofillChange::ADD, added_entry.key())); |
1304 | 1290 |
1305 web_data_service()->OnAutofillEntriesChanged(changes); | 1291 web_data_service()->OnAutofillEntriesChanged(changes); |
1306 | 1292 |
1307 std::vector<AutofillEntry> new_sync_entries; | 1293 std::vector<AutofillEntry> new_sync_entries; |
1308 std::vector<AutofillProfile> new_sync_profiles; | 1294 std::vector<AutofillProfile> new_sync_profiles; |
1309 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, | 1295 ASSERT_TRUE( |
1310 &new_sync_profiles)); | 1296 GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); |
1311 ASSERT_EQ(1U, new_sync_entries.size()); | 1297 ASSERT_EQ(1U, new_sync_entries.size()); |
1312 EXPECT_TRUE(added_entry == new_sync_entries[0]); | 1298 EXPECT_TRUE(added_entry == new_sync_entries[0]); |
1313 } | 1299 } |
1314 | 1300 |
1315 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfile) { | 1301 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfile) { |
1316 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)).WillOnce(Return(true)); | 1302 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)).WillOnce(Return(true)); |
1317 EXPECT_CALL(personal_data_manager(), Refresh()); | 1303 EXPECT_CALL(personal_data_manager(), Refresh()); |
1318 SetIdleChangeProcessorExpectations(); | 1304 SetIdleChangeProcessorExpectations(); |
1319 CreateRootHelper create_root(this, AUTOFILL_PROFILE); | 1305 CreateRootHelper create_root(this, AUTOFILL_PROFILE); |
1320 StartSyncService(create_root.callback(), false, AUTOFILL_PROFILE); | 1306 StartSyncService(create_root.callback(), false, AUTOFILL_PROFILE); |
1321 ASSERT_TRUE(create_root.success()); | 1307 ASSERT_TRUE(create_root.success()); |
1322 | 1308 |
1323 AutofillProfile added_profile; | 1309 AutofillProfile added_profile; |
1324 autofill::test::SetProfileInfoWithGuid(&added_profile, | 1310 autofill::test::SetProfileInfoWithGuid( |
1325 "D6ADA912-D374-4C0A-917D-F5C8EBE43011", "Josephine", "Alicia", "Saenz", | 1311 &added_profile, "D6ADA912-D374-4C0A-917D-F5C8EBE43011", "Josephine", |
1326 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", | 1312 "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", |
1327 "32801", "US", "19482937549"); | 1313 "Orlando", "FL", "32801", "US", "19482937549"); |
1328 | 1314 |
1329 AutofillProfileChange change( | 1315 AutofillProfileChange change(AutofillProfileChange::ADD, added_profile.guid(), |
1330 AutofillProfileChange::ADD, added_profile.guid(), &added_profile); | 1316 &added_profile); |
1331 web_data_service()->OnAutofillProfileChanged(change); | 1317 web_data_service()->OnAutofillProfileChanged(change); |
1332 | 1318 |
1333 std::vector<AutofillProfile> new_sync_profiles; | 1319 std::vector<AutofillProfile> new_sync_profiles; |
1334 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( | 1320 ASSERT_TRUE( |
1335 &new_sync_profiles)); | 1321 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); |
1336 ASSERT_EQ(1U, new_sync_profiles.size()); | 1322 ASSERT_EQ(1U, new_sync_profiles.size()); |
1337 EXPECT_EQ(0, added_profile.Compare(new_sync_profiles[0])); | 1323 EXPECT_EQ(0, added_profile.Compare(new_sync_profiles[0])); |
1338 } | 1324 } |
1339 | 1325 |
1340 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateEntry) { | 1326 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateEntry) { |
1341 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1)); | 1327 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1)); |
1342 std::vector<AutofillEntry> original_entries; | 1328 std::vector<AutofillEntry> original_entries; |
1343 original_entries.push_back(original_entry); | 1329 original_entries.push_back(original_entry); |
1344 | 1330 |
1345 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) | 1331 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) |
1346 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); | 1332 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); |
1347 EXPECT_CALL(personal_data_manager(), Refresh()); | 1333 EXPECT_CALL(personal_data_manager(), Refresh()); |
1348 CreateRootHelper create_root(this, AUTOFILL); | 1334 CreateRootHelper create_root(this, AUTOFILL); |
1349 StartSyncService(create_root.callback(), false, AUTOFILL); | 1335 StartSyncService(create_root.callback(), false, AUTOFILL); |
1350 ASSERT_TRUE(create_root.success()); | 1336 ASSERT_TRUE(create_root.success()); |
1351 | 1337 |
1352 AutofillEntry updated_entry(MakeAutofillEntry("my", "entry", 1, 2)); | 1338 AutofillEntry updated_entry(MakeAutofillEntry("my", "entry", 1, 2)); |
1353 | 1339 |
1354 EXPECT_CALL(autofill_table(), GetAutofillTimestamps(_, _, _, _)) | 1340 EXPECT_CALL(autofill_table(), GetAutofillTimestamps(_, _, _, _)) |
1355 .WillOnce(DoAll(SetArgumentPointee<2>(updated_entry.date_created()), | 1341 .WillOnce(DoAll(SetArgumentPointee<2>(updated_entry.date_created()), |
1356 SetArgumentPointee<3>(updated_entry.date_last_used()), | 1342 SetArgumentPointee<3>(updated_entry.date_last_used()), |
1357 Return(true))); | 1343 Return(true))); |
1358 | 1344 |
1359 AutofillChangeList changes; | 1345 AutofillChangeList changes; |
1360 changes.push_back(AutofillChange(AutofillChange::UPDATE, | 1346 changes.push_back( |
1361 updated_entry.key())); | 1347 AutofillChange(AutofillChange::UPDATE, updated_entry.key())); |
1362 web_data_service()->OnAutofillEntriesChanged(changes); | 1348 web_data_service()->OnAutofillEntriesChanged(changes); |
1363 | 1349 |
1364 std::vector<AutofillEntry> new_sync_entries; | 1350 std::vector<AutofillEntry> new_sync_entries; |
1365 std::vector<AutofillProfile> new_sync_profiles; | 1351 std::vector<AutofillProfile> new_sync_profiles; |
1366 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, | 1352 ASSERT_TRUE( |
1367 &new_sync_profiles)); | 1353 GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); |
1368 ASSERT_EQ(1U, new_sync_entries.size()); | 1354 ASSERT_EQ(1U, new_sync_entries.size()); |
1369 EXPECT_TRUE(updated_entry == new_sync_entries[0]); | 1355 EXPECT_TRUE(updated_entry == new_sync_entries[0]); |
1370 } | 1356 } |
1371 | 1357 |
1372 | |
1373 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveEntry) { | 1358 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveEntry) { |
1374 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1)); | 1359 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1)); |
1375 std::vector<AutofillEntry> original_entries; | 1360 std::vector<AutofillEntry> original_entries; |
1376 original_entries.push_back(original_entry); | 1361 original_entries.push_back(original_entry); |
1377 | 1362 |
1378 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) | 1363 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) |
1379 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); | 1364 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); |
1380 EXPECT_CALL(personal_data_manager(), Refresh()); | 1365 EXPECT_CALL(personal_data_manager(), Refresh()); |
1381 CreateRootHelper create_root(this, AUTOFILL); | 1366 CreateRootHelper create_root(this, AUTOFILL); |
1382 StartSyncService(create_root.callback(), false, AUTOFILL); | 1367 StartSyncService(create_root.callback(), false, AUTOFILL); |
1383 ASSERT_TRUE(create_root.success()); | 1368 ASSERT_TRUE(create_root.success()); |
1384 | 1369 |
1385 AutofillChangeList changes; | 1370 AutofillChangeList changes; |
1386 changes.push_back(AutofillChange(AutofillChange::REMOVE, | 1371 changes.push_back( |
1387 original_entry.key())); | 1372 AutofillChange(AutofillChange::REMOVE, original_entry.key())); |
1388 web_data_service()->OnAutofillEntriesChanged(changes); | 1373 web_data_service()->OnAutofillEntriesChanged(changes); |
1389 | 1374 |
1390 std::vector<AutofillEntry> new_sync_entries; | 1375 std::vector<AutofillEntry> new_sync_entries; |
1391 std::vector<AutofillProfile> new_sync_profiles; | 1376 std::vector<AutofillProfile> new_sync_profiles; |
1392 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, | 1377 ASSERT_TRUE( |
1393 &new_sync_profiles)); | 1378 GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); |
1394 ASSERT_EQ(0U, new_sync_entries.size()); | 1379 ASSERT_EQ(0U, new_sync_entries.size()); |
1395 } | 1380 } |
1396 | 1381 |
1397 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveProfile) { | 1382 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveProfile) { |
1398 AutofillProfile sync_profile; | 1383 AutofillProfile sync_profile; |
1399 autofill::test::SetProfileInfoWithGuid(&sync_profile, | 1384 autofill::test::SetProfileInfoWithGuid( |
1400 "3BA5FA1B-1EC4-4BB3-9B57-EC92BE3C1A09", "Josephine", "Alicia", "Saenz", | 1385 &sync_profile, "3BA5FA1B-1EC4-4BB3-9B57-EC92BE3C1A09", "Josephine", |
1401 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", | 1386 "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", |
1402 "32801", "US", "19482937549"); | 1387 "Orlando", "FL", "32801", "US", "19482937549"); |
1403 AutofillProfile* native_profile = new AutofillProfile; | 1388 AutofillProfile* native_profile = new AutofillProfile; |
1404 autofill::test::SetProfileInfoWithGuid(native_profile, | 1389 autofill::test::SetProfileInfoWithGuid( |
1405 "3BA5FA1B-1EC4-4BB3-9B57-EC92BE3C1A09", "Josephine", "Alicia", "Saenz", | 1390 native_profile, "3BA5FA1B-1EC4-4BB3-9B57-EC92BE3C1A09", "Josephine", |
1406 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", | 1391 "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", |
1407 "32801", "US", "19482937549"); | 1392 "Orlando", "FL", "32801", "US", "19482937549"); |
1408 | 1393 |
1409 std::vector<AutofillProfile*> native_profiles; | 1394 std::vector<AutofillProfile*> native_profiles; |
1410 native_profiles.push_back(native_profile); | 1395 native_profiles.push_back(native_profile); |
1411 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) | 1396 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
1412 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); | 1397 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
1413 | 1398 |
1414 std::vector<AutofillProfile> sync_profiles; | 1399 std::vector<AutofillProfile> sync_profiles; |
1415 sync_profiles.push_back(sync_profile); | 1400 sync_profiles.push_back(sync_profile); |
1416 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); | 1401 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
1417 EXPECT_CALL(personal_data_manager(), Refresh()); | 1402 EXPECT_CALL(personal_data_manager(), Refresh()); |
1418 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); | 1403 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); |
1419 ASSERT_TRUE(add_autofill.success()); | 1404 ASSERT_TRUE(add_autofill.success()); |
1420 | 1405 |
1421 AutofillProfileChange change( | 1406 AutofillProfileChange change(AutofillProfileChange::REMOVE, |
1422 AutofillProfileChange::REMOVE, sync_profile.guid(), NULL); | 1407 sync_profile.guid(), NULL); |
1423 web_data_service()->OnAutofillProfileChanged(change); | 1408 web_data_service()->OnAutofillProfileChanged(change); |
1424 | 1409 |
1425 std::vector<AutofillProfile> new_sync_profiles; | 1410 std::vector<AutofillProfile> new_sync_profiles; |
1426 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( | 1411 ASSERT_TRUE( |
1427 &new_sync_profiles)); | 1412 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); |
1428 ASSERT_EQ(0U, new_sync_profiles.size()); | 1413 ASSERT_EQ(0U, new_sync_profiles.size()); |
1429 } | 1414 } |
1430 | 1415 |
1431 TEST_F(ProfileSyncServiceAutofillTest, ServerChangeRace) { | 1416 TEST_F(ProfileSyncServiceAutofillTest, ServerChangeRace) { |
1432 // Once for MergeDataAndStartSyncing() and twice for ProcessSyncChanges(), via | 1417 // Once for MergeDataAndStartSyncing() and twice for ProcessSyncChanges(), via |
1433 // LoadAutofillData(). | 1418 // LoadAutofillData(). |
1434 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) | 1419 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) |
1435 .Times(3) | 1420 .Times(3) |
1436 .WillRepeatedly(Return(true)); | 1421 .WillRepeatedly(Return(true)); |
1437 // On the other hand Autofill and Autocomplete are separated now, so | 1422 // On the other hand Autofill and Autocomplete are separated now, so |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 | 1459 |
1475 // Let callbacks posted on UI thread execute. | 1460 // Let callbacks posted on UI thread execute. |
1476 base::RunLoop().RunUntilIdle(); | 1461 base::RunLoop().RunUntilIdle(); |
1477 | 1462 |
1478 std::vector<AutofillEntry> sync_entries; | 1463 std::vector<AutofillEntry> sync_entries; |
1479 std::vector<AutofillProfile> sync_profiles; | 1464 std::vector<AutofillProfile> sync_profiles; |
1480 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1465 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
1481 EXPECT_EQ(3U, sync_entries.size()); | 1466 EXPECT_EQ(3U, sync_entries.size()); |
1482 EXPECT_EQ(0U, sync_profiles.size()); | 1467 EXPECT_EQ(0U, sync_profiles.size()); |
1483 for (size_t i = 0; i < sync_entries.size(); i++) { | 1468 for (size_t i = 0; i < sync_entries.size(); i++) { |
1484 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1469 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() << ", " |
1485 << ", " << sync_entries[i].key().value(); | 1470 << sync_entries[i].key().value(); |
1486 } | 1471 } |
1487 } | 1472 } |
OLD | NEW |