1 /* 2 * Copyright (C) 2022 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.development; 18 19 import static junit.framework.Assert.assertFalse; 20 import static junit.framework.Assert.assertTrue; 21 22 import android.content.Context; 23 import android.os.SystemProperties; 24 25 import androidx.fragment.app.Fragment; 26 import androidx.preference.Preference; 27 import androidx.test.core.app.ApplicationProvider; 28 29 import org.junit.Before; 30 import org.junit.Ignore; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 import org.mockito.Mock; 34 import org.mockito.MockitoAnnotations; 35 import org.robolectric.RobolectricTestRunner; 36 import org.robolectric.annotation.Config; 37 import org.robolectric.shadows.ShadowSystemProperties; 38 39 @RunWith(RobolectricTestRunner.class) 40 @Config( 41 shadows = { 42 ShadowSystemProperties.class, 43 }) 44 public class RebootWithMtePreferenceControllerTest { 45 private Context mContext; 46 private RebootWithMtePreferenceController mController; 47 @Mock private Fragment mFragment; 48 49 @Before setup()50 public void setup() throws Exception { 51 MockitoAnnotations.initMocks(this); 52 53 mContext = ApplicationProvider.getApplicationContext(); 54 mController = new RebootWithMtePreferenceController(mContext); 55 mController.setFragment(mFragment); 56 } 57 58 @Test onAvailable_falseByDefault()59 public void onAvailable_falseByDefault() { 60 assertFalse(mController.isAvailable()); 61 } 62 63 @Ignore 64 @Test onAvailable_sysPropEnabled()65 public void onAvailable_sysPropEnabled() { 66 SystemProperties.set("ro.arm64.memtag.bootctl_supported", "1"); 67 assertTrue(mController.isAvailable()); 68 } 69 70 @Test updateState_enabledByDefault()71 public void updateState_enabledByDefault() { 72 Preference preference = new Preference(mContext); 73 mController.updateState(preference); 74 assertTrue(preference.isEnabled()); 75 } 76 77 @Test updateState_disabledIfAlreadyOn()78 public void updateState_disabledIfAlreadyOn() { 79 SystemProperties.set("arm64.memtag.bootctl", "memtag"); 80 Preference preference = new Preference(mContext); 81 mController.updateState(preference); 82 assertFalse(preference.isEnabled()); 83 } 84 } 85