summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAhmed ElArabawy <arabawy@google.com>2018-08-20 18:06:09 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-08-20 18:06:09 +0000
commit0df9f4904728899a5a4a2073ed9ba3b900ee73e6 (patch)
tree2563647e96f7842dc3bbee0f57ec22f6456983ce /tests
parent4da60b5fbb97f95f7fc3afc03d79a51985bf1298 (diff)
parentbd4ae452150a3605d8a592905ae843516aff4ec5 (diff)
Merge "Release the correct WiFi Multicast Wakelock"
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java96
1 files changed, 93 insertions, 3 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java
index 8939636af..1c560a146 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java
@@ -27,6 +27,7 @@ import com.android.internal.app.IBatteryStats;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -35,6 +36,9 @@ import org.mockito.MockitoAnnotations;
*/
@SmallTest
public class WifiMulticastLockManagerTest {
+ private static final String WL_1_TAG = "Wakelock-1";
+ private static final String WL_2_TAG = "Wakelock-2";
+
@Mock WifiMulticastLockManager.FilterController mHandler;
@Mock IBatteryStats mBatteryStats;
WifiMulticastLockManager mManager;
@@ -64,7 +68,7 @@ public class WifiMulticastLockManagerTest {
@Test
public void oneLock() throws RemoteException {
IBinder binder = mock(IBinder.class);
- mManager.acquireLock(binder, "Test");
+ mManager.acquireLock(binder, WL_1_TAG);
assertTrue(mManager.isMulticastEnabled());
verify(mHandler).stopFilteringMulticastPackets();
mManager.initializeFiltering();
@@ -72,9 +76,95 @@ public class WifiMulticastLockManagerTest {
verify(mBatteryStats).noteWifiMulticastEnabled(anyInt());
verify(mBatteryStats, times(0)).noteWifiMulticastDisabled(anyInt());
- mManager.releaseLock();
+ mManager.releaseLock(WL_1_TAG);
verify(mBatteryStats).noteWifiMulticastDisabled(anyInt());
assertFalse(mManager.isMulticastEnabled());
}
-}
+ /**
+ * Test behavior when one lock is aquired then released with the wrong tag.
+ */
+ @Test
+ public void oneLock_wrongName() throws RemoteException {
+ IBinder binder = mock(IBinder.class);
+ mManager.acquireLock(binder, WL_1_TAG);
+ assertTrue(mManager.isMulticastEnabled());
+ verify(mHandler).stopFilteringMulticastPackets();
+ mManager.initializeFiltering();
+ verify(mHandler, never()).startFilteringMulticastPackets();
+ verify(mBatteryStats).noteWifiMulticastEnabled(anyInt());
+ verify(mBatteryStats, never()).noteWifiMulticastDisabled(anyInt());
+
+ mManager.releaseLock(WL_2_TAG);
+ verify(mBatteryStats, never()).noteWifiMulticastDisabled(anyInt());
+ assertTrue(mManager.isMulticastEnabled());
+ }
+
+ /**
+ * Test behavior when multiple locks are aquired then released in nesting order.
+ */
+ @Test
+ public void multipleLocksInOrder() throws RemoteException {
+ IBinder binder = mock(IBinder.class);
+
+ InOrder inOrderHandler = inOrder(mHandler);
+ InOrder inOrderBatteryStats = inOrder(mBatteryStats);
+
+ mManager.acquireLock(binder, WL_1_TAG);
+ inOrderHandler.verify(mHandler).stopFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastEnabled(anyInt());
+ assertTrue(mManager.isMulticastEnabled());
+
+ mManager.acquireLock(binder, WL_2_TAG);
+ inOrderHandler.verify(mHandler).stopFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastEnabled(anyInt());
+ assertTrue(mManager.isMulticastEnabled());
+
+ mManager.initializeFiltering();
+ inOrderHandler.verify(mHandler, never()).startFilteringMulticastPackets();
+
+ mManager.releaseLock(WL_2_TAG);
+ inOrderHandler.verify(mHandler, never()).startFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastDisabled(anyInt());
+ assertTrue(mManager.isMulticastEnabled());
+
+ mManager.releaseLock(WL_1_TAG);
+ inOrderHandler.verify(mHandler).startFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastDisabled(anyInt());
+ assertFalse(mManager.isMulticastEnabled());
+ }
+
+ /**
+ * Test behavior when multiple locks are aquired then released out of nesting order.
+ */
+ @Test
+ public void multipleLocksOutOfOrder() throws RemoteException {
+ IBinder binder = mock(IBinder.class);
+
+ InOrder inOrderHandler = inOrder(mHandler);
+ InOrder inOrderBatteryStats = inOrder(mBatteryStats);
+
+ mManager.acquireLock(binder, WL_1_TAG);
+ inOrderHandler.verify(mHandler).stopFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastEnabled(anyInt());
+ assertTrue(mManager.isMulticastEnabled());
+
+ mManager.acquireLock(binder, WL_2_TAG);
+ inOrderHandler.verify(mHandler).stopFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastEnabled(anyInt());
+ assertTrue(mManager.isMulticastEnabled());
+
+ mManager.initializeFiltering();
+ inOrderHandler.verify(mHandler, never()).startFilteringMulticastPackets();
+
+ mManager.releaseLock(WL_1_TAG);
+ inOrderHandler.verify(mHandler, never()).startFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastDisabled(anyInt());
+ assertTrue(mManager.isMulticastEnabled());
+
+ mManager.releaseLock(WL_2_TAG);
+ inOrderHandler.verify(mHandler).startFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastDisabled(anyInt());
+ assertFalse(mManager.isMulticastEnabled());
+ }
+}