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 23 import com.android.settings.core.BasePreferenceController; 24 25 import org.junit.After; 26 import org.junit.Before; 27 import org.junit.Test; 28 import org.junit.runner.RunWith; 29 import org.mockito.MockitoAnnotations; 30 import org.robolectric.RobolectricTestRunner; 31 import org.robolectric.RuntimeEnvironment; 32 import org.robolectric.annotation.Config; 33 34 import static com.android.settings.backup.UserBackupSettingsActivityTest.ShadowBackupSettingsHelper; 35 36 @RunWith(RobolectricTestRunner.class) 37 @Config(shadows = {ShadowPrivacySettingsUtils.class, ShadowBackupSettingsHelper.class}) 38 public class BackupInactivePreferenceControllerTest { 39 private Context mContext; 40 private BackupInactivePreferenceController mController; 41 42 @Before setUp()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 tearDown()51 public void tearDown() { 52 ShadowPrivacySettingsUtils.reset(); 53 ShadowBackupSettingsHelper.reset(); 54 } 55 56 @Test getAvailabilityStatus_isnotInvisibleKey_backupActive_shouldBeAvailable()57 public void getAvailabilityStatus_isnotInvisibleKey_backupActive_shouldBeAvailable() { 58 ShadowPrivacySettingsUtils.setIsInvisibleKey(false); 59 ShadowBackupSettingsHelper.isBackupServiceActive = true; 60 61 assertThat(mController.getAvailabilityStatus()) 62 .isEqualTo(BasePreferenceController.AVAILABLE); 63 } 64 65 @Test getAvailabilityStatus_isnotInvisibleKey_backupNotActive_shouldBeUnsearchable()66 public void getAvailabilityStatus_isnotInvisibleKey_backupNotActive_shouldBeUnsearchable() { 67 ShadowPrivacySettingsUtils.setIsInvisibleKey(false); 68 ShadowBackupSettingsHelper.isBackupServiceActive = false; 69 70 assertThat(mController.getAvailabilityStatus()) 71 .isEqualTo(BasePreferenceController.AVAILABLE_UNSEARCHABLE); 72 } 73 74 @Test getAvailabilityStatus_isInvisibleKey_shouldBeDisabledUnsupported()75 public void getAvailabilityStatus_isInvisibleKey_shouldBeDisabledUnsupported() { 76 ShadowPrivacySettingsUtils.setIsInvisibleKey(true); 77 ShadowBackupSettingsHelper.isBackupServiceActive = true; 78 79 assertThat(mController.getAvailabilityStatus()) 80 .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE); 81 } 82 } 83