Fix broken RoboTests in "com.android.settings.fuelgauge.*"
Bug: 305125530 Test: make RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.fuelgauge.*" Change-Id: Idaf2a5da4aef3a2fe317fc1f5a24ba9ba457cadd
This commit is contained in:
@@ -30,7 +30,6 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.shadows.ShadowLooper.shadowMainLooper;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.backup.BackupManager;
|
||||
@@ -42,7 +41,6 @@ import android.content.pm.InstallSourceInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
@@ -77,6 +75,8 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
ShadowEntityHeaderController.class,
|
||||
@@ -88,7 +88,6 @@ public class AdvancedPowerUsageDetailTest {
|
||||
private static final String SUMMARY = "summary";
|
||||
private static final String[] PACKAGE_NAME = {"com.android.app"};
|
||||
private static final String USAGE_PERCENT = "16%";
|
||||
private static final String SLOT_TIME = "12 am-2 am";
|
||||
private static final int ICON_ID = 123;
|
||||
private static final int UID = 1;
|
||||
private static final long BACKGROUND_TIME_MS = 100;
|
||||
@@ -96,7 +95,6 @@ public class AdvancedPowerUsageDetailTest {
|
||||
private static final long FOREGROUND_SERVICE_TIME_MS = 444;
|
||||
private static final long FOREGROUND_TIME_MS =
|
||||
FOREGROUND_ACTIVITY_TIME_MS + FOREGROUND_SERVICE_TIME_MS;
|
||||
private static final long FOREGROUND_SERVICE_TIME_US = FOREGROUND_SERVICE_TIME_MS * 1000;
|
||||
private static final String KEY_PREF_UNRESTRICTED = "unrestricted_pref";
|
||||
private static final String KEY_PREF_OPTIMIZED = "optimized_pref";
|
||||
private static final String KEY_PREF_RESTRICTED = "restricted_pref";
|
||||
@@ -263,405 +261,6 @@ public class AdvancedPowerUsageDetailTest {
|
||||
verify(mEntityHeaderController).setIsInstantApp(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_noAnyTimeNoConsumedPower_hasEmptySummary() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, /* value */ 0);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, /* value */ 0);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, /* value */ 0);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_noAnyTimeButConsumedPower_hasEmptySummary() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, /* value */ 0);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, /* value */ 0);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, /* value */ 0);
|
||||
bundle.putInt(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_AMOUNT, /* value */ 10);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeZerobackgroundTwoMin_hasCorrectSummary() {
|
||||
final long backgroundTimeTwoMinutes = 120000;
|
||||
final long foregroundTimeZero = 0;
|
||||
final long screenOnTimeZero = 0;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeZero);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeZero);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString())
|
||||
.isEqualTo("Background: 2 min\n(since last full charge)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeZerobackgroundLessThanAMin_hasCorrectSummary() {
|
||||
final long backgroundTimeLessThanAMinute = 59999;
|
||||
final long foregroundTimeZero = 0;
|
||||
final long screenOnTimeZero = 0;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(
|
||||
AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanAMinute);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeZero);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeZero);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString())
|
||||
.isEqualTo("Background: less than a min\n(since last full charge)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeAMinuteBackgroundTwoMin_hasCorrectSummary() {
|
||||
final long backgroundTimeTwoMinutes = 120000;
|
||||
final long foregroundTimeTwoMinutes = 120000;
|
||||
final long screenOnTimeAMinute = 60000;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeAMinute);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEqualTo(
|
||||
"Screen time: 1 min\nBackground: 2 min\n(since last full charge)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeAMinuteBackgroundLessThanAMin_hasCorrectSummary() {
|
||||
final long backgroundTimeLessThanAMinute = 59999;
|
||||
final long foregroundTimeTwoMinutes = 120000;
|
||||
final long screenOnTimeAMinute = 60000;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(
|
||||
AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanAMinute);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeAMinute);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEqualTo(
|
||||
"Screen time: 1 min\nBackground: less than a min\n(since last full charge)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeAMinuteBackgroundZero_hasCorrectSummary() {
|
||||
final long backgroundTimezero = 0;
|
||||
final long foregroundTimeTwoMinutes = 120000;
|
||||
final long screenOnTimeAMinute = 60000;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimezero);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeAMinute);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEqualTo(
|
||||
"Screen time: 1 min\n(since last full charge)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeLessThanAMinBackgroundTwoMin_hasCorrectSummary() {
|
||||
final long backgroundTimeTwoMinutes = 120000;
|
||||
final long foregroundTimeTwoMinutes = 120000;
|
||||
final long screenOnTimeLessThanAMinute = 59999;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeLessThanAMinute);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEqualTo(
|
||||
"Screen time: less than a min\nBackground: 2 min\n(since last full charge)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeLessThanAMinBackgroundLessThanAMin_hasCorrectSummary() {
|
||||
final long backgroundTimeLessThanAMinute = 59999;
|
||||
final long foregroundTimeTwoMinutes = 120000;
|
||||
final long screenOnTimeLessThanAMinute = 59999;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(
|
||||
AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanAMinute);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeLessThanAMinute);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEqualTo(
|
||||
"Screen time: less than a min\nBackground: less than a min\n(since last full "
|
||||
+ "charge)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeLessThanAMinBackgroundZero_hasCorrectSummary() {
|
||||
final long backgroundTimezero = 0;
|
||||
final long foregroundTimeTwoMinutes = 120000;
|
||||
final long screenOnTimeLessThanAMinute = 59999;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimezero);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeLessThanAMinute);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEqualTo(
|
||||
"Screen time: less than a min\n(since last full charge)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_noAnyTimeNoConsumedPowerWithSlotTime_hasEmptySummary() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, /* value */ 0);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, /* value */ 0);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, /* value */ 0);
|
||||
bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_noAnyTimeButConsumedPowerWithSlotTime_hasEmptySummary() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, /* value */ 0);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, /* value */ 0);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, /* value */ 0);
|
||||
bundle.putInt(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_AMOUNT, /* value */ 10);
|
||||
bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeZerobackgroundTwoMinWithSlotTime_hasCorrectSummary() {
|
||||
final long backgroundTimeTwoMinutes = 120000;
|
||||
final long foregroundTimeZero = 0;
|
||||
final long screenOnTimeZero = 0;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeZero);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeZero);
|
||||
bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString())
|
||||
.isEqualTo("Background: 2 min\n(12 am-2 am)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeZerobackgroundLessThanAMinWithSlotTime_hasCorrectSummary() {
|
||||
final long backgroundTimeLessThanAMinute = 59999;
|
||||
final long foregroundTimeZero = 0;
|
||||
final long screenOnTimeZero = 0;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(
|
||||
AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanAMinute);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeZero);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeZero);
|
||||
bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString())
|
||||
.isEqualTo("Background: less than a min\n(12 am-2 am)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeAMinuteBackgroundTwoMinWithSlotTime_hasCorrectSummary() {
|
||||
final long backgroundTimeTwoMinutes = 120000;
|
||||
final long foregroundTimeTwoMinutes = 120000;
|
||||
final long screenOnTimeAMinute = 60000;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeAMinute);
|
||||
bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEqualTo(
|
||||
"Screen time: 1 min\nBackground: 2 min\n(12 am-2 am)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeAMinuteBackgroundLessThanAMinWithSlotTime_hasCorrectSummary() {
|
||||
final long backgroundTimeLessThanAMinute = 59999;
|
||||
final long foregroundTimeTwoMinutes = 120000;
|
||||
final long screenOnTimeAMinute = 60000;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(
|
||||
AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanAMinute);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeAMinute);
|
||||
bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEqualTo(
|
||||
"Screen time: 1 min\nBackground: less than a min\n(12 am-2 am)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeAMinuteBackgroundZeroWithSlotTime_hasCorrectSummary() {
|
||||
final long backgroundTimezero = 0;
|
||||
final long foregroundTimeTwoMinutes = 120000;
|
||||
final long screenOnTimeAMinute = 60000;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimezero);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeAMinute);
|
||||
bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEqualTo(
|
||||
"Screen time: 1 min\n(12 am-2 am)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeLessThanAMinBackgroundTwoMinWithSlotTime_hasCorrectSummary() {
|
||||
final long backgroundTimeTwoMinutes = 120000;
|
||||
final long foregroundTimeTwoMinutes = 120000;
|
||||
final long screenOnTimeLessThanAMinute = 59999;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeLessThanAMinute);
|
||||
bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEqualTo(
|
||||
"Screen time: less than a min\nBackground: 2 min\n(12 am-2 am)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeLessAMinBackgroundLessAMinWithSlotTime_hasCorrectSummary() {
|
||||
final long backgroundTimeLessThanAMinute = 59999;
|
||||
final long foregroundTimeTwoMinutes = 120000;
|
||||
final long screenOnTimeLessThanAMinute = 59999;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(
|
||||
AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanAMinute);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeLessThanAMinute);
|
||||
bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEqualTo(
|
||||
"Screen time: less than a min\nBackground: less than a min\n(12 am-2 am)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_ScreenTimeLessThanAMinBackgroundZeroWithSlotTime_hasCorrectSummary() {
|
||||
final long backgroundTimezero = 0;
|
||||
final long foregroundTimeTwoMinutes = 120000;
|
||||
final long screenOnTimeLessThanAMinute = 59999;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimezero);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeLessThanAMinute);
|
||||
bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEqualTo(
|
||||
"Screen time: less than a min\n(12 am-2 am)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initHeader_systemUidWithChartIsEnabled_notNullSummary() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, 240000);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, 120000);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, 120000);
|
||||
bundle.putInt(AdvancedPowerUsageDetail.EXTRA_UID, Process.SYSTEM_UID);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startBatteryDetailPage_invalidToShowSummary_noFGBDData() {
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(mActivity, mFragment,
|
||||
@@ -767,7 +366,7 @@ public class AdvancedPowerUsageDetailTest {
|
||||
mFragment.onRadioButtonClicked(mOptimizePreference);
|
||||
mFragment.onPause();
|
||||
|
||||
shadowMainLooper().idle();
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
verify(mMetricsFeatureProvider)
|
||||
.action(
|
||||
SettingsEnums.OPEN_APP_BATTERY_USAGE,
|
||||
@@ -791,7 +390,7 @@ public class AdvancedPowerUsageDetailTest {
|
||||
mFragment.onRadioButtonClicked(mOptimizePreference);
|
||||
mFragment.onPause();
|
||||
|
||||
shadowMainLooper().idle();
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
verifyNoInteractions(mMetricsFeatureProvider);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user