OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <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 |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 | 445 |
446 sync_api::WriteNode node(&trans); | 446 sync_api::WriteNode node(&trans); |
447 std::string tag = AutocompleteSyncableService::KeyToTag( | 447 std::string tag = AutocompleteSyncableService::KeyToTag( |
448 UTF16ToUTF8(entry.key().name()), UTF16ToUTF8(entry.key().value())); | 448 UTF16ToUTF8(entry.key().name()), UTF16ToUTF8(entry.key().value())); |
449 if (!node.InitUniqueByCreation(syncable::AUTOFILL, autofill_root, tag)) | 449 if (!node.InitUniqueByCreation(syncable::AUTOFILL, autofill_root, tag)) |
450 return false; | 450 return false; |
451 | 451 |
452 sync_pb::EntitySpecifics specifics; | 452 sync_pb::EntitySpecifics specifics; |
453 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics); | 453 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics); |
454 sync_pb::AutofillSpecifics* autofill_specifics = | 454 sync_pb::AutofillSpecifics* autofill_specifics = |
455 specifics.MutableExtension(sync_pb::autofill); | 455 specifics.mutable_autofill(); |
456 node.SetAutofillSpecifics(*autofill_specifics); | 456 node.SetAutofillSpecifics(*autofill_specifics); |
457 return true; | 457 return true; |
458 } | 458 } |
459 | 459 |
460 bool AddAutofillSyncNode(const AutofillProfile& profile) { | 460 bool AddAutofillSyncNode(const AutofillProfile& profile) { |
461 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); | 461 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); |
462 sync_api::ReadNode autofill_root(&trans); | 462 sync_api::ReadNode autofill_root(&trans); |
463 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) | 463 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) |
464 return false; | 464 return false; |
465 sync_api::WriteNode node(&trans); | 465 sync_api::WriteNode node(&trans); |
466 std::string tag = profile.guid(); | 466 std::string tag = profile.guid(); |
467 if (!node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE, | 467 if (!node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE, |
468 autofill_root, tag)) | 468 autofill_root, tag)) |
469 return false; | 469 return false; |
470 sync_pb::EntitySpecifics specifics; | 470 sync_pb::EntitySpecifics specifics; |
471 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics); | 471 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics); |
472 sync_pb::AutofillProfileSpecifics* profile_specifics = | 472 sync_pb::AutofillProfileSpecifics* profile_specifics = |
473 specifics.MutableExtension(sync_pb::autofill_profile); | 473 specifics.mutable_autofill_profile(); |
474 node.SetAutofillProfileSpecifics(*profile_specifics); | 474 node.SetAutofillProfileSpecifics(*profile_specifics); |
475 return true; | 475 return true; |
476 } | 476 } |
477 | 477 |
478 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries, | 478 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries, |
479 std::vector<AutofillProfile>* profiles) { | 479 std::vector<AutofillProfile>* profiles) { |
480 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); | 480 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); |
481 sync_api::ReadNode autofill_root(&trans); | 481 sync_api::ReadNode autofill_root(&trans); |
482 if (!autofill_root.InitByTagLookup( | 482 if (!autofill_root.InitByTagLookup( |
483 syncable::ModelTypeToRootTag(syncable::AUTOFILL))) | 483 syncable::ModelTypeToRootTag(syncable::AUTOFILL))) |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 sync_pb::AutofillSpecifics new_autofill; | 656 sync_pb::AutofillSpecifics new_autofill; |
657 new_autofill.set_name(UTF16ToUTF8(entry_.key().name())); | 657 new_autofill.set_name(UTF16ToUTF8(entry_.key().name())); |
658 new_autofill.set_value(UTF16ToUTF8(entry_.key().value())); | 658 new_autofill.set_value(UTF16ToUTF8(entry_.key().value())); |
659 const std::vector<base::Time>& ts(entry_.timestamps()); | 659 const std::vector<base::Time>& ts(entry_.timestamps()); |
660 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); | 660 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); |
661 timestamp != ts.end(); ++timestamp) { | 661 timestamp != ts.end(); ++timestamp) { |
662 new_autofill.add_usage_timestamp(timestamp->ToInternalValue()); | 662 new_autofill.add_usage_timestamp(timestamp->ToInternalValue()); |
663 } | 663 } |
664 | 664 |
665 sync_pb::EntitySpecifics entity_specifics; | 665 sync_pb::EntitySpecifics entity_specifics; |
666 entity_specifics.MutableExtension(sync_pb::autofill)-> | 666 entity_specifics.mutable_autofill()->CopyFrom(new_autofill); |
667 CopyFrom(new_autofill); | |
668 | 667 |
669 { | 668 { |
670 // Tell main thread we've started | 669 // Tell main thread we've started |
671 (*wait_for_start_)->Signal(); | 670 (*wait_for_start_)->Signal(); |
672 | 671 |
673 // Create write transaction. | 672 // Create write transaction. |
674 WriteTransactionTest trans(FROM_HERE, UNITTEST, dir, | 673 WriteTransactionTest trans(FROM_HERE, UNITTEST, dir, |
675 wait_for_syncapi_); | 674 wait_for_syncapi_); |
676 | 675 |
677 // Create actual entry based on autofill protobuf information. | 676 // Create actual entry based on autofill protobuf information. |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1232 std::vector<AutofillEntry> sync_entries; | 1231 std::vector<AutofillEntry> sync_entries; |
1233 std::vector<AutofillProfile> sync_profiles; | 1232 std::vector<AutofillProfile> sync_profiles; |
1234 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1233 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
1235 EXPECT_EQ(3U, sync_entries.size()); | 1234 EXPECT_EQ(3U, sync_entries.size()); |
1236 EXPECT_EQ(0U, sync_profiles.size()); | 1235 EXPECT_EQ(0U, sync_profiles.size()); |
1237 for (size_t i = 0; i < sync_entries.size(); i++) { | 1236 for (size_t i = 0; i < sync_entries.size(); i++) { |
1238 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1237 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
1239 << ", " << sync_entries[i].key().value(); | 1238 << ", " << sync_entries[i].key().value(); |
1240 } | 1239 } |
1241 } | 1240 } |
OLD | NEW |