Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 EXPECT_FALSE(js_backend_.IsInitialized()); | 746 EXPECT_FALSE(js_backend_.IsInitialized()); |
| 747 | 747 |
| 748 std::vector<ModelSafeWorker*> workers; | 748 std::vector<ModelSafeWorker*> workers; |
| 749 ModelSafeRoutingInfo routing_info; | 749 ModelSafeRoutingInfo routing_info; |
| 750 GetModelSafeRoutingInfo(&routing_info); | 750 GetModelSafeRoutingInfo(&routing_info); |
| 751 | 751 |
| 752 // Takes ownership of |fake_invalidator_|. | 752 // Takes ownership of |fake_invalidator_|. |
| 753 sync_manager_.Init(temp_dir_.path(), | 753 sync_manager_.Init(temp_dir_.path(), |
| 754 WeakHandle<JsEventHandler>(), | 754 WeakHandle<JsEventHandler>(), |
| 755 "bogus", 0, false, | 755 "bogus", 0, false, |
| 756 base::MessageLoopProxy::current(), | |
| 757 scoped_ptr<HttpPostProviderFactory>( | 756 scoped_ptr<HttpPostProviderFactory>( |
| 758 new TestHttpPostProviderFactory()), | 757 new TestHttpPostProviderFactory()), |
| 759 workers, &extensions_activity_monitor_, this, | 758 workers, &extensions_activity_monitor_, this, |
| 760 credentials, | 759 credentials, |
| 761 scoped_ptr<Invalidator>(fake_invalidator_), | 760 scoped_ptr<Invalidator>(fake_invalidator_), |
| 762 "", "", // bootstrap tokens | 761 "", "", // bootstrap tokens |
| 763 scoped_ptr<InternalComponentsFactory>(GetFactory()), | 762 scoped_ptr<InternalComponentsFactory>(GetFactory()), |
| 764 &encryptor_, | 763 &encryptor_, |
| 765 &handler_, | 764 &handler_, |
| 766 NULL); | 765 NULL); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 784 sync_manager_.ShutdownOnSyncThread(); | 783 sync_manager_.ShutdownOnSyncThread(); |
| 785 // We can't assert that |sync_manager_| isn't registered with | 784 // We can't assert that |sync_manager_| isn't registered with |
| 786 // |fake_invalidator_| anymore because |fake_invalidator_| is now | 785 // |fake_invalidator_| anymore because |fake_invalidator_| is now |
| 787 // destroyed. | 786 // destroyed. |
| 788 fake_invalidator_ = NULL; | 787 fake_invalidator_ = NULL; |
| 789 PumpLoop(); | 788 PumpLoop(); |
| 790 } | 789 } |
| 791 | 790 |
| 792 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 791 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
| 793 (*out)[NIGORI] = GROUP_PASSIVE; | 792 (*out)[NIGORI] = GROUP_PASSIVE; |
| 793 (*out)[DEVICE_INFO] = GROUP_PASSIVE; | |
| 794 (*out)[BOOKMARKS] = GROUP_PASSIVE; | 794 (*out)[BOOKMARKS] = GROUP_PASSIVE; |
| 795 (*out)[THEMES] = GROUP_PASSIVE; | 795 (*out)[THEMES] = GROUP_PASSIVE; |
| 796 (*out)[SESSIONS] = GROUP_PASSIVE; | 796 (*out)[SESSIONS] = GROUP_PASSIVE; |
| 797 (*out)[PASSWORDS] = GROUP_PASSIVE; | 797 (*out)[PASSWORDS] = GROUP_PASSIVE; |
| 798 (*out)[PREFERENCES] = GROUP_PASSIVE; | 798 (*out)[PREFERENCES] = GROUP_PASSIVE; |
| 799 } | 799 } |
| 800 | 800 |
| 801 virtual void OnChangesApplied( | 801 virtual void OnChangesApplied( |
| 802 ModelType model_type, | 802 ModelType model_type, |
| 803 const BaseTransaction* trans, | 803 const BaseTransaction* trans, |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1182 ListValue args; | 1182 ListValue args; |
| 1183 args.Append(Value::CreateStringValue("1")); | 1183 args.Append(Value::CreateStringValue("1")); |
| 1184 SendJsMessage("getChildNodeIds", | 1184 SendJsMessage("getChildNodeIds", |
| 1185 JsArgList(&args), reply_handler.AsWeakHandle()); | 1185 JsArgList(&args), reply_handler.AsWeakHandle()); |
| 1186 } | 1186 } |
| 1187 | 1187 |
| 1188 EXPECT_EQ(1u, return_args.Get().GetSize()); | 1188 EXPECT_EQ(1u, return_args.Get().GetSize()); |
| 1189 const ListValue* nodes = NULL; | 1189 const ListValue* nodes = NULL; |
| 1190 ASSERT_TRUE(return_args.Get().GetList(0, &nodes)); | 1190 ASSERT_TRUE(return_args.Get().GetList(0, &nodes)); |
| 1191 ASSERT_TRUE(nodes); | 1191 ASSERT_TRUE(nodes); |
| 1192 EXPECT_EQ(6u, nodes->GetSize()); | 1192 EXPECT_EQ(7u, nodes->GetSize()); |
| 1193 } | 1193 } |
| 1194 | 1194 |
| 1195 TEST_F(SyncManagerTest, GetChildNodeIdsFailure) { | 1195 TEST_F(SyncManagerTest, GetChildNodeIdsFailure) { |
| 1196 StrictMock<MockJsReplyHandler> reply_handler; | 1196 StrictMock<MockJsReplyHandler> reply_handler; |
| 1197 | 1197 |
| 1198 ListValue empty_list_args; | 1198 ListValue empty_list_args; |
| 1199 empty_list_args.Append(new ListValue()); | 1199 empty_list_args.Append(new ListValue()); |
| 1200 | 1200 |
| 1201 EXPECT_CALL(reply_handler, | 1201 EXPECT_CALL(reply_handler, |
| 1202 HandleJsReply("getChildNodeIds", | 1202 HandleJsReply("getChildNodeIds", |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1342 TriggerOnIncomingNotificationForTest(model_types); | 1342 TriggerOnIncomingNotificationForTest(model_types); |
| 1343 SetJsEventHandler(WeakHandle<JsEventHandler>()); | 1343 SetJsEventHandler(WeakHandle<JsEventHandler>()); |
| 1344 | 1344 |
| 1345 TriggerOnIncomingNotificationForTest(empty_model_types); | 1345 TriggerOnIncomingNotificationForTest(empty_model_types); |
| 1346 TriggerOnIncomingNotificationForTest(model_types); | 1346 TriggerOnIncomingNotificationForTest(model_types); |
| 1347 | 1347 |
| 1348 // Should trigger the replies. | 1348 // Should trigger the replies. |
| 1349 PumpLoop(); | 1349 PumpLoop(); |
| 1350 } | 1350 } |
| 1351 | 1351 |
| 1352 #if 0 // FIXME -> Move these | |
|
Nicolas Zea
2012/09/13 00:45:55
did you mean to leave this?
rlarocque
2012/09/14 01:03:07
Nope, that was a mistake. The tests have already
| |
| 1353 // New client scenario: set device info when no previous info existed. | |
| 1354 TEST_F(SyncManagerTest, CreateNewDeviceInfo) { | |
| 1355 UserShare* share = sync_manager_.GetUserShare(); | |
| 1356 const std::string version("v1"); | |
| 1357 const std::string session_name("session"); | |
| 1358 sync_pb::DeviceInfoSpecifics device_info; | |
| 1359 | |
| 1360 ASSERT_FALSE(GetDeviceInfo(share->directory.get(), &device_info)); | |
| 1361 | |
| 1362 UpdateDeviceInfo(version, session_name); | |
| 1363 | |
| 1364 ASSERT_TRUE(GetDeviceInfo(share->directory.get(), &device_info)); | |
| 1365 | |
| 1366 EXPECT_EQ(version, device_info.chrome_version()); | |
| 1367 EXPECT_EQ(session_name, device_info.name()); | |
| 1368 EXPECT_EQ(share->directory->cache_guid(), device_info.cache_guid()); | |
| 1369 } | |
| 1370 | |
| 1371 // Restart scenario: update existing device info with identical data. | |
| 1372 TEST_F(SyncManagerTest, DontModifyExistingDeviceInfo) { | |
| 1373 UserShare* share = sync_manager_.GetUserShare(); | |
| 1374 const std::string version("v1"); | |
| 1375 const std::string session_name("session"); | |
| 1376 sync_pb::DeviceInfoSpecifics old_device_info; | |
| 1377 sync_pb::DeviceInfoSpecifics new_device_info; | |
| 1378 | |
| 1379 UpdateDeviceInfo(version, session_name); | |
| 1380 ASSERT_TRUE(GetDeviceInfo(share->directory.get(), &old_device_info)); | |
| 1381 | |
| 1382 // Pretend we committed by unsetting all unsynced bits. | |
| 1383 share->directory->SetInvariantCheckLevel(syncable::OFF); | |
| 1384 { | |
| 1385 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, | |
| 1386 share->directory.get()); | |
| 1387 syncable::Directory::UnsyncedMetaHandles handles; | |
| 1388 share->directory->GetUnsyncedMetaHandles(&trans, &handles); | |
| 1389 | |
| 1390 for (syncable::Directory::UnsyncedMetaHandles::iterator it = | |
| 1391 handles.begin(); it != handles.end(); ++it) { | |
| 1392 syncable::MutableEntry entry(&trans, syncable::GET_BY_HANDLE, *it); | |
| 1393 entry.Put(syncable::IS_UNSYNCED, false); | |
| 1394 } | |
| 1395 | |
| 1396 ASSERT_EQ(0, share->directory->unsynced_entity_count()); | |
| 1397 } | |
| 1398 | |
| 1399 // Overwrite the device info with the same data as before. | |
| 1400 UpdateDeviceInfo(version, session_name); | |
| 1401 ASSERT_TRUE(GetDeviceInfo(share->directory.get(), &new_device_info)); | |
| 1402 | |
| 1403 // Ensure that this didn't count as a change worth syncing. | |
| 1404 EXPECT_EQ(0, share->directory->unsynced_entity_count()); | |
| 1405 EXPECT_EQ(old_device_info.SerializeAsString(), | |
| 1406 new_device_info.SerializeAsString()); | |
| 1407 | |
| 1408 EXPECT_EQ(old_device_info.chrome_version(), new_device_info.chrome_version()); | |
| 1409 EXPECT_EQ(old_device_info.name(), new_device_info.name()); | |
| 1410 EXPECT_EQ(old_device_info.cache_guid(), new_device_info.cache_guid()); | |
| 1411 } | |
| 1412 | |
| 1413 // Upgrade scenario: update existing device info with new version. | |
| 1414 TEST_F(SyncManagerTest, UpdateExistingDeviceInfo) { | |
| 1415 UserShare* share = sync_manager_.GetUserShare(); | |
| 1416 const std::string old_version("v1"); | |
| 1417 const std::string new_version("v2"); | |
| 1418 const std::string session_name("session"); | |
| 1419 sync_pb::DeviceInfoSpecifics device_info; | |
| 1420 | |
| 1421 UpdateDeviceInfo(old_version, session_name); | |
| 1422 UpdateDeviceInfo(new_version, session_name); | |
| 1423 | |
| 1424 GetDeviceInfo(share->directory.get(), &device_info); | |
| 1425 | |
| 1426 EXPECT_EQ(new_version, device_info.chrome_version()); | |
| 1427 } | |
| 1428 #endif | |
| 1429 | |
| 1352 TEST_F(SyncManagerTest, RefreshEncryptionReady) { | 1430 TEST_F(SyncManagerTest, RefreshEncryptionReady) { |
| 1353 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1431 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1354 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1432 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1355 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1433 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1356 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); | 1434 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); |
| 1357 | 1435 |
| 1358 sync_manager_.GetEncryptionHandler()->Init(); | 1436 sync_manager_.GetEncryptionHandler()->Init(); |
| 1359 PumpLoop(); | 1437 PumpLoop(); |
| 1360 | 1438 |
| 1361 const ModelTypeSet encrypted_types = GetEncryptedTypes(); | 1439 const ModelTypeSet encrypted_types = GetEncryptedTypes(); |
| (...skipping 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2886 | 2964 |
| 2887 // Verify only the non-disabled types remain after cleanup. | 2965 // Verify only the non-disabled types remain after cleanup. |
| 2888 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); | 2966 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); |
| 2889 EXPECT_TRUE(new_enabled_types.Equals( | 2967 EXPECT_TRUE(new_enabled_types.Equals( |
| 2890 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); | 2968 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); |
| 2891 EXPECT_TRUE(disabled_types.Equals( | 2969 EXPECT_TRUE(disabled_types.Equals( |
| 2892 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); | 2970 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); |
| 2893 } | 2971 } |
| 2894 | 2972 |
| 2895 } // namespace | 2973 } // namespace |
| OLD | NEW |