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

Side by Side Diff: sync/engine/process_updates_command_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698