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 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT | 683 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT |
684 MOCK_METHOD2(OnEncryptedTypesChanged, | 684 MOCK_METHOD2(OnEncryptedTypesChanged, |
685 void(ModelTypeSet, bool)); // NOLINT | 685 void(ModelTypeSet, bool)); // NOLINT |
686 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT | 686 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT |
687 MOCK_METHOD1(OnActionableError, | 687 MOCK_METHOD1(OnActionableError, |
688 void(const syncer::SyncProtocolError&)); // NOLINT | 688 void(const syncer::SyncProtocolError&)); // NOLINT |
689 }; | 689 }; |
690 | 690 |
691 class SyncNotifierMock : public syncer::SyncNotifier { | 691 class SyncNotifierMock : public syncer::SyncNotifier { |
692 public: | 692 public: |
693 MOCK_METHOD1(AddObserver, void(syncer::SyncNotifierObserver*)); | 693 MOCK_METHOD1(AddHandler, void(syncer::SyncNotifierObserver*)); |
694 MOCK_METHOD1(RemoveObserver, void(syncer::SyncNotifierObserver*)); | 694 MOCK_METHOD1(RemoveHandler, void(syncer::SyncNotifierObserver*)); |
| 695 MOCK_METHOD0(ReloadHandlers, void()); |
695 MOCK_METHOD1(SetUniqueId, void(const std::string&)); | 696 MOCK_METHOD1(SetUniqueId, void(const std::string&)); |
696 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); | 697 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); |
697 MOCK_METHOD2(UpdateCredentials, | 698 MOCK_METHOD2(UpdateCredentials, |
698 void(const std::string&, const std::string&)); | 699 void(const std::string&, const std::string&)); |
699 MOCK_METHOD1(UpdateEnabledTypes, | |
700 void(syncer::ModelTypeSet)); | |
701 MOCK_METHOD1(SendNotification, void(syncer::ModelTypeSet)); | 700 MOCK_METHOD1(SendNotification, void(syncer::ModelTypeSet)); |
702 }; | 701 }; |
703 | 702 |
704 } // namespace | 703 } // namespace |
705 | 704 |
706 class SyncManagerTest : public testing::Test, | 705 class SyncManagerTest : public testing::Test, |
707 public SyncManager::ChangeDelegate { | 706 public SyncManager::ChangeDelegate { |
708 protected: | 707 protected: |
709 enum NigoriStatus { | 708 enum NigoriStatus { |
710 DONT_WRITE_NIGORI, | 709 DONT_WRITE_NIGORI, |
(...skipping 18 matching lines...) Expand all Loading... |
729 | 728 |
730 // Test implementation. | 729 // Test implementation. |
731 void SetUp() { | 730 void SetUp() { |
732 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 731 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
733 | 732 |
734 SyncCredentials credentials; | 733 SyncCredentials credentials; |
735 credentials.email = "foo@bar.com"; | 734 credentials.email = "foo@bar.com"; |
736 credentials.sync_token = "sometoken"; | 735 credentials.sync_token = "sometoken"; |
737 | 736 |
738 sync_notifier_mock_ = new StrictMock<SyncNotifierMock>(); | 737 sync_notifier_mock_ = new StrictMock<SyncNotifierMock>(); |
739 EXPECT_CALL(*sync_notifier_mock_, AddObserver(_)). | 738 EXPECT_CALL(*sync_notifier_mock_, AddHandler(_)). |
740 WillOnce(Invoke(this, &SyncManagerTest::SyncNotifierAddObserver)); | 739 WillOnce(Invoke(this, &SyncManagerTest::SyncNotifierAddObserver)); |
741 EXPECT_CALL(*sync_notifier_mock_, SetUniqueId(_)); | 740 EXPECT_CALL(*sync_notifier_mock_, SetUniqueId(_)); |
742 EXPECT_CALL(*sync_notifier_mock_, SetStateDeprecated("")); | 741 EXPECT_CALL(*sync_notifier_mock_, SetStateDeprecated("")); |
743 EXPECT_CALL(*sync_notifier_mock_, | 742 EXPECT_CALL(*sync_notifier_mock_, |
744 UpdateCredentials(credentials.email, credentials.sync_token)); | 743 UpdateCredentials(credentials.email, credentials.sync_token)); |
745 EXPECT_CALL(*sync_notifier_mock_, UpdateEnabledTypes(_)). | 744 EXPECT_CALL(*sync_notifier_mock_, ReloadHandlers()). |
746 WillRepeatedly( | 745 WillRepeatedly( |
747 Invoke(this, &SyncManagerTest::SyncNotifierUpdateEnabledTypes)); | 746 Invoke(this, &SyncManagerTest::SyncNotifierReloadHandlers)); |
748 EXPECT_CALL(*sync_notifier_mock_, RemoveObserver(_)). | 747 EXPECT_CALL(*sync_notifier_mock_, RemoveHandler(_)). |
749 WillOnce(Invoke(this, &SyncManagerTest::SyncNotifierRemoveObserver)); | 748 WillOnce(Invoke(this, &SyncManagerTest::SyncNotifierRemoveObserver)); |
750 | 749 |
751 sync_manager_.AddObserver(&observer_); | 750 sync_manager_.AddObserver(&observer_); |
752 EXPECT_CALL(observer_, OnInitializationComplete(_, _)). | 751 EXPECT_CALL(observer_, OnInitializationComplete(_, _)). |
753 WillOnce(SaveArg<0>(&js_backend_)); | 752 WillOnce(SaveArg<0>(&js_backend_)); |
754 | 753 |
755 EXPECT_FALSE(sync_notifier_observer_); | 754 EXPECT_FALSE(sync_notifier_observer_); |
756 EXPECT_FALSE(js_backend_.IsInitialized()); | 755 EXPECT_FALSE(js_backend_.IsInitialized()); |
757 | 756 |
758 std::vector<ModelSafeWorker*> workers; | 757 std::vector<ModelSafeWorker*> workers; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 EXPECT_EQ(NULL, sync_notifier_observer_); | 855 EXPECT_EQ(NULL, sync_notifier_observer_); |
857 sync_notifier_observer_ = sync_notifier_observer; | 856 sync_notifier_observer_ = sync_notifier_observer; |
858 } | 857 } |
859 | 858 |
860 void SyncNotifierRemoveObserver( | 859 void SyncNotifierRemoveObserver( |
861 syncer::SyncNotifierObserver* sync_notifier_observer) { | 860 syncer::SyncNotifierObserver* sync_notifier_observer) { |
862 EXPECT_EQ(sync_notifier_observer_, sync_notifier_observer); | 861 EXPECT_EQ(sync_notifier_observer_, sync_notifier_observer); |
863 sync_notifier_observer_ = NULL; | 862 sync_notifier_observer_ = NULL; |
864 } | 863 } |
865 | 864 |
866 void SyncNotifierUpdateEnabledTypes(syncer::ModelTypeSet types) { | 865 void SyncNotifierReloadHandlers() { |
867 ModelSafeRoutingInfo routes; | 866 ModelSafeRoutingInfo routes; |
868 GetModelSafeRoutingInfo(&routes); | 867 GetModelSafeRoutingInfo(&routes); |
869 const syncer::ModelTypeSet expected_types = GetRoutingInfoTypes(routes); | 868 const syncer::ModelTypeSet expected_types = GetRoutingInfoTypes(routes); |
870 EXPECT_TRUE(types.Equals(expected_types)); | 869 |
| 870 ASSERT_TRUE(sync_notifier_observer_); |
| 871 EXPECT_EQ(ModelTypeSetToObjectIdSet(expected_types), |
| 872 sync_notifier_observer_->GetHandledIds()); |
| 873 |
871 ++update_enabled_types_call_count_; | 874 ++update_enabled_types_call_count_; |
872 } | 875 } |
873 | 876 |
874 void PumpLoop() { | 877 void PumpLoop() { |
875 message_loop_.RunAllPending(); | 878 message_loop_.RunAllPending(); |
876 } | 879 } |
877 | 880 |
878 void SendJsMessage(const std::string& name, const JsArgList& args, | 881 void SendJsMessage(const std::string& name, const JsArgList& args, |
879 const WeakHandle<JsReplyHandler>& reply_handler) { | 882 const WeakHandle<JsReplyHandler>& reply_handler) { |
880 js_backend_.Call(FROM_HERE, &JsBackend::ProcessJsMessage, | 883 js_backend_.Call(FROM_HERE, &JsBackend::ProcessJsMessage, |
(...skipping 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2479 EXPECT_EQ(title, node.GetTitle()); | 2482 EXPECT_EQ(title, node.GetTitle()); |
2480 EXPECT_EQ(GURL(url2), node.GetURL()); | 2483 EXPECT_EQ(GURL(url2), node.GetURL()); |
2481 const syncable::Entry* node_entry = node.GetEntry(); | 2484 const syncable::Entry* node_entry = node.GetEntry(); |
2482 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2485 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
2483 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2486 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
2484 EXPECT_TRUE(specifics.has_encrypted()); | 2487 EXPECT_TRUE(specifics.has_encrypted()); |
2485 } | 2488 } |
2486 } | 2489 } |
2487 | 2490 |
2488 } // namespace syncer | 2491 } // namespace syncer |
OLD | NEW |