}
};
- private ChartDataUsagePreference mChart;
- private TelephonyManager mTelephonyManager;
-
@VisibleForTesting
NetworkTemplate mTemplate;
@VisibleForTesting
int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
@VisibleForTesting
int mNetworkType;
+ @VisibleForTesting
+ Spinner mCycleSpinner;
+ @VisibleForTesting
+ LoadingViewController mLoadingViewController;
+
+ private ChartDataUsagePreference mChart;
+ private TelephonyManager mTelephonyManager;
private List<NetworkCycleChartData> mCycleData;
private ArrayList<Long> mCycles;
-
- private LoadingViewController mLoadingViewController;
private UidDetailProvider mUidDetailProvider;
private CycleAdapter mCycleAdapter;
- private Spinner mCycleSpinner;
private Preference mUsageAmount;
private PreferenceGroup mApps;
private View mHeader;
.launch();
});
mCycleSpinner = mHeader.findViewById(R.id.filter_spinner);
+ mCycleSpinner.setVisibility(View.GONE);
mCycleAdapter = new CycleAdapter(mCycleSpinner.getContext(), new SpinnerInterface() {
@Override
public void setAdapter(CycleAdapter cycleAdapter) {
* Update chart sweeps and cycle list to reflect {@link NetworkPolicy} for
* current {@link #mTemplate}.
*/
- private void updatePolicy() {
+ @VisibleForTesting
+ void updatePolicy() {
final NetworkPolicy policy = services.mPolicyEditor.getPolicy(mTemplate);
final View configureButton = mHeader.findViewById(R.id.filter_settings);
//SUB SELECT
}
};
- private final LoaderCallbacks<List<NetworkCycleChartData>> mNetworkCycleDataCallbacks =
+ @VisibleForTesting
+ final LoaderCallbacks<List<NetworkCycleChartData>> mNetworkCycleDataCallbacks =
new LoaderCallbacks<List<NetworkCycleChartData>>() {
@Override
public Loader<List<NetworkCycleChartData>> onCreateLoader(int id, Bundle args) {
mCycleData = data;
// calculate policy cycles based on available data
updatePolicy();
+ mCycleSpinner.setVisibility(View.VISIBLE);
}
@Override
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import android.content.Context;
+import android.app.Activity;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkTemplate;
import android.os.Bundle;
import android.provider.Settings;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.FrameLayout;
import android.widget.Spinner;
+import androidx.fragment.app.FragmentActivity;
+import androidx.preference.PreferenceManager;
+
+import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.widget.LoadingViewController;
import com.android.settingslib.AppItem;
import com.android.settingslib.NetworkPolicyEditor;
import com.android.settingslib.core.instrumentation.VisibilityLoggerMixin;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.android.controller.ActivityController;
import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
import java.util.List;
-import androidx.fragment.app.FragmentActivity;
-import androidx.preference.PreferenceManager;
-
@RunWith(RobolectricTestRunner.class)
public class DataUsageListTest {
private CellDataPreference.DataStateListener mListener;
@Mock
private TemplatePreference.NetworkServices mNetworkServices;
- @Mock
- private Context mContext;
+
+ private Activity mActivity;
private DataUsageList mDataUsageList;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest();
+ final ActivityController<Activity> mActivityController =
+ Robolectric.buildActivity(Activity.class);
+ mActivity = spy(mActivityController.get());
mNetworkServices.mPolicyEditor = mock(NetworkPolicyEditor.class);
mDataUsageList = spy(DataUsageList.class);
- doReturn(mContext).when(mDataUsageList).getContext();
+ doReturn(mActivity).when(mDataUsageList).getContext();
ReflectionHelpers.setField(mDataUsageList, "mDataStateListener", mListener);
ReflectionHelpers.setField(mDataUsageList, "services", mNetworkServices);
}
mDataUsageList.onResume();
- verify(mListener).setListener(true, mDataUsageList.mSubId, mContext);
+ verify(mListener).setListener(true, mDataUsageList.mSubId, mActivity);
mDataUsageList.onPause();
- verify(mListener).setListener(false, mDataUsageList.mSubId, mContext);
+ verify(mListener).setListener(false, mDataUsageList.mSubId, mActivity);
}
@Test
final List<NetworkCycleChartData> data = new ArrayList<>();
final NetworkCycleChartData.Builder builder = new NetworkCycleChartData.Builder();
builder.setStartTime(startTime)
- .setEndTime(endTime);
+ .setEndTime(endTime);
data.add(builder.build());
ReflectionHelpers.setField(mDataUsageList, "mCycleData", data);
final Spinner spinner = mock(Spinner.class);
mDataUsageList.startAppDataUsage(new AppItem());
- verify(mContext).startActivity(intent.capture());
+ verify(mActivity).startActivity(intent.capture());
final Bundle arguments =
- intent.getValue().getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
+ intent.getValue().getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
assertThat(arguments.getLong(AppDataUsage.ARG_SELECTED_CYCLE)).isEqualTo(endTime);
final ArrayList<Long> cycles =
- (ArrayList) arguments.getSerializable(AppDataUsage.ARG_NETWORK_CYCLES);
+ (ArrayList) arguments.getSerializable(AppDataUsage.ARG_NETWORK_CYCLES);
assertThat(cycles).hasSize(2);
assertThat(cycles.get(0)).isEqualTo(endTime);
assertThat(cycles.get(1)).isEqualTo(startTime);
}
+
+ @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();
+
+ mDataUsageList.onViewCreated(view, null);
+
+ assertThat(spinner.getVisibility()).isEqualTo(View.GONE);
+ }
+
+ @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);
+ doNothing().when(mDataUsageList).updatePolicy();
+
+ mDataUsageList.mNetworkCycleDataCallbacks.onLoadFinished(null, null);
+
+ assertThat(spinner.getVisibility()).isEqualTo(View.VISIBLE);
+ }
+
+ private View getHeader() {
+ final 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 header;
+ }
+
+ private Spinner getSpinner(View header) {
+ final Spinner spinner = header.findViewById(R.id.filter_spinner);
+ return spinner;
+ }
}