• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.accessibility;
18 
19 import static com.android.settings.core.BasePreferenceController.AVAILABLE;
20 import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
21 
22 import static com.google.common.truth.Truth.assertThat;
23 
24 import android.content.pm.ResolveInfo;
25 
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.robolectric.RobolectricTestRunner;
30 import org.robolectric.RuntimeEnvironment;
31 import org.robolectric.Shadows;
32 import org.robolectric.shadows.ShadowPackageManager;
33 
34 import java.util.Collections;
35 
36 @RunWith(RobolectricTestRunner.class)
37 public class LiveCaptionPreferenceControllerTest {
38 
39     private LiveCaptionPreferenceController mController;
40 
41     @Before
setUp()42     public void setUp() {
43         mController = new LiveCaptionPreferenceController(RuntimeEnvironment.application,
44                 "test_key");
45     }
46 
47     @Test
getAvailabilityStatus_canResolveIntent_shouldReturnAvailable()48     public void getAvailabilityStatus_canResolveIntent_shouldReturnAvailable() {
49         final ShadowPackageManager pm = Shadows.shadowOf(
50                 RuntimeEnvironment.application.getPackageManager());
51         pm.addResolveInfoForIntent(LiveCaptionPreferenceController.LIVE_CAPTION_INTENT,
52                 new ResolveInfo());
53 
54         assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
55     }
56 
57     @Test
getAvailabilityStatus_noResolveIntent_shouldReturnUnavailable()58     public void getAvailabilityStatus_noResolveIntent_shouldReturnUnavailable() {
59         final ShadowPackageManager pm = Shadows.shadowOf(
60                 RuntimeEnvironment.application.getPackageManager());
61         pm.setResolveInfosForIntent(LiveCaptionPreferenceController.LIVE_CAPTION_INTENT,
62                 Collections.emptyList());
63 
64         assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
65     }
66 }