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); |
- } |
} |