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