• 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 import android.support.v7.preference.Preference;
25 
26 import com.android.settings.R;
27 import com.android.settings.testutils.SettingsRobolectricTestRunner;
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.RuntimeEnvironment;
35 import org.robolectric.annotation.Config;
36 
37 @RunWith(SettingsRobolectricTestRunner.class)
38 public class ScreenPinningPreferenceControllerTest {
39 
40     private Context mContext;
41     private ScreenPinningPreferenceController mController;
42     private Preference mPreference;
43 
44     @Before
setUp()45     public void setUp() {
46         MockitoAnnotations.initMocks(this);
47         mContext = RuntimeEnvironment.application;
48         mController = new ScreenPinningPreferenceController(mContext);
49         mPreference = new Preference(mContext);
50         mPreference.setKey(mController.getPreferenceKey());
51     }
52 
53     @After
tearDown()54     public void tearDown() {
55         final ContentResolver contentResolver = mContext.getContentResolver();
56         Settings.System.putInt(contentResolver, Settings.System.LOCK_TO_APP_ENABLED, 0);
57     }
58 
59     @Test
isAvailable_byDefault_isTrue()60     public void isAvailable_byDefault_isTrue() {
61         assertThat(mController.isAvailable()).isTrue();
62     }
63 
64     @Test
65     @Config(qualifiers = "mcc999")
isAvailable_whenNotVisible_isFalse()66     public void isAvailable_whenNotVisible_isFalse() {
67         assertThat(mController.isAvailable()).isFalse();
68     }
69 
70     @Test
updateState_isOff_shouldDisableOffSummary()71     public void updateState_isOff_shouldDisableOffSummary() {
72         final ContentResolver contentResolver = mContext.getContentResolver();
73         Settings.System.putInt(contentResolver, Settings.System.LOCK_TO_APP_ENABLED, 0);
74 
75         mController.updateState(mPreference);
76 
77         assertThat(mPreference.getSummary())
78                 .isEqualTo(mContext.getString(R.string.switch_off_text));
79     }
80 
81     @Test
updateState_isOn_shouldDisableOnSummary()82     public void updateState_isOn_shouldDisableOnSummary() {
83         final ContentResolver contentResolver = mContext.getContentResolver();
84         Settings.System.putInt(contentResolver, Settings.System.LOCK_TO_APP_ENABLED, 1);
85 
86         mController.updateState(mPreference);
87 
88         assertThat(mPreference.getSummary())
89                 .isEqualTo(mContext.getString(R.string.switch_on_text));
90     }
91 }
92