summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Betty Chang <changbetty@google.com> 2022-06-01 08:02:26 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2022-06-01 08:02:26 +0000
commita7ca16d7b460e4a5f3ad15e5f3ec88d622a536bf (patch)
tree6fa0594b4cc19d29b470d8346f6755da4a527bbc
parentb803bfcc2738393176991dd0cc0f864b8c6b7245 (diff)
parent69538f6613e809994f71854555bd4f4a1efdee95 (diff)
Merge "[LE] Test cases for Media Output Broadcast Dialog" into tm-dev am: fc02968aac am: 69538f6613
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18287503 Change-Id: Ib906c986380afc95c7a48c9817b1382cc484136a Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java15
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogTest.java175
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogReceiverTest.kt77
3 files changed, 264 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java
index 8f065461c22d..9fb4a60a2fd2 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java
@@ -35,6 +35,7 @@ import android.widget.TextView;
import androidx.core.graphics.drawable.IconCompat;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.settingslib.qrcode.QrCodeGenerator;
import com.android.systemui.R;
import com.android.systemui.broadcast.BroadcastSender;
@@ -176,7 +177,8 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog {
refreshUi();
}
- private void refreshUi() {
+ @VisibleForTesting
+ void refreshUi() {
setQrCodeView();
mCurrentBroadcastName = getBroadcastMetadataInfo(METADATA_BROADCAST_NAME);
@@ -215,7 +217,8 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog {
mIsPasswordHide = !mIsPasswordHide;
}
- private void launchBroadcastUpdatedDialog(boolean isBroadcastCode, String editString) {
+ @VisibleForTesting
+ void launchBroadcastUpdatedDialog(boolean isBroadcastCode, String editString) {
final View layout = LayoutInflater.from(mContext).inflate(
R.layout.media_output_broadcast_update_dialog, null);
final EditText editText = layout.requireViewById(R.id.broadcast_edit_text);
@@ -242,7 +245,8 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog {
return mMediaOutputController.getBroadcastMetadata();
}
- private void updateBroadcastInfo(boolean isBroadcastCode, String updatedString) {
+ @VisibleForTesting
+ void updateBroadcastInfo(boolean isBroadcastCode, String updatedString) {
Button positiveBtn = mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
if (positiveBtn != null) {
positiveBtn.setEnabled(false);
@@ -345,4 +349,9 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog {
mBroadcastErrorMessage.setText(R.string.media_output_broadcast_last_update_error);
}
}
+
+ @VisibleForTesting
+ int getRetryCount() {
+ return mRetryCount;
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogTest.java
new file mode 100644
index 000000000000..1767ccdc93d8
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogTest.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.media.dialog;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import android.media.session.MediaController;
+import android.media.session.MediaSessionManager;
+import android.media.session.PlaybackState;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import androidx.test.filters.SmallTest;
+
+import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
+import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastMetadata;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
+import com.android.settingslib.media.LocalMediaManager;
+import com.android.settingslib.media.MediaDevice;
+import com.android.systemui.R;
+import com.android.systemui.SysuiTestCase;
+import com.android.systemui.animation.DialogLaunchAnimator;
+import com.android.systemui.broadcast.BroadcastSender;
+import com.android.systemui.media.nearby.NearbyMediaDevicesManager;
+import com.android.systemui.plugins.ActivityStarter;
+import com.android.systemui.statusbar.notification.NotificationEntryManager;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+@SmallTest
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+public class MediaOutputBroadcastDialogTest extends SysuiTestCase {
+
+ private static final String TEST_PACKAGE = "test_package";
+ private static final String BROADCAST_NAME_TEST = "Broadcast_name_test";
+ private static final String BROADCAST_CODE_TEST = "112233";
+ private static final String BROADCAST_CODE_UPDATE_TEST = "11223344";
+
+ // Mock
+ private final MediaSessionManager mMediaSessionManager = mock(MediaSessionManager.class);
+ private MediaController mMediaController = mock(MediaController.class);
+ private PlaybackState mPlaybackState = mock(PlaybackState.class);
+ private final LocalBluetoothManager mLocalBluetoothManager = mock(LocalBluetoothManager.class);
+ private final LocalBluetoothProfileManager mLocalBluetoothProfileManager = mock(
+ LocalBluetoothProfileManager.class);
+ private final LocalBluetoothLeBroadcast mLocalBluetoothLeBroadcast = mock(
+ LocalBluetoothLeBroadcast.class);
+ private final ActivityStarter mStarter = mock(ActivityStarter.class);
+ private final BroadcastSender mBroadcastSender = mock(BroadcastSender.class);
+ private final LocalMediaManager mLocalMediaManager = mock(LocalMediaManager.class);
+ private final MediaDevice mMediaDevice = mock(MediaDevice.class);
+ private final NotificationEntryManager mNotificationEntryManager =
+ mock(NotificationEntryManager.class);
+ private final DialogLaunchAnimator mDialogLaunchAnimator = mock(DialogLaunchAnimator.class);
+ private final NearbyMediaDevicesManager mNearbyMediaDevicesManager = mock(
+ NearbyMediaDevicesManager.class);
+ private final LocalBluetoothLeBroadcastMetadata mLocalBluetoothLeBroadcastMetadata =
+ mock(LocalBluetoothLeBroadcastMetadata.class);
+
+ private List<MediaController> mMediaControllers = new ArrayList<>();
+ private MediaOutputBroadcastDialog mMediaOutputBroadcastDialog;
+ private MediaOutputController mMediaOutputController;
+ private final List<String> mFeatures = new ArrayList<>();
+
+ @Before
+ public void setUp() {
+ when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
+ when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile())
+ .thenReturn(mLocalBluetoothLeBroadcast);
+ when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
+ when(mPlaybackState.getState()).thenReturn(PlaybackState.STATE_NONE);
+ when(mMediaController.getPackageName()).thenReturn(TEST_PACKAGE);
+ mMediaControllers.add(mMediaController);
+ when(mMediaSessionManager.getActiveSessions(any())).thenReturn(mMediaControllers);
+ when(mLocalBluetoothLeBroadcast.getLocalBluetoothLeBroadcastMetaData()).thenReturn(
+ mLocalBluetoothLeBroadcastMetadata);
+ when(mLocalBluetoothLeBroadcastMetadata.convertToQrCodeString())
+ .thenReturn("metadata_test_convert");
+ when(mLocalBluetoothLeBroadcast.getProgramInfo()).thenReturn(BROADCAST_NAME_TEST);
+ when(mLocalBluetoothLeBroadcast.getBroadcastCode())
+ .thenReturn(BROADCAST_CODE_TEST.getBytes(StandardCharsets.UTF_8));
+
+ mMediaOutputController = new MediaOutputController(mContext, TEST_PACKAGE,
+ mMediaSessionManager, mLocalBluetoothManager, mStarter,
+ mNotificationEntryManager, mDialogLaunchAnimator,
+ Optional.of(mNearbyMediaDevicesManager));
+ mMediaOutputController.mLocalMediaManager = mLocalMediaManager;
+ mMediaOutputBroadcastDialog = new MediaOutputBroadcastDialog(mContext, false,
+ mBroadcastSender, mMediaOutputController);
+ mMediaOutputBroadcastDialog.show();
+
+ when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(mMediaDevice);
+ when(mMediaDevice.getFeatures()).thenReturn(mFeatures);
+ }
+
+ @After
+ public void tearDown() {
+ mMediaOutputBroadcastDialog.dismissDialog();
+ }
+
+ @Test
+ public void refreshUi_checkBroadcastQrCodeView() {
+ mMediaOutputBroadcastDialog.refreshUi();
+ final ImageView broadcastQrCodeView = mMediaOutputBroadcastDialog.mDialogView
+ .requireViewById(R.id.qrcode_view);
+
+ assertThat(broadcastQrCodeView.getDrawable()).isNotNull();
+ }
+
+ @Test
+ public void refreshUi_checkBroadcastName() {
+ mMediaOutputBroadcastDialog.refreshUi();
+ final TextView broadcastName = mMediaOutputBroadcastDialog.mDialogView
+ .requireViewById(R.id.broadcast_name_summary);
+
+ assertThat(broadcastName.getText().toString()).isEqualTo(BROADCAST_NAME_TEST);
+ }
+
+ @Test
+ public void refreshUi_checkBroadcastCode() {
+ mMediaOutputBroadcastDialog.refreshUi();
+ final TextView broadcastCode = mMediaOutputBroadcastDialog.mDialogView
+ .requireViewById(R.id.broadcast_code_summary);
+
+ assertThat(broadcastCode.getText().toString()).isEqualTo(BROADCAST_CODE_TEST);
+ }
+
+ @Test
+ public void updateBroadcastInfo_stopBroadcastFailed_handleFailedUI() {
+ mMediaOutputBroadcastDialog.launchBroadcastUpdatedDialog(true, BROADCAST_CODE_UPDATE_TEST);
+ when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile())
+ .thenReturn(null);
+
+ mMediaOutputBroadcastDialog.updateBroadcastInfo(true, BROADCAST_CODE_UPDATE_TEST);
+ assertThat(mMediaOutputBroadcastDialog.getRetryCount()).isEqualTo(1);
+
+ mMediaOutputBroadcastDialog.updateBroadcastInfo(true, BROADCAST_CODE_UPDATE_TEST);
+ assertThat(mMediaOutputBroadcastDialog.getRetryCount()).isEqualTo(2);
+
+ // It will be the MAX Retry Count = 3
+ mMediaOutputBroadcastDialog.updateBroadcastInfo(true, BROADCAST_CODE_UPDATE_TEST);
+ assertThat(mMediaOutputBroadcastDialog.getRetryCount()).isEqualTo(0);
+ }
+
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogReceiverTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogReceiverTest.kt
new file mode 100644
index 000000000000..d03b0a419f17
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogReceiverTest.kt
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.media.dialog
+
+import android.content.Intent
+import android.testing.AndroidTestingRunner
+import androidx.test.filters.SmallTest
+
+import com.android.settingslib.media.MediaOutputConstants
+import com.android.systemui.SysuiTestCase
+
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.ArgumentMatchers.anyBoolean
+import org.mockito.ArgumentMatchers.anyString
+import org.mockito.ArgumentMatchers.any
+import org.mockito.Mock
+import org.mockito.Mockito.never
+import org.mockito.Mockito.times
+import org.mockito.Mockito.verify
+import org.mockito.MockitoAnnotations
+
+@SmallTest
+@RunWith(AndroidTestingRunner::class)
+class MediaOutputDialogReceiverTest : SysuiTestCase() {
+
+ @Mock
+ private lateinit var mediaOutputDialogFactory: MediaOutputDialogFactory
+ @Mock
+ private lateinit var mediaOutputBroadcastDialogFactory: MediaOutputBroadcastDialogFactory
+
+ private lateinit var receiver: MediaOutputDialogReceiver
+ private lateinit var intent: Intent
+
+ @Before
+ fun setUp() {
+ MockitoAnnotations.initMocks(this)
+
+ receiver = MediaOutputDialogReceiver(
+ mediaOutputDialogFactory, mediaOutputBroadcastDialogFactory)
+ }
+
+ @Test
+ fun onReceive_intentWithPackageName_LaunchBroadcastDialog() {
+ intent = Intent(MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_BROADCAST_DIALOG).apply {
+ putExtra(MediaOutputConstants.EXTRA_PACKAGE_NAME, "test_pkg") }
+
+ receiver.onReceive(mContext, intent)
+
+ verify(mediaOutputBroadcastDialogFactory, times(1)).create(anyString(), anyBoolean(), any())
+ }
+
+ @Test
+ fun onReceive_intentWithoutPackageName_doNotLaunchBroadcastDialog() {
+ intent = Intent(MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_BROADCAST_DIALOG).apply {
+ putExtra(MediaOutputConstants.EXTRA_PACKAGE_NAME, "") }
+
+ receiver.onReceive(mContext, intent)
+
+ verify(mediaOutputBroadcastDialogFactory, never()).create(anyString(), anyBoolean(), any())
+ }
+} \ No newline at end of file