| 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 "base/location.h" | 5 #include "base/location.h" |
| 6 #include "sync/engine/verify_updates_command.h" | 6 #include "sync/engine/verify_updates_command.h" |
| 7 #include "sync/protocol/bookmark_specifics.pb.h" | 7 #include "sync/protocol/bookmark_specifics.pb.h" |
| 8 #include "sync/sessions/session_state.h" | 8 #include "sync/sessions/session_state.h" |
| 9 #include "sync/sessions/sync_session.h" | 9 #include "sync/sessions/sync_session.h" |
| 10 #include "sync/syncable/mutable_entry.h" | 10 #include "sync/syncable/mutable_entry.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 using syncable::UNITTEST; | 22 using syncable::UNITTEST; |
| 23 using syncable::WriteTransaction; | 23 using syncable::WriteTransaction; |
| 24 | 24 |
| 25 class VerifyUpdatesCommandTest : public SyncerCommandTest { | 25 class VerifyUpdatesCommandTest : public SyncerCommandTest { |
| 26 public: | 26 public: |
| 27 virtual void SetUp() { | 27 virtual void SetUp() { |
| 28 workers()->clear(); | 28 workers()->clear(); |
| 29 mutable_routing_info()->clear(); | 29 mutable_routing_info()->clear(); |
| 30 workers()->push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); | 30 workers()->push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); |
| 31 workers()->push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | 31 workers()->push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
| 32 (*mutable_routing_info())[syncer::PREFERENCES] = GROUP_UI; | 32 (*mutable_routing_info())[PREFERENCES] = GROUP_UI; |
| 33 (*mutable_routing_info())[syncer::BOOKMARKS] = GROUP_UI; | 33 (*mutable_routing_info())[BOOKMARKS] = GROUP_UI; |
| 34 (*mutable_routing_info())[syncer::AUTOFILL] = GROUP_DB; | 34 (*mutable_routing_info())[AUTOFILL] = GROUP_DB; |
| 35 SyncerCommandTest::SetUp(); | 35 SyncerCommandTest::SetUp(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void CreateLocalItem(const std::string& item_id, | 38 void CreateLocalItem(const std::string& item_id, |
| 39 const std::string& parent_id, | 39 const std::string& parent_id, |
| 40 const syncer::ModelType& type) { | 40 const ModelType& type) { |
| 41 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 41 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
| 42 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | 42 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
| 43 Id::CreateFromServerId(item_id)); | 43 Id::CreateFromServerId(item_id)); |
| 44 ASSERT_TRUE(entry.good()); | 44 ASSERT_TRUE(entry.good()); |
| 45 | 45 |
| 46 entry.Put(syncable::BASE_VERSION, 1); | 46 entry.Put(syncable::BASE_VERSION, 1); |
| 47 entry.Put(syncable::SERVER_VERSION, 1); | 47 entry.Put(syncable::SERVER_VERSION, 1); |
| 48 entry.Put(syncable::NON_UNIQUE_NAME, item_id); | 48 entry.Put(syncable::NON_UNIQUE_NAME, item_id); |
| 49 entry.Put(syncable::PARENT_ID, Id::CreateFromServerId(parent_id)); | 49 entry.Put(syncable::PARENT_ID, Id::CreateFromServerId(parent_id)); |
| 50 sync_pb::EntitySpecifics default_specifics; | 50 sync_pb::EntitySpecifics default_specifics; |
| 51 AddDefaultFieldValue(type, &default_specifics); | 51 AddDefaultFieldValue(type, &default_specifics); |
| 52 entry.Put(syncable::SERVER_SPECIFICS, default_specifics); | 52 entry.Put(syncable::SERVER_SPECIFICS, default_specifics); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void AddUpdate(sync_pb::GetUpdatesResponse* updates, | 55 void AddUpdate(sync_pb::GetUpdatesResponse* updates, |
| 56 const std::string& id, const std::string& parent, | 56 const std::string& id, const std::string& parent, |
| 57 const syncer::ModelType& type) { | 57 const ModelType& type) { |
| 58 sync_pb::SyncEntity* e = updates->add_entries(); | 58 sync_pb::SyncEntity* e = updates->add_entries(); |
| 59 e->set_id_string("b1"); | 59 e->set_id_string("b1"); |
| 60 e->set_parent_id_string(parent); | 60 e->set_parent_id_string(parent); |
| 61 e->set_non_unique_name("b1"); | 61 e->set_non_unique_name("b1"); |
| 62 e->set_name("b1"); | 62 e->set_name("b1"); |
| 63 AddDefaultFieldValue(type, e->mutable_specifics()); | 63 AddDefaultFieldValue(type, e->mutable_specifics()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 VerifyUpdatesCommand command_; | 66 VerifyUpdatesCommand command_; |
| 67 | 67 |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 TEST_F(VerifyUpdatesCommandTest, AllVerified) { | 70 TEST_F(VerifyUpdatesCommandTest, AllVerified) { |
| 71 string root = syncable::GetNullId().GetServerId(); | 71 string root = syncable::GetNullId().GetServerId(); |
| 72 | 72 |
| 73 CreateLocalItem("b1", root, syncer::BOOKMARKS); | 73 CreateLocalItem("b1", root, BOOKMARKS); |
| 74 CreateLocalItem("b2", root, syncer::BOOKMARKS); | 74 CreateLocalItem("b2", root, BOOKMARKS); |
| 75 CreateLocalItem("p1", root, syncer::PREFERENCES); | 75 CreateLocalItem("p1", root, PREFERENCES); |
| 76 CreateLocalItem("a1", root, syncer::AUTOFILL); | 76 CreateLocalItem("a1", root, AUTOFILL); |
| 77 | 77 |
| 78 ExpectNoGroupsToChange(command_); | 78 ExpectNoGroupsToChange(command_); |
| 79 | 79 |
| 80 sync_pb::GetUpdatesResponse* updates = | 80 sync_pb::GetUpdatesResponse* updates = |
| 81 session()->mutable_status_controller()-> | 81 session()->mutable_status_controller()-> |
| 82 mutable_updates_response()->mutable_get_updates(); | 82 mutable_updates_response()->mutable_get_updates(); |
| 83 AddUpdate(updates, "b1", root, syncer::BOOKMARKS); | 83 AddUpdate(updates, "b1", root, BOOKMARKS); |
| 84 AddUpdate(updates, "b2", root, syncer::BOOKMARKS); | 84 AddUpdate(updates, "b2", root, BOOKMARKS); |
| 85 AddUpdate(updates, "p1", root, syncer::PREFERENCES); | 85 AddUpdate(updates, "p1", root, PREFERENCES); |
| 86 AddUpdate(updates, "a1", root, syncer::AUTOFILL); | 86 AddUpdate(updates, "a1", root, AUTOFILL); |
| 87 | 87 |
| 88 ExpectGroupsToChange(command_, GROUP_UI, GROUP_DB); | 88 ExpectGroupsToChange(command_, GROUP_UI, GROUP_DB); |
| 89 | 89 |
| 90 command_.ExecuteImpl(session()); | 90 command_.ExecuteImpl(session()); |
| 91 | 91 |
| 92 StatusController* status = session()->mutable_status_controller(); | 92 StatusController* status = session()->mutable_status_controller(); |
| 93 { | 93 { |
| 94 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); | 94 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); |
| 95 ASSERT_TRUE(status->update_progress()); | 95 ASSERT_TRUE(status->update_progress()); |
| 96 EXPECT_EQ(3, status->update_progress()->VerifiedUpdatesSize()); | 96 EXPECT_EQ(3, status->update_progress()->VerifiedUpdatesSize()); |
| 97 } | 97 } |
| 98 { | 98 { |
| 99 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_DB); | 99 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_DB); |
| 100 ASSERT_TRUE(status->update_progress()); | 100 ASSERT_TRUE(status->update_progress()); |
| 101 EXPECT_EQ(1, status->update_progress()->VerifiedUpdatesSize()); | 101 EXPECT_EQ(1, status->update_progress()->VerifiedUpdatesSize()); |
| 102 } | 102 } |
| 103 { | 103 { |
| 104 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 104 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); |
| 105 EXPECT_FALSE(status->update_progress()); | 105 EXPECT_FALSE(status->update_progress()); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 } // namespace syncer | 109 } // namespace syncer |
| OLD | NEW |