Fix "Play media to" popup close issue when screen rotate
- Avoid calling getListPreference() in onDialogClose() everytime. Due to exception in onDialogClose(). Move preference declaration into if condition. - Add test case for crash case. Bug: 119744621 Test: make -j50 RunSettingsRoboTests ROBOTEST_FILTER=UpdatableListPreferenceDialogFragmentTest Change-Id: Ia20b8289a5863136ea74e02e32b537f6967474e8
This commit is contained in:
@@ -18,7 +18,9 @@ package com.android.settings.widget;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.ArrayAdapter;
|
||||
@@ -31,6 +33,7 @@ import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
@@ -42,9 +45,10 @@ import java.util.ArrayList;
|
||||
@Config(shadows = ShadowBluetoothUtils.class)
|
||||
public class UpdatableListPreferenceDialogFragmentTest {
|
||||
|
||||
private Context mContext;
|
||||
private UpdatableListPreferenceDialogFragment mUpdatableListPrefDlgFragment;
|
||||
private static final String KEY = "Test_Key";
|
||||
@Mock
|
||||
private UpdatableListPreferenceDialogFragment mUpdatableListPrefDlgFragment;
|
||||
private Context mContext;
|
||||
private ArrayAdapter mAdapter;
|
||||
private ArrayList<CharSequence> mEntries;
|
||||
|
||||
@@ -53,8 +57,8 @@ public class UpdatableListPreferenceDialogFragmentTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mUpdatableListPrefDlgFragment = UpdatableListPreferenceDialogFragment
|
||||
.newInstance(KEY, MetricsProto.MetricsEvent.DIALOG_SWITCH_A2DP_DEVICES);
|
||||
mUpdatableListPrefDlgFragment = spy(UpdatableListPreferenceDialogFragment
|
||||
.newInstance(KEY, MetricsProto.MetricsEvent.DIALOG_SWITCH_A2DP_DEVICES));
|
||||
mEntries = spy(new ArrayList<>());
|
||||
mUpdatableListPrefDlgFragment.setEntries(mEntries);
|
||||
mUpdatableListPrefDlgFragment.
|
||||
@@ -87,4 +91,11 @@ public class UpdatableListPreferenceDialogFragmentTest {
|
||||
|
||||
assertThat(mUpdatableListPrefDlgFragment.getAdapter().getCount()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDialogClosed_emptyPreference() {
|
||||
mUpdatableListPrefDlgFragment.onDialogClosed(false);
|
||||
|
||||
verify(mUpdatableListPrefDlgFragment, never()).getListPreference();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user