• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.security;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.content.ContentResolver;
22 import android.content.Context;
23 import android.provider.Settings;
24 
25 import androidx.preference.Preference;
26 
27 import com.android.settings.R;
28 
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.MockitoAnnotations;
34 import org.robolectric.RobolectricTestRunner;
35 import org.robolectric.RuntimeEnvironment;
36 import org.robolectric.annotation.Config;
37 
38 @RunWith(RobolectricTestRunner.class)
39 public class ScreenPinningPreferenceControllerTest {
40 
41     private Context mContext;
42     private ScreenPinningPreferenceController mController;
43     private Preference mPreference;
44 
45     @Before
setUp()46     public void setUp() {
47         MockitoAnnotations.initMocks(this);
48         mContext = RuntimeEnvironment.application;
49         mController = new ScreenPinningPreferenceController(mContext);
50         mPreference = new Preference(mContext);
51         mPreference.setKey(mController.getPreferenceKey());
52     }
53 
54     @After
tearDown()55     public void tearDown() {
56         final ContentResolver contentResolver = mContext.getContentResolver();
57         Settings.System.putInt(contentResolver, Settings.System.LOCK_TO_APP_ENABLED, 0);
58     }
59 
60     @Test
isAvailable_byDefault_isTrue()61     public void isAvailable_byDefault_isTrue() {
62         assertThat(mController.isAvailable()).isTrue();
63     }
64 
65     @Test
66     @Config(qualifiers = "mcc999")
isAvailable_whenNotVisible_isFalse()67     public void isAvailable_whenNotVisible_isFalse() {
68         assertThat(mController.isAvailable()).isFalse();
69     }
70 
71     @Test
updateState_isOff_shouldDisableOffSummary()72     public void updateState_isOff_shouldDisableOffSummary() {
73         final ContentResolver contentResolver = mContext.getContentResolver();
74         Settings.System.putInt(contentResolver, Settings.System.LOCK_TO_APP_ENABLED, 0);
75 
76         mController.updateState(mPreference);
77 
78         assertThat(mPreference.getSummary())
79                 .isEqualTo(mContext.getString(R.string.switch_off_text));
80     }
81 
82     @Test
updateState_isOn_shouldDisableOnSummary()83     public void updateState_isOn_shouldDisableOnSummary() {
84         final ContentResolver contentResolver = mContext.getContentResolver();
85         Settings.System.putInt(contentResolver, Settings.System.LOCK_TO_APP_ENABLED, 1);
86 
87         mController.updateState(mPreference);
88 
89         assertThat(mPreference.getSummary())
90                 .isEqualTo(mContext.getString(R.string.switch_on_text));
91     }
92 }
93