blob: c17cc671e558c3ba4214848fa637d51726a27a84 [file] [log] [blame]
sunnyshao15ec2cf2018-03-29 19:50:20 +08001/*
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
17package com.android.settings.backup;
18
19import static com.google.common.truth.Truth.assertThat;
20
21import android.content.Context;
22import android.support.v7.preference.Preference;
23
24import com.android.settings.core.BasePreferenceController;
25import com.android.settings.testutils.SettingsRobolectricTestRunner;
26
27import org.junit.After;
28import org.junit.Before;
29import org.junit.Test;
30import org.junit.runner.RunWith;
31import org.mockito.MockitoAnnotations;
32import org.robolectric.RuntimeEnvironment;
33import org.robolectric.annotation.Config;
34
35@RunWith(SettingsRobolectricTestRunner.class)
36@Config(shadows = {ShadowPrivacySettingsUtils.class})
37public class BackupInactivePreferenceControllerTest {
38 private Context mContext;
39 private BackupInactivePreferenceController mController;
40 private Preference mPreference;
41
42 @Before
43 public void setUp() {
44 MockitoAnnotations.initMocks(this);
45 mContext = RuntimeEnvironment.application;
46 mController = new BackupInactivePreferenceController(mContext,
47 PrivacySettingsUtils.BACKUP_INACTIVE);
48 }
49
50 @After
51 public void tearDown() {
52 ShadowPrivacySettingsUtils.reset();
53 }
54
55 @Test
56 public void getAvailabilityStatus_isAdmiUser_isnotInvisibleKey_shouldBeAvailable() {
57 ShadowPrivacySettingsUtils.setIsAdminUser(true);
58 ShadowPrivacySettingsUtils.setIsInvisibleKey(false);
59 assertThat(mController.getAvailabilityStatus())
60 .isEqualTo(BasePreferenceController.AVAILABLE);
61 }
62
63 @Test
64 public void getAvailabilityStatus_isnotAdmiUser_shouldBeDisabledForUser() {
65 ShadowPrivacySettingsUtils.setIsAdminUser(false);
66 assertThat(mController.getAvailabilityStatus())
67 .isEqualTo(BasePreferenceController.DISABLED_FOR_USER);
68 }
69
70 @Test
71 public void getAvailabilityStatus_isAdmiUser_isInvisibleKey_shouldBeDisabledUnsupported() {
72 ShadowPrivacySettingsUtils.setIsAdminUser(true);
73 ShadowPrivacySettingsUtils.setIsInvisibleKey(true);
74 assertThat(mController.getAvailabilityStatus())
75 .isEqualTo(BasePreferenceController.DISABLED_UNSUPPORTED);
76 }
77}