From 9a4643cd0e2167c362465a51e75a18ac8c9cfb36 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Fri, 25 Mar 2016 17:51:45 -0700 Subject: [PATCH] Improved test case for blacklist access. BUG: 27127112 BUG: 26685616 Change-Id: I8b183cdb1cf5ebbc446176a042e4196ab063f1a3 --- .../cts/net/hostside/DataSaverModeTest.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/DataSaverModeTest.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/DataSaverModeTest.java index de75a49935..2971f9dfee 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/DataSaverModeTest.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/DataSaverModeTest.java @@ -24,7 +24,10 @@ import static android.net.ConnectivityManager.RESTRICT_BACKGROUND_STATUS_WHITELI * TODO: need to add more scenarios: * - test access on foreground app * - test access on foreground service app - * - make sure it tests transition of data saver status while app is on foreground + * - make sure it works when app is on foreground and state is transitioned: + * - data saver is enabled + * - app is added/removed to blacklist + * */ public class DataSaverModeTest extends AbstractRestrictBackgroundNetworkTestCase { @@ -46,13 +49,13 @@ public class DataSaverModeTest extends AbstractRestrictBackgroundNetworkTestCase public void testGetRestrictBackgroundStatus_disabled() throws Exception { removeRestrictBackgroundWhitelist(mUid); - assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_DISABLED); assertRestrictBackgroundChangedReceived(0); + assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_DISABLED); // Sanity check: make sure status is always disabled, never whitelisted addRestrictBackgroundWhitelist(mUid); - assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_DISABLED); assertRestrictBackgroundChangedReceived(0); + assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_DISABLED); } public void testGetRestrictBackgroundStatus_whitelisted() throws Exception { @@ -60,40 +63,39 @@ public class DataSaverModeTest extends AbstractRestrictBackgroundNetworkTestCase assertRestrictBackgroundChangedReceived(1); addRestrictBackgroundWhitelist(mUid); - assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_WHITELISTED); assertRestrictBackgroundChangedReceived(2); + assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_WHITELISTED); } public void testGetRestrictBackgroundStatus_enabled() throws Exception { setRestrictBackground(true); assertRestrictBackgroundChangedReceived(1); + assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_ENABLED); removeRestrictBackgroundWhitelist(mUid); - assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_ENABLED); assertRestrictBackgroundChangedReceived(1); + assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_ENABLED); } public void testGetRestrictBackgroundStatus_blacklisted() throws Exception { addRestrictBackgroundBlacklist(mUid); assertRestrictBackgroundChangedReceived(1); - assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_ENABLED); - // TODO: currently whitelist is prevailing, hence remaining of the test below is disabled - if (true) return; - // Make sure blacklist prevails over whitelist. setRestrictBackground(true); assertRestrictBackgroundChangedReceived(2); + assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_ENABLED); addRestrictBackgroundWhitelist(mUid); + assertRestrictBackgroundChangedReceived(3); assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_ENABLED); // Check status after removing blacklist. removeRestrictBackgroundBlacklist(mUid); - assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_WHITELISTED); - assertRestrictBackgroundChangedReceived(3); - setRestrictBackground(false); - assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_DISABLED); assertRestrictBackgroundChangedReceived(4); + assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_WHITELISTED); + setRestrictBackground(false); + assertRestrictBackgroundChangedReceived(5); + assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_DISABLED); } }