Merge "[DataUsage] Adjusting the control of display sequence"

This commit is contained in:
Bonian Chen
2022-03-17 05:36:33 +00:00
committed by Android (Google) Code Review
4 changed files with 102 additions and 56 deletions

View File

@@ -17,7 +17,10 @@ package com.android.settings.datausage;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -163,23 +166,32 @@ public class ChartDataUsagePreferenceTest {
@Test
public void notifyChange_nonEmptyDataUsage_shouldHaveSingleContentDescription() {
final UsageView chart = (UsageView) mHolder.findViewById(R.id.data_usage);
final TextView labelTop = (TextView) mHolder.findViewById(R.id.label_top);
final TextView labelMiddle = (TextView) mHolder.findViewById(R.id.label_middle);
final TextView labelBottom = (TextView) mHolder.findViewById(R.id.label_bottom);
final TextView labelStart = (TextView) mHolder.findViewById(R.id.label_start);
final TextView labelEnd = (TextView) mHolder.findViewById(R.id.label_end);
final ArgumentCaptor<CharSequence> contentCaptor =
ArgumentCaptor.forClass(CharSequence.class);
final UsageView chart = mock(UsageView.class);
doReturn(chart).when(mHolder).findViewById(R.id.data_usage);
final TextView labelTop = mock(TextView.class);
doReturn(labelTop).when(mHolder).findViewById(R.id.label_top);
final TextView labelMiddle = mock(TextView.class);
doReturn(labelMiddle).when(mHolder).findViewById(R.id.label_middle);
final TextView labelBottom = mock(TextView.class);
doReturn(labelBottom).when(mHolder).findViewById(R.id.label_bottom);
final TextView labelStart = mock(TextView.class);
doReturn(labelStart).when(mHolder).findViewById(R.id.label_start);
final TextView labelEnd = mock(TextView.class);
doReturn(labelEnd).when(mHolder).findViewById(R.id.label_end);
createTestNetworkData();
mPreference.setNetworkCycleData(mNetworkCycleChartData);
mPreference.onBindViewHolder(mHolder);
mPreference.setNetworkCycleData(mNetworkCycleChartData);
assertThat(chart.getContentDescription()).isNotNull();
assertThat(labelTop.getContentDescription()).isNull();
assertThat(labelMiddle.getContentDescription()).isNull();
assertThat(labelBottom.getContentDescription()).isNull();
assertThat(labelStart.getContentDescription()).isNull();
assertThat(labelEnd.getContentDescription()).isNull();
verify(chart).setContentDescription(contentCaptor.capture());
assertThat(contentCaptor.getValue()).isNotNull();
verify(labelTop, never()).setContentDescription(any());
verify(labelMiddle, never()).setContentDescription(any());
verify(labelBottom, never()).setContentDescription(any());
verify(labelStart, never()).setContentDescription(any());
verify(labelEnd, never()).setContentDescription(any());
}
@Test

View File

@@ -192,32 +192,23 @@ public class DataUsageListTest {
}
@Test
public void onViewCreated_shouldHideCycleSpinner() {
final View view = new View(mActivity);
final View header = getHeader();
final Spinner spinner = getSpinner(header);
spinner.setVisibility(View.VISIBLE);
doReturn(header).when(mDataUsageList).setPinnedHeaderView(anyInt());
doReturn(view).when(mDataUsageList).getView();
public void onViewCreated_shouldNotSetCycleSpinner() {
View view = constructRootView();
mDataUsageList.onViewCreated(view, null);
assertThat(spinner.getVisibility()).isEqualTo(View.GONE);
assertThat(getSpinner(view)).isNull();
}
@Test
public void onLoadFinished_networkCycleDataCallback_shouldShowCycleSpinner() {
final LoadingViewController loadingViewController = mock(LoadingViewController.class);
mDataUsageList.mLoadingViewController = loadingViewController;
final Spinner spinner = getSpinner(getHeader());
spinner.setVisibility(View.INVISIBLE);
mDataUsageList.mCycleSpinner = spinner;
assertThat(spinner.getVisibility()).isEqualTo(View.INVISIBLE);
public void onLoadFinished_networkCycleDataCallback_shouldSetCycleSpinner() {
final View view = constructRootView();
doNothing().when(mDataUsageList).updatePolicy();
doReturn(setupHeaderView(view)).when(mDataUsageList).setPinnedHeaderView(anyInt());
mDataUsageList.mNetworkCycleDataCallbacks.onLoadFinished(null, null);
assertThat(spinner.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(getSpinner(view)).isNotNull();
}
@Test
@@ -228,18 +219,24 @@ public class DataUsageListTest {
verify(mLoaderManager).destroyLoader(DataUsageList.LOADER_SUMMARY);
}
private View getHeader() {
final View rootView = LayoutInflater.from(mActivity)
private View constructRootView() {
View rootView = LayoutInflater.from(mActivity)
.inflate(R.layout.preference_list_fragment, null, false);
final FrameLayout pinnedHeader = rootView.findViewById(R.id.pinned_header);
final View header = mActivity.getLayoutInflater()
.inflate(R.layout.apps_filter_spinner, pinnedHeader, false);
return rootView;
}
private View setupHeaderView(View rootView) {
final FrameLayout pinnedHeader = (FrameLayout) rootView.findViewById(R.id.pinned_header);
final View header = mActivity.getLayoutInflater()
.inflate(R.layout.apps_filter_spinner, pinnedHeader, true);
return header;
}
private Spinner getSpinner(View header) {
final Spinner spinner = header.findViewById(R.id.filter_spinner);
return spinner;
private Spinner getSpinner(View rootView) {
final FrameLayout pinnedHeader = (FrameLayout) rootView.findViewById(R.id.pinned_header);
if (pinnedHeader == null) {
return null;
}
return pinnedHeader.findViewById(R.id.filter_spinner);
}
}