Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d7348251 authored by mxyyiyi's avatar mxyyiyi Committed by Xinyi Mao
Browse files

Update battery tips cards test.

Test: manual
Bug: 291689623
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:71c4b617ccbf15200816b59d037991bcb1f4adcd)
Change-Id: Ifd429e10b09fb2e740b644131c6fdedce574aaa5
parent d4074dab
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -36,11 +36,12 @@ public class BatteryTipsController extends BasePreferenceController {
    private static final String ROOT_PREFERENCE_KEY = "battery_tips_category";
    private static final String CARD_PREFERENCE_KEY = "battery_tips_card";

    private final PowerUsageFeatureProvider mPowerUsageFeatureProvider;
    private final String[] mPowerAnomalyKeys;

    @VisibleForTesting
    BatteryTipsCardPreference mCardPreference;
    @VisibleForTesting
    PowerUsageFeatureProvider mPowerUsageFeatureProvider;

    public BatteryTipsController(Context context) {
        super(context, ROOT_PREFERENCE_KEY);
+0 −21
Original line number Diff line number Diff line
@@ -19,20 +19,14 @@ package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.android.settings.R;
import com.android.settings.testutils.BatteryTestUtils;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

@@ -42,8 +36,6 @@ public final class BatteryTipsCardPreferenceTest {
    private Context mContext;
    private BatteryTipsCardPreference mBatteryTipsCardPreference;
    private BatteryTipsController mBatteryTipsController;
    @Mock
    private View mMockButton;

    @Before
    public void setUp() {
@@ -51,7 +43,6 @@ public final class BatteryTipsCardPreferenceTest {
        mBatteryTipsCardPreference = new BatteryTipsCardPreference(mContext, /*attrs=*/ null);
        mBatteryTipsController = new BatteryTipsController(mContext);
        mBatteryTipsController.mCardPreference = mBatteryTipsCardPreference;
        mMockButton.setId(R.id.action_button);
    }

    @Test
@@ -59,16 +50,4 @@ public final class BatteryTipsCardPreferenceTest {
        assertThat(mBatteryTipsCardPreference.getLayoutResource()).isEqualTo(
                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());
    }
}
+17 −16
Original line number Diff line number Diff line
@@ -21,11 +21,13 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.res.Resources;
import android.os.LocaleList;

import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.testutils.BatteryTestUtils;

import org.junit.Before;
@@ -48,6 +50,9 @@ public final class BatteryTipsControllerTest {
    @Mock
    private BatteryTipsCardPreference mBatteryTipsCardPreference;

    @Mock
    private PowerUsageFeatureProvider mPowerUsageFeatureProvider;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
@@ -60,6 +65,7 @@ public final class BatteryTipsControllerTest {
        doReturn(resources).when(mContext).getResources();
        mBatteryTipsController = new BatteryTipsController(mContext);
        mBatteryTipsController.mCardPreference = mBatteryTipsCardPreference;
        mBatteryTipsController.mPowerUsageFeatureProvider = mPowerUsageFeatureProvider;
    }

    @Test
@@ -87,16 +93,15 @@ public final class BatteryTipsControllerTest {
    @Test
    public void handleBatteryTipsCardUpdated_adaptiveBrightnessAnomaly_showAnomaly() {
        PowerAnomalyEvent event = BatteryTestUtils.createAdaptiveBrightnessAnomalyEvent();
        when(mPowerUsageFeatureProvider.isBatteryTipsEnabled()).thenReturn(true);

        mBatteryTipsController.handleBatteryTipsCardUpdated(event);

        // Check pre-defined string
        verify(mBatteryTipsCardPreference).setTitle(
                "Turn on adaptive brightness to extend battery life");
        verify(mBatteryTipsCardPreference).setMainButtonLabel(
                "View Settings");
        verify(mBatteryTipsCardPreference).setDismissButtonLabel(
                "Got it");
        verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings");
        verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
        // Check proto info
        verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
                "com.android.settings.display.AutoBrightnessSettings",
@@ -107,15 +112,13 @@ public final class BatteryTipsControllerTest {
    @Test
    public void handleBatteryTipsCardUpdated_screenTimeoutAnomaly_showAnomaly() {
        PowerAnomalyEvent event = BatteryTestUtils.createScreenTimeoutAnomalyEvent();
        when(mPowerUsageFeatureProvider.isBatteryTipsEnabled()).thenReturn(true);

        mBatteryTipsController.handleBatteryTipsCardUpdated(event);

        verify(mBatteryTipsCardPreference).setTitle(
                "Reduce screen timeout to extend battery life");
        verify(mBatteryTipsCardPreference).setMainButtonLabel(
                "View Settings");
        verify(mBatteryTipsCardPreference).setDismissButtonLabel(
                "Got it");
        verify(mBatteryTipsCardPreference).setTitle("Reduce screen timeout to extend battery life");
        verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings");
        verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
        verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
                "com.android.settings.display.ScreenTimeoutSettings",
                1852);
@@ -131,15 +134,13 @@ public final class BatteryTipsControllerTest {
                                .setTitleString(testTitle)
                                .build())
                .build();
        when(mPowerUsageFeatureProvider.isBatteryTipsEnabled()).thenReturn(true);

        mBatteryTipsController.handleBatteryTipsCardUpdated(event);

        verify(mBatteryTipsCardPreference).setTitle(
                testTitle);
        verify(mBatteryTipsCardPreference).setMainButtonLabel(
                "View Settings");
        verify(mBatteryTipsCardPreference).setDismissButtonLabel(
                "Got it");
        verify(mBatteryTipsCardPreference).setTitle(testTitle);
        verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings");
        verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
        verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
                "com.android.settings.display.ScreenTimeoutSettings",
                1852);