| 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_commit_contribution.h" | 5 #include "components/sync/engine_impl/directory_commit_contribution.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "sync/internal_api/public/base/attachment_id_proto.h" | 13 #include "components/sync/base/attachment_id_proto.h" |
| 14 #include "sync/sessions/status_controller.h" | 14 #include "components/sync/sessions_impl/status_controller.h" |
| 15 #include "sync/syncable/entry.h" | 15 #include "components/sync/syncable/entry.h" |
| 16 #include "sync/syncable/mutable_entry.h" | 16 #include "components/sync/syncable/mutable_entry.h" |
| 17 #include "sync/syncable/syncable_read_transaction.h" | 17 #include "components/sync/syncable/syncable_read_transaction.h" |
| 18 #include "sync/syncable/syncable_write_transaction.h" | 18 #include "components/sync/syncable/syncable_write_transaction.h" |
| 19 #include "sync/test/engine/test_directory_setter_upper.h" | 19 #include "components/sync/test/engine/test_directory_setter_upper.h" |
| 20 #include "sync/test/engine/test_id_factory.h" | 20 #include "components/sync/test/engine/test_id_factory.h" |
| 21 #include "sync/test/engine/test_syncable_utils.h" | 21 #include "components/sync/test/engine/test_syncable_utils.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 namespace syncer { | 24 namespace syncer { |
| 25 | 25 |
| 26 class DirectoryCommitContributionTest : public ::testing::Test { | 26 class DirectoryCommitContributionTest : public ::testing::Test { |
| 27 public: | 27 public: |
| 28 void SetUp() override { | 28 void SetUp() override { |
| 29 dir_maker_.SetUp(); | 29 dir_maker_.SetUp(); |
| 30 | 30 |
| 31 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); | 31 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 55 if (attachment_metadata.record_size() > 0) { | 55 if (attachment_metadata.record_size() > 0) { |
| 56 entry.PutAttachmentMetadata(attachment_metadata); | 56 entry.PutAttachmentMetadata(attachment_metadata); |
| 57 } | 57 } |
| 58 entry.PutIsUnsynced(true); | 58 entry.PutIsUnsynced(true); |
| 59 return entry.GetMetahandle(); | 59 return entry.GetMetahandle(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 int64_t CreateUnsyncedItem(syncable::WriteTransaction* trans, | 62 int64_t CreateUnsyncedItem(syncable::WriteTransaction* trans, |
| 63 ModelType type, | 63 ModelType type, |
| 64 const std::string& tag) { | 64 const std::string& tag) { |
| 65 return CreateUnsyncedItemWithAttachments( | 65 return CreateUnsyncedItemWithAttachments(trans, type, tag, |
| 66 trans, type, tag, sync_pb::AttachmentMetadata()); | 66 sync_pb::AttachmentMetadata()); |
| 67 } | 67 } |
| 68 | 68 |
| 69 int64_t CreateSyncedItem(syncable::WriteTransaction* trans, | 69 int64_t CreateSyncedItem(syncable::WriteTransaction* trans, |
| 70 ModelType type, | 70 ModelType type, |
| 71 const std::string& tag) { | 71 const std::string& tag) { |
| 72 syncable::Entry parent_entry(trans, syncable::GET_TYPE_ROOT, type); | 72 syncable::Entry parent_entry(trans, syncable::GET_TYPE_ROOT, type); |
| 73 syncable::MutableEntry entry( | 73 syncable::MutableEntry entry(trans, syncable::CREATE, type, |
| 74 trans, | 74 parent_entry.GetId(), tag); |
| 75 syncable::CREATE, | |
| 76 type, | |
| 77 parent_entry.GetId(), | |
| 78 tag); | |
| 79 | 75 |
| 80 entry.PutId(syncable::Id::CreateFromServerId( | 76 entry.PutId(syncable::Id::CreateFromServerId( |
| 81 id_factory_.NewServerId().GetServerId())); | 77 id_factory_.NewServerId().GetServerId())); |
| 82 entry.PutBaseVersion(10); | 78 entry.PutBaseVersion(10); |
| 83 entry.PutServerVersion(10); | 79 entry.PutServerVersion(10); |
| 84 entry.PutIsUnappliedUpdate(false); | 80 entry.PutIsUnappliedUpdate(false); |
| 85 entry.PutIsUnsynced(false); | 81 entry.PutIsUnsynced(false); |
| 86 entry.PutIsDel(false); | 82 entry.PutIsDel(false); |
| 87 entry.PutServerIsDel(false); | 83 entry.PutServerIsDel(false); |
| 88 | 84 |
| 89 return entry.GetMetahandle(); | 85 return entry.GetMetahandle(); |
| 90 } | 86 } |
| 91 | 87 |
| 92 void CreateSuccessfulCommitResponse( | 88 void CreateSuccessfulCommitResponse( |
| 93 const sync_pb::SyncEntity& entity, | 89 const sync_pb::SyncEntity& entity, |
| 94 sync_pb::CommitResponse::EntryResponse* response) { | 90 sync_pb::CommitResponse::EntryResponse* response) { |
| 95 response->set_response_type(sync_pb::CommitResponse::SUCCESS); | 91 response->set_response_type(sync_pb::CommitResponse::SUCCESS); |
| 96 response->set_non_unique_name(entity.name()); | 92 response->set_non_unique_name(entity.name()); |
| 97 response->set_version(entity.version() + 1); | 93 response->set_version(entity.version() + 1); |
| 98 response->set_parent_id_string(entity.parent_id_string()); | 94 response->set_parent_id_string(entity.parent_id_string()); |
| 99 | 95 |
| 100 if (entity.id_string()[0] == '-') // Look for the - in 'c-1234' style IDs. | 96 if (entity.id_string()[0] == '-') // Look for the - in 'c-1234' style IDs. |
| 101 response->set_id_string(id_factory_.NewServerId().GetServerId()); | 97 response->set_id_string(id_factory_.NewServerId().GetServerId()); |
| 102 else | 98 else |
| 103 response->set_id_string(entity.id_string()); | 99 response->set_id_string(entity.id_string()); |
| 104 } | 100 } |
| 105 | 101 |
| 106 syncable::Directory* dir() { | 102 syncable::Directory* dir() { return dir_maker_.directory(); } |
| 107 return dir_maker_.directory(); | |
| 108 } | |
| 109 | 103 |
| 110 TestIdFactory id_factory_; | 104 TestIdFactory id_factory_; |
| 111 | 105 |
| 112 // Used in construction of DirectoryTypeDebugInfoEmitters. | 106 // Used in construction of DirectoryTypeDebugInfoEmitters. |
| 113 base::ObserverList<TypeDebugInfoObserver> type_observers_; | 107 base::ObserverList<TypeDebugInfoObserver> type_observers_; |
| 114 | 108 |
| 115 private: | 109 private: |
| 116 base::MessageLoop loop_; // Neeed to initialize the directory. | 110 base::MessageLoop loop_; // Neeed to initialize the directory. |
| 117 TestDirectorySetterUpper dir_maker_; | 111 TestDirectorySetterUpper dir_maker_; |
| 118 }; | 112 }; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 184 |
| 191 const sync_pb::CommitMessage& commit_message = message.commit(); | 185 const sync_pb::CommitMessage& commit_message = message.commit(); |
| 192 | 186 |
| 193 std::set<syncable::Id> ids_for_commit; | 187 std::set<syncable::Id> ids_for_commit; |
| 194 ASSERT_EQ(3, commit_message.entries_size()); | 188 ASSERT_EQ(3, commit_message.entries_size()); |
| 195 for (int i = 0; i < commit_message.entries_size(); ++i) { | 189 for (int i = 0; i < commit_message.entries_size(); ++i) { |
| 196 const sync_pb::SyncEntity& entity = commit_message.entries(i); | 190 const sync_pb::SyncEntity& entity = commit_message.entries(i); |
| 197 // The entities in this test have client-style IDs since they've never been | 191 // The entities in this test have client-style IDs since they've never been |
| 198 // committed before, so we must use CreateFromClientString to re-create them | 192 // committed before, so we must use CreateFromClientString to re-create them |
| 199 // from the commit message. | 193 // from the commit message. |
| 200 ids_for_commit.insert(syncable::Id::CreateFromClientString( | 194 ids_for_commit.insert( |
| 201 entity.id_string())); | 195 syncable::Id::CreateFromClientString(entity.id_string())); |
| 202 } | 196 } |
| 203 | 197 |
| 204 ASSERT_EQ(3U, ids_for_commit.size()); | 198 ASSERT_EQ(3U, ids_for_commit.size()); |
| 205 { | 199 { |
| 206 syncable::ReadTransaction trans(FROM_HERE, dir()); | 200 syncable::ReadTransaction trans(FROM_HERE, dir()); |
| 207 for (std::set<syncable::Id>::iterator it = ids_for_commit.begin(); | 201 for (std::set<syncable::Id>::iterator it = ids_for_commit.begin(); |
| 208 it != ids_for_commit.end(); ++it) { | 202 it != ids_for_commit.end(); ++it) { |
| 209 SCOPED_TRACE(it->value()); | 203 SCOPED_TRACE(it->value()); |
| 210 syncable::Entry entry(&trans, syncable::GET_BY_ID, *it); | 204 syncable::Entry entry(&trans, syncable::GET_BY_ID, *it); |
| 211 ASSERT_TRUE(entry.good()); | 205 ASSERT_TRUE(entry.good()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 234 DirectoryTypeDebugInfoEmitter emitter(PREFERENCES, &type_observers_); | 228 DirectoryTypeDebugInfoEmitter emitter(PREFERENCES, &type_observers_); |
| 235 std::unique_ptr<DirectoryCommitContribution> pref_cc( | 229 std::unique_ptr<DirectoryCommitContribution> pref_cc( |
| 236 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25, &emitter)); | 230 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25, &emitter)); |
| 237 ASSERT_TRUE(pref_cc); | 231 ASSERT_TRUE(pref_cc); |
| 238 | 232 |
| 239 sync_pb::ClientToServerMessage message; | 233 sync_pb::ClientToServerMessage message; |
| 240 pref_cc->AddToCommitMessage(&message); | 234 pref_cc->AddToCommitMessage(&message); |
| 241 | 235 |
| 242 const sync_pb::CommitMessage& commit_message = message.commit(); | 236 const sync_pb::CommitMessage& commit_message = message.commit(); |
| 243 ASSERT_EQ(1, commit_message.entries_size()); | 237 ASSERT_EQ(1, commit_message.entries_size()); |
| 244 EXPECT_TRUE( | 238 EXPECT_TRUE(commit_message.entries(0).specifics().has_preference()); |
| 245 commit_message.entries(0).specifics().has_preference()); | |
| 246 | 239 |
| 247 pref_cc->CleanUp(); | 240 pref_cc->CleanUp(); |
| 248 } | 241 } |
| 249 | 242 |
| 250 // As ususal, bookmarks are special. Bookmark deletion is special. | 243 // As ususal, bookmarks are special. Bookmark deletion is special. |
| 251 // Deleted bookmarks include a valid "is folder" bit and their full specifics | 244 // Deleted bookmarks include a valid "is folder" bit and their full specifics |
| 252 // (especially the meta info, which is what server really wants). | 245 // (especially the meta info, which is what server really wants). |
| 253 TEST_F(DirectoryCommitContributionTest, DeletedBookmarksWithSpecifics) { | 246 TEST_F(DirectoryCommitContributionTest, DeletedBookmarksWithSpecifics) { |
| 254 int64_t bm1; | 247 int64_t bm1; |
| 255 { | 248 { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 int64_t art2_handle; | 430 int64_t art2_handle; |
| 438 int64_t art3_handle; | 431 int64_t art3_handle; |
| 439 { | 432 { |
| 440 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); | 433 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); |
| 441 | 434 |
| 442 // art1 has two attachments, both have been uploaded to the server. art1 is | 435 // art1 has two attachments, both have been uploaded to the server. art1 is |
| 443 // eligible to be committed. | 436 // eligible to be committed. |
| 444 sync_pb::AttachmentMetadata art1_attachments; | 437 sync_pb::AttachmentMetadata art1_attachments; |
| 445 AddAttachment(&art1_attachments, true /* is_on_server */); | 438 AddAttachment(&art1_attachments, true /* is_on_server */); |
| 446 AddAttachment(&art1_attachments, true /* is_on_server */); | 439 AddAttachment(&art1_attachments, true /* is_on_server */); |
| 447 art1_handle = CreateUnsyncedItemWithAttachments( | 440 art1_handle = CreateUnsyncedItemWithAttachments(&trans, ARTICLES, "art1", |
| 448 &trans, ARTICLES, "art1", art1_attachments); | 441 art1_attachments); |
| 449 | 442 |
| 450 // art2 has two attachments, one of which has been uploaded to the | 443 // art2 has two attachments, one of which has been uploaded to the |
| 451 // server. art2 is not eligible to be committed. | 444 // server. art2 is not eligible to be committed. |
| 452 sync_pb::AttachmentMetadata art2_attachments; | 445 sync_pb::AttachmentMetadata art2_attachments; |
| 453 AddAttachment(&art2_attachments, false /* is_on_server */); | 446 AddAttachment(&art2_attachments, false /* is_on_server */); |
| 454 AddAttachment(&art2_attachments, true /* is_on_server */); | 447 AddAttachment(&art2_attachments, true /* is_on_server */); |
| 455 art2_handle = CreateUnsyncedItemWithAttachments( | 448 art2_handle = CreateUnsyncedItemWithAttachments(&trans, ARTICLES, "art2", |
| 456 &trans, ARTICLES, "art2", art2_attachments); | 449 art2_attachments); |
| 457 | 450 |
| 458 // art3 has two attachments, neither of which have been uploaded to the | 451 // art3 has two attachments, neither of which have been uploaded to the |
| 459 // server. art2 is not eligible to be committed. | 452 // server. art2 is not eligible to be committed. |
| 460 sync_pb::AttachmentMetadata art3_attachments; | 453 sync_pb::AttachmentMetadata art3_attachments; |
| 461 AddAttachment(&art3_attachments, false /* is_on_server */); | 454 AddAttachment(&art3_attachments, false /* is_on_server */); |
| 462 AddAttachment(&art3_attachments, false /* is_on_server */); | 455 AddAttachment(&art3_attachments, false /* is_on_server */); |
| 463 art3_handle = CreateUnsyncedItemWithAttachments( | 456 art3_handle = CreateUnsyncedItemWithAttachments(&trans, ARTICLES, "art3", |
| 464 &trans, ARTICLES, "art3", art3_attachments); | 457 art3_attachments); |
| 465 } | 458 } |
| 466 | 459 |
| 467 DirectoryTypeDebugInfoEmitter emitter(ARTICLES, &type_observers_); | 460 DirectoryTypeDebugInfoEmitter emitter(ARTICLES, &type_observers_); |
| 468 std::unique_ptr<DirectoryCommitContribution> art_cc( | 461 std::unique_ptr<DirectoryCommitContribution> art_cc( |
| 469 DirectoryCommitContribution::Build(dir(), ARTICLES, 25, &emitter)); | 462 DirectoryCommitContribution::Build(dir(), ARTICLES, 25, &emitter)); |
| 470 | 463 |
| 471 // Only art1 is ready. | 464 // Only art1 is ready. |
| 472 EXPECT_EQ(1U, art_cc->GetNumEntries()); | 465 EXPECT_EQ(1U, art_cc->GetNumEntries()); |
| 473 | 466 |
| 474 sync_pb::ClientToServerMessage message; | 467 sync_pb::ClientToServerMessage message; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 EXPECT_FALSE(a3.GetId().ServerKnows()); | 499 EXPECT_FALSE(a3.GetId().ServerKnows()); |
| 507 EXPECT_FALSE(a3.GetSyncing()); | 500 EXPECT_FALSE(a3.GetSyncing()); |
| 508 EXPECT_FALSE(a3.GetDirtySync()); | 501 EXPECT_FALSE(a3.GetDirtySync()); |
| 509 EXPECT_EQ(0, a3.GetServerVersion()); | 502 EXPECT_EQ(0, a3.GetServerVersion()); |
| 510 } | 503 } |
| 511 | 504 |
| 512 art_cc->CleanUp(); | 505 art_cc->CleanUp(); |
| 513 } | 506 } |
| 514 | 507 |
| 515 } // namespace syncer | 508 } // namespace syncer |
| OLD | NEW |