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

Side by Side Diff: components/sync/engine_impl/directory_update_handler_unittest.cc

Issue 2258873003: [Sync] Move sessions/ to engine/cycle/ and rename things to match. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 4 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
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 "components/sync/engine_impl/directory_update_handler.h" 5 #include "components/sync/engine_impl/directory_update_handler.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "components/sync/base/attachment_id_proto.h" 18 #include "components/sync/base/attachment_id_proto.h"
19 #include "components/sync/base/model_type.h" 19 #include "components/sync/base/model_type.h"
20 #include "components/sync/core/test/test_entry_factory.h" 20 #include "components/sync/core/test/test_entry_factory.h"
21 #include "components/sync/engine_impl/cycle/directory_type_debug_info_emitter.h"
22 #include "components/sync/engine_impl/cycle/status_controller.h"
21 #include "components/sync/engine_impl/syncer_proto_util.h" 23 #include "components/sync/engine_impl/syncer_proto_util.h"
22 #include "components/sync/protocol/sync.pb.h" 24 #include "components/sync/protocol/sync.pb.h"
23 #include "components/sync/sessions_impl/directory_type_debug_info_emitter.h"
24 #include "components/sync/sessions_impl/status_controller.h"
25 #include "components/sync/syncable/directory.h" 25 #include "components/sync/syncable/directory.h"
26 #include "components/sync/syncable/entry.h" 26 #include "components/sync/syncable/entry.h"
27 #include "components/sync/syncable/mutable_entry.h" 27 #include "components/sync/syncable/mutable_entry.h"
28 #include "components/sync/syncable/syncable_model_neutral_write_transaction.h" 28 #include "components/sync/syncable/syncable_model_neutral_write_transaction.h"
29 #include "components/sync/syncable/syncable_proto_util.h" 29 #include "components/sync/syncable/syncable_proto_util.h"
30 #include "components/sync/syncable/syncable_read_transaction.h" 30 #include "components/sync/syncable/syncable_read_transaction.h"
31 #include "components/sync/syncable/syncable_write_transaction.h" 31 #include "components/sync/syncable/syncable_write_transaction.h"
32 #include "components/sync/test/engine/fake_model_worker.h" 32 #include "components/sync/test/engine/fake_model_worker.h"
33 #include "components/sync/test/engine/test_directory_setter_upper.h" 33 #include "components/sync/test/engine/test_directory_setter_upper.h"
34 #include "components/sync/test/engine/test_id_factory.h" 34 #include "components/sync/test/engine/test_id_factory.h"
(...skipping 27 matching lines...) Expand all
62 62
63 protected: 63 protected:
64 std::unique_ptr<sync_pb::SyncEntity> CreateUpdate(const std::string& id, 64 std::unique_ptr<sync_pb::SyncEntity> CreateUpdate(const std::string& id,
65 const std::string& parent, 65 const std::string& parent,
66 const ModelType& type); 66 const ModelType& type);
67 67
68 // This exists mostly to give tests access to the protected member function. 68 // This exists mostly to give tests access to the protected member function.
69 // Warning: This takes the syncable directory lock. 69 // Warning: This takes the syncable directory lock.
70 void UpdateSyncEntities(DirectoryUpdateHandler* handler, 70 void UpdateSyncEntities(DirectoryUpdateHandler* handler,
71 const SyncEntityList& applicable_updates, 71 const SyncEntityList& applicable_updates,
72 sessions::StatusController* status); 72 StatusController* status);
73 73
74 // Another function to access private member functions. 74 // Another function to access private member functions.
75 void UpdateProgressMarkers(DirectoryUpdateHandler* handler, 75 void UpdateProgressMarkers(DirectoryUpdateHandler* handler,
76 const sync_pb::DataTypeProgressMarker& progress); 76 const sync_pb::DataTypeProgressMarker& progress);
77 77
78 scoped_refptr<FakeModelWorker> ui_worker() { return ui_worker_; } 78 scoped_refptr<FakeModelWorker> ui_worker() { return ui_worker_; }
79 79
80 bool EntryExists(const std::string& id) { 80 bool EntryExists(const std::string& id) {
81 syncable::ReadTransaction trans(FROM_HERE, dir()); 81 syncable::ReadTransaction trans(FROM_HERE, dir());
82 syncable::Entry e(&trans, syncable::GET_BY_ID, Id::CreateFromServerId(id)); 82 syncable::Entry e(&trans, syncable::GET_BY_ID, Id::CreateFromServerId(id));
(...skipping 24 matching lines...) Expand all
107 e->set_non_unique_name(id); 107 e->set_non_unique_name(id);
108 e->set_name(id); 108 e->set_name(id);
109 e->set_version(kDefaultVersion); 109 e->set_version(kDefaultVersion);
110 AddDefaultFieldValue(type, e->mutable_specifics()); 110 AddDefaultFieldValue(type, e->mutable_specifics());
111 return e; 111 return e;
112 } 112 }
113 113
114 void DirectoryUpdateHandlerProcessUpdateTest::UpdateSyncEntities( 114 void DirectoryUpdateHandlerProcessUpdateTest::UpdateSyncEntities(
115 DirectoryUpdateHandler* handler, 115 DirectoryUpdateHandler* handler,
116 const SyncEntityList& applicable_updates, 116 const SyncEntityList& applicable_updates,
117 sessions::StatusController* status) { 117 StatusController* status) {
118 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, UNITTEST, dir()); 118 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, UNITTEST, dir());
119 handler->UpdateSyncEntities(&trans, applicable_updates, status); 119 handler->UpdateSyncEntities(&trans, applicable_updates, status);
120 } 120 }
121 121
122 void DirectoryUpdateHandlerProcessUpdateTest::UpdateProgressMarkers( 122 void DirectoryUpdateHandlerProcessUpdateTest::UpdateProgressMarkers(
123 DirectoryUpdateHandler* handler, 123 DirectoryUpdateHandler* handler,
124 const sync_pb::DataTypeProgressMarker& progress) { 124 const sync_pb::DataTypeProgressMarker& progress) {
125 handler->UpdateProgressMarker(progress); 125 handler->UpdateProgressMarker(progress);
126 } 126 }
127 127
128 static const char kCacheGuid[] = "IrcjZ2jyzHDV9Io4+zKcXQ=="; 128 static const char kCacheGuid[] = "IrcjZ2jyzHDV9Io4+zKcXQ==";
129 129
130 // Test that the bookmark tag is set on newly downloaded items. 130 // Test that the bookmark tag is set on newly downloaded items.
131 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, NewBookmarkTag) { 131 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, NewBookmarkTag) {
132 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_); 132 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_);
133 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter); 133 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter);
134 sync_pb::GetUpdatesResponse gu_response; 134 sync_pb::GetUpdatesResponse gu_response;
135 sessions::StatusController status; 135 StatusController status;
136 136
137 // Add a bookmark item to the update message. 137 // Add a bookmark item to the update message.
138 std::string root = Id::GetRoot().GetServerId(); 138 std::string root = Id::GetRoot().GetServerId();
139 Id server_id = Id::CreateFromServerId("b1"); 139 Id server_id = Id::CreateFromServerId("b1");
140 std::unique_ptr<sync_pb::SyncEntity> e = 140 std::unique_ptr<sync_pb::SyncEntity> e =
141 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS); 141 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS);
142 e->set_originator_cache_guid( 142 e->set_originator_cache_guid(
143 std::string(kCacheGuid, arraysize(kCacheGuid) - 1)); 143 std::string(kCacheGuid, arraysize(kCacheGuid) - 1));
144 Id client_id = Id::CreateFromClientString("-2"); 144 Id client_id = Id::CreateFromClientString("-2");
145 e->set_originator_client_item_id(client_id.GetServerId()); 145 e->set_originator_client_item_id(client_id.GetServerId());
(...skipping 18 matching lines...) Expand all
164 // intend to make such a change. 164 // intend to make such a change.
165 EXPECT_EQ("6wHRAb3kbnXV5GHrejp4/c1y5tw=", entry.GetUniqueBookmarkTag()); 165 EXPECT_EQ("6wHRAb3kbnXV5GHrejp4/c1y5tw=", entry.GetUniqueBookmarkTag());
166 } 166 }
167 167
168 // Test the receipt of a type root node. 168 // Test the receipt of a type root node.
169 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, 169 TEST_F(DirectoryUpdateHandlerProcessUpdateTest,
170 ReceiveServerCreatedBookmarkFolders) { 170 ReceiveServerCreatedBookmarkFolders) {
171 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_); 171 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_);
172 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter); 172 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter);
173 sync_pb::GetUpdatesResponse gu_response; 173 sync_pb::GetUpdatesResponse gu_response;
174 sessions::StatusController status; 174 StatusController status;
175 175
176 // Create an update that mimics the bookmark root. 176 // Create an update that mimics the bookmark root.
177 Id server_id = Id::CreateFromServerId("xyz"); 177 Id server_id = Id::CreateFromServerId("xyz");
178 std::string root = Id::GetRoot().GetServerId(); 178 std::string root = Id::GetRoot().GetServerId();
179 std::unique_ptr<sync_pb::SyncEntity> e = 179 std::unique_ptr<sync_pb::SyncEntity> e =
180 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS); 180 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS);
181 e->set_server_defined_unique_tag("google_chrome_bookmarks"); 181 e->set_server_defined_unique_tag("google_chrome_bookmarks");
182 e->set_folder(true); 182 e->set_folder(true);
183 183
184 // Add it to the applicable updates list. 184 // Add it to the applicable updates list.
(...skipping 14 matching lines...) Expand all
199 EXPECT_FALSE(entry.GetUniquePosition().IsValid()); 199 EXPECT_FALSE(entry.GetUniquePosition().IsValid());
200 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid()); 200 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid());
201 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty()); 201 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty());
202 } 202 }
203 203
204 // Test the receipt of a non-bookmark item. 204 // Test the receipt of a non-bookmark item.
205 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ReceiveNonBookmarkItem) { 205 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ReceiveNonBookmarkItem) {
206 DirectoryTypeDebugInfoEmitter emitter(AUTOFILL, &type_observers_); 206 DirectoryTypeDebugInfoEmitter emitter(AUTOFILL, &type_observers_);
207 DirectoryUpdateHandler handler(dir(), AUTOFILL, ui_worker(), &emitter); 207 DirectoryUpdateHandler handler(dir(), AUTOFILL, ui_worker(), &emitter);
208 sync_pb::GetUpdatesResponse gu_response; 208 sync_pb::GetUpdatesResponse gu_response;
209 sessions::StatusController status; 209 StatusController status;
210 210
211 std::string root = Id::GetRoot().GetServerId(); 211 std::string root = Id::GetRoot().GetServerId();
212 Id server_id = Id::CreateFromServerId("xyz"); 212 Id server_id = Id::CreateFromServerId("xyz");
213 std::unique_ptr<sync_pb::SyncEntity> e = 213 std::unique_ptr<sync_pb::SyncEntity> e =
214 CreateUpdate(SyncableIdToProto(server_id), root, AUTOFILL); 214 CreateUpdate(SyncableIdToProto(server_id), root, AUTOFILL);
215 e->set_server_defined_unique_tag("9PGRuKdX5sHyGMB17CvYTXuC43I="); 215 e->set_server_defined_unique_tag("9PGRuKdX5sHyGMB17CvYTXuC43I=");
216 216
217 // Add it to the applicable updates list. 217 // Add it to the applicable updates list.
218 SyncEntityList autofill_updates; 218 SyncEntityList autofill_updates;
219 autofill_updates.push_back(e.get()); 219 autofill_updates.push_back(e.get());
(...skipping 28 matching lines...) Expand all
248 dir()->GetDownloadProgress(BOOKMARKS, &saved); 248 dir()->GetDownloadProgress(BOOKMARKS, &saved);
249 249
250 EXPECT_EQ(progress.token(), saved.token()); 250 EXPECT_EQ(progress.token(), saved.token());
251 EXPECT_EQ(progress.data_type_id(), saved.data_type_id()); 251 EXPECT_EQ(progress.data_type_id(), saved.data_type_id());
252 } 252 }
253 253
254 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, GarbageCollectionByVersion) { 254 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, GarbageCollectionByVersion) {
255 DirectoryTypeDebugInfoEmitter emitter(SYNCED_NOTIFICATIONS, &type_observers_); 255 DirectoryTypeDebugInfoEmitter emitter(SYNCED_NOTIFICATIONS, &type_observers_);
256 DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS, ui_worker(), 256 DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS, ui_worker(),
257 &emitter); 257 &emitter);
258 sessions::StatusController status; 258 StatusController status;
259 259
260 sync_pb::DataTypeProgressMarker progress; 260 sync_pb::DataTypeProgressMarker progress;
261 progress.set_data_type_id( 261 progress.set_data_type_id(
262 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); 262 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS));
263 progress.set_token("token"); 263 progress.set_token("token");
264 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10); 264 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10);
265 265
266 sync_pb::DataTypeContext context; 266 sync_pb::DataTypeContext context;
267 context.set_data_type_id( 267 context.set_data_type_id(
268 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); 268 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS));
(...skipping 30 matching lines...) Expand all
299 progress, context, SyncEntityList(), &status)); 299 progress, context, SyncEntityList(), &status));
300 handler.ApplyUpdates(&status); 300 handler.ApplyUpdates(&status);
301 EXPECT_FALSE(EntryExists(e1->id_string())); 301 EXPECT_FALSE(EntryExists(e1->id_string()));
302 EXPECT_TRUE(EntryExists(e2->id_string())); 302 EXPECT_TRUE(EntryExists(e2->id_string()));
303 } 303 }
304 304
305 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ContextVersion) { 305 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ContextVersion) {
306 DirectoryTypeDebugInfoEmitter emitter(SYNCED_NOTIFICATIONS, &type_observers_); 306 DirectoryTypeDebugInfoEmitter emitter(SYNCED_NOTIFICATIONS, &type_observers_);
307 DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS, ui_worker(), 307 DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS, ui_worker(),
308 &emitter); 308 &emitter);
309 sessions::StatusController status; 309 StatusController status;
310 int field_number = GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS); 310 int field_number = GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS);
311 311
312 sync_pb::DataTypeProgressMarker progress; 312 sync_pb::DataTypeProgressMarker progress;
313 progress.set_data_type_id( 313 progress.set_data_type_id(
314 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); 314 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS));
315 progress.set_token("token"); 315 progress.set_token("token");
316 316
317 sync_pb::DataTypeContext old_context; 317 sync_pb::DataTypeContext old_context;
318 old_context.set_version(1); 318 old_context.set_version(1);
319 old_context.set_context("data"); 319 old_context.set_context("data");
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 EXPECT_EQ(old_context.SerializeAsString(), dir_context.SerializeAsString()); 372 EXPECT_EQ(old_context.SerializeAsString(), dir_context.SerializeAsString());
373 } 373 }
374 } 374 }
375 375
376 // See that updates containing attachment metadata are applied 376 // See that updates containing attachment metadata are applied
377 // (i.e. server_attachment_metadata is copied to attachment_metadata). 377 // (i.e. server_attachment_metadata is copied to attachment_metadata).
378 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, 378 TEST_F(DirectoryUpdateHandlerProcessUpdateTest,
379 ProcessAndApplyUpdatesWithAttachments) { 379 ProcessAndApplyUpdatesWithAttachments) {
380 DirectoryTypeDebugInfoEmitter emitter(ARTICLES, &type_observers_); 380 DirectoryTypeDebugInfoEmitter emitter(ARTICLES, &type_observers_);
381 DirectoryUpdateHandler handler(dir(), ARTICLES, ui_worker(), &emitter); 381 DirectoryUpdateHandler handler(dir(), ARTICLES, ui_worker(), &emitter);
382 sessions::StatusController status; 382 StatusController status;
383 383
384 sync_pb::DataTypeProgressMarker progress; 384 sync_pb::DataTypeProgressMarker progress;
385 progress.set_data_type_id(GetSpecificsFieldNumberFromModelType(ARTICLES)); 385 progress.set_data_type_id(GetSpecificsFieldNumberFromModelType(ARTICLES));
386 progress.set_token("token"); 386 progress.set_token("token");
387 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10); 387 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10);
388 388
389 sync_pb::DataTypeContext context; 389 sync_pb::DataTypeContext context;
390 context.set_data_type_id(GetSpecificsFieldNumberFromModelType(ARTICLES)); 390 context.set_data_type_id(GetSpecificsFieldNumberFromModelType(ARTICLES));
391 context.set_context("context"); 391 context.set_context("context");
392 context.set_version(1); 392 context.set_version(1);
(...skipping 29 matching lines...) Expand all
422 ASSERT_EQ(attachment_metadata.SerializeAsString(), 422 ASSERT_EQ(attachment_metadata.SerializeAsString(),
423 e.GetServerAttachmentMetadata().SerializeAsString()); 423 e.GetServerAttachmentMetadata().SerializeAsString());
424 } 424 }
425 } 425 }
426 426
427 // Tests that IsInitialSyncEnded value is updated by ApplyUpdates, but not by 427 // Tests that IsInitialSyncEnded value is updated by ApplyUpdates, but not by
428 // ProcessGetUpdatesResponse. 428 // ProcessGetUpdatesResponse.
429 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, IsInitialSyncEnded) { 429 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, IsInitialSyncEnded) {
430 DirectoryTypeDebugInfoEmitter emitter(AUTOFILL, &type_observers_); 430 DirectoryTypeDebugInfoEmitter emitter(AUTOFILL, &type_observers_);
431 DirectoryUpdateHandler handler(dir(), AUTOFILL, ui_worker(), &emitter); 431 DirectoryUpdateHandler handler(dir(), AUTOFILL, ui_worker(), &emitter);
432 sessions::StatusController status; 432 StatusController status;
433 433
434 EXPECT_FALSE(handler.IsInitialSyncEnded()); 434 EXPECT_FALSE(handler.IsInitialSyncEnded());
435 435
436 sync_pb::DataTypeProgressMarker progress; 436 sync_pb::DataTypeProgressMarker progress;
437 progress.set_data_type_id(GetSpecificsFieldNumberFromModelType(AUTOFILL)); 437 progress.set_data_type_id(GetSpecificsFieldNumberFromModelType(AUTOFILL));
438 progress.set_token("token"); 438 progress.set_token("token");
439 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10); 439 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10);
440 440
441 std::unique_ptr<sync_pb::SyncEntity> e = CreateUpdate( 441 std::unique_ptr<sync_pb::SyncEntity> e = CreateUpdate(
442 SyncableIdToProto(Id::CreateFromServerId("e1")), "", AUTOFILL); 442 SyncableIdToProto(Id::CreateFromServerId("e1")), "", AUTOFILL);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 503
504 const UpdateCounters& GetPasswordsUpdateCounters() { 504 const UpdateCounters& GetPasswordsUpdateCounters() {
505 return passwords_emitter_.GetUpdateCounters(); 505 return passwords_emitter_.GetUpdateCounters();
506 } 506 }
507 507
508 const UpdateCounters& GetArticlesUpdateCounters() { 508 const UpdateCounters& GetArticlesUpdateCounters() {
509 return articles_emitter_.GetUpdateCounters(); 509 return articles_emitter_.GetUpdateCounters();
510 } 510 }
511 511
512 protected: 512 protected:
513 void ApplyBookmarkUpdates(sessions::StatusController* status) { 513 void ApplyBookmarkUpdates(StatusController* status) {
514 update_handler_map_.find(BOOKMARKS)->second->ApplyUpdates(status); 514 update_handler_map_.find(BOOKMARKS)->second->ApplyUpdates(status);
515 } 515 }
516 516
517 void ApplyPasswordUpdates(sessions::StatusController* status) { 517 void ApplyPasswordUpdates(StatusController* status) {
518 update_handler_map_.find(PASSWORDS)->second->ApplyUpdates(status); 518 update_handler_map_.find(PASSWORDS)->second->ApplyUpdates(status);
519 } 519 }
520 520
521 void ApplyArticlesUpdates(sessions::StatusController* status) { 521 void ApplyArticlesUpdates(StatusController* status) {
522 update_handler_map_.find(ARTICLES)->second->ApplyUpdates(status); 522 update_handler_map_.find(ARTICLES)->second->ApplyUpdates(status);
523 } 523 }
524 524
525 TestEntryFactory* entry_factory() { return entry_factory_.get(); } 525 TestEntryFactory* entry_factory() { return entry_factory_.get(); }
526 526
527 syncable::Directory* directory() { return dir_maker_.directory(); } 527 syncable::Directory* directory() { return dir_maker_.directory(); }
528 528
529 private: 529 private:
530 base::MessageLoop loop_; // Needed to initialize the directory. 530 base::MessageLoop loop_; // Needed to initialize the directory.
531 TestDirectorySetterUpper dir_maker_; 531 TestDirectorySetterUpper dir_maker_;
(...skipping 14 matching lines...) Expand all
546 namespace { 546 namespace {
547 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() { 547 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() {
548 sync_pb::EntitySpecifics result; 548 sync_pb::EntitySpecifics result;
549 AddDefaultFieldValue(BOOKMARKS, &result); 549 AddDefaultFieldValue(BOOKMARKS, &result);
550 return result; 550 return result;
551 } 551 }
552 } // namespace 552 } // namespace
553 553
554 // Test update application for a few bookmark items. 554 // Test update application for a few bookmark items.
555 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, SimpleBookmark) { 555 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, SimpleBookmark) {
556 sessions::StatusController status; 556 StatusController status;
557 557
558 std::string root_server_id = Id::GetRoot().GetServerId(); 558 std::string root_server_id = Id::GetRoot().GetServerId();
559 int64_t parent_handle = 559 int64_t parent_handle =
560 entry_factory()->CreateUnappliedNewBookmarkItemWithParent( 560 entry_factory()->CreateUnappliedNewBookmarkItemWithParent(
561 "parent", DefaultBookmarkSpecifics(), root_server_id); 561 "parent", DefaultBookmarkSpecifics(), root_server_id);
562 int64_t child_handle = 562 int64_t child_handle =
563 entry_factory()->CreateUnappliedNewBookmarkItemWithParent( 563 entry_factory()->CreateUnappliedNewBookmarkItemWithParent(
564 "child", DefaultBookmarkSpecifics(), "parent"); 564 "child", DefaultBookmarkSpecifics(), "parent");
565 565
566 ApplyBookmarkUpdates(&status); 566 ApplyBookmarkUpdates(&status);
(...skipping 25 matching lines...) Expand all
592 // Test that the applicator can handle updates delivered out of order. 592 // Test that the applicator can handle updates delivered out of order.
593 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, BookmarkChildrenBeforeParent) { 593 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, BookmarkChildrenBeforeParent) {
594 // Start with some bookmarks whose parents are unknown. 594 // Start with some bookmarks whose parents are unknown.
595 std::string root_server_id = Id::GetRoot().GetServerId(); 595 std::string root_server_id = Id::GetRoot().GetServerId();
596 int64_t a_handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( 596 int64_t a_handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent(
597 "a_child_created_first", DefaultBookmarkSpecifics(), "parent"); 597 "a_child_created_first", DefaultBookmarkSpecifics(), "parent");
598 int64_t x_handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( 598 int64_t x_handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent(
599 "x_child_created_first", DefaultBookmarkSpecifics(), "parent"); 599 "x_child_created_first", DefaultBookmarkSpecifics(), "parent");
600 600
601 // Update application will fail. 601 // Update application will fail.
602 sessions::StatusController status1; 602 StatusController status1;
603 ApplyBookmarkUpdates(&status1); 603 ApplyBookmarkUpdates(&status1);
604 EXPECT_EQ(0, status1.num_updates_applied()); 604 EXPECT_EQ(0, status1.num_updates_applied());
605 EXPECT_EQ(2, status1.num_hierarchy_conflicts()); 605 EXPECT_EQ(2, status1.num_hierarchy_conflicts());
606 606
607 { 607 {
608 syncable::ReadTransaction trans(FROM_HERE, directory()); 608 syncable::ReadTransaction trans(FROM_HERE, directory());
609 609
610 syncable::Entry a(&trans, syncable::GET_BY_HANDLE, a_handle); 610 syncable::Entry a(&trans, syncable::GET_BY_HANDLE, a_handle);
611 syncable::Entry x(&trans, syncable::GET_BY_HANDLE, x_handle); 611 syncable::Entry x(&trans, syncable::GET_BY_HANDLE, x_handle);
612 612
613 ASSERT_TRUE(a.good()); 613 ASSERT_TRUE(a.good());
614 ASSERT_TRUE(x.good()); 614 ASSERT_TRUE(x.good());
615 615
616 EXPECT_TRUE(a.GetIsUnappliedUpdate()); 616 EXPECT_TRUE(a.GetIsUnappliedUpdate());
617 EXPECT_TRUE(x.GetIsUnappliedUpdate()); 617 EXPECT_TRUE(x.GetIsUnappliedUpdate());
618 } 618 }
619 619
620 // Now add their parent and a few siblings. 620 // Now add their parent and a few siblings.
621 entry_factory()->CreateUnappliedNewBookmarkItemWithParent( 621 entry_factory()->CreateUnappliedNewBookmarkItemWithParent(
622 "parent", DefaultBookmarkSpecifics(), root_server_id); 622 "parent", DefaultBookmarkSpecifics(), root_server_id);
623 entry_factory()->CreateUnappliedNewBookmarkItemWithParent( 623 entry_factory()->CreateUnappliedNewBookmarkItemWithParent(
624 "a_child_created_second", DefaultBookmarkSpecifics(), "parent"); 624 "a_child_created_second", DefaultBookmarkSpecifics(), "parent");
625 entry_factory()->CreateUnappliedNewBookmarkItemWithParent( 625 entry_factory()->CreateUnappliedNewBookmarkItemWithParent(
626 "x_child_created_second", DefaultBookmarkSpecifics(), "parent"); 626 "x_child_created_second", DefaultBookmarkSpecifics(), "parent");
627 627
628 // Update application will succeed. 628 // Update application will succeed.
629 sessions::StatusController status2; 629 StatusController status2;
630 ApplyBookmarkUpdates(&status2); 630 ApplyBookmarkUpdates(&status2);
631 EXPECT_EQ(5, status2.num_updates_applied()) 631 EXPECT_EQ(5, status2.num_updates_applied())
632 << "All updates should have been successfully applied"; 632 << "All updates should have been successfully applied";
633 633
634 { 634 {
635 syncable::ReadTransaction trans(FROM_HERE, directory()); 635 syncable::ReadTransaction trans(FROM_HERE, directory());
636 636
637 syncable::Entry a(&trans, syncable::GET_BY_HANDLE, a_handle); 637 syncable::Entry a(&trans, syncable::GET_BY_HANDLE, a_handle);
638 syncable::Entry x(&trans, syncable::GET_BY_HANDLE, x_handle); 638 syncable::Entry x(&trans, syncable::GET_BY_HANDLE, x_handle);
639 639
(...skipping 12 matching lines...) Expand all
652 652
653 int original_server_version = -10; 653 int original_server_version = -10;
654 { 654 {
655 syncable::ReadTransaction trans(FROM_HERE, directory()); 655 syncable::ReadTransaction trans(FROM_HERE, directory());
656 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); 656 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle);
657 original_server_version = e.GetServerVersion(); 657 original_server_version = e.GetServerVersion();
658 ASSERT_NE(original_server_version, e.GetBaseVersion()); 658 ASSERT_NE(original_server_version, e.GetBaseVersion());
659 EXPECT_TRUE(e.GetIsUnsynced()); 659 EXPECT_TRUE(e.GetIsUnsynced());
660 } 660 }
661 661
662 sessions::StatusController status; 662 StatusController status;
663 ApplyBookmarkUpdates(&status); 663 ApplyBookmarkUpdates(&status);
664 664
665 const UpdateCounters& counters = GetBookmarksUpdateCounters(); 665 const UpdateCounters& counters = GetBookmarksUpdateCounters();
666 EXPECT_EQ(1, counters.num_server_overwrites) 666 EXPECT_EQ(1, counters.num_server_overwrites)
667 << "Unsynced and unapplied item conflict should be resolved"; 667 << "Unsynced and unapplied item conflict should be resolved";
668 EXPECT_EQ(0, counters.num_updates_applied) 668 EXPECT_EQ(0, counters.num_updates_applied)
669 << "Update should not be applied; we should override the server."; 669 << "Update should not be applied; we should override the server.";
670 670
671 { 671 {
672 syncable::ReadTransaction trans(FROM_HERE, directory()); 672 syncable::ReadTransaction trans(FROM_HERE, directory());
(...skipping 19 matching lines...) Expand all
692 { 692 {
693 // Manually set the SERVER_PARENT_ID to bad value. 693 // Manually set the SERVER_PARENT_ID to bad value.
694 // A bad parent indicates a hierarchy conflict. 694 // A bad parent indicates a hierarchy conflict.
695 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 695 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
696 syncable::MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle); 696 syncable::MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle);
697 ASSERT_TRUE(entry.good()); 697 ASSERT_TRUE(entry.good());
698 698
699 entry.PutServerParentId(TestIdFactory::MakeServer("bogus_parent")); 699 entry.PutServerParentId(TestIdFactory::MakeServer("bogus_parent"));
700 } 700 }
701 701
702 sessions::StatusController status; 702 StatusController status;
703 ApplyBookmarkUpdates(&status); 703 ApplyBookmarkUpdates(&status);
704 704
705 const UpdateCounters& counters = GetBookmarksUpdateCounters(); 705 const UpdateCounters& counters = GetBookmarksUpdateCounters();
706 EXPECT_EQ(0, counters.num_updates_applied); 706 EXPECT_EQ(0, counters.num_updates_applied);
707 EXPECT_EQ(0, counters.num_server_overwrites); 707 EXPECT_EQ(0, counters.num_server_overwrites);
708 EXPECT_EQ(1, counters.num_hierarchy_conflict_application_failures); 708 EXPECT_EQ(1, counters.num_hierarchy_conflict_application_failures);
709 709
710 { 710 {
711 syncable::ReadTransaction trans(FROM_HERE, directory()); 711 syncable::ReadTransaction trans(FROM_HERE, directory());
712 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); 712 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle);
(...skipping 26 matching lines...) Expand all
739 // Item 'Y' is child of 'X'. 739 // Item 'Y' is child of 'X'.
740 entry_factory()->CreateUnsyncedItem(TestIdFactory::MakeServer("Y"), 740 entry_factory()->CreateUnsyncedItem(TestIdFactory::MakeServer("Y"),
741 TestIdFactory::MakeServer("X"), "Y", true, 741 TestIdFactory::MakeServer("X"), "Y", true,
742 BOOKMARKS, NULL); 742 BOOKMARKS, NULL);
743 743
744 // If the server's update were applied, we would have X be a child of Y, and Y 744 // If the server's update were applied, we would have X be a child of Y, and Y
745 // as a child of X. That's a directory loop. The UpdateApplicator should 745 // as a child of X. That's a directory loop. The UpdateApplicator should
746 // prevent the update from being applied and note that this is a hierarchy 746 // prevent the update from being applied and note that this is a hierarchy
747 // conflict. 747 // conflict.
748 748
749 sessions::StatusController status; 749 StatusController status;
750 ApplyBookmarkUpdates(&status); 750 ApplyBookmarkUpdates(&status);
751 751
752 // This should count as a hierarchy conflict. 752 // This should count as a hierarchy conflict.
753 const UpdateCounters& counters = GetBookmarksUpdateCounters(); 753 const UpdateCounters& counters = GetBookmarksUpdateCounters();
754 EXPECT_EQ(1, counters.num_hierarchy_conflict_application_failures); 754 EXPECT_EQ(1, counters.num_hierarchy_conflict_application_failures);
755 755
756 { 756 {
757 syncable::ReadTransaction trans(FROM_HERE, directory()); 757 syncable::ReadTransaction trans(FROM_HERE, directory());
758 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); 758 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle);
759 ASSERT_TRUE(e.good()); 759 ASSERT_TRUE(e.good());
(...skipping 18 matching lines...) Expand all
778 } 778 }
779 779
780 // Create an incoming child from the server. 780 // Create an incoming child from the server.
781 int64_t child_handle = entry_factory()->CreateUnappliedNewItemWithParent( 781 int64_t child_handle = entry_factory()->CreateUnappliedNewItemWithParent(
782 "child", DefaultBookmarkSpecifics(), "parent"); 782 "child", DefaultBookmarkSpecifics(), "parent");
783 783
784 // The server's update may seem valid to some other client, but on this client 784 // The server's update may seem valid to some other client, but on this client
785 // that new item's parent no longer exists. The update should not be applied 785 // that new item's parent no longer exists. The update should not be applied
786 // and the update applicator should indicate this is a hierarchy conflict. 786 // and the update applicator should indicate this is a hierarchy conflict.
787 787
788 sessions::StatusController status; 788 StatusController status;
789 ApplyBookmarkUpdates(&status); 789 ApplyBookmarkUpdates(&status);
790 const UpdateCounters& counters = GetBookmarksUpdateCounters(); 790 const UpdateCounters& counters = GetBookmarksUpdateCounters();
791 EXPECT_EQ(1, counters.num_hierarchy_conflict_application_failures); 791 EXPECT_EQ(1, counters.num_hierarchy_conflict_application_failures);
792 792
793 { 793 {
794 syncable::ReadTransaction trans(FROM_HERE, directory()); 794 syncable::ReadTransaction trans(FROM_HERE, directory());
795 syncable::Entry child(&trans, syncable::GET_BY_HANDLE, child_handle); 795 syncable::Entry child(&trans, syncable::GET_BY_HANDLE, child_handle);
796 ASSERT_TRUE(child.good()); 796 ASSERT_TRUE(child.good());
797 EXPECT_TRUE(child.GetIsUnappliedUpdate()); 797 EXPECT_TRUE(child.GetIsUnappliedUpdate());
798 EXPECT_FALSE(child.GetIsUnsynced()); 798 EXPECT_FALSE(child.GetIsUnsynced());
(...skipping 21 matching lines...) Expand all
820 } 820 }
821 821
822 // Create a local child of the server-deleted directory. 822 // Create a local child of the server-deleted directory.
823 entry_factory()->CreateUnsyncedItem(TestIdFactory::MakeServer("child"), 823 entry_factory()->CreateUnsyncedItem(TestIdFactory::MakeServer("child"),
824 TestIdFactory::MakeServer("parent"), 824 TestIdFactory::MakeServer("parent"),
825 "child", false, BOOKMARKS, NULL); 825 "child", false, BOOKMARKS, NULL);
826 826
827 // The server's request to delete the directory must be ignored, otherwise our 827 // The server's request to delete the directory must be ignored, otherwise our
828 // unsynced new child would be orphaned. This is a hierarchy conflict. 828 // unsynced new child would be orphaned. This is a hierarchy conflict.
829 829
830 sessions::StatusController status; 830 StatusController status;
831 ApplyBookmarkUpdates(&status); 831 ApplyBookmarkUpdates(&status);
832 832
833 // This should count as a hierarchy conflict. 833 // This should count as a hierarchy conflict.
834 const UpdateCounters& counters = GetBookmarksUpdateCounters(); 834 const UpdateCounters& counters = GetBookmarksUpdateCounters();
835 EXPECT_EQ(1, counters.num_hierarchy_conflict_application_failures); 835 EXPECT_EQ(1, counters.num_hierarchy_conflict_application_failures);
836 836
837 { 837 {
838 syncable::ReadTransaction trans(FROM_HERE, directory()); 838 syncable::ReadTransaction trans(FROM_HERE, directory());
839 syncable::Entry parent(&trans, syncable::GET_BY_HANDLE, parent_handle); 839 syncable::Entry parent(&trans, syncable::GET_BY_HANDLE, parent_handle);
840 ASSERT_TRUE(parent.good()); 840 ASSERT_TRUE(parent.good());
841 EXPECT_TRUE(parent.GetIsUnappliedUpdate()); 841 EXPECT_TRUE(parent.GetIsUnappliedUpdate());
842 EXPECT_FALSE(parent.GetIsUnsynced()); 842 EXPECT_FALSE(parent.GetIsUnsynced());
843 } 843 }
844 } 844 }
845 845
846 // Attempt to apply updates where the updated item's parent is not known to this 846 // Attempt to apply updates where the updated item's parent is not known to this
847 // client. The update application attempt should fail. 847 // client. The update application attempt should fail.
848 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, HierarchyConflictUnknownParent) { 848 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, HierarchyConflictUnknownParent) {
849 // We shouldn't be able to do anything with either of these items. 849 // We shouldn't be able to do anything with either of these items.
850 int64_t x_handle = entry_factory()->CreateUnappliedNewItemWithParent( 850 int64_t x_handle = entry_factory()->CreateUnappliedNewItemWithParent(
851 "some_item", DefaultBookmarkSpecifics(), "unknown_parent"); 851 "some_item", DefaultBookmarkSpecifics(), "unknown_parent");
852 int64_t y_handle = entry_factory()->CreateUnappliedNewItemWithParent( 852 int64_t y_handle = entry_factory()->CreateUnappliedNewItemWithParent(
853 "some_other_item", DefaultBookmarkSpecifics(), "some_item"); 853 "some_other_item", DefaultBookmarkSpecifics(), "some_item");
854 854
855 sessions::StatusController status; 855 StatusController status;
856 ApplyBookmarkUpdates(&status); 856 ApplyBookmarkUpdates(&status);
857 857
858 const UpdateCounters& counters = GetBookmarksUpdateCounters(); 858 const UpdateCounters& counters = GetBookmarksUpdateCounters();
859 EXPECT_EQ(2, counters.num_hierarchy_conflict_application_failures) 859 EXPECT_EQ(2, counters.num_hierarchy_conflict_application_failures)
860 << "All updates with an unknown ancestors should be in conflict"; 860 << "All updates with an unknown ancestors should be in conflict";
861 EXPECT_EQ(0, counters.num_updates_applied) 861 EXPECT_EQ(0, counters.num_updates_applied)
862 << "No item with an unknown ancestor should be applied"; 862 << "No item with an unknown ancestor should be applied";
863 863
864 { 864 {
865 syncable::ReadTransaction trans(FROM_HERE, directory()); 865 syncable::ReadTransaction trans(FROM_HERE, directory());
(...skipping 19 matching lines...) Expand all
885 "first_known_item", DefaultBookmarkSpecifics(), root_server_id); 885 "first_known_item", DefaultBookmarkSpecifics(), root_server_id);
886 int64_t u2_handle = entry_factory()->CreateUnappliedNewItemWithParent( 886 int64_t u2_handle = entry_factory()->CreateUnappliedNewItemWithParent(
887 "second_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent"); 887 "second_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent");
888 int64_t k2_handle = entry_factory()->CreateUnappliedNewItemWithParent( 888 int64_t k2_handle = entry_factory()->CreateUnappliedNewItemWithParent(
889 "second_known_item", DefaultBookmarkSpecifics(), "first_known_item"); 889 "second_known_item", DefaultBookmarkSpecifics(), "first_known_item");
890 int64_t k3_handle = entry_factory()->CreateUnappliedNewItemWithParent( 890 int64_t k3_handle = entry_factory()->CreateUnappliedNewItemWithParent(
891 "third_known_item", DefaultBookmarkSpecifics(), "fourth_known_item"); 891 "third_known_item", DefaultBookmarkSpecifics(), "fourth_known_item");
892 int64_t k4_handle = entry_factory()->CreateUnappliedNewItemWithParent( 892 int64_t k4_handle = entry_factory()->CreateUnappliedNewItemWithParent(
893 "fourth_known_item", DefaultBookmarkSpecifics(), root_server_id); 893 "fourth_known_item", DefaultBookmarkSpecifics(), root_server_id);
894 894
895 sessions::StatusController status; 895 StatusController status;
896 ApplyBookmarkUpdates(&status); 896 ApplyBookmarkUpdates(&status);
897 897
898 const UpdateCounters& counters = GetBookmarksUpdateCounters(); 898 const UpdateCounters& counters = GetBookmarksUpdateCounters();
899 EXPECT_EQ(2, counters.num_hierarchy_conflict_application_failures) 899 EXPECT_EQ(2, counters.num_hierarchy_conflict_application_failures)
900 << "The updates with unknown ancestors should be in conflict"; 900 << "The updates with unknown ancestors should be in conflict";
901 EXPECT_EQ(4, counters.num_updates_applied) 901 EXPECT_EQ(4, counters.num_updates_applied)
902 << "The updates with known ancestors should be successfully applied"; 902 << "The updates with known ancestors should be successfully applied";
903 903
904 { 904 {
905 syncable::ReadTransaction trans(FROM_HERE, directory()); 905 syncable::ReadTransaction trans(FROM_HERE, directory());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 940
941 sync_pb::EntitySpecifics specifics; 941 sync_pb::EntitySpecifics specifics;
942 sync_pb::PasswordSpecificsData data; 942 sync_pb::PasswordSpecificsData data;
943 data.set_origin("http://example.com"); 943 data.set_origin("http://example.com");
944 944
945 cryptographer->Encrypt(data, 945 cryptographer->Encrypt(data,
946 specifics.mutable_password()->mutable_encrypted()); 946 specifics.mutable_password()->mutable_encrypted());
947 int64_t handle = 947 int64_t handle =
948 entry_factory()->CreateUnappliedNewItem("item", specifics, false); 948 entry_factory()->CreateUnappliedNewItem("item", specifics, false);
949 949
950 sessions::StatusController status; 950 StatusController status;
951 ApplyPasswordUpdates(&status); 951 ApplyPasswordUpdates(&status);
952 952
953 const UpdateCounters& counters = GetPasswordsUpdateCounters(); 953 const UpdateCounters& counters = GetPasswordsUpdateCounters();
954 EXPECT_EQ(1, counters.num_updates_applied) 954 EXPECT_EQ(1, counters.num_updates_applied)
955 << "The updates that can be decrypted should be applied"; 955 << "The updates that can be decrypted should be applied";
956 956
957 { 957 {
958 syncable::ReadTransaction trans(FROM_HERE, directory()); 958 syncable::ReadTransaction trans(FROM_HERE, directory());
959 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); 959 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle);
960 ASSERT_TRUE(e.good()); 960 ASSERT_TRUE(e.good());
(...skipping 11 matching lines...) Expand all
972 std::string root_server_id = Id::GetRoot().GetServerId(); 972 std::string root_server_id = Id::GetRoot().GetServerId();
973 int64_t folder_handle = entry_factory()->CreateUnappliedNewItemWithParent( 973 int64_t folder_handle = entry_factory()->CreateUnappliedNewItemWithParent(
974 "folder", encrypted_bookmark, root_server_id); 974 "folder", encrypted_bookmark, root_server_id);
975 int64_t bookmark_handle = entry_factory()->CreateUnappliedNewItem( 975 int64_t bookmark_handle = entry_factory()->CreateUnappliedNewItem(
976 "item2", encrypted_bookmark, false); 976 "item2", encrypted_bookmark, false);
977 sync_pb::EntitySpecifics encrypted_password; 977 sync_pb::EntitySpecifics encrypted_password;
978 encrypted_password.mutable_password(); 978 encrypted_password.mutable_password();
979 int64_t password_handle = entry_factory()->CreateUnappliedNewItem( 979 int64_t password_handle = entry_factory()->CreateUnappliedNewItem(
980 "item3", encrypted_password, false); 980 "item3", encrypted_password, false);
981 981
982 sessions::StatusController status; 982 StatusController status;
983 ApplyBookmarkUpdates(&status); 983 ApplyBookmarkUpdates(&status);
984 ApplyPasswordUpdates(&status); 984 ApplyPasswordUpdates(&status);
985 985
986 const UpdateCounters& bm_counters = GetBookmarksUpdateCounters(); 986 const UpdateCounters& bm_counters = GetBookmarksUpdateCounters();
987 EXPECT_EQ(2, bm_counters.num_encryption_conflict_application_failures) 987 EXPECT_EQ(2, bm_counters.num_encryption_conflict_application_failures)
988 << "Updates that can't be decrypted should be in encryption conflict"; 988 << "Updates that can't be decrypted should be in encryption conflict";
989 EXPECT_EQ(0, bm_counters.num_updates_applied) 989 EXPECT_EQ(0, bm_counters.num_updates_applied)
990 << "No update that can't be decrypted should be applied"; 990 << "No update that can't be decrypted should be applied";
991 991
992 const UpdateCounters& pw_counters = GetPasswordsUpdateCounters(); 992 const UpdateCounters& pw_counters = GetPasswordsUpdateCounters();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 KeyParams params = {"localhost", "dummy", "foobar"}; 1028 KeyParams params = {"localhost", "dummy", "foobar"};
1029 cryptographer->AddKey(params); 1029 cryptographer->AddKey(params);
1030 1030
1031 cryptographer->Encrypt(data, 1031 cryptographer->Encrypt(data,
1032 specifics.mutable_password()->mutable_encrypted()); 1032 specifics.mutable_password()->mutable_encrypted());
1033 } 1033 }
1034 decryptable_handle = 1034 decryptable_handle =
1035 entry_factory()->CreateUnappliedNewItem("item1", specifics, false); 1035 entry_factory()->CreateUnappliedNewItem("item1", specifics, false);
1036 } 1036 }
1037 { 1037 {
1038 // Create a new cryptographer, independent of the one in the session. 1038 // Create a new cryptographer, independent of the one in the cycle.
1039 Cryptographer other_cryptographer(cryptographer->encryptor()); 1039 Cryptographer other_cryptographer(cryptographer->encryptor());
1040 KeyParams params = {"localhost", "dummy", "bazqux"}; 1040 KeyParams params = {"localhost", "dummy", "bazqux"};
1041 other_cryptographer.AddKey(params); 1041 other_cryptographer.AddKey(params);
1042 1042
1043 sync_pb::EntitySpecifics specifics; 1043 sync_pb::EntitySpecifics specifics;
1044 sync_pb::PasswordSpecificsData data; 1044 sync_pb::PasswordSpecificsData data;
1045 data.set_origin("http://example.com/2"); 1045 data.set_origin("http://example.com/2");
1046 1046
1047 other_cryptographer.Encrypt( 1047 other_cryptographer.Encrypt(
1048 data, specifics.mutable_password()->mutable_encrypted()); 1048 data, specifics.mutable_password()->mutable_encrypted());
1049 undecryptable_handle = 1049 undecryptable_handle =
1050 entry_factory()->CreateUnappliedNewItem("item2", specifics, false); 1050 entry_factory()->CreateUnappliedNewItem("item2", specifics, false);
1051 } 1051 }
1052 1052
1053 sessions::StatusController status; 1053 StatusController status;
1054 ApplyPasswordUpdates(&status); 1054 ApplyPasswordUpdates(&status);
1055 1055
1056 const UpdateCounters& counters = GetPasswordsUpdateCounters(); 1056 const UpdateCounters& counters = GetPasswordsUpdateCounters();
1057 EXPECT_EQ(1, counters.num_encryption_conflict_application_failures) 1057 EXPECT_EQ(1, counters.num_encryption_conflict_application_failures)
1058 << "The updates that can't be decrypted should be in encryption " 1058 << "The updates that can't be decrypted should be in encryption "
1059 << "conflict"; 1059 << "conflict";
1060 EXPECT_EQ(1, counters.num_updates_applied) 1060 EXPECT_EQ(1, counters.num_updates_applied)
1061 << "The undecryptable password update shouldn't be applied"; 1061 << "The undecryptable password update shouldn't be applied";
1062 1062
1063 { 1063 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 sync_pb::AttachmentMetadataRecord* server_record = 1096 sync_pb::AttachmentMetadataRecord* server_record =
1097 server_metadata.add_record(); 1097 server_metadata.add_record();
1098 *server_record->mutable_id() = server_attachment_id; 1098 *server_record->mutable_id() = server_attachment_id;
1099 server_record->set_is_on_server(true); 1099 server_record->set_is_on_server(true);
1100 entry_factory()->SetServerAttachmentMetadataForItem(handle, server_metadata); 1100 entry_factory()->SetServerAttachmentMetadataForItem(handle, server_metadata);
1101 1101
1102 // At this point we have a simple conflict. The server says art1 should have 1102 // At this point we have a simple conflict. The server says art1 should have
1103 // server_attachment_id, but the local sync engine says it should have 1103 // server_attachment_id, but the local sync engine says it should have
1104 // local_attachment_id. 1104 // local_attachment_id.
1105 1105
1106 sessions::StatusController status; 1106 StatusController status;
1107 ApplyArticlesUpdates(&status); 1107 ApplyArticlesUpdates(&status);
1108 1108
1109 // See that the server won. 1109 // See that the server won.
1110 const UpdateCounters& counters = GetArticlesUpdateCounters(); 1110 const UpdateCounters& counters = GetArticlesUpdateCounters();
1111 EXPECT_EQ(1, counters.num_updates_applied); 1111 EXPECT_EQ(1, counters.num_updates_applied);
1112 EXPECT_EQ(1, counters.num_local_overwrites); 1112 EXPECT_EQ(1, counters.num_local_overwrites);
1113 EXPECT_EQ(0, counters.num_server_overwrites); 1113 EXPECT_EQ(0, counters.num_server_overwrites);
1114 local_metadata = entry_factory()->GetLocalAttachmentMetadataForItem(handle); 1114 local_metadata = entry_factory()->GetLocalAttachmentMetadataForItem(handle);
1115 EXPECT_EQ(server_metadata.SerializeAsString(), 1115 EXPECT_EQ(server_metadata.SerializeAsString(),
1116 local_metadata.SerializeAsString()); 1116 local_metadata.SerializeAsString());
(...skipping 25 matching lines...) Expand all
1142 record = server_metadata.add_record(); 1142 record = server_metadata.add_record();
1143 *record->mutable_id() = id2; 1143 *record->mutable_id() = id2;
1144 record->set_is_on_server(true); 1144 record->set_is_on_server(true);
1145 record = local_metadata.add_record(); 1145 record = local_metadata.add_record();
1146 *record->mutable_id() = id1; 1146 *record->mutable_id() = id1;
1147 record->set_is_on_server(true); 1147 record->set_is_on_server(true);
1148 entry_factory()->SetServerAttachmentMetadataForItem(handle, server_metadata); 1148 entry_factory()->SetServerAttachmentMetadataForItem(handle, server_metadata);
1149 1149
1150 // At this point we have a (false) conflict. 1150 // At this point we have a (false) conflict.
1151 1151
1152 sessions::StatusController status; 1152 StatusController status;
1153 ApplyArticlesUpdates(&status); 1153 ApplyArticlesUpdates(&status);
1154 1154
1155 // See that the server won. 1155 // See that the server won.
1156 const UpdateCounters& counters = GetArticlesUpdateCounters(); 1156 const UpdateCounters& counters = GetArticlesUpdateCounters();
1157 EXPECT_EQ(1, counters.num_updates_applied); 1157 EXPECT_EQ(1, counters.num_updates_applied);
1158 EXPECT_EQ(1, counters.num_local_overwrites); 1158 EXPECT_EQ(1, counters.num_local_overwrites);
1159 EXPECT_EQ(0, counters.num_server_overwrites); 1159 EXPECT_EQ(0, counters.num_server_overwrites);
1160 local_metadata = entry_factory()->GetLocalAttachmentMetadataForItem(handle); 1160 local_metadata = entry_factory()->GetLocalAttachmentMetadataForItem(handle);
1161 EXPECT_EQ(server_metadata.SerializeAsString(), 1161 EXPECT_EQ(server_metadata.SerializeAsString(),
1162 local_metadata.SerializeAsString()); 1162 local_metadata.SerializeAsString());
1163 } 1163 }
1164 1164
1165 } // namespace syncer 1165 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/engine_impl/directory_update_handler.cc ('k') | components/sync/engine_impl/get_commit_ids.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698