OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/download.h" | 5 #include "sync/engine/download.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "sync/engine/sync_directory_update_handler.h" | 9 #include "sync/engine/sync_directory_update_handler.h" |
10 #include "sync/internal_api/public/base/model_type_test_util.h" | 10 #include "sync/internal_api/public/base/model_type_test_util.h" |
11 #include "sync/protocol/sync.pb.h" | 11 #include "sync/protocol/sync.pb.h" |
12 #include "sync/sessions/debug_info_getter.h" | 12 #include "sync/sessions/debug_info_getter.h" |
13 #include "sync/sessions/nudge_tracker.h" | 13 #include "sync/sessions/nudge_tracker.h" |
14 #include "sync/sessions/status_controller.h" | 14 #include "sync/sessions/status_controller.h" |
15 #include "sync/syncable/directory.h" | 15 #include "sync/syncable/directory.h" |
16 #include "sync/test/engine/test_directory_setter_upper.h" | 16 #include "sync/test/engine/test_directory_setter_upper.h" |
| 17 #include "sync/test/sessions/mock_debug_info_getter.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 namespace syncer { | 20 namespace syncer { |
20 | 21 |
| 22 using sessions::MockDebugInfoGetter; |
| 23 |
21 // A test fixture for tests exercising download updates functions. | 24 // A test fixture for tests exercising download updates functions. |
22 class DownloadUpdatesTest : public ::testing::Test { | 25 class DownloadUpdatesTest : public ::testing::Test { |
23 protected: | 26 protected: |
24 DownloadUpdatesTest() | 27 DownloadUpdatesTest() |
25 : update_handler_map_deleter_(&update_handler_map_) { | 28 : update_handler_map_deleter_(&update_handler_map_) { |
26 } | 29 } |
27 | 30 |
28 virtual void SetUp() { | 31 virtual void SetUp() { |
29 dir_maker_.SetUp(); | 32 dir_maker_.SetUp(); |
30 | 33 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 197 |
195 ModelTypeSet progress_types; | 198 ModelTypeSet progress_types; |
196 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | 199 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { |
197 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( | 200 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( |
198 gu_msg.from_progress_marker(i).data_type_id()); | 201 gu_msg.from_progress_marker(i).data_type_id()); |
199 progress_types.Put(type); | 202 progress_types.Put(type); |
200 } | 203 } |
201 EXPECT_TRUE(proto_request_types().Equals(progress_types)); | 204 EXPECT_TRUE(proto_request_types().Equals(progress_types)); |
202 } | 205 } |
203 | 206 |
204 class MockDebugInfoGetter : public sessions::DebugInfoGetter { | |
205 public: | |
206 MockDebugInfoGetter() {} | |
207 virtual ~MockDebugInfoGetter() {} | |
208 | |
209 virtual void GetAndClearDebugInfo(sync_pb::DebugInfo* debug_info) OVERRIDE { | |
210 debug_info->CopyFrom(debug_info_); | |
211 debug_info_.Clear(); | |
212 } | |
213 | |
214 void AddDebugEvent() { | |
215 debug_info_.add_events(); | |
216 } | |
217 | |
218 private: | |
219 sync_pb::DebugInfo debug_info_; | |
220 }; | |
221 | |
222 class DownloadUpdatesDebugInfoTest : public ::testing::Test { | 207 class DownloadUpdatesDebugInfoTest : public ::testing::Test { |
223 public: | 208 public: |
224 DownloadUpdatesDebugInfoTest() {} | 209 DownloadUpdatesDebugInfoTest() {} |
225 virtual ~DownloadUpdatesDebugInfoTest() {} | 210 virtual ~DownloadUpdatesDebugInfoTest() {} |
226 | 211 |
227 sessions::StatusController* status() { | 212 sessions::StatusController* status() { |
228 return &status_; | 213 return &status_; |
229 } | 214 } |
230 | 215 |
231 sessions::DebugInfoGetter* debug_info_getter() { | 216 sessions::DebugInfoGetter* debug_info_getter() { |
232 return &debug_info_getter_; | 217 return &debug_info_getter_; |
233 } | 218 } |
234 | 219 |
235 void AddDebugEvent() { | 220 void AddDebugEvent() { |
236 debug_info_getter_.AddDebugEvent(); | 221 debug_info_getter_.AddDebugEvent(); |
237 } | 222 } |
238 | 223 |
239 private: | 224 private: |
240 sessions::StatusController status_; | 225 sessions::StatusController status_; |
241 MockDebugInfoGetter debug_info_getter_; | 226 MockDebugInfoGetter debug_info_getter_; |
242 }; | 227 }; |
243 | 228 |
244 | 229 |
245 // Verify AppendDebugInfo when there are no events to upload. | 230 // Verify CopyClientDebugInfo when there are no events to upload. |
246 TEST_F(DownloadUpdatesDebugInfoTest, VerifyAppendDebugInfo_Empty) { | 231 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyClientDebugInfo_Empty) { |
247 sync_pb::DebugInfo debug_info; | 232 sync_pb::DebugInfo debug_info; |
248 download::AppendClientDebugInfoIfNeeded(debug_info_getter(), | 233 download::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
249 status(), | |
250 &debug_info); | |
251 EXPECT_EQ(0, debug_info.events_size()); | 234 EXPECT_EQ(0, debug_info.events_size()); |
252 } | 235 } |
253 | 236 |
254 // We should upload debug info only once per sync cycle. | 237 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { |
255 TEST_F(DownloadUpdatesDebugInfoTest, TryDoubleAppend) { | 238 sync_pb::DebugInfo debug_info; |
256 sync_pb::DebugInfo debug_info1; | |
257 | |
258 AddDebugEvent(); | 239 AddDebugEvent(); |
259 download::AppendClientDebugInfoIfNeeded(debug_info_getter(), | 240 download::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
260 status(), | 241 EXPECT_EQ(1, debug_info.events_size()); |
261 &debug_info1); | 242 download::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
262 EXPECT_EQ(1, debug_info1.events_size()); | 243 EXPECT_EQ(1, debug_info.events_size()); |
263 | |
264 | |
265 // Repeated invocations should not send up more events. | |
266 AddDebugEvent(); | |
267 sync_pb::DebugInfo debug_info2; | |
268 download::AppendClientDebugInfoIfNeeded(debug_info_getter(), | |
269 status(), | |
270 &debug_info2); | |
271 EXPECT_EQ(0, debug_info2.events_size()); | |
272 } | 244 } |
273 | 245 |
274 } // namespace syncer | 246 } // namespace syncer |
OLD | NEW |