sunnyshao | 15ec2cf | 2018-03-29 19:50:20 +0800 | [diff] [blame] | 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.backup; |
| 18 | |
| 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | |
| 21 | import android.content.Context; |
| 22 | import android.support.v7.preference.Preference; |
| 23 | |
| 24 | import com.android.settings.core.BasePreferenceController; |
| 25 | import com.android.settings.testutils.SettingsRobolectricTestRunner; |
| 26 | |
| 27 | import org.junit.After; |
| 28 | import org.junit.Before; |
| 29 | import org.junit.Test; |
| 30 | import org.junit.runner.RunWith; |
| 31 | import org.mockito.MockitoAnnotations; |
| 32 | import org.robolectric.RuntimeEnvironment; |
| 33 | import org.robolectric.annotation.Config; |
| 34 | |
| 35 | @RunWith(SettingsRobolectricTestRunner.class) |
| 36 | @Config(shadows = {ShadowPrivacySettingsUtils.class}) |
| 37 | public 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 | } |