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