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