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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/invalidation/InvalidationServiceTest.java

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

Powered by Google App Engine
This is Rietveld 408576698