Display app stats for location permission

Bug: 120221631
Test: manually
Change-Id: I53f43079807759c50eeb62029bb0d8d1f84e1118
This commit is contained in:
Lifu Tang
2018-12-11 13:50:34 -08:00
parent 811d95c373
commit 3da8f8d31d
8 changed files with 226 additions and 29 deletions

View File

@@ -5,6 +5,10 @@ import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.Settings;
import androidx.lifecycle.LifecycleOwner;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -21,11 +25,16 @@ public class AppLocationPermissionPreferenceControllerTest {
@Mock
private Context mContext;
private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new AppLocationPermissionPreferenceController(mContext);
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
mController = new AppLocationPermissionPreferenceController(mContext, mLifecycle);
}
@Test

View File

@@ -84,30 +84,31 @@ public class LocationEnablerTest {
}
@Test
public void onResume_shouldSetActiveAndRegisterListener() {
mEnabler.onResume();
public void onStart_shouldSetActiveAndRegisterListener() {
mEnabler.onStart();
verify(mContext).registerReceiver(eq(mEnabler.mReceiver),
eq(LocationEnabler.INTENT_FILTER_LOCATION_MODE_CHANGED));
}
@Test
public void onResume_shouldRefreshLocationMode() {
mEnabler.onResume();
public void onStart_shouldRefreshLocationMode() {
mEnabler.onStart();
verify(mEnabler).refreshLocationMode();
}
@Test
public void onPause_shouldUnregisterListener() {
mEnabler.onPause();
public void onStop_shouldUnregisterListener() {
mEnabler.onStart();
mEnabler.onStop();
verify(mContext).unregisterReceiver(mEnabler.mReceiver);
}
@Test
public void onReceive_shouldRefreshLocationMode() {
mEnabler.onResume();
mEnabler.onStart();
reset(mListener);
mEnabler.mReceiver.onReceive(mContext, new Intent());