• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.TestConfig;
30 import com.android.settings.testutils.shadow.ShadowSecureSettings;
31 
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.MockitoAnnotations;
36 import org.robolectric.RuntimeEnvironment;
37 import org.robolectric.annotation.Config;
38 
39 import java.util.List;
40 
41 @RunWith(SettingsRobolectricTestRunner.class)
42 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
43 public class VrDisplayPreferencePickerTest {
44 
45     private VrDisplayPreferencePicker mPicker;
46 
47     @Before
setUp()48     public void setUp() {
49         MockitoAnnotations.initMocks(this);
50 
51         mPicker = spy(new VrDisplayPreferencePicker());
52         doReturn(RuntimeEnvironment.application).when(mPicker).getContext();
53     }
54 
55     @Test
verifyMetricsConstant()56     public void verifyMetricsConstant() {
57         assertThat(mPicker.getMetricsCategory())
58                 .isEqualTo(MetricsProto.MetricsEvent.VR_DISPLAY_PREFERENCE);
59     }
60 
61     @Test
getCandidates_shouldReturnTwoCandidates()62     public void getCandidates_shouldReturnTwoCandidates() {
63         List<VrDisplayPreferencePicker.VrCandidateInfo> candidates = mPicker.getCandidates();
64 
65         assertThat(candidates.size()).isEqualTo(2);
66         assertThat(candidates.get(0).getKey())
67                 .isEqualTo(VrDisplayPreferencePicker.PREF_KEY_PREFIX + 0);
68         assertThat(candidates.get(1).getKey())
69                 .isEqualTo(VrDisplayPreferencePicker.PREF_KEY_PREFIX + 1);
70     }
71 
72     @Test
73     @Config(shadows = ShadowSecureSettings.class)
getKey_shouldGetFromSettingsProvider()74     public void getKey_shouldGetFromSettingsProvider() {
75         final ContentResolver cr = RuntimeEnvironment.application.getContentResolver();
76         Settings.Secure.putIntForUser(cr, Settings.Secure.VR_DISPLAY_MODE, 1,
77                 UserHandle.myUserId());
78 
79         assertThat(mPicker.getDefaultKey())
80                 .isEqualTo(VrDisplayPreferencePicker.PREF_KEY_PREFIX + 1);
81     }
82 }
83