OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chrome.browser.invalidation; | |
6 | |
7 import android.content.Intent; | |
8 import android.test.UiThreadTest; | |
9 import android.test.suitebuilder.annotation.SmallTest; | |
10 | |
11 import com.google.ipc.invalidation.external.client.types.ObjectId; | |
12 | |
13 import org.chromium.base.test.util.Feature; | |
14 import org.chromium.chrome.shell.ChromeShellTestBase; | |
15 import org.chromium.components.invalidation.InvalidationClientService; | |
16 import org.chromium.components.invalidation.InvalidationService; | |
17 import org.chromium.sync.AndroidSyncSettings; | |
18 import org.chromium.sync.internal_api.pub.base.ModelType; | |
19 import org.chromium.sync.notifier.InvalidationIntentProtocol; | |
20 import org.chromium.sync.test.util.MockSyncContentResolverDelegate; | |
21 | |
22 import java.util.Set; | |
23 | |
24 /** | |
25 * Tests for {@link InvalidationService}. | |
26 */ | |
27 public class InvalidationServiceTest extends ChromeShellTestBase { | |
28 private IntentSavingContext mContext; | |
29 | |
30 @Override | |
31 protected void setUp() throws Exception { | |
32 super.setUp(); | |
33 startChromeBrowserProcessSync(getInstrumentation().getTargetContext()); | |
34 mContext = new IntentSavingContext(getInstrumentation().getTargetContext
()); | |
35 // We don't want to use the system content resolver, so we override it. | |
36 MockSyncContentResolverDelegate delegate = new MockSyncContentResolverDe
legate(); | |
37 // Android master sync can safely always be on. | |
38 delegate.setMasterSyncAutomatically(true); | |
39 AndroidSyncSettings.overrideForTests(mContext, delegate); | |
40 } | |
41 | |
42 @SmallTest | |
43 @UiThreadTest | |
44 @Feature({"Sync"}) | |
45 public void testSetRegisteredObjectIds() { | |
46 InvalidationService service = InvalidationServiceFactory.getForTest(mCon
text); | |
47 ObjectId bookmark = ModelType.BOOKMARK.toObjectId(); | |
48 service.setRegisteredObjectIds(new int[] {1, 2, bookmark.getSource()}, | |
49 new String[] {"a", "b", new String(boo
kmark.getName())}); | |
50 assertEquals(1, mContext.getNumStartedIntents()); | |
51 | |
52 // Validate destination. | |
53 Intent intent = mContext.getStartedIntent(0); | |
54 validateIntentComponent(intent); | |
55 assertEquals(InvalidationIntentProtocol.ACTION_REGISTER, intent.getActio
n()); | |
56 | |
57 // Validate registered object ids. The bookmark object should not be reg
istered since it is | |
58 // a Sync type. | |
59 assertNull(intent.getStringArrayListExtra( | |
60 InvalidationIntentProtocol.EXTRA_REGISTERED_TYPE
S)); | |
61 Set<ObjectId> objectIds = InvalidationIntentProtocol.getRegisteredObject
Ids(intent); | |
62 assertEquals(2, objectIds.size()); | |
63 assertTrue(objectIds.contains(ObjectId.newInstance(1, "a".getBytes()))); | |
64 assertTrue(objectIds.contains(ObjectId.newInstance(2, "b".getBytes()))); | |
65 } | |
66 | |
67 /** | |
68 * Asserts that {@code intent} is destined for the correct component. | |
69 */ | |
70 private static void validateIntentComponent(Intent intent) { | |
71 assertNotNull(intent.getComponent()); | |
72 assertEquals(InvalidationClientService.class.getName(), | |
73 intent.getComponent().getClassName()); | |
74 } | |
75 | |
76 } | |
OLD | NEW |