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.accessibility;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.content.Context;
22 import android.provider.Settings;
23 
24 import androidx.test.core.app.ApplicationProvider;
25 
26 import com.android.settings.R;
27 import com.android.settings.core.BasePreferenceController;
28 
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.robolectric.RobolectricTestRunner;
33 
34 /** Tests for {@link AccessibilityTimeoutPreferenceController}. */
35 @RunWith(RobolectricTestRunner.class)
36 public class AccessibilityTimeoutPreferenceControllerTest {
37 
38     private Context mContext = ApplicationProvider.getApplicationContext();
39     private AccessibilityTimeoutPreferenceController mController;
40 
41     @Before
setUp()42     public void setUp() {
43         mController = new AccessibilityTimeoutPreferenceController(mContext, "control_timeout");
44     }
45 
46     @Test
getAvailabilityStatus_shouldReturnAvailable()47     public void getAvailabilityStatus_shouldReturnAvailable() {
48         assertThat(mController.getAvailabilityStatus()).isEqualTo(
49                 BasePreferenceController.AVAILABLE);
50     }
51 
52     @Test
getSummary_byDefault_shouldReturnDefaultSummary()53     public void getSummary_byDefault_shouldReturnDefaultSummary() {
54         final String[] timeoutSummaries = mContext.getResources().getStringArray(
55                 R.array.accessibility_timeout_summaries);
56         Settings.Secure.putString(mContext.getContentResolver(),
57                 Settings.Secure.ACCESSIBILITY_INTERACTIVE_UI_TIMEOUT_MS, "0");
58 
59         assertThat(mController.getSummary().toString()).isEqualTo(timeoutSummaries[0]);
60     }
61 
62     @Test
getSummary_invalidTimeout_shouldReturnDefaultSummary()63     public void getSummary_invalidTimeout_shouldReturnDefaultSummary() {
64         final String[] timeoutSummaries = mContext.getResources().getStringArray(
65                 R.array.accessibility_timeout_summaries);
66         Settings.Secure.putString(mContext.getContentResolver(),
67                 Settings.Secure.ACCESSIBILITY_INTERACTIVE_UI_TIMEOUT_MS, "invalid_timeout");
68 
69         assertThat(mController.getSummary().toString()).isEqualTo(timeoutSummaries[0]);
70     }
71 
72     @Test
getSummary_validTimeout_shouldReturnValidSummary()73     public void getSummary_validTimeout_shouldReturnValidSummary() {
74         final String[] timeoutSummaries = mContext.getResources().getStringArray(
75                 R.array.accessibility_timeout_summaries);
76         Settings.Secure.putString(mContext.getContentResolver(),
77                 Settings.Secure.ACCESSIBILITY_INTERACTIVE_UI_TIMEOUT_MS, "60000");
78 
79         assertThat(mController.getSummary().toString()).isEqualTo(timeoutSummaries[3]);
80     }
81 }
82