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

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

Issue 10916131: [Invalidations] Add GetInvalidatorState() to Invalidator{,Frontend} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android Created 8 years, 3 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 (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 888 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 ModelTypeSet GetEncryptedTypes() { 899 ModelTypeSet GetEncryptedTypes() {
900 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 900 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
901 return GetEncryptedTypesWithTrans(&trans); 901 return GetEncryptedTypesWithTrans(&trans);
902 } 902 }
903 903
904 ModelTypeSet GetEncryptedTypesWithTrans(BaseTransaction* trans) { 904 ModelTypeSet GetEncryptedTypesWithTrans(BaseTransaction* trans) {
905 return trans->GetDirectory()->GetNigoriHandler()-> 905 return trans->GetDirectory()->GetNigoriHandler()->
906 GetEncryptedTypes(trans->GetWrappedTrans()); 906 GetEncryptedTypes(trans->GetWrappedTrans());
907 } 907 }
908 908
909 void SimulateEnableNotificationsForTest() { 909 void SimulateInvalidatorStateChangeForTest(InvalidatorState state) {
910 DCHECK(sync_manager_.thread_checker_.CalledOnValidThread()); 910 DCHECK(sync_manager_.thread_checker_.CalledOnValidThread());
911 sync_manager_.OnNotificationsEnabled(); 911 sync_manager_.OnInvalidatorStateChange(state);
912 }
913
914 void SimulateDisableNotificationsForTest(
915 NotificationsDisabledReason reason) {
916 DCHECK(sync_manager_.thread_checker_.CalledOnValidThread());
917 sync_manager_.OnNotificationsDisabled(reason);
918 } 912 }
919 913
920 void TriggerOnIncomingNotificationForTest(ModelTypeSet model_types) { 914 void TriggerOnIncomingNotificationForTest(ModelTypeSet model_types) {
921 DCHECK(sync_manager_.thread_checker_.CalledOnValidThread()); 915 DCHECK(sync_manager_.thread_checker_.CalledOnValidThread());
922 ModelTypeStateMap type_state_map = 916 ModelTypeStateMap type_state_map =
923 ModelTypeSetToStateMap(model_types, std::string()); 917 ModelTypeSetToStateMap(model_types, std::string());
924 sync_manager_.OnIncomingNotification( 918 sync_manager_.OnIncomingInvalidation(
925 ModelTypeStateMapToObjectIdStateMap(type_state_map), 919 ModelTypeStateMapToObjectIdStateMap(type_state_map),
926 REMOTE_NOTIFICATION); 920 REMOTE_INVALIDATION);
927 } 921 }
928 922
929 void SetProgressMarkerForType(ModelType type, bool set) { 923 void SetProgressMarkerForType(ModelType type, bool set) {
930 if (set) { 924 if (set) {
931 sync_pb::DataTypeProgressMarker marker; 925 sync_pb::DataTypeProgressMarker marker;
932 marker.set_token("token"); 926 marker.set_token("token");
933 marker.set_data_type_id(GetSpecificsFieldNumberFromModelType(type)); 927 marker.set_data_type_id(GetSpecificsFieldNumberFromModelType(type));
934 sync_manager_.directory()->SetDownloadProgress(type, marker); 928 sync_manager_.directory()->SetDownloadProgress(type, marker);
935 } else { 929 } else {
936 sync_pb::DataTypeProgressMarker marker; 930 sync_pb::DataTypeProgressMarker marker;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 EXPECT_FALSE(fake_invalidator_->IsHandlerRegistered(&fake_handler)); 983 EXPECT_FALSE(fake_invalidator_->IsHandlerRegistered(&fake_handler));
990 } 984 }
991 985
992 TEST_F(SyncManagerTest, ProcessJsMessage) { 986 TEST_F(SyncManagerTest, ProcessJsMessage) {
993 const JsArgList kNoArgs; 987 const JsArgList kNoArgs;
994 988
995 StrictMock<MockJsReplyHandler> reply_handler; 989 StrictMock<MockJsReplyHandler> reply_handler;
996 990
997 ListValue disabled_args; 991 ListValue disabled_args;
998 disabled_args.Append( 992 disabled_args.Append(
999 Value::CreateStringValue("TRANSIENT_NOTIFICATION_ERROR")); 993 Value::CreateStringValue("TRANSIENT_INVALIDATION_ERROR"));
1000 994
1001 EXPECT_CALL(reply_handler, 995 EXPECT_CALL(reply_handler,
1002 HandleJsReply("getNotificationState", 996 HandleJsReply("getNotificationState",
1003 HasArgsAsList(disabled_args))); 997 HasArgsAsList(disabled_args)));
1004 998
1005 // This message should be dropped. 999 // This message should be dropped.
1006 SendJsMessage("unknownMessage", kNoArgs, reply_handler.AsWeakHandle()); 1000 SendJsMessage("unknownMessage", kNoArgs, reply_handler.AsWeakHandle());
1007 1001
1008 SendJsMessage("getNotificationState", kNoArgs, reply_handler.AsWeakHandle()); 1002 SendJsMessage("getNotificationState", kNoArgs, reply_handler.AsWeakHandle());
1009 } 1003 }
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 ASSERT_TRUE(node_list->GetDictionary(0, &first_result)); 1271 ASSERT_TRUE(node_list->GetDictionary(0, &first_result));
1278 EXPECT_TRUE(first_result->HasKey("ID")); 1272 EXPECT_TRUE(first_result->HasKey("ID"));
1279 EXPECT_TRUE(first_result->HasKey("NON_UNIQUE_NAME")); 1273 EXPECT_TRUE(first_result->HasKey("NON_UNIQUE_NAME"));
1280 } 1274 }
1281 1275
1282 TEST_F(SyncManagerTest, OnNotificationStateChange) { 1276 TEST_F(SyncManagerTest, OnNotificationStateChange) {
1283 InSequence dummy; 1277 InSequence dummy;
1284 StrictMock<MockJsEventHandler> event_handler; 1278 StrictMock<MockJsEventHandler> event_handler;
1285 1279
1286 DictionaryValue enabled_details; 1280 DictionaryValue enabled_details;
1287 enabled_details.SetString("state", "NO_NOTIFICATION_ERROR"); 1281 enabled_details.SetString("state", "INVALIDATIONS_ENABLED");
1288 DictionaryValue disabled_details; 1282 DictionaryValue disabled_details;
1289 disabled_details.SetString("state", "TRANSIENT_NOTIFICATION_ERROR"); 1283 disabled_details.SetString("state", "TRANSIENT_INVALIDATION_ERROR");
1290 1284
1291 EXPECT_CALL(event_handler, 1285 EXPECT_CALL(event_handler,
1292 HandleJsEvent("onNotificationStateChange", 1286 HandleJsEvent("onNotificationStateChange",
1293 HasDetailsAsDictionary(enabled_details))); 1287 HasDetailsAsDictionary(enabled_details)));
1294 EXPECT_CALL(event_handler, 1288 EXPECT_CALL(event_handler,
1295 HandleJsEvent("onNotificationStateChange", 1289 HandleJsEvent("onNotificationStateChange",
1296 HasDetailsAsDictionary(disabled_details))); 1290 HasDetailsAsDictionary(disabled_details)));
1297 1291
1298 SimulateEnableNotificationsForTest(); 1292 SimulateInvalidatorStateChangeForTest(INVALIDATIONS_ENABLED);
1299 SimulateDisableNotificationsForTest(TRANSIENT_NOTIFICATION_ERROR); 1293 SimulateInvalidatorStateChangeForTest(TRANSIENT_INVALIDATION_ERROR);
1300 1294
1301 SetJsEventHandler(event_handler.AsWeakHandle()); 1295 SetJsEventHandler(event_handler.AsWeakHandle());
1302 SimulateEnableNotificationsForTest(); 1296 SimulateInvalidatorStateChangeForTest(INVALIDATIONS_ENABLED);
1303 SimulateDisableNotificationsForTest(TRANSIENT_NOTIFICATION_ERROR); 1297 SimulateInvalidatorStateChangeForTest(TRANSIENT_INVALIDATION_ERROR);
1304 SetJsEventHandler(WeakHandle<JsEventHandler>()); 1298 SetJsEventHandler(WeakHandle<JsEventHandler>());
1305 1299
1306 SimulateEnableNotificationsForTest(); 1300 SimulateInvalidatorStateChangeForTest(INVALIDATIONS_ENABLED);
1307 SimulateDisableNotificationsForTest(TRANSIENT_NOTIFICATION_ERROR); 1301 SimulateInvalidatorStateChangeForTest(TRANSIENT_INVALIDATION_ERROR);
1308 1302
1309 // Should trigger the replies. 1303 // Should trigger the replies.
1310 PumpLoop(); 1304 PumpLoop();
1311 } 1305 }
1312 1306
1313 TEST_F(SyncManagerTest, OnIncomingNotification) { 1307 TEST_F(SyncManagerTest, OnIncomingNotification) {
1314 StrictMock<MockJsEventHandler> event_handler; 1308 StrictMock<MockJsEventHandler> event_handler;
1315 1309
1316 const ModelTypeSet empty_model_types; 1310 const ModelTypeSet empty_model_types;
1317 const ModelTypeSet model_types( 1311 const ModelTypeSet model_types(
1318 BOOKMARKS, THEMES); 1312 BOOKMARKS, THEMES);
1319 1313
1320 // Build expected_args to have a single argument with the string 1314 // Build expected_args to have a single argument with the string
1321 // equivalents of model_types. 1315 // equivalents of model_types.
1322 DictionaryValue expected_details; 1316 DictionaryValue expected_details;
1323 { 1317 {
1324 ListValue* model_type_list = new ListValue(); 1318 ListValue* model_type_list = new ListValue();
1325 expected_details.SetString("source", "REMOTE_NOTIFICATION"); 1319 expected_details.SetString("source", "REMOTE_INVALIDATION");
1326 expected_details.Set("changedTypes", model_type_list); 1320 expected_details.Set("changedTypes", model_type_list);
1327 for (ModelTypeSet::Iterator it = model_types.First(); 1321 for (ModelTypeSet::Iterator it = model_types.First();
1328 it.Good(); it.Inc()) { 1322 it.Good(); it.Inc()) {
1329 model_type_list->Append( 1323 model_type_list->Append(
1330 Value::CreateStringValue(ModelTypeToString(it.Get()))); 1324 Value::CreateStringValue(ModelTypeToString(it.Get())));
1331 } 1325 }
1332 } 1326 }
1333 1327
1334 EXPECT_CALL(event_handler, 1328 EXPECT_CALL(event_handler,
1335 HandleJsEvent("onIncomingNotification", 1329 HandleJsEvent("onIncomingNotification",
(...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after
2886 2880
2887 // Verify only the non-disabled types remain after cleanup. 2881 // Verify only the non-disabled types remain after cleanup.
2888 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); 2882 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types);
2889 EXPECT_TRUE(new_enabled_types.Equals( 2883 EXPECT_TRUE(new_enabled_types.Equals(
2890 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); 2884 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types)));
2891 EXPECT_TRUE(disabled_types.Equals( 2885 EXPECT_TRUE(disabled_types.Equals(
2892 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); 2886 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
2893 } 2887 }
2894 2888
2895 } // namespace 2889 } // 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