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

Side by Side Diff: sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java

Issue 23643002: Enable invalidations for arbitrary objects on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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.sync.notifier; 5 package org.chromium.sync.notifier;
6 6
7 import android.accounts.Account; 7 import android.accounts.Account;
8 import android.app.Activity; 8 import android.app.Activity;
9 import android.content.ComponentName; 9 import android.content.ComponentName;
10 import android.content.Context; 10 import android.content.Context;
11 import android.content.Intent; 11 import android.content.Intent;
12 import android.content.pm.PackageManager; 12 import android.content.pm.PackageManager;
13 import android.test.InstrumentationTestCase; 13 import android.test.InstrumentationTestCase;
14 import android.test.suitebuilder.annotation.SmallTest; 14 import android.test.suitebuilder.annotation.SmallTest;
15 15
16 import com.google.ipc.invalidation.external.client.types.ObjectId;
17
16 import org.chromium.base.ActivityStatus; 18 import org.chromium.base.ActivityStatus;
17 import org.chromium.base.CollectionUtil; 19 import org.chromium.base.CollectionUtil;
18 import org.chromium.base.test.util.AdvancedMockContext; 20 import org.chromium.base.test.util.AdvancedMockContext;
19 import org.chromium.base.test.util.Feature; 21 import org.chromium.base.test.util.Feature;
20 import org.chromium.sync.internal_api.pub.base.ModelType; 22 import org.chromium.sync.internal_api.pub.base.ModelType;
21 import org.chromium.sync.notifier.InvalidationController.IntentProtocol; 23 import org.chromium.sync.notifier.InvalidationController.IntentProtocol;
22 import org.chromium.sync.signin.AccountManagerHelper; 24 import org.chromium.sync.signin.AccountManagerHelper;
23 import org.chromium.sync.signin.ChromeSigninController; 25 import org.chromium.sync.signin.ChromeSigninController;
24 import org.chromium.sync.test.util.MockSyncContentResolverDelegate; 26 import org.chromium.sync.test.util.MockSyncContentResolverDelegate;
25 27
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // Validate account. 166 // Validate account.
165 Account intentAccount = intent.getParcelableExtra(IntentProtocol.EXTRA_A CCOUNT); 167 Account intentAccount = intent.getParcelableExtra(IntentProtocol.EXTRA_A CCOUNT);
166 assertEquals(account, intentAccount); 168 assertEquals(account, intentAccount);
167 169
168 // Validate registered types. 170 // Validate registered types.
169 Set<String> expectedTypes = CollectionUtil.newHashSet(ModelType.BOOKMARK .name(), 171 Set<String> expectedTypes = CollectionUtil.newHashSet(ModelType.BOOKMARK .name(),
170 ModelType.SESSION.name()); 172 ModelType.SESSION.name());
171 Set<String> actualTypes = new HashSet<String>(); 173 Set<String> actualTypes = new HashSet<String>();
172 actualTypes.addAll(intent.getStringArrayListExtra(IntentProtocol.EXTRA_R EGISTERED_TYPES)); 174 actualTypes.addAll(intent.getStringArrayListExtra(IntentProtocol.EXTRA_R EGISTERED_TYPES));
173 assertEquals(expectedTypes, actualTypes); 175 assertEquals(expectedTypes, actualTypes);
176 assertNull(IntentProtocol.getRegisteredObjectIds(intent));
174 } 177 }
175 178
176 @SmallTest 179 @SmallTest
177 @Feature({"Sync"}) 180 @Feature({"Sync"})
178 public void testRegisterForAllTypes() { 181 public void testRegisterForAllTypes() {
179 Account account = new Account("test@example.com", "bogus"); 182 Account account = new Account("test@example.com", "bogus");
180 mController.setRegisteredTypes(account, true, 183 mController.setRegisteredTypes(account, true,
181 CollectionUtil.newHashSet(ModelType.BOOKMARK, ModelType.SESSION) ); 184 CollectionUtil.newHashSet(ModelType.BOOKMARK, ModelType.SESSION) );
182 assertEquals(1, mContext.getNumStartedIntents()); 185 assertEquals(1, mContext.getNumStartedIntents());
183 186
184 // Validate destination. 187 // Validate destination.
185 Intent intent = mContext.getStartedIntent(0); 188 Intent intent = mContext.getStartedIntent(0);
186 validateIntentComponent(intent); 189 validateIntentComponent(intent);
187 assertEquals(IntentProtocol.ACTION_REGISTER, intent.getAction()); 190 assertEquals(IntentProtocol.ACTION_REGISTER, intent.getAction());
188 191
189 // Validate account. 192 // Validate account.
190 Account intentAccount = intent.getParcelableExtra(IntentProtocol.EXTRA_A CCOUNT); 193 Account intentAccount = intent.getParcelableExtra(IntentProtocol.EXTRA_A CCOUNT);
191 assertEquals(account, intentAccount); 194 assertEquals(account, intentAccount);
192 195
193 // Validate registered types. 196 // Validate registered types.
194 Set<String> expectedTypes = CollectionUtil.newHashSet(ModelType.ALL_TYPE S_TYPE); 197 Set<String> expectedTypes = CollectionUtil.newHashSet(ModelType.ALL_TYPE S_TYPE);
195 Set<String> actualTypes = new HashSet<String>(); 198 Set<String> actualTypes = new HashSet<String>();
196 actualTypes.addAll(intent.getStringArrayListExtra(IntentProtocol.EXTRA_R EGISTERED_TYPES)); 199 actualTypes.addAll(intent.getStringArrayListExtra(IntentProtocol.EXTRA_R EGISTERED_TYPES));
197 assertEquals(expectedTypes, actualTypes); 200 assertEquals(expectedTypes, actualTypes);
201 assertNull(IntentProtocol.getRegisteredObjectIds(intent));
198 } 202 }
199 203
200 @SmallTest 204 @SmallTest
201 @Feature({"Sync"}) 205 @Feature({"Sync"})
202 public void testRefreshShouldReadValuesFromDiskWithSpecificTypes() { 206 public void testRefreshShouldReadValuesFromDiskWithSpecificTypes() {
203 // Store some preferences for ModelTypes and account. We are using the h elper class 207 // Store some preferences for ModelTypes and account. We are using the h elper class
204 // for this, so we don't have to deal with low-level details such as pre ference keys. 208 // for this, so we don't have to deal with low-level details such as pre ference keys.
205 InvalidationPreferences invalidationPreferences = new InvalidationPrefer ences(mContext); 209 InvalidationPreferences invalidationPreferences = new InvalidationPrefer ences(mContext);
206 InvalidationPreferences.EditContext edit = invalidationPreferences.edit( ); 210 InvalidationPreferences.EditContext edit = invalidationPreferences.edit( );
207 Set<String> storedModelTypes = new HashSet<String>(); 211 Set<String> storedModelTypes = new HashSet<String>();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 }; 274 };
271 275
272 // Execute the test. 276 // Execute the test.
273 controller.refreshRegisteredTypes(new HashSet<ModelType>()); 277 controller.refreshRegisteredTypes(new HashSet<ModelType>());
274 278
275 // Validate the values. 279 // Validate the values.
276 assertEquals(storedAccount, resultAccount.get()); 280 assertEquals(storedAccount, resultAccount.get());
277 assertEquals(true, resultAllTypes.get()); 281 assertEquals(true, resultAllTypes.get());
278 } 282 }
279 283
284 @SmallTest
285 @Feature({"Sync"})
286 public void testSetRegisteredObjectIds() {
287 InvalidationController controller = new InvalidationController(mContext) ;
288 controller.setRegisteredObjectIds(new int[] {1, 2}, new String[] {"a", " b"});
289 assertEquals(1, mContext.getNumStartedIntents());
290
291 // Validate destination.
292 Intent intent = mContext.getStartedIntent(0);
293 validateIntentComponent(intent);
294 assertEquals(IntentProtocol.ACTION_REGISTER, intent.getAction());
295
296 // Validate registered object ids.
297 assertNull(intent.getStringArrayListExtra(IntentProtocol.EXTRA_REGISTERE D_TYPES));
298 Set<ObjectId> objectIds = IntentProtocol.getRegisteredObjectIds(intent);
299 assertEquals(2, objectIds.size());
300 assertTrue(objectIds.contains(ObjectId.newInstance(1, "a".getBytes())));
301 assertTrue(objectIds.contains(ObjectId.newInstance(2, "b".getBytes())));
302 }
303
280 /** 304 /**
281 * Asserts that {@code intent} is destined for the correct component. 305 * Asserts that {@code intent} is destined for the correct component.
282 */ 306 */
283 private static void validateIntentComponent(Intent intent) { 307 private static void validateIntentComponent(Intent intent) {
284 assertNotNull(intent.getComponent()); 308 assertNotNull(intent.getComponent());
285 assertEquals(InvalidationService.class.getName(), 309 assertEquals(InvalidationService.class.getName(),
286 intent.getComponent().getClassName()); 310 intent.getComponent().getClassName());
287 } 311 }
288 312
289 /** 313 /**
(...skipping 19 matching lines...) Expand all
309 Intent getStartedIntent(int idx) { 333 Intent getStartedIntent(int idx) {
310 return startedIntents.get(idx); 334 return startedIntents.get(idx);
311 } 335 }
312 336
313 @Override 337 @Override
314 public PackageManager getPackageManager() { 338 public PackageManager getPackageManager() {
315 return getBaseContext().getPackageManager(); 339 return getBaseContext().getPackageManager();
316 } 340 }
317 } 341 }
318 } 342 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698