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> |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 #include <limits> | 13 #include <limits> |
14 #include <list> | 14 #include <list> |
15 #include <map> | 15 #include <map> |
16 #include <memory> | 16 #include <memory> |
17 #include <set> | 17 #include <set> |
18 #include <string> | 18 #include <string> |
19 | 19 |
20 #include "base/bind.h" | 20 #include "base/bind.h" |
21 #include "base/bind_helpers.h" | 21 #include "base/bind_helpers.h" |
22 #include "base/compiler_specific.h" | 22 #include "base/compiler_specific.h" |
23 #include "base/location.h" | 23 #include "base/location.h" |
| 24 #include "base/memory/ptr_util.h" |
24 #include "base/message_loop/message_loop.h" | 25 #include "base/message_loop/message_loop.h" |
25 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
26 #include "base/test/histogram_tester.h" | 27 #include "base/test/histogram_tester.h" |
27 #include "base/time/time.h" | 28 #include "base/time/time.h" |
28 #include "build/build_config.h" | 29 #include "build/build_config.h" |
29 #include "components/sync/base/cancelation_signal.h" | 30 #include "components/sync/base/cancelation_signal.h" |
30 #include "components/sync/base/cryptographer.h" | 31 #include "components/sync/base/cryptographer.h" |
31 #include "components/sync/base/extensions_activity.h" | 32 #include "components/sync/base/extensions_activity.h" |
32 #include "components/sync/base/fake_encryptor.h" | 33 #include "components/sync/base/fake_encryptor.h" |
33 #include "components/sync/base/time.h" | 34 #include "components/sync/base/time.h" |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 260 |
260 bool SyncShareConfigure() { | 261 bool SyncShareConfigure() { |
261 ResetCycle(); | 262 ResetCycle(); |
262 return syncer_->ConfigureSyncShare( | 263 return syncer_->ConfigureSyncShare( |
263 context_->GetEnabledTypes(), | 264 context_->GetEnabledTypes(), |
264 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, cycle_.get()); | 265 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, cycle_.get()); |
265 } | 266 } |
266 | 267 |
267 void SetUp() override { | 268 void SetUp() override { |
268 dir_maker_.SetUp(); | 269 dir_maker_.SetUp(); |
269 mock_server_.reset( | 270 mock_server_ = base::MakeUnique<MockConnectionManager>( |
270 new MockConnectionManager(directory(), &cancelation_signal_)); | 271 directory(), &cancelation_signal_); |
271 debug_info_getter_.reset(new MockDebugInfoGetter); | 272 debug_info_getter_ = base::MakeUnique<MockDebugInfoGetter>(); |
272 EnableDatatype(BOOKMARKS); | 273 EnableDatatype(BOOKMARKS); |
273 EnableDatatype(EXTENSIONS); | 274 EnableDatatype(EXTENSIONS); |
274 EnableDatatype(NIGORI); | 275 EnableDatatype(NIGORI); |
275 EnableDatatype(PREFERENCES); | 276 EnableDatatype(PREFERENCES); |
276 EnableDatatype(NIGORI); | 277 EnableDatatype(NIGORI); |
277 workers_.push_back( | 278 workers_.push_back( |
278 scoped_refptr<ModelSafeWorker>(new FakeModelWorker(GROUP_PASSIVE))); | 279 scoped_refptr<ModelSafeWorker>(new FakeModelWorker(GROUP_PASSIVE))); |
279 std::vector<SyncEngineEventListener*> listeners; | 280 std::vector<SyncEngineEventListener*> listeners; |
280 listeners.push_back(this); | 281 listeners.push_back(this); |
281 | 282 |
282 ModelSafeRoutingInfo routing_info; | 283 ModelSafeRoutingInfo routing_info; |
283 GetModelSafeRoutingInfo(&routing_info); | 284 GetModelSafeRoutingInfo(&routing_info); |
284 | 285 |
285 model_type_registry_.reset( | 286 model_type_registry_ = base::MakeUnique<ModelTypeRegistry>( |
286 new ModelTypeRegistry(workers_, directory(), &mock_nudge_handler_)); | 287 workers_, directory(), &mock_nudge_handler_); |
287 model_type_registry_->RegisterDirectoryTypeDebugInfoObserver( | 288 model_type_registry_->RegisterDirectoryTypeDebugInfoObserver( |
288 &debug_info_cache_); | 289 &debug_info_cache_); |
289 | 290 |
290 context_.reset(new SyncCycleContext( | 291 context_ = base::MakeUnique<SyncCycleContext>( |
291 mock_server_.get(), directory(), extensions_activity_.get(), listeners, | 292 mock_server_.get(), directory(), extensions_activity_.get(), listeners, |
292 debug_info_getter_.get(), model_type_registry_.get(), | 293 debug_info_getter_.get(), model_type_registry_.get(), |
293 true, // enable keystore encryption | 294 true, // enable keystore encryption |
294 false, // force enable pre-commit GU avoidance experiment | 295 false, // force enable pre-commit GU avoidance experiment |
295 "fake_invalidator_client_id")); | 296 "fake_invalidator_client_id"); |
296 context_->SetRoutingInfo(routing_info); | 297 context_->SetRoutingInfo(routing_info); |
297 syncer_ = new Syncer(&cancelation_signal_); | 298 syncer_ = new Syncer(&cancelation_signal_); |
298 scheduler_.reset(new SyncSchedulerImpl( | 299 scheduler_ = base::MakeUnique<SyncSchedulerImpl>( |
299 "TestSyncScheduler", BackoffDelayProvider::FromDefaults(), | 300 "TestSyncScheduler", BackoffDelayProvider::FromDefaults(), |
300 context_.get(), | 301 context_.get(), |
301 // scheduler_ owned syncer_ now and will manage the memory of syncer_ | 302 // scheduler_ owned syncer_ now and will manage the memory of syncer_ |
302 syncer_)); | 303 syncer_); |
303 | 304 |
304 syncable::ReadTransaction trans(FROM_HERE, directory()); | 305 syncable::ReadTransaction trans(FROM_HERE, directory()); |
305 Directory::Metahandles children; | 306 Directory::Metahandles children; |
306 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); | 307 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); |
307 ASSERT_EQ(0u, children.size()); | 308 ASSERT_EQ(0u, children.size()); |
308 root_id_ = TestIdFactory::root(); | 309 root_id_ = TestIdFactory::root(); |
309 parent_id_ = ids_.MakeServer("parent id"); | 310 parent_id_ = ids_.MakeServer("parent id"); |
310 child_id_ = ids_.MakeServer("child id"); | 311 child_id_ = ids_.MakeServer("child id"); |
311 directory()->set_store_birthday(mock_server_->store_birthday()); | 312 directory()->set_store_birthday(mock_server_->store_birthday()); |
312 mock_server_->SetKeystoreKey("encryption_key"); | 313 mock_server_->SetKeystoreKey("encryption_key"); |
(...skipping 5526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5839 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 5840 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
5840 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5841 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
5841 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5842 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
5842 } else { | 5843 } else { |
5843 EXPECT_TRUE(final_monitor_records.empty()) | 5844 EXPECT_TRUE(final_monitor_records.empty()) |
5844 << "Should not restore records after successful bookmark commit."; | 5845 << "Should not restore records after successful bookmark commit."; |
5845 } | 5846 } |
5846 } | 5847 } |
5847 | 5848 |
5848 } // namespace syncer | 5849 } // namespace syncer |
OLD | NEW |