Added tests for network restrictions while the screen is off.

BUG: 30785671
Change-Id: I1b211e545ff234272ff6acadfda9ce97765695a9
(cherry picked from commit b80a93061aa7d0a19b47a7dbb82f0dc06e3afb7e)
This commit is contained in:
Felipe Leme
2016-08-10 13:16:15 -07:00
parent b7ff856a2a
commit 2882cd2a7a
3 changed files with 21 additions and 5 deletions

View File

@@ -85,16 +85,24 @@ abstract class AbstractBatterySaverModeTestCase extends AbstractRestrictBackgrou
assertsForegroundAlwaysHasNetworkAccess();
assertBackgroundNetworkAccess(false);
// Make sure foreground app doesn't lose access upon enabling it.
// Make sure foreground app doesn't lose access upon Battery Saver.
setBatterySaverMode(false);
launchActivity();
assertForegroundNetworkAccess();
setBatterySaverMode(true);
assertForegroundNetworkAccess();
// Although it should not have access while the screen is off.
turnScreenOff();
assertBackgroundNetworkAccess(false);
turnScreenOn();
assertForegroundNetworkAccess();
// Goes back to background state.
finishActivity();
assertBackgroundNetworkAccess(false);
// Same for foreground service.
// Make sure foreground service doesn't lose access upon enabling Battery Saver.
setBatterySaverMode(false);
startForegroundService();
assertForegroundNetworkAccess();

View File

@@ -244,7 +244,7 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
if (isBackground(state.state)) {
return;
}
Log.d(TAG, "App not on background state on attempt #" + i
Log.d(TAG, "App not on background state (" + state + ") on attempt #" + i
+ "; sleeping 1s before trying again");
SystemClock.sleep(SECOND_IN_MS);
}

View File

@@ -98,16 +98,24 @@ public class DataSaverModeTest extends AbstractRestrictBackgroundNetworkTestCase
assertsForegroundAlwaysHasNetworkAccess();
assertDataSaverStatusOnBackground(RESTRICT_BACKGROUND_STATUS_ENABLED);
// Make sure foreground app doesn't lose access upon enabling it.
// Make sure foreground app doesn't lose access upon enabling Data Saver.
setRestrictBackground(false);
launchActivity();
assertForegroundNetworkAccess();
setRestrictBackground(true);
assertForegroundNetworkAccess();
// Although it should not have access while the screen is off.
turnScreenOff();
assertBackgroundNetworkAccess(false);
turnScreenOn();
assertForegroundNetworkAccess();
// Goes back to background state.
finishActivity();
assertBackgroundNetworkAccess(false);
// Same for foreground service.
// Make sure foreground service doesn't lose access upon enabling Data Saver.
setRestrictBackground(false);
startForegroundService();
assertForegroundNetworkAccess();