| 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/fake_model_worker.h" |
| 16 #include "sync/test/engine/test_directory_setter_upper.h" | 17 #include "sync/test/engine/test_directory_setter_upper.h" |
| 17 #include "sync/test/sessions/mock_debug_info_getter.h" | 18 #include "sync/test/sessions/mock_debug_info_getter.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace syncer { | 21 namespace syncer { |
| 21 | 22 |
| 22 using sessions::MockDebugInfoGetter; | 23 using sessions::MockDebugInfoGetter; |
| 23 | 24 |
| 24 // A test fixture for tests exercising download updates functions. | 25 // A test fixture for tests exercising download updates functions. |
| 25 class DownloadUpdatesTest : public ::testing::Test { | 26 class DownloadUpdatesTest : public ::testing::Test { |
| 26 protected: | 27 protected: |
| 27 DownloadUpdatesTest() | 28 DownloadUpdatesTest() |
| 28 : update_handler_map_deleter_(&update_handler_map_) { | 29 : update_handler_map_deleter_(&update_handler_map_) { |
| 29 } | 30 } |
| 30 | 31 |
| 31 virtual void SetUp() { | 32 virtual void SetUp() { |
| 32 dir_maker_.SetUp(); | 33 dir_maker_.SetUp(); |
| 33 | 34 |
| 34 AddUpdateHandler(AUTOFILL); | 35 AddUpdateHandler(AUTOFILL, GROUP_DB); |
| 35 AddUpdateHandler(BOOKMARKS); | 36 AddUpdateHandler(BOOKMARKS, GROUP_UI); |
| 36 AddUpdateHandler(PREFERENCES); | 37 AddUpdateHandler(PREFERENCES, GROUP_UI); |
| 37 } | 38 } |
| 38 | 39 |
| 39 virtual void TearDown() { | 40 virtual void TearDown() { |
| 40 dir_maker_.TearDown(); | 41 dir_maker_.TearDown(); |
| 41 } | 42 } |
| 42 | 43 |
| 43 ModelTypeSet proto_request_types() { | 44 ModelTypeSet proto_request_types() { |
| 44 ModelTypeSet types; | 45 ModelTypeSet types; |
| 45 for (UpdateHandlerMap::iterator it = update_handler_map_.begin(); | 46 for (UpdateHandlerMap::iterator it = update_handler_map_.begin(); |
| 46 it != update_handler_map_.end(); ++it) { | 47 it != update_handler_map_.end(); ++it) { |
| 47 types.Put(it->first); | 48 types.Put(it->first); |
| 48 } | 49 } |
| 49 return types; | 50 return types; |
| 50 } | 51 } |
| 51 | 52 |
| 52 syncable::Directory* directory() { | 53 syncable::Directory* directory() { |
| 53 return dir_maker_.directory(); | 54 return dir_maker_.directory(); |
| 54 } | 55 } |
| 55 | 56 |
| 56 UpdateHandlerMap* update_handler_map() { | 57 UpdateHandlerMap* update_handler_map() { |
| 57 return &update_handler_map_; | 58 return &update_handler_map_; |
| 58 } | 59 } |
| 59 | 60 |
| 60 private: | 61 private: |
| 61 void AddUpdateHandler(ModelType type) { | 62 void AddUpdateHandler(ModelType type, ModelSafeGroup group) { |
| 62 DCHECK(directory()); | 63 DCHECK(directory()); |
| 63 update_handler_map_.insert( | 64 scoped_refptr<ModelSafeWorker> worker = new FakeModelWorker(group); |
| 64 std::make_pair(type, | 65 SyncDirectoryUpdateHandler* handler = |
| 65 new SyncDirectoryUpdateHandler(directory(), type))); | 66 new SyncDirectoryUpdateHandler(directory(), type, worker); |
| 67 update_handler_map_.insert(std::make_pair(type, handler)); |
| 66 } | 68 } |
| 67 | 69 |
| 68 base::MessageLoop loop_; // Needed for directory init. | 70 base::MessageLoop loop_; // Needed for directory init. |
| 69 TestDirectorySetterUpper dir_maker_; | 71 TestDirectorySetterUpper dir_maker_; |
| 70 | 72 |
| 71 UpdateHandlerMap update_handler_map_; | 73 UpdateHandlerMap update_handler_map_; |
| 72 STLValueDeleter<UpdateHandlerMap> update_handler_map_deleter_; | 74 STLValueDeleter<UpdateHandlerMap> update_handler_map_deleter_; |
| 73 | 75 |
| 74 DISALLOW_COPY_AND_ASSIGN(DownloadUpdatesTest); | 76 DISALLOW_COPY_AND_ASSIGN(DownloadUpdatesTest); |
| 75 }; | 77 }; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { | 239 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { |
| 238 sync_pb::DebugInfo debug_info; | 240 sync_pb::DebugInfo debug_info; |
| 239 AddDebugEvent(); | 241 AddDebugEvent(); |
| 240 download::CopyClientDebugInfo(debug_info_getter(), &debug_info); | 242 download::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
| 241 EXPECT_EQ(1, debug_info.events_size()); | 243 EXPECT_EQ(1, debug_info.events_size()); |
| 242 download::CopyClientDebugInfo(debug_info_getter(), &debug_info); | 244 download::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
| 243 EXPECT_EQ(1, debug_info.events_size()); | 245 EXPECT_EQ(1, debug_info.events_size()); |
| 244 } | 246 } |
| 245 | 247 |
| 246 } // namespace syncer | 248 } // namespace syncer |
| OLD | NEW |