OLD | NEW |
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" |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10); | 394 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10); |
395 | 395 |
396 sync_pb::DataTypeContext context; | 396 sync_pb::DataTypeContext context; |
397 context.set_data_type_id(GetSpecificsFieldNumberFromModelType(ARTICLES)); | 397 context.set_data_type_id(GetSpecificsFieldNumberFromModelType(ARTICLES)); |
398 context.set_context("context"); | 398 context.set_context("context"); |
399 context.set_version(1); | 399 context.set_version(1); |
400 | 400 |
401 scoped_ptr<sync_pb::SyncEntity> e1 = CreateUpdate( | 401 scoped_ptr<sync_pb::SyncEntity> e1 = CreateUpdate( |
402 SyncableIdToProto(Id::CreateFromServerId("e1")), "", ARTICLES); | 402 SyncableIdToProto(Id::CreateFromServerId("e1")), "", ARTICLES); |
403 sync_pb::AttachmentIdProto* attachment_id = e1->add_attachment_id(); | 403 sync_pb::AttachmentIdProto* attachment_id = e1->add_attachment_id(); |
404 *attachment_id = CreateAttachmentIdProto(); | 404 *attachment_id = CreateAttachmentIdProto(0, 0); |
405 | 405 |
406 SyncEntityList updates; | 406 SyncEntityList updates; |
407 updates.push_back(e1.get()); | 407 updates.push_back(e1.get()); |
408 | 408 |
409 // Process and apply updates. | 409 // Process and apply updates. |
410 EXPECT_EQ( | 410 EXPECT_EQ( |
411 SYNCER_OK, | 411 SYNCER_OK, |
412 handler.ProcessGetUpdatesResponse(progress, context, updates, &status)); | 412 handler.ProcessGetUpdatesResponse(progress, context, updates, &status)); |
413 handler.ApplyUpdates(&status); | 413 handler.ApplyUpdates(&status); |
414 | 414 |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 } | 1073 } |
1074 } | 1074 } |
1075 | 1075 |
1076 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, | 1076 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, |
1077 SimpleConflictDifferentAttachmentMetadata) { | 1077 SimpleConflictDifferentAttachmentMetadata) { |
1078 const bool is_folder = false; | 1078 const bool is_folder = false; |
1079 sync_pb::EntitySpecifics specifics; | 1079 sync_pb::EntitySpecifics specifics; |
1080 *specifics.mutable_article() = sync_pb::ArticleSpecifics(); | 1080 *specifics.mutable_article() = sync_pb::ArticleSpecifics(); |
1081 int64 handle = entry_factory()->CreateSyncedItem("art1", ARTICLES, is_folder); | 1081 int64 handle = entry_factory()->CreateSyncedItem("art1", ARTICLES, is_folder); |
1082 | 1082 |
1083 sync_pb::AttachmentIdProto local_attachment_id = CreateAttachmentIdProto(); | 1083 sync_pb::AttachmentIdProto local_attachment_id = |
1084 sync_pb::AttachmentIdProto server_attachment_id = CreateAttachmentIdProto(); | 1084 CreateAttachmentIdProto(0, 0); |
| 1085 sync_pb::AttachmentIdProto server_attachment_id = |
| 1086 CreateAttachmentIdProto(0, 0); |
1085 | 1087 |
1086 // Add an attachment to the local attachment metadata. | 1088 // Add an attachment to the local attachment metadata. |
1087 sync_pb::AttachmentMetadata local_metadata; | 1089 sync_pb::AttachmentMetadata local_metadata; |
1088 sync_pb::AttachmentMetadataRecord* local_record = local_metadata.add_record(); | 1090 sync_pb::AttachmentMetadataRecord* local_record = local_metadata.add_record(); |
1089 *local_record->mutable_id() = local_attachment_id; | 1091 *local_record->mutable_id() = local_attachment_id; |
1090 local_record->set_is_on_server(true); | 1092 local_record->set_is_on_server(true); |
1091 entry_factory()->SetLocalAttachmentMetadataForItem(handle, local_metadata); | 1093 entry_factory()->SetLocalAttachmentMetadataForItem(handle, local_metadata); |
1092 | 1094 |
1093 // Add a different attachment to the server attachment metadata. | 1095 // Add a different attachment to the server attachment metadata. |
1094 sync_pb::AttachmentMetadata server_metadata; | 1096 sync_pb::AttachmentMetadata server_metadata; |
(...skipping 20 matching lines...) Expand all Loading... |
1115 local_metadata.SerializeAsString()); | 1117 local_metadata.SerializeAsString()); |
1116 } | 1118 } |
1117 | 1119 |
1118 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, | 1120 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, |
1119 SimpleConflictSameAttachmentMetadataDifferentOrder) { | 1121 SimpleConflictSameAttachmentMetadataDifferentOrder) { |
1120 const bool is_folder = false; | 1122 const bool is_folder = false; |
1121 sync_pb::EntitySpecifics specifics; | 1123 sync_pb::EntitySpecifics specifics; |
1122 *specifics.mutable_article() = sync_pb::ArticleSpecifics(); | 1124 *specifics.mutable_article() = sync_pb::ArticleSpecifics(); |
1123 int64 handle = entry_factory()->CreateSyncedItem("art1", ARTICLES, is_folder); | 1125 int64 handle = entry_factory()->CreateSyncedItem("art1", ARTICLES, is_folder); |
1124 | 1126 |
1125 sync_pb::AttachmentIdProto id1 = CreateAttachmentIdProto(); | 1127 sync_pb::AttachmentIdProto id1 = CreateAttachmentIdProto(0, 0); |
1126 sync_pb::AttachmentIdProto id2 = CreateAttachmentIdProto(); | 1128 sync_pb::AttachmentIdProto id2 = CreateAttachmentIdProto(0, 0); |
1127 | 1129 |
1128 // Add id1, then id2 to the local attachment metadata. | 1130 // Add id1, then id2 to the local attachment metadata. |
1129 sync_pb::AttachmentMetadata local_metadata; | 1131 sync_pb::AttachmentMetadata local_metadata; |
1130 sync_pb::AttachmentMetadataRecord* record = local_metadata.add_record(); | 1132 sync_pb::AttachmentMetadataRecord* record = local_metadata.add_record(); |
1131 *record->mutable_id() = id1; | 1133 *record->mutable_id() = id1; |
1132 record->set_is_on_server(true); | 1134 record->set_is_on_server(true); |
1133 record = local_metadata.add_record(); | 1135 record = local_metadata.add_record(); |
1134 *record->mutable_id() = id2; | 1136 *record->mutable_id() = id2; |
1135 record->set_is_on_server(true); | 1137 record->set_is_on_server(true); |
1136 entry_factory()->SetLocalAttachmentMetadataForItem(handle, local_metadata); | 1138 entry_factory()->SetLocalAttachmentMetadataForItem(handle, local_metadata); |
(...skipping 17 matching lines...) Expand all Loading... |
1154 const UpdateCounters& counters = GetArticlesUpdateCounters(); | 1156 const UpdateCounters& counters = GetArticlesUpdateCounters(); |
1155 EXPECT_EQ(1, counters.num_updates_applied); | 1157 EXPECT_EQ(1, counters.num_updates_applied); |
1156 EXPECT_EQ(1, counters.num_local_overwrites); | 1158 EXPECT_EQ(1, counters.num_local_overwrites); |
1157 EXPECT_EQ(0, counters.num_server_overwrites); | 1159 EXPECT_EQ(0, counters.num_server_overwrites); |
1158 local_metadata = entry_factory()->GetLocalAttachmentMetadataForItem(handle); | 1160 local_metadata = entry_factory()->GetLocalAttachmentMetadataForItem(handle); |
1159 EXPECT_EQ(server_metadata.SerializeAsString(), | 1161 EXPECT_EQ(server_metadata.SerializeAsString(), |
1160 local_metadata.SerializeAsString()); | 1162 local_metadata.SerializeAsString()); |
1161 } | 1163 } |
1162 | 1164 |
1163 } // namespace syncer | 1165 } // namespace syncer |
OLD | NEW |