OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 // Syncer unit tests. Unfortunately a lot of these tests | 5 // Syncer unit tests. Unfortunately a lot of these tests |
6 // are outdated and need to be reworked and updated. | 6 // are outdated and need to be reworked and updated. |
7 | 7 |
8 #include "components/sync/engine_impl/syncer.h" | 8 #include "components/sync/engine_impl/syncer.h" |
9 | 9 |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 using std::count; | 71 using std::count; |
72 using std::map; | 72 using std::map; |
73 using std::multimap; | 73 using std::multimap; |
74 using std::set; | 74 using std::set; |
75 using std::string; | 75 using std::string; |
76 using std::vector; | 76 using std::vector; |
77 | 77 |
78 namespace syncer { | 78 namespace syncer { |
79 | 79 |
80 using syncable::BaseTransaction; | 80 using syncer::syncable::BaseTransaction; |
81 using syncable::CountEntriesWithName; | 81 using syncer::syncable::CountEntriesWithName; |
82 using syncable::Directory; | 82 using syncer::syncable::Directory; |
83 using syncable::Entry; | 83 using syncer::syncable::Entry; |
84 using syncable::GetFirstEntryWithName; | 84 using syncer::syncable::GetFirstEntryWithName; |
85 using syncable::GetOnlyEntryWithName; | 85 using syncer::syncable::GetOnlyEntryWithName; |
86 using syncable::Id; | 86 using syncer::syncable::Id; |
87 using syncable::kEncryptedString; | 87 using syncer::syncable::kEncryptedString; |
88 using syncable::MutableEntry; | 88 using syncer::syncable::MutableEntry; |
89 using syncable::WriteTransaction; | 89 using syncer::syncable::WriteTransaction; |
90 | 90 |
91 using syncable::CREATE; | 91 using syncer::syncable::CREATE; |
92 using syncable::GET_BY_HANDLE; | 92 using syncer::syncable::GET_BY_HANDLE; |
93 using syncable::GET_BY_ID; | 93 using syncer::syncable::GET_BY_ID; |
94 using syncable::GET_BY_CLIENT_TAG; | 94 using syncer::syncable::GET_BY_CLIENT_TAG; |
95 using syncable::GET_BY_SERVER_TAG; | 95 using syncer::syncable::GET_BY_SERVER_TAG; |
96 using syncable::GET_TYPE_ROOT; | 96 using syncer::syncable::GET_TYPE_ROOT; |
97 using syncable::UNITTEST; | 97 using syncer::syncable::UNITTEST; |
98 | 98 |
99 namespace { | 99 namespace { |
100 | 100 |
101 // A helper to hold on to the counters emitted by the sync engine. | 101 // A helper to hold on to the counters emitted by the sync engine. |
102 class TypeDebugInfoCache : public TypeDebugInfoObserver { | 102 class TypeDebugInfoCache : public TypeDebugInfoObserver { |
103 public: | 103 public: |
104 TypeDebugInfoCache(); | 104 TypeDebugInfoCache(); |
105 ~TypeDebugInfoCache() override; | 105 ~TypeDebugInfoCache() override; |
106 | 106 |
107 CommitCounters GetLatestCommitCounters(ModelType type) const; | 107 CommitCounters GetLatestCommitCounters(ModelType type) const; |
108 UpdateCounters GetLatestUpdateCounters(ModelType type) const; | 108 UpdateCounters GetLatestUpdateCounters(ModelType type) const; |
109 StatusCounters GetLatestStatusCounters(ModelType type) const; | 109 StatusCounters GetLatestStatusCounters(ModelType type) const; |
110 | 110 |
111 // TypeDebugInfoObserver implementation. | 111 // TypeDebugInfoObserver implementation. |
112 void OnCommitCountersUpdated(syncer::ModelType type, | 112 void OnCommitCountersUpdated(ModelType type, |
113 const CommitCounters& counters) override; | 113 const CommitCounters& counters) override; |
114 void OnUpdateCountersUpdated(syncer::ModelType type, | 114 void OnUpdateCountersUpdated(ModelType type, |
115 const UpdateCounters& counters) override; | 115 const UpdateCounters& counters) override; |
116 void OnStatusCountersUpdated(syncer::ModelType type, | 116 void OnStatusCountersUpdated(ModelType type, |
117 const StatusCounters& counters) override; | 117 const StatusCounters& counters) override; |
118 | 118 |
119 private: | 119 private: |
120 std::map<ModelType, CommitCounters> commit_counters_map_; | 120 std::map<ModelType, CommitCounters> commit_counters_map_; |
121 std::map<ModelType, UpdateCounters> update_counters_map_; | 121 std::map<ModelType, UpdateCounters> update_counters_map_; |
122 std::map<ModelType, StatusCounters> status_counters_map_; | 122 std::map<ModelType, StatusCounters> status_counters_map_; |
123 }; | 123 }; |
124 | 124 |
125 TypeDebugInfoCache::TypeDebugInfoCache() {} | 125 TypeDebugInfoCache::TypeDebugInfoCache() {} |
126 | 126 |
(...skipping 26 matching lines...) Expand all Loading... |
153 std::map<ModelType, StatusCounters>::const_iterator it = | 153 std::map<ModelType, StatusCounters>::const_iterator it = |
154 status_counters_map_.find(type); | 154 status_counters_map_.find(type); |
155 if (it == status_counters_map_.end()) { | 155 if (it == status_counters_map_.end()) { |
156 return StatusCounters(); | 156 return StatusCounters(); |
157 } else { | 157 } else { |
158 return it->second; | 158 return it->second; |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 void TypeDebugInfoCache::OnCommitCountersUpdated( | 162 void TypeDebugInfoCache::OnCommitCountersUpdated( |
163 syncer::ModelType type, | 163 ModelType type, |
164 const CommitCounters& counters) { | 164 const CommitCounters& counters) { |
165 commit_counters_map_[type] = counters; | 165 commit_counters_map_[type] = counters; |
166 } | 166 } |
167 | 167 |
168 void TypeDebugInfoCache::OnUpdateCountersUpdated( | 168 void TypeDebugInfoCache::OnUpdateCountersUpdated( |
169 syncer::ModelType type, | 169 ModelType type, |
170 const UpdateCounters& counters) { | 170 const UpdateCounters& counters) { |
171 update_counters_map_[type] = counters; | 171 update_counters_map_[type] = counters; |
172 } | 172 } |
173 | 173 |
174 void TypeDebugInfoCache::OnStatusCountersUpdated( | 174 void TypeDebugInfoCache::OnStatusCountersUpdated( |
175 syncer::ModelType type, | 175 ModelType type, |
176 const StatusCounters& counters) { | 176 const StatusCounters& counters) { |
177 status_counters_map_[type] = counters; | 177 status_counters_map_[type] = counters; |
178 } | 178 } |
179 | 179 |
180 } // namespace | 180 } // namespace |
181 | 181 |
182 class SyncerTest : public testing::Test, | 182 class SyncerTest : public testing::Test, |
183 public SyncCycle::Delegate, | 183 public SyncCycle::Delegate, |
184 public SyncEngineEventListener { | 184 public SyncEngineEventListener { |
185 protected: | 185 protected: |
(...skipping 5659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5845 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 5845 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
5846 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5846 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
5847 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5847 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
5848 } else { | 5848 } else { |
5849 EXPECT_TRUE(final_monitor_records.empty()) | 5849 EXPECT_TRUE(final_monitor_records.empty()) |
5850 << "Should not restore records after successful bookmark commit."; | 5850 << "Should not restore records after successful bookmark commit."; |
5851 } | 5851 } |
5852 } | 5852 } |
5853 | 5853 |
5854 } // namespace syncer | 5854 } // namespace syncer |
OLD | NEW |