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

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

Issue 1324173002: [Background Sync] Use GcmNetworkManager to start the browser for sync events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@bgsync-fix-background5
Patch Set: Make BackgroundSyncLauncher testable Created 5 years, 2 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/BackgroundSyncLauncherTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/BackgroundSyncLauncherTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/BackgroundSyncLauncherTest.java
similarity index 52%
rename from content/public/android/javatests/src/org/chromium/content/browser/BackgroundSyncLauncherTest.java
rename to chrome/android/javatests/src/org/chromium/chrome/browser/BackgroundSyncLauncherTest.java
index 0fc40e3bc5b8abf7c9472b2e005d5ac9d938c151..e78eea275328ec329f4bf536180d847b3a8c8cb9 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/BackgroundSyncLauncherTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/BackgroundSyncLauncherTest.java
@@ -2,11 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-package org.chromium.content.browser;
+package org.chromium.chrome.browser;
import android.content.Context;
-import android.content.Intent;
-import android.net.ConnectivityManager;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
@@ -16,46 +14,24 @@ import org.chromium.base.test.util.Feature;
import java.util.concurrent.Semaphore;
/**
- * Tests {@link BackgroundSyncLauncherService} and {@link BackgroundSyncLauncherService.Receiver}.
+ * Tests {@link BackgroundSyncLauncher}.
*/
public class BackgroundSyncLauncherTest extends InstrumentationTestCase {
private Context mContext;
private BackgroundSyncLauncher mLauncher;
- private MockReceiver mLauncherServiceReceiver;
private Boolean mShouldLaunchResult;
- static class MockReceiver extends BackgroundSyncLauncherService.Receiver {
- private boolean mIsOnline = true;
- private boolean mDidStartService;
-
- public void setOnline(boolean online) {
- mIsOnline = online;
- }
-
- @Override
- protected boolean isOnline(Context context) {
- return mIsOnline;
- }
-
- @Override
- protected void startService(Context context) {
- startServiceImpl();
- }
-
- private void startServiceImpl() {
- mDidStartService = true;
- }
-
- protected void checkExpectations(boolean expectedStartService) {
- assertEquals("StartedService", expectedStartService, mDidStartService);
- }
- }
-
@Override
protected void setUp() throws Exception {
mContext = new AdvancedMockContext(getInstrumentation().getTargetContext());
+ BackgroundSyncLauncher.setGCMEnabled(false);
mLauncher = BackgroundSyncLauncher.create(mContext);
- mLauncherServiceReceiver = new MockReceiver();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ BackgroundSyncLauncher.setGCMEnabled(true);
+ super.tearDown();
}
private void deleteLauncherInstance() {
@@ -63,12 +39,6 @@ public class BackgroundSyncLauncherTest extends InstrumentationTestCase {
mLauncher = null;
}
- private void startOnReceiveAndVerify(boolean shouldStart) {
- mLauncherServiceReceiver.onReceive(
- mContext, new Intent(ConnectivityManager.CONNECTIVITY_ACTION));
- mLauncherServiceReceiver.checkExpectations(shouldStart);
- }
-
private Boolean shouldLaunchWhenNextOnlineSync() {
mShouldLaunchResult = false;
@@ -112,16 +82,16 @@ public class BackgroundSyncLauncherTest extends InstrumentationTestCase {
@Feature({"BackgroundSync"})
public void testSetLaunchWhenNextOnline() {
assertFalse(shouldLaunchWhenNextOnlineSync());
- mLauncher.setLaunchWhenNextOnline(mContext, true);
+ mLauncher.launchBrowserWhenNextOnlineIfStopped(mContext, true);
assertTrue(shouldLaunchWhenNextOnlineSync());
- mLauncher.setLaunchWhenNextOnline(mContext, false);
+ mLauncher.launchBrowserWhenNextOnlineIfStopped(mContext, false);
assertFalse(shouldLaunchWhenNextOnlineSync());
}
@SmallTest
@Feature({"BackgroundSync"})
public void testNewLauncherDisablesNextOnline() {
- mLauncher.setLaunchWhenNextOnline(mContext, true);
+ mLauncher.launchBrowserWhenNextOnlineIfStopped(mContext, true);
assertTrue(shouldLaunchWhenNextOnlineSync());
// Simulate restarting the browser by deleting the launcher and creating a new one.
@@ -129,40 +99,4 @@ public class BackgroundSyncLauncherTest extends InstrumentationTestCase {
mLauncher = BackgroundSyncLauncher.create(mContext);
assertFalse(shouldLaunchWhenNextOnlineSync());
}
-
- @SmallTest
- @Feature({"BackgroundSync"})
- public void testNoFireWhenInstanceExists() {
- mLauncher.setLaunchWhenNextOnline(mContext, true);
- mLauncherServiceReceiver.setOnline(true);
- startOnReceiveAndVerify(false);
-
- deleteLauncherInstance();
- startOnReceiveAndVerify(true);
- }
-
- @SmallTest
- @Feature({"BackgroundSync"})
- public void testReceiverOffline() {
- mLauncher.setLaunchWhenNextOnline(mContext, true);
- mLauncherServiceReceiver.setOnline(false);
- deleteLauncherInstance();
- startOnReceiveAndVerify(false);
- }
-
- @SmallTest
- @Feature({"BackgroundSync"})
- public void testReceiverOnline() {
- mLauncher.setLaunchWhenNextOnline(mContext, true);
- mLauncherServiceReceiver.setOnline(true);
- deleteLauncherInstance();
- startOnReceiveAndVerify(true);
- }
-
- @SmallTest
- @Feature({"BackgroundSync"})
- public void testStartingService() {
- Intent serviceIntent = new Intent(mContext, BackgroundSyncLauncherService.class);
- MockReceiver.startWakefulService(mContext, serviceIntent);
- }
}

Powered by Google App Engine
This is Rietveld 408576698