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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/format_macros.h" | 15 #include "base/format_macros.h" |
| 16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 19 #include "base/message_loop_proxy.h" | 19 #include "base/message_loop_proxy.h" |
| 20 #include "base/scoped_temp_dir.h" | 20 #include "base/scoped_temp_dir.h" |
| 21 #include "base/string_number_conversions.h" | 21 #include "base/string_number_conversions.h" |
| 22 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
| 23 #include "base/test/values_test_util.h" | 23 #include "base/test/values_test_util.h" |
| 24 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
| 25 #include "base/values.h" | 25 #include "base/values.h" |
| 26 #include "sync/engine/nigori_util.h" | 26 #include "sync/engine/nigori_util.h" |
| 27 #include "sync/engine/sync_scheduler.h" | |
| 27 #include "sync/internal_api/change_record.h" | 28 #include "sync/internal_api/change_record.h" |
| 28 #include "sync/internal_api/http_post_provider_factory.h" | 29 #include "sync/internal_api/http_post_provider_factory.h" |
| 29 #include "sync/internal_api/http_post_provider_interface.h" | 30 #include "sync/internal_api/http_post_provider_interface.h" |
| 30 #include "sync/internal_api/public/engine/model_safe_worker.h" | 31 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 31 #include "sync/internal_api/public/engine/polling_constants.h" | 32 #include "sync/internal_api/public/engine/polling_constants.h" |
| 32 #include "sync/internal_api/public/syncable/model_type_test_util.h" | 33 #include "sync/internal_api/public/syncable/model_type_test_util.h" |
| 33 #include "sync/internal_api/read_node.h" | 34 #include "sync/internal_api/read_node.h" |
| 34 #include "sync/internal_api/read_transaction.h" | 35 #include "sync/internal_api/read_transaction.h" |
| 35 #include "sync/internal_api/sync_manager.h" | 36 #include "sync/internal_api/sync_manager.h" |
| 36 #include "sync/internal_api/syncapi_internal.h" | 37 #include "sync/internal_api/syncapi_internal.h" |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 713 MOCK_METHOD1(RemoveObserver, void(sync_notifier::SyncNotifierObserver*)); | 714 MOCK_METHOD1(RemoveObserver, void(sync_notifier::SyncNotifierObserver*)); |
| 714 MOCK_METHOD1(SetUniqueId, void(const std::string&)); | 715 MOCK_METHOD1(SetUniqueId, void(const std::string&)); |
| 715 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); | 716 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); |
| 716 MOCK_METHOD2(UpdateCredentials, | 717 MOCK_METHOD2(UpdateCredentials, |
| 717 void(const std::string&, const std::string&)); | 718 void(const std::string&, const std::string&)); |
| 718 MOCK_METHOD1(UpdateEnabledTypes, | 719 MOCK_METHOD1(UpdateEnabledTypes, |
| 719 void(syncable::ModelTypeSet)); | 720 void(syncable::ModelTypeSet)); |
| 720 MOCK_METHOD1(SendNotification, void(syncable::ModelTypeSet)); | 721 MOCK_METHOD1(SendNotification, void(syncable::ModelTypeSet)); |
| 721 }; | 722 }; |
| 722 | 723 |
| 724 class TestSyncManager : public SyncManager { | |
| 725 public: | |
| 726 TestSyncManager() | |
| 727 : SyncManager("Test sync manager"), | |
| 728 result_(true) {} | |
| 729 | |
| 730 browser_sync::ConfigureParams get_config_params() const { return params_; } | |
| 731 void set_config_result(bool result) { result_ = result; } | |
| 732 | |
| 733 protected: | |
| 734 // SyncManager implementation. | |
| 735 virtual bool DoConfigureSyncer( | |
| 736 const browser_sync::ConfigureParams& params) OVERRIDE { | |
| 737 params_ = params; | |
| 738 if (params.ready_task.is_null()) { | |
| 739 ADD_FAILURE(); | |
| 740 return result_; | |
| 741 } | |
| 742 | |
| 743 if (result_) | |
| 744 params.ready_task.Run(); | |
| 745 return result_; | |
| 746 } | |
| 747 | |
| 748 private: | |
| 749 browser_sync::ConfigureParams params_; | |
| 750 bool result_; | |
| 751 }; | |
| 752 | |
| 723 } // namespace | 753 } // namespace |
| 724 | 754 |
| 725 class SyncManagerTest : public testing::Test, | 755 class SyncManagerTest : public testing::Test, |
| 726 public SyncManager::ChangeDelegate { | 756 public SyncManager::ChangeDelegate { |
| 727 protected: | 757 protected: |
| 728 enum NigoriStatus { | 758 enum NigoriStatus { |
| 729 DONT_WRITE_NIGORI, | 759 DONT_WRITE_NIGORI, |
| 730 WRITE_TO_NIGORI | 760 WRITE_TO_NIGORI |
| 731 }; | 761 }; |
| 732 | 762 |
| 733 enum EncryptionStatus { | 763 enum EncryptionStatus { |
| 734 UNINITIALIZED, | 764 UNINITIALIZED, |
| 735 DEFAULT_ENCRYPTION, | 765 DEFAULT_ENCRYPTION, |
| 736 FULL_ENCRYPTION | 766 FULL_ENCRYPTION |
| 737 }; | 767 }; |
| 738 | 768 |
| 739 SyncManagerTest() | 769 SyncManagerTest() |
| 740 : sync_notifier_mock_(NULL), | 770 : sync_notifier_mock_(NULL), |
| 741 sync_manager_("Test sync manager"), | |
| 742 sync_notifier_observer_(NULL), | 771 sync_notifier_observer_(NULL), |
| 743 update_enabled_types_call_count_(0) {} | 772 update_enabled_types_call_count_(0) {} |
| 744 | 773 |
| 745 virtual ~SyncManagerTest() { | 774 virtual ~SyncManagerTest() { |
| 746 EXPECT_FALSE(sync_notifier_mock_); | 775 EXPECT_FALSE(sync_notifier_mock_); |
| 747 } | 776 } |
| 748 | 777 |
| 749 // Test implementation. | 778 // Test implementation. |
| 750 void SetUp() { | 779 void SetUp() { |
| 751 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 780 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 // Needed by |sync_manager_|. | 961 // Needed by |sync_manager_|. |
| 933 ScopedTempDir temp_dir_; | 962 ScopedTempDir temp_dir_; |
| 934 // Sync Id's for the roots of the enabled datatypes. | 963 // Sync Id's for the roots of the enabled datatypes. |
| 935 std::map<ModelType, int64> type_roots_; | 964 std::map<ModelType, int64> type_roots_; |
| 936 FakeExtensionsActivityMonitor extensions_activity_monitor_; | 965 FakeExtensionsActivityMonitor extensions_activity_monitor_; |
| 937 StrictMock<SyncNotifierMock>* sync_notifier_mock_; | 966 StrictMock<SyncNotifierMock>* sync_notifier_mock_; |
| 938 | 967 |
| 939 protected: | 968 protected: |
| 940 FakeEncryptor encryptor_; | 969 FakeEncryptor encryptor_; |
| 941 TestUnrecoverableErrorHandler handler_; | 970 TestUnrecoverableErrorHandler handler_; |
| 942 SyncManager sync_manager_; | 971 TestSyncManager sync_manager_; |
| 943 WeakHandle<JsBackend> js_backend_; | 972 WeakHandle<JsBackend> js_backend_; |
| 944 StrictMock<SyncManagerObserverMock> observer_; | 973 StrictMock<SyncManagerObserverMock> observer_; |
| 945 sync_notifier::SyncNotifierObserver* sync_notifier_observer_; | 974 sync_notifier::SyncNotifierObserver* sync_notifier_observer_; |
| 946 int update_enabled_types_call_count_; | 975 int update_enabled_types_call_count_; |
| 947 }; | 976 }; |
| 948 | 977 |
| 949 TEST_F(SyncManagerTest, UpdateEnabledTypes) { | 978 TEST_F(SyncManagerTest, UpdateEnabledTypes) { |
| 950 EXPECT_EQ(0, update_enabled_types_call_count_); | 979 EXPECT_EQ(0, update_enabled_types_call_count_); |
| 951 | 980 |
| 952 ModelSafeRoutingInfo routes; | 981 ModelSafeRoutingInfo routes; |
| (...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2500 node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); | 2529 node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); |
| 2501 EXPECT_EQ(title, node.GetTitle()); | 2530 EXPECT_EQ(title, node.GetTitle()); |
| 2502 EXPECT_EQ(GURL(url2), node.GetURL()); | 2531 EXPECT_EQ(GURL(url2), node.GetURL()); |
| 2503 const syncable::Entry* node_entry = node.GetEntry(); | 2532 const syncable::Entry* node_entry = node.GetEntry(); |
| 2504 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2533 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2505 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2534 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2506 EXPECT_TRUE(specifics.has_encrypted()); | 2535 EXPECT_TRUE(specifics.has_encrypted()); |
| 2507 } | 2536 } |
| 2508 } | 2537 } |
| 2509 | 2538 |
| 2539 namespace { | |
| 2540 void SetBool(bool* called) { | |
|
rlarocque
2012/06/09 01:44:35
Same comment as in the other file: I'd prefer to s
Nicolas Zea
2012/06/11 23:05:20
See other response.
| |
| 2541 *called = true; | |
| 2542 } | |
| 2543 } // namespace | |
| 2544 | |
| 2545 // Test that the configuration params are properly sent to DoConfigureSyncer. | |
| 2546 TEST_F(SyncManagerTest, BasicConfiguration) { | |
| 2547 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; | |
| 2548 syncable::ModelTypeSet types_to_config(syncable::BOOKMARKS, | |
| 2549 syncable::PREFERENCES); | |
| 2550 browser_sync::ModelSafeRoutingInfo new_routing_info; | |
| 2551 GetModelSafeRoutingInfo(&new_routing_info); | |
| 2552 sync_manager_.set_config_result(true); | |
| 2553 | |
| 2554 bool ready_task = false; | |
| 2555 bool retry_task = false; | |
| 2556 sync_manager_.ConfigureSyncer(reason, | |
| 2557 types_to_config, | |
| 2558 new_routing_info, | |
| 2559 base::Bind(&SetBool, &ready_task), | |
| 2560 base::Bind(&SetBool, &retry_task)); | |
| 2561 EXPECT_TRUE(ready_task); | |
| 2562 EXPECT_FALSE(retry_task); | |
| 2563 browser_sync::ConfigureParams params = sync_manager_.get_config_params(); | |
| 2564 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, | |
| 2565 params.source); | |
| 2566 EXPECT_TRUE(types_to_config.Equals(params.types_to_config)); | |
| 2567 EXPECT_EQ(new_routing_info, params.routing_info); | |
| 2568 } | |
| 2569 | |
| 2570 // Test that the retry callback is invoked on configuration failure. | |
| 2571 TEST_F(SyncManagerTest, ConfigurationRetry) { | |
| 2572 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; | |
| 2573 syncable::ModelTypeSet types_to_config(syncable::BOOKMARKS, | |
| 2574 syncable::PREFERENCES); | |
| 2575 browser_sync::ModelSafeRoutingInfo new_routing_info; | |
| 2576 GetModelSafeRoutingInfo(&new_routing_info); | |
| 2577 sync_manager_.set_config_result(false); | |
| 2578 | |
| 2579 bool ready_task = false; | |
| 2580 bool retry_task = false; | |
| 2581 sync_manager_.ConfigureSyncer(reason, | |
| 2582 types_to_config, | |
| 2583 new_routing_info, | |
| 2584 base::Bind(&SetBool, &ready_task), | |
| 2585 base::Bind(&SetBool, &retry_task)); | |
| 2586 EXPECT_FALSE(ready_task); | |
| 2587 EXPECT_TRUE(retry_task); | |
| 2588 browser_sync::ConfigureParams params = sync_manager_.get_config_params(); | |
| 2589 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, | |
| 2590 params.source); | |
| 2591 EXPECT_TRUE(types_to_config.Equals(params.types_to_config)); | |
| 2592 EXPECT_EQ(new_routing_info, params.routing_info); | |
| 2593 } | |
| 2594 | |
| 2510 } // namespace browser_sync | 2595 } // namespace browser_sync |
| OLD | NEW |