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