Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: chrome/browser/sync/profile_sync_service_autofill_unittest.cc

Issue 10152003: sync: Make BaseNode lookup-related Init functions return specific failures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 using syncable::CREATE; 75 using syncable::CREATE;
76 using syncable::GET_BY_SERVER_TAG; 76 using syncable::GET_BY_SERVER_TAG;
77 using syncable::INVALID; 77 using syncable::INVALID;
78 using syncable::MutableEntry; 78 using syncable::MutableEntry;
79 using syncable::SERVER_PARENT_ID; 79 using syncable::SERVER_PARENT_ID;
80 using syncable::SERVER_SPECIFICS; 80 using syncable::SERVER_SPECIFICS;
81 using syncable::SPECIFICS; 81 using syncable::SPECIFICS;
82 using syncable::UNITTEST; 82 using syncable::UNITTEST;
83 using syncable::WriterTag; 83 using syncable::WriterTag;
84 using syncable::WriteTransaction; 84 using syncable::WriteTransaction;
85 using sync_api::BaseNode;
85 using testing::_; 86 using testing::_;
86 using testing::DoAll; 87 using testing::DoAll;
87 using testing::DoDefault; 88 using testing::DoDefault;
88 using testing::ElementsAre; 89 using testing::ElementsAre;
89 using testing::Eq; 90 using testing::Eq;
90 using testing::Invoke; 91 using testing::Invoke;
91 using testing::Mock; 92 using testing::Mock;
92 using testing::Return; 93 using testing::Return;
93 using testing::SaveArg; 94 using testing::SaveArg;
94 using testing::SetArgumentPointee; 95 using testing::SetArgumentPointee;
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 token_service_->IssueAuthTokenForTest(GaiaConstants::kSyncService, "token"); 430 token_service_->IssueAuthTokenForTest(GaiaConstants::kSyncService, "token");
430 431
431 service_->RegisterDataTypeController(data_type_controller); 432 service_->RegisterDataTypeController(data_type_controller);
432 service_->Initialize(); 433 service_->Initialize();
433 MessageLoop::current()->Run(); 434 MessageLoop::current()->Run();
434 } 435 }
435 436
436 bool AddAutofillSyncNode(const AutofillEntry& entry) { 437 bool AddAutofillSyncNode(const AutofillEntry& entry) {
437 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); 438 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare());
438 sync_api::ReadNode autofill_root(&trans); 439 sync_api::ReadNode autofill_root(&trans);
439 if (!autofill_root.InitByTagLookup( 440 if (autofill_root.InitByTagLookup(
440 syncable::ModelTypeToRootTag(syncable::AUTOFILL))) 441 syncable::ModelTypeToRootTag(syncable::AUTOFILL)) !=
442 BaseNode::INIT_OK) {
441 return false; 443 return false;
444 }
442 445
443 sync_api::WriteNode node(&trans); 446 sync_api::WriteNode node(&trans);
444 std::string tag = AutocompleteSyncableService::KeyToTag( 447 std::string tag = AutocompleteSyncableService::KeyToTag(
445 UTF16ToUTF8(entry.key().name()), UTF16ToUTF8(entry.key().value())); 448 UTF16ToUTF8(entry.key().name()), UTF16ToUTF8(entry.key().value()));
446 if (!node.InitUniqueByCreation(syncable::AUTOFILL, autofill_root, tag)) 449 if (!node.InitUniqueByCreation(syncable::AUTOFILL, autofill_root, tag))
447 return false; 450 return false;
448 451
449 sync_pb::EntitySpecifics specifics; 452 sync_pb::EntitySpecifics specifics;
450 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics); 453 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics);
451 sync_pb::AutofillSpecifics* autofill_specifics = 454 sync_pb::AutofillSpecifics* autofill_specifics =
452 specifics.mutable_autofill(); 455 specifics.mutable_autofill();
453 node.SetAutofillSpecifics(*autofill_specifics); 456 node.SetAutofillSpecifics(*autofill_specifics);
454 return true; 457 return true;
455 } 458 }
456 459
457 bool AddAutofillSyncNode(const AutofillProfile& profile) { 460 bool AddAutofillSyncNode(const AutofillProfile& profile) {
458 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); 461 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare());
459 sync_api::ReadNode autofill_root(&trans); 462 sync_api::ReadNode autofill_root(&trans);
460 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) 463 if (autofill_root.InitByTagLookup(kAutofillProfileTag) !=
464 BaseNode::INIT_OK) {
461 return false; 465 return false;
466 }
462 sync_api::WriteNode node(&trans); 467 sync_api::WriteNode node(&trans);
463 std::string tag = profile.guid(); 468 std::string tag = profile.guid();
464 if (!node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE, 469 if (!node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE,
465 autofill_root, tag)) 470 autofill_root, tag))
466 return false; 471 return false;
467 sync_pb::EntitySpecifics specifics; 472 sync_pb::EntitySpecifics specifics;
468 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics); 473 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics);
469 sync_pb::AutofillProfileSpecifics* profile_specifics = 474 sync_pb::AutofillProfileSpecifics* profile_specifics =
470 specifics.mutable_autofill_profile(); 475 specifics.mutable_autofill_profile();
471 node.SetAutofillProfileSpecifics(*profile_specifics); 476 node.SetAutofillProfileSpecifics(*profile_specifics);
472 return true; 477 return true;
473 } 478 }
474 479
475 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries, 480 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries,
476 std::vector<AutofillProfile>* profiles) { 481 std::vector<AutofillProfile>* profiles) {
477 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); 482 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare());
478 sync_api::ReadNode autofill_root(&trans); 483 sync_api::ReadNode autofill_root(&trans);
479 if (!autofill_root.InitByTagLookup( 484 if (autofill_root.InitByTagLookup(
480 syncable::ModelTypeToRootTag(syncable::AUTOFILL))) 485 syncable::ModelTypeToRootTag(syncable::AUTOFILL)) !=
486 BaseNode::INIT_OK) {
481 return false; 487 return false;
488 }
482 489
483 int64 child_id = autofill_root.GetFirstChildId(); 490 int64 child_id = autofill_root.GetFirstChildId();
484 while (child_id != sync_api::kInvalidId) { 491 while (child_id != sync_api::kInvalidId) {
485 sync_api::ReadNode child_node(&trans); 492 sync_api::ReadNode child_node(&trans);
486 if (!child_node.InitByIdLookup(child_id)) 493 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK)
487 return false; 494 return false;
488 495
489 const sync_pb::AutofillSpecifics& autofill( 496 const sync_pb::AutofillSpecifics& autofill(
490 child_node.GetAutofillSpecifics()); 497 child_node.GetAutofillSpecifics());
491 if (autofill.has_value()) { 498 if (autofill.has_value()) {
492 AutofillKey key(UTF8ToUTF16(autofill.name()), 499 AutofillKey key(UTF8ToUTF16(autofill.name()),
493 UTF8ToUTF16(autofill.value())); 500 UTF8ToUTF16(autofill.value()));
494 std::vector<base::Time> timestamps; 501 std::vector<base::Time> timestamps;
495 int timestamps_count = autofill.usage_timestamp_size(); 502 int timestamps_count = autofill.usage_timestamp_size();
496 for (int i = 0; i < timestamps_count; ++i) { 503 for (int i = 0; i < timestamps_count; ++i) {
(...skipping 10 matching lines...) Expand all
507 } 514 }
508 child_id = child_node.GetSuccessorId(); 515 child_id = child_node.GetSuccessorId();
509 } 516 }
510 return true; 517 return true;
511 } 518 }
512 519
513 bool GetAutofillProfilesFromSyncDBUnderProfileNode( 520 bool GetAutofillProfilesFromSyncDBUnderProfileNode(
514 std::vector<AutofillProfile>* profiles) { 521 std::vector<AutofillProfile>* profiles) {
515 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); 522 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare());
516 sync_api::ReadNode autofill_root(&trans); 523 sync_api::ReadNode autofill_root(&trans);
517 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) 524 if (autofill_root.InitByTagLookup(kAutofillProfileTag) !=
525 BaseNode::INIT_OK) {
518 return false; 526 return false;
527 }
519 528
520 int64 child_id = autofill_root.GetFirstChildId(); 529 int64 child_id = autofill_root.GetFirstChildId();
521 while (child_id != sync_api::kInvalidId) { 530 while (child_id != sync_api::kInvalidId) {
522 sync_api::ReadNode child_node(&trans); 531 sync_api::ReadNode child_node(&trans);
523 if (!child_node.InitByIdLookup(child_id)) 532 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK)
524 return false; 533 return false;
525 534
526 const sync_pb::AutofillProfileSpecifics& autofill( 535 const sync_pb::AutofillProfileSpecifics& autofill(
527 child_node.GetAutofillProfileSpecifics()); 536 child_node.GetAutofillProfileSpecifics());
528 AutofillProfile p; 537 AutofillProfile p;
529 p.set_guid(autofill.guid()); 538 p.set_guid(autofill.guid());
530 AutofillProfileSyncableService::OverwriteProfileWithServerData( 539 AutofillProfileSyncableService::OverwriteProfileWithServerData(
531 autofill, &p); 540 autofill, &p);
532 profiles->push_back(p); 541 profiles->push_back(p);
533 child_id = child_node.GetSuccessorId(); 542 child_id = child_node.GetSuccessorId();
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 std::vector<AutofillEntry> sync_entries; 1239 std::vector<AutofillEntry> sync_entries;
1231 std::vector<AutofillProfile> sync_profiles; 1240 std::vector<AutofillProfile> sync_profiles;
1232 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1241 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1233 EXPECT_EQ(3U, sync_entries.size()); 1242 EXPECT_EQ(3U, sync_entries.size());
1234 EXPECT_EQ(0U, sync_profiles.size()); 1243 EXPECT_EQ(0U, sync_profiles.size());
1235 for (size_t i = 0; i < sync_entries.size(); i++) { 1244 for (size_t i = 0; i < sync_entries.size(); i++) {
1236 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1245 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1237 << ", " << sync_entries[i].key().value(); 1246 << ", " << sync_entries[i].key().value();
1238 } 1247 }
1239 } 1248 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/internal_api/write_node.cc ('k') | chrome/browser/sync/profile_sync_service_bookmark_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698