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

Unified Diff: chrome/android/junit/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTaskTest.java

Issue 2737093002: [Offline pages] Clean up of device conditions related code (Closed)
Patch Set: Compilation fix and small code update Created 3 years, 9 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/junit/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTaskTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTaskTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTaskTest.java
index d09cfd91903c41cb71a88ea2a988a98314304050..8fbd78bdb7435e6f1d57cbc5c180da912aebd9db 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTaskTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTaskTest.java
@@ -10,8 +10,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.when;
import android.app.Activity;
import android.content.Context;
@@ -25,8 +23,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.internal.ShadowExtractor;
@@ -47,7 +43,8 @@ import org.chromium.net.ConnectionType;
*/
@RunWith(OfflinePageTestRunner.class)
@Config(manifest = Config.NONE, application = BaseChromiumApplication.class,
- shadows = {ShadowGcmNetworkManager.class, ShadowGoogleApiAvailability.class})
+ shadows = {ShadowGcmNetworkManager.class, ShadowGoogleApiAvailability.class,
+ ShadowDeviceConditions.class})
public class BackgroundOfflinerTaskTest {
private static final boolean REQUIRE_POWER = true;
private static final boolean REQUIRE_UNMETERED = true;
@@ -59,9 +56,6 @@ public class BackgroundOfflinerTaskTest {
@Rule
public DisableHistogramsRule mDisableHistogramsRule = new DisableHistogramsRule();
- @Mock
- private OfflinePageUtils mOfflinePageUtils;
-
private Bundle mTaskExtras;
private long mTestTime;
private StubBackgroundSchedulerProcessor mStubBackgroundSchedulerProcessor;
@@ -76,16 +70,13 @@ public class BackgroundOfflinerTaskTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- when(mOfflinePageUtils.getDeviceConditionsImpl(any(Context.class)))
- .thenReturn(mDeviceConditions);
+ ShadowDeviceConditions.setCurrentConditions(mDeviceConditions);
// Build a bundle with trigger conditions.
mTaskExtras = new Bundle();
TaskExtrasPacker.packTimeInBundle(mTaskExtras);
TaskExtrasPacker.packTriggerConditionsInBundle(mTaskExtras, mTriggerConditions);
- OfflinePageUtils.setInstanceForTesting(mOfflinePageUtils);
mStubBackgroundSchedulerProcessor = new StubBackgroundSchedulerProcessor();
mContext = RuntimeEnvironment.application;
mGcmNetworkManager = (ShadowGcmNetworkManager) ShadowExtractor.extract(
@@ -161,8 +152,7 @@ public class BackgroundOfflinerTaskTest {
// Setup low battery conditions.
DeviceConditions deviceConditionsLowBattery = new DeviceConditions(
!POWER_CONNECTED, MINIMUM_BATTERY_LEVEL - 1, ConnectionType.CONNECTION_WIFI);
- when(mOfflinePageUtils.getDeviceConditionsImpl(any(Context.class)))
- .thenReturn(deviceConditionsLowBattery);
+ ShadowDeviceConditions.setCurrentConditions(deviceConditionsLowBattery);
BackgroundOfflinerTask task = new BackgroundOfflinerTask(mStubBackgroundSchedulerProcessor);
ChromeBackgroundServiceWaiter waiter = new ChromeBackgroundServiceWaiter(1);
@@ -182,8 +172,7 @@ public class BackgroundOfflinerTaskTest {
// Now verify low battery level but with power connected will start processing.
DeviceConditions deviceConditionsPowerConnected = new DeviceConditions(
POWER_CONNECTED, MINIMUM_BATTERY_LEVEL - 1, ConnectionType.CONNECTION_WIFI);
- when(mOfflinePageUtils.getDeviceConditionsImpl(any(Context.class)))
- .thenReturn(deviceConditionsPowerConnected);
+ ShadowDeviceConditions.setCurrentConditions(deviceConditionsPowerConnected);
BackgroundOfflinerTask task2 =
new BackgroundOfflinerTask(mStubBackgroundSchedulerProcessor);

Powered by Google App Engine
This is Rietveld 408576698