| 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/get_updates_delegate.h" | 9 #include "sync/engine/get_updates_delegate.h" |
| 10 #include "sync/engine/sync_directory_update_handler.h" | 10 #include "sync/engine/update_handler.h" |
| 11 #include "sync/internal_api/public/base/model_type_test_util.h" | 11 #include "sync/internal_api/public/base/model_type_test_util.h" |
| 12 #include "sync/protocol/sync.pb.h" | 12 #include "sync/protocol/sync.pb.h" |
| 13 #include "sync/sessions/debug_info_getter.h" | 13 #include "sync/sessions/debug_info_getter.h" |
| 14 #include "sync/sessions/nudge_tracker.h" | 14 #include "sync/sessions/nudge_tracker.h" |
| 15 #include "sync/sessions/status_controller.h" | 15 #include "sync/sessions/status_controller.h" |
| 16 #include "sync/syncable/directory.h" | |
| 17 #include "sync/test/engine/fake_model_worker.h" | 16 #include "sync/test/engine/fake_model_worker.h" |
| 18 #include "sync/test/engine/test_directory_setter_upper.h" | 17 #include "sync/test/engine/mock_update_handler.h" |
| 19 #include "sync/test/sessions/mock_debug_info_getter.h" | 18 #include "sync/test/sessions/mock_debug_info_getter.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 20 |
| 22 namespace syncer { | 21 namespace syncer { |
| 23 | 22 |
| 24 using sessions::MockDebugInfoGetter; | 23 using sessions::MockDebugInfoGetter; |
| 25 | 24 |
| 26 // A test fixture for tests exercising download updates functions. | 25 // A test fixture for tests exercising download updates functions. |
| 27 class DownloadUpdatesTest : public ::testing::Test { | 26 class DownloadUpdatesTest : public ::testing::Test { |
| 28 protected: | 27 protected: |
| 29 DownloadUpdatesTest() : | 28 DownloadUpdatesTest() : |
| 30 kTestStartTime(base::TimeTicks::Now()), | 29 kTestStartTime(base::TimeTicks::Now()), |
| 31 update_handler_deleter_(&update_handler_map_) {} | 30 update_handler_deleter_(&update_handler_map_) {} |
| 32 | 31 |
| 33 virtual void SetUp() { | 32 virtual void SetUp() { |
| 34 dir_maker_.SetUp(); | 33 AddUpdateHandler(AUTOFILL); |
| 35 | 34 AddUpdateHandler(BOOKMARKS); |
| 36 AddUpdateHandler(AUTOFILL, GROUP_DB); | 35 AddUpdateHandler(PREFERENCES); |
| 37 AddUpdateHandler(BOOKMARKS, GROUP_UI); | |
| 38 AddUpdateHandler(PREFERENCES, GROUP_UI); | |
| 39 } | |
| 40 | |
| 41 virtual void TearDown() { | |
| 42 dir_maker_.TearDown(); | |
| 43 } | 36 } |
| 44 | 37 |
| 45 ModelTypeSet request_types() { | 38 ModelTypeSet request_types() { |
| 46 return request_types_; | 39 return request_types_; |
| 47 } | 40 } |
| 48 | 41 |
| 49 syncable::Directory* directory() { | |
| 50 return dir_maker_.directory(); | |
| 51 } | |
| 52 | |
| 53 scoped_ptr<GetUpdatesProcessor> BuildGetUpdatesProcessor( | 42 scoped_ptr<GetUpdatesProcessor> BuildGetUpdatesProcessor( |
| 54 const GetUpdatesDelegate& delegate) { | 43 const GetUpdatesDelegate& delegate) { |
| 55 return scoped_ptr<GetUpdatesProcessor>( | 44 return scoped_ptr<GetUpdatesProcessor>( |
| 56 new GetUpdatesProcessor(&update_handler_map_, delegate)); | 45 new GetUpdatesProcessor(&update_handler_map_, delegate)); |
| 57 } | 46 } |
| 58 | 47 |
| 59 void InitFakeUpdateResponse(sync_pb::GetUpdatesResponse* response) { | 48 void InitFakeUpdateResponse(sync_pb::GetUpdatesResponse* response) { |
| 60 ModelTypeSet types = request_types(); | 49 ModelTypeSet types = request_types(); |
| 61 | 50 |
| 62 for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { | 51 for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { |
| 63 sync_pb::DataTypeProgressMarker* marker = | 52 sync_pb::DataTypeProgressMarker* marker = |
| 64 response->add_new_progress_marker(); | 53 response->add_new_progress_marker(); |
| 65 marker->set_data_type_id(GetSpecificsFieldNumberFromModelType(it.Get())); | 54 marker->set_data_type_id(GetSpecificsFieldNumberFromModelType(it.Get())); |
| 66 marker->set_token("foobarbaz"); | 55 marker->set_token("foobarbaz"); |
| 67 } | 56 } |
| 68 | 57 |
| 69 response->set_changes_remaining(0); | 58 response->set_changes_remaining(0); |
| 70 } | 59 } |
| 71 | 60 |
| 72 const base::TimeTicks kTestStartTime; | 61 const base::TimeTicks kTestStartTime; |
| 73 | 62 |
| 74 private: | 63 private: |
| 75 void AddUpdateHandler(ModelType type, ModelSafeGroup group) { | 64 void AddUpdateHandler(ModelType type) { |
| 76 DCHECK(directory()); | |
| 77 | |
| 78 request_types_.Put(type); | 65 request_types_.Put(type); |
| 79 | 66 |
| 80 scoped_refptr<ModelSafeWorker> worker = new FakeModelWorker(group); | 67 UpdateHandler* handler = new MockUpdateHandler(type); |
| 81 SyncDirectoryUpdateHandler* handler = | |
| 82 new SyncDirectoryUpdateHandler(directory(), type, worker); | |
| 83 update_handler_map_.insert(std::make_pair(type, handler)); | 68 update_handler_map_.insert(std::make_pair(type, handler)); |
| 84 } | 69 } |
| 85 | 70 |
| 86 base::MessageLoop loop_; // Needed for directory init. | |
| 87 TestDirectorySetterUpper dir_maker_; | |
| 88 | |
| 89 ModelTypeSet request_types_; | 71 ModelTypeSet request_types_; |
| 90 UpdateHandlerMap update_handler_map_; | 72 UpdateHandlerMap update_handler_map_; |
| 91 STLValueDeleter<UpdateHandlerMap> update_handler_deleter_; | 73 STLValueDeleter<UpdateHandlerMap> update_handler_deleter_; |
| 92 scoped_ptr<GetUpdatesProcessor> get_updates_processor_; | 74 scoped_ptr<GetUpdatesProcessor> get_updates_processor_; |
| 93 | 75 |
| 94 DISALLOW_COPY_AND_ASSIGN(DownloadUpdatesTest); | 76 DISALLOW_COPY_AND_ASSIGN(DownloadUpdatesTest); |
| 95 }; | 77 }; |
| 96 | 78 |
| 97 // Basic test to make sure nudges are expressed properly in the request. | 79 // Basic test to make sure nudges are expressed properly in the request. |
| 98 TEST_F(DownloadUpdatesTest, BookmarkNudge) { | 80 TEST_F(DownloadUpdatesTest, BookmarkNudge) { |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { | 346 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { |
| 365 sync_pb::DebugInfo debug_info; | 347 sync_pb::DebugInfo debug_info; |
| 366 AddDebugEvent(); | 348 AddDebugEvent(); |
| 367 download::CopyClientDebugInfo(debug_info_getter(), &debug_info); | 349 download::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
| 368 EXPECT_EQ(1, debug_info.events_size()); | 350 EXPECT_EQ(1, debug_info.events_size()); |
| 369 download::CopyClientDebugInfo(debug_info_getter(), &debug_info); | 351 download::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
| 370 EXPECT_EQ(1, debug_info.events_size()); | 352 EXPECT_EQ(1, debug_info.events_size()); |
| 371 } | 353 } |
| 372 | 354 |
| 373 } // namespace syncer | 355 } // namespace syncer |
| OLD | NEW |