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

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

Issue 2784353002: Android: Remove GetApplicationContext part 2 (Closed)
Patch Set: Fix tests Created 3 years, 8 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 df4ae0027797468aa52eb817f9a2878a3067dc69..57d675ea4e33efb9797939881b6d3896b219e871 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
@@ -17,6 +17,7 @@ import org.junit.Rule;
import org.junit.Test;
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.test.invalidation.IntentSavingContext;
@@ -41,18 +42,21 @@ public class InvalidationServiceTest {
@Rule
public UiThreadTestRule mUiThreadTestRule = new UiThreadTestRule();
- private IntentSavingContext mContext;
+ private IntentSavingContext mAppContext;
@Before
public void setUp() throws Exception {
mActivityTestRule.loadNativeLibraryAndInitBrowserProcess();
- mContext = new IntentSavingContext(
- InstrumentationRegistry.getInstrumentation().getTargetContext());
+ mAppContext = new IntentSavingContext(InstrumentationRegistry.getInstrumentation()
+ .getTargetContext()
+ .getApplicationContext());
+ // TODO(wnwen): Remove mAppContext and just use application context.
// We don't want to use the system content resolver, so we override it.
MockSyncContentResolverDelegate delegate = new MockSyncContentResolverDelegate();
// Android master sync can safely always be on.
delegate.setMasterSyncAutomatically(true);
- AndroidSyncSettings.overrideForTests(mContext, delegate);
+ AndroidSyncSettings.overrideForTests(mAppContext, delegate);
+ ContextUtils.initApplicationContextForTests(mAppContext);
}
@Test
@@ -62,14 +66,14 @@ public class InvalidationServiceTest {
mUiThreadTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
- InvalidationService service = InvalidationServiceFactory.getForTest(mContext);
+ 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, mContext.getNumStartedIntents());
+ Assert.assertEquals(1, mAppContext.getNumStartedIntents());
// Validate destination.
- Intent intent = mContext.getStartedIntent(0);
+ Intent intent = mAppContext.getStartedIntent(0);
validateIntentComponent(intent);
Assert.assertEquals(InvalidationIntentProtocol.ACTION_REGISTER, intent.getAction());

Powered by Google App Engine
This is Rietveld 408576698