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

Side by Side Diff: chrome/browser/sync/internal_api/syncapi_unittest.cc

Issue 8772074: [Sync] Convert syncable/ directory to ModelEnumSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 640
641 class SyncNotifierMock : public sync_notifier::SyncNotifier { 641 class SyncNotifierMock : public sync_notifier::SyncNotifier {
642 public: 642 public:
643 MOCK_METHOD1(AddObserver, void(sync_notifier::SyncNotifierObserver*)); 643 MOCK_METHOD1(AddObserver, void(sync_notifier::SyncNotifierObserver*));
644 MOCK_METHOD1(RemoveObserver, void(sync_notifier::SyncNotifierObserver*)); 644 MOCK_METHOD1(RemoveObserver, void(sync_notifier::SyncNotifierObserver*));
645 MOCK_METHOD1(SetUniqueId, void(const std::string&)); 645 MOCK_METHOD1(SetUniqueId, void(const std::string&));
646 MOCK_METHOD1(SetState, void(const std::string&)); 646 MOCK_METHOD1(SetState, void(const std::string&));
647 MOCK_METHOD2(UpdateCredentials, 647 MOCK_METHOD2(UpdateCredentials,
648 void(const std::string&, const std::string&)); 648 void(const std::string&, const std::string&));
649 MOCK_METHOD1(UpdateEnabledTypes, 649 MOCK_METHOD1(UpdateEnabledTypes,
650 void(const syncable::ModelTypeSet&)); 650 void(syncable::ModelEnumSet));
651 MOCK_METHOD1(SendNotification, void(const syncable::ModelTypeSet&)); 651 MOCK_METHOD1(SendNotification, void(syncable::ModelEnumSet));
652 }; 652 };
653 653
654 class SyncManagerTest : public testing::Test, 654 class SyncManagerTest : public testing::Test,
655 public ModelSafeWorkerRegistrar, 655 public ModelSafeWorkerRegistrar,
656 public SyncManager::ChangeDelegate { 656 public SyncManager::ChangeDelegate {
657 protected: 657 protected:
658 SyncManagerTest() 658 SyncManagerTest()
659 : ui_thread_(BrowserThread::UI, &ui_loop_), 659 : ui_thread_(BrowserThread::UI, &ui_loop_),
660 sync_notifier_mock_(NULL), 660 sync_notifier_mock_(NULL),
661 sync_manager_("Test sync manager"), 661 sync_manager_("Test sync manager"),
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 EXPECT_EQ(NULL, sync_notifier_observer_); 794 EXPECT_EQ(NULL, sync_notifier_observer_);
795 sync_notifier_observer_ = sync_notifier_observer; 795 sync_notifier_observer_ = sync_notifier_observer;
796 } 796 }
797 797
798 void SyncNotifierRemoveObserver( 798 void SyncNotifierRemoveObserver(
799 sync_notifier::SyncNotifierObserver* sync_notifier_observer) { 799 sync_notifier::SyncNotifierObserver* sync_notifier_observer) {
800 EXPECT_EQ(sync_notifier_observer_, sync_notifier_observer); 800 EXPECT_EQ(sync_notifier_observer_, sync_notifier_observer);
801 sync_notifier_observer_ = NULL; 801 sync_notifier_observer_ = NULL;
802 } 802 }
803 803
804 void SyncNotifierUpdateEnabledTypes( 804 void SyncNotifierUpdateEnabledTypes(syncable::ModelEnumSet types) {
805 const syncable::ModelTypeSet& types) {
806 ModelSafeRoutingInfo routes; 805 ModelSafeRoutingInfo routes;
807 GetModelSafeRoutingInfo(&routes); 806 GetModelSafeRoutingInfo(&routes);
808 syncable::ModelTypeSet expected_types; 807 const syncable::ModelEnumSet expected_types =
809 for (ModelSafeRoutingInfo::const_iterator it = routes.begin(); 808 GetRoutingInfoTypes(routes);
810 it != routes.end(); ++it) { 809 EXPECT_TRUE(types.Equals(expected_types));
811 expected_types.insert(it->first);
812 }
813 EXPECT_EQ(expected_types, types);
814 ++update_enabled_types_call_count_; 810 ++update_enabled_types_call_count_;
815 } 811 }
816 812
817 void PumpLoop() { 813 void PumpLoop() {
818 ui_loop_.RunAllPending(); 814 ui_loop_.RunAllPending();
819 } 815 }
820 816
821 void SendJsMessage(const std::string& name, const JsArgList& args, 817 void SendJsMessage(const std::string& name, const JsArgList& args,
822 const WeakHandle<JsReplyHandler>& reply_handler) { 818 const WeakHandle<JsReplyHandler>& reply_handler) {
823 js_backend_.Call(FROM_HERE, &JsBackend::ProcessJsMessage, 819 js_backend_.Call(FROM_HERE, &JsBackend::ProcessJsMessage,
(...skipping 27 matching lines...) Expand all
851 }; 847 };
852 848
853 TEST_F(SyncManagerTest, UpdateEnabledTypes) { 849 TEST_F(SyncManagerTest, UpdateEnabledTypes) {
854 EXPECT_EQ(1, update_enabled_types_call_count_); 850 EXPECT_EQ(1, update_enabled_types_call_count_);
855 // Triggers SyncNotifierUpdateEnabledTypes. 851 // Triggers SyncNotifierUpdateEnabledTypes.
856 sync_manager_.UpdateEnabledTypes(); 852 sync_manager_.UpdateEnabledTypes();
857 EXPECT_EQ(2, update_enabled_types_call_count_); 853 EXPECT_EQ(2, update_enabled_types_call_count_);
858 } 854 }
859 855
860 TEST_F(SyncManagerTest, DoNotSyncTabsInNigoriNode) { 856 TEST_F(SyncManagerTest, DoNotSyncTabsInNigoriNode) {
861 syncable::ModelTypeSet encrypted_types; 857 syncable::ModelEnumSet encrypted_types(syncable::TYPED_URLS);
862 encrypted_types.insert(syncable::TYPED_URLS);
863 sync_manager_.MaybeSetSyncTabsInNigoriNode(encrypted_types); 858 sync_manager_.MaybeSetSyncTabsInNigoriNode(encrypted_types);
864 859
865 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 860 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
866 ReadNode node(&trans); 861 ReadNode node(&trans);
867 ASSERT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); 862 ASSERT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI)));
868 EXPECT_FALSE(node.GetNigoriSpecifics().sync_tabs()); 863 EXPECT_FALSE(node.GetNigoriSpecifics().sync_tabs());
869 } 864 }
870 865
871 TEST_F(SyncManagerTest, SyncTabsInNigoriNode) { 866 TEST_F(SyncManagerTest, SyncTabsInNigoriNode) {
872 syncable::ModelTypeSet encrypted_types; 867 syncable::ModelEnumSet encrypted_types(syncable::SESSIONS);
873 encrypted_types.insert(syncable::SESSIONS);
874 sync_manager_.MaybeSetSyncTabsInNigoriNode(encrypted_types); 868 sync_manager_.MaybeSetSyncTabsInNigoriNode(encrypted_types);
875 869
876 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 870 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
877 ReadNode node(&trans); 871 ReadNode node(&trans);
878 ASSERT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); 872 ASSERT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI)));
879 EXPECT_TRUE(node.GetNigoriSpecifics().sync_tabs()); 873 EXPECT_TRUE(node.GetNigoriSpecifics().sync_tabs());
880 } 874 }
881 875
882 TEST_F(SyncManagerTest, ProcessJsMessage) { 876 TEST_F(SyncManagerTest, ProcessJsMessage) {
883 const JsArgList kNoArgs; 877 const JsArgList kNoArgs;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 sync_manager_.TriggerOnNotificationStateChangeForTest(true); 1151 sync_manager_.TriggerOnNotificationStateChangeForTest(true);
1158 sync_manager_.TriggerOnNotificationStateChangeForTest(false); 1152 sync_manager_.TriggerOnNotificationStateChangeForTest(false);
1159 1153
1160 // Should trigger the replies. 1154 // Should trigger the replies.
1161 PumpLoop(); 1155 PumpLoop();
1162 } 1156 }
1163 1157
1164 TEST_F(SyncManagerTest, OnIncomingNotification) { 1158 TEST_F(SyncManagerTest, OnIncomingNotification) {
1165 StrictMock<MockJsEventHandler> event_handler; 1159 StrictMock<MockJsEventHandler> event_handler;
1166 1160
1167 const syncable::ModelTypeBitSet empty_model_types; 1161 const syncable::ModelEnumSet empty_model_types;
1168 syncable::ModelTypeBitSet model_types; 1162 syncable::ModelEnumSet model_types(syncable::BOOKMARKS, syncable::THEMES);
1169 model_types.set(syncable::BOOKMARKS);
1170 model_types.set(syncable::THEMES);
1171 1163
1172 // Build expected_args to have a single argument with the string 1164 // Build expected_args to have a single argument with the string
1173 // equivalents of model_types. 1165 // equivalents of model_types.
1174 DictionaryValue expected_details; 1166 DictionaryValue expected_details;
1175 { 1167 {
1176 ListValue* model_type_list = new ListValue(); 1168 ListValue* model_type_list = new ListValue();
1177 expected_details.Set("changedTypes", model_type_list); 1169 expected_details.Set("changedTypes", model_type_list);
1178 for (int i = syncable::FIRST_REAL_MODEL_TYPE; 1170 for (syncable::ModelEnumSet::Iterator it = model_types.First();
1179 i < syncable::MODEL_TYPE_COUNT; ++i) { 1171 it.Good(); it.Inc()) {
1180 if (model_types[i]) { 1172 model_type_list->Append(
1181 model_type_list->Append( 1173 Value::CreateStringValue(
1182 Value::CreateStringValue( 1174 syncable::ModelTypeToString(it.Get())));
1183 syncable::ModelTypeToString(
1184 syncable::ModelTypeFromInt(i))));
1185 }
1186 } 1175 }
1187 } 1176 }
1188 1177
1189 EXPECT_CALL(event_handler, 1178 EXPECT_CALL(event_handler,
1190 HandleJsEvent("onIncomingNotification", 1179 HandleJsEvent("onIncomingNotification",
1191 HasDetailsAsDictionary(expected_details))); 1180 HasDetailsAsDictionary(expected_details)));
1192 1181
1193 sync_manager_.TriggerOnIncomingNotificationForTest(empty_model_types); 1182 sync_manager_.TriggerOnIncomingNotificationForTest(empty_model_types);
1194 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); 1183 sync_manager_.TriggerOnIncomingNotificationForTest(model_types);
1195 1184
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType()); 1520 EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType());
1532 // We should de-canonicalize the title in GetTitle(), but the title in the 1521 // We should de-canonicalize the title in GetTitle(), but the title in the
1533 // specifics should be stored in the server legal form. 1522 // specifics should be stored in the server legal form.
1534 EXPECT_EQ(raw_title2, node2.GetTitle()); 1523 EXPECT_EQ(raw_title2, node2.GetTitle());
1535 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); 1524 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title());
1536 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); 1525 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url());
1537 } 1526 }
1538 } 1527 }
1539 1528
1540 } // namespace browser_sync 1529 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/internal_api/sync_manager.cc ('k') | chrome/browser/sync/js/js_mutation_event_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698