| 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 // Unit tests for the SyncApi. Note that a lot of the underlying | 5 // Unit tests for the SyncApi. Note that a lot of the underlying |
| 6 // functionality is provided by the Syncable layer, which has its own | 6 // functionality is provided by the Syncable layer, which has its own |
| 7 // unit tests. We'll test SyncApi specific things in this harness. | 7 // unit tests. We'll test SyncApi specific things in this harness. |
| 8 | 8 |
| 9 #include <cstddef> | 9 #include <cstddef> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 bool initialization_succeeded_; | 1068 bool initialization_succeeded_; |
| 1069 StrictMock<SyncManagerObserverMock> manager_observer_; | 1069 StrictMock<SyncManagerObserverMock> manager_observer_; |
| 1070 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; | 1070 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; |
| 1071 InternalComponentsFactory::Switches switches_; | 1071 InternalComponentsFactory::Switches switches_; |
| 1072 InternalComponentsFactory::StorageOption storage_used_; | 1072 InternalComponentsFactory::StorageOption storage_used_; |
| 1073 }; | 1073 }; |
| 1074 | 1074 |
| 1075 TEST_F(SyncManagerTest, GetAllNodesForTypeTest) { | 1075 TEST_F(SyncManagerTest, GetAllNodesForTypeTest) { |
| 1076 ModelSafeRoutingInfo routing_info; | 1076 ModelSafeRoutingInfo routing_info; |
| 1077 GetModelSafeRoutingInfo(&routing_info); | 1077 GetModelSafeRoutingInfo(&routing_info); |
| 1078 sync_manager_.StartSyncingNormally(routing_info, base::Time()); | 1078 sync_manager_.StartSyncingNormally(routing_info); |
| 1079 | 1079 |
| 1080 scoped_ptr<base::ListValue> node_list( | 1080 scoped_ptr<base::ListValue> node_list( |
| 1081 sync_manager_.GetAllNodesForType(syncer::PREFERENCES)); | 1081 sync_manager_.GetAllNodesForType(syncer::PREFERENCES)); |
| 1082 | 1082 |
| 1083 // Should have one node: the type root node. | 1083 // Should have one node: the type root node. |
| 1084 ASSERT_EQ(1U, node_list->GetSize()); | 1084 ASSERT_EQ(1U, node_list->GetSize()); |
| 1085 | 1085 |
| 1086 const base::DictionaryValue* first_result; | 1086 const base::DictionaryValue* first_result; |
| 1087 ASSERT_TRUE(node_list->GetDictionary(0, &first_result)); | 1087 ASSERT_TRUE(node_list->GetDictionary(0, &first_result)); |
| 1088 EXPECT_TRUE(first_result->HasKey("ID")); | 1088 EXPECT_TRUE(first_result->HasKey("ID")); |
| (...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2370 GetTransactionVersion(i->first)); | 2370 GetTransactionVersion(i->first)); |
| 2371 } | 2371 } |
| 2372 } | 2372 } |
| 2373 } | 2373 } |
| 2374 | 2374 |
| 2375 class MockSyncScheduler : public FakeSyncScheduler { | 2375 class MockSyncScheduler : public FakeSyncScheduler { |
| 2376 public: | 2376 public: |
| 2377 MockSyncScheduler() : FakeSyncScheduler() {} | 2377 MockSyncScheduler() : FakeSyncScheduler() {} |
| 2378 virtual ~MockSyncScheduler() {} | 2378 virtual ~MockSyncScheduler() {} |
| 2379 | 2379 |
| 2380 MOCK_METHOD2(Start, void(SyncScheduler::Mode, base::Time)); | 2380 MOCK_METHOD1(Start, void(SyncScheduler::Mode)); |
| 2381 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&)); | 2381 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&)); |
| 2382 }; | 2382 }; |
| 2383 | 2383 |
| 2384 class ComponentsFactory : public TestInternalComponentsFactory { | 2384 class ComponentsFactory : public TestInternalComponentsFactory { |
| 2385 public: | 2385 public: |
| 2386 ComponentsFactory(const Switches& switches, | 2386 ComponentsFactory(const Switches& switches, |
| 2387 SyncScheduler* scheduler_to_use, | 2387 SyncScheduler* scheduler_to_use, |
| 2388 sessions::SyncSessionContext** session_context, | 2388 sessions::SyncSessionContext** session_context, |
| 2389 InternalComponentsFactory::StorageOption* storage_used) | 2389 InternalComponentsFactory::StorageOption* storage_used) |
| 2390 : TestInternalComponentsFactory( | 2390 : TestInternalComponentsFactory( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2430 // should be purged. | 2430 // should be purged. |
| 2431 TEST_F(SyncManagerTestWithMockScheduler, BasicConfiguration) { | 2431 TEST_F(SyncManagerTestWithMockScheduler, BasicConfiguration) { |
| 2432 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; | 2432 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; |
| 2433 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); | 2433 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); |
| 2434 ModelSafeRoutingInfo new_routing_info; | 2434 ModelSafeRoutingInfo new_routing_info; |
| 2435 GetModelSafeRoutingInfo(&new_routing_info); | 2435 GetModelSafeRoutingInfo(&new_routing_info); |
| 2436 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); | 2436 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); |
| 2437 ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types); | 2437 ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types); |
| 2438 | 2438 |
| 2439 ConfigurationParams params; | 2439 ConfigurationParams params; |
| 2440 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE, _)); | 2440 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE)); |
| 2441 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)). | 2441 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)). |
| 2442 WillOnce(SaveArg<0>(¶ms)); | 2442 WillOnce(SaveArg<0>(¶ms)); |
| 2443 | 2443 |
| 2444 // Set data for all types. | 2444 // Set data for all types. |
| 2445 ModelTypeSet protocol_types = ProtocolTypes(); | 2445 ModelTypeSet protocol_types = ProtocolTypes(); |
| 2446 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); | 2446 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); |
| 2447 iter.Inc()) { | 2447 iter.Inc()) { |
| 2448 SetProgressMarkerForType(iter.Get(), true); | 2448 SetProgressMarkerForType(iter.Get(), true); |
| 2449 } | 2449 } |
| 2450 | 2450 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2482 ModelTypeSet disabled_types = ModelTypeSet(THEMES, SESSIONS); | 2482 ModelTypeSet disabled_types = ModelTypeSet(THEMES, SESSIONS); |
| 2483 ModelSafeRoutingInfo old_routing_info; | 2483 ModelSafeRoutingInfo old_routing_info; |
| 2484 ModelSafeRoutingInfo new_routing_info; | 2484 ModelSafeRoutingInfo new_routing_info; |
| 2485 GetModelSafeRoutingInfo(&old_routing_info); | 2485 GetModelSafeRoutingInfo(&old_routing_info); |
| 2486 new_routing_info = old_routing_info; | 2486 new_routing_info = old_routing_info; |
| 2487 new_routing_info.erase(THEMES); | 2487 new_routing_info.erase(THEMES); |
| 2488 new_routing_info.erase(SESSIONS); | 2488 new_routing_info.erase(SESSIONS); |
| 2489 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); | 2489 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); |
| 2490 | 2490 |
| 2491 ConfigurationParams params; | 2491 ConfigurationParams params; |
| 2492 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE, _)); | 2492 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE)); |
| 2493 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)). | 2493 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)). |
| 2494 WillOnce(SaveArg<0>(¶ms)); | 2494 WillOnce(SaveArg<0>(¶ms)); |
| 2495 | 2495 |
| 2496 // Set data for all types except those recently disabled (so we can verify | 2496 // Set data for all types except those recently disabled (so we can verify |
| 2497 // only those recently disabled are purged) . | 2497 // only those recently disabled are purged) . |
| 2498 ModelTypeSet protocol_types = ProtocolTypes(); | 2498 ModelTypeSet protocol_types = ProtocolTypes(); |
| 2499 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); | 2499 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); |
| 2500 iter.Inc()) { | 2500 iter.Inc()) { |
| 2501 if (!disabled_types.Has(iter.Get())) { | 2501 if (!disabled_types.Has(iter.Get())) { |
| 2502 SetProgressMarkerForType(iter.Get(), true); | 2502 SetProgressMarkerForType(iter.Get(), true); |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3197 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3197 // SyncManagerInitInvalidStorageTest::GetFactory will return |
| 3198 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3198 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
| 3199 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3199 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
| 3200 // task is to ensure that SyncManagerImpl reported initialization failure in | 3200 // task is to ensure that SyncManagerImpl reported initialization failure in |
| 3201 // OnInitializationComplete callback. | 3201 // OnInitializationComplete callback. |
| 3202 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3202 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
| 3203 EXPECT_FALSE(initialization_succeeded_); | 3203 EXPECT_FALSE(initialization_succeeded_); |
| 3204 } | 3204 } |
| 3205 | 3205 |
| 3206 } // namespace syncer | 3206 } // namespace syncer |
| OLD | NEW |