Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 1 | package com.android.systemui.statusbar.policy; |
| 2 | |
| 3 | import android.net.NetworkCapabilities; |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 4 | import android.support.test.runner.AndroidJUnit4; |
Jason Monk | e427cb8 | 2015-07-28 09:18:08 -0400 | [diff] [blame] | 5 | import android.test.suitebuilder.annotation.SmallTest; |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 6 | import android.testing.AndroidTestingRunner; |
| 7 | import android.testing.TestableLooper.RunWithLooper; |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 8 | |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 9 | import com.android.systemui.statusbar.policy.NetworkController.IconState; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 10 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 11 | import org.junit.Test; |
| 12 | import org.junit.runner.RunWith; |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 13 | import org.mockito.ArgumentCaptor; |
| 14 | import org.mockito.Mockito; |
| 15 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 16 | import static junit.framework.Assert.assertEquals; |
| 17 | |
Jason Monk | e427cb8 | 2015-07-28 09:18:08 -0400 | [diff] [blame] | 18 | @SmallTest |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 19 | @RunWith(AndroidTestingRunner.class) |
| 20 | @RunWithLooper |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 21 | public class NetworkControllerEthernetTest extends NetworkControllerBaseTest { |
| 22 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 23 | @Test |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 24 | public void testEthernetIcons() { |
| 25 | verifyLastEthernetIcon(false, 0); |
| 26 | |
| 27 | setEthernetState(true, false); // Connected, unvalidated. |
| 28 | verifyLastEthernetIcon(true, EthernetIcons.ETHERNET_ICONS[0][0]); |
| 29 | |
| 30 | setEthernetState(true, true); // Connected, validated. |
| 31 | verifyLastEthernetIcon(true, EthernetIcons.ETHERNET_ICONS[1][0]); |
| 32 | |
| 33 | setEthernetState(true, false); // Connected, unvalidated. |
| 34 | verifyLastEthernetIcon(true, EthernetIcons.ETHERNET_ICONS[0][0]); |
| 35 | |
| 36 | setEthernetState(false, false); // Disconnected. |
| 37 | verifyLastEthernetIcon(false, 0); |
| 38 | } |
| 39 | |
| 40 | protected void setEthernetState(boolean connected, boolean validated) { |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 41 | setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_ETHERNET, validated, connected); |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | protected void verifyLastEthernetIcon(boolean visible, int icon) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 45 | ArgumentCaptor<IconState> iconArg = ArgumentCaptor.forClass(IconState.class); |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 46 | |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 47 | Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setEthernetIndicators( |
| 48 | iconArg.capture()); |
| 49 | IconState iconState = iconArg.getValue(); |
| 50 | assertEquals("Ethernet visible, in status bar", visible, iconState.visible); |
| 51 | assertEquals("Ethernet icon, in status bar", icon, iconState.icon); |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 52 | } |
| 53 | } |