• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.enterprise;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.Mockito.when;
22 
23 import android.content.Context;
24 
25 import androidx.preference.Preference;
26 
27 import com.android.settings.R;
28 import com.android.settings.testutils.FakeFeatureFactory;
29 
30 import org.junit.Before;
31 import org.junit.Ignore;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Answers;
35 import org.mockito.Mock;
36 import org.mockito.MockitoAnnotations;
37 import org.robolectric.RobolectricTestRunner;
38 
39 @RunWith(RobolectricTestRunner.class)
40 @Ignore
41 public final class AlwaysOnVpnCurrentUserPreferenceControllerTest {
42 
43     private static final String VPN_SET_DEVICE = "VPN set";
44     private static final String VPN_SET_PERSONAL = "VPN set in personal profile";
45     private static final String KEY_ALWAYS_ON_VPN_PRIMARY_USER = "always_on_vpn_primary_user";
46 
47     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
48     private Context mContext;
49     private FakeFeatureFactory mFeatureFactory;
50 
51     private AlwaysOnVpnCurrentUserPreferenceController mController;
52 
53     @Before
setUp()54     public void setUp() {
55         MockitoAnnotations.initMocks(this);
56         mFeatureFactory = FakeFeatureFactory.setupForTest();
57         mController = new AlwaysOnVpnCurrentUserPreferenceController(mContext);
58         when(mContext.getString(R.string.enterprise_privacy_always_on_vpn_device))
59                 .thenReturn(VPN_SET_DEVICE);
60         when(mContext.getString(R.string.enterprise_privacy_always_on_vpn_personal))
61                 .thenReturn(VPN_SET_PERSONAL);
62     }
63 
64     @Test
testUpdateState()65     public void testUpdateState() {
66         final Preference preference = new Preference(mContext, null, 0, 0);
67 
68         when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInCurrentUser())
69                 .thenReturn(true);
70 
71         when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(false);
72         mController.updateState(preference);
73         assertThat(preference.getTitle()).isEqualTo(VPN_SET_DEVICE);
74 
75         when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(true);
76         mController.updateState(preference);
77         assertThat(preference.getTitle()).isEqualTo(VPN_SET_PERSONAL);
78     }
79 
80     @Test
testIsAvailable()81     public void testIsAvailable() {
82         when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInCurrentUser())
83                 .thenReturn(false);
84         assertThat(mController.isAvailable()).isFalse();
85 
86         when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInCurrentUser())
87                 .thenReturn(true);
88         assertThat(mController.isAvailable()).isTrue();
89     }
90 
91     @Test
testHandlePreferenceTreeClick()92     public void testHandlePreferenceTreeClick() {
93         assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0)))
94                 .isFalse();
95     }
96 
97     @Test
testGetPreferenceKey()98     public void testGetPreferenceKey() {
99         assertThat(mController.getPreferenceKey()).isEqualTo(KEY_ALWAYS_ON_VPN_PRIMARY_USER);
100     }
101 }
102