1 /* 2 * Copyright (C) 2017 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.display; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.Mockito.doReturn; 22 import static org.mockito.Mockito.spy; 23 24 import android.content.ContentResolver; 25 import android.os.UserHandle; 26 import android.provider.Settings; 27 28 import com.android.internal.logging.nano.MetricsProto; 29 import com.android.settings.testutils.shadow.ShadowSecureSettings; 30 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 import org.mockito.MockitoAnnotations; 35 import org.robolectric.RobolectricTestRunner; 36 import org.robolectric.RuntimeEnvironment; 37 import org.robolectric.annotation.Config; 38 39 import java.util.List; 40 41 @RunWith(RobolectricTestRunner.class) 42 public class VrDisplayPreferencePickerTest { 43 44 private VrDisplayPreferencePicker mPicker; 45 46 @Before setUp()47 public void setUp() { 48 MockitoAnnotations.initMocks(this); 49 50 mPicker = spy(new VrDisplayPreferencePicker()); 51 doReturn(RuntimeEnvironment.application).when(mPicker).getContext(); 52 } 53 54 @Test verifyMetricsConstant()55 public void verifyMetricsConstant() { 56 assertThat(mPicker.getMetricsCategory()) 57 .isEqualTo(MetricsProto.MetricsEvent.VR_DISPLAY_PREFERENCE); 58 } 59 60 @Test getCandidates_shouldReturnTwoCandidates()61 public void getCandidates_shouldReturnTwoCandidates() { 62 List<VrDisplayPreferencePicker.VrCandidateInfo> candidates = mPicker.getCandidates(); 63 64 assertThat(candidates.size()).isEqualTo(2); 65 assertThat(candidates.get(0).getKey()) 66 .isEqualTo(VrDisplayPreferencePicker.PREF_KEY_PREFIX + 0); 67 assertThat(candidates.get(1).getKey()) 68 .isEqualTo(VrDisplayPreferencePicker.PREF_KEY_PREFIX + 1); 69 } 70 71 @Test 72 @Config(shadows = ShadowSecureSettings.class) getKey_shouldGetFromSettingsProvider()73 public void getKey_shouldGetFromSettingsProvider() { 74 final ContentResolver cr = RuntimeEnvironment.application.getContentResolver(); 75 Settings.Secure.putIntForUser(cr, Settings.Secure.VR_DISPLAY_MODE, 1, 76 UserHandle.myUserId()); 77 78 assertThat(mPicker.getDefaultKey()) 79 .isEqualTo(VrDisplayPreferencePicker.PREF_KEY_PREFIX + 1); 80 } 81 } 82