Merge "Add stop casting button for output switch"

This commit is contained in:
TreeHugger Robot
2020-02-19 12:25:05 +00:00
committed by Android (Google) Code Review
6 changed files with 245 additions and 8 deletions

View File

@@ -21,7 +21,9 @@ import static com.android.settings.media.MediaOutputSlice.MEDIA_PACKAGE_NAME;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
@@ -32,6 +34,9 @@ import android.net.Uri;
import com.android.settings.R;
import com.android.settings.slices.CustomSliceRegistry;
import com.android.settingslib.media.InfoMediaDevice;
import com.android.settingslib.media.LocalMediaManager;
import com.android.settingslib.media.PhoneMediaDevice;
import org.junit.Before;
import org.junit.Test;
@@ -58,6 +63,11 @@ public class MediaOutputPanelTest {
@Mock
private MediaMetadata mMediaMetadata;
@Mock
private LocalMediaManager mLocalMediaManager;
@Mock
private PanelCustomizedButtonCallback mCallback;
private MediaOutputPanel mPanel;
private Context mContext;
private List<MediaController> mMediaControllers = new ArrayList<>();
@@ -67,12 +77,16 @@ public class MediaOutputPanelTest {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mMediaControllers.add(mMediaController);
when(mMediaController.getPackageName()).thenReturn(TEST_PACKAGENAME);
when(mMediaSessionManager.getActiveSessions(any())).thenReturn(mMediaControllers);
when(mContext.getApplicationContext()).thenReturn(mContext);
when(mContext.getSystemService(MediaSessionManager.class)).thenReturn(mMediaSessionManager);
mPanel = MediaOutputPanel.create(mContext, TEST_PACKAGENAME);
mPanel.mLocalMediaManager = mLocalMediaManager;
mPanel.registerCallback(mCallback);
}
@Test
@@ -94,6 +108,63 @@ public class MediaOutputPanelTest {
assertThat(mPanel.getSeeMoreIntent()).isNull();
}
@Test
public void onStart_shouldRegisterCallback() {
mPanel.onStart();
verify(mLocalMediaManager).registerCallback(any());
verify(mLocalMediaManager).startScan();
}
@Test
public void onStop_shouldUnregisterCallback() {
mPanel.onStop();
verify(mLocalMediaManager).unregisterCallback(any());
verify(mLocalMediaManager).stopScan();
}
@Test
public void onSelectedDeviceStateChanged_shouldDispatchCustomButtonStateChanged() {
mPanel.onSelectedDeviceStateChanged(null, 0);
verify(mCallback).onCustomizedButtonStateChanged();
}
@Test
public void onDeviceListUpdate_shouldDispatchCustomButtonStateChanged() {
mPanel.onDeviceListUpdate(null);
verify(mCallback).onCustomizedButtonStateChanged();
}
@Test
public void onDeviceAttributesChanged_shouldDispatchCustomButtonStateChanged() {
mPanel.onDeviceAttributesChanged();
verify(mCallback).onCustomizedButtonStateChanged();
}
@Test
public void currentConnectDeviceIsInfoDevice_useCustomButtonIsTrue() {
final InfoMediaDevice infoMediaDevice = mock(InfoMediaDevice.class);
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(infoMediaDevice);
mPanel.onDeviceAttributesChanged();
assertThat(mPanel.isCustomizedButtonUsed()).isTrue();
}
@Test
public void currentConnectDeviceIsNotInfoDevice_useCustomButtonIsFalse() {
final PhoneMediaDevice phoneMediaDevice = mock(PhoneMediaDevice.class);
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(phoneMediaDevice);
mPanel.onDeviceAttributesChanged();
assertThat(mPanel.isCustomizedButtonUsed()).isFalse();
}
@Test
public void getTitle_withMetadata_returnArtistName() {
when(mMediaMetadata.getString(MediaMetadata.METADATA_KEY_ARTIST)).thenReturn(TEST_ARTIST);