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 import android.util.FeatureFlagUtils; 32 33 import androidx.test.core.app.ApplicationProvider; 34 import androidx.test.ext.junit.runners.AndroidJUnit4; 35 36 import org.junit.Before; 37 import org.junit.Test; 38 import org.junit.runner.RunWith; 39 import org.mockito.ArgumentCaptor; 40 41 @RunWith(AndroidJUnit4.class) 42 public class PanelFeatureProviderImplTest { 43 44 private static final String TEST_PACKAGENAME = "com.test.packagename"; 45 46 private static final String SYSTEMUI_PACKAGE_NAME = "com.android.systemui"; 47 private Context mContext; 48 private PanelFeatureProviderImpl mProvider; 49 private Bundle mBundle; 50 51 @Before setUp()52 public void setUp() { 53 mContext = spy(ApplicationProvider.getApplicationContext()); 54 mProvider = new PanelFeatureProviderImpl(); 55 mBundle = new Bundle(); 56 mBundle.putString(KEY_MEDIA_PACKAGE_NAME, TEST_PACKAGENAME); 57 } 58 59 @Test getPanel_internetConnectivityKey_sendsCorrectBroadcast()60 public void getPanel_internetConnectivityKey_sendsCorrectBroadcast() { 61 mBundle.putString(KEY_PANEL_TYPE_ARGUMENT, Settings.Panel.ACTION_INTERNET_CONNECTIVITY); 62 mProvider.getPanel(mContext, mBundle); 63 Intent intent = new Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY); 64 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND) 65 .setPackage(SYSTEMUI_PACKAGE_NAME); 66 67 verify(mContext, never()).sendBroadcast(intent); 68 } 69 70 @Test getPanel_volumePanel_returnsCorrectPanel()71 public void getPanel_volumePanel_returnsCorrectPanel() { 72 FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_VOLUME_PANEL_IN_SYSTEMUI, 73 false); 74 mBundle.putString(KEY_PANEL_TYPE_ARGUMENT, Settings.Panel.ACTION_VOLUME); 75 76 final PanelContent panel = mProvider.getPanel(mContext, mBundle); 77 78 assertThat(panel).isInstanceOf(VolumePanel.class); 79 } 80 81 @Test getPanel_volumePanelFlagEnabled_sendRedirectIntent()82 public void getPanel_volumePanelFlagEnabled_sendRedirectIntent() { 83 FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_VOLUME_PANEL_IN_SYSTEMUI, 84 true); 85 mBundle.putString(KEY_PANEL_TYPE_ARGUMENT, Settings.Panel.ACTION_VOLUME); 86 final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); 87 88 mProvider.getPanel(mContext, mBundle); 89 90 verify(mContext).sendBroadcast(intentCaptor.capture()); 91 assertThat(intentCaptor.getValue().getAction()).isEqualTo(Settings.Panel.ACTION_VOLUME); 92 assertThat(intentCaptor.getValue().getPackage()).isEqualTo(SYSTEMUI_PACKAGE_NAME); 93 } 94 } 95