diff --git a/res/xml/network_and_internet_v2.xml b/res/xml/network_and_internet_v2.xml index f004d06450e..0d9e2ea1331 100644 --- a/res/xml/network_and_internet_v2.xml +++ b/res/xml/network_and_internet_v2.xml @@ -18,7 +18,8 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:settings="http://schemas.android.com/apk/res-auto" android:key="network_and_internet_screen" - android:title="@string/network_dashboard_title"> + android:title="@string/network_dashboard_title" + settings:initialExpandedChildrenCount="6"> values = captor.getAllValues(); assertThat(values.get(values.size()-1)).isEqualTo(Boolean.TRUE); + + ArgumentCaptor expandedCountCaptor = ArgumentCaptor.forClass(Integer.class); + verify(mPreferenceScreen).setInitialExpandedChildrenCount(expandedCountCaptor.capture()); + assertThat(expandedCountCaptor.getValue()).isEqualTo( + EXPANDED_CHILDREN_COUNT + mPreferenceCategory.getPreferenceCount()); } @Test @@ -148,5 +158,23 @@ public class MultiNetworkHeaderControllerTest { verify(mPreferenceCategory, atLeastOnce()).setVisible(captor.capture()); List values = captor.getAllValues(); assertThat(values.get(values.size()-1)).isEqualTo(Boolean.FALSE); + + ArgumentCaptor expandedCountCaptor = ArgumentCaptor.forClass(Integer.class); + verify(mPreferenceScreen).setInitialExpandedChildrenCount(expandedCountCaptor.capture()); + assertThat(expandedCountCaptor.getValue()).isEqualTo(EXPANDED_CHILDREN_COUNT); + } + + @Test + public void onChildUpdated_noExpandedChildCountAndAvailable_doesNotSetExpandedCount() { + when(mPreferenceScreen.getInitialExpandedChildrenCount()).thenReturn(Integer.MAX_VALUE); + + when(mSubscriptionsController.isAvailable()).thenReturn(false); + mHeaderController.init(mLifecycle); + mHeaderController.displayPreference(mPreferenceScreen); + + when(mSubscriptionsController.isAvailable()).thenReturn(true); + mHeaderController.onChildrenUpdated(); + + verify(mPreferenceScreen, never()).setInitialExpandedChildrenCount(anyInt()); } } diff --git a/tests/robotests/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java index a4847457441..97966b3420a 100644 --- a/tests/robotests/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java @@ -20,6 +20,7 @@ import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; @@ -186,19 +187,24 @@ public class SubscriptionsPreferenceControllerTest { } @Test - public void onSubscriptionsChanged_countBecameOne_eventFired() { + public void onSubscriptionsChanged_countBecameOne_eventFiredAndPrefsRemoved() { final SubscriptionInfo sub1 = mock(SubscriptionInfo.class); final SubscriptionInfo sub2 = mock(SubscriptionInfo.class); + when(sub1.getSubscriptionId()).thenReturn(1); + when(sub2.getSubscriptionId()).thenReturn(2); SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2)); mController.onResume(); mController.displayPreference(mScreen); assertThat(mController.isAvailable()).isTrue(); + verify(mPreferenceCategory, times(2)).addPreference(any(Preference.class)); final int updateCountBeforeSubscriptionChange = mOnChildUpdatedCount; SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1)); mController.onSubscriptionsChanged(); assertThat(mController.isAvailable()).isFalse(); assertThat(mOnChildUpdatedCount).isEqualTo(updateCountBeforeSubscriptionChange + 1); + + verify(mPreferenceCategory, times(2)).removePreference(any(Preference.class)); }