| 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/memory/ref_counted.h" | |
| 7 #include "sync/engine/process_updates_command.h" | 6 #include "sync/engine/process_updates_command.h" |
| 8 #include "sync/internal_api/public/base/model_type.h" | 7 #include "sync/internal_api/public/base/model_type.h" |
| 9 #include "sync/sessions/session_state.h" | |
| 10 #include "sync/sessions/sync_session.h" | 8 #include "sync/sessions/sync_session.h" |
| 9 #include "sync/syncable/mutable_entry.h" |
| 11 #include "sync/syncable/syncable_id.h" | 10 #include "sync/syncable/syncable_id.h" |
| 12 #include "sync/test/engine/fake_model_worker.h" | 11 #include "sync/test/engine/fake_model_worker.h" |
| 13 #include "sync/test/engine/syncer_command_test.h" | 12 #include "sync/test/engine/syncer_command_test.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 14 |
| 16 namespace syncer { | 15 namespace syncer { |
| 17 | 16 |
| 17 using syncable::Id; |
| 18 using syncable::MutableEntry; |
| 19 using syncable::UNITTEST; |
| 20 using syncable::WriteTransaction; |
| 21 |
| 18 namespace { | 22 namespace { |
| 19 | 23 |
| 20 class ProcessUpdatesCommandTest : public SyncerCommandTest { | 24 class ProcessUpdatesCommandTest : public SyncerCommandTest { |
| 21 protected: | 25 protected: |
| 22 ProcessUpdatesCommandTest() {} | 26 ProcessUpdatesCommandTest() {} |
| 23 virtual ~ProcessUpdatesCommandTest() {} | 27 virtual ~ProcessUpdatesCommandTest() {} |
| 24 | 28 |
| 25 virtual void SetUp() { | 29 virtual void SetUp() { |
| 26 workers()->push_back( | 30 workers()->push_back( |
| 27 make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | 31 make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
| 28 workers()->push_back( | 32 workers()->push_back( |
| 29 make_scoped_refptr(new FakeModelWorker(GROUP_DB))); | 33 make_scoped_refptr(new FakeModelWorker(GROUP_DB))); |
| 34 (*mutable_routing_info())[PREFERENCES] = GROUP_UI; |
| 30 (*mutable_routing_info())[BOOKMARKS] = GROUP_UI; | 35 (*mutable_routing_info())[BOOKMARKS] = GROUP_UI; |
| 31 (*mutable_routing_info())[AUTOFILL] = GROUP_DB; | 36 (*mutable_routing_info())[AUTOFILL] = GROUP_DB; |
| 32 SyncerCommandTest::SetUp(); | 37 SyncerCommandTest::SetUp(); |
| 33 } | 38 } |
| 34 | 39 |
| 40 void CreateLocalItem(const std::string& item_id, |
| 41 const std::string& parent_id, |
| 42 const ModelType& type) { |
| 43 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
| 44 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
| 45 Id::CreateFromServerId(item_id)); |
| 46 ASSERT_TRUE(entry.good()); |
| 47 |
| 48 entry.Put(syncable::BASE_VERSION, 1); |
| 49 entry.Put(syncable::SERVER_VERSION, 1); |
| 50 entry.Put(syncable::NON_UNIQUE_NAME, item_id); |
| 51 entry.Put(syncable::PARENT_ID, Id::CreateFromServerId(parent_id)); |
| 52 sync_pb::EntitySpecifics default_specifics; |
| 53 AddDefaultFieldValue(type, &default_specifics); |
| 54 entry.Put(syncable::SERVER_SPECIFICS, default_specifics); |
| 55 } |
| 56 |
| 57 void AddUpdate(sync_pb::GetUpdatesResponse* updates, |
| 58 const std::string& id, const std::string& parent, |
| 59 const ModelType& type) { |
| 60 sync_pb::SyncEntity* e = updates->add_entries(); |
| 61 e->set_id_string("b1"); |
| 62 e->set_parent_id_string(parent); |
| 63 e->set_non_unique_name("b1"); |
| 64 e->set_name("b1"); |
| 65 AddDefaultFieldValue(type, e->mutable_specifics()); |
| 66 } |
| 67 |
| 35 ProcessUpdatesCommand command_; | 68 ProcessUpdatesCommand command_; |
| 36 | 69 |
| 37 private: | 70 private: |
| 38 DISALLOW_COPY_AND_ASSIGN(ProcessUpdatesCommandTest); | 71 DISALLOW_COPY_AND_ASSIGN(ProcessUpdatesCommandTest); |
| 39 }; | 72 }; |
| 40 | 73 |
| 41 TEST_F(ProcessUpdatesCommandTest, GetGroupsToChange) { | 74 TEST_F(ProcessUpdatesCommandTest, GroupsToChange) { |
| 75 std::string root = syncable::GetNullId().GetServerId(); |
| 76 |
| 77 CreateLocalItem("b1", root, BOOKMARKS); |
| 78 CreateLocalItem("b2", root, BOOKMARKS); |
| 79 CreateLocalItem("p1", root, PREFERENCES); |
| 80 CreateLocalItem("a1", root, AUTOFILL); |
| 81 |
| 42 ExpectNoGroupsToChange(command_); | 82 ExpectNoGroupsToChange(command_); |
| 43 // Add a verified update for GROUP_DB. | 83 |
| 44 session()->mutable_status_controller()-> | 84 sync_pb::GetUpdatesResponse* updates = |
| 45 GetUnrestrictedMutableUpdateProgressForTest(GROUP_DB)-> | 85 session()->mutable_status_controller()-> |
| 46 AddVerifyResult(VerifyResult(), sync_pb::SyncEntity()); | 86 mutable_updates_response()->mutable_get_updates(); |
| 47 ExpectGroupToChange(command_, GROUP_DB); | 87 AddUpdate(updates, "b1", root, BOOKMARKS); |
| 88 AddUpdate(updates, "b2", root, BOOKMARKS); |
| 89 AddUpdate(updates, "p1", root, PREFERENCES); |
| 90 AddUpdate(updates, "a1", root, AUTOFILL); |
| 91 |
| 92 ExpectGroupsToChange(command_, GROUP_UI, GROUP_DB); |
| 93 |
| 94 command_.ExecuteImpl(session()); |
| 48 } | 95 } |
| 49 | 96 |
| 50 } // namespace | 97 } // namespace |
| 51 | 98 |
| 52 } // namespace syncer | 99 } // namespace syncer |
| OLD | NEW |