• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.privacy;
18 
19 import static com.android.settings.core.BasePreferenceController.AVAILABLE;
20 import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
21 
22 import static com.google.common.truth.Truth.assertThat;
23 import android.accessibilityservice.AccessibilityServiceInfo;
24 import android.content.Context;
25 import android.provider.DeviceConfig;
26 import android.view.accessibility.AccessibilityManager;
27 
28 import com.android.settings.Utils;
29 import com.android.settings.testutils.shadow.ShadowDeviceConfig;
30 
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.MockitoAnnotations;
36 import org.robolectric.RobolectricTestRunner;
37 import org.robolectric.RuntimeEnvironment;
38 import org.robolectric.annotation.Config;
39 import org.robolectric.shadow.api.Shadow;
40 import org.robolectric.shadows.ShadowAccessibilityManager;
41 
42 import java.util.ArrayList;
43 import java.util.Arrays;
44 
45 @RunWith(RobolectricTestRunner.class)
46 @Config(shadows = {ShadowDeviceConfig.class})
47 public class AccessibilityUsagePreferenceControllerTest {
48 
49     private Context mContext;
50     private ShadowAccessibilityManager mAccessibilityManager;
51 
52     @Before
setUp()53     public void setUp() {
54         MockitoAnnotations.initMocks(this);
55         mContext = RuntimeEnvironment.application;
56         mAccessibilityManager = Shadow.extract(
57                 RuntimeEnvironment.application.getSystemService(AccessibilityManager.class));
58     }
59 
60     @After
tearDown()61     public void tearDown() {
62         ShadowAccessibilityManager.reset();
63         ShadowDeviceConfig.reset();
64     }
65 
66     @Test
getAvailabilityStatus_noEnabledServices_shouldReturnUnsupported()67     public void getAvailabilityStatus_noEnabledServices_shouldReturnUnsupported() {
68         mAccessibilityManager.setEnabledAccessibilityServiceList(new ArrayList<>());
69         AccessibilityUsagePreferenceController controller =
70                 new AccessibilityUsagePreferenceController(mContext, "test_key");
71 
72         assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
73     }
74 
75     @Test
getAvailabilityStatus_enabledServices_shouldReturnAvailable()76     public void getAvailabilityStatus_enabledServices_shouldReturnAvailable() {
77         mAccessibilityManager.setEnabledAccessibilityServiceList(
78                 new ArrayList<>(Arrays.asList(new AccessibilityServiceInfo())));
79         AccessibilityUsagePreferenceController controller =
80                 new AccessibilityUsagePreferenceController(mContext, "test_key");
81 
82         assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE);
83     }
84 }
85