OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 package org.chromium.components.invalidation; | 5 package org.chromium.components.invalidation; |
6 | 6 |
7 import android.accounts.Account; | 7 import android.accounts.Account; |
8 import android.content.ComponentName; | 8 import android.content.ComponentName; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.Intent; | 10 import android.content.Intent; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 /** Intents provided to {@link #startService}. */ | 51 /** Intents provided to {@link #startService}. */ |
52 private List<Intent> mStartServiceIntents; | 52 private List<Intent> mStartServiceIntents; |
53 | 53 |
54 public InvalidationClientServiceTest() { | 54 public InvalidationClientServiceTest() { |
55 super(TestableInvalidationClientService.class); | 55 super(TestableInvalidationClientService.class); |
56 } | 56 } |
57 | 57 |
58 @Override | 58 @Override |
59 public void setUp() throws Exception { | 59 public void setUp() throws Exception { |
60 super.setUp(); | 60 super.setUp(); |
61 mStartServiceIntents = new ArrayList<Intent>(); | 61 mStartServiceIntents = new ArrayList<>(); |
62 setContext(new AdvancedMockContext(getContext()) { | 62 setContext(new AdvancedMockContext(getContext()) { |
63 @Override | 63 @Override |
64 public ComponentName startService(Intent intent) { | 64 public ComponentName startService(Intent intent) { |
65 mStartServiceIntents.add(intent); | 65 mStartServiceIntents.add(intent); |
66 return new ComponentName(this, InvalidationClientServiceTest.cla
ss); | 66 return new ComponentName(this, InvalidationClientServiceTest.cla
ss); |
67 } | 67 } |
68 }); | 68 }); |
69 Context appContext = getContext().getApplicationContext(); | 69 Context appContext = getContext().getApplicationContext(); |
70 ContextUtils.initApplicationContextForTests(appContext); | 70 ContextUtils.initApplicationContextForTests(appContext); |
71 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, a
ppContext); | 71 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, a
ppContext); |
72 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(
getContext()); | 72 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(
); |
73 setupService(); | 73 setupService(); |
74 } | 74 } |
75 | 75 |
76 @Override | 76 @Override |
77 public void tearDown() throws Exception { | 77 public void tearDown() throws Exception { |
78 if (InvalidationClientService.getIsClientStartedForTest()) { | 78 if (InvalidationClientService.getIsClientStartedForTest()) { |
79 Intent stopIntent = createStopIntent(); | 79 Intent stopIntent = createStopIntent(); |
80 getService().onHandleIntent(stopIntent); | 80 getService().onHandleIntent(stopIntent); |
81 } | 81 } |
82 assertFalse(InvalidationClientService.getIsClientStartedForTest()); | 82 assertFalse(InvalidationClientService.getIsClientStartedForTest()); |
83 super.tearDown(); | 83 super.tearDown(); |
84 } | 84 } |
85 | 85 |
86 @SmallTest | 86 @SmallTest |
87 @Feature({"Sync"}) | 87 @Feature({"Sync"}) |
88 public void testComputeRegistrationOps() { | 88 public void testComputeRegistrationOps() { |
89 /* | 89 /* |
90 * Test plan: compute the set of registration operations resulting from
various combinations | 90 * Test plan: compute the set of registration operations resulting from
various combinations |
91 * of existing and desired registrations. Verifying that they are correc
t. | 91 * of existing and desired registrations. Verifying that they are correc
t. |
92 */ | 92 */ |
93 Set<ObjectId> regAccumulator = new HashSet<ObjectId>(); | 93 Set<ObjectId> regAccumulator = new HashSet<>(); |
94 Set<ObjectId> unregAccumulator = new HashSet<ObjectId>(); | 94 Set<ObjectId> unregAccumulator = new HashSet<>(); |
95 | 95 |
96 // Empty existing and desired registrations should yield empty operation
sets. | 96 // Empty existing and desired registrations should yield empty operation
sets. |
97 InvalidationClientService.computeRegistrationOps( | 97 InvalidationClientService.computeRegistrationOps( |
98 toObjectIdSet(ModelType.BOOKMARKS, ModelType.SESSIONS), | 98 toObjectIdSet(ModelType.BOOKMARKS, ModelType.SESSIONS), |
99 toObjectIdSet(ModelType.BOOKMARKS, ModelType.SESSIONS), | 99 toObjectIdSet(ModelType.BOOKMARKS, ModelType.SESSIONS), |
100 regAccumulator, unregAccumulator); | 100 regAccumulator, unregAccumulator); |
101 assertEquals(0, regAccumulator.size()); | 101 assertEquals(0, regAccumulator.size()); |
102 assertEquals(0, unregAccumulator.size()); | 102 assertEquals(0, unregAccumulator.size()); |
103 | 103 |
104 // Equal existing and desired registrations should yield empty operation
sets. | 104 // Equal existing and desired registrations should yield empty operation
sets. |
105 InvalidationClientService.computeRegistrationOps(new HashSet<ObjectId>()
, | 105 InvalidationClientService.computeRegistrationOps(new HashSet<ObjectId>()
, |
106 new HashSet<ObjectId>(), regAccumulator, unregAccumulator); | 106 new HashSet<ObjectId>(), regAccumulator, unregAccumulator); |
107 assertEquals(0, regAccumulator.size()); | 107 assertEquals(0, regAccumulator.size()); |
108 assertEquals(0, unregAccumulator.size()); | 108 assertEquals(0, unregAccumulator.size()); |
109 | 109 |
110 // Empty existing and non-empty desired registrations should yield desir
ed registrations | 110 // Empty existing and non-empty desired registrations should yield desir
ed registrations |
111 // as the registration operations to do and no unregistrations. | 111 // as the registration operations to do and no unregistrations. |
112 Set<ObjectId> desiredTypes = toObjectIdSet(ModelType.BOOKMARKS, ModelTyp
e.SESSIONS); | 112 Set<ObjectId> desiredTypes = toObjectIdSet(ModelType.BOOKMARKS, ModelTyp
e.SESSIONS); |
113 InvalidationClientService.computeRegistrationOps( | 113 InvalidationClientService.computeRegistrationOps( |
114 new HashSet<ObjectId>(), | 114 new HashSet<ObjectId>(), |
115 desiredTypes, | 115 desiredTypes, |
116 regAccumulator, unregAccumulator); | 116 regAccumulator, unregAccumulator); |
117 assertEquals( | 117 assertEquals( |
118 toObjectIdSet(ModelType.BOOKMARKS, ModelType.SESSIONS), | 118 toObjectIdSet(ModelType.BOOKMARKS, ModelType.SESSIONS), |
119 new HashSet<ObjectId>(regAccumulator)); | 119 new HashSet<>(regAccumulator)); |
120 assertEquals(0, unregAccumulator.size()); | 120 assertEquals(0, unregAccumulator.size()); |
121 regAccumulator.clear(); | 121 regAccumulator.clear(); |
122 | 122 |
123 // Unequal existing and desired registrations should yield both registra
tions and | 123 // Unequal existing and desired registrations should yield both registra
tions and |
124 // unregistrations. We should unregister TYPED_URLS and register BOOKMAR
KS, keeping | 124 // unregistrations. We should unregister TYPED_URLS and register BOOKMAR
KS, keeping |
125 // SESSIONS. | 125 // SESSIONS. |
126 InvalidationClientService.computeRegistrationOps( | 126 InvalidationClientService.computeRegistrationOps( |
127 toObjectIdSet(ModelType.SESSIONS, ModelType.TYPED_URLS), | 127 toObjectIdSet(ModelType.SESSIONS, ModelType.TYPED_URLS), |
128 toObjectIdSet(ModelType.BOOKMARKS, ModelType.SESSIONS), | 128 toObjectIdSet(ModelType.BOOKMARKS, ModelType.SESSIONS), |
129 regAccumulator, unregAccumulator); | 129 regAccumulator, unregAccumulator); |
(...skipping 22 matching lines...) Expand all Loading... |
152 // Issue ready. | 152 // Issue ready. |
153 getService().ready(CLIENT_ID); | 153 getService().ready(CLIENT_ID); |
154 assertTrue(Arrays.equals(CLIENT_ID, InvalidationClientService.getClientI
dForTest())); | 154 assertTrue(Arrays.equals(CLIENT_ID, InvalidationClientService.getClientI
dForTest())); |
155 byte[] otherCid = "otherCid".getBytes(); | 155 byte[] otherCid = "otherCid".getBytes(); |
156 getService().ready(otherCid); | 156 getService().ready(otherCid); |
157 assertTrue(Arrays.equals(otherCid, InvalidationClientService.getClientId
ForTest())); | 157 assertTrue(Arrays.equals(otherCid, InvalidationClientService.getClientId
ForTest())); |
158 | 158 |
159 // Verify registrations issued. | 159 // Verify registrations issued. |
160 assertEquals(CollectionUtil.newHashSet( | 160 assertEquals(CollectionUtil.newHashSet( |
161 toObjectId(ModelType.BOOKMARKS), toObjectId(ModelType.SESSIONS),
objectId), | 161 toObjectId(ModelType.BOOKMARKS), toObjectId(ModelType.SESSIONS),
objectId), |
162 new HashSet<ObjectId>(getService().mRegistrations.get(0))); | 162 new HashSet<>(getService().mRegistrations.get(0))); |
163 } | 163 } |
164 | 164 |
165 @SmallTest | 165 @SmallTest |
166 @Feature({"Sync"}) | 166 @Feature({"Sync"}) |
167 public void testReissueRegistrations() { | 167 public void testReissueRegistrations() { |
168 /* | 168 /* |
169 * Test plan: call the reissueRegistrations method of the listener with
both empty and | 169 * Test plan: call the reissueRegistrations method of the listener with
both empty and |
170 * non-empty sets of desired registrations stored in preferences. Verify
that no register | 170 * non-empty sets of desired registrations stored in preferences. Verify
that no register |
171 * intent is set in the first case and that the appropriate register int
ent is sent in | 171 * intent is set in the first case and that the appropriate register int
ent is sent in |
172 * the second. | 172 * the second. |
173 */ | 173 */ |
174 | 174 |
175 // No persisted registrations. | 175 // No persisted registrations. |
176 getService().reissueRegistrations(CLIENT_ID); | 176 getService().reissueRegistrations(CLIENT_ID); |
177 assertTrue(getService().mRegistrations.isEmpty()); | 177 assertTrue(getService().mRegistrations.isEmpty()); |
178 | 178 |
179 // Persist some registrations. | 179 // Persist some registrations. |
180 InvalidationPreferences invPrefs = new InvalidationPreferences(); | 180 InvalidationPreferences invPrefs = new InvalidationPreferences(); |
181 EditContext editContext = invPrefs.edit(); | 181 EditContext editContext = invPrefs.edit(); |
182 invPrefs.setSyncTypes(editContext, CollectionUtil.newArrayList("BOOKMARK
", "SESSION")); | 182 invPrefs.setSyncTypes(editContext, CollectionUtil.newArrayList("BOOKMARK
", "SESSION")); |
183 ObjectId objectId = ObjectId.newInstance(1, "obj".getBytes()); | 183 ObjectId objectId = ObjectId.newInstance(1, "obj".getBytes()); |
184 invPrefs.setObjectIds(editContext, CollectionUtil.newArrayList(objectId)
); | 184 invPrefs.setObjectIds(editContext, CollectionUtil.newArrayList(objectId)
); |
185 assertTrue(invPrefs.commit(editContext)); | 185 assertTrue(invPrefs.commit(editContext)); |
186 | 186 |
187 // Reissue registrations and verify that the appropriate registrations a
re issued. | 187 // Reissue registrations and verify that the appropriate registrations a
re issued. |
188 getService().reissueRegistrations(CLIENT_ID); | 188 getService().reissueRegistrations(CLIENT_ID); |
189 assertEquals(1, getService().mRegistrations.size()); | 189 assertEquals(1, getService().mRegistrations.size()); |
190 assertEquals(CollectionUtil.newHashSet( | 190 assertEquals(CollectionUtil.newHashSet( |
191 toObjectId(ModelType.BOOKMARKS), toObjectId(ModelType.SESSIONS),
objectId), | 191 toObjectId(ModelType.BOOKMARKS), toObjectId(ModelType.SESSIONS),
objectId), |
192 new HashSet<ObjectId>(getService().mRegistrations.get(0))); | 192 new HashSet<>(getService().mRegistrations.get(0))); |
193 } | 193 } |
194 | 194 |
195 @SmallTest | 195 @SmallTest |
196 @Feature({"Sync"}) | 196 @Feature({"Sync"}) |
197 public void testInformRegistrationStatus() { | 197 public void testInformRegistrationStatus() { |
198 /* | 198 /* |
199 * Test plan: call inform registration status under a variety of circums
tances and verify | 199 * Test plan: call inform registration status under a variety of circums
tances and verify |
200 * that the appropriate (un)register calls are issued. | 200 * that the appropriate (un)register calls are issued. |
201 * | 201 * |
202 * 1. Registration of desired object. No calls issued. | 202 * 1. Registration of desired object. No calls issued. |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 * @param expectedObjectIds The additional object ids expected to be registe
red. | 572 * @param expectedObjectIds The additional object ids expected to be registe
red. |
573 * @param isReady Whether the client is ready to register/unregister. | 573 * @param isReady Whether the client is ready to register/unregister. |
574 */ | 574 */ |
575 private boolean expectedObjectIdsRegistered(Set<Integer> expectedTypes, | 575 private boolean expectedObjectIdsRegistered(Set<Integer> expectedTypes, |
576 Set<ObjectId> expectedObjectIds, boolean isReady) { | 576 Set<ObjectId> expectedObjectIds, boolean isReady) { |
577 // Get synced types saved to preferences. | 577 // Get synced types saved to preferences. |
578 Set<String> expectedSyncTypes = modelTypesToNotificationTypes(expectedTy
pes); | 578 Set<String> expectedSyncTypes = modelTypesToNotificationTypes(expectedTy
pes); |
579 InvalidationPreferences invPrefs = new InvalidationPreferences(); | 579 InvalidationPreferences invPrefs = new InvalidationPreferences(); |
580 Set<String> actualSyncTypes = invPrefs.getSavedSyncedTypes(); | 580 Set<String> actualSyncTypes = invPrefs.getSavedSyncedTypes(); |
581 if (actualSyncTypes == null) { | 581 if (actualSyncTypes == null) { |
582 actualSyncTypes = new HashSet<String>(); | 582 actualSyncTypes = new HashSet<>(); |
583 } | 583 } |
584 | 584 |
585 // Get object ids saved to preferences. | 585 // Get object ids saved to preferences. |
586 Set<ObjectId> actualObjectIds = invPrefs.getSavedObjectIds(); | 586 Set<ObjectId> actualObjectIds = invPrefs.getSavedObjectIds(); |
587 if (actualObjectIds == null) { | 587 if (actualObjectIds == null) { |
588 actualObjectIds = new HashSet<ObjectId>(); | 588 actualObjectIds = new HashSet<>(); |
589 } | 589 } |
590 | 590 |
591 // Get expected registered object ids. | 591 // Get expected registered object ids. |
592 Set<ObjectId> expectedRegisteredIds = new HashSet<ObjectId>(); | 592 Set<ObjectId> expectedRegisteredIds = new HashSet<>(); |
593 if (isReady) { | 593 if (isReady) { |
594 expectedRegisteredIds.addAll(modelTypesToObjectIds(expectedTypes)); | 594 expectedRegisteredIds.addAll(modelTypesToObjectIds(expectedTypes)); |
595 expectedRegisteredIds.addAll(expectedObjectIds); | 595 expectedRegisteredIds.addAll(expectedObjectIds); |
596 } | 596 } |
597 | 597 |
598 return actualSyncTypes.equals(expectedSyncTypes) | 598 return actualSyncTypes.equals(expectedSyncTypes) |
599 && actualObjectIds.equals(expectedObjectIds) | 599 && actualObjectIds.equals(expectedObjectIds) |
600 && getService().mCurrentRegistrations.equals(expectedRegisteredI
ds); | 600 && getService().mCurrentRegistrations.equals(expectedRegisteredI
ds); |
601 } | 601 } |
602 | 602 |
603 @SmallTest | 603 @SmallTest |
604 @Feature({"Sync"}) | 604 @Feature({"Sync"}) |
605 public void testRegistrationIntentWithTypesAndObjectIds() { | 605 public void testRegistrationIntentWithTypesAndObjectIds() { |
606 /* | 606 /* |
607 * Test plan: send a mix of registration-change intents: some for Sync t
ypes and some for | 607 * Test plan: send a mix of registration-change intents: some for Sync t
ypes and some for |
608 * object ids. Verify that registering for Sync types does not interfere
with object id | 608 * object ids. Verify that registering for Sync types does not interfere
with object id |
609 * registration and vice-versa. | 609 * registration and vice-versa. |
610 */ | 610 */ |
611 getService().setShouldRunStates(true, true); | 611 getService().setShouldRunStates(true, true); |
612 getService().onCreate(); | 612 getService().onCreate(); |
613 | 613 |
614 Account account = AccountManagerHelper.createAccountFromName("test@examp
le.com"); | 614 Account account = AccountManagerHelper.createAccountFromName("test@examp
le.com"); |
615 Set<ObjectId> objectIds = new HashSet<ObjectId>(); | 615 Set<ObjectId> objectIds = new HashSet<>(); |
616 Set<Integer> types = new HashSet<Integer>(); | 616 Set<Integer> types = new HashSet<>(); |
617 | 617 |
618 // Register for some object ids. | 618 // Register for some object ids. |
619 objectIds.add(ObjectId.newInstance(1, "obj1".getBytes())); | 619 objectIds.add(ObjectId.newInstance(1, "obj1".getBytes())); |
620 objectIds.add(ObjectId.newInstance(2, "obj2".getBytes())); | 620 objectIds.add(ObjectId.newInstance(2, "obj2".getBytes())); |
621 Intent registrationIntent = | 621 Intent registrationIntent = |
622 createRegisterIntent(account, new int[] {1, 2}, new String[] {"o
bj1", "obj2"}); | 622 createRegisterIntent(account, new int[] {1, 2}, new String[] {"o
bj1", "obj2"}); |
623 getService().onHandleIntent(registrationIntent); | 623 getService().onHandleIntent(registrationIntent); |
624 assertTrue(expectedObjectIdsRegistered(types, objectIds, false /* isRead
y */)); | 624 assertTrue(expectedObjectIdsRegistered(types, objectIds, false /* isRead
y */)); |
625 | 625 |
626 // Register for some types. | 626 // Register for some types. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 assertTrue(isAndroidListenerStartIntent(mStartServiceIntents.get(0))); | 696 assertTrue(isAndroidListenerStartIntent(mStartServiceIntents.get(0))); |
697 | 697 |
698 // Set client to be ready. This triggers registrations. | 698 // Set client to be ready. This triggers registrations. |
699 getService().ready(CLIENT_ID); | 699 getService().ready(CLIENT_ID); |
700 assertTrue(Arrays.equals(CLIENT_ID, InvalidationClientService.getClientI
dForTest())); | 700 assertTrue(Arrays.equals(CLIENT_ID, InvalidationClientService.getClientI
dForTest())); |
701 | 701 |
702 // Ensure registrations are correct. | 702 // Ensure registrations are correct. |
703 Set<ObjectId> expectedRegistrations = | 703 Set<ObjectId> expectedRegistrations = |
704 modelTypesToObjectIds(CollectionUtil.newHashSet(ModelType.SESSIO
NS)); | 704 modelTypesToObjectIds(CollectionUtil.newHashSet(ModelType.SESSIO
NS)); |
705 assertEquals(expectedRegistrations, | 705 assertEquals(expectedRegistrations, |
706 new HashSet<ObjectId>(getService().mRegistrations.get(0))); | 706 new HashSet<>(getService().mRegistrations.get(0))); |
707 } | 707 } |
708 | 708 |
709 @SmallTest | 709 @SmallTest |
710 @Feature({"Sync"}) | 710 @Feature({"Sync"}) |
711 public void testRegistrationIntentNoProxyTabsAlreadyWithClientId() { | 711 public void testRegistrationIntentNoProxyTabsAlreadyWithClientId() { |
712 getService().setShouldRunStates(true, true); | 712 getService().setShouldRunStates(true, true); |
713 getService().onCreate(); | 713 getService().onCreate(); |
714 | 714 |
715 // Send register Intent with no desired types. | 715 // Send register Intent with no desired types. |
716 Account account = AccountManagerHelper.createAccountFromName("test@examp
le.com"); | 716 Account account = AccountManagerHelper.createAccountFromName("test@examp
le.com"); |
(...skipping 14 matching lines...) Expand all Loading... |
731 | 731 |
732 // Send register Intent for SESSIONS and PROXY_TABS in an already ready
client. | 732 // Send register Intent for SESSIONS and PROXY_TABS in an already ready
client. |
733 registrationIntent = createRegisterIntent(account, | 733 registrationIntent = createRegisterIntent(account, |
734 CollectionUtil.newHashSet(ModelType.PROXY_TABS, ModelType.SESSIO
NS)); | 734 CollectionUtil.newHashSet(ModelType.PROXY_TABS, ModelType.SESSIO
NS)); |
735 getService().onHandleIntent(registrationIntent); | 735 getService().onHandleIntent(registrationIntent); |
736 | 736 |
737 // Ensure that PROXY_TABS registration request is ignored. | 737 // Ensure that PROXY_TABS registration request is ignored. |
738 assertEquals(1, getService().mRegistrations.size()); | 738 assertEquals(1, getService().mRegistrations.size()); |
739 Set<ObjectId> expectedTypes = | 739 Set<ObjectId> expectedTypes = |
740 modelTypesToObjectIds(CollectionUtil.newHashSet(ModelType.SESSIO
NS)); | 740 modelTypesToObjectIds(CollectionUtil.newHashSet(ModelType.SESSIO
NS)); |
741 assertEquals(expectedTypes, new HashSet<ObjectId>(getService().mRegistra
tions.get(0))); | 741 assertEquals(expectedTypes, new HashSet<>(getService().mRegistrations.ge
t(0))); |
742 } | 742 } |
743 | 743 |
744 @SmallTest | 744 @SmallTest |
745 @Feature({"Sync"}) | 745 @Feature({"Sync"}) |
746 public void testRegistrationIntentWhenClientShouldNotBeRunning() { | 746 public void testRegistrationIntentWhenClientShouldNotBeRunning() { |
747 /* | 747 /* |
748 * Test plan: send a registration change event when the client should no
t be running. | 748 * Test plan: send a registration change event when the client should no
t be running. |
749 * Verify that the service updates the on-disk state but does not start
the client. | 749 * Verify that the service updates the on-disk state but does not start
the client. |
750 */ | 750 */ |
751 getService().onCreate(); | 751 getService().onCreate(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 Intent expectedRegisterIntent = AndroidListener.createRegisterIntent( | 799 Intent expectedRegisterIntent = AndroidListener.createRegisterIntent( |
800 getContext(), | 800 getContext(), |
801 CLIENT_ID, | 801 CLIENT_ID, |
802 desiredObjectIds); | 802 desiredObjectIds); |
803 Intent actualRegisterIntent = mStartServiceIntents.get(1); | 803 Intent actualRegisterIntent = mStartServiceIntents.get(1); |
804 assertTrue(expectedRegisterIntent.filterEquals(actualRegisterIntent)); | 804 assertTrue(expectedRegisterIntent.filterEquals(actualRegisterIntent)); |
805 assertEquals(expectedRegisterIntent.getExtras().keySet(), | 805 assertEquals(expectedRegisterIntent.getExtras().keySet(), |
806 actualRegisterIntent.getExtras().keySet()); | 806 actualRegisterIntent.getExtras().keySet()); |
807 assertEquals( | 807 assertEquals( |
808 desiredObjectIds, | 808 desiredObjectIds, |
809 new HashSet<ObjectId>(getService().mRegistrations.get(0))); | 809 new HashSet<>(getService().mRegistrations.get(0))); |
810 } | 810 } |
811 | 811 |
812 @SmallTest | 812 @SmallTest |
813 @Feature({"Sync"}) | 813 @Feature({"Sync"}) |
814 public void testNullIntent() { | 814 public void testNullIntent() { |
815 getService().setShouldRunStates(true, true); | 815 getService().setShouldRunStates(true, true); |
816 getService().onCreate(); | 816 getService().onCreate(); |
817 // onHandleIntent must gracefully handle receiving a null intent. | 817 // onHandleIntent must gracefully handle receiving a null intent. |
818 getService().onHandleIntent(null); | 818 getService().onHandleIntent(null); |
819 // No crash == success. | 819 // No crash == success. |
(...skipping 10 matching lines...) Expand all Loading... |
830 */ | 830 */ |
831 // TODO(dsmyers): implement. | 831 // TODO(dsmyers): implement. |
832 // Bug: https://code.google.com/p/chromium/issues/detail?id=172398 | 832 // Bug: https://code.google.com/p/chromium/issues/detail?id=172398 |
833 } | 833 } |
834 | 834 |
835 private ObjectId toObjectId(int modelType) { | 835 private ObjectId toObjectId(int modelType) { |
836 return ModelTypeHelper.toObjectId(modelType); | 836 return ModelTypeHelper.toObjectId(modelType); |
837 } | 837 } |
838 | 838 |
839 private Set<ObjectId> toObjectIdSet(int... modelTypes) { | 839 private Set<ObjectId> toObjectIdSet(int... modelTypes) { |
840 Set<ObjectId> objectIds = new HashSet<ObjectId>(modelTypes.length); | 840 Set<ObjectId> objectIds = new HashSet<>(modelTypes.length); |
841 for (int i = 0; i < modelTypes.length; i++) { | 841 for (int i = 0; i < modelTypes.length; i++) { |
842 objectIds.add(toObjectId(modelTypes[i])); | 842 objectIds.add(toObjectId(modelTypes[i])); |
843 } | 843 } |
844 return objectIds; | 844 return objectIds; |
845 } | 845 } |
846 | 846 |
847 private Set<ObjectId> modelTypesToObjectIds(Set<Integer> modelTypes) { | 847 private Set<ObjectId> modelTypesToObjectIds(Set<Integer> modelTypes) { |
848 Set<ObjectId> objectIds = new HashSet<ObjectId>(); | 848 Set<ObjectId> objectIds = new HashSet<>(); |
849 for (Integer modelType : modelTypes) { | 849 for (Integer modelType : modelTypes) { |
850 objectIds.add(toObjectId(modelType)); | 850 objectIds.add(toObjectId(modelType)); |
851 } | 851 } |
852 return objectIds; | 852 return objectIds; |
853 } | 853 } |
854 | 854 |
855 private Set<String> modelTypesToNotificationTypes(Set<Integer> modelTypes) { | 855 private Set<String> modelTypesToNotificationTypes(Set<Integer> modelTypes) { |
856 Set<String> strings = new HashSet<String>(); | 856 Set<String> strings = new HashSet<>(); |
857 for (Integer modelType : modelTypes) { | 857 for (Integer modelType : modelTypes) { |
858 strings.add(ModelTypeHelper.toNotificationType(modelType)); | 858 strings.add(ModelTypeHelper.toNotificationType(modelType)); |
859 } | 859 } |
860 return strings; | 860 return strings; |
861 } | 861 } |
862 | 862 |
863 /** Creates an intent to start the InvalidationClientService. */ | 863 /** Creates an intent to start the InvalidationClientService. */ |
864 private Intent createStartIntent() { | 864 private Intent createStartIntent() { |
865 Intent intent = new Intent(); | 865 Intent intent = new Intent(); |
866 return intent; | 866 return intent; |
(...skipping 26 matching lines...) Expand all Loading... |
893 InvalidationClientService.CLIENT_TYPE, "unused".getBytes()); | 893 InvalidationClientService.CLIENT_TYPE, "unused".getBytes()); |
894 return intent.getExtras().keySet().equals(startIntent.getExtras().keySet
()); | 894 return intent.getExtras().keySet().equals(startIntent.getExtras().keySet
()); |
895 } | 895 } |
896 | 896 |
897 /** Returns whether {@code intent} is an {@link AndroidListener} stop intent
. */ | 897 /** Returns whether {@code intent} is an {@link AndroidListener} stop intent
. */ |
898 private boolean isAndroidListenerStopIntent(Intent intent) { | 898 private boolean isAndroidListenerStopIntent(Intent intent) { |
899 Intent stopIntent = AndroidListener.createStopIntent(getContext()); | 899 Intent stopIntent = AndroidListener.createStopIntent(getContext()); |
900 return intent.getExtras().keySet().equals(stopIntent.getExtras().keySet(
)); | 900 return intent.getExtras().keySet().equals(stopIntent.getExtras().keySet(
)); |
901 } | 901 } |
902 } | 902 } |
OLD | NEW |