Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.qs; |
| 16 | |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 17 | import static junit.framework.Assert.assertEquals; |
| 18 | |
| 19 | import static org.mockito.Mockito.mock; |
| 20 | import static org.mockito.Mockito.when; |
| 21 | |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 22 | import android.content.Context; |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 23 | import android.os.Handler; |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 24 | import android.os.Looper; |
| 25 | import android.support.test.runner.AndroidJUnit4; |
| 26 | import android.test.suitebuilder.annotation.SmallTest; |
| 27 | import android.text.SpannableStringBuilder; |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 28 | import android.view.View; |
| 29 | import android.view.ViewGroup; |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 30 | import android.widget.TextView; |
| 31 | |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 32 | import com.android.systemui.Dependency; |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 33 | import com.android.systemui.R; |
| 34 | import com.android.systemui.SysuiTestCase; |
| 35 | import com.android.systemui.statusbar.policy.SecurityController; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 36 | import android.testing.LayoutInflaterBuilder; |
| 37 | import android.testing.TestableImageView; |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 38 | |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 39 | import org.junit.Before; |
| 40 | import org.junit.Test; |
| 41 | import org.junit.runner.RunWith; |
| 42 | |
phweiss | 4f70f10 | 2017-04-12 19:32:55 +0200 | [diff] [blame] | 43 | /* |
| 44 | * Compile and run the whole SystemUI test suite: |
| 45 | runtest --path frameworks/base/packages/SystemUI/tests |
| 46 | * |
| 47 | * Compile and run just this class: |
| 48 | runtest --path \ |
| 49 | frameworks/base/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java |
| 50 | */ |
| 51 | |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 52 | @SmallTest |
| 53 | @RunWith(AndroidJUnit4.class) |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 54 | public class QSSecurityFooterTest extends SysuiTestCase { |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 55 | |
| 56 | private final String MANAGING_ORGANIZATION = "organization"; |
| 57 | private final String DEVICE_OWNER_PACKAGE = "TestDPC"; |
| 58 | private final String VPN_PACKAGE = "TestVPN"; |
phweiss | 4f70f10 | 2017-04-12 19:32:55 +0200 | [diff] [blame] | 59 | private final String VPN_PACKAGE_2 = "TestVPN 2"; |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 60 | |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 61 | private ViewGroup mRootView; |
| 62 | private TextView mFooterText; |
| 63 | private TestableImageView mFooterIcon; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 64 | private QSSecurityFooter mFooter; |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 65 | private SecurityController mSecurityController = mock(SecurityController.class); |
| 66 | |
| 67 | @Before |
| 68 | public void setUp() { |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 69 | mDependency.injectTestDependency(SecurityController.class, mSecurityController); |
| 70 | mDependency.injectTestDependency(Dependency.BG_LOOPER, Looper.getMainLooper()); |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 71 | mContext.addMockSystemService(Context.LAYOUT_INFLATER_SERVICE, |
| 72 | new LayoutInflaterBuilder(mContext) |
| 73 | .replace("ImageView", TestableImageView.class) |
| 74 | .build()); |
| 75 | Handler h = new Handler(Looper.getMainLooper()); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 76 | h.post(() -> mFooter = new QSSecurityFooter(null, mContext)); |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 77 | waitForIdleSync(h); |
| 78 | mRootView = (ViewGroup) mFooter.getView(); |
| 79 | mFooterText = (TextView) mRootView.findViewById(R.id.footer_text); |
| 80 | mFooterIcon = (TestableImageView) mRootView.findViewById(R.id.footer_icon); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 81 | mFooter.setHostEnvironment(null); |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | @Test |
| 85 | public void testUnmanaged() { |
| 86 | when(mSecurityController.isDeviceManaged()).thenReturn(false); |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 87 | mFooter.refreshState(); |
| 88 | |
| 89 | waitForIdleSync(mFooter.mHandler); |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 90 | assertEquals(View.GONE, mRootView.getVisibility()); |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | @Test |
| 94 | public void testManagedNoOwnerName() { |
| 95 | when(mSecurityController.isDeviceManaged()).thenReturn(true); |
| 96 | when(mSecurityController.getDeviceOwnerOrganizationName()).thenReturn(null); |
| 97 | mFooter.refreshState(); |
| 98 | |
| 99 | waitForIdleSync(mFooter.mHandler); |
phweiss | 4f70f10 | 2017-04-12 19:32:55 +0200 | [diff] [blame] | 100 | assertEquals(mContext.getString(R.string.quick_settings_disclosure_management), |
| 101 | mFooterText.getText()); |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 102 | assertEquals(View.VISIBLE, mRootView.getVisibility()); |
phweiss | 4f70f10 | 2017-04-12 19:32:55 +0200 | [diff] [blame] | 103 | assertEquals(View.VISIBLE, mFooterIcon.getVisibility()); |
| 104 | // -1 == never set. |
| 105 | assertEquals(-1, mFooterIcon.getLastImageResource()); |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Test |
| 109 | public void testManagedOwnerName() { |
| 110 | when(mSecurityController.isDeviceManaged()).thenReturn(true); |
| 111 | when(mSecurityController.getDeviceOwnerOrganizationName()) |
| 112 | .thenReturn(MANAGING_ORGANIZATION); |
| 113 | mFooter.refreshState(); |
| 114 | |
| 115 | waitForIdleSync(mFooter.mHandler); |
phweiss | 4f70f10 | 2017-04-12 19:32:55 +0200 | [diff] [blame] | 116 | assertEquals(mContext.getString(R.string.quick_settings_disclosure_named_management, |
| 117 | MANAGING_ORGANIZATION), |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 118 | mFooterText.getText()); |
| 119 | assertEquals(View.VISIBLE, mRootView.getVisibility()); |
phweiss | 4f70f10 | 2017-04-12 19:32:55 +0200 | [diff] [blame] | 120 | assertEquals(View.VISIBLE, mFooterIcon.getVisibility()); |
| 121 | // -1 == never set. |
| 122 | assertEquals(-1, mFooterIcon.getLastImageResource()); |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | @Test |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 126 | public void testNetworkLoggingEnabled() { |
| 127 | when(mSecurityController.isDeviceManaged()).thenReturn(true); |
| 128 | when(mSecurityController.isNetworkLoggingEnabled()).thenReturn(true); |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 129 | mFooter.refreshState(); |
| 130 | |
| 131 | waitForIdleSync(mFooter.mHandler); |
phweiss | 4f70f10 | 2017-04-12 19:32:55 +0200 | [diff] [blame] | 132 | assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_monitoring), |
| 133 | mFooterText.getText()); |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 134 | assertEquals(View.VISIBLE, mFooterIcon.getVisibility()); |
| 135 | // -1 == never set. |
| 136 | assertEquals(-1, mFooterIcon.getLastImageResource()); |
phweiss | 4f70f10 | 2017-04-12 19:32:55 +0200 | [diff] [blame] | 137 | |
| 138 | // Same situation, but with organization name set |
| 139 | when(mSecurityController.getDeviceOwnerOrganizationName()) |
| 140 | .thenReturn(MANAGING_ORGANIZATION); |
| 141 | mFooter.refreshState(); |
| 142 | |
| 143 | waitForIdleSync(mFooter.mHandler); |
| 144 | assertEquals(mContext.getString( |
| 145 | R.string.quick_settings_disclosure_named_management_monitoring, |
| 146 | MANAGING_ORGANIZATION), |
| 147 | mFooterText.getText()); |
| 148 | } |
| 149 | |
| 150 | @Test |
| 151 | public void testManagedCACertsInstalled() { |
| 152 | when(mSecurityController.isDeviceManaged()).thenReturn(true); |
| 153 | when(mSecurityController.hasCACertInCurrentUser()).thenReturn(true); |
| 154 | mFooter.refreshState(); |
| 155 | |
| 156 | waitForIdleSync(mFooter.mHandler); |
| 157 | assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_monitoring), |
| 158 | mFooterText.getText()); |
| 159 | } |
| 160 | |
| 161 | @Test |
| 162 | public void testManagedOneVpnEnabled() { |
| 163 | when(mSecurityController.isDeviceManaged()).thenReturn(true); |
| 164 | when(mSecurityController.isVpnEnabled()).thenReturn(true); |
| 165 | when(mSecurityController.getPrimaryVpnName()).thenReturn(VPN_PACKAGE); |
| 166 | mFooter.refreshState(); |
| 167 | |
| 168 | waitForIdleSync(mFooter.mHandler); |
| 169 | assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_named_vpn, |
| 170 | VPN_PACKAGE), |
| 171 | mFooterText.getText()); |
| 172 | assertEquals(View.VISIBLE, mFooterIcon.getVisibility()); |
| 173 | assertEquals(R.drawable.ic_qs_vpn, mFooterIcon.getLastImageResource()); |
| 174 | |
| 175 | // Same situation, but with organization name set |
| 176 | when(mSecurityController.getDeviceOwnerOrganizationName()) |
| 177 | .thenReturn(MANAGING_ORGANIZATION); |
| 178 | mFooter.refreshState(); |
| 179 | |
| 180 | waitForIdleSync(mFooter.mHandler); |
| 181 | assertEquals(mContext.getString( |
| 182 | R.string.quick_settings_disclosure_named_management_named_vpn, |
| 183 | MANAGING_ORGANIZATION, VPN_PACKAGE), |
| 184 | mFooterText.getText()); |
| 185 | } |
| 186 | |
| 187 | @Test |
| 188 | public void testManagedTwoVpnsEnabled() { |
| 189 | when(mSecurityController.isDeviceManaged()).thenReturn(true); |
| 190 | when(mSecurityController.isVpnEnabled()).thenReturn(true); |
| 191 | when(mSecurityController.getPrimaryVpnName()).thenReturn(VPN_PACKAGE); |
| 192 | when(mSecurityController.getWorkProfileVpnName()).thenReturn(VPN_PACKAGE_2); |
| 193 | mFooter.refreshState(); |
| 194 | |
| 195 | waitForIdleSync(mFooter.mHandler); |
| 196 | assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_vpns), |
| 197 | mFooterText.getText()); |
| 198 | assertEquals(View.VISIBLE, mFooterIcon.getVisibility()); |
| 199 | assertEquals(R.drawable.ic_qs_vpn, mFooterIcon.getLastImageResource()); |
| 200 | |
| 201 | // Same situation, but with organization name set |
| 202 | when(mSecurityController.getDeviceOwnerOrganizationName()) |
| 203 | .thenReturn(MANAGING_ORGANIZATION); |
| 204 | mFooter.refreshState(); |
| 205 | |
| 206 | waitForIdleSync(mFooter.mHandler); |
| 207 | assertEquals(mContext.getString(R.string.quick_settings_disclosure_named_management_vpns, |
| 208 | MANAGING_ORGANIZATION), |
| 209 | mFooterText.getText()); |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | @Test |
| 213 | public void testNetworkLoggingAndVpnEnabled() { |
| 214 | when(mSecurityController.isDeviceManaged()).thenReturn(true); |
| 215 | when(mSecurityController.isNetworkLoggingEnabled()).thenReturn(true); |
| 216 | when(mSecurityController.isVpnEnabled()).thenReturn(true); |
phweiss | 4f70f10 | 2017-04-12 19:32:55 +0200 | [diff] [blame] | 217 | when(mSecurityController.getPrimaryVpnName()).thenReturn("VPN Test App"); |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 218 | mFooter.refreshState(); |
| 219 | |
| 220 | waitForIdleSync(mFooter.mHandler); |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 221 | assertEquals(View.VISIBLE, mFooterIcon.getVisibility()); |
phweiss | 4f70f10 | 2017-04-12 19:32:55 +0200 | [diff] [blame] | 222 | assertEquals(R.drawable.ic_qs_vpn, mFooterIcon.getLastImageResource()); |
| 223 | assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_monitoring), |
| 224 | mFooterText.getText()); |
| 225 | } |
| 226 | |
| 227 | @Test |
| 228 | public void testWorkProfileCACertsInstalled() { |
| 229 | when(mSecurityController.isDeviceManaged()).thenReturn(false); |
| 230 | when(mSecurityController.hasCACertInWorkProfile()).thenReturn(true); |
| 231 | mFooter.refreshState(); |
| 232 | |
| 233 | waitForIdleSync(mFooter.mHandler); |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 234 | // -1 == never set. |
| 235 | assertEquals(-1, mFooterIcon.getLastImageResource()); |
phweiss | 4f70f10 | 2017-04-12 19:32:55 +0200 | [diff] [blame] | 236 | assertEquals(mContext.getString( |
| 237 | R.string.quick_settings_disclosure_managed_profile_monitoring), |
| 238 | mFooterText.getText()); |
| 239 | |
| 240 | // Same situation, but with organization name set |
| 241 | when(mSecurityController.getWorkProfileOrganizationName()) |
| 242 | .thenReturn(MANAGING_ORGANIZATION); |
| 243 | mFooter.refreshState(); |
| 244 | |
| 245 | waitForIdleSync(mFooter.mHandler); |
| 246 | assertEquals(mContext.getString( |
| 247 | R.string.quick_settings_disclosure_named_managed_profile_monitoring, |
| 248 | MANAGING_ORGANIZATION), |
| 249 | mFooterText.getText()); |
| 250 | } |
| 251 | |
| 252 | @Test |
| 253 | public void testCACertsInstalled() { |
| 254 | when(mSecurityController.isDeviceManaged()).thenReturn(false); |
| 255 | when(mSecurityController.hasCACertInCurrentUser()).thenReturn(true); |
| 256 | mFooter.refreshState(); |
| 257 | |
| 258 | waitForIdleSync(mFooter.mHandler); |
| 259 | // -1 == never set. |
| 260 | assertEquals(-1, mFooterIcon.getLastImageResource()); |
| 261 | assertEquals(mContext.getString(R.string.quick_settings_disclosure_monitoring), |
| 262 | mFooterText.getText()); |
| 263 | } |
| 264 | |
| 265 | @Test |
| 266 | public void testTwoVpnsEnabled() { |
| 267 | when(mSecurityController.isVpnEnabled()).thenReturn(true); |
| 268 | when(mSecurityController.getPrimaryVpnName()).thenReturn(VPN_PACKAGE); |
| 269 | when(mSecurityController.getWorkProfileVpnName()).thenReturn(VPN_PACKAGE_2); |
| 270 | mFooter.refreshState(); |
| 271 | |
| 272 | waitForIdleSync(mFooter.mHandler); |
| 273 | assertEquals(R.drawable.ic_qs_vpn, mFooterIcon.getLastImageResource()); |
| 274 | assertEquals(mContext.getString(R.string.quick_settings_disclosure_vpns), |
| 275 | mFooterText.getText()); |
| 276 | } |
| 277 | |
| 278 | @Test |
| 279 | public void testWorkProfileVpnEnabled() { |
| 280 | when(mSecurityController.isVpnEnabled()).thenReturn(true); |
| 281 | when(mSecurityController.getWorkProfileVpnName()).thenReturn(VPN_PACKAGE_2); |
| 282 | mFooter.refreshState(); |
| 283 | |
| 284 | waitForIdleSync(mFooter.mHandler); |
| 285 | assertEquals(R.drawable.ic_qs_vpn, mFooterIcon.getLastImageResource()); |
| 286 | assertEquals(mContext.getString( |
| 287 | R.string.quick_settings_disclosure_managed_profile_named_vpn, |
| 288 | VPN_PACKAGE_2), |
| 289 | mFooterText.getText()); |
| 290 | } |
| 291 | |
| 292 | @Test |
| 293 | public void testVpnEnabled() { |
| 294 | when(mSecurityController.isVpnEnabled()).thenReturn(true); |
| 295 | when(mSecurityController.getPrimaryVpnName()).thenReturn(VPN_PACKAGE); |
| 296 | mFooter.refreshState(); |
| 297 | |
| 298 | waitForIdleSync(mFooter.mHandler); |
| 299 | assertEquals(R.drawable.ic_qs_vpn, mFooterIcon.getLastImageResource()); |
| 300 | assertEquals(mContext.getString(R.string.quick_settings_disclosure_named_vpn, |
| 301 | VPN_PACKAGE), |
| 302 | mFooterText.getText()); |
| 303 | |
| 304 | when(mSecurityController.hasWorkProfile()).thenReturn(true); |
| 305 | mFooter.refreshState(); |
| 306 | |
| 307 | waitForIdleSync(mFooter.mHandler); |
| 308 | assertEquals(mContext.getString( |
| 309 | R.string.quick_settings_disclosure_personal_profile_named_vpn, |
| 310 | VPN_PACKAGE), |
| 311 | mFooterText.getText()); |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | @Test |
phweiss | 48e353c | 2017-04-19 20:14:51 +0200 | [diff] [blame] | 315 | public void testGetManagementMessage() { |
| 316 | assertEquals(null, mFooter.getManagementMessage(false, MANAGING_ORGANIZATION)); |
| 317 | assertEquals(mContext.getString(R.string.monitoring_description_named_management, |
| 318 | MANAGING_ORGANIZATION), |
| 319 | mFooter.getManagementMessage(true, MANAGING_ORGANIZATION)); |
| 320 | assertEquals(mContext.getString(R.string.monitoring_description_management), |
| 321 | mFooter.getManagementMessage(true, null)); |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | @Test |
phweiss | 48e353c | 2017-04-19 20:14:51 +0200 | [diff] [blame] | 325 | public void testGetCaCertsMessage() { |
| 326 | assertEquals(null, mFooter.getCaCertsMessage(true, false, false)); |
| 327 | assertEquals(null, mFooter.getCaCertsMessage(false, false, false)); |
| 328 | assertEquals(mContext.getString(R.string.monitoring_description_management_ca_certificate), |
| 329 | mFooter.getCaCertsMessage(true, true, true)); |
| 330 | assertEquals(mContext.getString(R.string.monitoring_description_management_ca_certificate), |
| 331 | mFooter.getCaCertsMessage(true, false, true)); |
| 332 | assertEquals(mContext.getString( |
| 333 | R.string.monitoring_description_managed_profile_ca_certificate), |
| 334 | mFooter.getCaCertsMessage(false, false, true)); |
| 335 | assertEquals(mContext.getString( |
| 336 | R.string.monitoring_description_ca_certificate), |
| 337 | mFooter.getCaCertsMessage(false, true, false)); |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | @Test |
phweiss | 48e353c | 2017-04-19 20:14:51 +0200 | [diff] [blame] | 341 | public void testGetNetworkLoggingMessage() { |
| 342 | assertEquals(null, mFooter.getNetworkLoggingMessage(false)); |
| 343 | assertEquals(mContext.getString(R.string.monitoring_description_management_network_logging), |
| 344 | mFooter.getNetworkLoggingMessage(true)); |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | @Test |
phweiss | 48e353c | 2017-04-19 20:14:51 +0200 | [diff] [blame] | 348 | public void testGetVpnMessage() { |
| 349 | assertEquals(null, mFooter.getVpnMessage(true, true, null, null)); |
| 350 | assertEquals(addLink(mContext.getString(R.string.monitoring_description_two_named_vpns, |
| 351 | VPN_PACKAGE, VPN_PACKAGE_2)), |
| 352 | mFooter.getVpnMessage(true, true, VPN_PACKAGE, VPN_PACKAGE_2)); |
| 353 | assertEquals(addLink(mContext.getString(R.string.monitoring_description_two_named_vpns, |
| 354 | VPN_PACKAGE, VPN_PACKAGE_2)), |
| 355 | mFooter.getVpnMessage(false, true, VPN_PACKAGE, VPN_PACKAGE_2)); |
| 356 | assertEquals(addLink(mContext.getString(R.string.monitoring_description_named_vpn, |
| 357 | VPN_PACKAGE)), |
| 358 | mFooter.getVpnMessage(true, false, VPN_PACKAGE, null)); |
| 359 | assertEquals(addLink(mContext.getString(R.string.monitoring_description_named_vpn, |
| 360 | VPN_PACKAGE)), |
| 361 | mFooter.getVpnMessage(false, false, VPN_PACKAGE, null)); |
| 362 | assertEquals(addLink(mContext.getString(R.string.monitoring_description_named_vpn, |
| 363 | VPN_PACKAGE_2)), |
| 364 | mFooter.getVpnMessage(true, true, null, VPN_PACKAGE_2)); |
| 365 | assertEquals(addLink(mContext.getString( |
| 366 | R.string.monitoring_description_managed_profile_named_vpn, |
| 367 | VPN_PACKAGE_2)), |
| 368 | mFooter.getVpnMessage(false, true, null, VPN_PACKAGE_2)); |
| 369 | assertEquals(addLink(mContext.getString( |
| 370 | R.string.monitoring_description_personal_profile_named_vpn, |
| 371 | VPN_PACKAGE)), |
| 372 | mFooter.getVpnMessage(false, true, VPN_PACKAGE, null)); |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 373 | } |
| 374 | |
phweiss | 48e353c | 2017-04-19 20:14:51 +0200 | [diff] [blame] | 375 | private CharSequence addLink(CharSequence description) { |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 376 | final SpannableStringBuilder message = new SpannableStringBuilder(); |
phweiss | 48e353c | 2017-04-19 20:14:51 +0200 | [diff] [blame] | 377 | message.append(description); |
| 378 | message.append(mContext.getString(R.string.monitoring_description_vpn_settings_separator)); |
| 379 | message.append(mContext.getString(R.string.monitoring_description_vpn_settings), |
| 380 | mFooter.new VpnSpan(), 0); |
Bartosz Fabianowski | 46bea2e | 2016-12-06 01:20:29 +0100 | [diff] [blame] | 381 | return message; |
| 382 | } |
| 383 | } |