Add summary text for more top level setting tiles
- Connected devices - App & notifs - Battery Bug: 110405144 Test: robotests Change-Id: Ife44f7c5165483a1bad903ce90a241108ab5da25
This commit is contained in:
@@ -15,40 +15,20 @@
|
||||
*/
|
||||
package com.android.settings.accounts;
|
||||
|
||||
import static com.android.settings.accounts.AccountDashboardFragmentTest
|
||||
.ShadowAuthenticationHelper.LABELS;
|
||||
import static com.android.settings.accounts.AccountDashboardFragmentTest
|
||||
.ShadowAuthenticationHelper.TYPES;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.testutils.Robolectric;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.accounts.AuthenticatorHelper;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class AccountDashboardFragmentTest {
|
||||
|
||||
@@ -59,66 +39,11 @@ public class AccountDashboardFragmentTest {
|
||||
mFragment = new AccountDashboardFragment();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowAuthenticationHelper.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCategory_isAccount() {
|
||||
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_ACCOUNT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
ShadowAuthenticationHelper.class
|
||||
})
|
||||
public void updateSummary_hasAccount_shouldDisplayUpTo3AccountTypes() {
|
||||
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||
final FragmentActivity activity = Robolectric.buildActivity(
|
||||
FragmentActivity.class).setup().get();
|
||||
|
||||
final SummaryLoader.SummaryProvider provider =
|
||||
AccountDashboardFragment.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(activity,
|
||||
loader);
|
||||
provider.setListening(true);
|
||||
|
||||
verify(loader).setSummary(provider, LABELS[0] + ", " + LABELS[1] + ", and " + LABELS[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAuthenticationHelper.class)
|
||||
public void updateSummary_noAccount_shouldDisplayDefaultSummary() {
|
||||
ShadowAuthenticationHelper.setEnabledAccount(null);
|
||||
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||
final FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).setup().get();
|
||||
|
||||
final SummaryLoader.SummaryProvider provider =
|
||||
AccountDashboardFragment.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(activity,
|
||||
loader);
|
||||
provider.setListening(true);
|
||||
|
||||
verify(loader).setSummary(provider,
|
||||
activity.getString(R.string.account_dashboard_default_summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAuthenticationHelper.class)
|
||||
public void updateSummary_noAccountTypeLabel_shouldNotDisplayNullEntry() {
|
||||
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||
final FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).setup().get();
|
||||
final String[] enabledAccounts = {TYPES[0], "unlabeled_account_type", TYPES[1]};
|
||||
ShadowAuthenticationHelper.setEnabledAccount(enabledAccounts);
|
||||
|
||||
final SummaryLoader.SummaryProvider provider =
|
||||
AccountDashboardFragment.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(activity,
|
||||
loader);
|
||||
provider.setListening(true);
|
||||
|
||||
// should only show the 2 accounts with labels
|
||||
verify(loader).setSummary(provider, LABELS[0] + " and " + LABELS[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_shouldIndexResource() {
|
||||
final List<SearchIndexableResource> indexRes =
|
||||
@@ -129,43 +54,5 @@ public class AccountDashboardFragmentTest {
|
||||
assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId());
|
||||
}
|
||||
|
||||
@Implements(AuthenticatorHelper.class)
|
||||
public static class ShadowAuthenticationHelper {
|
||||
|
||||
static final String[] TYPES = {"type1", "type2", "type3", "type4"};
|
||||
static final String[] LABELS = {"LABEL1", "LABEL2", "LABEL3", "LABEL4"};
|
||||
private static String[] sEnabledAccount = TYPES;
|
||||
|
||||
public void __constructor__(Context context, UserHandle userHandle,
|
||||
AuthenticatorHelper.OnAccountsUpdateListener listener) {
|
||||
}
|
||||
|
||||
private static void setEnabledAccount(String[] enabledAccount) {
|
||||
sEnabledAccount = enabledAccount;
|
||||
}
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sEnabledAccount = TYPES;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public String[] getEnabledAccountTypes() {
|
||||
return sEnabledAccount;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public CharSequence getLabelForType(Context context, final String accountType) {
|
||||
if (TextUtils.equals(accountType, TYPES[0])) {
|
||||
return LABELS[0];
|
||||
} else if (TextUtils.equals(accountType, TYPES[1])) {
|
||||
return LABELS[1];
|
||||
} else if (TextUtils.equals(accountType, TYPES[2])) {
|
||||
return LABELS[2];
|
||||
} else if (TextUtils.equals(accountType, TYPES[3])) {
|
||||
return LABELS[3];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accounts;
|
||||
|
||||
import static com.android.settings.accounts.TopLevelAccountEntryPreferenceControllerTest
|
||||
.ShadowAuthenticationHelper.LABELS;
|
||||
import static com.android.settings.accounts.TopLevelAccountEntryPreferenceControllerTest
|
||||
.ShadowAuthenticationHelper.TYPES;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.accounts.AuthenticatorHelper;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {TopLevelAccountEntryPreferenceControllerTest.ShadowAuthenticationHelper.class})
|
||||
public class TopLevelAccountEntryPreferenceControllerTest {
|
||||
|
||||
private TopLevelAccountEntryPreferenceController mController;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new TopLevelAccountEntryPreferenceController(mContext, "test_key");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowAuthenticationHelper.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
public void updateSummary_hasAccount_shouldDisplayUpTo3AccountTypes() {
|
||||
assertThat(mController.getSummary())
|
||||
.isEqualTo(LABELS[0] + ", " + LABELS[1] + ", and " + LABELS[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSummary_noAccount_shouldDisplayDefaultSummary() {
|
||||
ShadowAuthenticationHelper.setEnabledAccount(null);
|
||||
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
mContext.getText(R.string.account_dashboard_default_summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSummary_noAccountTypeLabel_shouldNotDisplayNullEntry() {
|
||||
final String[] enabledAccounts = {TYPES[0], "unlabeled_account_type", TYPES[1]};
|
||||
ShadowAuthenticationHelper.setEnabledAccount(enabledAccounts);
|
||||
|
||||
|
||||
// should only show the 2 accounts with labels
|
||||
assertThat(mController.getSummary()).isEqualTo(LABELS[0] + " and " + LABELS[1]);
|
||||
}
|
||||
|
||||
@Implements(AuthenticatorHelper.class)
|
||||
public static class ShadowAuthenticationHelper {
|
||||
|
||||
static final String[] TYPES = {"type1", "type2", "type3", "type4"};
|
||||
static final String[] LABELS = {"LABEL1", "LABEL2", "LABEL3", "LABEL4"};
|
||||
private static String[] sEnabledAccount = TYPES;
|
||||
|
||||
public void __constructor__(Context context, UserHandle userHandle,
|
||||
AuthenticatorHelper.OnAccountsUpdateListener listener) {
|
||||
}
|
||||
|
||||
private static void setEnabledAccount(String[] enabledAccount) {
|
||||
sEnabledAccount = enabledAccount;
|
||||
}
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sEnabledAccount = TYPES;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public String[] getEnabledAccountTypes() {
|
||||
return sEnabledAccount;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public CharSequence getLabelForType(Context context, final String accountType) {
|
||||
if (TextUtils.equals(accountType, TYPES[0])) {
|
||||
return LABELS[0];
|
||||
} else if (TextUtils.equals(accountType, TYPES[1])) {
|
||||
return LABELS[1];
|
||||
} else if (TextUtils.equals(accountType, TYPES[2])) {
|
||||
return LABELS[2];
|
||||
} else if (TextUtils.equals(accountType, TYPES[3])) {
|
||||
return LABELS[3];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.connecteddevice;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class TopLevelConnectedDevicesPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private TopLevelConnectedDevicesPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new TopLevelConnectedDevicesPreferenceController(mContext, "test_key");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAdvancedConnectedDeviceController.class)
|
||||
public void getSummary_shouldCallAdvancedConnectedDeviceController() {
|
||||
assertThat(mController.getSummary())
|
||||
.isEqualTo(mContext.getText(R.string.settings_label_launcher));
|
||||
}
|
||||
|
||||
@Implements(AdvancedConnectedDeviceController.class)
|
||||
private static class ShadowAdvancedConnectedDeviceController {
|
||||
|
||||
@Implementation
|
||||
public static int getConnectedDevicesSummaryResourceId(Context context) {
|
||||
return R.string.settings_label_launcher;
|
||||
}
|
||||
}
|
||||
}
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.deviceinfo;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -25,14 +24,9 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.usage.StorageStatsManager;
|
||||
import android.content.Intent;
|
||||
import android.icu.text.NumberFormat;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.text.format.Formatter;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
|
||||
|
||||
@@ -41,8 +35,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -65,34 +57,6 @@ public class StorageSettingsTest {
|
||||
when(mStorageManagerVolumeProvider.getVolumes()).thenReturn(mVolumes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSummary_shouldDisplayUsedPercentAndFreeSpace() throws Exception {
|
||||
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||
final SummaryLoader.SummaryProvider provider =
|
||||
StorageSettings.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(mActivity, loader);
|
||||
final VolumeInfo volumeInfo = mVolumes.get(0);
|
||||
when(volumeInfo.isMountedReadable()).thenReturn(true);
|
||||
when(volumeInfo.getType()).thenReturn(VolumeInfo.TYPE_PRIVATE);
|
||||
when(mStorageManagerVolumeProvider
|
||||
.getTotalBytes(nullable(StorageStatsManager.class), nullable(VolumeInfo.class)))
|
||||
.thenReturn(500L);
|
||||
when(mStorageManagerVolumeProvider
|
||||
.getFreeBytes(nullable(StorageStatsManager.class), nullable(VolumeInfo.class)))
|
||||
.thenReturn(0L);
|
||||
|
||||
ReflectionHelpers
|
||||
.setField(provider, "mStorageManagerVolumeProvider", mStorageManagerVolumeProvider);
|
||||
ReflectionHelpers.setField(provider, "mContext", RuntimeEnvironment.application);
|
||||
|
||||
provider.setListening(true);
|
||||
|
||||
final String percentage = NumberFormat.getPercentInstance().format(1);
|
||||
final String freeSpace = Formatter.formatFileSize(RuntimeEnvironment.application, 0);
|
||||
verify(loader).setSummary(provider,
|
||||
RuntimeEnvironment.application.getString(
|
||||
R.string.storage_summary, percentage, freeSpace));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePublicVolumeClick_startsANonNullActivityWhenVolumeHasNoBrowse() {
|
||||
VolumeInfo volumeInfo = mock(VolumeInfo.class, RETURNS_DEEP_STUBS);
|
||||
|
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.deviceinfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.usage.StorageStatsManager;
|
||||
import android.content.Context;
|
||||
import android.icu.text.NumberFormat;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.text.format.Formatter;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class TopLevelStoragePreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private StorageManagerVolumeProvider mStorageManagerVolumeProvider;
|
||||
|
||||
private Context mContext;
|
||||
private TopLevelStoragePreferenceController mController;
|
||||
private List<VolumeInfo> mVolumes;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mVolumes = new ArrayList<>();
|
||||
mVolumes.add(mock(VolumeInfo.class, RETURNS_DEEP_STUBS));
|
||||
when(mStorageManagerVolumeProvider.getVolumes()).thenReturn(mVolumes);
|
||||
|
||||
mController = new TopLevelStoragePreferenceController(mContext, "test_key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSummary_shouldDisplayUsedPercentAndFreeSpace() throws Exception {
|
||||
final VolumeInfo volumeInfo = mVolumes.get(0);
|
||||
when(volumeInfo.isMountedReadable()).thenReturn(true);
|
||||
when(volumeInfo.getType()).thenReturn(VolumeInfo.TYPE_PRIVATE);
|
||||
when(mStorageManagerVolumeProvider
|
||||
.getTotalBytes(nullable(StorageStatsManager.class), nullable(VolumeInfo.class)))
|
||||
.thenReturn(500L);
|
||||
when(mStorageManagerVolumeProvider
|
||||
.getFreeBytes(nullable(StorageStatsManager.class), nullable(VolumeInfo.class)))
|
||||
.thenReturn(0L);
|
||||
|
||||
ReflectionHelpers.setField(mController,
|
||||
"mStorageManagerVolumeProvider", mStorageManagerVolumeProvider);
|
||||
|
||||
final String percentage = NumberFormat.getPercentInstance().format(1);
|
||||
final String freeSpace = Formatter.formatFileSize(RuntimeEnvironment.application, 0);
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
RuntimeEnvironment.application.getString(
|
||||
R.string.storage_summary, percentage, freeSpace));
|
||||
}
|
||||
}
|
@@ -16,7 +16,9 @@
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_ADVANCED_BATTERY;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
@@ -40,6 +42,8 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.loader.app.LoaderManager;
|
||||
|
||||
import com.android.internal.os.BatterySipper;
|
||||
import com.android.internal.os.BatteryStatsHelper;
|
||||
import com.android.settings.R;
|
||||
@@ -50,7 +54,6 @@ import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -69,8 +72,6 @@ import org.robolectric.annotation.Config;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.loader.app.LoaderManager;
|
||||
|
||||
// TODO: Improve this test class so that it starts up the real activity and fragment.
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
@@ -343,18 +344,6 @@ public class PowerUsageSummaryTest {
|
||||
verify(mFragment).restartBatteryTipLoader();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDashboardLabel_returnsCorrectLabel() {
|
||||
BatteryInfo info = new BatteryInfo();
|
||||
info.batteryPercentString = "3%";
|
||||
assertThat(PowerUsageSummary.getDashboardLabel(mRealContext, info))
|
||||
.isEqualTo(info.batteryPercentString);
|
||||
|
||||
info.remainingLabel = "Phone will shut down soon";
|
||||
assertThat(PowerUsageSummary.getDashboardLabel(mRealContext, info))
|
||||
.isEqualTo("3% - Phone will shut down soon");
|
||||
}
|
||||
|
||||
public static class TestFragment extends PowerUsageSummary {
|
||||
private Context mContext;
|
||||
|
||||
|
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.android.settings.fuelgauge.TopLevelBatteryPreferenceController.getDashboardLabel;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class TopLevelBatteryPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDashboardLabel_returnsCorrectLabel() {
|
||||
BatteryInfo info = new BatteryInfo();
|
||||
info.batteryPercentString = "3%";
|
||||
assertThat(getDashboardLabel(mContext, info))
|
||||
.isEqualTo(info.batteryPercentString);
|
||||
|
||||
info.remainingLabel = "Phone will shut down soon";
|
||||
assertThat(getDashboardLabel(mContext, info))
|
||||
.isEqualTo("3% - Phone will shut down soon");
|
||||
}
|
||||
}
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.security;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -26,7 +25,6 @@ import android.hardware.face.FaceManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -37,17 +35,15 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class SecuritySettingsTest {
|
||||
public class TopLevelSecurityPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private SummaryLoader mSummaryLoader;
|
||||
@Mock
|
||||
private FingerprintManager mFingerprintManager;
|
||||
@Mock
|
||||
private FaceManager mFaceManager;
|
||||
private SecuritySettings.SummaryProvider mSummaryProvider;
|
||||
private TopLevelSecurityEntryPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -56,87 +52,80 @@ public class SecuritySettingsTest {
|
||||
.thenReturn(mFingerprintManager);
|
||||
when(mContext.getSystemService(Context.FACE_SERVICE))
|
||||
.thenReturn(mFaceManager);
|
||||
mSummaryProvider = new SecuritySettings.SummaryProvider(mContext, mSummaryLoader);
|
||||
mController = new TopLevelSecurityEntryPreferenceController(mContext, "test_key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_notListening() {
|
||||
mSummaryProvider.setListening(false);
|
||||
|
||||
verifyNoMoreInteractions(mSummaryLoader);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_hasFace_hasStaticSummary() {
|
||||
public void geSummary_hasFace_hasStaticSummary() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE))
|
||||
.thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
mController.getSummary();
|
||||
|
||||
verify(mContext).getString(R.string.security_dashboard_summary_face);
|
||||
verify(mContext).getText(R.string.security_dashboard_summary_face);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_hasFingerPrint_hasStaticSummary() {
|
||||
public void geSummary_hasFingerPrint_hasStaticSummary() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE))
|
||||
.thenReturn(false);
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
mController.getSummary();
|
||||
|
||||
verify(mContext).getString(R.string.security_dashboard_summary);
|
||||
verify(mContext).getText(R.string.security_dashboard_summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_noFpFeature_shouldSetSummaryWithNoBiometrics() {
|
||||
public void geSummary_noFpFeature_shouldSetSummaryWithNoBiometrics() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(false);
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE))
|
||||
.thenReturn(false);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
mController.getSummary();
|
||||
|
||||
verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
|
||||
verify(mContext).getText(R.string.security_dashboard_summary_no_fingerprint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_noFpHardware_shouldSetSummaryWithNoBiometrics() {
|
||||
public void geSummary_noFpHardware_shouldSetSummaryWithNoBiometrics() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE))
|
||||
.thenReturn(false);
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
mController.getSummary();
|
||||
|
||||
verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
|
||||
verify(mContext).getText(R.string.security_dashboard_summary_no_fingerprint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_noFaceFeature_shouldSetSummaryWithNoBiometrics() {
|
||||
public void geSummary_noFaceFeature_shouldSetSummaryWithNoBiometrics() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(false);
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE))
|
||||
.thenReturn(false);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
mController.getSummary();
|
||||
|
||||
verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
|
||||
verify(mContext).getText(R.string.security_dashboard_summary_no_fingerprint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_noFaceHardware_shouldSetSummaryWithNoBiometrics() {
|
||||
public void geSummary_noFaceHardware_shouldSetSummaryWithNoBiometrics() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE))
|
||||
.thenReturn(true);
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
mController.getSummary();
|
||||
|
||||
verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
|
||||
verify(mContext).getText(R.string.security_dashboard_summary_no_fingerprint);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user