| 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 "sync/engine/directory_commit_contribution.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "sync/sessions/status_controller.h" | 8 #include "sync/sessions/status_controller.h" |
| 9 #include "sync/syncable/entry.h" | 9 #include "sync/syncable/entry.h" |
| 10 #include "sync/syncable/mutable_entry.h" | 10 #include "sync/syncable/mutable_entry.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // specified type. | 78 // specified type. |
| 79 TEST_F(DirectoryCommitContributionTest, GatherByTypes) { | 79 TEST_F(DirectoryCommitContributionTest, GatherByTypes) { |
| 80 int64 pref1; | 80 int64 pref1; |
| 81 { | 81 { |
| 82 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); | 82 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); |
| 83 pref1 = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); | 83 pref1 = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); |
| 84 CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); | 84 CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); |
| 85 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); | 85 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); |
| 86 } | 86 } |
| 87 | 87 |
| 88 DirectoryTypeDebugInfoEmitter emitter; |
| 88 scoped_ptr<DirectoryCommitContribution> cc( | 89 scoped_ptr<DirectoryCommitContribution> cc( |
| 89 DirectoryCommitContribution::Build(dir(), PREFERENCES, 5)); | 90 DirectoryCommitContribution::Build(dir(), PREFERENCES, 5, &emitter)); |
| 90 ASSERT_EQ(2U, cc->GetNumEntries()); | 91 ASSERT_EQ(2U, cc->GetNumEntries()); |
| 91 | 92 |
| 92 const std::vector<int64>& metahandles = cc->metahandles_; | 93 const std::vector<int64>& metahandles = cc->metahandles_; |
| 93 EXPECT_TRUE(std::find(metahandles.begin(), metahandles.end(), pref1) != | 94 EXPECT_TRUE(std::find(metahandles.begin(), metahandles.end(), pref1) != |
| 94 metahandles.end()); | 95 metahandles.end()); |
| 95 EXPECT_TRUE(std::find(metahandles.begin(), metahandles.end(), pref1) != | 96 EXPECT_TRUE(std::find(metahandles.begin(), metahandles.end(), pref1) != |
| 96 metahandles.end()); | 97 metahandles.end()); |
| 97 | 98 |
| 98 cc->CleanUp(); | 99 cc->CleanUp(); |
| 99 } | 100 } |
| 100 | 101 |
| 101 // Verify that the DirectoryCommitContributionTest builder function | 102 // Verify that the DirectoryCommitContributionTest builder function |
| 102 // truncates if necessary. | 103 // truncates if necessary. |
| 103 TEST_F(DirectoryCommitContributionTest, GatherAndTruncate) { | 104 TEST_F(DirectoryCommitContributionTest, GatherAndTruncate) { |
| 104 int64 pref1; | 105 int64 pref1; |
| 105 int64 pref2; | 106 int64 pref2; |
| 106 { | 107 { |
| 107 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); | 108 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); |
| 108 pref1 = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); | 109 pref1 = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); |
| 109 pref2 = CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); | 110 pref2 = CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); |
| 110 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); | 111 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); |
| 111 } | 112 } |
| 112 | 113 |
| 114 DirectoryTypeDebugInfoEmitter emitter; |
| 113 scoped_ptr<DirectoryCommitContribution> cc( | 115 scoped_ptr<DirectoryCommitContribution> cc( |
| 114 DirectoryCommitContribution::Build(dir(), PREFERENCES, 1)); | 116 DirectoryCommitContribution::Build(dir(), PREFERENCES, 1, &emitter)); |
| 115 ASSERT_EQ(1U, cc->GetNumEntries()); | 117 ASSERT_EQ(1U, cc->GetNumEntries()); |
| 116 | 118 |
| 117 int64 only_metahandle = cc->metahandles_[0]; | 119 int64 only_metahandle = cc->metahandles_[0]; |
| 118 EXPECT_TRUE(only_metahandle == pref1 || only_metahandle == pref2); | 120 EXPECT_TRUE(only_metahandle == pref1 || only_metahandle == pref2); |
| 119 | 121 |
| 120 cc->CleanUp(); | 122 cc->CleanUp(); |
| 121 } | 123 } |
| 122 | 124 |
| 123 // Sanity check for building commits from DirectoryCommitContributions. | 125 // Sanity check for building commits from DirectoryCommitContributions. |
| 124 // This test makes two CommitContribution objects of different types and uses | 126 // This test makes two CommitContribution objects of different types and uses |
| 125 // them to initialize a commit message. Then it checks that the contents of the | 127 // them to initialize a commit message. Then it checks that the contents of the |
| 126 // commit message match those of the directory they came from. | 128 // commit message match those of the directory they came from. |
| 127 TEST_F(DirectoryCommitContributionTest, PrepareCommit) { | 129 TEST_F(DirectoryCommitContributionTest, PrepareCommit) { |
| 128 { | 130 { |
| 129 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); | 131 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); |
| 130 CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); | 132 CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); |
| 131 CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); | 133 CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); |
| 132 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); | 134 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); |
| 133 } | 135 } |
| 134 | 136 |
| 137 DirectoryTypeDebugInfoEmitter emitter1; |
| 138 DirectoryTypeDebugInfoEmitter emitter2; |
| 135 scoped_ptr<DirectoryCommitContribution> pref_cc( | 139 scoped_ptr<DirectoryCommitContribution> pref_cc( |
| 136 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25)); | 140 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25, &emitter1)); |
| 137 scoped_ptr<DirectoryCommitContribution> ext_cc( | 141 scoped_ptr<DirectoryCommitContribution> ext_cc( |
| 138 DirectoryCommitContribution::Build(dir(), EXTENSIONS, 25)); | 142 DirectoryCommitContribution::Build(dir(), EXTENSIONS, 25, &emitter2)); |
| 139 | 143 |
| 140 sync_pb::ClientToServerMessage message; | 144 sync_pb::ClientToServerMessage message; |
| 141 pref_cc->AddToCommitMessage(&message); | 145 pref_cc->AddToCommitMessage(&message); |
| 142 ext_cc->AddToCommitMessage(&message); | 146 ext_cc->AddToCommitMessage(&message); |
| 143 | 147 |
| 144 const sync_pb::CommitMessage& commit_message = message.commit(); | 148 const sync_pb::CommitMessage& commit_message = message.commit(); |
| 145 | 149 |
| 146 std::set<syncable::Id> ids_for_commit; | 150 std::set<syncable::Id> ids_for_commit; |
| 147 ASSERT_EQ(3, commit_message.entries_size()); | 151 ASSERT_EQ(3, commit_message.entries_size()); |
| 148 for (int i = 0; i < commit_message.entries_size(); ++i) { | 152 for (int i = 0; i < commit_message.entries_size(); ++i) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 177 int64 pref1_handle; | 181 int64 pref1_handle; |
| 178 int64 pref2_handle; | 182 int64 pref2_handle; |
| 179 int64 ext1_handle; | 183 int64 ext1_handle; |
| 180 { | 184 { |
| 181 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); | 185 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); |
| 182 pref1_handle = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); | 186 pref1_handle = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); |
| 183 pref2_handle = CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); | 187 pref2_handle = CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); |
| 184 ext1_handle = CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); | 188 ext1_handle = CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); |
| 185 } | 189 } |
| 186 | 190 |
| 191 DirectoryTypeDebugInfoEmitter emitter1; |
| 192 DirectoryTypeDebugInfoEmitter emitter2; |
| 187 scoped_ptr<DirectoryCommitContribution> pref_cc( | 193 scoped_ptr<DirectoryCommitContribution> pref_cc( |
| 188 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25)); | 194 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25, &emitter1)); |
| 189 scoped_ptr<DirectoryCommitContribution> ext_cc( | 195 scoped_ptr<DirectoryCommitContribution> ext_cc( |
| 190 DirectoryCommitContribution::Build(dir(), EXTENSIONS, 25)); | 196 DirectoryCommitContribution::Build(dir(), EXTENSIONS, 25, &emitter2)); |
| 191 | 197 |
| 192 sync_pb::ClientToServerMessage message; | 198 sync_pb::ClientToServerMessage message; |
| 193 pref_cc->AddToCommitMessage(&message); | 199 pref_cc->AddToCommitMessage(&message); |
| 194 ext_cc->AddToCommitMessage(&message); | 200 ext_cc->AddToCommitMessage(&message); |
| 195 | 201 |
| 196 const sync_pb::CommitMessage& commit_message = message.commit(); | 202 const sync_pb::CommitMessage& commit_message = message.commit(); |
| 197 ASSERT_EQ(3, commit_message.entries_size()); | 203 ASSERT_EQ(3, commit_message.entries_size()); |
| 198 | 204 |
| 199 sync_pb::ClientToServerResponse response; | 205 sync_pb::ClientToServerResponse response; |
| 200 for (int i = 0; i < commit_message.entries_size(); ++i) { | 206 for (int i = 0; i < commit_message.entries_size(); ++i) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 226 EXPECT_TRUE(e1.GetId().ServerKnows()); | 232 EXPECT_TRUE(e1.GetId().ServerKnows()); |
| 227 EXPECT_FALSE(e1.GetSyncing()); | 233 EXPECT_FALSE(e1.GetSyncing()); |
| 228 EXPECT_LT(0, e1.GetServerVersion()); | 234 EXPECT_LT(0, e1.GetServerVersion()); |
| 229 } | 235 } |
| 230 | 236 |
| 231 pref_cc->CleanUp(); | 237 pref_cc->CleanUp(); |
| 232 ext_cc->CleanUp(); | 238 ext_cc->CleanUp(); |
| 233 } | 239 } |
| 234 | 240 |
| 235 } // namespace syncer | 241 } // namespace syncer |
| OLD | NEW |