• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.sound;
18 
19 import static com.android.settings.core.BasePreferenceController.AVAILABLE;
20 
21 import static com.google.common.truth.Truth.assertThat;
22 
23 import static org.mockito.Mockito.spy;
24 
25 import android.content.ContentResolver;
26 import android.content.Context;
27 import android.provider.Settings;
28 
29 import com.android.settings.R;
30 
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.robolectric.RobolectricTestRunner;
36 import org.robolectric.RuntimeEnvironment;
37 
38 @RunWith(RobolectricTestRunner.class)
39 public class MediaControlsParentPreferenceControllerTest {
40 
41     private static final String KEY = "media_controls_summary";
42 
43     private Context mContext;
44     private int mOriginalQs;
45     private int mOriginalResume;
46     private ContentResolver mContentResolver;
47     private MediaControlsParentPreferenceController mController;
48 
49     @Before
setUp()50     public void setUp() {
51         mContext = spy(RuntimeEnvironment.application);
52         mContentResolver = mContext.getContentResolver();
53         mOriginalQs = Settings.Global.getInt(mContentResolver,
54                 Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1);
55         mOriginalResume = Settings.Secure.getInt(mContentResolver,
56                 Settings.Secure.MEDIA_CONTROLS_RESUME, 1);
57         mController = new MediaControlsParentPreferenceController(mContext, KEY);
58     }
59 
60     @After
tearDown()61     public void tearDown() {
62         Settings.Global.putInt(mContentResolver, Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS,
63                 mOriginalQs);
64         Settings.Secure.putInt(mContentResolver, Settings.Secure.MEDIA_CONTROLS_RESUME,
65                 mOriginalResume);
66     }
67 
68     @Test
getAvailability_returnAvailable()69     public void getAvailability_returnAvailable() {
70         assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
71     }
72 
73     @Test
getSummary_isOn_showPlayer()74     public void getSummary_isOn_showPlayer() {
75         Settings.Global.putInt(mContentResolver, Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1);
76         Settings.Secure.putInt(mContentResolver, Settings.Secure.MEDIA_CONTROLS_RESUME, 1);
77 
78         assertThat(mController.getSummary())
79                 .isEqualTo(mContext.getString(R.string.media_controls_show_player));
80     }
81 
82     @Test
getSummary_isOff_hidePlayer()83     public void getSummary_isOff_hidePlayer() {
84         Settings.Global.putInt(mContentResolver, Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1);
85         Settings.Secure.putInt(mContentResolver, Settings.Secure.MEDIA_CONTROLS_RESUME, 0);
86 
87         assertThat(mController.getSummary())
88                 .isEqualTo(mContext.getString(R.string.media_controls_hide_player));
89     }
90 }
91