• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 com.android.internal.logging.nano.MetricsProto.MetricsEvent;
26 import com.android.settings.R;
27 import com.android.settings.testutils.FakeFeatureFactory;
28 import com.android.settings.widget.PreferenceCategoryController;
29 import com.android.settingslib.core.AbstractPreferenceController;
30 import com.android.settingslib.drawer.CategoryKey;
31 
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.Answers;
36 import org.mockito.Mock;
37 import org.mockito.MockitoAnnotations;
38 import org.robolectric.RobolectricTestRunner;
39 import org.robolectric.RuntimeEnvironment;
40 
41 import java.util.List;
42 
43 @RunWith(RobolectricTestRunner.class)
44 public class EnterprisePrivacySettingsTest {
45 
46     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
47     private Context mContext;
48     private FakeFeatureFactory mFeatureFactory;
49     private EnterprisePrivacySettings mSettings;
50 
51     @Before
setUp()52     public void setUp() {
53         MockitoAnnotations.initMocks(this);
54         mFeatureFactory = FakeFeatureFactory.setupForTest();
55         mSettings = new EnterprisePrivacySettings();
56     }
57 
58     @Test
verifyConstants()59     public void verifyConstants() {
60         assertThat(mSettings.getMetricsCategory())
61                 .isEqualTo(MetricsEvent.ENTERPRISE_PRIVACY_SETTINGS);
62         assertThat(mSettings.getLogTag()).isEqualTo("EnterprisePrivacySettings");
63         assertThat(mSettings.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_ENTERPRISE_PRIVACY);
64         assertThat(mSettings.getPreferenceScreenResId())
65                 .isEqualTo(R.xml.enterprise_privacy_settings);
66     }
67 
68     @Test
isPageEnabled_hasDeviceOwner_shouldReturnTrue()69     public void isPageEnabled_hasDeviceOwner_shouldReturnTrue() {
70         when(mFeatureFactory.enterprisePrivacyFeatureProvider.hasDeviceOwner())
71                 .thenReturn(true);
72 
73         assertThat(EnterprisePrivacySettings.isPageEnabled(mContext))
74                 .isTrue();
75     }
76 
77     @Test
isPageEnabled_noDeviceOwner_shouldReturnFalse()78     public void isPageEnabled_noDeviceOwner_shouldReturnFalse() {
79         when(mFeatureFactory.enterprisePrivacyFeatureProvider.hasDeviceOwner())
80                 .thenReturn(false);
81 
82         assertThat(EnterprisePrivacySettings.isPageEnabled(mContext))
83                 .isFalse();
84     }
85 
86     @Test
getPreferenceControllers()87     public void getPreferenceControllers() {
88         final List<AbstractPreferenceController> controllers =
89             mSettings.createPreferenceControllers(RuntimeEnvironment.application);
90         verifyPreferenceControllers(controllers);
91     }
92 
93     @Test
getSearchIndexProviderPreferenceControllers()94     public void getSearchIndexProviderPreferenceControllers() {
95         final List<AbstractPreferenceController> controllers =
96             EnterprisePrivacySettings.SEARCH_INDEX_DATA_PROVIDER
97                 .getPreferenceControllers(RuntimeEnvironment.application);
98         verifyPreferenceControllers(controllers);
99     }
100 
verifyPreferenceControllers(List<AbstractPreferenceController> controllers)101     private void verifyPreferenceControllers(List<AbstractPreferenceController> controllers) {
102         assertThat(controllers).isNotNull();
103         assertThat(controllers.size()).isEqualTo(17);
104         int position = 0;
105         assertThat(controllers.get(position++)).isInstanceOf(NetworkLogsPreferenceController.class);
106         assertThat(controllers.get(position++)).isInstanceOf(BugReportsPreferenceController.class);
107         assertThat(controllers.get(position++)).isInstanceOf(
108                 SecurityLogsPreferenceController.class);
109         assertThat(controllers.get(position++)).isInstanceOf(
110                 EnterpriseInstalledPackagesPreferenceController.class);
111         assertThat(controllers.get(position++)).isInstanceOf(
112                 AdminGrantedLocationPermissionsPreferenceController.class);
113         assertThat(controllers.get(position++)).isInstanceOf(
114                 AdminGrantedMicrophonePermissionPreferenceController.class);
115         assertThat(controllers.get(position++)).isInstanceOf(
116                 AdminGrantedCameraPermissionPreferenceController.class);
117         assertThat(controllers.get(position++)).isInstanceOf(
118                 EnterpriseSetDefaultAppsPreferenceController.class);
119         assertThat(controllers.get(position++)).isInstanceOf(
120                 AlwaysOnVpnCurrentUserPreferenceController.class);
121         assertThat(controllers.get(position++)).isInstanceOf(
122                 AlwaysOnVpnManagedProfilePreferenceController.class);
123         assertThat(controllers.get(position++)).isInstanceOf(ImePreferenceController.class);
124         assertThat(controllers.get(position++)).isInstanceOf(
125                 GlobalHttpProxyPreferenceController.class);
126         assertThat(controllers.get(position++)).isInstanceOf(
127                 CaCertsCurrentUserPreferenceController.class);
128         assertThat(controllers.get(position++)).isInstanceOf(
129                 CaCertsManagedProfilePreferenceController.class);
130         assertThat(controllers.get(position++)).isInstanceOf(
131                 PreferenceCategoryController.class);
132         assertThat(controllers.get(position++)).isInstanceOf(
133                 FailedPasswordWipeCurrentUserPreferenceController.class);
134         assertThat(controllers.get(position)).isInstanceOf(
135                 FailedPasswordWipeManagedProfilePreferenceController.class);
136     }
137 }
138