Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Side by Side Diff: sync/internal_api/sync_manager_impl_unittest.cc

Issue 17911005: Merge 208347 "Revert 208315 "Make use of InvalidationService"" (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1547/src/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/internal_api/sync_manager_impl.cc ('k') | sync/internal_api/test/fake_sync_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 28 matching lines...) Expand all
39 #include "sync/internal_api/public/write_transaction.h" 39 #include "sync/internal_api/public/write_transaction.h"
40 #include "sync/internal_api/sync_encryption_handler_impl.h" 40 #include "sync/internal_api/sync_encryption_handler_impl.h"
41 #include "sync/internal_api/sync_manager_impl.h" 41 #include "sync/internal_api/sync_manager_impl.h"
42 #include "sync/internal_api/syncapi_internal.h" 42 #include "sync/internal_api/syncapi_internal.h"
43 #include "sync/js/js_arg_list.h" 43 #include "sync/js/js_arg_list.h"
44 #include "sync/js/js_backend.h" 44 #include "sync/js/js_backend.h"
45 #include "sync/js/js_event_handler.h" 45 #include "sync/js/js_event_handler.h"
46 #include "sync/js/js_reply_handler.h" 46 #include "sync/js/js_reply_handler.h"
47 #include "sync/js/js_test_util.h" 47 #include "sync/js/js_test_util.h"
48 #include "sync/notifier/fake_invalidation_handler.h" 48 #include "sync/notifier/fake_invalidation_handler.h"
49 #include "sync/notifier/fake_invalidator.h"
49 #include "sync/notifier/invalidation_handler.h" 50 #include "sync/notifier/invalidation_handler.h"
50 #include "sync/notifier/invalidator.h" 51 #include "sync/notifier/invalidator.h"
51 #include "sync/protocol/bookmark_specifics.pb.h" 52 #include "sync/protocol/bookmark_specifics.pb.h"
52 #include "sync/protocol/encryption.pb.h" 53 #include "sync/protocol/encryption.pb.h"
53 #include "sync/protocol/extension_specifics.pb.h" 54 #include "sync/protocol/extension_specifics.pb.h"
54 #include "sync/protocol/password_specifics.pb.h" 55 #include "sync/protocol/password_specifics.pb.h"
55 #include "sync/protocol/preference_specifics.pb.h" 56 #include "sync/protocol/preference_specifics.pb.h"
56 #include "sync/protocol/proto_value_conversions.h" 57 #include "sync/protocol/proto_value_conversions.h"
57 #include "sync/protocol/sync.pb.h" 58 #include "sync/protocol/sync.pb.h"
58 #include "sync/sessions/sync_session.h" 59 #include "sync/sessions/sync_session.h"
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 WRITE_TO_NIGORI 782 WRITE_TO_NIGORI
782 }; 783 };
783 784
784 enum EncryptionStatus { 785 enum EncryptionStatus {
785 UNINITIALIZED, 786 UNINITIALIZED,
786 DEFAULT_ENCRYPTION, 787 DEFAULT_ENCRYPTION,
787 FULL_ENCRYPTION 788 FULL_ENCRYPTION
788 }; 789 };
789 790
790 SyncManagerTest() 791 SyncManagerTest()
791 : sync_manager_("Test sync manager") { 792 : fake_invalidator_(NULL),
793 sync_manager_("Test sync manager") {
792 switches_.encryption_method = 794 switches_.encryption_method =
793 InternalComponentsFactory::ENCRYPTION_KEYSTORE; 795 InternalComponentsFactory::ENCRYPTION_KEYSTORE;
794 } 796 }
795 797
796 virtual ~SyncManagerTest() { 798 virtual ~SyncManagerTest() {
799 EXPECT_FALSE(fake_invalidator_);
797 } 800 }
798 801
799 // Test implementation. 802 // Test implementation.
800 void SetUp() { 803 void SetUp() {
801 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 804 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
802 805
803 SyncCredentials credentials; 806 SyncCredentials credentials;
804 credentials.email = "foo@bar.com"; 807 credentials.email = "foo@bar.com";
805 credentials.sync_token = "sometoken"; 808 credentials.sync_token = "sometoken";
806 809
810 fake_invalidator_ = new FakeInvalidator();
811
807 sync_manager_.AddObserver(&manager_observer_); 812 sync_manager_.AddObserver(&manager_observer_);
808 EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _, _)). 813 EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _, _)).
809 WillOnce(SaveArg<0>(&js_backend_)); 814 WillOnce(SaveArg<0>(&js_backend_));
810 815
811 EXPECT_FALSE(js_backend_.IsInitialized()); 816 EXPECT_FALSE(js_backend_.IsInitialized());
812 817
813 std::vector<ModelSafeWorker*> workers; 818 std::vector<ModelSafeWorker*> workers;
814 ModelSafeRoutingInfo routing_info; 819 ModelSafeRoutingInfo routing_info;
815 GetModelSafeRoutingInfo(&routing_info); 820 GetModelSafeRoutingInfo(&routing_info);
816 821
817 // Takes ownership of |fake_invalidator_|. 822 // Takes ownership of |fake_invalidator_|.
818 sync_manager_.Init( 823 sync_manager_.Init(
819 temp_dir_.path(), 824 temp_dir_.path(),
820 WeakHandle<JsEventHandler>(), 825 WeakHandle<JsEventHandler>(),
821 "bogus", 826 "bogus",
822 0, 827 0,
823 false, 828 false,
824 scoped_ptr<HttpPostProviderFactory>(new TestHttpPostProviderFactory()), 829 scoped_ptr<HttpPostProviderFactory>(new TestHttpPostProviderFactory()),
825 workers, 830 workers,
826 &extensions_activity_monitor_, 831 &extensions_activity_monitor_,
827 this, 832 this,
828 credentials, 833 credentials,
834 scoped_ptr<Invalidator>(fake_invalidator_),
829 "fake_invalidator_client_id", 835 "fake_invalidator_client_id",
830 std::string(), 836 std::string(),
831 std::string(), // bootstrap tokens 837 std::string(), // bootstrap tokens
832 scoped_ptr<InternalComponentsFactory>(GetFactory()), 838 scoped_ptr<InternalComponentsFactory>(GetFactory()),
833 &encryptor_, 839 &encryptor_,
834 &handler_, 840 &handler_,
835 NULL, 841 NULL,
836 false); 842 false);
837 843
838 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); 844 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_);
839 845
840 EXPECT_TRUE(js_backend_.IsInitialized()); 846 EXPECT_TRUE(js_backend_.IsInitialized());
841 847
842 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); 848 for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
843 i != routing_info.end(); ++i) { 849 i != routing_info.end(); ++i) {
844 type_roots_[i->first] = MakeServerNodeForType( 850 type_roots_[i->first] = MakeServerNodeForType(
845 sync_manager_.GetUserShare(), i->first); 851 sync_manager_.GetUserShare(), i->first);
846 } 852 }
847 PumpLoop(); 853 PumpLoop();
854
855 EXPECT_TRUE(fake_invalidator_->IsHandlerRegistered(&sync_manager_));
848 } 856 }
849 857
850 void TearDown() { 858 void TearDown() {
851 sync_manager_.RemoveObserver(&manager_observer_); 859 sync_manager_.RemoveObserver(&manager_observer_);
852 sync_manager_.ShutdownOnSyncThread(); 860 sync_manager_.ShutdownOnSyncThread();
861 // We can't assert that |sync_manager_| isn't registered with
862 // |fake_invalidator_| anymore because |fake_invalidator_| is now
863 // destroyed.
864 fake_invalidator_ = NULL;
853 PumpLoop(); 865 PumpLoop();
854 } 866 }
855 867
856 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { 868 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) {
857 (*out)[NIGORI] = GROUP_PASSIVE; 869 (*out)[NIGORI] = GROUP_PASSIVE;
858 (*out)[DEVICE_INFO] = GROUP_PASSIVE; 870 (*out)[DEVICE_INFO] = GROUP_PASSIVE;
859 (*out)[EXPERIMENTS] = GROUP_PASSIVE; 871 (*out)[EXPERIMENTS] = GROUP_PASSIVE;
860 (*out)[BOOKMARKS] = GROUP_PASSIVE; 872 (*out)[BOOKMARKS] = GROUP_PASSIVE;
861 (*out)[THEMES] = GROUP_PASSIVE; 873 (*out)[THEMES] = GROUP_PASSIVE;
862 (*out)[SESSIONS] = GROUP_PASSIVE; 874 (*out)[SESSIONS] = GROUP_PASSIVE;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 base::MessageLoop message_loop_; 1020 base::MessageLoop message_loop_;
1009 // Needed by |sync_manager_|. 1021 // Needed by |sync_manager_|.
1010 base::ScopedTempDir temp_dir_; 1022 base::ScopedTempDir temp_dir_;
1011 // Sync Id's for the roots of the enabled datatypes. 1023 // Sync Id's for the roots of the enabled datatypes.
1012 std::map<ModelType, int64> type_roots_; 1024 std::map<ModelType, int64> type_roots_;
1013 FakeExtensionsActivityMonitor extensions_activity_monitor_; 1025 FakeExtensionsActivityMonitor extensions_activity_monitor_;
1014 1026
1015 protected: 1027 protected:
1016 FakeEncryptor encryptor_; 1028 FakeEncryptor encryptor_;
1017 TestUnrecoverableErrorHandler handler_; 1029 TestUnrecoverableErrorHandler handler_;
1030 FakeInvalidator* fake_invalidator_;
1018 SyncManagerImpl sync_manager_; 1031 SyncManagerImpl sync_manager_;
1019 WeakHandle<JsBackend> js_backend_; 1032 WeakHandle<JsBackend> js_backend_;
1020 StrictMock<SyncManagerObserverMock> manager_observer_; 1033 StrictMock<SyncManagerObserverMock> manager_observer_;
1021 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; 1034 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_;
1022 InternalComponentsFactory::Switches switches_; 1035 InternalComponentsFactory::Switches switches_;
1023 }; 1036 };
1024 1037
1038 TEST_F(SyncManagerTest, UpdateEnabledTypes) {
1039 ModelSafeRoutingInfo routes;
1040 GetModelSafeRoutingInfo(&routes);
1041 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes);
1042 sync_manager_.UpdateEnabledTypes(enabled_types);
1043 EXPECT_EQ(ModelTypeSetToObjectIdSet(enabled_types),
1044 fake_invalidator_->GetRegisteredIds(&sync_manager_));
1045 }
1046
1047 TEST_F(SyncManagerTest, RegisterInvalidationHandler) {
1048 FakeInvalidationHandler fake_handler;
1049 sync_manager_.RegisterInvalidationHandler(&fake_handler);
1050 EXPECT_TRUE(fake_invalidator_->IsHandlerRegistered(&fake_handler));
1051
1052 const ObjectIdSet& ids =
1053 ModelTypeSetToObjectIdSet(ModelTypeSet(BOOKMARKS, PREFERENCES));
1054 sync_manager_.UpdateRegisteredInvalidationIds(&fake_handler, ids);
1055 EXPECT_EQ(ids, fake_invalidator_->GetRegisteredIds(&fake_handler));
1056
1057 sync_manager_.UnregisterInvalidationHandler(&fake_handler);
1058 EXPECT_FALSE(fake_invalidator_->IsHandlerRegistered(&fake_handler));
1059 }
1060
1025 TEST_F(SyncManagerTest, ProcessJsMessage) { 1061 TEST_F(SyncManagerTest, ProcessJsMessage) {
1026 const JsArgList kNoArgs; 1062 const JsArgList kNoArgs;
1027 1063
1028 StrictMock<MockJsReplyHandler> reply_handler; 1064 StrictMock<MockJsReplyHandler> reply_handler;
1029 1065
1030 base::ListValue disabled_args; 1066 base::ListValue disabled_args;
1031 disabled_args.Append(new base::StringValue("TRANSIENT_INVALIDATION_ERROR")); 1067 disabled_args.Append(new base::StringValue("TRANSIENT_INVALIDATION_ERROR"));
1032 1068
1033 EXPECT_CALL(reply_handler, 1069 EXPECT_CALL(reply_handler,
1034 HandleJsReply("getNotificationState", 1070 HandleJsReply("getNotificationState",
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 base::DictionaryValue enabled_details; 1355 base::DictionaryValue enabled_details;
1320 enabled_details.SetString("state", "INVALIDATIONS_ENABLED"); 1356 enabled_details.SetString("state", "INVALIDATIONS_ENABLED");
1321 base::DictionaryValue credentials_rejected_details; 1357 base::DictionaryValue credentials_rejected_details;
1322 credentials_rejected_details.SetString( 1358 credentials_rejected_details.SetString(
1323 "state", "INVALIDATION_CREDENTIALS_REJECTED"); 1359 "state", "INVALIDATION_CREDENTIALS_REJECTED");
1324 base::DictionaryValue transient_error_details; 1360 base::DictionaryValue transient_error_details;
1325 transient_error_details.SetString("state", "TRANSIENT_INVALIDATION_ERROR"); 1361 transient_error_details.SetString("state", "TRANSIENT_INVALIDATION_ERROR");
1326 base::DictionaryValue auth_error_details; 1362 base::DictionaryValue auth_error_details;
1327 auth_error_details.SetString("status", "CONNECTION_AUTH_ERROR"); 1363 auth_error_details.SetString("status", "CONNECTION_AUTH_ERROR");
1328 1364
1365 EXPECT_CALL(manager_observer_,
1366 OnConnectionStatusChange(CONNECTION_AUTH_ERROR));
1367
1368 EXPECT_CALL(
1369 event_handler,
1370 HandleJsEvent("onConnectionStatusChange",
1371 HasDetailsAsDictionary(auth_error_details)));
1372
1329 EXPECT_CALL(event_handler, 1373 EXPECT_CALL(event_handler,
1330 HandleJsEvent("onNotificationStateChange", 1374 HandleJsEvent("onNotificationStateChange",
1331 HasDetailsAsDictionary(enabled_details))); 1375 HasDetailsAsDictionary(enabled_details)));
1332 1376
1333 EXPECT_CALL( 1377 EXPECT_CALL(
1334 event_handler, 1378 event_handler,
1335 HandleJsEvent("onNotificationStateChange", 1379 HandleJsEvent("onNotificationStateChange",
1336 HasDetailsAsDictionary(credentials_rejected_details))) 1380 HasDetailsAsDictionary(credentials_rejected_details)))
1337 .Times(2); 1381 .Times(2);
1338 1382
(...skipping 20 matching lines...) Expand all
1359 SetJsEventHandler(WeakHandle<JsEventHandler>()); 1403 SetJsEventHandler(WeakHandle<JsEventHandler>());
1360 1404
1361 SimulateInvalidatorStateChangeForTest(INVALIDATIONS_ENABLED); 1405 SimulateInvalidatorStateChangeForTest(INVALIDATIONS_ENABLED);
1362 SimulateInvalidatorStateChangeForTest(INVALIDATION_CREDENTIALS_REJECTED); 1406 SimulateInvalidatorStateChangeForTest(INVALIDATION_CREDENTIALS_REJECTED);
1363 SimulateInvalidatorStateChangeForTest(TRANSIENT_INVALIDATION_ERROR); 1407 SimulateInvalidatorStateChangeForTest(TRANSIENT_INVALIDATION_ERROR);
1364 1408
1365 // Should trigger the replies. 1409 // Should trigger the replies.
1366 PumpLoop(); 1410 PumpLoop();
1367 } 1411 }
1368 1412
1413 // Simulate the invalidator's credentials being rejected. That should
1414 // also clear the sync token.
1415 TEST_F(SyncManagerTest, OnInvalidatorStateChangeCredentialsRejected) {
1416 EXPECT_CALL(manager_observer_,
1417 OnConnectionStatusChange(CONNECTION_AUTH_ERROR));
1418
1419 EXPECT_FALSE(sync_manager_.GetHasInvalidAuthTokenForTest());
1420
1421 SimulateInvalidatorStateChangeForTest(INVALIDATION_CREDENTIALS_REJECTED);
1422
1423 EXPECT_TRUE(sync_manager_.GetHasInvalidAuthTokenForTest());
1424
1425 // Should trigger the replies.
1426 PumpLoop();
1427 }
1428
1369 TEST_F(SyncManagerTest, OnIncomingNotification) { 1429 TEST_F(SyncManagerTest, OnIncomingNotification) {
1370 StrictMock<MockJsEventHandler> event_handler; 1430 StrictMock<MockJsEventHandler> event_handler;
1371 1431
1372 const ModelTypeSet empty_model_types; 1432 const ModelTypeSet empty_model_types;
1373 const ModelTypeSet model_types( 1433 const ModelTypeSet model_types(
1374 BOOKMARKS, THEMES); 1434 BOOKMARKS, THEMES);
1375 1435
1376 // Build expected_args to have a single argument with the string 1436 // Build expected_args to have a single argument with the string
1377 // equivalents of model_types. 1437 // equivalents of model_types.
1378 base::DictionaryValue expected_details; 1438 base::DictionaryValue expected_details;
(...skipping 2127 matching lines...) Expand 10 before | Expand all | Expand 10 after
3506 size_t folder_b_pos = 3566 size_t folder_b_pos =
3507 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); 3567 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE);
3508 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); 3568 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE);
3509 3569
3510 // Deletes should appear before updates. 3570 // Deletes should appear before updates.
3511 EXPECT_LT(child_pos, folder_a_pos); 3571 EXPECT_LT(child_pos, folder_a_pos);
3512 EXPECT_LT(folder_b_pos, folder_a_pos); 3572 EXPECT_LT(folder_b_pos, folder_a_pos);
3513 } 3573 }
3514 3574
3515 } // namespace 3575 } // namespace
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager_impl.cc ('k') | sync/internal_api/test/fake_sync_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698