| 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 14 matching lines...) Expand all Loading... |
| 25 #include "base/values.h" | 25 #include "base/values.h" |
| 26 #include "sync/internal_api/public/base/model_type_test_util.h" | 26 #include "sync/internal_api/public/base/model_type_test_util.h" |
| 27 #include "sync/engine/sync_scheduler.h" | 27 #include "sync/engine/sync_scheduler.h" |
| 28 #include "sync/internal_api/public/change_record.h" | 28 #include "sync/internal_api/public/change_record.h" |
| 29 #include "sync/internal_api/public/engine/model_safe_worker.h" | 29 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 30 #include "sync/internal_api/public/engine/polling_constants.h" | 30 #include "sync/internal_api/public/engine/polling_constants.h" |
| 31 #include "sync/internal_api/public/http_post_provider_factory.h" | 31 #include "sync/internal_api/public/http_post_provider_factory.h" |
| 32 #include "sync/internal_api/public/http_post_provider_interface.h" | 32 #include "sync/internal_api/public/http_post_provider_interface.h" |
| 33 #include "sync/internal_api/public/read_node.h" | 33 #include "sync/internal_api/public/read_node.h" |
| 34 #include "sync/internal_api/public/read_transaction.h" | 34 #include "sync/internal_api/public/read_transaction.h" |
| 35 #include "sync/internal_api/public/sync_manager.h" | |
| 36 #include "sync/internal_api/public/test/test_user_share.h" | 35 #include "sync/internal_api/public/test/test_user_share.h" |
| 37 #include "sync/internal_api/public/write_node.h" | 36 #include "sync/internal_api/public/write_node.h" |
| 38 #include "sync/internal_api/public/write_transaction.h" | 37 #include "sync/internal_api/public/write_transaction.h" |
| 39 #include "sync/internal_api/syncapi_internal.h" | 38 #include "sync/internal_api/syncapi_internal.h" |
| 39 #include "sync/internal_api/sync_manager_impl.h" |
| 40 #include "sync/js/js_arg_list.h" | 40 #include "sync/js/js_arg_list.h" |
| 41 #include "sync/js/js_backend.h" | 41 #include "sync/js/js_backend.h" |
| 42 #include "sync/js/js_event_handler.h" | 42 #include "sync/js/js_event_handler.h" |
| 43 #include "sync/js/js_reply_handler.h" | 43 #include "sync/js/js_reply_handler.h" |
| 44 #include "sync/js/js_test_util.h" | 44 #include "sync/js/js_test_util.h" |
| 45 #include "sync/notifier/sync_notifier.h" | 45 #include "sync/notifier/sync_notifier.h" |
| 46 #include "sync/notifier/sync_notifier_observer.h" | 46 #include "sync/notifier/sync_notifier_observer.h" |
| 47 #include "sync/protocol/bookmark_specifics.pb.h" | 47 #include "sync/protocol/bookmark_specifics.pb.h" |
| 48 #include "sync/protocol/encryption.pb.h" | 48 #include "sync/protocol/encryption.pb.h" |
| 49 #include "sync/protocol/extension_specifics.pb.h" | 49 #include "sync/protocol/extension_specifics.pb.h" |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 | 761 |
| 762 std::vector<ModelSafeWorker*> workers; | 762 std::vector<ModelSafeWorker*> workers; |
| 763 ModelSafeRoutingInfo routing_info; | 763 ModelSafeRoutingInfo routing_info; |
| 764 GetModelSafeRoutingInfo(&routing_info); | 764 GetModelSafeRoutingInfo(&routing_info); |
| 765 | 765 |
| 766 // Takes ownership of |sync_notifier_mock_|. | 766 // Takes ownership of |sync_notifier_mock_|. |
| 767 sync_manager_.Init(temp_dir_.path(), | 767 sync_manager_.Init(temp_dir_.path(), |
| 768 WeakHandle<JsEventHandler>(), | 768 WeakHandle<JsEventHandler>(), |
| 769 "bogus", 0, false, | 769 "bogus", 0, false, |
| 770 base::MessageLoopProxy::current(), | 770 base::MessageLoopProxy::current(), |
| 771 new TestHttpPostProviderFactory(), routing_info, workers, | 771 scoped_ptr<HttpPostProviderFactory>( |
| 772 new TestHttpPostProviderFactory()), |
| 773 routing_info, workers, |
| 772 &extensions_activity_monitor_, this, | 774 &extensions_activity_monitor_, this, |
| 773 credentials, | 775 credentials, |
| 774 sync_notifier_mock_, "", | 776 scoped_ptr<SyncNotifier>(sync_notifier_mock_), |
| 777 "", |
| 775 syncer::SyncManager::TEST_IN_MEMORY, | 778 syncer::SyncManager::TEST_IN_MEMORY, |
| 776 &encryptor_, | 779 &encryptor_, |
| 777 &handler_, | 780 &handler_, |
| 778 NULL); | 781 NULL); |
| 779 | 782 |
| 780 EXPECT_TRUE(sync_notifier_observer_); | 783 EXPECT_TRUE(sync_notifier_observer_); |
| 781 EXPECT_TRUE(js_backend_.IsInitialized()); | 784 EXPECT_TRUE(js_backend_.IsInitialized()); |
| 782 | 785 |
| 783 EXPECT_EQ(0, update_enabled_types_call_count_); | 786 EXPECT_EQ(0, update_enabled_types_call_count_); |
| 784 | 787 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 // Needed by |sync_manager_|. | 923 // Needed by |sync_manager_|. |
| 921 ScopedTempDir temp_dir_; | 924 ScopedTempDir temp_dir_; |
| 922 // Sync Id's for the roots of the enabled datatypes. | 925 // Sync Id's for the roots of the enabled datatypes. |
| 923 std::map<ModelType, int64> type_roots_; | 926 std::map<ModelType, int64> type_roots_; |
| 924 FakeExtensionsActivityMonitor extensions_activity_monitor_; | 927 FakeExtensionsActivityMonitor extensions_activity_monitor_; |
| 925 StrictMock<SyncNotifierMock>* sync_notifier_mock_; | 928 StrictMock<SyncNotifierMock>* sync_notifier_mock_; |
| 926 | 929 |
| 927 protected: | 930 protected: |
| 928 FakeEncryptor encryptor_; | 931 FakeEncryptor encryptor_; |
| 929 TestUnrecoverableErrorHandler handler_; | 932 TestUnrecoverableErrorHandler handler_; |
| 930 SyncManager sync_manager_; | 933 SyncManagerImpl sync_manager_; |
| 931 WeakHandle<JsBackend> js_backend_; | 934 WeakHandle<JsBackend> js_backend_; |
| 932 StrictMock<SyncManagerObserverMock> observer_; | 935 StrictMock<SyncManagerObserverMock> observer_; |
| 933 syncer::SyncNotifierObserver* sync_notifier_observer_; | 936 syncer::SyncNotifierObserver* sync_notifier_observer_; |
| 934 int update_enabled_types_call_count_; | 937 int update_enabled_types_call_count_; |
| 935 }; | 938 }; |
| 936 | 939 |
| 937 TEST_F(SyncManagerTest, UpdateEnabledTypes) { | 940 TEST_F(SyncManagerTest, UpdateEnabledTypes) { |
| 938 EXPECT_EQ(0, update_enabled_types_call_count_); | 941 EXPECT_EQ(0, update_enabled_types_call_count_); |
| 939 | 942 |
| 940 ModelSafeRoutingInfo routes; | 943 ModelSafeRoutingInfo routes; |
| (...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1816 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1819 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1817 ReadNode password_node(&trans); | 1820 ReadNode password_node(&trans); |
| 1818 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, | 1821 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, |
| 1819 password_node.InitByIdLookup(node_id)); | 1822 password_node.InitByIdLookup(node_id)); |
| 1820 } | 1823 } |
| 1821 } | 1824 } |
| 1822 | 1825 |
| 1823 TEST_F(SyncManagerTest, NudgeDelayTest) { | 1826 TEST_F(SyncManagerTest, NudgeDelayTest) { |
| 1824 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(syncer::BOOKMARKS), | 1827 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(syncer::BOOKMARKS), |
| 1825 base::TimeDelta::FromMilliseconds( | 1828 base::TimeDelta::FromMilliseconds( |
| 1826 SyncManager::kDefaultNudgeDelayMilliseconds)); | 1829 SyncManagerImpl::GetDefaultNudgeDelay())); |
| 1827 | 1830 |
| 1828 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(syncer::AUTOFILL), | 1831 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(syncer::AUTOFILL), |
| 1829 base::TimeDelta::FromSeconds( | 1832 base::TimeDelta::FromSeconds( |
| 1830 syncer::kDefaultShortPollIntervalSeconds)); | 1833 syncer::kDefaultShortPollIntervalSeconds)); |
| 1831 | 1834 |
| 1832 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(syncer::PREFERENCES), | 1835 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(syncer::PREFERENCES), |
| 1833 base::TimeDelta::FromMilliseconds( | 1836 base::TimeDelta::FromMilliseconds( |
| 1834 SyncManager::kPreferencesNudgeDelayMilliseconds)); | 1837 SyncManagerImpl::GetPreferencesNudgeDelay())); |
| 1835 } | 1838 } |
| 1836 | 1839 |
| 1837 // Friended by WriteNode, so can't be in an anonymouse namespace. | 1840 // Friended by WriteNode, so can't be in an anonymouse namespace. |
| 1838 TEST_F(SyncManagerTest, EncryptBookmarksWithLegacyData) { | 1841 TEST_F(SyncManagerTest, EncryptBookmarksWithLegacyData) { |
| 1839 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1842 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1840 std::string title; | 1843 std::string title; |
| 1841 SyncAPINameToServerName("Google", &title); | 1844 SyncAPINameToServerName("Google", &title); |
| 1842 std::string url = "http://www.google.com"; | 1845 std::string url = "http://www.google.com"; |
| 1843 std::string raw_title2 = ".."; // An invalid cosmo title. | 1846 std::string raw_title2 = ".."; // An invalid cosmo title. |
| 1844 std::string title2; | 1847 std::string title2; |
| (...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2603 // Ensure only bookmarks and nigori lost their progress marker. Preferences | 2606 // Ensure only bookmarks and nigori lost their progress marker. Preferences |
| 2604 // should still have it. | 2607 // should still have it. |
| 2605 partial_types = | 2608 partial_types = |
| 2606 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()); | 2609 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()); |
| 2607 EXPECT_TRUE(partial_types.Has(NIGORI)); | 2610 EXPECT_TRUE(partial_types.Has(NIGORI)); |
| 2608 EXPECT_TRUE(partial_types.Has(BOOKMARKS)); | 2611 EXPECT_TRUE(partial_types.Has(BOOKMARKS)); |
| 2609 EXPECT_FALSE(partial_types.Has(PREFERENCES)); | 2612 EXPECT_FALSE(partial_types.Has(PREFERENCES)); |
| 2610 } | 2613 } |
| 2611 | 2614 |
| 2612 } // namespace | 2615 } // namespace |
| OLD | NEW |