Merge "[Audiosharing] Fix IllegalStateException at getChildFragmentManager" into main
This commit is contained in:
@@ -23,6 +23,7 @@ import static org.robolectric.shadows.ShadowLooper.shadowMainLooper;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothStatusCodes;
|
||||
import android.os.Bundle;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
@@ -78,10 +79,6 @@ public class AudioSharingCallAudioDialogFragmentTest {
|
||||
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||
shadowBluetoothAdapter.setIsLeAudioBroadcastAssistantSupported(
|
||||
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||
mFragment = new AudioSharingCallAudioDialogFragment();
|
||||
mParent = new Fragment();
|
||||
FragmentController.setupFragment(
|
||||
mParent, FragmentActivity.class, /* containerViewId= */ 0, /* bundle= */ null);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -91,6 +88,7 @@ public class AudioSharingCallAudioDialogFragmentTest {
|
||||
|
||||
@Test
|
||||
public void getMetricsCategory_correctValue() {
|
||||
mFragment = new AudioSharingCallAudioDialogFragment();
|
||||
assertThat(mFragment.getMetricsCategory())
|
||||
.isEqualTo(SettingsEnums.DIALOG_AUDIO_SHARING_CALL_AUDIO);
|
||||
}
|
||||
@@ -98,21 +96,52 @@ public class AudioSharingCallAudioDialogFragmentTest {
|
||||
@Test
|
||||
public void onCreateDialog_flagOff_dialogNotExist() {
|
||||
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
mFragment.show(mParent, new ArrayList<>(), (item) -> {});
|
||||
mParent = new Fragment();
|
||||
FragmentController.setupFragment(
|
||||
mParent, FragmentActivity.class, /* containerViewId= */ 0, /* bundle= */ null);
|
||||
AudioSharingCallAudioDialogFragment.show(mParent, new ArrayList<>(), (item) -> {});
|
||||
shadowMainLooper().idle();
|
||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_unattachedFragment_dialogNotExist() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
mParent = new Fragment();
|
||||
AudioSharingCallAudioDialogFragment.show(mParent, new ArrayList<>(), (item) -> {});
|
||||
shadowMainLooper().idle();
|
||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_nullDeviceItems_showEmptyDialog() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
mFragment = new AudioSharingCallAudioDialogFragment();
|
||||
mFragment.setArguments(Bundle.EMPTY);
|
||||
FragmentController.setupFragment(
|
||||
mFragment, FragmentActivity.class, /* containerViewId= */ 0, /* bundle= */ null);
|
||||
AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
|
||||
dialog.show();
|
||||
shadowMainLooper().idle();
|
||||
assertThat(dialog.isShowing()).isTrue();
|
||||
assertThat(dialog.getListView()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_showCorrectItems() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
mParent = new Fragment();
|
||||
FragmentController.setupFragment(
|
||||
mParent, FragmentActivity.class, /* containerViewId= */ 0, /* bundle= */ null);
|
||||
ArrayList<AudioSharingDeviceItem> deviceItemList = new ArrayList<>();
|
||||
deviceItemList.add(TEST_DEVICE_ITEM1);
|
||||
deviceItemList.add(TEST_DEVICE_ITEM2);
|
||||
mFragment.show(mParent, deviceItemList, (item) -> {});
|
||||
AudioSharingCallAudioDialogFragment.show(mParent, deviceItemList, (item) -> {});
|
||||
shadowMainLooper().idle();
|
||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog).isNotNull();
|
||||
assertThat(dialog.getListView().getCount()).isEqualTo(2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +95,15 @@ public class AudioSharingConfirmDialogFragmentTest {
|
||||
assertThat(dialog).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_unattachedFragment_dialogNotExist() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
AudioSharingConfirmDialogFragment.show(new Fragment());
|
||||
shadowMainLooper().idle();
|
||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_flagOn_showDialog() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
|
||||
@@ -130,7 +130,16 @@ public class AudioSharingDialogFragmentTest {
|
||||
AudioSharingDialogFragment.show(
|
||||
mParent, new ArrayList<>(), EMPTY_EVENT_LISTENER, TEST_EVENT_DATA_LIST);
|
||||
shadowMainLooper().idle();
|
||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_unattachedFragment_dialogNotExist() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
AudioSharingDialogFragment.show(
|
||||
new Fragment(), new ArrayList<>(), EMPTY_EVENT_LISTENER, TEST_EVENT_DATA_LIST);
|
||||
shadowMainLooper().idle();
|
||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog).isNull();
|
||||
}
|
||||
|
||||
@@ -647,6 +647,15 @@ public class AudioSharingDialogHandlerTest {
|
||||
SettingsEnums.DIALOG_START_AUDIO_SHARING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closeOpeningDialogsForLeaDevice_unattachedFragment_doNothing() {
|
||||
mParentFragment = new Fragment();
|
||||
mHandler = new AudioSharingDialogHandler(mContext, mParentFragment);
|
||||
mHandler.closeOpeningDialogsForLeaDevice(mCachedDevice1);
|
||||
shadowOf(Looper.getMainLooper()).idle();
|
||||
verifyNoMoreInteractions(mFeatureFactory.metricsFeatureProvider);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closeOpeningDialogsForLeaDevice_closeDisconnectDialog() {
|
||||
// Show disconnect dialog
|
||||
@@ -674,6 +683,15 @@ public class AudioSharingDialogHandlerTest {
|
||||
SettingsEnums.DIALOG_AUDIO_SHARING_SWITCH_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closeOpeningDialogsForNonLeaDevice_unattachedFragment_doNothing() {
|
||||
mParentFragment = new Fragment();
|
||||
mHandler = new AudioSharingDialogHandler(mContext, mParentFragment);
|
||||
mHandler.closeOpeningDialogsForNonLeaDevice(mCachedDevice2);
|
||||
shadowOf(Looper.getMainLooper()).idle();
|
||||
verifyNoMoreInteractions(mFeatureFactory.metricsFeatureProvider);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closeOpeningDialogsForNonLeaDevice_closeStopDialog() {
|
||||
// Show stop dialog
|
||||
|
||||
@@ -153,6 +153,23 @@ public class AudioSharingDisconnectDialogFragmentTest {
|
||||
assertThat(dialog).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_unattachedFragment_dialogNotExist() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
mDeviceItems = new ArrayList<>();
|
||||
mDeviceItems.add(TEST_DEVICE_ITEM1);
|
||||
mDeviceItems.add(TEST_DEVICE_ITEM2);
|
||||
AudioSharingDisconnectDialogFragment.show(
|
||||
new Fragment(),
|
||||
mDeviceItems,
|
||||
mCachedDevice3,
|
||||
EMPTY_EVENT_LISTENER,
|
||||
TEST_EVENT_DATA_LIST);
|
||||
shadowMainLooper().idle();
|
||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_flagOn_dialogShowBtnForTwoDevices() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
|
||||
@@ -163,6 +163,20 @@ public class AudioSharingJoinDialogFragmentTest {
|
||||
assertThat(dialog).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_unattachedFragment_dialogNotExist() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
AudioSharingJoinDialogFragment.show(
|
||||
new Fragment(),
|
||||
new ArrayList<>(),
|
||||
mCachedDevice2,
|
||||
EMPTY_EVENT_LISTENER,
|
||||
TEST_EVENT_DATA_LIST);
|
||||
shadowMainLooper().idle();
|
||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_flagOn_dialogShowTextForSingleDevice() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
|
||||
@@ -148,6 +148,20 @@ public class AudioSharingStopDialogFragmentTest {
|
||||
assertThat(dialog).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_unattachedFragment_dialogNotExist() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
AudioSharingStopDialogFragment.show(
|
||||
new Fragment(),
|
||||
ImmutableList.of(TEST_DEVICE_ITEM2),
|
||||
mCachedDevice1,
|
||||
EMPTY_EVENT_LISTENER,
|
||||
TEST_EVENT_DATA_LIST);
|
||||
shadowMainLooper().idle();
|
||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_oneDeviceInSharing_showDialogWithCorrectMessage() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
|
||||
Reference in New Issue
Block a user