Loading packages/Tethering/tests/unit/src/com/android/server/connectivity/tethering/EntitlementManagerTest.java +0 −26 Original line number Original line Diff line number Diff line Loading @@ -33,7 +33,6 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSess import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString; Loading Loading @@ -72,8 +71,6 @@ import org.mockito.MockitoSession; import org.mockito.quality.Strictness; import org.mockito.quality.Strictness; import java.util.ArrayList; import java.util.ArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class) @SmallTest @SmallTest Loading Loading @@ -255,19 +252,16 @@ public final class EntitlementManagerTest { @Test @Test public void testRequestLastEntitlementCacheValue() throws Exception { public void testRequestLastEntitlementCacheValue() throws Exception { final CountDownLatch mCallbacklatch = new CountDownLatch(1); // 1. Entitlement check is not required. // 1. Entitlement check is not required. mEnMgr.fakeEntitlementResult = TETHER_ERROR_NO_ERROR; mEnMgr.fakeEntitlementResult = TETHER_ERROR_NO_ERROR; ResultReceiver receiver = new ResultReceiver(null) { ResultReceiver receiver = new ResultReceiver(null) { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_NO_ERROR, resultCode); assertEquals(TETHER_ERROR_NO_ERROR, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(0, mEnMgr.uiProvisionCount); assertEquals(0, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); Loading @@ -277,12 +271,10 @@ public final class EntitlementManagerTest { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_ENTITLEMENT_UNKNOWN, resultCode); assertEquals(TETHER_ERROR_ENTITLEMENT_UNKNOWN, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, false); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, false); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(0, mEnMgr.uiProvisionCount); assertEquals(0, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); // 3. No cache value and ui entitlement check is needed. // 3. No cache value and ui entitlement check is needed. Loading @@ -291,12 +283,10 @@ public final class EntitlementManagerTest { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_PROVISIONING_FAILED, resultCode); assertEquals(TETHER_ERROR_PROVISIONING_FAILED, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(1, mEnMgr.uiProvisionCount); assertEquals(1, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); // 4. Cache value is TETHER_ERROR_PROVISIONING_FAILED and don't need to run entitlement // 4. Cache value is TETHER_ERROR_PROVISIONING_FAILED and don't need to run entitlement Loading @@ -306,12 +296,10 @@ public final class EntitlementManagerTest { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_PROVISIONING_FAILED, resultCode); assertEquals(TETHER_ERROR_PROVISIONING_FAILED, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, false); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, false); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(0, mEnMgr.uiProvisionCount); assertEquals(0, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); // 5. Cache value is TETHER_ERROR_PROVISIONING_FAILED and ui entitlement check is needed. // 5. Cache value is TETHER_ERROR_PROVISIONING_FAILED and ui entitlement check is needed. Loading @@ -320,12 +308,10 @@ public final class EntitlementManagerTest { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_NO_ERROR, resultCode); assertEquals(TETHER_ERROR_NO_ERROR, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(1, mEnMgr.uiProvisionCount); assertEquals(1, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); // 6. Cache value is TETHER_ERROR_NO_ERROR. // 6. Cache value is TETHER_ERROR_NO_ERROR. Loading @@ -334,12 +320,10 @@ public final class EntitlementManagerTest { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_NO_ERROR, resultCode); assertEquals(TETHER_ERROR_NO_ERROR, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(0, mEnMgr.uiProvisionCount); assertEquals(0, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); // 7. Test get value for other downstream type. // 7. Test get value for other downstream type. Loading @@ -347,12 +331,10 @@ public final class EntitlementManagerTest { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_ENTITLEMENT_UNKNOWN, resultCode); assertEquals(TETHER_ERROR_ENTITLEMENT_UNKNOWN, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_USB, receiver, false); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_USB, receiver, false); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(0, mEnMgr.uiProvisionCount); assertEquals(0, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); // 8. Test get value for invalid downstream type. // 8. Test get value for invalid downstream type. Loading @@ -361,22 +343,14 @@ public final class EntitlementManagerTest { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_ENTITLEMENT_UNKNOWN, resultCode); assertEquals(TETHER_ERROR_ENTITLEMENT_UNKNOWN, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI_P2P, receiver, true); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI_P2P, receiver, true); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(0, mEnMgr.uiProvisionCount); assertEquals(0, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); } } void callbackTimeoutHelper(final CountDownLatch latch) throws Exception { if (!latch.await(1, TimeUnit.SECONDS)) { fail("Timout, fail to receive callback"); } } @Test @Test public void verifyPermissionResult() { public void verifyPermissionResult() { setupForRequiredProvisioning(); setupForRequiredProvisioning(); Loading Loading
packages/Tethering/tests/unit/src/com/android/server/connectivity/tethering/EntitlementManagerTest.java +0 −26 Original line number Original line Diff line number Diff line Loading @@ -33,7 +33,6 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSess import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString; Loading Loading @@ -72,8 +71,6 @@ import org.mockito.MockitoSession; import org.mockito.quality.Strictness; import org.mockito.quality.Strictness; import java.util.ArrayList; import java.util.ArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class) @SmallTest @SmallTest Loading Loading @@ -255,19 +252,16 @@ public final class EntitlementManagerTest { @Test @Test public void testRequestLastEntitlementCacheValue() throws Exception { public void testRequestLastEntitlementCacheValue() throws Exception { final CountDownLatch mCallbacklatch = new CountDownLatch(1); // 1. Entitlement check is not required. // 1. Entitlement check is not required. mEnMgr.fakeEntitlementResult = TETHER_ERROR_NO_ERROR; mEnMgr.fakeEntitlementResult = TETHER_ERROR_NO_ERROR; ResultReceiver receiver = new ResultReceiver(null) { ResultReceiver receiver = new ResultReceiver(null) { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_NO_ERROR, resultCode); assertEquals(TETHER_ERROR_NO_ERROR, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(0, mEnMgr.uiProvisionCount); assertEquals(0, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); Loading @@ -277,12 +271,10 @@ public final class EntitlementManagerTest { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_ENTITLEMENT_UNKNOWN, resultCode); assertEquals(TETHER_ERROR_ENTITLEMENT_UNKNOWN, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, false); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, false); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(0, mEnMgr.uiProvisionCount); assertEquals(0, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); // 3. No cache value and ui entitlement check is needed. // 3. No cache value and ui entitlement check is needed. Loading @@ -291,12 +283,10 @@ public final class EntitlementManagerTest { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_PROVISIONING_FAILED, resultCode); assertEquals(TETHER_ERROR_PROVISIONING_FAILED, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(1, mEnMgr.uiProvisionCount); assertEquals(1, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); // 4. Cache value is TETHER_ERROR_PROVISIONING_FAILED and don't need to run entitlement // 4. Cache value is TETHER_ERROR_PROVISIONING_FAILED and don't need to run entitlement Loading @@ -306,12 +296,10 @@ public final class EntitlementManagerTest { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_PROVISIONING_FAILED, resultCode); assertEquals(TETHER_ERROR_PROVISIONING_FAILED, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, false); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, false); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(0, mEnMgr.uiProvisionCount); assertEquals(0, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); // 5. Cache value is TETHER_ERROR_PROVISIONING_FAILED and ui entitlement check is needed. // 5. Cache value is TETHER_ERROR_PROVISIONING_FAILED and ui entitlement check is needed. Loading @@ -320,12 +308,10 @@ public final class EntitlementManagerTest { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_NO_ERROR, resultCode); assertEquals(TETHER_ERROR_NO_ERROR, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(1, mEnMgr.uiProvisionCount); assertEquals(1, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); // 6. Cache value is TETHER_ERROR_NO_ERROR. // 6. Cache value is TETHER_ERROR_NO_ERROR. Loading @@ -334,12 +320,10 @@ public final class EntitlementManagerTest { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_NO_ERROR, resultCode); assertEquals(TETHER_ERROR_NO_ERROR, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(0, mEnMgr.uiProvisionCount); assertEquals(0, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); // 7. Test get value for other downstream type. // 7. Test get value for other downstream type. Loading @@ -347,12 +331,10 @@ public final class EntitlementManagerTest { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_ENTITLEMENT_UNKNOWN, resultCode); assertEquals(TETHER_ERROR_ENTITLEMENT_UNKNOWN, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_USB, receiver, false); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_USB, receiver, false); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(0, mEnMgr.uiProvisionCount); assertEquals(0, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); // 8. Test get value for invalid downstream type. // 8. Test get value for invalid downstream type. Loading @@ -361,22 +343,14 @@ public final class EntitlementManagerTest { @Override @Override protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) { assertEquals(TETHER_ERROR_ENTITLEMENT_UNKNOWN, resultCode); assertEquals(TETHER_ERROR_ENTITLEMENT_UNKNOWN, resultCode); mCallbacklatch.countDown(); } } }; }; mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI_P2P, receiver, true); mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI_P2P, receiver, true); mLooper.dispatchAll(); mLooper.dispatchAll(); callbackTimeoutHelper(mCallbacklatch); assertEquals(0, mEnMgr.uiProvisionCount); assertEquals(0, mEnMgr.uiProvisionCount); mEnMgr.reset(); mEnMgr.reset(); } } void callbackTimeoutHelper(final CountDownLatch latch) throws Exception { if (!latch.await(1, TimeUnit.SECONDS)) { fail("Timout, fail to receive callback"); } } @Test @Test public void verifyPermissionResult() { public void verifyPermissionResult() { setupForRequiredProvisioning(); setupForRequiredProvisioning(); Loading