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 package com.android.settings.panel;
17 
18 import static com.android.settings.panel.SettingsPanelActivity.KEY_MEDIA_PACKAGE_NAME;
19 import static com.android.settings.panel.SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT;
20 
21 import static com.google.common.truth.Truth.assertThat;
22 
23 import static org.mockito.Mockito.never;
24 import static org.mockito.Mockito.spy;
25 import static org.mockito.Mockito.verify;
26 
27 import android.content.Context;
28 import android.content.Intent;
29 import android.os.Bundle;
30 import android.provider.Settings;
31 
32 import androidx.test.core.app.ApplicationProvider;
33 import androidx.test.ext.junit.runners.AndroidJUnit4;
34 
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 
39 @RunWith(AndroidJUnit4.class)
40 public class PanelFeatureProviderImplTest {
41 
42     private static final String TEST_PACKAGENAME = "com.test.packagename";
43 
44     private static final String SYSTEMUI_PACKAGE_NAME = "com.android.systemui";
45     private Context mContext;
46     private PanelFeatureProviderImpl mProvider;
47     private Bundle mBundle;
48 
49     @Before
setUp()50     public void setUp() {
51         mContext = spy(ApplicationProvider.getApplicationContext());
52         mProvider = new PanelFeatureProviderImpl();
53         mBundle = new Bundle();
54         mBundle.putString(KEY_MEDIA_PACKAGE_NAME, TEST_PACKAGENAME);
55     }
56 
57     @Test
getPanel_internetConnectivityKey_sendsCorrectBroadcast()58     public void getPanel_internetConnectivityKey_sendsCorrectBroadcast() {
59         mBundle.putString(KEY_PANEL_TYPE_ARGUMENT, Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
60         mProvider.getPanel(mContext, mBundle);
61         Intent intent = new Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
62         intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
63                 .setPackage(SYSTEMUI_PACKAGE_NAME);
64 
65         verify(mContext, never()).sendBroadcast(intent);
66     }
67 
68     @Test
getPanel_volume_returnsCorrectPanel()69     public void getPanel_volume_returnsCorrectPanel() {
70         mBundle.putString(KEY_PANEL_TYPE_ARGUMENT, Settings.Panel.ACTION_VOLUME);
71 
72         final PanelContent panel = mProvider.getPanel(mContext, mBundle);
73 
74         assertThat(panel).isInstanceOf(VolumePanel.class);
75     }
76 }
77