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

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

Issue 260613002: sync: Expose DirectoryDebugInfoEmitters in engine (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update comment Created 6 years, 7 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
« no previous file with comments | « sync/engine/directory_update_handler.cc ('k') | sync/sessions/model_type_registry.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/directory_update_handler.h" 5 #include "sync/engine/directory_update_handler.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "sync/engine/syncer_proto_util.h" 10 #include "sync/engine/syncer_proto_util.h"
11 #include "sync/internal_api/public/base/model_type.h" 11 #include "sync/internal_api/public/base/model_type.h"
12 #include "sync/internal_api/public/test/test_entry_factory.h" 12 #include "sync/internal_api/public/test/test_entry_factory.h"
13 #include "sync/protocol/sync.pb.h" 13 #include "sync/protocol/sync.pb.h"
14 #include "sync/sessions/directory_type_debug_info_emitter.h"
14 #include "sync/sessions/status_controller.h" 15 #include "sync/sessions/status_controller.h"
15 #include "sync/syncable/directory.h" 16 #include "sync/syncable/directory.h"
16 #include "sync/syncable/entry.h" 17 #include "sync/syncable/entry.h"
17 #include "sync/syncable/mutable_entry.h" 18 #include "sync/syncable/mutable_entry.h"
18 #include "sync/syncable/syncable_model_neutral_write_transaction.h" 19 #include "sync/syncable/syncable_model_neutral_write_transaction.h"
19 #include "sync/syncable/syncable_proto_util.h" 20 #include "sync/syncable/syncable_proto_util.h"
20 #include "sync/syncable/syncable_read_transaction.h" 21 #include "sync/syncable/syncable_read_transaction.h"
21 #include "sync/syncable/syncable_write_transaction.h" 22 #include "sync/syncable/syncable_write_transaction.h"
22 #include "sync/test/engine/fake_model_worker.h" 23 #include "sync/test/engine/fake_model_worker.h"
23 #include "sync/test/engine/test_directory_setter_upper.h" 24 #include "sync/test/engine/test_directory_setter_upper.h"
(...skipping 24 matching lines...) Expand all
48 dir_maker_.SetUp(); 49 dir_maker_.SetUp();
49 } 50 }
50 51
51 virtual void TearDown() OVERRIDE { 52 virtual void TearDown() OVERRIDE {
52 dir_maker_.TearDown(); 53 dir_maker_.TearDown();
53 } 54 }
54 55
55 syncable::Directory* dir() { 56 syncable::Directory* dir() {
56 return dir_maker_.directory(); 57 return dir_maker_.directory();
57 } 58 }
59
58 protected: 60 protected:
59 scoped_ptr<sync_pb::SyncEntity> CreateUpdate( 61 scoped_ptr<sync_pb::SyncEntity> CreateUpdate(
60 const std::string& id, 62 const std::string& id,
61 const std::string& parent, 63 const std::string& parent,
62 const ModelType& type); 64 const ModelType& type);
63 65
64 // This exists mostly to give tests access to the protected member function. 66 // This exists mostly to give tests access to the protected member function.
65 // Warning: This takes the syncable directory lock. 67 // Warning: This takes the syncable directory lock.
66 void UpdateSyncEntities( 68 void UpdateSyncEntities(
67 DirectoryUpdateHandler* handler, 69 DirectoryUpdateHandler* handler,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 void DirectoryUpdateHandlerProcessUpdateTest::UpdateProgressMarkers( 118 void DirectoryUpdateHandlerProcessUpdateTest::UpdateProgressMarkers(
117 DirectoryUpdateHandler* handler, 119 DirectoryUpdateHandler* handler,
118 const sync_pb::DataTypeProgressMarker& progress) { 120 const sync_pb::DataTypeProgressMarker& progress) {
119 handler->UpdateProgressMarker(progress); 121 handler->UpdateProgressMarker(progress);
120 } 122 }
121 123
122 static const char kCacheGuid[] = "IrcjZ2jyzHDV9Io4+zKcXQ=="; 124 static const char kCacheGuid[] = "IrcjZ2jyzHDV9Io4+zKcXQ==";
123 125
124 // Test that the bookmark tag is set on newly downloaded items. 126 // Test that the bookmark tag is set on newly downloaded items.
125 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, NewBookmarkTag) { 127 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, NewBookmarkTag) {
126 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker()); 128 DirectoryTypeDebugInfoEmitter emitter;
129 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter);
127 sync_pb::GetUpdatesResponse gu_response; 130 sync_pb::GetUpdatesResponse gu_response;
128 sessions::StatusController status; 131 sessions::StatusController status;
129 132
130 // Add a bookmark item to the update message. 133 // Add a bookmark item to the update message.
131 std::string root = syncable::GetNullId().GetServerId(); 134 std::string root = syncable::GetNullId().GetServerId();
132 syncable::Id server_id = syncable::Id::CreateFromServerId("b1"); 135 syncable::Id server_id = syncable::Id::CreateFromServerId("b1");
133 scoped_ptr<sync_pb::SyncEntity> e = 136 scoped_ptr<sync_pb::SyncEntity> e =
134 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS); 137 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS);
135 e->set_originator_cache_guid( 138 e->set_originator_cache_guid(
136 std::string(kCacheGuid, arraysize(kCacheGuid)-1)); 139 std::string(kCacheGuid, arraysize(kCacheGuid)-1));
(...skipping 17 matching lines...) Expand all
154 // If this assertion fails, that might indicate that the algorithm used to 157 // If this assertion fails, that might indicate that the algorithm used to
155 // generate bookmark tags has been modified. This could have implications for 158 // generate bookmark tags has been modified. This could have implications for
156 // bookmark ordering. Please make sure you know what you're doing if you 159 // bookmark ordering. Please make sure you know what you're doing if you
157 // intend to make such a change. 160 // intend to make such a change.
158 EXPECT_EQ("6wHRAb3kbnXV5GHrejp4/c1y5tw=", entry.GetUniqueBookmarkTag()); 161 EXPECT_EQ("6wHRAb3kbnXV5GHrejp4/c1y5tw=", entry.GetUniqueBookmarkTag());
159 } 162 }
160 163
161 // Test the receipt of a type root node. 164 // Test the receipt of a type root node.
162 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, 165 TEST_F(DirectoryUpdateHandlerProcessUpdateTest,
163 ReceiveServerCreatedBookmarkFolders) { 166 ReceiveServerCreatedBookmarkFolders) {
164 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker()); 167 DirectoryTypeDebugInfoEmitter emitter;
168 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter);
165 sync_pb::GetUpdatesResponse gu_response; 169 sync_pb::GetUpdatesResponse gu_response;
166 sessions::StatusController status; 170 sessions::StatusController status;
167 171
168 // Create an update that mimics the bookmark root. 172 // Create an update that mimics the bookmark root.
169 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz"); 173 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz");
170 std::string root = syncable::GetNullId().GetServerId(); 174 std::string root = syncable::GetNullId().GetServerId();
171 scoped_ptr<sync_pb::SyncEntity> e = 175 scoped_ptr<sync_pb::SyncEntity> e =
172 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS); 176 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS);
173 e->set_server_defined_unique_tag("google_chrome_bookmarks"); 177 e->set_server_defined_unique_tag("google_chrome_bookmarks");
174 e->set_folder(true); 178 e->set_folder(true);
(...skipping 13 matching lines...) Expand all
188 ASSERT_TRUE(entry.good()); 192 ASSERT_TRUE(entry.good());
189 193
190 EXPECT_FALSE(entry.ShouldMaintainPosition()); 194 EXPECT_FALSE(entry.ShouldMaintainPosition());
191 EXPECT_FALSE(entry.GetUniquePosition().IsValid()); 195 EXPECT_FALSE(entry.GetUniquePosition().IsValid());
192 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid()); 196 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid());
193 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty()); 197 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty());
194 } 198 }
195 199
196 // Test the receipt of a non-bookmark item. 200 // Test the receipt of a non-bookmark item.
197 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ReceiveNonBookmarkItem) { 201 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ReceiveNonBookmarkItem) {
198 DirectoryUpdateHandler handler(dir(), AUTOFILL, ui_worker()); 202 DirectoryTypeDebugInfoEmitter emitter;
203 DirectoryUpdateHandler handler(dir(), AUTOFILL, ui_worker(), &emitter);
199 sync_pb::GetUpdatesResponse gu_response; 204 sync_pb::GetUpdatesResponse gu_response;
200 sessions::StatusController status; 205 sessions::StatusController status;
201 206
202 std::string root = syncable::GetNullId().GetServerId(); 207 std::string root = syncable::GetNullId().GetServerId();
203 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz"); 208 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz");
204 scoped_ptr<sync_pb::SyncEntity> e = 209 scoped_ptr<sync_pb::SyncEntity> e =
205 CreateUpdate(SyncableIdToProto(server_id), root, AUTOFILL); 210 CreateUpdate(SyncableIdToProto(server_id), root, AUTOFILL);
206 e->set_server_defined_unique_tag("9PGRuKdX5sHyGMB17CvYTXuC43I="); 211 e->set_server_defined_unique_tag("9PGRuKdX5sHyGMB17CvYTXuC43I=");
207 212
208 // Add it to the applicable updates list. 213 // Add it to the applicable updates list.
(...skipping 10 matching lines...) Expand all
219 ASSERT_TRUE(entry.good()); 224 ASSERT_TRUE(entry.good());
220 225
221 EXPECT_FALSE(entry.ShouldMaintainPosition()); 226 EXPECT_FALSE(entry.ShouldMaintainPosition());
222 EXPECT_FALSE(entry.GetUniquePosition().IsValid()); 227 EXPECT_FALSE(entry.GetUniquePosition().IsValid());
223 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid()); 228 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid());
224 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty()); 229 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty());
225 } 230 }
226 231
227 // Tests the setting of progress markers. 232 // Tests the setting of progress markers.
228 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ProcessNewProgressMarkers) { 233 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ProcessNewProgressMarkers) {
229 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker()); 234 DirectoryTypeDebugInfoEmitter emitter;
235 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter);
230 236
231 sync_pb::DataTypeProgressMarker progress; 237 sync_pb::DataTypeProgressMarker progress;
232 progress.set_data_type_id(GetSpecificsFieldNumberFromModelType(BOOKMARKS)); 238 progress.set_data_type_id(GetSpecificsFieldNumberFromModelType(BOOKMARKS));
233 progress.set_token("token"); 239 progress.set_token("token");
234 240
235 UpdateProgressMarkers(&handler, progress); 241 UpdateProgressMarkers(&handler, progress);
236 242
237 sync_pb::DataTypeProgressMarker saved; 243 sync_pb::DataTypeProgressMarker saved;
238 dir()->GetDownloadProgress(BOOKMARKS, &saved); 244 dir()->GetDownloadProgress(BOOKMARKS, &saved);
239 245
240 EXPECT_EQ(progress.token(), saved.token()); 246 EXPECT_EQ(progress.token(), saved.token());
241 EXPECT_EQ(progress.data_type_id(), saved.data_type_id()); 247 EXPECT_EQ(progress.data_type_id(), saved.data_type_id());
242 } 248 }
243 249
244 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, GarbageCollectionByVersion) { 250 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, GarbageCollectionByVersion) {
245 DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS, ui_worker()); 251 DirectoryTypeDebugInfoEmitter emitter;
252 DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS,
253 ui_worker(), &emitter);
246 sessions::StatusController status; 254 sessions::StatusController status;
247 255
248 sync_pb::DataTypeProgressMarker progress; 256 sync_pb::DataTypeProgressMarker progress;
249 progress.set_data_type_id( 257 progress.set_data_type_id(
250 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); 258 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS));
251 progress.set_token("token"); 259 progress.set_token("token");
252 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10); 260 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10);
253 261
254 sync_pb::DataTypeContext context; 262 sync_pb::DataTypeContext context;
255 context.set_data_type_id( 263 context.set_data_type_id(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 EXPECT_EQ(SYNCER_OK, 306 EXPECT_EQ(SYNCER_OK,
299 handler.ProcessGetUpdatesResponse( 307 handler.ProcessGetUpdatesResponse(
300 progress, context, SyncEntityList(), &status)); 308 progress, context, SyncEntityList(), &status));
301 handler.ApplyUpdates(&status); 309 handler.ApplyUpdates(&status);
302 EXPECT_TRUE(EntryExists(type_root->id_string())); 310 EXPECT_TRUE(EntryExists(type_root->id_string()));
303 EXPECT_FALSE(EntryExists(e1->id_string())); 311 EXPECT_FALSE(EntryExists(e1->id_string()));
304 EXPECT_TRUE(EntryExists(e2->id_string())); 312 EXPECT_TRUE(EntryExists(e2->id_string()));
305 } 313 }
306 314
307 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ContextVersion) { 315 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ContextVersion) {
308 DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS, ui_worker()); 316 DirectoryTypeDebugInfoEmitter emitter;
317 DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS,
318 ui_worker(), &emitter);
309 sessions::StatusController status; 319 sessions::StatusController status;
310 int field_number = GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS); 320 int field_number = GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS);
311 321
312 sync_pb::DataTypeProgressMarker progress; 322 sync_pb::DataTypeProgressMarker progress;
313 progress.set_data_type_id( 323 progress.set_data_type_id(
314 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); 324 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS));
315 progress.set_token("token"); 325 progress.set_token("token");
316 326
317 sync_pb::DataTypeContext old_context; 327 sync_pb::DataTypeContext old_context;
318 old_context.set_version(1); 328 old_context.set_version(1);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 password_worker_(new FakeModelWorker(GROUP_PASSWORD)), 414 password_worker_(new FakeModelWorker(GROUP_PASSWORD)),
405 passive_worker_(new FakeModelWorker(GROUP_PASSIVE)), 415 passive_worker_(new FakeModelWorker(GROUP_PASSIVE)),
406 update_handler_map_deleter_(&update_handler_map_) {} 416 update_handler_map_deleter_(&update_handler_map_) {}
407 417
408 virtual void SetUp() OVERRIDE { 418 virtual void SetUp() OVERRIDE {
409 dir_maker_.SetUp(); 419 dir_maker_.SetUp();
410 entry_factory_.reset(new TestEntryFactory(directory())); 420 entry_factory_.reset(new TestEntryFactory(directory()));
411 421
412 update_handler_map_.insert(std::make_pair( 422 update_handler_map_.insert(std::make_pair(
413 BOOKMARKS, 423 BOOKMARKS,
414 new DirectoryUpdateHandler(directory(), BOOKMARKS, ui_worker_))); 424 new DirectoryUpdateHandler(directory(), BOOKMARKS,
425 ui_worker_, &bookmarks_emitter_)));
415 update_handler_map_.insert(std::make_pair( 426 update_handler_map_.insert(std::make_pair(
416 PASSWORDS, 427 PASSWORDS,
417 new DirectoryUpdateHandler(directory(), 428 new DirectoryUpdateHandler(directory(),
418 PASSWORDS, 429 PASSWORDS,
419 password_worker_))); 430 password_worker_,
431 &passwords_emitter_)));
420 } 432 }
421 433
422 virtual void TearDown() OVERRIDE { 434 virtual void TearDown() OVERRIDE {
423 dir_maker_.TearDown(); 435 dir_maker_.TearDown();
424 } 436 }
425 437
426 protected: 438 protected:
427 void ApplyBookmarkUpdates(sessions::StatusController* status) { 439 void ApplyBookmarkUpdates(sessions::StatusController* status) {
428 update_handler_map_[BOOKMARKS]->ApplyUpdates(status); 440 update_handler_map_[BOOKMARKS]->ApplyUpdates(status);
429 } 441 }
(...skipping 14 matching lines...) Expand all
444 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap; 456 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap;
445 457
446 base::MessageLoop loop_; // Needed to initialize the directory. 458 base::MessageLoop loop_; // Needed to initialize the directory.
447 TestDirectorySetterUpper dir_maker_; 459 TestDirectorySetterUpper dir_maker_;
448 scoped_ptr<TestEntryFactory> entry_factory_; 460 scoped_ptr<TestEntryFactory> entry_factory_;
449 461
450 scoped_refptr<FakeModelWorker> ui_worker_; 462 scoped_refptr<FakeModelWorker> ui_worker_;
451 scoped_refptr<FakeModelWorker> password_worker_; 463 scoped_refptr<FakeModelWorker> password_worker_;
452 scoped_refptr<FakeModelWorker> passive_worker_; 464 scoped_refptr<FakeModelWorker> passive_worker_;
453 465
466 DirectoryTypeDebugInfoEmitter bookmarks_emitter_;
467 DirectoryTypeDebugInfoEmitter passwords_emitter_;
468
454 UpdateHandlerMap update_handler_map_; 469 UpdateHandlerMap update_handler_map_;
455 STLValueDeleter<UpdateHandlerMap> update_handler_map_deleter_; 470 STLValueDeleter<UpdateHandlerMap> update_handler_map_deleter_;
456 }; 471 };
457 472
458 namespace { 473 namespace {
459 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() { 474 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() {
460 sync_pb::EntitySpecifics result; 475 sync_pb::EntitySpecifics result;
461 AddDefaultFieldValue(BOOKMARKS, &result); 476 AddDefaultFieldValue(BOOKMARKS, &result);
462 return result; 477 return result;
463 } 478 }
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 syncable::Entry e1(&trans, syncable::GET_BY_HANDLE, decryptable_handle); 984 syncable::Entry e1(&trans, syncable::GET_BY_HANDLE, decryptable_handle);
970 syncable::Entry e2(&trans, syncable::GET_BY_HANDLE, undecryptable_handle); 985 syncable::Entry e2(&trans, syncable::GET_BY_HANDLE, undecryptable_handle);
971 ASSERT_TRUE(e1.good()); 986 ASSERT_TRUE(e1.good());
972 ASSERT_TRUE(e2.good()); 987 ASSERT_TRUE(e2.good());
973 EXPECT_FALSE(e1.GetIsUnappliedUpdate()); 988 EXPECT_FALSE(e1.GetIsUnappliedUpdate());
974 EXPECT_TRUE(e2.GetIsUnappliedUpdate()); 989 EXPECT_TRUE(e2.GetIsUnappliedUpdate());
975 } 990 }
976 } 991 }
977 992
978 } // namespace syncer 993 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/directory_update_handler.cc ('k') | sync/sessions/model_type_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698