Update battery tips cards test.
Test: manual Bug: 291689623 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:71c4b617ccbf15200816b59d037991bcb1f4adcd) Change-Id: Ifd429e10b09fb2e740b644131c6fdedce574aaa5
This commit is contained in:
@@ -36,11 +36,12 @@ public class BatteryTipsController extends BasePreferenceController {
|
|||||||
private static final String ROOT_PREFERENCE_KEY = "battery_tips_category";
|
private static final String ROOT_PREFERENCE_KEY = "battery_tips_category";
|
||||||
private static final String CARD_PREFERENCE_KEY = "battery_tips_card";
|
private static final String CARD_PREFERENCE_KEY = "battery_tips_card";
|
||||||
|
|
||||||
private final PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
|
||||||
private final String[] mPowerAnomalyKeys;
|
private final String[] mPowerAnomalyKeys;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
BatteryTipsCardPreference mCardPreference;
|
BatteryTipsCardPreference mCardPreference;
|
||||||
|
@VisibleForTesting
|
||||||
|
PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
||||||
|
|
||||||
public BatteryTipsController(Context context) {
|
public BatteryTipsController(Context context) {
|
||||||
super(context, ROOT_PREFERENCE_KEY);
|
super(context, ROOT_PREFERENCE_KEY);
|
||||||
|
@@ -19,20 +19,14 @@ package com.android.settings.fuelgauge.batteryusage;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.testutils.BatteryTestUtils;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
@@ -42,8 +36,6 @@ public final class BatteryTipsCardPreferenceTest {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BatteryTipsCardPreference mBatteryTipsCardPreference;
|
private BatteryTipsCardPreference mBatteryTipsCardPreference;
|
||||||
private BatteryTipsController mBatteryTipsController;
|
private BatteryTipsController mBatteryTipsController;
|
||||||
@Mock
|
|
||||||
private View mMockButton;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -51,7 +43,6 @@ public final class BatteryTipsCardPreferenceTest {
|
|||||||
mBatteryTipsCardPreference = new BatteryTipsCardPreference(mContext, /*attrs=*/ null);
|
mBatteryTipsCardPreference = new BatteryTipsCardPreference(mContext, /*attrs=*/ null);
|
||||||
mBatteryTipsController = new BatteryTipsController(mContext);
|
mBatteryTipsController = new BatteryTipsController(mContext);
|
||||||
mBatteryTipsController.mCardPreference = mBatteryTipsCardPreference;
|
mBatteryTipsController.mCardPreference = mBatteryTipsCardPreference;
|
||||||
mMockButton.setId(R.id.action_button);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -59,16 +50,4 @@ public final class BatteryTipsCardPreferenceTest {
|
|||||||
assertThat(mBatteryTipsCardPreference.getLayoutResource()).isEqualTo(
|
assertThat(mBatteryTipsCardPreference.getLayoutResource()).isEqualTo(
|
||||||
R.layout.battery_tips_card);
|
R.layout.battery_tips_card);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onClick_actionBtn_getAdaptiveBrightnessLauncher() {
|
|
||||||
final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
|
|
||||||
PowerAnomalyEvent adaptiveBrightnessAnomaly =
|
|
||||||
BatteryTestUtils.createAdaptiveBrightnessAnomalyEvent();
|
|
||||||
|
|
||||||
mBatteryTipsController.handleBatteryTipsCardUpdated(adaptiveBrightnessAnomaly);
|
|
||||||
mBatteryTipsCardPreference.onClick(mMockButton);
|
|
||||||
|
|
||||||
verify(mContext).startActivity(captor.capture());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -21,11 +21,13 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.LocaleList;
|
import android.os.LocaleList;
|
||||||
|
|
||||||
|
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||||
import com.android.settings.testutils.BatteryTestUtils;
|
import com.android.settings.testutils.BatteryTestUtils;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -48,6 +50,9 @@ public final class BatteryTipsControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private BatteryTipsCardPreference mBatteryTipsCardPreference;
|
private BatteryTipsCardPreference mBatteryTipsCardPreference;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
@@ -60,6 +65,7 @@ public final class BatteryTipsControllerTest {
|
|||||||
doReturn(resources).when(mContext).getResources();
|
doReturn(resources).when(mContext).getResources();
|
||||||
mBatteryTipsController = new BatteryTipsController(mContext);
|
mBatteryTipsController = new BatteryTipsController(mContext);
|
||||||
mBatteryTipsController.mCardPreference = mBatteryTipsCardPreference;
|
mBatteryTipsController.mCardPreference = mBatteryTipsCardPreference;
|
||||||
|
mBatteryTipsController.mPowerUsageFeatureProvider = mPowerUsageFeatureProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -87,16 +93,15 @@ public final class BatteryTipsControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void handleBatteryTipsCardUpdated_adaptiveBrightnessAnomaly_showAnomaly() {
|
public void handleBatteryTipsCardUpdated_adaptiveBrightnessAnomaly_showAnomaly() {
|
||||||
PowerAnomalyEvent event = BatteryTestUtils.createAdaptiveBrightnessAnomalyEvent();
|
PowerAnomalyEvent event = BatteryTestUtils.createAdaptiveBrightnessAnomalyEvent();
|
||||||
|
when(mPowerUsageFeatureProvider.isBatteryTipsEnabled()).thenReturn(true);
|
||||||
|
|
||||||
mBatteryTipsController.handleBatteryTipsCardUpdated(event);
|
mBatteryTipsController.handleBatteryTipsCardUpdated(event);
|
||||||
|
|
||||||
// Check pre-defined string
|
// Check pre-defined string
|
||||||
verify(mBatteryTipsCardPreference).setTitle(
|
verify(mBatteryTipsCardPreference).setTitle(
|
||||||
"Turn on adaptive brightness to extend battery life");
|
"Turn on adaptive brightness to extend battery life");
|
||||||
verify(mBatteryTipsCardPreference).setMainButtonLabel(
|
verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings");
|
||||||
"View Settings");
|
verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
|
||||||
verify(mBatteryTipsCardPreference).setDismissButtonLabel(
|
|
||||||
"Got it");
|
|
||||||
// Check proto info
|
// Check proto info
|
||||||
verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
|
verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
|
||||||
"com.android.settings.display.AutoBrightnessSettings",
|
"com.android.settings.display.AutoBrightnessSettings",
|
||||||
@@ -107,15 +112,13 @@ public final class BatteryTipsControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void handleBatteryTipsCardUpdated_screenTimeoutAnomaly_showAnomaly() {
|
public void handleBatteryTipsCardUpdated_screenTimeoutAnomaly_showAnomaly() {
|
||||||
PowerAnomalyEvent event = BatteryTestUtils.createScreenTimeoutAnomalyEvent();
|
PowerAnomalyEvent event = BatteryTestUtils.createScreenTimeoutAnomalyEvent();
|
||||||
|
when(mPowerUsageFeatureProvider.isBatteryTipsEnabled()).thenReturn(true);
|
||||||
|
|
||||||
mBatteryTipsController.handleBatteryTipsCardUpdated(event);
|
mBatteryTipsController.handleBatteryTipsCardUpdated(event);
|
||||||
|
|
||||||
verify(mBatteryTipsCardPreference).setTitle(
|
verify(mBatteryTipsCardPreference).setTitle("Reduce screen timeout to extend battery life");
|
||||||
"Reduce screen timeout to extend battery life");
|
verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings");
|
||||||
verify(mBatteryTipsCardPreference).setMainButtonLabel(
|
verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
|
||||||
"View Settings");
|
|
||||||
verify(mBatteryTipsCardPreference).setDismissButtonLabel(
|
|
||||||
"Got it");
|
|
||||||
verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
|
verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
|
||||||
"com.android.settings.display.ScreenTimeoutSettings",
|
"com.android.settings.display.ScreenTimeoutSettings",
|
||||||
1852);
|
1852);
|
||||||
@@ -131,15 +134,13 @@ public final class BatteryTipsControllerTest {
|
|||||||
.setTitleString(testTitle)
|
.setTitleString(testTitle)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
when(mPowerUsageFeatureProvider.isBatteryTipsEnabled()).thenReturn(true);
|
||||||
|
|
||||||
mBatteryTipsController.handleBatteryTipsCardUpdated(event);
|
mBatteryTipsController.handleBatteryTipsCardUpdated(event);
|
||||||
|
|
||||||
verify(mBatteryTipsCardPreference).setTitle(
|
verify(mBatteryTipsCardPreference).setTitle(testTitle);
|
||||||
testTitle);
|
verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings");
|
||||||
verify(mBatteryTipsCardPreference).setMainButtonLabel(
|
verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
|
||||||
"View Settings");
|
|
||||||
verify(mBatteryTipsCardPreference).setDismissButtonLabel(
|
|
||||||
"Got it");
|
|
||||||
verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
|
verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
|
||||||
"com.android.settings.display.ScreenTimeoutSettings",
|
"com.android.settings.display.ScreenTimeoutSettings",
|
||||||
1852);
|
1852);
|
||||||
|
Reference in New Issue
Block a user