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

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

Issue 2954393003: Fix test crashes related to AccountManagerHelper. (Closed)
Patch Set: . Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/invalidation/InvalidationServiceTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/invalidation/InvalidationServiceTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/invalidation/InvalidationServiceTest.java
index 7a20cee18a52d52d8d50d1cedb7833913665e9b3..ca8771ab530d483f7962b095873402b9342b15d5 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/invalidation/InvalidationServiceTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/invalidation/InvalidationServiceTest.java
@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.invalidation;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
+import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
import android.support.test.rule.UiThreadTestRule;
@@ -15,11 +16,13 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.RuleChain;
import org.junit.runner.RunWith;
import org.chromium.base.ContextUtils;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.Feature;
+import org.chromium.chrome.browser.test.ChromeBrowserTestRule;
import org.chromium.chrome.test.invalidation.IntentSavingContext;
import org.chromium.components.invalidation.InvalidationService;
import org.chromium.components.sync.AndroidSyncSettings;
@@ -27,7 +30,6 @@ import org.chromium.components.sync.ModelType;
import org.chromium.components.sync.ModelTypeHelper;
import org.chromium.components.sync.notifier.InvalidationIntentProtocol;
import org.chromium.components.sync.test.util.MockSyncContentResolverDelegate;
-import org.chromium.content.browser.test.NativeLibraryTestRule;
import java.util.Set;
@@ -37,16 +39,13 @@ import java.util.Set;
@RunWith(BaseJUnit4ClassRunner.class)
public class InvalidationServiceTest {
@Rule
- public NativeLibraryTestRule mActivityTestRule = new NativeLibraryTestRule();
-
- @Rule
- public UiThreadTestRule mUiThreadTestRule = new UiThreadTestRule();
+ public final RuleChain mChain =
+ RuleChain.outerRule(new ChromeBrowserTestRule()).around(new UiThreadTestRule());
private IntentSavingContext mAppContext;
@Before
public void setUp() throws Exception {
- mActivityTestRule.loadNativeLibraryAndInitBrowserProcess();
mAppContext = new IntentSavingContext(InstrumentationRegistry.getInstrumentation()
.getTargetContext()
.getApplicationContext());
@@ -60,32 +59,28 @@ public class InvalidationServiceTest {
@Test
@SmallTest
+ @UiThreadTest
@Feature({"Sync"})
public void testSetRegisteredObjectIds() throws Throwable {
- mUiThreadTestRule.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- InvalidationService service = InvalidationServiceFactory.getForTest();
- ObjectId bookmark = ModelTypeHelper.toObjectId(ModelType.BOOKMARKS);
- service.setRegisteredObjectIds(new int[] {1, 2, bookmark.getSource()},
- new String[] {"a", "b", new String(bookmark.getName())});
- Assert.assertEquals(1, mAppContext.getNumStartedIntents());
+ InvalidationService service = InvalidationServiceFactory.getForTest();
+ ObjectId bookmark = ModelTypeHelper.toObjectId(ModelType.BOOKMARKS);
+ service.setRegisteredObjectIds(new int[] {1, 2, bookmark.getSource()},
+ new String[] {"a", "b", new String(bookmark.getName())});
+ Assert.assertEquals(1, mAppContext.getNumStartedIntents());
- // Validate destination.
- Intent intent = mAppContext.getStartedIntent(0);
- validateIntentComponent(intent);
- Assert.assertEquals(InvalidationIntentProtocol.ACTION_REGISTER, intent.getAction());
+ // Validate destination.
+ Intent intent = mAppContext.getStartedIntent(0);
+ validateIntentComponent(intent);
+ Assert.assertEquals(InvalidationIntentProtocol.ACTION_REGISTER, intent.getAction());
- // Validate registered object ids. The bookmark object should not be registered
- // since it is a Sync type.
- Assert.assertNull(intent.getStringArrayListExtra(
- InvalidationIntentProtocol.EXTRA_REGISTERED_TYPES));
- Set<ObjectId> objectIds = InvalidationIntentProtocol.getRegisteredObjectIds(intent);
- Assert.assertEquals(2, objectIds.size());
- Assert.assertTrue(objectIds.contains(ObjectId.newInstance(1, "a".getBytes())));
- Assert.assertTrue(objectIds.contains(ObjectId.newInstance(2, "b".getBytes())));
- }
- });
+ // Validate registered object ids. The bookmark object should not be registered
+ // since it is a Sync type.
+ Assert.assertNull(
+ intent.getStringArrayListExtra(InvalidationIntentProtocol.EXTRA_REGISTERED_TYPES));
+ Set<ObjectId> objectIds = InvalidationIntentProtocol.getRegisteredObjectIds(intent);
+ Assert.assertEquals(2, objectIds.size());
+ Assert.assertTrue(objectIds.contains(ObjectId.newInstance(1, "a".getBytes())));
+ Assert.assertTrue(objectIds.contains(ObjectId.newInstance(2, "b".getBytes())));
}
/**

Powered by Google App Engine
This is Rietveld 408576698