Merge changes from topic "update_entry"

* changes:
  Update rule of launching media output dialog
  Update OutputSwitcher from MediaOutputSlice to MediaOutputDialog in Settings
This commit is contained in:
tim peng
2020-10-12 01:03:27 +00:00
committed by Android (Google) Code Review
7 changed files with 138 additions and 63 deletions

View File

@@ -23,6 +23,8 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
@@ -54,6 +56,7 @@ import com.android.settingslib.media.MediaOutputSliceConstants;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@@ -203,31 +206,45 @@ public class MediaOutputIndicatorSliceTest {
}
@Test
public void getMediaOutputSliceIntent_withActiveLocalMedia_verifyIntentExtra() {
public void onNotifyChange_withActiveLocalMedia_verifyIntentExtra() {
when(mMediaController.getSessionToken()).thenReturn(mToken);
when(mMediaController.getPackageName()).thenReturn(TEST_PACKAGE_NAME);
doReturn(mMediaController).when(sMediaOutputIndicatorWorker)
.getActiveLocalMediaController();
final Intent intent = mMediaOutputIndicatorSlice.getMediaOutputSliceIntent();
ArgumentCaptor<Intent> argument = ArgumentCaptor.forClass(Intent.class);
mMediaOutputIndicatorSlice.onNotifyChange(null);
verify(mContext, times(2)).sendBroadcast(argument.capture());
List<Intent> intentList = argument.getAllValues();
Intent intent = intentList.get(0);
assertThat(TextUtils.equals(TEST_PACKAGE_NAME, intent.getStringExtra(
MediaOutputSliceConstants.EXTRA_PACKAGE_NAME))).isTrue();
assertThat(MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT).isEqualTo(intent.getAction());
assertThat(TextUtils.equals(Utils.SETTINGS_PACKAGE_NAME, intent.getPackage())).isTrue();
assertThat(MediaOutputSliceConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG).isEqualTo(
intent.getAction());
assertThat(TextUtils.equals(MediaOutputSliceConstants.SYSTEMUI_PACKAGE_NAME,
intent.getPackage())).isTrue();
assertThat(mToken == intent.getExtras().getParcelable(
MediaOutputSliceConstants.KEY_MEDIA_SESSION_TOKEN)).isTrue();
}
@Test
public void getMediaOutputSliceIntent_withoutActiveLocalMedia_verifyIntentExtra() {
public void onNotifyChange_withoutActiveLocalMedia_verifyIntentExtra() {
doReturn(mMediaController).when(sMediaOutputIndicatorWorker)
.getActiveLocalMediaController();
final Intent intent = mMediaOutputIndicatorSlice.getMediaOutputSliceIntent();
ArgumentCaptor<Intent> argument = ArgumentCaptor.forClass(Intent.class);
mMediaOutputIndicatorSlice.onNotifyChange(null);
verify(mContext, times(2)).sendBroadcast(argument.capture());
List<Intent> intentList = argument.getAllValues();
Intent intent = intentList.get(0);
assertThat(TextUtils.isEmpty(intent.getStringExtra(
MediaOutputSliceConstants.EXTRA_PACKAGE_NAME))).isTrue();
assertThat(MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT).isEqualTo(intent.getAction());
assertThat(TextUtils.equals(Utils.SETTINGS_PACKAGE_NAME, intent.getPackage())).isTrue();
assertThat(MediaOutputSliceConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG).isEqualTo(
intent.getAction());
assertThat(TextUtils.equals(MediaOutputSliceConstants.SYSTEMUI_PACKAGE_NAME,
intent.getPackage())).isTrue();
assertThat(intent.getExtras().getParcelable(
MediaOutputSliceConstants.KEY_MEDIA_SESSION_TOKEN) == null).isTrue();
}

View File

@@ -300,9 +300,9 @@ public class MediaOutputPreferenceControllerTest {
mPreference.setKey(TEST_KEY);
mController.handlePreferenceTreeClick(mPreference);
verify(mContext).startActivity(intentCaptor.capture());
verify(mContext).sendBroadcast(intentCaptor.capture());
assertThat(intentCaptor.getValue().getAction())
.isEqualTo(MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT);
.isEqualTo(MediaOutputSliceConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG);
}
/**