| 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 "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace syncer { | 20 namespace syncer { |
| 20 | 21 |
| 21 // A test fixture for tests exercising download updates functions. | 22 // A test fixture for tests exercising download updates functions. |
| 22 class DownloadUpdatesTest : public ::testing::Test { | 23 class DownloadUpdatesTest : public ::testing::Test { |
| 23 protected: | 24 protected: |
| 24 DownloadUpdatesTest() | 25 DownloadUpdatesTest() |
| 25 : update_handler_map_deleter_(&update_handler_map_) { | 26 : update_handler_map_deleter_(&update_handler_map_) { |
| 26 } | 27 } |
| 27 | 28 |
| 28 virtual void SetUp() { | 29 virtual void SetUp() { |
| 29 dir_maker_.SetUp(); | 30 dir_maker_.SetUp(); |
| 30 | 31 |
| 31 AddUpdateHandler(AUTOFILL); | 32 AddUpdateHandler(AUTOFILL, GROUP_DB); |
| 32 AddUpdateHandler(BOOKMARKS); | 33 AddUpdateHandler(BOOKMARKS, GROUP_UI); |
| 33 AddUpdateHandler(PREFERENCES); | 34 AddUpdateHandler(PREFERENCES, GROUP_UI); |
| 34 } | 35 } |
| 35 | 36 |
| 36 virtual void TearDown() { | 37 virtual void TearDown() { |
| 37 dir_maker_.TearDown(); | 38 dir_maker_.TearDown(); |
| 38 } | 39 } |
| 39 | 40 |
| 40 ModelTypeSet proto_request_types() { | 41 ModelTypeSet proto_request_types() { |
| 41 ModelTypeSet types; | 42 ModelTypeSet types; |
| 42 for (UpdateHandlerMap::iterator it = update_handler_map_.begin(); | 43 for (UpdateHandlerMap::iterator it = update_handler_map_.begin(); |
| 43 it != update_handler_map_.end(); ++it) { | 44 it != update_handler_map_.end(); ++it) { |
| 44 types.Put(it->first); | 45 types.Put(it->first); |
| 45 } | 46 } |
| 46 return types; | 47 return types; |
| 47 } | 48 } |
| 48 | 49 |
| 49 syncable::Directory* directory() { | 50 syncable::Directory* directory() { |
| 50 return dir_maker_.directory(); | 51 return dir_maker_.directory(); |
| 51 } | 52 } |
| 52 | 53 |
| 53 UpdateHandlerMap* update_handler_map() { | 54 UpdateHandlerMap* update_handler_map() { |
| 54 return &update_handler_map_; | 55 return &update_handler_map_; |
| 55 } | 56 } |
| 56 | 57 |
| 57 private: | 58 private: |
| 58 void AddUpdateHandler(ModelType type) { | 59 void AddUpdateHandler(ModelType type, ModelSafeGroup group) { |
| 59 DCHECK(directory()); | 60 DCHECK(directory()); |
| 60 update_handler_map_.insert( | 61 scoped_refptr<ModelSafeWorker> worker = new FakeModelWorker(group); |
| 61 std::make_pair(type, | 62 SyncDirectoryUpdateHandler* handler = |
| 62 new SyncDirectoryUpdateHandler(directory(), type))); | 63 new SyncDirectoryUpdateHandler(directory(), type, worker); |
| 64 update_handler_map_.insert(std::make_pair(type, handler)); |
| 63 } | 65 } |
| 64 | 66 |
| 65 base::MessageLoop loop_; // Needed for directory init. | 67 base::MessageLoop loop_; // Needed for directory init. |
| 66 TestDirectorySetterUpper dir_maker_; | 68 TestDirectorySetterUpper dir_maker_; |
| 67 | 69 |
| 68 UpdateHandlerMap update_handler_map_; | 70 UpdateHandlerMap update_handler_map_; |
| 69 STLValueDeleter<UpdateHandlerMap> update_handler_map_deleter_; | 71 STLValueDeleter<UpdateHandlerMap> update_handler_map_deleter_; |
| 70 | 72 |
| 71 DISALLOW_COPY_AND_ASSIGN(DownloadUpdatesTest); | 73 DISALLOW_COPY_AND_ASSIGN(DownloadUpdatesTest); |
| 72 }; | 74 }; |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 // Repeated invocations should not send up more events. | 267 // Repeated invocations should not send up more events. |
| 266 AddDebugEvent(); | 268 AddDebugEvent(); |
| 267 sync_pb::DebugInfo debug_info2; | 269 sync_pb::DebugInfo debug_info2; |
| 268 download::AppendClientDebugInfoIfNeeded(debug_info_getter(), | 270 download::AppendClientDebugInfoIfNeeded(debug_info_getter(), |
| 269 status(), | 271 status(), |
| 270 &debug_info2); | 272 &debug_info2); |
| 271 EXPECT_EQ(0, debug_info2.events_size()); | 273 EXPECT_EQ(0, debug_info2.events_size()); |
| 272 } | 274 } |
| 273 | 275 |
| 274 } // namespace syncer | 276 } // namespace syncer |
| OLD | NEW |