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.chrome.browser.invalidation; | 5 package org.chromium.chrome.browser.invalidation; |
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; | |
10 import android.content.Context; | |
11 import android.content.Intent; | 9 import android.content.Intent; |
12 import android.content.pm.PackageManager; | |
13 import android.test.InstrumentationTestCase; | 10 import android.test.InstrumentationTestCase; |
14 import android.test.suitebuilder.annotation.SmallTest; | 11 import android.test.suitebuilder.annotation.SmallTest; |
15 | 12 |
16 import com.google.ipc.invalidation.external.client.types.ObjectId; | |
17 | |
18 import org.chromium.base.ActivityState; | 13 import org.chromium.base.ActivityState; |
19 import org.chromium.base.ApplicationState; | 14 import org.chromium.base.ApplicationState; |
20 import org.chromium.base.ApplicationStatus; | 15 import org.chromium.base.ApplicationStatus; |
21 import org.chromium.base.CollectionUtil; | 16 import org.chromium.base.CollectionUtil; |
22 import org.chromium.base.test.util.AdvancedMockContext; | |
23 import org.chromium.base.test.util.Feature; | 17 import org.chromium.base.test.util.Feature; |
| 18 import org.chromium.components.invalidation.InvalidationClientService; |
24 import org.chromium.sync.internal_api.pub.base.ModelType; | 19 import org.chromium.sync.internal_api.pub.base.ModelType; |
25 import org.chromium.sync.notifier.InvalidationIntentProtocol; | 20 import org.chromium.sync.notifier.InvalidationIntentProtocol; |
26 import org.chromium.sync.notifier.InvalidationPreferences; | 21 import org.chromium.sync.notifier.InvalidationPreferences; |
27 import org.chromium.sync.notifier.InvalidationService; | |
28 import org.chromium.sync.notifier.SyncStatusHelper; | 22 import org.chromium.sync.notifier.SyncStatusHelper; |
29 import org.chromium.sync.signin.AccountManagerHelper; | 23 import org.chromium.sync.signin.AccountManagerHelper; |
30 import org.chromium.sync.signin.ChromeSigninController; | 24 import org.chromium.sync.signin.ChromeSigninController; |
31 import org.chromium.sync.test.util.MockSyncContentResolverDelegate; | 25 import org.chromium.sync.test.util.MockSyncContentResolverDelegate; |
32 | 26 |
33 import java.util.ArrayList; | 27 import java.util.ArrayList; |
34 import java.util.HashSet; | 28 import java.util.HashSet; |
35 import java.util.List; | 29 import java.util.List; |
36 import java.util.Set; | 30 import java.util.Set; |
37 import java.util.concurrent.atomic.AtomicBoolean; | 31 import java.util.concurrent.atomic.AtomicBoolean; |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 }; | 275 }; |
282 | 276 |
283 // Execute the test. | 277 // Execute the test. |
284 controller.refreshRegisteredTypes(new HashSet<ModelType>()); | 278 controller.refreshRegisteredTypes(new HashSet<ModelType>()); |
285 | 279 |
286 // Validate the values. | 280 // Validate the values. |
287 assertEquals(storedAccount, resultAccount.get()); | 281 assertEquals(storedAccount, resultAccount.get()); |
288 assertEquals(true, resultAllTypes.get()); | 282 assertEquals(true, resultAllTypes.get()); |
289 } | 283 } |
290 | 284 |
291 @SmallTest | |
292 @Feature({"Sync"}) | |
293 public void testSetRegisteredObjectIds() { | |
294 InvalidationController controller = new InvalidationController(mContext)
; | |
295 ObjectId bookmark = ModelType.BOOKMARK.toObjectId(); | |
296 controller.setRegisteredObjectIds(new int[] {1, 2, bookmark.getSource()}
, | |
297 new String[] {"a", "b", new String(boo
kmark.getName())}); | |
298 assertEquals(1, mContext.getNumStartedIntents()); | |
299 | |
300 // Validate destination. | |
301 Intent intent = mContext.getStartedIntent(0); | |
302 validateIntentComponent(intent); | |
303 assertEquals(InvalidationIntentProtocol.ACTION_REGISTER, intent.getActio
n()); | |
304 | |
305 // Validate registered object ids. The bookmark object should not be reg
istered since it is | |
306 // a Sync type. | |
307 assertNull(intent.getStringArrayListExtra( | |
308 InvalidationIntentProtocol.EXTRA_REGISTERED_TYPE
S)); | |
309 Set<ObjectId> objectIds = InvalidationIntentProtocol.getRegisteredObject
Ids(intent); | |
310 assertEquals(2, objectIds.size()); | |
311 assertTrue(objectIds.contains(ObjectId.newInstance(1, "a".getBytes()))); | |
312 assertTrue(objectIds.contains(ObjectId.newInstance(2, "b".getBytes()))); | |
313 } | |
314 | |
315 /** | 285 /** |
316 * Asserts that {@code intent} is destined for the correct component. | 286 * Asserts that {@code intent} is destined for the correct component. |
317 */ | 287 */ |
318 private static void validateIntentComponent(Intent intent) { | 288 private static void validateIntentComponent(Intent intent) { |
319 assertNotNull(intent.getComponent()); | 289 assertNotNull(intent.getComponent()); |
320 assertEquals(InvalidationService.class.getName(), | 290 assertEquals(InvalidationClientService.class.getName(), |
321 intent.getComponent().getClassName()); | 291 intent.getComponent().getClassName()); |
322 } | 292 } |
323 | 293 |
324 /** | |
325 * Mock context that saves all intents given to {@code startService}. | |
326 */ | |
327 private static class IntentSavingContext extends AdvancedMockContext { | |
328 private final List<Intent> mStartedIntents = new ArrayList<Intent>(); | |
329 | |
330 IntentSavingContext(Context targetContext) { | |
331 super(targetContext); | |
332 } | |
333 | |
334 @Override | |
335 public ComponentName startService(Intent intent) { | |
336 mStartedIntents.add(intent); | |
337 return new ComponentName(this, getClass()); | |
338 } | |
339 | |
340 int getNumStartedIntents() { | |
341 return mStartedIntents.size(); | |
342 } | |
343 | |
344 Intent getStartedIntent(int idx) { | |
345 return mStartedIntents.get(idx); | |
346 } | |
347 | |
348 @Override | |
349 public PackageManager getPackageManager() { | |
350 return getBaseContext().getPackageManager(); | |
351 } | |
352 } | |
353 | |
354 } | 294 } |
OLD | NEW |