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