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

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

Issue 161253002: sync: Add interfaces for per-type sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor fix Created 6 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "sync/engine/sync_directory_commit_contribution.h" 5 #include "sync/engine/directory_commit_contribution.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "sync/sessions/status_controller.h" 8 #include "sync/sessions/status_controller.h"
9 #include "sync/syncable/entry.h" 9 #include "sync/syncable/entry.h"
10 #include "sync/syncable/mutable_entry.h" 10 #include "sync/syncable/mutable_entry.h"
11 #include "sync/syncable/syncable_read_transaction.h" 11 #include "sync/syncable/syncable_read_transaction.h"
12 #include "sync/syncable/syncable_write_transaction.h" 12 #include "sync/syncable/syncable_write_transaction.h"
13 #include "sync/test/engine/test_directory_setter_upper.h" 13 #include "sync/test/engine/test_directory_setter_upper.h"
14 #include "sync/test/engine/test_id_factory.h" 14 #include "sync/test/engine/test_id_factory.h"
15 #include "sync/test/engine/test_syncable_utils.h" 15 #include "sync/test/engine/test_syncable_utils.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace syncer { 18 namespace syncer {
19 19
20 class SyncDirectoryCommitContributionTest : public ::testing::Test { 20 class DirectoryCommitContributionTest : public ::testing::Test {
21 public: 21 public:
22 virtual void SetUp() OVERRIDE { 22 virtual void SetUp() OVERRIDE {
23 dir_maker_.SetUp(); 23 dir_maker_.SetUp();
24 24
25 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); 25 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir());
26 CreateTypeRoot(&trans, dir(), PREFERENCES); 26 CreateTypeRoot(&trans, dir(), PREFERENCES);
27 CreateTypeRoot(&trans, dir(), EXTENSIONS); 27 CreateTypeRoot(&trans, dir(), EXTENSIONS);
28 } 28 }
29 29
30 virtual void TearDown() OVERRIDE { 30 virtual void TearDown() OVERRIDE {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return dir_maker_.directory(); 67 return dir_maker_.directory();
68 } 68 }
69 69
70 TestIdFactory id_factory_; 70 TestIdFactory id_factory_;
71 71
72 private: 72 private:
73 base::MessageLoop loop_; // Neeed to initialize the directory. 73 base::MessageLoop loop_; // Neeed to initialize the directory.
74 TestDirectorySetterUpper dir_maker_; 74 TestDirectorySetterUpper dir_maker_;
75 }; 75 };
76 76
77 // Verify that the SyncDirectoryCommitContribution contains only entries of its 77 // Verify that the DirectoryCommitContribution contains only entries of its
78 // specified type. 78 // specified type.
79 TEST_F(SyncDirectoryCommitContributionTest, GatherByTypes) { 79 TEST_F(DirectoryCommitContributionTest, GatherByTypes) {
80 int64 pref1; 80 int64 pref1;
81 { 81 {
82 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); 82 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir());
83 pref1 = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); 83 pref1 = CreateUnsyncedItem(&trans, PREFERENCES, "pref1");
84 CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); 84 CreateUnsyncedItem(&trans, PREFERENCES, "pref2");
85 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); 85 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1");
86 } 86 }
87 87
88 scoped_ptr<SyncDirectoryCommitContribution> cc( 88 scoped_ptr<DirectoryCommitContribution> cc(
89 SyncDirectoryCommitContribution::Build(dir(), PREFERENCES, 5)); 89 DirectoryCommitContribution::Build(dir(), PREFERENCES, 5));
90 ASSERT_EQ(2U, cc->GetNumEntries()); 90 ASSERT_EQ(2U, cc->GetNumEntries());
91 91
92 const std::vector<int64>& metahandles = cc->metahandles_; 92 const std::vector<int64>& metahandles = cc->metahandles_;
93 EXPECT_TRUE(std::find(metahandles.begin(), metahandles.end(), pref1) != 93 EXPECT_TRUE(std::find(metahandles.begin(), metahandles.end(), pref1) !=
94 metahandles.end()); 94 metahandles.end());
95 EXPECT_TRUE(std::find(metahandles.begin(), metahandles.end(), pref1) != 95 EXPECT_TRUE(std::find(metahandles.begin(), metahandles.end(), pref1) !=
96 metahandles.end()); 96 metahandles.end());
97 97
98 cc->CleanUp(); 98 cc->CleanUp();
99 } 99 }
100 100
101 // Verify that the SyncDirectoryCommitContributionTest builder function 101 // Verify that the DirectoryCommitContributionTest builder function
102 // truncates if necessary. 102 // truncates if necessary.
103 TEST_F(SyncDirectoryCommitContributionTest, GatherAndTruncate) { 103 TEST_F(DirectoryCommitContributionTest, GatherAndTruncate) {
104 int64 pref1; 104 int64 pref1;
105 int64 pref2; 105 int64 pref2;
106 { 106 {
107 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); 107 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir());
108 pref1 = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); 108 pref1 = CreateUnsyncedItem(&trans, PREFERENCES, "pref1");
109 pref2 = CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); 109 pref2 = CreateUnsyncedItem(&trans, PREFERENCES, "pref2");
110 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); 110 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1");
111 } 111 }
112 112
113 scoped_ptr<SyncDirectoryCommitContribution> cc( 113 scoped_ptr<DirectoryCommitContribution> cc(
114 SyncDirectoryCommitContribution::Build(dir(), PREFERENCES, 1)); 114 DirectoryCommitContribution::Build(dir(), PREFERENCES, 1));
115 ASSERT_EQ(1U, cc->GetNumEntries()); 115 ASSERT_EQ(1U, cc->GetNumEntries());
116 116
117 int64 only_metahandle = cc->metahandles_[0]; 117 int64 only_metahandle = cc->metahandles_[0];
118 EXPECT_TRUE(only_metahandle == pref1 || only_metahandle == pref2); 118 EXPECT_TRUE(only_metahandle == pref1 || only_metahandle == pref2);
119 119
120 cc->CleanUp(); 120 cc->CleanUp();
121 } 121 }
122 122
123 // Sanity check for building commits from SyncDirectoryCommitContributions. 123 // Sanity check for building commits from DirectoryCommitContributions.
124 // This test makes two CommitContribution objects of different types and uses 124 // This test makes two CommitContribution objects of different types and uses
125 // them to initialize a commit message. Then it checks that the contents of the 125 // them to initialize a commit message. Then it checks that the contents of the
126 // commit message match those of the directory they came from. 126 // commit message match those of the directory they came from.
127 TEST_F(SyncDirectoryCommitContributionTest, PrepareCommit) { 127 TEST_F(DirectoryCommitContributionTest, PrepareCommit) {
128 { 128 {
129 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); 129 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir());
130 CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); 130 CreateUnsyncedItem(&trans, PREFERENCES, "pref1");
131 CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); 131 CreateUnsyncedItem(&trans, PREFERENCES, "pref2");
132 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); 132 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1");
133 } 133 }
134 134
135 scoped_ptr<SyncDirectoryCommitContribution> pref_cc( 135 scoped_ptr<DirectoryCommitContribution> pref_cc(
136 SyncDirectoryCommitContribution::Build(dir(), PREFERENCES, 25)); 136 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25));
137 scoped_ptr<SyncDirectoryCommitContribution> ext_cc( 137 scoped_ptr<DirectoryCommitContribution> ext_cc(
138 SyncDirectoryCommitContribution::Build(dir(), EXTENSIONS, 25)); 138 DirectoryCommitContribution::Build(dir(), EXTENSIONS, 25));
139 139
140 sync_pb::ClientToServerMessage message; 140 sync_pb::ClientToServerMessage message;
141 pref_cc->AddToCommitMessage(&message); 141 pref_cc->AddToCommitMessage(&message);
142 ext_cc->AddToCommitMessage(&message); 142 ext_cc->AddToCommitMessage(&message);
143 143
144 const sync_pb::CommitMessage& commit_message = message.commit(); 144 const sync_pb::CommitMessage& commit_message = message.commit();
145 145
146 std::set<syncable::Id> ids_for_commit; 146 std::set<syncable::Id> ids_for_commit;
147 ASSERT_EQ(3, commit_message.entries_size()); 147 ASSERT_EQ(3, commit_message.entries_size());
148 for (int i = 0; i < commit_message.entries_size(); ++i) { 148 for (int i = 0; i < commit_message.entries_size(); ++i) {
(...skipping 17 matching lines...) Expand all
166 } 166 }
167 } 167 }
168 168
169 pref_cc->CleanUp(); 169 pref_cc->CleanUp();
170 ext_cc->CleanUp(); 170 ext_cc->CleanUp();
171 } 171 }
172 172
173 // Creates some unsynced items, pretends to commit them, and hands back a 173 // Creates some unsynced items, pretends to commit them, and hands back a
174 // specially crafted response to the syncer in order to test commit response 174 // specially crafted response to the syncer in order to test commit response
175 // processing. The response simulates a succesful commit scenario. 175 // processing. The response simulates a succesful commit scenario.
176 TEST_F(SyncDirectoryCommitContributionTest, ProcessCommitResponse) { 176 TEST_F(DirectoryCommitContributionTest, ProcessCommitResponse) {
177 int64 pref1_handle; 177 int64 pref1_handle;
178 int64 pref2_handle; 178 int64 pref2_handle;
179 int64 ext1_handle; 179 int64 ext1_handle;
180 { 180 {
181 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); 181 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir());
182 pref1_handle = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); 182 pref1_handle = CreateUnsyncedItem(&trans, PREFERENCES, "pref1");
183 pref2_handle = CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); 183 pref2_handle = CreateUnsyncedItem(&trans, PREFERENCES, "pref2");
184 ext1_handle = CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); 184 ext1_handle = CreateUnsyncedItem(&trans, EXTENSIONS, "extension1");
185 } 185 }
186 186
187 scoped_ptr<SyncDirectoryCommitContribution> pref_cc( 187 scoped_ptr<DirectoryCommitContribution> pref_cc(
188 SyncDirectoryCommitContribution::Build(dir(), PREFERENCES, 25)); 188 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25));
189 scoped_ptr<SyncDirectoryCommitContribution> ext_cc( 189 scoped_ptr<DirectoryCommitContribution> ext_cc(
190 SyncDirectoryCommitContribution::Build(dir(), EXTENSIONS, 25)); 190 DirectoryCommitContribution::Build(dir(), EXTENSIONS, 25));
191 191
192 sync_pb::ClientToServerMessage message; 192 sync_pb::ClientToServerMessage message;
193 pref_cc->AddToCommitMessage(&message); 193 pref_cc->AddToCommitMessage(&message);
194 ext_cc->AddToCommitMessage(&message); 194 ext_cc->AddToCommitMessage(&message);
195 195
196 const sync_pb::CommitMessage& commit_message = message.commit(); 196 const sync_pb::CommitMessage& commit_message = message.commit();
197 ASSERT_EQ(3, commit_message.entries_size()); 197 ASSERT_EQ(3, commit_message.entries_size());
198 198
199 sync_pb::ClientToServerResponse response; 199 sync_pb::ClientToServerResponse response;
200 for (int i = 0; i < commit_message.entries_size(); ++i) { 200 for (int i = 0; i < commit_message.entries_size(); ++i) {
(...skipping 25 matching lines...) Expand all
226 EXPECT_TRUE(e1.GetId().ServerKnows()); 226 EXPECT_TRUE(e1.GetId().ServerKnows());
227 EXPECT_FALSE(e1.GetSyncing()); 227 EXPECT_FALSE(e1.GetSyncing());
228 EXPECT_LT(0, e1.GetServerVersion()); 228 EXPECT_LT(0, e1.GetServerVersion());
229 } 229 }
230 230
231 pref_cc->CleanUp(); 231 pref_cc->CleanUp();
232 ext_cc->CleanUp(); 232 ext_cc->CleanUp();
233 } 233 }
234 234
235 } // namespace syncer 235 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698