Merge commit '937ede14d84c2093f831ff8adab96dca207ad742' from
oc-mr1-dev-plus-aosp-without-vendor into stage-aosp-master Change-Id: I91ee596e3800726445cfff5dd784bae9dfdad3ee Merged-In: I91c48c73287a271bd6c99e60e216dead22e68764
This commit is contained in:
@@ -32,9 +32,6 @@ public class OemLockManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canUserAllowOemUnlock() {
|
||||
return true;
|
||||
}
|
||||
public boolean isOemUnlockAllowed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,11 @@ import org.robolectric.annotation.Config;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = ShadowUtils.class
|
||||
)
|
||||
public class DeviceInfoSettingsTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@@ -83,7 +87,6 @@ public class DeviceInfoSettingsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowUtils.class)
|
||||
public void testNonIndexableKeys_existInXmlLayout() {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
final List<String> niks = DeviceInfoSettings.SEARCH_INDEX_DATA_PROVIDER
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.android.settings;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowPowerManagerWrapper;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
@@ -14,10 +17,6 @@ import org.robolectric.annotation.Config;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DisplaySettingsTest {
|
||||
@@ -33,7 +32,7 @@ public class DisplaySettingsTest {
|
||||
fragment.getPreferenceScreenResId());
|
||||
final List<String> preferenceKeys = new ArrayList<>();
|
||||
|
||||
for (PreferenceController controller : fragment.getPreferenceControllers(context)) {
|
||||
for (AbstractPreferenceController controller : fragment.getPreferenceControllers(context)) {
|
||||
preferenceKeys.add(controller.getPreferenceKey());
|
||||
}
|
||||
// Nightmode is currently hidden
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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;
|
||||
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowHelpUtils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowActivity;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
ShadowHelpUtils.class
|
||||
})
|
||||
public class HelpTrampolineTest {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowHelpUtils.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchHelp_noExtra_shouldDoNothing() {
|
||||
final Intent intent = new Intent().setClassName(
|
||||
RuntimeEnvironment.application.getPackageName(), HelpTrampoline.class.getName());
|
||||
|
||||
Robolectric.buildActivity(HelpTrampoline.class).withIntent(intent).create().get();
|
||||
|
||||
assertThat(ShadowHelpUtils.isGetHelpIntentCalled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchHelp_hasExtra_shouldLaunchHelp() {
|
||||
final Intent intent = new Intent().setClassName(
|
||||
RuntimeEnvironment.application.getPackageName(), HelpTrampoline.class.getName())
|
||||
.putExtra(Intent.EXTRA_TEXT, "help_url_upgrading");
|
||||
final ShadowActivity shadow = shadowOf(Robolectric.buildActivity(HelpTrampoline.class)
|
||||
.withIntent(intent).create().get());
|
||||
final Intent launchedIntent = shadow.getNextStartedActivity();
|
||||
|
||||
assertThat(ShadowHelpUtils.isGetHelpIntentCalled()).isTrue();
|
||||
assertThat(launchedIntent).isNotNull();
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,6 @@ import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ScrollView;
|
||||
|
||||
@@ -46,12 +45,15 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowActivity;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {ShadowUtils.class}
|
||||
)
|
||||
public class MasterClearTest {
|
||||
|
||||
@Mock
|
||||
@@ -144,7 +146,6 @@ public class MasterClearTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = { ShadowUtils.class })
|
||||
public void testInitiateMasterClear_inDemoMode_sendsIntent() {
|
||||
ShadowUtils.setIsDemoUser(true);
|
||||
|
||||
|
||||
@@ -60,7 +60,11 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {ShadowLockPatternUtils.class}
|
||||
)
|
||||
public class SecuritySettingsTest {
|
||||
|
||||
private static final String MOCK_SUMMARY = "summary";
|
||||
@@ -181,9 +185,6 @@ public class SecuritySettingsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config (shadows = {
|
||||
ShadowLockPatternUtils.class,
|
||||
})
|
||||
public void testNonIndexableKeys_existInXmlLayout() {
|
||||
final Context context = spy(RuntimeEnvironment.application);
|
||||
UserManager manager = mock(UserManager.class);
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.android.settings.password.ChooseLockPattern.IntentBuilder;
|
||||
import com.android.settings.password.SetupChooseLockPattern;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
|
||||
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
|
||||
@@ -49,7 +48,6 @@ import org.robolectric.res.builder.RobolectricPackageManager.ComponentState;
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class,
|
||||
ShadowDynamicIndexableContentMonitor.class,
|
||||
ShadowEventLogWriter.class,
|
||||
ShadowUtils.class
|
||||
})
|
||||
|
||||
@@ -8,14 +8,17 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.LinkAddress;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.Network;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.os.storage.DiskInfo;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.os.storage.VolumeInfo;
|
||||
@@ -23,6 +26,7 @@ import android.text.SpannableStringBuilder;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.style.TtsSpan;
|
||||
|
||||
import com.android.settings.enterprise.DevicePolicyManagerWrapper;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -34,12 +38,15 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class UtilsTest {
|
||||
|
||||
private static final String TIME_DESCRIPTION = "1 day 20 hours 30 minutes";
|
||||
private static final String PACKAGE_NAME = "com.android.app";
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private WifiManager wifiManager;
|
||||
@@ -47,6 +54,10 @@ public class UtilsTest {
|
||||
private Network network;
|
||||
@Mock
|
||||
private ConnectivityManager connectivityManager;
|
||||
@Mock
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -94,8 +105,8 @@ public class UtilsTest {
|
||||
|
||||
@Test
|
||||
public void testFormatElapsedTime_WithSeconds_ShowSeconds() {
|
||||
final double testMillis = 5 * DateUtils.MINUTE_IN_MILLIS;
|
||||
final String expectedTime = "5m 0s";
|
||||
final double testMillis = 5 * DateUtils.MINUTE_IN_MILLIS + 30 * DateUtils.SECOND_IN_MILLIS;
|
||||
final String expectedTime = "5m 30s";
|
||||
|
||||
assertThat(Utils.formatElapsedTime(mContext, testMillis, true).toString()).isEqualTo(
|
||||
expectedTime);
|
||||
@@ -103,8 +114,8 @@ public class UtilsTest {
|
||||
|
||||
@Test
|
||||
public void testFormatElapsedTime_NoSeconds_DoNotShowSeconds() {
|
||||
final double testMillis = 5 * DateUtils.MINUTE_IN_MILLIS;
|
||||
final String expectedTime = "5m";
|
||||
final double testMillis = 5 * DateUtils.MINUTE_IN_MILLIS + 30 * DateUtils.SECOND_IN_MILLIS;
|
||||
final String expectedTime = "6m";
|
||||
|
||||
assertThat(Utils.formatElapsedTime(mContext, testMillis, false).toString()).isEqualTo(
|
||||
expectedTime);
|
||||
@@ -120,6 +131,33 @@ public class UtilsTest {
|
||||
expectedTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatElapsedTime_ZeroFieldsInTheMiddleDontShow() {
|
||||
final double testMillis = 2 * DateUtils.DAY_IN_MILLIS + 15 * DateUtils.MINUTE_IN_MILLIS;
|
||||
final String expectedTime = "2d 15m";
|
||||
|
||||
assertThat(Utils.formatElapsedTime(mContext, testMillis, false).toString()).isEqualTo(
|
||||
expectedTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatElapsedTime_FormatZero_WithSeconds() {
|
||||
final double testMillis = 0;
|
||||
final String expectedTime = "0s";
|
||||
|
||||
assertThat(Utils.formatElapsedTime(mContext, testMillis, true).toString()).isEqualTo(
|
||||
expectedTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatElapsedTime_FormatZero_NoSeconds() {
|
||||
final double testMillis = 0;
|
||||
final String expectedTime = "0m";
|
||||
|
||||
assertThat(Utils.formatElapsedTime(mContext, testMillis, false).toString()).isEqualTo(
|
||||
expectedTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatElapsedTime_onlyContainsMinute_hasTtsSpan() {
|
||||
final double testMillis = 15 * DateUtils.MINUTE_IN_MILLIS;
|
||||
@@ -167,4 +205,25 @@ public class UtilsTest {
|
||||
|
||||
assertThat(Utils.getInstallationStatus(info)).isEqualTo(R.string.disabled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsProfileOrDeviceOwner_deviceOwnerApp_returnTrue() {
|
||||
when(mDevicePolicyManager.isDeviceOwnerAppOnAnyUser(PACKAGE_NAME)).thenReturn(true);
|
||||
|
||||
assertThat(Utils.isProfileOrDeviceOwner(mUserManager, mDevicePolicyManager,
|
||||
PACKAGE_NAME)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsProfileOrDeviceOwner_profileOwnerApp_returnTrue() {
|
||||
final List<UserInfo> userInfos = new ArrayList<>();
|
||||
userInfos.add(new UserInfo());
|
||||
|
||||
when(mUserManager.getUsers()).thenReturn(userInfos);
|
||||
when(mDevicePolicyManager.getProfileOwnerAsUser(userInfos.get(0).id)).thenReturn(
|
||||
new ComponentName(PACKAGE_NAME, ""));
|
||||
|
||||
assertThat(Utils.isProfileOrDeviceOwner(mUserManager, mDevicePolicyManager,
|
||||
PACKAGE_NAME)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@@ -17,14 +17,21 @@ package com.android.settings.accounts;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.DashboardFeatureProviderImpl;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
@@ -33,12 +40,20 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@@ -48,6 +63,8 @@ public class AccountDetailDashboardFragmentTest {
|
||||
private static final String METADATA_ACCOUNT_TYPE = "com.android.settings.ia.account";
|
||||
private static final String METADATA_USER_HANDLE = "user_handle";
|
||||
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private Activity mActivity;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private AccountManager mAccountManager;
|
||||
@Mock
|
||||
@@ -74,16 +91,16 @@ public class AccountDetailDashboardFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCategory_isAccount() {
|
||||
public void testCategory_isAccountDetail() {
|
||||
assertThat(new AccountDetailDashboardFragment().getCategoryKey())
|
||||
.isEqualTo(CategoryKey.CATEGORY_ACCOUNT);
|
||||
.isEqualTo(CategoryKey.CATEGORY_ACCOUNT_DETAIL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshDashboardTiles_HasAccountType_shouldDisplay() {
|
||||
final Tile tile = new Tile();
|
||||
final Bundle metaData = new Bundle();
|
||||
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
|
||||
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
|
||||
metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
|
||||
tile.metaData = metaData;
|
||||
|
||||
@@ -94,7 +111,7 @@ public class AccountDetailDashboardFragmentTest {
|
||||
public void refreshDashboardTiles_NoAccountType_shouldNotDisplay() {
|
||||
final Tile tile = new Tile();
|
||||
final Bundle metaData = new Bundle();
|
||||
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
|
||||
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
|
||||
tile.metaData = metaData;
|
||||
|
||||
assertThat(mFragment.displayTile(tile)).isFalse();
|
||||
@@ -104,10 +121,46 @@ public class AccountDetailDashboardFragmentTest {
|
||||
public void refreshDashboardTiles_OtherAccountType_shouldNotDisplay() {
|
||||
final Tile tile = new Tile();
|
||||
final Bundle metaData = new Bundle();
|
||||
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
|
||||
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
|
||||
metaData.putString(METADATA_ACCOUNT_TYPE, "com.other");
|
||||
tile.metaData = metaData;
|
||||
|
||||
assertThat(mFragment.displayTile(tile)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent() {
|
||||
FakeFeatureFactory.setupForTest(mActivity);
|
||||
final FakeFeatureFactory featureFactory =
|
||||
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
|
||||
final DashboardFeatureProviderImpl dashboardFeatureProvider =
|
||||
new DashboardFeatureProviderImpl(mActivity);
|
||||
final PackageManager packageManager = mock(PackageManager.class);
|
||||
ReflectionHelpers.setField(dashboardFeatureProvider, "mPackageManager", packageManager);
|
||||
when(packageManager.resolveActivity(any(Intent.class), anyInt()))
|
||||
.thenReturn(mock(ResolveInfo.class));
|
||||
|
||||
final Tile tile = new Tile();
|
||||
tile.key = "key";
|
||||
tile.metaData = new Bundle();
|
||||
tile.metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
|
||||
tile.metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
|
||||
tile.metaData.putString("com.android.settings.intent.action", Intent.ACTION_ASSIST);
|
||||
tile.intent = new Intent();
|
||||
tile.userHandle = null;
|
||||
mFragment.displayTile(tile);
|
||||
|
||||
final Activity activity = Robolectric.buildActivity(Activity.class).get();
|
||||
final Preference preference = new Preference(mContext);
|
||||
dashboardFeatureProvider.bindPreferenceToTile(activity,
|
||||
MetricsProto.MetricsEvent.DASHBOARD_SUMMARY, preference, tile, "key",
|
||||
Preference.DEFAULT_ORDER);
|
||||
|
||||
preference.performClick();
|
||||
|
||||
final Intent intent = shadowOf(activity).getNextStartedActivityForResult().intent;
|
||||
|
||||
assertThat(intent.getStringExtra("extra.accountName"))
|
||||
.isEqualTo("name1@abc.com");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,11 @@ import org.robolectric.annotation.Implements;
|
||||
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = AccountHeaderPreferenceControllerTest.ShadowAuthenticatorHelper.class
|
||||
)
|
||||
public class AccountHeaderPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@@ -83,7 +87,6 @@ public class AccountHeaderPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAuthenticatorHelper.class)
|
||||
public void onResume_shouldDisplayAccountInEntityHeader() {
|
||||
final Lifecycle lifecycle = new Lifecycle();
|
||||
final Account account = new Account("name1@abc.com", "com.abc");
|
||||
|
||||
@@ -111,7 +111,6 @@ public class AccountPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
public void onResume_linkedUser_shouldAddOneAccountCategory() {
|
||||
final UserInfo info = new UserInfo(1, "user 1", 0);
|
||||
when(mUserManager.isManagedProfile()).thenReturn(false);
|
||||
@@ -124,7 +123,6 @@ public class AccountPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
public void onResume_oneProfile_shouldAddOneAccountCategory() {
|
||||
final List<UserInfo> infos = new ArrayList<>();
|
||||
infos.add(new UserInfo(1, "user 1", 0));
|
||||
@@ -138,7 +136,6 @@ public class AccountPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
public void onResume_twoProfiles_shouldAddTwoAccountCategory() {
|
||||
final List<UserInfo> infos = new ArrayList<>();
|
||||
infos.add(new UserInfo(1, "user 1", 0));
|
||||
@@ -153,7 +150,6 @@ public class AccountPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
public void onResume_noProfileChange_shouldNotAddOrRemoveAccountCategory() {
|
||||
final List<UserInfo> infos = new ArrayList<>();
|
||||
infos.add(new UserInfo(1, "user 1", 0));
|
||||
@@ -171,7 +167,6 @@ public class AccountPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
public void onResume_oneNewProfile_shouldAddOneAccountCategory() {
|
||||
final List<UserInfo> infos = new ArrayList<>();
|
||||
infos.add(new UserInfo(1, "user 1", 0));
|
||||
@@ -189,7 +184,6 @@ public class AccountPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
public void onResume_oneProfileRemoved_shouldRemoveOneAccountCategory() {
|
||||
final List<UserInfo> infos = new ArrayList<>();
|
||||
infos.add(new UserInfo(1, "user 1", 0));
|
||||
@@ -207,7 +201,6 @@ public class AccountPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
public void onResume_oneProfile_shouldSetAccountTitleWithUserName() {
|
||||
final List<UserInfo> infos = new ArrayList<>();
|
||||
infos.add(new UserInfo(1, "user 1", UserInfo.FLAG_MANAGED_PROFILE));
|
||||
@@ -226,7 +219,6 @@ public class AccountPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
public void onResume_noPreferenceScreen_shouldNotCrash() {
|
||||
final List<UserInfo> infos = new ArrayList<>();
|
||||
infos.add(new UserInfo(1, "user 1", 0));
|
||||
@@ -244,7 +236,6 @@ public class AccountPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
public void onResume_noPreferenceManager_shouldNotCrash() {
|
||||
when(mFragment.getPreferenceManager()).thenReturn(null);
|
||||
final List<UserInfo> infos = new ArrayList<>();
|
||||
@@ -337,7 +328,6 @@ public class AccountPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
public void onResume_twoAccountsOfSameType_shouldAddThreePreferences() {
|
||||
final List<UserInfo> infos = new ArrayList<>();
|
||||
infos.add(new UserInfo(1, "user 1", 0));
|
||||
@@ -417,7 +407,6 @@ public class AccountPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
public void onResume_noAccountChange_shouldNotAddAccountPreference() {
|
||||
final List<UserInfo> infos = new ArrayList<>();
|
||||
infos.add(new UserInfo(1, "user 1", 0));
|
||||
@@ -498,7 +487,6 @@ public class AccountPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
public void onResume_oneNewAccountType_shouldAddOneAccountPreference() {
|
||||
final List<UserInfo> infos = new ArrayList<>();
|
||||
infos.add(new UserInfo(1, "user 1", 0));
|
||||
@@ -534,7 +522,6 @@ public class AccountPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
public void onResume_oneAccountRemoved_shouldRemoveOneAccountPreference() {
|
||||
final List<UserInfo> infos = new ArrayList<>();
|
||||
infos.add(new UserInfo(1, "user 1", 0));
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -33,17 +34,20 @@ import android.app.Activity;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.v14.preference.PreferenceFragment;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.enterprise.DevicePolicyManagerWrapper;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowAccountManager;
|
||||
import com.android.settings.testutils.shadow.ShadowContentResolver;
|
||||
|
||||
@@ -64,6 +68,8 @@ public class RemoveAccountPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private AccountManager mAccountManager;
|
||||
@Mock
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private PreferenceFragment mFragment;
|
||||
@Mock
|
||||
@@ -92,7 +98,8 @@ public class RemoveAccountPreferenceControllerTest {
|
||||
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(
|
||||
new AuthenticatorDescription[0]);
|
||||
when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(new Account[0]);
|
||||
mController = new RemoveAccountPreferenceController(mContext, mFragment);
|
||||
mController = new RemoveAccountPreferenceController(mContext, mFragment,
|
||||
mDevicePolicyManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,6 +123,18 @@ public class RemoveAccountPreferenceControllerTest {
|
||||
eq(TAG_REMOVE_ACCOUNT_DIALOG));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClick_shouldNotStartConfirmDialogWhenModifyAccountsIsDisallowed() {
|
||||
when(mFragment.isAdded()).thenReturn(true);
|
||||
when(mDevicePolicyManager.createAdminSupportIntent(UserManager.DISALLOW_MODIFY_ACCOUNTS))
|
||||
.thenReturn(new Intent());
|
||||
mController.onClick(null);
|
||||
|
||||
verify(mFragmentTransaction, never()).add(
|
||||
any(RemoveAccountPreferenceController.ConfirmRemoveAccountDialog.class),
|
||||
eq(TAG_REMOVE_ACCOUNT_DIALOG));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
|
||||
public void confirmRemove_shouldRemoveAccount() {
|
||||
@@ -134,4 +153,4 @@ public class RemoveAccountPreferenceControllerTest {
|
||||
verify(mAccountManager).removeAccountAsUser(eq(account), nullable(Activity.class),
|
||||
nullable(AccountManagerCallback.class), nullable(Handler.class), eq(userHandle));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,27 +66,6 @@ public class UserAndAccountDashboardFragmentTest {
|
||||
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_ACCOUNT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshDashboardTiles_HasAccountType_shouldNotDisplay() {
|
||||
final Tile tile = new Tile();
|
||||
final Bundle metaData = new Bundle();
|
||||
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
|
||||
metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
|
||||
tile.metaData = metaData;
|
||||
|
||||
assertThat(mFragment.displayTile(tile)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshDashboardTiles_NoAccountType_shouldDisplay() {
|
||||
final Tile tile = new Tile();
|
||||
final Bundle metaData = new Bundle();
|
||||
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
|
||||
tile.metaData = metaData;
|
||||
|
||||
assertThat(mFragment.displayTile(tile)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSummary_shouldDisplaySignedInUser() {
|
||||
final Activity activity = mock(Activity.class);
|
||||
|
||||
@@ -16,18 +16,29 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
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.pm.PackageManager;
|
||||
import android.os.UserManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.defaultapps.DefaultBrowserPreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultPhonePreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultSmsPreferenceController;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -40,31 +51,19 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AdvancedAppSettingsTest {
|
||||
public class DefaultAppSettingsTest {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private AdvancedAppSettings mFragment;
|
||||
private DefaultAppSettings mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mFragment = new AdvancedAppSettings();
|
||||
mFragment = new DefaultAppSettings();
|
||||
mFragment.onAttach(mContext);
|
||||
}
|
||||
|
||||
@@ -77,8 +76,8 @@ public class AdvancedAppSettingsTest {
|
||||
@Test
|
||||
public void setListening_shouldUpdateSummary() {
|
||||
final SummaryLoader summaryLoader = mock(SummaryLoader.class);
|
||||
final AdvancedAppSettings.SummaryProvider summaryProvider =
|
||||
new AdvancedAppSettings.SummaryProvider(mContext, summaryLoader);
|
||||
final DefaultAppSettings.SummaryProvider summaryProvider =
|
||||
new DefaultAppSettings.SummaryProvider(mContext, summaryLoader);
|
||||
final DefaultSmsPreferenceController defaultSms =
|
||||
mock(DefaultSmsPreferenceController.class);
|
||||
final DefaultBrowserPreferenceController defaultBrowser =
|
||||
@@ -149,6 +148,7 @@ public class AdvancedAppSettingsTest {
|
||||
public void testNonIndexableKeys_existInXmlLayout() {
|
||||
final Context context = spy(RuntimeEnvironment.application);
|
||||
final Context mockContext = mock(Context.class);
|
||||
when(mockContext.getApplicationContext()).thenReturn(mockContext);
|
||||
final UserManager userManager = mock(UserManager.class, RETURNS_DEEP_STUBS);
|
||||
|
||||
when(mockContext.getSystemService(Context.USER_SERVICE))
|
||||
@@ -159,10 +159,10 @@ public class AdvancedAppSettingsTest {
|
||||
.thenReturn(mock(TelephonyManager.class));
|
||||
when(mockContext.getPackageManager())
|
||||
.thenReturn(mock(PackageManager.class));
|
||||
final List<String> niks = AdvancedAppSettings.SEARCH_INDEX_DATA_PROVIDER
|
||||
final List<String> niks = DefaultAppSettings.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(mockContext);
|
||||
|
||||
final int xmlId = (new AdvancedAppSettings()).getPreferenceScreenResId();
|
||||
final int xmlId = (new DefaultAppSettings()).getPreferenceScreenResId();
|
||||
|
||||
final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
|
||||
|
||||
@@ -19,52 +19,59 @@ package com.android.settings.applications;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Matchers.nullable;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
||||
import android.view.Window;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.TouchOverlayManager;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowPreferenceFragment;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowAppInfoBase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.Spy;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DrawOverlayDetailsTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private DrawOverlayDetails mFragment;
|
||||
private Activity mActivity;
|
||||
|
||||
@Mock
|
||||
private TouchOverlayManager mTouchOverlayManager;
|
||||
private Window mWindow;
|
||||
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Spy
|
||||
private DrawOverlayDetails mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
|
||||
mFragment = new DrawOverlayDetails();
|
||||
ReflectionHelpers.setField(mFragment, "mTouchOverlayManager", mTouchOverlayManager);
|
||||
FakeFeatureFactory.setupForTest(mActivity);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void logSpecialPermissionChange() {
|
||||
mFragment.onAttach(ShadowApplication.getInstance().getApplicationContext());
|
||||
when(mFragment.getContext()).thenReturn(
|
||||
ShadowApplication.getInstance().getApplicationContext());
|
||||
|
||||
mFragment.logSpecialPermissionChange(true, "app");
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_APPDRAW_ALLOW), eq("app"));
|
||||
@@ -75,16 +82,17 @@ public class DrawOverlayDetailsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowPreferenceFragment.class)
|
||||
public void onStart_disableOverlay() {
|
||||
mFragment.onStart();
|
||||
verify(mTouchOverlayManager).setOverlayAllowed(false);
|
||||
}
|
||||
@Config(shadows = {ShadowAppInfoBase.class})
|
||||
public void hideNonSystemOverlaysWhenResumed() {
|
||||
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||
when(mActivity.getWindow()).thenReturn(mWindow);
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowPreferenceFragment.class)
|
||||
public void onStop_enableOverlay() {
|
||||
mFragment.onStop();
|
||||
verify(mTouchOverlayManager).setOverlayAllowed(true);
|
||||
mFragment.onResume();
|
||||
mFragment.onPause();
|
||||
|
||||
InOrder inOrder = Mockito.inOrder(mWindow);
|
||||
inOrder.verify(mWindow).addFlags(PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
|
||||
inOrder.verify(mWindow).clearFlags(PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.instantapps.InstantAppButtonsController;
|
||||
import com.android.settings.applications.instantapps.InstantAppButtonsController.ShowDialogDelegate;
|
||||
import com.android.settings.enterprise.DevicePolicyManagerWrapper;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.Utils;
|
||||
@@ -83,7 +84,11 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = InstalledAppDetailsTest.ShadowUtils.class
|
||||
)
|
||||
public final class InstalledAppDetailsTest {
|
||||
|
||||
private static final String PACKAGE_NAME = "test_package_name";
|
||||
@@ -99,7 +104,7 @@ public final class InstalledAppDetailsTest {
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private SettingsActivity mActivity;
|
||||
@Mock
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
@Mock
|
||||
private BatterySipper mBatterySipper;
|
||||
@Mock
|
||||
@@ -491,7 +496,6 @@ public final class InstalledAppDetailsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowUtils.class)
|
||||
public void handleDisableable_appIsEnabled_buttonShouldWork() {
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.packageName = "pkg";
|
||||
@@ -513,7 +517,6 @@ public final class InstalledAppDetailsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowUtils.class)
|
||||
public void handleDisableable_appIsEnabledAndInKeepEnabledWhitelist_buttonShouldNotWork() {
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.packageName = "pkg";
|
||||
|
||||
@@ -16,6 +16,17 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
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.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@@ -35,14 +46,11 @@ import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources.SettingsShadowTheme;
|
||||
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
|
||||
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
|
||||
import com.android.settings.widget.LoadingViewController;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.applications.ApplicationsState.Callbacks;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -53,17 +61,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.fakes.RoboMenuItem;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
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;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Tests for {@link ManageApplications}.
|
||||
@@ -75,7 +73,6 @@ import static org.mockito.Mockito.when;
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowTheme.class,
|
||||
ShadowDynamicIndexableContentMonitor.class,
|
||||
ShadowEventLogWriter.class
|
||||
})
|
||||
public class ManageApplicationsTest {
|
||||
@@ -170,12 +167,12 @@ public class ManageApplicationsTest {
|
||||
ReflectionHelpers.setField(fragment, "mLoadingContainer", mock(View.class));
|
||||
ReflectionHelpers.setField(fragment, "mListContainer", mock(View.class));
|
||||
when(fragment.getActivity()).thenReturn(mock(Activity.class));
|
||||
final Runnable showLoadingContainerRunnable = mock(Runnable.class);
|
||||
final Handler handler = mock(Handler.class);
|
||||
final ManageApplications.ApplicationsAdapter adapter =
|
||||
spy(new ManageApplications.ApplicationsAdapter(mState, fragment, 0));
|
||||
ReflectionHelpers.setField(adapter, "mShowLoadingContainerRunnable",
|
||||
showLoadingContainerRunnable);
|
||||
final LoadingViewController loadingViewController =
|
||||
mock(LoadingViewController.class);
|
||||
ReflectionHelpers.setField(adapter, "mLoadingViewController", loadingViewController);
|
||||
ReflectionHelpers.setField(adapter, "mFgHandler", handler);
|
||||
|
||||
// app loading completed
|
||||
@@ -186,7 +183,7 @@ public class ManageApplicationsTest {
|
||||
|
||||
adapter.updateLoading();
|
||||
|
||||
verify(handler, never()).postDelayed(eq(showLoadingContainerRunnable), anyLong());
|
||||
verify(loadingViewController, never()).showLoadingViewDelayed();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -195,12 +192,13 @@ public class ManageApplicationsTest {
|
||||
ReflectionHelpers.setField(fragment, "mLoadingContainer", mock(View.class));
|
||||
ReflectionHelpers.setField(fragment, "mListContainer", mock(View.class));
|
||||
when(fragment.getActivity()).thenReturn(mock(Activity.class));
|
||||
final Runnable showLoadingContainerRunnable = mock(Runnable.class);
|
||||
|
||||
final Handler handler = mock(Handler.class);
|
||||
final ManageApplications.ApplicationsAdapter adapter =
|
||||
spy(new ManageApplications.ApplicationsAdapter(mState, fragment, 0));
|
||||
ReflectionHelpers.setField(adapter, "mShowLoadingContainerRunnable",
|
||||
showLoadingContainerRunnable);
|
||||
final LoadingViewController loadingViewController =
|
||||
mock(LoadingViewController.class);
|
||||
ReflectionHelpers.setField(adapter, "mLoadingViewController", loadingViewController);
|
||||
ReflectionHelpers.setField(adapter, "mFgHandler", handler);
|
||||
|
||||
// app loading not yet completed
|
||||
@@ -208,11 +206,11 @@ public class ManageApplicationsTest {
|
||||
|
||||
adapter.updateLoading();
|
||||
|
||||
verify(handler).postDelayed(eq(showLoadingContainerRunnable), anyLong());
|
||||
verify(loadingViewController).showLoadingViewDelayed();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onRebuildComplete_shouldCancelDelayedRunnable() {
|
||||
public void onRebuildComplete_shouldHideLoadingView() {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
final ManageApplications fragment = mock(ManageApplications.class);
|
||||
final View loadingContainer = mock(View.class);
|
||||
@@ -223,12 +221,12 @@ public class ManageApplicationsTest {
|
||||
ReflectionHelpers.setField(fragment, "mLoadingContainer", loadingContainer);
|
||||
ReflectionHelpers.setField(fragment, "mListContainer", listContainer);
|
||||
when(fragment.getActivity()).thenReturn(mock(Activity.class));
|
||||
final Runnable showLoadingContainerRunnable = mock(Runnable.class);
|
||||
final Handler handler = mock(Handler.class);
|
||||
final ManageApplications.ApplicationsAdapter adapter =
|
||||
spy(new ManageApplications.ApplicationsAdapter(mState, fragment, 0));
|
||||
ReflectionHelpers.setField(adapter, "mShowLoadingContainerRunnable",
|
||||
showLoadingContainerRunnable);
|
||||
final LoadingViewController loadingViewController =
|
||||
mock(LoadingViewController.class);
|
||||
ReflectionHelpers.setField(adapter, "mLoadingViewController", loadingViewController);
|
||||
ReflectionHelpers.setField(adapter, "mFgHandler", handler);
|
||||
ReflectionHelpers.setField(adapter, "mFilterMode", -1);
|
||||
|
||||
@@ -244,7 +242,7 @@ public class ManageApplicationsTest {
|
||||
|
||||
adapter.onRebuildComplete(null);
|
||||
|
||||
verify(handler).removeCallbacks(showLoadingContainerRunnable);
|
||||
verify(loadingViewController).showContent(true /* animate */);
|
||||
}
|
||||
|
||||
private void setUpOptionMenus() {
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.android.settings.applications;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.nullable;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.UserHandle;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class PhotosViewHolderControllerTest {
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Fragment mFragment;
|
||||
|
||||
@Mock private StorageVolumeProvider mSvp;
|
||||
@Mock private StorageStatsSource mSource;
|
||||
|
||||
private Context mContext;
|
||||
private PhotosViewHolderController mController;
|
||||
private VolumeInfo mVolume;
|
||||
private AppViewHolder mHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mVolume = new VolumeInfo("id", 0, null, "id");
|
||||
mController =
|
||||
new PhotosViewHolderController(
|
||||
mContext, mSource, mVolume.fsUuid, new UserHandle(0));
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
mHolder = AppViewHolder.createOrRecycle(inflater, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void storageShouldBeZeroBytesIfQueriedBeforeStorageQueryFinishes() {
|
||||
mController.setupView(mHolder);
|
||||
|
||||
assertThat(mHolder.summary.getText().toString()).isEqualTo("0.00B");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void storageShouldRepresentStorageStatsQuery() throws Exception {
|
||||
when(mSource.getExternalStorageStats(nullable(String.class), nullable(UserHandle.class)))
|
||||
.thenReturn(new StorageStatsSource.ExternalStorageStats(1, 0, 1, 10, 0));
|
||||
|
||||
mController.queryStats();
|
||||
mController.setupView(mHolder);
|
||||
|
||||
assertThat(mHolder.summary.getText().toString()).isEqualTo("11.00B");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickingShouldIntentIntoFilesApp() {
|
||||
mController.onClick(mFragment);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment).startActivity(argumentCaptor.capture());
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
|
||||
assertThat(intent.getType()).isEqualTo("image/*");
|
||||
assertThat(intent.getAction()).isEqualTo(android.content.Intent.ACTION_VIEW);
|
||||
assertThat(intent.getBooleanExtra(Intent.EXTRA_FROM_STORAGE, false)).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.applications;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class PictureInPictureSettingsTest {
|
||||
|
||||
private static final int PRIMARY_USER_ID = 0;
|
||||
private static final int PROFILE_USER_ID = 10;
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private PictureInPictureSettings mFragment;
|
||||
@Mock
|
||||
private PackageManagerWrapper mPackageManager;
|
||||
@Mock
|
||||
private UserManagerWrapper mUserManager;
|
||||
private ArrayList<PackageInfo> mPrimaryUserPackages;
|
||||
private ArrayList<PackageInfo> mProfileUserPackages;
|
||||
private ArrayList<UserInfo> mUsers;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mFragment = new PictureInPictureSettings(mPackageManager, mUserManager);
|
||||
mPrimaryUserPackages = new ArrayList<>();
|
||||
mProfileUserPackages = new ArrayList<>();
|
||||
mUsers = new ArrayList<>();
|
||||
when(mPackageManager.getInstalledPackagesAsUser(anyInt(), eq(PRIMARY_USER_ID)))
|
||||
.thenReturn(mPrimaryUserPackages);
|
||||
when(mPackageManager.getInstalledPackagesAsUser(anyInt(), eq(PROFILE_USER_ID)))
|
||||
.thenReturn(mProfileUserPackages);
|
||||
when(mUserManager.getProfiles(anyInt())).thenReturn(mUsers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollectPipApps() {
|
||||
PackageInfo primaryP1 = createPackage("Calculator", true);
|
||||
PackageInfo primaryP2 = createPackage("Clock", false);
|
||||
PackageInfo profileP1 = createPackage("Calculator", false);
|
||||
PackageInfo profileP2 = createPackage("Clock", true);
|
||||
|
||||
mPrimaryUserPackages.add(primaryP1);
|
||||
mPrimaryUserPackages.add(primaryP2);
|
||||
mProfileUserPackages.add(profileP1);
|
||||
mProfileUserPackages.add(profileP2);
|
||||
|
||||
ArrayList<Pair<ApplicationInfo, Integer>> apps = mFragment.collectPipApps(PRIMARY_USER_ID);
|
||||
assertThat(containsPackages(apps, primaryP1, profileP2));
|
||||
assertThat(!containsPackages(apps, primaryP2, profileP1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppSort() {
|
||||
PackageInfo primaryP1 = createPackage("Android", true);
|
||||
PackageInfo primaryP2 = createPackage("Boop", true);
|
||||
PackageInfo primaryP3 = createPackage("Deck", true);
|
||||
PackageInfo profileP1 = createPackage("Android", true);
|
||||
PackageInfo profileP2 = createPackage("Cool", true);
|
||||
PackageInfo profileP3 = createPackage("Fast", false);
|
||||
|
||||
mPrimaryUserPackages.add(primaryP1);
|
||||
mPrimaryUserPackages.add(primaryP2);
|
||||
mPrimaryUserPackages.add(primaryP3);
|
||||
mProfileUserPackages.add(profileP1);
|
||||
mProfileUserPackages.add(profileP2);
|
||||
mProfileUserPackages.add(profileP3);
|
||||
|
||||
ArrayList<Pair<ApplicationInfo, Integer>> apps = mFragment.collectPipApps(PRIMARY_USER_ID);
|
||||
Collections.sort(apps, new PictureInPictureSettings.AppComparator(null));
|
||||
assertThat(isOrdered(apps, primaryP1, profileP1, primaryP2, profileP2));
|
||||
}
|
||||
|
||||
private boolean containsPackages(ArrayList<Pair<ApplicationInfo, Integer>> apps,
|
||||
PackageInfo... packages) {
|
||||
for (int i = 0; i < packages.length; i++) {
|
||||
boolean found = false;
|
||||
for (int j = 0; j < apps.size(); j++) {
|
||||
if (apps.get(j).first == packages[i].applicationInfo) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isOrdered(ArrayList<Pair<ApplicationInfo, Integer>> apps,
|
||||
PackageInfo... packages) {
|
||||
if (apps.size() != packages.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < packages.length; i++) {
|
||||
if (packages[i].applicationInfo != apps.get(i).first) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private PackageInfo createPackage(String appTitle, boolean supportsPip) {
|
||||
PackageInfo pi = new PackageInfo();
|
||||
ActivityInfo ai = new ActivityInfo();
|
||||
if (supportsPip) {
|
||||
ai.flags |= ActivityInfo.FLAG_SUPPORTS_PICTURE_IN_PICTURE;
|
||||
}
|
||||
pi.activities = new ActivityInfo[1];
|
||||
pi.activities[0] = ai;
|
||||
pi.applicationInfo = new ApplicationInfo();
|
||||
pi.applicationInfo.name = appTitle;
|
||||
return pi;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import android.app.usage.UsageStatsManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
@@ -46,6 +47,7 @@ import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
@@ -179,8 +181,9 @@ public class RecentAppsPreferenceControllerTest {
|
||||
.thenReturn(new ResolveInfo());
|
||||
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
|
||||
.thenReturn(stats);
|
||||
when(mMockContext.getString(eq(R.string.battery_history_minutes_no_seconds), anyInt()))
|
||||
.thenReturn(mContext.getString(R.string.battery_history_minutes_no_seconds, 45));
|
||||
final Configuration configuration = new Configuration();
|
||||
configuration.locale = Locale.US;
|
||||
when(mMockContext.getResources().getConfiguration()).thenReturn(configuration);
|
||||
|
||||
mController = new RecentAppsPreferenceController(mMockContext, mAppState, null);
|
||||
mController.displayPreference(mScreen);
|
||||
@@ -245,15 +248,17 @@ public class RecentAppsPreferenceControllerTest {
|
||||
.thenReturn(new ResolveInfo());
|
||||
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
|
||||
.thenReturn(stats);
|
||||
when(mMockContext.getString(eq(R.string.battery_history_minutes_no_seconds), anyInt()))
|
||||
.thenReturn(mContext.getString(R.string.battery_history_minutes_no_seconds, 35));
|
||||
|
||||
when(mMockContext.getResources().getText(eq(R.string.recent_app_summary)))
|
||||
.thenReturn(mContext.getResources().getText(R.string.recent_app_summary));
|
||||
final Configuration configuration = new Configuration();
|
||||
configuration.locale = Locale.US;
|
||||
when(mMockContext.getResources().getConfiguration()).thenReturn(configuration);
|
||||
|
||||
mController = new RecentAppsPreferenceController(mMockContext, mAppState, null);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mCategory).addPreference(argThat(summaryMatches("35m ago")));
|
||||
verify(mCategory).addPreference(argThat(summaryMatches("0m ago")));
|
||||
}
|
||||
|
||||
private static ArgumentMatcher<Preference> summaryMatches(String expected) {
|
||||
|
||||
@@ -78,8 +78,8 @@ public class AssistFlashScreenPreferenceControllerTest {
|
||||
@Config(shadows = {ShadowSecureSettings.class})
|
||||
public void isAvailable_hasAssistantAndAllowDisclosure_shouldReturnTrue() {
|
||||
ReflectionHelpers.setField(mController, "mContext", mMockContext);
|
||||
ShadowSecureSettings.putString(null, Settings.Secure.ASSISTANT,
|
||||
"com.android.settings/assist");
|
||||
final ContentResolver cr = mContext.getContentResolver();
|
||||
Settings.Secure.putString(cr, Settings.Secure.ASSISTANT, "com.android.settings/assist");
|
||||
doReturn(true).when(mController).allowDisablingAssistDisclosure();
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
@@ -89,8 +89,8 @@ public class AssistFlashScreenPreferenceControllerTest {
|
||||
@Config(shadows = {ShadowSecureSettings.class})
|
||||
public void isAvailable_hasAssistantAndDisallowDisclosure_shouldReturnTrue() {
|
||||
ReflectionHelpers.setField(mController, "mContext", mMockContext);
|
||||
ShadowSecureSettings.putString(null, Settings.Secure.ASSISTANT,
|
||||
"com.android.settings/assist");
|
||||
final ContentResolver cr = mContext.getContentResolver();
|
||||
Settings.Secure.putString(cr, Settings.Secure.ASSISTANT, "com.android.settings/assist");
|
||||
doReturn(false).when(mController).allowDisablingAssistDisclosure();
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
@@ -98,8 +98,7 @@ public class AssistFlashScreenPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void isAvailable_hasNoAssistant_shouldReturnFalse() {
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ASSISTANT, "");
|
||||
Settings.Secure.putString(mContext.getContentResolver(), Settings.Secure.ASSISTANT, "");
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,16 @@
|
||||
|
||||
package com.android.settings.applications.assist;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.SearchManager;
|
||||
import android.content.ComponentName;
|
||||
@@ -28,33 +38,29 @@ import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.internal.app.AssistUtils;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.defaultapps.DefaultAppInfo;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DefaultAssistPreferenceControllerTest {
|
||||
|
||||
private static final String TEST_KEY = "test_pref_key";
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
@@ -66,7 +72,8 @@ public class DefaultAssistPreferenceControllerTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new DefaultAssistPreferenceController(mContext);
|
||||
mController = new DefaultAssistPreferenceController(mContext, TEST_KEY,
|
||||
true /* showSetting */);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,11 +81,17 @@ public class DefaultAssistPreferenceControllerTest {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPrefKey_shouldReturnKey() {
|
||||
assertThat(mController.getPreferenceKey())
|
||||
.isEqualTo(TEST_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowSecureSettings.class})
|
||||
public void getDefaultAppInfo_hasDefaultAssist_shouldReturnKey() {
|
||||
final String flattenKey = "com.android.settings/assist";
|
||||
ShadowSecureSettings.putString(null, Settings.Secure.ASSISTANT, flattenKey);
|
||||
Settings.Secure.putString(null, Settings.Secure.ASSISTANT, flattenKey);
|
||||
DefaultAppInfo appInfo = mController.getDefaultAppInfo();
|
||||
|
||||
assertThat(appInfo.getKey()).isEqualTo(flattenKey);
|
||||
@@ -87,17 +100,17 @@ public class DefaultAssistPreferenceControllerTest {
|
||||
@Test
|
||||
public void getSettingIntent_noSettingsActivity_shouldNotCrash() {
|
||||
final String flattenKey = "com.android.settings/assist";
|
||||
ShadowSecureSettings.putString(null, Settings.Secure.ASSISTANT, flattenKey);
|
||||
Settings.Secure.putString(null, Settings.Secure.ASSISTANT, flattenKey);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
DefaultAssistPreferenceController controller =
|
||||
spy(new DefaultAssistPreferenceController(mContext));
|
||||
DefaultAssistPreferenceController controller = spy(
|
||||
new DefaultAssistPreferenceController(mContext, TEST_KEY, true /* showSetting */));
|
||||
final ResolveInfo resolveInfo = new ResolveInfo();
|
||||
resolveInfo.activityInfo = new ActivityInfo();
|
||||
resolveInfo.activityInfo.name = "assist";
|
||||
resolveInfo.activityInfo.applicationInfo = new ApplicationInfo();
|
||||
resolveInfo.activityInfo.applicationInfo.packageName = "com.android.settings";
|
||||
when(mPackageManager.resolveActivityAsUser(any(Intent.class), anyInt(), anyInt()))
|
||||
.thenReturn(resolveInfo);
|
||||
.thenReturn(resolveInfo);
|
||||
when(mContext.getSystemService(Context.SEARCH_SERVICE)).thenReturn(mSearchManager);
|
||||
when(mSearchManager.getAssistIntent(anyBoolean())).thenReturn(mock(Intent.class));
|
||||
final ServiceInfo serviceInfo = new ServiceInfo();
|
||||
@@ -107,9 +120,21 @@ public class DefaultAssistPreferenceControllerTest {
|
||||
services.add(resolveInfo);
|
||||
when(mPackageManager.queryIntentServices(any(Intent.class), anyInt())).thenReturn(services);
|
||||
doReturn(null).when(controller).getAssistSettingsActivity(
|
||||
ComponentName.unflattenFromString(flattenKey), resolveInfo, mPackageManager);
|
||||
ComponentName.unflattenFromString(flattenKey), resolveInfo, mPackageManager);
|
||||
|
||||
controller.getSettingIntent(null);
|
||||
// should not crash
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSettingIntent_doNotShowSetting_shouldNotTryToGetSettingIntent() {
|
||||
final AssistUtils assistUtils = mock(AssistUtils.class);
|
||||
final DefaultAssistPreferenceController controller = new DefaultAssistPreferenceController(
|
||||
mContext, TEST_KEY, false /* showSetting */);
|
||||
ReflectionHelpers.setField(controller, "mAssistUtils", assistUtils);
|
||||
|
||||
controller.getSettingIntent(null);
|
||||
|
||||
verifyZeroInteractions(assistUtils);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,14 +17,22 @@
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyList;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.PackageManagerWrapper;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -35,14 +43,6 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyList;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DefaultHomePreferenceControllerTest {
|
||||
@@ -79,11 +79,10 @@ public class DefaultHomePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_noDefaultApp_shouldAskPackageManagerForOnlyApp() {
|
||||
doReturn(null).when(mController).getDefaultAppInfo();
|
||||
|
||||
when(mPackageManager.getHomeActivities(anyList())).thenReturn(null);
|
||||
mController.updateState(mock(Preference.class));
|
||||
|
||||
verify(mPackageManager).getHomeActivities(anyList());
|
||||
verify(mPackageManager, atLeastOnce()).getHomeActivities(anyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.applications.defaultapps;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.PackageManagerWrapper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
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.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DefaultNotificationAssistantPickerTest {
|
||||
|
||||
private static final String TEST_APP_KEY = "com.android.settings/PickerTest";
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private PackageManagerWrapper mPackageManager;
|
||||
|
||||
private DefaultNotificationAssistantPicker mPicker;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
|
||||
mPicker = spy(new DefaultNotificationAssistantPicker());
|
||||
mPicker.onAttach((Context) mActivity);
|
||||
|
||||
ReflectionHelpers.setField(mPicker, "mPm", mPackageManager);
|
||||
doReturn(RuntimeEnvironment.application).when(mPicker).getContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDefaultAppKey_shouldUpdateDefault() {
|
||||
mPicker.setDefaultKey(TEST_APP_KEY);
|
||||
|
||||
assertThat(mPicker.getDefaultKey()).isEqualTo(TEST_APP_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultAppKey_shouldReturnDefault() {
|
||||
Settings.Secure.putString(RuntimeEnvironment.application.getContentResolver(),
|
||||
Settings.Secure.ENABLED_NOTIFICATION_ASSISTANT,
|
||||
TEST_APP_KEY);
|
||||
|
||||
assertThat(mPicker.getDefaultKey()).isEqualTo(TEST_APP_KEY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.applications.defaultapps;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.nfc.NfcAdapter;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.nfc.PaymentBackend;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
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.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DefaultPaymentSettingsPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private NfcAdapter mNfcAdapter;
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private PaymentBackend mPaymentBackend;
|
||||
|
||||
private DefaultPaymentSettingsPreferenceController mController;
|
||||
private Preference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
mController = new DefaultPaymentSettingsPreferenceController(mContext);
|
||||
ReflectionHelpers.setField(mController, "mNfcAdapter", mNfcAdapter);
|
||||
|
||||
mPreference = new Preference(RuntimeEnvironment.application);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_hasNfc_shouldReturnTrue() {
|
||||
when(mPackageManager.hasSystemFeature(anyString())).thenReturn(true);
|
||||
when(mUserManager.isAdminUser()).thenReturn(true);
|
||||
when(mNfcAdapter.isEnabled()).thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_noNfcAdapter_shouldReturnFalse() {
|
||||
when(mPackageManager.hasSystemFeature(anyString())).thenReturn(true);
|
||||
when(mUserManager.isAdminUser()).thenReturn(true);
|
||||
ReflectionHelpers.setField(mController, "mNfcAdapter", null);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_shouldSetSummaryToDefaultPaymentApp() {
|
||||
final PaymentBackend.PaymentAppInfo defaultApp = mock(PaymentBackend.PaymentAppInfo.class);
|
||||
defaultApp.label = "test_payment_app";
|
||||
when(mPaymentBackend.getDefaultApp()).thenReturn(defaultApp);
|
||||
ReflectionHelpers.setField(mController, "mPaymentBackend", mPaymentBackend);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPaymentBackend).refresh();
|
||||
assertThat(mPreference.getSummary()).isEqualTo(defaultApp.label);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
|
||||
@@ -45,7 +46,8 @@ import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows={SettingsShadowBluetoothDevice.class, ShadowEntityHeaderController.class})
|
||||
shadows={SettingsShadowBluetoothDevice.class, ShadowEntityHeaderController.class,
|
||||
SettingsShadowResources.class})
|
||||
public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsControllerTestBase {
|
||||
private BluetoothDetailsHeaderController mController;
|
||||
private LayoutPreference mPreference;
|
||||
|
||||
@@ -72,8 +72,9 @@ public class BluetoothDeviceNamePreferenceControllerTest {
|
||||
mController.updateDeviceName(mPreference, DEVICE_NAME);
|
||||
|
||||
final CharSequence summary = mPreference.getSummary();
|
||||
|
||||
assertThat(summary.toString())
|
||||
.isEqualTo("Visible as 'Nightshade' to other devices");
|
||||
.isEqualTo("Visible as \u201CNightshade\u201D to other devices");
|
||||
assertThat(mPreference.isSelectable()).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -38,18 +39,24 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = SettingsShadowResources.class)
|
||||
public class BluetoothDevicePreferenceTest {
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||
@Mock
|
||||
private DeviceListPreferenceFragment mDeviceListPreferenceFragment;
|
||||
|
||||
private FakeFeatureFactory mFakeFeatureFactory;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
@@ -62,7 +69,8 @@ public class BluetoothDevicePreferenceTest {
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
|
||||
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice);
|
||||
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
mDeviceListPreferenceFragment);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,11 +99,29 @@ public class BluetoothDevicePreferenceTest {
|
||||
when(mCachedBluetoothDevice.isConnected()).thenReturn(false);
|
||||
when(mCachedBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_NONE);
|
||||
when(mCachedBluetoothDevice.startPairing()).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.hasHumanReadableName()).thenReturn(true);
|
||||
|
||||
mPreference.onClicked();
|
||||
|
||||
verify(mMetricsFeatureProvider).action(
|
||||
mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
|
||||
verify(mMetricsFeatureProvider, never()).action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR_DEVICES_WITHOUT_NAMES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClicked_deviceNotBonded_shouldLogBluetoothPairEventAndPairWithoutNameEvent() {
|
||||
when(mCachedBluetoothDevice.isConnected()).thenReturn(false);
|
||||
when(mCachedBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_NONE);
|
||||
when(mCachedBluetoothDevice.startPairing()).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.hasHumanReadableName()).thenReturn(false);
|
||||
|
||||
mPreference.onClicked();
|
||||
|
||||
verify(mMetricsFeatureProvider).action(
|
||||
mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
|
||||
verify(mMetricsFeatureProvider).action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR_DEVICES_WITHOUT_NAMES);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,10 +166,58 @@ public class BluetoothDevicePreferenceTest {
|
||||
|
||||
@Test
|
||||
public void imagingDeviceIcon_isICSettingsPrint() {
|
||||
when(mCachedBluetoothDevice.getBatteryLevel()).thenReturn(
|
||||
BluetoothDevice.BATTERY_LEVEL_UNKNOWN);
|
||||
when(mCachedBluetoothDevice.getBtClass()).thenReturn(
|
||||
new BluetoothClass(BluetoothClass.Device.Major.IMAGING));
|
||||
|
||||
mPreference.onDeviceAttributesChanged();
|
||||
assertThat(mPreference.getIcon()).isEqualTo(
|
||||
mContext.getDrawable(R.drawable.ic_settings_print));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisible_notVisibleThenVisible() {
|
||||
when(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames()).thenReturn(false);
|
||||
final boolean[] humanReadableName = {false};
|
||||
doAnswer(invocation -> humanReadableName[0]).when(mCachedBluetoothDevice)
|
||||
.hasHumanReadableName();
|
||||
BluetoothDevicePreference preference =
|
||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
mDeviceListPreferenceFragment);
|
||||
assertThat(preference.isVisible()).isFalse();
|
||||
humanReadableName[0] = true;
|
||||
preference.onDeviceAttributesChanged();
|
||||
assertThat(preference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisible_visibleThenNotVisible() {
|
||||
when(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames()).thenReturn(false);
|
||||
final boolean[] humanReadableName = {true};
|
||||
doAnswer(invocation -> humanReadableName[0]).when(mCachedBluetoothDevice)
|
||||
.hasHumanReadableName();
|
||||
BluetoothDevicePreference preference =
|
||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
mDeviceListPreferenceFragment);
|
||||
assertThat(preference.isVisible()).isTrue();
|
||||
humanReadableName[0] = false;
|
||||
preference.onDeviceAttributesChanged();
|
||||
assertThat(preference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisible_alwaysVisibleWhenEnabled() {
|
||||
when(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames()).thenReturn(true);
|
||||
final boolean[] humanReadableName = {true};
|
||||
doAnswer(invocation -> humanReadableName[0]).when(mCachedBluetoothDevice)
|
||||
.hasHumanReadableName();
|
||||
BluetoothDevicePreference preference =
|
||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
mDeviceListPreferenceFragment);
|
||||
assertThat(preference.isVisible()).isTrue();
|
||||
humanReadableName[0] = false;
|
||||
preference.onDeviceAttributesChanged();
|
||||
assertThat(preference.isVisible()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,36 +15,51 @@
|
||||
*/
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.View;
|
||||
import android.widget.Switch;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.widget.MasterSwitchController;
|
||||
import com.android.settings.widget.MasterSwitchPreference;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
|
||||
SettingsShadowResources.class, SettingsShadowResources.SettingsShadowTheme.class
|
||||
})
|
||||
public class BluetoothEnablerTest {
|
||||
|
||||
private static final EnforcedAdmin FAKE_ENFORCED_ADMIN =
|
||||
@@ -53,24 +68,37 @@ public class BluetoothEnablerTest {
|
||||
@Mock
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private MasterSwitchController mMasterSwitchController;
|
||||
@Mock
|
||||
private RestrictionUtils mRestrictionUtils;
|
||||
@Mock
|
||||
private LocalBluetoothManager mBluetoothManager;
|
||||
@Mock
|
||||
private LocalBluetoothAdapter mBluetoothAdapter;
|
||||
|
||||
private Context mContext;
|
||||
Switch mSwitch;
|
||||
private MasterSwitchPreference mMasterSwitchPreference;
|
||||
private MasterSwitchController mMasterSwitchController;
|
||||
private BluetoothEnabler mBluetoothEnabler;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mBluetoothManager.getBluetoothAdapter()).thenReturn(mBluetoothAdapter);
|
||||
|
||||
mSwitch = new Switch(mContext);
|
||||
mMasterSwitchPreference = new MasterSwitchPreference(mContext);
|
||||
mMasterSwitchController = spy(new MasterSwitchController(mMasterSwitchPreference));
|
||||
mBluetoothEnabler = new BluetoothEnabler(
|
||||
mContext,
|
||||
mMasterSwitchController,
|
||||
mMetricsFeatureProvider,
|
||||
mock(LocalBluetoothManager.class),
|
||||
mBluetoothManager,
|
||||
123,
|
||||
mRestrictionUtils);
|
||||
PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(mock(View.class));
|
||||
when(holder.findViewById(R.id.switchWidget)).thenReturn(mSwitch);
|
||||
mMasterSwitchPreference.onBindViewHolder(holder);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,4 +164,84 @@ public class BluetoothEnablerTest {
|
||||
verify(mMasterSwitchController).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void maybeEnforceRestrictions_disallowBluetoothNotOverriden() {
|
||||
// GIVEN Bluetooth has been disallowed...
|
||||
when(mRestrictionUtils.checkIfRestrictionEnforced(
|
||||
mContext, UserManager.DISALLOW_BLUETOOTH)).thenReturn(FAKE_ENFORCED_ADMIN);
|
||||
when(mRestrictionUtils.checkIfRestrictionEnforced(
|
||||
mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH)).thenReturn(null);
|
||||
|
||||
mBluetoothEnabler.resume(mContext);
|
||||
|
||||
verify(mMasterSwitchController, never()).setEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithBluetoothOff_switchIsOff() {
|
||||
when(mBluetoothAdapter.getBluetoothState()).thenReturn(BluetoothAdapter.STATE_OFF);
|
||||
verify(mMasterSwitchController, never()).setChecked(anyBoolean());
|
||||
mBluetoothEnabler.resume(mContext);
|
||||
verify(mMasterSwitchController, never()).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithBluetoothOn_switchIsOn() {
|
||||
when(mBluetoothAdapter.getBluetoothState()).thenReturn(BluetoothAdapter.STATE_ON);
|
||||
verify(mMasterSwitchController, never()).setChecked(anyBoolean());
|
||||
mBluetoothEnabler.resume(mContext);
|
||||
verify(mMasterSwitchController, never()).setChecked(false);
|
||||
verify(mMasterSwitchController).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bluetoothTurnsOff_switchTurnsOff() {
|
||||
// Start up with bluetooth turned on. The switch should get turned on.
|
||||
assertThat(mSwitch.isChecked()).isFalse();
|
||||
ArgumentCaptor<BroadcastReceiver> captor = ArgumentCaptor.forClass(BroadcastReceiver.class);
|
||||
when(mContext.registerReceiver(captor.capture(), any(IntentFilter.class))).thenReturn(null);
|
||||
when(mBluetoothAdapter.getBluetoothState()).thenReturn(BluetoothAdapter.STATE_ON);
|
||||
verify(mMasterSwitchController, never()).setChecked(anyBoolean());
|
||||
mBluetoothEnabler.resume(mContext);
|
||||
verify(mMasterSwitchController, never()).setChecked(false);
|
||||
verify(mMasterSwitchController).setChecked(true);
|
||||
|
||||
// Now simulate bluetooth being turned off via an event.
|
||||
BroadcastReceiver receiver = captor.getValue();
|
||||
Intent turningOff = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||
turningOff.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_TURNING_OFF);
|
||||
receiver.onReceive(mContext, turningOff);
|
||||
Intent off = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||
off.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);
|
||||
receiver.onReceive(mContext, off);
|
||||
|
||||
// Make sure the switch was turned off.
|
||||
verify(mMasterSwitchController).setChecked(false);
|
||||
assertThat(mSwitch.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bluetoothTurnsOn_switchTurnsOn() {
|
||||
// Start up with bluetooth turned on. The switch should be left off.
|
||||
assertThat(mSwitch.isChecked()).isFalse();
|
||||
ArgumentCaptor<BroadcastReceiver> captor = ArgumentCaptor.forClass(BroadcastReceiver.class);
|
||||
when(mContext.registerReceiver(captor.capture(), any(IntentFilter.class))).thenReturn(null);
|
||||
when(mBluetoothAdapter.getBluetoothState()).thenReturn(BluetoothAdapter.STATE_OFF);
|
||||
verify(mMasterSwitchController, never()).setChecked(anyBoolean());
|
||||
mBluetoothEnabler.resume(mContext);
|
||||
verify(mMasterSwitchController, never()).setChecked(anyBoolean());
|
||||
|
||||
// Now simulate bluetooth being turned on via an event.
|
||||
BroadcastReceiver receiver = captor.getValue();
|
||||
Intent turningOn = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||
turningOn.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_TURNING_ON);
|
||||
receiver.onReceive(mContext, turningOn);
|
||||
Intent on = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||
on.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_ON);
|
||||
receiver.onReceive(mContext, on);
|
||||
|
||||
// Make sure the switch was turned on.
|
||||
verify(mMasterSwitchController).setChecked(true);
|
||||
assertThat(mSwitch.isChecked()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
@@ -47,6 +48,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowAlertDialog;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.FragmentTestUtil;
|
||||
|
||||
@@ -412,6 +414,39 @@ public class BluetoothPairingDialogTest {
|
||||
verify(dialogActivity, times(1)).dismiss();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rotateDialog_nullPinText_okButtonEnabled() {
|
||||
userEntryDialogExistingTextTest(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rotateDialog_emptyPinText_okButtonEnabled() {
|
||||
userEntryDialogExistingTextTest("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rotateDialog_nonEmptyPinText_okButtonEnabled() {
|
||||
userEntryDialogExistingTextTest("test");
|
||||
}
|
||||
|
||||
// Runs a test simulating the user entry dialog type in a situation like device rotation, where
|
||||
// the dialog fragment gets created and we already have some existing text entered into the
|
||||
// pin field.
|
||||
private void userEntryDialogExistingTextTest(CharSequence existingText) {
|
||||
when(controller.getDialogType()).thenReturn(BluetoothPairingController.USER_ENTRY_DIALOG);
|
||||
when(controller.getDeviceVariantMessageHintId())
|
||||
.thenReturn(BluetoothPairingController.INVALID_DIALOG_TYPE);
|
||||
when(controller.getDeviceVariantMessageId())
|
||||
.thenReturn(BluetoothPairingController.INVALID_DIALOG_TYPE);
|
||||
|
||||
BluetoothPairingDialogFragment fragment = spy(new BluetoothPairingDialogFragment());
|
||||
when(fragment.getPairingViewText()).thenReturn(existingText);
|
||||
setupFragment(fragment);
|
||||
AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog();
|
||||
boolean expected = !TextUtils.isEmpty(existingText);
|
||||
assertThat(dialog.getButton(Dialog.BUTTON_POSITIVE).isEnabled()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
private void setupFragment(BluetoothPairingDialogFragment frag) {
|
||||
assertThat(frag.isPairingControllerSet()).isFalse();
|
||||
frag.setPairingController(controller);
|
||||
|
||||
@@ -18,17 +18,25 @@ package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doCallRealMethod;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -39,19 +47,9 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothSummaryUpdaterTest {
|
||||
@@ -70,16 +68,33 @@ public class BluetoothSummaryUpdaterTest {
|
||||
@Mock
|
||||
private SummaryListener mListener;
|
||||
|
||||
// Disabled by default
|
||||
private final boolean[] mAdapterEnabled = {false};
|
||||
// Not connected by default
|
||||
private final int[] mAdapterConnectionState = {BluetoothAdapter.STATE_DISCONNECTED};
|
||||
// Not connected by default
|
||||
private final boolean[] mDeviceConnected = {false, false};
|
||||
private final Set<BluetoothDevice> mBondedDevices = new HashSet<>();
|
||||
private BluetoothSummaryUpdater mSummaryUpdater;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mBluetoothManager.getBluetoothAdapter()).thenReturn(mBtAdapter);
|
||||
when(mBtAdapter.isEnabled()).thenReturn(true);
|
||||
when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_CONNECTED);
|
||||
mContext = RuntimeEnvironment.application.getApplicationContext();
|
||||
doCallRealMethod().when(mListener).onSummaryChanged(anyString());
|
||||
// Setup mock adapter
|
||||
when(mBluetoothManager.getBluetoothAdapter()).thenReturn(mBtAdapter);
|
||||
doAnswer(invocation -> mAdapterEnabled[0]).when(mBtAdapter).isEnabled();
|
||||
doAnswer(invocation -> mAdapterConnectionState[0]).when(mBtAdapter).getConnectionState();
|
||||
mSummaryUpdater = new BluetoothSummaryUpdater(mContext, mListener, mBluetoothManager);
|
||||
// Setup first device
|
||||
doReturn(DEVICE_NAME).when(mConnectedDevice).getName();
|
||||
doAnswer(invocation -> mDeviceConnected[0]).when(mConnectedDevice).isConnected();
|
||||
// Setup second device
|
||||
doReturn(DEVICE_KEYBOARD_NAME).when(mConnectedKeyBoardDevice).getName();
|
||||
doAnswer(invocation -> mDeviceConnected[1]).when(mConnectedKeyBoardDevice)
|
||||
.isConnected();
|
||||
doReturn(mBondedDevices).when(mBtAdapter).getBondedDevices();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,7 +113,10 @@ public class BluetoothSummaryUpdaterTest {
|
||||
|
||||
@Test
|
||||
public void register_true_shouldSendSummaryChange() {
|
||||
prepareConnectedDevice(false);
|
||||
mAdapterEnabled[0] = true;
|
||||
mAdapterConnectionState[0] = BluetoothAdapter.STATE_CONNECTED;
|
||||
mBondedDevices.add(mConnectedDevice);
|
||||
mDeviceConnected[0] = true;
|
||||
|
||||
mSummaryUpdater.register(true);
|
||||
|
||||
@@ -108,7 +126,11 @@ public class BluetoothSummaryUpdaterTest {
|
||||
|
||||
@Test
|
||||
public void onBluetoothStateChanged_btDisabled_shouldSendDisabledSummary() {
|
||||
mSummaryUpdater.register(true);
|
||||
// These states should be ignored
|
||||
mAdapterConnectionState[0] = BluetoothAdapter.STATE_CONNECTED;
|
||||
mBondedDevices.add(mConnectedDevice);
|
||||
mDeviceConnected[0] = true;
|
||||
|
||||
mSummaryUpdater.onBluetoothStateChanged(BluetoothAdapter.STATE_OFF);
|
||||
|
||||
verify(mListener).onSummaryChanged(mContext.getString(R.string.bluetooth_disabled));
|
||||
@@ -116,68 +138,83 @@ public class BluetoothSummaryUpdaterTest {
|
||||
|
||||
@Test
|
||||
public void onBluetoothStateChanged_btEnabled_connected_shouldSendConnectedSummary() {
|
||||
prepareConnectedDevice(false);
|
||||
mAdapterEnabled[0] = true;
|
||||
mAdapterConnectionState[0] = BluetoothAdapter.STATE_CONNECTED;
|
||||
mBondedDevices.add(mConnectedDevice);
|
||||
mDeviceConnected[0] = true;
|
||||
|
||||
mSummaryUpdater.register(true);
|
||||
mSummaryUpdater.onBluetoothStateChanged(BluetoothAdapter.STATE_ON);
|
||||
|
||||
verify(mListener).onSummaryChanged(
|
||||
mContext.getString(R.string.bluetooth_connected_summary, DEVICE_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBluetoothStateChanged_btEnabled_connectedMisMatch_shouldSendNotConnected() {
|
||||
mAdapterEnabled[0] = true;
|
||||
mAdapterConnectionState[0] = BluetoothAdapter.STATE_CONNECTED;
|
||||
mBondedDevices.add(mConnectedDevice);
|
||||
// State mismatch
|
||||
mDeviceConnected[0] = false;
|
||||
|
||||
mSummaryUpdater.onBluetoothStateChanged(BluetoothAdapter.STATE_ON);
|
||||
|
||||
verify(mListener).onSummaryChanged(mContext.getString(R.string.disconnected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBluetoothStateChanged_btEnabled_notConnected_shouldSendDisconnectedMessage() {
|
||||
when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_DISCONNECTED);
|
||||
mSummaryUpdater.register(true);
|
||||
mAdapterEnabled[0] = true;
|
||||
mAdapterConnectionState[0] = BluetoothAdapter.STATE_DISCONNECTED;
|
||||
mBondedDevices.add(mConnectedDevice);
|
||||
// This should be ignored
|
||||
mDeviceConnected[0] = true;
|
||||
|
||||
mSummaryUpdater.onBluetoothStateChanged(BluetoothAdapter.STATE_TURNING_ON);
|
||||
|
||||
verify(mListener).onSummaryChanged(
|
||||
mContext.getString(R.string.disconnected));
|
||||
verify(mListener).onSummaryChanged(mContext.getString(R.string.disconnected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBluetoothStateChanged_ConnectedDisabledEnabled_shouldSendDisconnectedSummary() {
|
||||
final boolean[] connected = {false};
|
||||
final List<CachedBluetoothDevice> devices = new ArrayList<>();
|
||||
devices.add(mock(CachedBluetoothDevice.class));
|
||||
doAnswer(invocation -> connected[0]).when(devices.get(0)).isConnected();
|
||||
when(mBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy())
|
||||
.thenReturn(devices);
|
||||
when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_DISCONNECTED);
|
||||
prepareConnectedDevice(false);
|
||||
mAdapterEnabled[0] = true;
|
||||
mAdapterConnectionState[0] = BluetoothAdapter.STATE_DISCONNECTED;
|
||||
mBondedDevices.add(mConnectedDevice);
|
||||
mDeviceConnected[0] = false;
|
||||
|
||||
mSummaryUpdater.register(true);
|
||||
verify(mListener).onSummaryChanged(mContext.getString(R.string.disconnected));
|
||||
|
||||
connected[0] = true;
|
||||
when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_CONNECTED);
|
||||
mAdapterConnectionState[0] = BluetoothAdapter.STATE_CONNECTED;
|
||||
mDeviceConnected[0] = true;
|
||||
mSummaryUpdater.onConnectionStateChanged(null /* device */,
|
||||
BluetoothAdapter.STATE_CONNECTED);
|
||||
verify(mListener).onSummaryChanged(
|
||||
mContext.getString(R.string.bluetooth_connected_summary, DEVICE_NAME));
|
||||
|
||||
mAdapterEnabled[0] = false;
|
||||
mSummaryUpdater.onBluetoothStateChanged(BluetoothAdapter.STATE_OFF);
|
||||
verify(mListener).onSummaryChanged(mContext.getString(R.string.bluetooth_disabled));
|
||||
|
||||
connected[0] = false;
|
||||
// Turning ON means not enabled
|
||||
mSummaryUpdater.onBluetoothStateChanged(BluetoothAdapter.STATE_TURNING_ON);
|
||||
// There should still be only one invocation of disabled message
|
||||
verify(mListener).onSummaryChanged(mContext.getString(R.string.bluetooth_disabled));
|
||||
|
||||
mAdapterEnabled[0] = true;
|
||||
mDeviceConnected[0] = false;
|
||||
mSummaryUpdater.onBluetoothStateChanged(BluetoothAdapter.STATE_ON);
|
||||
verify(mListener, times(2)).onSummaryChanged(mContext.getString(R.string.disconnected));
|
||||
verify(mListener, times(4)).onSummaryChanged(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onConnectionStateChanged_connected_shouldSendConnectedMessage() {
|
||||
final List<CachedBluetoothDevice> devices = new ArrayList<>();
|
||||
devices.add(mock(CachedBluetoothDevice.class));
|
||||
when(devices.get(0).isConnected()).thenReturn(true);
|
||||
when(mBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy())
|
||||
.thenReturn(devices);
|
||||
when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_DISCONNECTED);
|
||||
prepareConnectedDevice(false);
|
||||
mAdapterEnabled[0] = true;
|
||||
mAdapterConnectionState[0] = BluetoothAdapter.STATE_CONNECTED;
|
||||
mBondedDevices.add(mConnectedDevice);
|
||||
mDeviceConnected[0] = true;
|
||||
|
||||
mSummaryUpdater.register(true);
|
||||
|
||||
when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_CONNECTED);
|
||||
mSummaryUpdater.onConnectionStateChanged(null /* device */,
|
||||
BluetoothAdapter.STATE_CONNECTED);
|
||||
|
||||
@@ -187,7 +224,22 @@ public class BluetoothSummaryUpdaterTest {
|
||||
|
||||
@Test
|
||||
public void onConnectionStateChanged_inconsistentState_shouldSendDisconnectedMessage() {
|
||||
mSummaryUpdater.register(true);
|
||||
mAdapterEnabled[0] = true;
|
||||
mAdapterConnectionState[0] = BluetoothAdapter.STATE_DISCONNECTED;
|
||||
mBondedDevices.add(mConnectedDevice);
|
||||
mDeviceConnected[0] = false;
|
||||
|
||||
mSummaryUpdater.onConnectionStateChanged(null /* device */,
|
||||
BluetoothAdapter.STATE_CONNECTED);
|
||||
|
||||
verify(mListener).onSummaryChanged(mContext.getString(R.string.disconnected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onConnectionStateChanged_noBondedDevice_shouldSendDisconnectedMessage() {
|
||||
mAdapterEnabled[0] = true;
|
||||
mAdapterConnectionState[0] = BluetoothAdapter.STATE_CONNECTED;
|
||||
|
||||
mSummaryUpdater.onConnectionStateChanged(null /* device */,
|
||||
BluetoothAdapter.STATE_CONNECTED);
|
||||
|
||||
@@ -197,8 +249,10 @@ public class BluetoothSummaryUpdaterTest {
|
||||
|
||||
@Test
|
||||
public void onConnectionStateChanged_connecting_shouldSendConnectingMessage() {
|
||||
mSummaryUpdater.register(true);
|
||||
when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_CONNECTING);
|
||||
// No need for bonded devices
|
||||
mAdapterEnabled[0] = true;
|
||||
mAdapterConnectionState[0] = BluetoothAdapter.STATE_CONNECTING;
|
||||
|
||||
mSummaryUpdater.onConnectionStateChanged(null /* device */,
|
||||
BluetoothAdapter.STATE_CONNECTING);
|
||||
|
||||
@@ -207,8 +261,10 @@ public class BluetoothSummaryUpdaterTest {
|
||||
|
||||
@Test
|
||||
public void onConnectionStateChanged_disconnecting_shouldSendDisconnectingMessage() {
|
||||
mSummaryUpdater.register(true);
|
||||
when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_DISCONNECTING);
|
||||
// No need for bonded devices
|
||||
mAdapterEnabled[0] = true;
|
||||
mAdapterConnectionState[0] = BluetoothAdapter.STATE_DISCONNECTING;
|
||||
|
||||
mSummaryUpdater.onConnectionStateChanged(null /* device */,
|
||||
BluetoothAdapter.STATE_DISCONNECTING);
|
||||
|
||||
@@ -217,7 +273,8 @@ public class BluetoothSummaryUpdaterTest {
|
||||
|
||||
@Test
|
||||
public void getConnectedDeviceSummary_hasConnectedDevice_returnOneDeviceSummary() {
|
||||
prepareConnectedDevice(false);
|
||||
mBondedDevices.add(mConnectedDevice);
|
||||
mDeviceConnected[0] = true;
|
||||
final String expectedSummary = mContext.getString(R.string.bluetooth_connected_summary,
|
||||
DEVICE_NAME);
|
||||
|
||||
@@ -226,28 +283,16 @@ public class BluetoothSummaryUpdaterTest {
|
||||
|
||||
@Test
|
||||
public void getConnectedDeviceSummary_multipleDevices_returnMultipleDevicesSummary() {
|
||||
prepareConnectedDevice(true);
|
||||
mBondedDevices.add(mConnectedDevice);
|
||||
mBondedDevices.add(mConnectedKeyBoardDevice);
|
||||
mDeviceConnected[0] = true;
|
||||
mDeviceConnected[1] = true;
|
||||
final String expectedSummary = mContext.getString(
|
||||
R.string.bluetooth_connected_multiple_devices_summary);
|
||||
|
||||
assertThat(mSummaryUpdater.getConnectedDeviceSummary()).isEqualTo(expectedSummary);
|
||||
}
|
||||
|
||||
private void prepareConnectedDevice(boolean multipleDevices) {
|
||||
final Set<BluetoothDevice> devices = new HashSet<>();
|
||||
doReturn(DEVICE_NAME).when(mConnectedDevice).getName();
|
||||
doReturn(true).when(mConnectedDevice).isConnected();
|
||||
devices.add(mConnectedDevice);
|
||||
if (multipleDevices) {
|
||||
// Add one more device if we need to test multiple devices
|
||||
doReturn(DEVICE_KEYBOARD_NAME).when(mConnectedKeyBoardDevice).getName();
|
||||
doReturn(true).when(mConnectedKeyBoardDevice).isConnected();
|
||||
devices.add(mConnectedKeyBoardDevice);
|
||||
}
|
||||
|
||||
doReturn(devices).when(mBtAdapter).getBondedDevices();
|
||||
}
|
||||
|
||||
private class SummaryListener implements OnSummaryChangeListener {
|
||||
String summary;
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ import android.support.v7.preference.Preference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -208,7 +208,7 @@ public class DeviceListPreferenceFragmentTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,21 @@
|
||||
*/
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.graph.BluetoothDeviceLayerDrawable;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -30,6 +37,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
@@ -40,7 +48,8 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = SettingsShadowResources.class)
|
||||
public class UtilsTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@@ -60,11 +69,27 @@ public class UtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showConnectingError_shouldLogBluetoothConnectError() {
|
||||
public void testShowConnectingError_shouldLogBluetoothConnectError() {
|
||||
when(mContext.getString(anyInt(), anyString())).thenReturn("testMessage");
|
||||
Utils.showConnectingError(mContext, "testName", mock(LocalBluetoothManager.class));
|
||||
|
||||
verify(mMetricsFeatureProvider).visible(eq(mContext), anyInt(),
|
||||
eq(MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT_ERROR));
|
||||
eq(MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT_ERROR));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBluetoothDrawable_noBatteryLevel_returnSimpleDrawable() {
|
||||
final Drawable drawable = Utils.getBluetoothDrawable(RuntimeEnvironment.application,
|
||||
R.drawable.ic_bt_laptop, BluetoothDevice.BATTERY_LEVEL_UNKNOWN, 1 /* iconScale */);
|
||||
|
||||
assertThat(drawable).isNotInstanceOf(BluetoothDeviceLayerDrawable.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBluetoothDrawable_hasBatteryLevel_returnLayerDrawable() {
|
||||
final Drawable drawable = Utils.getBluetoothDrawable(RuntimeEnvironment.application,
|
||||
R.drawable.ic_bt_laptop, 10 /* batteryLevel */, 1 /* iconScale */);
|
||||
|
||||
assertThat(drawable).isInstanceOf(BluetoothDeviceLayerDrawable.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,16 +22,19 @@ import android.nfc.NfcManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.nfc.NfcPreferenceController;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
@@ -50,19 +53,45 @@ import static org.mockito.Mockito.when;
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ConnectedDeviceDashboardFragmentTest {
|
||||
|
||||
@Mock
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
Context mContext;
|
||||
|
||||
@Mock
|
||||
private PackageManager mManager;
|
||||
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private SmsMirroringFeatureProvider mFeatureProvider;
|
||||
private ConnectedDeviceDashboardFragment mFragment;
|
||||
private TestSmsMirroringPreferenceController mSmsMirroringPreferenceController;
|
||||
|
||||
private static final class TestSmsMirroringPreferenceController
|
||||
extends SmsMirroringPreferenceController implements PreferenceControllerMixin {
|
||||
|
||||
private boolean mIsAvailable;
|
||||
|
||||
public TestSmsMirroringPreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mIsAvailable;
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mFeatureProvider = mFeatureFactory.smsMirroringFeatureProvider;
|
||||
|
||||
mFragment = new ConnectedDeviceDashboardFragment();
|
||||
when(mContext.getPackageManager()).thenReturn(mManager);
|
||||
|
||||
mSmsMirroringPreferenceController = new TestSmsMirroringPreferenceController(mContext);
|
||||
when(mFeatureProvider.getController(mContext)).thenReturn(
|
||||
mSmsMirroringPreferenceController);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,12 +131,36 @@ public class ConnectedDeviceDashboardFragmentTest {
|
||||
assertThat(keys).doesNotContain(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_NoSmsMirroring_KeyAdded() {
|
||||
when(mFeatureProvider.shouldShowSmsMirroring(mContext)).thenReturn(false);
|
||||
mSmsMirroringPreferenceController.mIsAvailable = false;
|
||||
|
||||
final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||
mContext);
|
||||
|
||||
assertThat(keys).isNotNull();
|
||||
assertThat(keys).contains(mSmsMirroringPreferenceController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_SmsMirroring_KeyNotAdded() {
|
||||
when(mFeatureProvider.shouldShowSmsMirroring(mContext)).thenReturn(true);
|
||||
mSmsMirroringPreferenceController.mIsAvailable = true;
|
||||
|
||||
final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||
mContext);
|
||||
|
||||
assertThat(keys).isNotNull();
|
||||
assertThat(keys).doesNotContain(mSmsMirroringPreferenceController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonIndexableKeys_existInXmlLayout() {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
|
||||
final List<String> niks = ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(context);
|
||||
.getNonIndexableKeys(mContext);
|
||||
final int xmlId = (new ConnectedDeviceDashboardFragment()).getPreferenceScreenResId();
|
||||
|
||||
final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
|
||||
@@ -141,6 +194,7 @@ public class ConnectedDeviceDashboardFragmentTest {
|
||||
final SummaryLoader summaryLoader = mock(SummaryLoader.class);
|
||||
|
||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||
when(mContext.getSystemService(NFC_SERVICE)).thenReturn(null);
|
||||
|
||||
SummaryLoader.SummaryProvider provider =
|
||||
new ConnectedDeviceDashboardFragment.SummaryProvider(mContext, summaryLoader);
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package com.android.settings.core.codeinspection;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.instrumentation.InstrumentableFragmentCodeInspector;
|
||||
import com.android.settings.search.SearchIndexProviderCodeInspector;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -39,7 +39,7 @@ import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
|
||||
.FIELD_SETTINGS_PREFERENCE_CHANGE_FLOAT_VALUE;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
|
||||
.FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE;
|
||||
.FIELD_SETTINGS_PREFERENCE_CHANGE_INT_VALUE;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
|
||||
.FIELD_SETTINGS_PREFERENCE_CHANGE_NAME;
|
||||
import static org.mockito.Matchers.any;
|
||||
@@ -88,7 +88,7 @@ public class SharedPreferenceLoggerTest {
|
||||
|
||||
verify(mMetricsFeature, times(6)).action(any(Context.class), anyInt(),
|
||||
argThat(mNamePairMatcher),
|
||||
argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, Long.class)));
|
||||
argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_INT_VALUE, Integer.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,10 +103,10 @@ public class SharedPreferenceLoggerTest {
|
||||
|
||||
verify(mMetricsFeature).action(any(Context.class), anyInt(),
|
||||
argThat(mNamePairMatcher),
|
||||
argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, true)));
|
||||
argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_INT_VALUE, true)));
|
||||
verify(mMetricsFeature, times(3)).action(any(Context.class), anyInt(),
|
||||
argThat(mNamePairMatcher),
|
||||
argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, false)));
|
||||
argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_INT_VALUE, false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,7 +120,33 @@ public class SharedPreferenceLoggerTest {
|
||||
|
||||
verify(mMetricsFeature, times(4)).action(any(Context.class), anyInt(),
|
||||
argThat(mNamePairMatcher),
|
||||
argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, Long.class)));
|
||||
argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_INT_VALUE, Integer.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putLong_biggerThanIntMax_shouldLogIntMax() {
|
||||
final SharedPreferences.Editor editor = mSharedPrefLogger.edit();
|
||||
final long veryBigNumber = 500L + Integer.MAX_VALUE;
|
||||
editor.putLong(TEST_KEY, 1);
|
||||
editor.putLong(TEST_KEY, veryBigNumber);
|
||||
|
||||
verify(mMetricsFeature).action(any(Context.class), anyInt(),
|
||||
argThat(mNamePairMatcher),
|
||||
argThat(pairMatches(
|
||||
FIELD_SETTINGS_PREFERENCE_CHANGE_INT_VALUE, Integer.MAX_VALUE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putLong_smallerThanIntMin_shouldLogIntMin() {
|
||||
final SharedPreferences.Editor editor = mSharedPrefLogger.edit();
|
||||
final long veryNegativeNumber = -500L + Integer.MIN_VALUE;
|
||||
editor.putLong(TEST_KEY, 1);
|
||||
editor.putLong(TEST_KEY, veryNegativeNumber);
|
||||
|
||||
verify(mMetricsFeature).action(any(Context.class), anyInt(),
|
||||
argThat(mNamePairMatcher),
|
||||
argThat(pairMatches(
|
||||
FIELD_SETTINGS_PREFERENCE_CHANGE_INT_VALUE, Integer.MIN_VALUE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -152,7 +178,13 @@ public class SharedPreferenceLoggerTest {
|
||||
|
||||
private ArgumentMatcher<Pair<Integer, Object>> pairMatches(int tag, boolean bool) {
|
||||
return pair -> pair.first == tag
|
||||
&& Platform.isInstanceOfType(pair.second, Long.class)
|
||||
&& pair.second.equals((bool ? 1L : 0L));
|
||||
&& Platform.isInstanceOfType(pair.second, Integer.class)
|
||||
&& pair.second.equals((bool ? 1 : 0));
|
||||
}
|
||||
|
||||
private ArgumentMatcher<Pair<Integer, Object>> pairMatches(int tag, int val) {
|
||||
return pair -> pair.first == tag
|
||||
&& Platform.isInstanceOfType(pair.second, Integer.class)
|
||||
&& pair.second.equals(val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.any;
|
||||
@@ -38,6 +37,7 @@ import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Pair;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
@@ -52,7 +52,6 @@ import com.android.settings.dashboard.suggestions.SuggestionAdapter;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
@@ -68,7 +67,6 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@@ -77,7 +75,6 @@ import java.util.List;
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class,
|
||||
ShadowDynamicIndexableContentMonitor.class
|
||||
})
|
||||
public class DashboardAdapterTest {
|
||||
|
||||
@@ -93,6 +90,8 @@ public class DashboardAdapterTest {
|
||||
private ArgumentCaptor<Integer> mActionCategoryCaptor = ArgumentCaptor.forClass(Integer.class);
|
||||
@Captor
|
||||
private ArgumentCaptor<String> mActionPackageCaptor = ArgumentCaptor.forClass(String.class);
|
||||
@Captor
|
||||
private ArgumentCaptor<Pair> mTaggedDataCaptor = ArgumentCaptor.forClass(Pair.class);
|
||||
private FakeFeatureFactory mFactory;
|
||||
private DashboardAdapter mDashboardAdapter;
|
||||
private DashboardAdapter.SuggestionAndConditionHeaderHolder mSuggestionHolder;
|
||||
@@ -127,112 +126,143 @@ public class DashboardAdapterTest {
|
||||
@Test
|
||||
public void testSuggestionsLogs_NotExpanded() {
|
||||
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
||||
|
||||
verify(mFactory.metricsFeatureProvider, times(2)).action(
|
||||
any(Context.class), mActionCategoryCaptor.capture(),
|
||||
mActionPackageCaptor.capture());
|
||||
String[] expectedPackages = new String[]{"pkg1", "pkg2"};
|
||||
Integer[] expectedActions = new Integer[]{
|
||||
mActionPackageCaptor.capture(),
|
||||
mTaggedDataCaptor.capture());
|
||||
assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION
|
||||
};
|
||||
assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
|
||||
assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION);
|
||||
assertThat(mActionPackageCaptor.getAllValues()).containsExactly("pkg1", "pkg2");
|
||||
assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestionsLogs_NotExpandedAndPaused() {
|
||||
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
||||
|
||||
mDashboardAdapter.onPause();
|
||||
|
||||
verify(mFactory.metricsFeatureProvider, times(4)).action(
|
||||
any(Context.class), mActionCategoryCaptor.capture(),
|
||||
mActionPackageCaptor.capture());
|
||||
String[] expectedPackages = new String[]{"pkg1", "pkg2", "pkg1", "pkg2"};
|
||||
Integer[] expectedActions = new Integer[]{
|
||||
mActionPackageCaptor.capture(),
|
||||
mTaggedDataCaptor.capture());
|
||||
assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION};
|
||||
assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
|
||||
assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION);
|
||||
assertThat(mActionPackageCaptor.getAllValues()).containsExactly(
|
||||
"pkg1", "pkg2", "pkg1", "pkg2");
|
||||
assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestionsLogs_Expanded() {
|
||||
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
||||
|
||||
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
|
||||
mSuggestionHolder.itemView.callOnClick();
|
||||
|
||||
verify(mFactory.metricsFeatureProvider, times(3)).action(
|
||||
any(Context.class), mActionCategoryCaptor.capture(),
|
||||
mActionPackageCaptor.capture());
|
||||
String[] expectedPackages = new String[]{"pkg1", "pkg2", "pkg3"};
|
||||
Integer[] expectedActions = new Integer[]{
|
||||
mActionPackageCaptor.capture(),
|
||||
mTaggedDataCaptor.capture());
|
||||
assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION
|
||||
};
|
||||
assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
|
||||
assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION);
|
||||
assertThat(mActionPackageCaptor.getAllValues()).containsExactly(
|
||||
"pkg1", "pkg2", "pkg3");
|
||||
assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestionsLogs_ExpandedAndPaused() {
|
||||
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
||||
|
||||
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
|
||||
mSuggestionHolder.itemView.callOnClick();
|
||||
mDashboardAdapter.onPause();
|
||||
|
||||
verify(mFactory.metricsFeatureProvider, times(6)).action(
|
||||
any(Context.class), mActionCategoryCaptor.capture(),
|
||||
mActionPackageCaptor.capture());
|
||||
String[] expectedPackages = new String[]{"pkg1", "pkg2", "pkg3", "pkg1", "pkg2", "pkg3"};
|
||||
Integer[] expectedActions = new Integer[]{
|
||||
mActionPackageCaptor.capture(),
|
||||
mTaggedDataCaptor.capture());
|
||||
assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION
|
||||
};
|
||||
assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
|
||||
assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION);
|
||||
assertThat(mActionPackageCaptor.getAllValues()).containsExactly(
|
||||
"pkg1", "pkg2", "pkg3", "pkg1", "pkg2", "pkg3");
|
||||
assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestionsLogs_ExpandedAfterPause() {
|
||||
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
||||
|
||||
mDashboardAdapter.onPause();
|
||||
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
|
||||
mSuggestionHolder.itemView.callOnClick();
|
||||
|
||||
verify(mFactory.metricsFeatureProvider, times(7)).action(
|
||||
any(Context.class), mActionCategoryCaptor.capture(),
|
||||
mActionPackageCaptor.capture());
|
||||
String[] expectedPackages = new String[]{
|
||||
"pkg1", "pkg2", "pkg1", "pkg2", "pkg1", "pkg2", "pkg3"};
|
||||
Integer[] expectedActions = new Integer[]{
|
||||
mActionPackageCaptor.capture(),
|
||||
mTaggedDataCaptor.capture());
|
||||
assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION
|
||||
};
|
||||
assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
|
||||
assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION);
|
||||
assertThat(mActionPackageCaptor.getAllValues()).containsExactly(
|
||||
"pkg1", "pkg2", "pkg1", "pkg2", "pkg1", "pkg2", "pkg3");
|
||||
assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestionsLogs_ExpandedAfterPauseAndPausedAgain() {
|
||||
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
||||
|
||||
mDashboardAdapter.onPause();
|
||||
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
|
||||
mSuggestionHolder.itemView.callOnClick();
|
||||
mDashboardAdapter.onPause();
|
||||
|
||||
verify(mFactory.metricsFeatureProvider, times(10)).action(
|
||||
any(Context.class), mActionCategoryCaptor.capture(),
|
||||
mActionPackageCaptor.capture());
|
||||
String[] expectedPackages = new String[]{
|
||||
"pkg1", "pkg2", "pkg1", "pkg2", "pkg1", "pkg2", "pkg3", "pkg1", "pkg2", "pkg3"};
|
||||
Integer[] expectedActions = new Integer[]{
|
||||
mActionPackageCaptor.capture(),
|
||||
mTaggedDataCaptor.capture());
|
||||
assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
|
||||
@@ -242,63 +272,82 @@ public class DashboardAdapterTest {
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION
|
||||
};
|
||||
assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
|
||||
assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION);
|
||||
assertThat(mActionPackageCaptor.getAllValues()).containsExactly(
|
||||
"pkg1", "pkg2", "pkg1", "pkg2", "pkg1", "pkg2", "pkg3", "pkg1", "pkg2", "pkg3");
|
||||
assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShown() {
|
||||
setupSuggestions(makeSuggestions("pkg1"));
|
||||
|
||||
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
|
||||
mSuggestionHolder.itemView.callOnClick();
|
||||
|
||||
verify(mFactory.metricsFeatureProvider, times(1)).action(
|
||||
any(Context.class), mActionCategoryCaptor.capture(),
|
||||
mActionPackageCaptor.capture());
|
||||
String[] expectedPackages = new String[]{"pkg1"};
|
||||
Integer[] expectedActions = new Integer[]{
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
};
|
||||
assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
|
||||
assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
|
||||
mActionPackageCaptor.capture(),
|
||||
mTaggedDataCaptor.capture());
|
||||
assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION);
|
||||
assertThat(mActionPackageCaptor.getAllValues()).containsExactly("pkg1");
|
||||
assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAndPaused() {
|
||||
setupSuggestions(makeSuggestions("pkg1"));
|
||||
|
||||
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
|
||||
mSuggestionHolder.itemView.callOnClick();
|
||||
mDashboardAdapter.onPause();
|
||||
|
||||
verify(mFactory.metricsFeatureProvider, times(2)).action(
|
||||
any(Context.class), mActionCategoryCaptor.capture(),
|
||||
mActionPackageCaptor.capture());
|
||||
String[] expectedPackages = new String[]{"pkg1", "pkg1"};
|
||||
Integer[] expectedActions = new Integer[]{
|
||||
mActionPackageCaptor.capture(),
|
||||
mTaggedDataCaptor.capture());
|
||||
assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION
|
||||
};
|
||||
assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
|
||||
assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION);
|
||||
assertThat(mActionPackageCaptor.getAllValues()).containsExactly("pkg1", "pkg1");
|
||||
assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAfterPause() {
|
||||
setupSuggestions(makeSuggestions("pkg1"));
|
||||
|
||||
mDashboardAdapter.onPause();
|
||||
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
|
||||
mSuggestionHolder.itemView.callOnClick();
|
||||
|
||||
verify(mFactory.metricsFeatureProvider, times(3)).action(
|
||||
any(Context.class), mActionCategoryCaptor.capture(),
|
||||
mActionPackageCaptor.capture());
|
||||
String[] expectedPackages = new String[]{"pkg1", "pkg1", "pkg1"};
|
||||
Integer[] expectedActions = new Integer[]{
|
||||
mActionPackageCaptor.capture(),
|
||||
mTaggedDataCaptor.capture());
|
||||
assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION
|
||||
};
|
||||
assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
|
||||
assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION);
|
||||
assertThat(mActionPackageCaptor.getAllValues()).containsExactly("pkg1", "pkg1", "pkg1");
|
||||
assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -308,26 +357,69 @@ public class DashboardAdapterTest {
|
||||
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
|
||||
mSuggestionHolder.itemView.callOnClick();
|
||||
mDashboardAdapter.onPause();
|
||||
|
||||
verify(mFactory.metricsFeatureProvider, times(4)).action(
|
||||
any(Context.class), mActionCategoryCaptor.capture(),
|
||||
mActionPackageCaptor.capture());
|
||||
String[] expectedPackages = new String[]{"pkg1", "pkg1", "pkg1", "pkg1"};
|
||||
Integer[] expectedActions = new Integer[]{
|
||||
mActionPackageCaptor.capture(),
|
||||
mTaggedDataCaptor.capture());
|
||||
assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION
|
||||
};
|
||||
assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
|
||||
assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION);
|
||||
assertThat(mActionPackageCaptor.getAllValues()).containsExactly(
|
||||
"pkg1", "pkg1", "pkg1", "pkg1");
|
||||
assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestioDismissed_notOnlySuggestion_updateSuggestionOnly() {
|
||||
public void testSuggestionsLogs_SmartSuggestionEnabled() {
|
||||
when(mFactory.suggestionsFeatureProvider
|
||||
.isSmartSuggestionEnabled(any(Context.class))).thenReturn(true);
|
||||
setupSuggestions(makeSuggestions("pkg1"));
|
||||
|
||||
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
|
||||
mSuggestionHolder.itemView.callOnClick();
|
||||
mDashboardAdapter.onPause();
|
||||
|
||||
verify(mFactory.metricsFeatureProvider, times(2)).action(
|
||||
any(Context.class), mActionCategoryCaptor.capture(),
|
||||
mActionPackageCaptor.capture(),
|
||||
mTaggedDataCaptor.capture());
|
||||
assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
|
||||
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION);
|
||||
assertThat(mActionPackageCaptor.getAllValues()).containsExactly("pkg1", "pkg1");
|
||||
assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 1),
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestionsLogs_nullSuggestionsList_shouldNotCrash() {
|
||||
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3", "pkg4", "pkg5"));
|
||||
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
|
||||
|
||||
// set suggestions to null
|
||||
final DashboardData prevData = mDashboardAdapter.mDashboardData;
|
||||
mDashboardAdapter.mDashboardData = new DashboardData.Builder(prevData)
|
||||
.setSuggestions(null)
|
||||
.build();
|
||||
|
||||
mSuggestionHolder.itemView.callOnClick();
|
||||
// no crash
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestionDismissed_notOnlySuggestion_updateSuggestionOnly() {
|
||||
final DashboardAdapter adapter =
|
||||
spy(new DashboardAdapter(mContext, null, null, null, null));
|
||||
final List<Tile> suggestions = makeSuggestions("pkg1", "pkg2", "pkg3");
|
||||
adapter.setCategoriesAndSuggestions(new ArrayList<>(), suggestions);
|
||||
adapter.setCategoriesAndSuggestions(null /* category */, suggestions);
|
||||
|
||||
final RecyclerView data = mock(RecyclerView.class);
|
||||
when(data.getResources()).thenReturn(mResources);
|
||||
@@ -364,7 +456,7 @@ public class DashboardAdapterTest {
|
||||
makeSuggestions("pkg1", "pkg2", "pkg3", "pkg4");
|
||||
final DashboardAdapter adapter = spy(new DashboardAdapter(mContext, null /*savedInstance */,
|
||||
null /* conditions */, null /* suggestionParser */, null /* callback */));
|
||||
adapter.setCategoriesAndSuggestions(new ArrayList<>(), suggestions);
|
||||
adapter.setCategoriesAndSuggestions(null /* category */, suggestions);
|
||||
adapter.onBindConditionAndSuggestion(
|
||||
holder, DashboardAdapter.SUGGESTION_CONDITION_HEADER_POSITION);
|
||||
// default mode, only displaying 2 suggestions
|
||||
@@ -373,16 +465,16 @@ public class DashboardAdapterTest {
|
||||
|
||||
// verify operations that access the lists will not cause ConcurrentModificationException
|
||||
assertThat(holder.data.getAdapter().getItemCount()).isEqualTo(1);
|
||||
adapter.setCategoriesAndSuggestions(new ArrayList<>(), suggestions);
|
||||
adapter.setCategoriesAndSuggestions(null /* category */, suggestions);
|
||||
// should not crash
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestioDismissed_onlySuggestion_updateDashboardData() {
|
||||
public void testSuggestionDismissed_onlySuggestion_updateDashboardData() {
|
||||
DashboardAdapter adapter =
|
||||
spy(new DashboardAdapter(mContext, null, null, null, null));
|
||||
final List<Tile> suggestions = makeSuggestions("pkg1");
|
||||
adapter.setCategoriesAndSuggestions(new ArrayList<>(), suggestions);
|
||||
adapter.setCategoriesAndSuggestions(null /* category */, suggestions);
|
||||
final DashboardData dashboardData = adapter.mDashboardData;
|
||||
reset(adapter); // clear interactions tracking
|
||||
|
||||
@@ -403,7 +495,27 @@ public class DashboardAdapterTest {
|
||||
packages.get(0).isIconTintable = true;
|
||||
packages.get(0).icon = mockIcon;
|
||||
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(Collections.emptyList(), packages);
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(null /* category */, packages);
|
||||
|
||||
verify(mockIcon).setTint(eq(0x89000000));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCategories_iconTinted() {
|
||||
TypedArray mockTypedArray = mock(TypedArray.class);
|
||||
doReturn(mockTypedArray).when(mContext).obtainStyledAttributes(any(int[].class));
|
||||
doReturn(0x89000000).when(mockTypedArray).getColor(anyInt(), anyInt());
|
||||
|
||||
final DashboardCategory category = mock(DashboardCategory.class);
|
||||
final List<Tile> tiles = new ArrayList<>();
|
||||
final Icon mockIcon = mock(Icon.class);
|
||||
final Tile tile = new Tile();
|
||||
tile.isIconTintable = true;
|
||||
tile.icon = mockIcon;
|
||||
tiles.add(tile);
|
||||
category.tiles = tiles;
|
||||
|
||||
mDashboardAdapter.setCategory(category);
|
||||
|
||||
verify(mockIcon).setTint(eq(0x89000000));
|
||||
}
|
||||
@@ -412,7 +524,7 @@ public class DashboardAdapterTest {
|
||||
public void testSetCategoriesAndSuggestions_limitSuggestionSize() {
|
||||
List<Tile> packages =
|
||||
makeSuggestions("pkg1", "pkg2", "pkg3", "pkg4", "pkg5", "pkg6", "pkg7");
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(Collections.emptyList(), packages);
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(null /* category */, packages);
|
||||
|
||||
assertThat(mDashboardAdapter.mDashboardData.getSuggestions().size())
|
||||
.isEqualTo(DashboardAdapter.MAX_SUGGESTION_TO_SHOW);
|
||||
@@ -422,12 +534,12 @@ public class DashboardAdapterTest {
|
||||
public void testBindConditionAndSuggestion_shouldSetSuggestionAdapterAndNoCrash() {
|
||||
mDashboardAdapter = new DashboardAdapter(mContext, null, null, null, null);
|
||||
final List<Tile> suggestions = makeSuggestions("pkg1");
|
||||
final List<DashboardCategory> categories = new ArrayList<>();
|
||||
final DashboardCategory category = mock(DashboardCategory.class);
|
||||
final List<Tile> tiles = new ArrayList<>();
|
||||
tiles.add(mock(Tile.class));
|
||||
category.tiles = tiles;
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(categories, suggestions);
|
||||
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(category, suggestions);
|
||||
|
||||
final RecyclerView data = mock(RecyclerView.class);
|
||||
when(data.getResources()).thenReturn(mResources);
|
||||
@@ -446,7 +558,7 @@ public class DashboardAdapterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindConditionAndSuggestion_emptySuggestion_shouldSetConditionAdapter() {
|
||||
public void testBindConditionAndSuggestion_emptySuggestion_shouldSetConditionAdpater() {
|
||||
final Bundle savedInstance = new Bundle();
|
||||
savedInstance.putInt(DashboardAdapter.STATE_SUGGESTION_CONDITION_MODE,
|
||||
DashboardData.HEADER_MODE_FULLY_EXPANDED);
|
||||
@@ -454,13 +566,11 @@ public class DashboardAdapterTest {
|
||||
null /* SuggestionParser */, null /* SuggestionDismissController.Callback */);
|
||||
|
||||
final List<Tile> suggestions = new ArrayList<>();
|
||||
final List<DashboardCategory> categories = new ArrayList<>();
|
||||
final DashboardCategory category = mock(DashboardCategory.class);
|
||||
categories.add(category);
|
||||
final List<Tile> tiles = new ArrayList<>();
|
||||
tiles.add(mock(Tile.class));
|
||||
category.tiles = tiles;
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(categories, suggestions);
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(category, suggestions);
|
||||
|
||||
final RecyclerView data = mock(RecyclerView.class);
|
||||
when(data.getResources()).thenReturn(mResources);
|
||||
@@ -489,7 +599,7 @@ public class DashboardAdapterTest {
|
||||
}
|
||||
|
||||
private void setupSuggestions(List<Tile> suggestions) {
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(new ArrayList<>(), suggestions);
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(null /* category */, suggestions);
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
mSuggestionHolder = new DashboardAdapter.SuggestionAndConditionHeaderHolder(
|
||||
LayoutInflater.from(context).inflate(
|
||||
|
||||
@@ -16,14 +16,24 @@
|
||||
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import static com.android.settings.dashboard.DashboardData.STABLE_ID_CONDITION_CONTAINER;
|
||||
import static com.android.settings.dashboard.DashboardData.STABLE_ID_SUGGESTION_CONDITION_FOOTER;
|
||||
import static com.android.settings.dashboard.DashboardData.STABLE_ID_SUGGESTION_CONTAINER;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.util.DiffUtil;
|
||||
import android.support.v7.util.ListUpdateCallback;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.conditional.AirplaneModeCondition;
|
||||
import com.android.settings.dashboard.conditional.Condition;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -33,12 +43,10 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import java.util.Objects;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@@ -80,55 +88,66 @@ public class DashboardDataTest {
|
||||
twoItemsConditions.add(mTestCondition);
|
||||
twoItemsConditions.add(mSecondCondition);
|
||||
|
||||
// Build categories
|
||||
final List<DashboardCategory> categories = new ArrayList<>();
|
||||
// Build category
|
||||
mTestCategoryTile.title = TEST_CATEGORY_TILE_TITLE;
|
||||
mDashboardCategory.title = "test";
|
||||
mDashboardCategory.tiles = new ArrayList<>();
|
||||
mDashboardCategory.tiles.add(mTestCategoryTile);
|
||||
categories.add(mDashboardCategory);
|
||||
|
||||
// Build DashboardData
|
||||
mDashboardDataWithOneConditions = new DashboardData.Builder()
|
||||
.setConditions(oneItemConditions)
|
||||
.setCategories(categories)
|
||||
.setCategory(mDashboardCategory)
|
||||
.setSuggestions(suggestions)
|
||||
.setSuggestionConditionMode(DashboardData.HEADER_MODE_FULLY_EXPANDED)
|
||||
.build();
|
||||
|
||||
mDashboardDataWithTwoConditions = new DashboardData.Builder()
|
||||
.setConditions(twoItemsConditions)
|
||||
.setCategories(categories)
|
||||
.setCategory(mDashboardCategory)
|
||||
.setSuggestions(suggestions)
|
||||
.setSuggestionConditionMode(DashboardData.HEADER_MODE_FULLY_EXPANDED)
|
||||
.build();
|
||||
|
||||
mDashboardDataWithNoItems = new DashboardData.Builder()
|
||||
.setConditions(null)
|
||||
.setCategories(null)
|
||||
.setCategory(null)
|
||||
.setSuggestions(null)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildItemsData_shouldSetstableId() {
|
||||
final List<DashboardData.Item> items = mDashboardDataWithOneConditions.getItemList();
|
||||
|
||||
// Header, suggestion, condition, footer, 1 tile
|
||||
assertThat(items).hasSize(4);
|
||||
|
||||
assertThat(items.get(0).id).isEqualTo(STABLE_ID_SUGGESTION_CONTAINER);
|
||||
assertThat(items.get(1).id).isEqualTo(STABLE_ID_CONDITION_CONTAINER);
|
||||
assertThat(items.get(2).id).isEqualTo(STABLE_ID_SUGGESTION_CONDITION_FOOTER);
|
||||
assertThat(items.get(3).id).isEqualTo(Objects.hash(mTestCategoryTile.title));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildItemsData_containsAllData() {
|
||||
final Object[] expectedObjects = {
|
||||
mDashboardDataWithOneConditions.getSuggestions(),
|
||||
mDashboardDataWithOneConditions.getConditions(),
|
||||
null, mDashboardCategory, mTestCategoryTile};
|
||||
mDashboardDataWithOneConditions.getSuggestions(),
|
||||
mDashboardDataWithOneConditions.getConditions(),
|
||||
null, mTestCategoryTile};
|
||||
final int expectedSize = expectedObjects.length;
|
||||
|
||||
assertThat(mDashboardDataWithOneConditions.getItemList().size())
|
||||
.isEqualTo(expectedSize);
|
||||
assertThat(mDashboardDataWithOneConditions.getItemList()).hasSize(expectedSize);
|
||||
|
||||
for (int i = 0; i < expectedSize; i++) {
|
||||
final Object item = mDashboardDataWithOneConditions.getItemEntityByPosition(i);
|
||||
if (item instanceof List) {
|
||||
assertThat(item).isEqualTo(expectedObjects[i]);
|
||||
} else if (item instanceof DashboardData.SuggestionConditionHeaderData) {
|
||||
DashboardData.SuggestionConditionHeaderData i1 =
|
||||
(DashboardData.SuggestionConditionHeaderData)item;
|
||||
(DashboardData.SuggestionConditionHeaderData) item;
|
||||
DashboardData.SuggestionConditionHeaderData i2 =
|
||||
(DashboardData.SuggestionConditionHeaderData)expectedObjects[i];
|
||||
(DashboardData.SuggestionConditionHeaderData) expectedObjects[i];
|
||||
assertThat(i1.title).isEqualTo(i2.title);
|
||||
assertThat(i1.conditionCount).isEqualTo(i2.conditionCount);
|
||||
assertThat(i1.hiddenSuggestionCount).isEqualTo(i2.hiddenSuggestionCount);
|
||||
@@ -189,22 +208,76 @@ public class DashboardDataTest {
|
||||
// Item in position 2 is the condition container containing the list of conditions, which
|
||||
// gets 1 more item
|
||||
testResultData.add(new ListUpdateResult.ResultData(
|
||||
ListUpdateResult.ResultData.TYPE_OPERATION_CHANGE, 1, 1));
|
||||
ListUpdateResult.ResultData.TYPE_OPERATION_CHANGE, 1, 1));
|
||||
|
||||
testDiffUtil(mDashboardDataWithOneConditions,
|
||||
mDashboardDataWithTwoConditions, testResultData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiffUtil_RemoveOneSuggestion_causeItemRemoveAndChange() {
|
||||
//Build testResultData
|
||||
final List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
|
||||
testResultData.add(new ListUpdateResult.ResultData(
|
||||
ListUpdateResult.ResultData.TYPE_OPERATION_REMOVE, 0, 1));
|
||||
testResultData.add(new ListUpdateResult.ResultData(
|
||||
ListUpdateResult.ResultData.TYPE_OPERATION_CHANGE, 1, 1));
|
||||
// Build DashboardData
|
||||
final List<Condition> oneItemConditions = new ArrayList<>();
|
||||
when(mTestCondition.shouldShow()).thenReturn(true);
|
||||
oneItemConditions.add(mTestCondition);
|
||||
final List<Tile> suggestions = new ArrayList<>();
|
||||
mTestSuggestion.title = TEST_SUGGESTION_TITLE;
|
||||
suggestions.add(mTestSuggestion);
|
||||
|
||||
final DashboardData oldData = new DashboardData.Builder()
|
||||
.setConditions(oneItemConditions)
|
||||
.setCategory(mDashboardCategory)
|
||||
.setSuggestions(suggestions)
|
||||
.setSuggestionConditionMode(DashboardData.HEADER_MODE_DEFAULT)
|
||||
.build();
|
||||
final DashboardData newData = new DashboardData.Builder()
|
||||
.setConditions(oneItemConditions)
|
||||
.setSuggestions(null)
|
||||
.setCategory(mDashboardCategory)
|
||||
.setSuggestionConditionMode(DashboardData.HEADER_MODE_DEFAULT)
|
||||
.build();
|
||||
|
||||
testDiffUtil(oldData, newData, testResultData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiffUtil_DeleteAllData_ResultDataOneDeleted() {
|
||||
//Build testResultData
|
||||
final List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
|
||||
testResultData.add(new ListUpdateResult.ResultData(
|
||||
ListUpdateResult.ResultData.TYPE_OPERATION_REMOVE, 0, 5));
|
||||
ListUpdateResult.ResultData.TYPE_OPERATION_REMOVE, 0, 4));
|
||||
|
||||
testDiffUtil(mDashboardDataWithOneConditions, mDashboardDataWithNoItems, testResultData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiffUtil_typeSuggestedContainer_ResultDataNothingChanged() {
|
||||
//Build testResultData
|
||||
final List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
|
||||
testResultData.add(new ListUpdateResult.ResultData(
|
||||
ListUpdateResult.ResultData.TYPE_OPERATION_CHANGE, 0, 1));
|
||||
Tile tile = new Tile();
|
||||
tile.remoteViews = mock(RemoteViews.class);
|
||||
|
||||
DashboardData prevData = new DashboardData.Builder()
|
||||
.setConditions(null)
|
||||
.setCategory(null)
|
||||
.setSuggestions(Arrays.asList(tile))
|
||||
.build();
|
||||
DashboardData currentData = new DashboardData.Builder()
|
||||
.setConditions(null)
|
||||
.setCategory(null)
|
||||
.setSuggestions(Arrays.asList(tile))
|
||||
.build();
|
||||
testDiffUtil(prevData, currentData, testResultData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test when using the
|
||||
* {@link com.android.settings.dashboard.DashboardData.ItemsDataDiffCallback}
|
||||
@@ -223,10 +296,6 @@ public class DashboardDataTest {
|
||||
* <p>
|
||||
* Because baseResultData and {@paramref testResultData} don't have sequence. When do the
|
||||
* comparison, we will sort them first and then compare the inside data from them one by one.
|
||||
*
|
||||
* @param baseDashboardData
|
||||
* @param diffDashboardData
|
||||
* @param testResultData
|
||||
*/
|
||||
private void testDiffUtil(DashboardData baseDashboardData, DashboardData diffDashboardData,
|
||||
List<ListUpdateResult.ResultData> testResultData) {
|
||||
|
||||
@@ -19,9 +19,9 @@ package com.android.settings.dashboard;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.search.DatabaseIndexingUtils;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@@ -47,8 +47,8 @@ public class DashboardFragmentSearchIndexProviderInspector {
|
||||
if (provider == null) {
|
||||
return true;
|
||||
}
|
||||
final List<PreferenceController> controllersFromSearchIndexProvider;
|
||||
final List<PreferenceController> controllersFromFragment;
|
||||
final List<AbstractPreferenceController> controllersFromSearchIndexProvider;
|
||||
final List<AbstractPreferenceController> controllersFromFragment;
|
||||
try {
|
||||
controllersFromSearchIndexProvider = provider.getPreferenceControllers(context);
|
||||
} catch (Throwable e) {
|
||||
|
||||
@@ -24,7 +24,10 @@ import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
@@ -32,12 +35,14 @@ import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.drawer.TileUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -126,7 +131,7 @@ public class DashboardFragmentTest {
|
||||
|
||||
@Test
|
||||
public void onAttach_shouldCreatePlaceholderPreferenceController() {
|
||||
final PreferenceController controller = mTestFragment.getPreferenceController(
|
||||
final AbstractPreferenceController controller = mTestFragment.getPreferenceController(
|
||||
DashboardTilePlaceholderPreferenceController.class);
|
||||
|
||||
assertThat(controller).isNotNull();
|
||||
@@ -134,9 +139,11 @@ public class DashboardFragmentTest {
|
||||
|
||||
@Test
|
||||
public void updateState_skipUnavailablePrefs() {
|
||||
final List<PreferenceController> preferenceControllers = mTestFragment.mControllers;
|
||||
final PreferenceController mockController1 = mock(PreferenceController.class);
|
||||
final PreferenceController mockController2 = mock(PreferenceController.class);
|
||||
final List<AbstractPreferenceController> preferenceControllers = mTestFragment.mControllers;
|
||||
final AbstractPreferenceController mockController1 =
|
||||
mock(AbstractPreferenceController.class);
|
||||
final AbstractPreferenceController mockController2 =
|
||||
mock(AbstractPreferenceController.class);
|
||||
preferenceControllers.add(mockController1);
|
||||
preferenceControllers.add(mockController2);
|
||||
when(mockController1.isAvailable()).thenReturn(false);
|
||||
@@ -149,7 +156,47 @@ public class DashboardFragmentTest {
|
||||
verify(mockController2).getPreferenceKey();
|
||||
}
|
||||
|
||||
public static class TestPreferenceController extends PreferenceController {
|
||||
@Test
|
||||
public void tintTileIcon_hasMetadata_shouldReturnIconTintableMetadata() {
|
||||
final Tile tile = new Tile();
|
||||
tile.icon = mock(Icon.class);
|
||||
final Bundle metaData = new Bundle();
|
||||
tile.metaData = metaData;
|
||||
|
||||
metaData.putBoolean(TileUtils.META_DATA_PREFERENCE_ICON_TINTABLE, false);
|
||||
assertThat(mTestFragment.tintTileIcon(tile)).isFalse();
|
||||
|
||||
metaData.putBoolean(TileUtils.META_DATA_PREFERENCE_ICON_TINTABLE, true);
|
||||
assertThat(mTestFragment.tintTileIcon(tile)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tintTileIcon_noIcon_shouldReturnFalse() {
|
||||
final Tile tile = new Tile();
|
||||
final Bundle metaData = new Bundle();
|
||||
tile.metaData = metaData;
|
||||
|
||||
assertThat(mTestFragment.tintTileIcon(tile)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tintTileIcon_noMetadata_shouldReturnPackageNameCheck() {
|
||||
final Tile tile = new Tile();
|
||||
tile.icon = mock(Icon.class);
|
||||
final Intent intent = new Intent();
|
||||
tile.intent = intent;
|
||||
|
||||
intent.setComponent(new ComponentName(
|
||||
ShadowApplication.getInstance().getApplicationContext().getPackageName(),
|
||||
"TestClass"));
|
||||
assertThat(mTestFragment.tintTileIcon(tile)).isFalse();
|
||||
|
||||
intent.setComponent(new ComponentName("OtherPackage", "TestClass"));
|
||||
assertThat(mTestFragment.tintTileIcon(tile)).isTrue();
|
||||
}
|
||||
|
||||
public static class TestPreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin {
|
||||
|
||||
public TestPreferenceController(Context context) {
|
||||
super(context);
|
||||
@@ -180,7 +227,7 @@ public class DashboardFragmentTest {
|
||||
|
||||
private final PreferenceManager mPreferenceManager;
|
||||
private final Context mContext;
|
||||
private final List<PreferenceController> mControllers;
|
||||
private final List<AbstractPreferenceController> mControllers;
|
||||
|
||||
public final PreferenceScreen mScreen;
|
||||
|
||||
@@ -221,7 +268,7 @@ public class DashboardFragmentTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||
return mControllers;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,12 @@ package com.android.settings.dashboard;
|
||||
import android.app.Activity;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.conditional.ConditionManager;
|
||||
import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -34,6 +35,8 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -57,6 +60,8 @@ public class DashboardSummaryTest {
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
@Mock
|
||||
private ConditionManager mConditionManager;
|
||||
@Mock
|
||||
private SummaryLoader mSummaryLoader;
|
||||
|
||||
private DashboardSummary mSummary;
|
||||
|
||||
@@ -70,12 +75,15 @@ public class DashboardSummaryTest {
|
||||
ReflectionHelpers.setField(mSummary, "mDashboard", mDashboard);
|
||||
ReflectionHelpers.setField(mSummary, "mLayoutManager", mLayoutManager);
|
||||
ReflectionHelpers.setField(mSummary, "mConditionManager", mConditionManager);
|
||||
ReflectionHelpers.setField(mSummary, "mSummaryLoader", mSummaryLoader);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateCategoryAndSuggestion_shouldGetCategoryFromFeatureProvider() {
|
||||
doReturn(mock(Activity.class)).when(mSummary).getActivity();
|
||||
mSummary.updateCategoryAndSuggestion(null);
|
||||
|
||||
verify(mSummaryLoader).updateSummaryToCache(nullable(DashboardCategory.class));
|
||||
verify(mDashboardFeatureProvider).getTilesForCategory(CategoryKey.CATEGORY_HOMEPAGE);
|
||||
}
|
||||
|
||||
@@ -83,6 +91,7 @@ public class DashboardSummaryTest {
|
||||
public void onConditionChanged_PositionAtTop_ScrollToTop() {
|
||||
when(mLayoutManager.findFirstCompletelyVisibleItemPosition()).thenReturn(1);
|
||||
mSummary.onConditionsChanged();
|
||||
mSummary.onConditionsChanged();
|
||||
verify(mDashboard).scrollToPosition(0);
|
||||
}
|
||||
|
||||
@@ -90,9 +99,23 @@ public class DashboardSummaryTest {
|
||||
public void onConditionChanged_PositionNotTop_RemainPosition() {
|
||||
when(mLayoutManager.findFirstCompletelyVisibleItemPosition()).thenReturn(2);
|
||||
mSummary.onConditionsChanged();
|
||||
mSummary.onConditionsChanged();
|
||||
verify(mDashboard, never()).scrollToPosition(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onConditionChanged_firstCall_shouldIgnore() {
|
||||
mSummary.onConditionsChanged();
|
||||
verify(mAdapter, never()).setConditions(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onConditionChanged_secondCall_shouldSetConditionsOnAdapter() {
|
||||
mSummary.onConditionsChanged();
|
||||
mSummary.onConditionsChanged();
|
||||
verify(mAdapter).setConditions(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCategoryChanged_noRebuildOnFirstCall() {
|
||||
doReturn(mock(Activity.class)).when(mSummary).getActivity();
|
||||
|
||||
@@ -17,13 +17,21 @@
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import android.app.Activity;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@@ -31,18 +39,27 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SummaryLoaderTest {
|
||||
|
||||
private static final String SUMMARY_1 = "summary1";
|
||||
private static final String SUMMARY_2 = "summary2";
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
private SummaryLoader mSummaryLoader;
|
||||
private boolean mCallbackInvoked;
|
||||
private Tile mTile;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void SetUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
|
||||
|
||||
mTile = new Tile();
|
||||
mTile.summary = SUMMARY_1;
|
||||
mCallbackInvoked = false;
|
||||
@@ -71,4 +88,23 @@ public class SummaryLoaderTest {
|
||||
|
||||
assertThat(mCallbackInvoked).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSummaryToCache_hasCache_shouldUpdate() {
|
||||
|
||||
final String testSummary = "test_summary";
|
||||
final DashboardCategory category = new DashboardCategory();
|
||||
final Tile tile = new Tile();
|
||||
tile.key = "123";
|
||||
tile.intent = new Intent();
|
||||
category.addTile(tile);
|
||||
when(mFeatureFactory.dashboardFeatureProvider.getDashboardKeyForTile(tile))
|
||||
.thenReturn(tile.key);
|
||||
|
||||
mSummaryLoader.updateSummaryIfNeeded(tile, testSummary);
|
||||
tile.summary = null;
|
||||
mSummaryLoader.updateSummaryToCache(category);
|
||||
|
||||
assertThat(tile.summary).isEqualTo(testSummary);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
package com.android.settings.dashboard.suggestions;
|
||||
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
@@ -27,19 +27,24 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Settings.AmbientDisplaySuggestionActivity;
|
||||
import com.android.settings.Settings.AmbientDisplayPickupSuggestionActivity;
|
||||
import com.android.settings.Settings.AmbientDisplaySuggestionActivity;
|
||||
import com.android.settings.Settings.DoubleTapPowerSuggestionActivity;
|
||||
import com.android.settings.Settings.DoubleTwistSuggestionActivity;
|
||||
import com.android.settings.Settings.NightDisplaySuggestionActivity;
|
||||
import com.android.settings.Settings.SwipeToNotificationSuggestionActivity;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.gestures.DoubleTapPowerSettings;
|
||||
@@ -49,22 +54,31 @@ import com.android.settings.gestures.SwipeToNotificationSettings;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.suggestions.SuggestionParser;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {ShadowSecureSettings.class, SettingsShadowResources.class}
|
||||
)
|
||||
public class SuggestionFeatureProviderImplTest {
|
||||
|
||||
private static final String DOUBLE_TWIST_SENSOR_NAME = "double_twist_sensor_name";
|
||||
@@ -77,11 +91,15 @@ public class SuggestionFeatureProviderImplTest {
|
||||
@Mock
|
||||
private Tile mSuggestion;
|
||||
@Mock
|
||||
private ActivityManager mActivityManager;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private FingerprintManager mFingerprintManager;
|
||||
@Mock
|
||||
private SharedPreferences mSharedPreferences;
|
||||
@Captor
|
||||
private ArgumentCaptor<Pair> mTaggedDataCaptor = ArgumentCaptor.forClass(Pair.class);
|
||||
|
||||
private FakeFeatureFactory mFactory;
|
||||
private SuggestionFeatureProviderImpl mProvider;
|
||||
@@ -96,6 +114,8 @@ public class SuggestionFeatureProviderImplTest {
|
||||
when((Object) mContext.getSystemService(FingerprintManager.class))
|
||||
.thenReturn(mFingerprintManager);
|
||||
when(mContext.getApplicationContext()).thenReturn(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(Context.ACTIVITY_SERVICE)).thenReturn(mActivityManager);
|
||||
when(mActivityManager.isLowRamDevice()).thenReturn(false);
|
||||
|
||||
mSuggestion.intent = new Intent().setClassName("pkg", "cls");
|
||||
mSuggestion.category = "category";
|
||||
@@ -104,7 +124,6 @@ public class SuggestionFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = SettingsShadowResources.class)
|
||||
public void isSuggestionCompleted_doubleTapPower_trueWhenNotAvailable() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, false);
|
||||
@@ -115,7 +134,6 @@ public class SuggestionFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = SettingsShadowResources.class)
|
||||
public void isSuggestionCompleted_doubleTapPower_falseWhenNotVisited() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true);
|
||||
@@ -127,7 +145,6 @@ public class SuggestionFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = SettingsShadowResources.class)
|
||||
public void isSuggestionCompleted_doubleTapPower_trueWhenVisited() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true);
|
||||
@@ -140,7 +157,6 @@ public class SuggestionFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = SettingsShadowResources.class)
|
||||
public void isSuggestionCompleted_doubleTwist_trueWhenNotAvailable() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
R.string.gesture_double_twist_sensor_name, "nonexistant name");
|
||||
@@ -153,7 +169,6 @@ public class SuggestionFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = SettingsShadowResources.class)
|
||||
public void isSuggestionCompleted_ambientDisplay_falseWhenNotVisited() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.string.config_dozeComponent, "foo");
|
||||
@@ -167,7 +182,6 @@ public class SuggestionFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = SettingsShadowResources.class)
|
||||
public void isSuggestionCompleted_ambientDisplay_trueWhenVisited() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.string.config_dozeComponent, "foo");
|
||||
@@ -182,7 +196,6 @@ public class SuggestionFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = SettingsShadowResources.class)
|
||||
public void isSuggestionCompleted_ambientDisplayPickup_falseWhenNotVisited() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.string.config_dozeComponent, "foo");
|
||||
@@ -196,7 +209,6 @@ public class SuggestionFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = SettingsShadowResources.class)
|
||||
public void isSuggestionCompleted_ambientDisplayPickup_trueWhenVisited() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.string.config_dozeComponent, "foo");
|
||||
@@ -263,6 +275,20 @@ public class SuggestionFeatureProviderImplTest {
|
||||
new ComponentName(mContext, SwipeToNotificationSuggestionActivity.class))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSuggestionEnabled_isLowMemoryDevice_shouldReturnFalse() {
|
||||
when(mActivityManager.isLowRamDevice()).thenReturn(true);
|
||||
|
||||
assertThat(mProvider.isSuggestionEnabled(mContext)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSuggestionEnabled_isNotLowMemoryDevice_shouldReturnTrue() {
|
||||
when(mActivityManager.isLowRamDevice()).thenReturn(false);
|
||||
|
||||
assertThat(mProvider.isSuggestionEnabled(mContext)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dismissSuggestion_noParserOrSuggestion_noop() {
|
||||
mProvider.dismissSuggestion(mContext, null, null);
|
||||
@@ -309,14 +335,17 @@ public class SuggestionFeatureProviderImplTest {
|
||||
|
||||
@Test
|
||||
public void dismissSuggestion_hasMoreDismissCount_shouldNotDisableComponent() {
|
||||
when(mSuggestionParser.dismissSuggestion(any(Tile.class), anyBoolean()))
|
||||
when(mSuggestionParser.dismissSuggestion(any(Tile.class)))
|
||||
.thenReturn(false);
|
||||
mProvider.dismissSuggestion(mContext, mSuggestionParser, mSuggestion);
|
||||
|
||||
verify(mFactory.metricsFeatureProvider).action(
|
||||
eq(mContext),
|
||||
eq(MetricsProto.MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION),
|
||||
anyString());
|
||||
anyString(),
|
||||
mTaggedDataCaptor.capture());
|
||||
assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
||||
verify(mContext, never()).getPackageManager();
|
||||
}
|
||||
|
||||
@@ -329,7 +358,7 @@ public class SuggestionFeatureProviderImplTest {
|
||||
|
||||
@Test
|
||||
public void dismissSuggestion_hasNoMoreDismissCount_shouldDisableComponent() {
|
||||
when(mSuggestionParser.dismissSuggestion(any(Tile.class), anyBoolean()))
|
||||
when(mSuggestionParser.dismissSuggestion(any(Tile.class)))
|
||||
.thenReturn(true);
|
||||
|
||||
mProvider.dismissSuggestion(mContext, mSuggestionParser, mSuggestion);
|
||||
@@ -337,8 +366,10 @@ public class SuggestionFeatureProviderImplTest {
|
||||
verify(mFactory.metricsFeatureProvider).action(
|
||||
eq(mContext),
|
||||
eq(MetricsProto.MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION),
|
||||
anyString());
|
||||
|
||||
anyString(),
|
||||
mTaggedDataCaptor.capture());
|
||||
assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
||||
verify(mContext.getPackageManager())
|
||||
.setComponentEnabledSetting(mSuggestion.intent.getComponent(),
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
@@ -365,4 +396,51 @@ public class SuggestionFeatureProviderImplTest {
|
||||
|
||||
assertThat(suggestions).hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasUsedNightDisplay_returnsFalse_byDefault() {
|
||||
assertThat(mProvider.hasUsedNightDisplay(mContext)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasUsedNightDisplay_returnsTrue_ifPreviouslyActivatedAndManual() {
|
||||
Secure.putString(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME,
|
||||
LocalDateTime.now().toString());
|
||||
Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_AUTO_MODE, 1);
|
||||
assertThat(mProvider.hasUsedNightDisplay(mContext)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nightDisplaySuggestion_isCompleted_ifPreviouslyActivated() {
|
||||
Secure.putString(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME,
|
||||
LocalDateTime.now().toString());
|
||||
final ComponentName componentName =
|
||||
new ComponentName(mContext, NightDisplaySuggestionActivity.class);
|
||||
assertThat(mProvider.isSuggestionCompleted(mContext, componentName)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nightDisplaySuggestion_isCompleted_ifNonManualMode() {
|
||||
Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_AUTO_MODE, 1);
|
||||
final ComponentName componentName =
|
||||
new ComponentName(mContext, NightDisplaySuggestionActivity.class);
|
||||
assertThat(mProvider.isSuggestionCompleted(mContext, componentName)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nightDisplaySuggestion_isCompleted_ifPreviouslyCleared() {
|
||||
Secure.putString(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME,
|
||||
null);
|
||||
Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_AUTO_MODE, 1);
|
||||
final ComponentName componentName =
|
||||
new ComponentName(mContext, NightDisplaySuggestionActivity.class);
|
||||
assertThat(mProvider.isSuggestionCompleted(mContext, componentName)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nightDisplaySuggestion_isNotCompleted_byDefault() {
|
||||
final ComponentName componentName =
|
||||
new ComponentName(mContext, NightDisplaySuggestionActivity.class);
|
||||
assertThat(mProvider.isSuggestionCompleted(mContext, componentName)).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.dashboard.suggestions;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class SuggestionLogHelperTest {
|
||||
|
||||
@Test
|
||||
public void testGetSmartSuggestionEnabledTaggedData_disabled() {
|
||||
assertThat(SuggestionLogHelper.getSuggestionTaggedData(false)).asList().containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSmartSuggestionEnabledTaggedData_enabled() {
|
||||
assertThat(SuggestionLogHelper.getSuggestionTaggedData(true)).asList().containsExactly(
|
||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,6 @@ public class SuggestionsChecksTest {
|
||||
assertThat(mSuggestionsChecks.isSuggestionComplete(tile)).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFingerprintEnrollmentIntroductionIsCompleteWhenFingerprintNotSupported() {
|
||||
stubFingerprintSupported(false);
|
||||
@@ -127,7 +126,7 @@ public class SuggestionsChecksTest {
|
||||
}
|
||||
|
||||
private Tile createFingerprintTile() {
|
||||
Tile tile = new Tile();
|
||||
final Tile tile = new Tile();
|
||||
tile.intent = new Intent();
|
||||
tile.intent.setComponent(new ComponentName(mContext,
|
||||
Settings.FingerprintEnrollSuggestionActivity.class));
|
||||
|
||||
@@ -17,21 +17,33 @@
|
||||
package com.android.settings.datausage;
|
||||
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
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.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.util.ArraySet;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.PackageManagerWrapper;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settings.widget.EntityHeaderController.ActionType;
|
||||
import com.android.settingslib.AppItem;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -45,16 +57,6 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = ShadowEntityHeaderController.class)
|
||||
@@ -96,7 +98,7 @@ public class AppDataUsageTest {
|
||||
|
||||
mFragment.onViewCreated(new View(RuntimeEnvironment.application), new Bundle());
|
||||
|
||||
verify(mHeaderController).setButtonActions(ActionType.ACTION_NONE, ActionType.ACTION_NONE);
|
||||
verify(mHeaderController).setHasAppInfoLink(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,6 +121,7 @@ public class AppDataUsageTest {
|
||||
ShadowEntityHeaderController.setUseMock(mHeaderController);
|
||||
when(mHeaderController.setRecyclerView(any(), any())).thenReturn(mHeaderController);
|
||||
when(mHeaderController.setUid(fakeUserId)).thenReturn(mHeaderController);
|
||||
when(mHeaderController.setHasAppInfoLink(anyBoolean())).thenReturn(mHeaderController);
|
||||
|
||||
doReturn(mock(PreferenceManager.class, RETURNS_DEEP_STUBS))
|
||||
.when(mFragment)
|
||||
@@ -127,9 +130,24 @@ public class AppDataUsageTest {
|
||||
|
||||
mFragment.onViewCreated(new View(RuntimeEnvironment.application), new Bundle());
|
||||
|
||||
verify(mHeaderController)
|
||||
.setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE);
|
||||
verify(mHeaderController)
|
||||
.setUid(fakeUserId);
|
||||
verify(mHeaderController).setHasAppInfoLink(true);
|
||||
verify(mHeaderController).setUid(fakeUserId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changePreference_backgroundData_shouldUpdateUI() {
|
||||
mFragment = spy(new AppDataUsage());
|
||||
final AppItem appItem = new AppItem(123456789);
|
||||
final SwitchPreference pref = mock(SwitchPreference.class);
|
||||
final DataSaverBackend dataSaverBackend = mock(DataSaverBackend.class);
|
||||
ReflectionHelpers.setField(mFragment, "mAppItem", appItem);
|
||||
ReflectionHelpers.setField(mFragment, "mRestrictBackground", pref);
|
||||
ReflectionHelpers.setField(mFragment, "mDataSaverBackend", dataSaverBackend);
|
||||
|
||||
doNothing().when(mFragment).updatePrefs();
|
||||
|
||||
mFragment.onPreferenceChange(pref, true /* value */);
|
||||
|
||||
verify(mFragment).updatePrefs();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.widget.DonutView;
|
||||
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;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class
|
||||
}
|
||||
)
|
||||
public final class DataPlanSummaryPreferenceTest {
|
||||
|
||||
private static final String TEST_PLAN_USAGE = "Test plan usage";
|
||||
private static final String TEST_PLAN_NAME = "Test plan name";
|
||||
private static final String TEST_PLAN_DESCRIPTION = "Test plan description";
|
||||
private static final int PLAN_USAGE_TEXT_COLOR = Color.parseColor("#FF5C94F1");
|
||||
private static final int METER_BACKGROUND_COLOR = Color.parseColor("#FFDBDCDC");
|
||||
private static final int METER_CONSUMED_COLOR = Color.parseColor("#FF5C94F1");
|
||||
|
||||
private DataPlanSummaryPreference mPreference;
|
||||
private PreferenceViewHolder mHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.string.config_headlineFontFamily, "");
|
||||
Context context = RuntimeEnvironment.application;
|
||||
mPreference = new DataPlanSummaryPreference(context);
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View view = inflater.inflate(mPreference.getLayoutResource(),
|
||||
new LinearLayout(context), false);
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowResources.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRender_withoutData() {
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
|
||||
TextView planUsageTextView = (TextView) mHolder.findViewById(android.R.id.title);
|
||||
assertThat(planUsageTextView.getText().toString()).isEmpty();
|
||||
TextView planNameTextView = (TextView) mHolder.findViewById(android.R.id.text1);
|
||||
assertThat(planNameTextView.getText().toString()).isEmpty();
|
||||
TextView planDescriptionTextView = (TextView) mHolder.findViewById(android.R.id.text2);
|
||||
assertThat(planDescriptionTextView.getText().toString()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRender_withData() {
|
||||
mPreference.setTitle(TEST_PLAN_USAGE);
|
||||
mPreference.setUsageTextColor(PLAN_USAGE_TEXT_COLOR);
|
||||
mPreference.setName(TEST_PLAN_NAME);
|
||||
mPreference.setDescription(TEST_PLAN_DESCRIPTION);
|
||||
mPreference.setPercentageUsage(0.25D);
|
||||
mPreference.setMeterBackgroundColor(METER_BACKGROUND_COLOR);
|
||||
mPreference.setMeterConsumedColor(METER_CONSUMED_COLOR);
|
||||
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
|
||||
TextView planUsageTextView = (TextView) mHolder.findViewById(android.R.id.title);
|
||||
assertThat(planUsageTextView.getTextColors().getDefaultColor())
|
||||
.isEqualTo(PLAN_USAGE_TEXT_COLOR);
|
||||
assertThat(planUsageTextView.getText()).isEqualTo(TEST_PLAN_USAGE);
|
||||
|
||||
TextView planNameTextView = (TextView) mHolder.findViewById(android.R.id.text1);
|
||||
assertThat(planNameTextView.getText()).isEqualTo(TEST_PLAN_NAME);
|
||||
|
||||
TextView planDescriptionTextView = (TextView) mHolder.findViewById(android.R.id.text2);
|
||||
assertThat(planDescriptionTextView.getText()).isEqualTo(TEST_PLAN_DESCRIPTION);
|
||||
|
||||
DonutView donutView = (DonutView) mHolder.findViewById(R.id.donut);
|
||||
assertThat(donutView.getMeterBackgroundColor()).isEqualTo(METER_BACKGROUND_COLOR);
|
||||
assertThat(donutView.getMeterConsumedColor()).isEqualTo(METER_CONSUMED_COLOR);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkPolicy;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
|
||||
import com.android.settings.testutils.shadow.ShadowDataUsageUtils;
|
||||
import com.android.settingslib.NetworkPolicyEditor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DataPlanUsageSummaryTest {
|
||||
@Mock
|
||||
private ConnectivityManager mManager;
|
||||
|
||||
private Context mContext;
|
||||
private DataPlanUsageSummary mDataUsageSummary;
|
||||
private NetworkPolicyEditor mPolicyEditor;
|
||||
private WifiConfiguration mWifiConfiguration;
|
||||
private NetworkPolicy mNetworkPolicy;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
ShadowApplication shadowContext = ShadowApplication.getInstance();
|
||||
shadowContext.setSystemService(Context.CONNECTIVITY_SERVICE, mManager);
|
||||
mContext = shadowContext.getApplicationContext();
|
||||
when(mManager.isNetworkSupported(anyInt())).thenReturn(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateNetworkRestrictionSummary_shouldSetSummary() {
|
||||
mDataUsageSummary = spy(new DataPlanUsageSummary());
|
||||
NetworkRestrictionsPreference preference = mock(NetworkRestrictionsPreference.class);
|
||||
mPolicyEditor = mock(NetworkPolicyEditor.class);
|
||||
WifiManager wifiManager = mock(WifiManager.class);
|
||||
ReflectionHelpers.setField(mDataUsageSummary, "mPolicyEditor", mPolicyEditor);
|
||||
ReflectionHelpers.setField(mDataUsageSummary, "mWifiManager", wifiManager);
|
||||
when(wifiManager.getConfiguredNetworks()).thenReturn(new ArrayList<>());
|
||||
doReturn(mContext.getResources()).when(mDataUsageSummary).getResources();
|
||||
|
||||
mDataUsageSummary.updateNetworkRestrictionSummary(preference);
|
||||
|
||||
verify(preference).setSummary(mContext.getResources().getQuantityString(
|
||||
R.plurals.network_restrictions_summary, 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_noSsid_shouldReturnFalse() {
|
||||
initTest();
|
||||
|
||||
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_noNetworkPolicy_shouldReturnFalse() {
|
||||
initTest();
|
||||
mWifiConfiguration.SSID = "network1";
|
||||
doReturn(null).when(mPolicyEditor).getPolicyMaybeUnquoted(any());
|
||||
|
||||
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_policyHasLimit_shouldReturnTrue() {
|
||||
initTest();
|
||||
mWifiConfiguration.SSID = "network1";
|
||||
mNetworkPolicy = mock(NetworkPolicy.class);
|
||||
mNetworkPolicy.limitBytes = 100;
|
||||
doReturn(mNetworkPolicy).when(mPolicyEditor).getPolicyMaybeUnquoted(any());
|
||||
|
||||
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_noPolicyLimit_shouldReturnMeteredValue() {
|
||||
initTest();
|
||||
mWifiConfiguration.SSID = "network1";
|
||||
mNetworkPolicy = mock(NetworkPolicy.class);
|
||||
mNetworkPolicy.limitBytes = NetworkPolicy.LIMIT_DISABLED;
|
||||
doReturn(mNetworkPolicy).when(mPolicyEditor).getPolicyMaybeUnquoted(any());
|
||||
|
||||
mNetworkPolicy.metered = true;
|
||||
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isTrue();
|
||||
|
||||
mNetworkPolicy.metered = false;
|
||||
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowDataUsageUtils.class)
|
||||
public void testNonIndexableKeys_existInXmlLayout() {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
|
||||
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = true;
|
||||
final List<String> niks = DataPlanUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(context);
|
||||
final List<String> keys = new ArrayList<>();
|
||||
|
||||
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage_wifi));
|
||||
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage));
|
||||
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context,
|
||||
R.xml.data_plan_usage_cell_data_preference_screen));
|
||||
|
||||
assertThat(keys).containsAllIn(niks);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowDataUsageUtils.class)
|
||||
public void testNonIndexableKeys_hasMobileData_hasWifi_allNonIndexableKeysAdded() {
|
||||
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = false;
|
||||
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = false;
|
||||
List<String> keys = DataPlanUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(mContext);
|
||||
|
||||
// Mobile data keys
|
||||
assertThat(keys).contains(DataPlanUsageSummary.KEY_MOBILE_USAGE_TITLE);
|
||||
assertThat(keys).contains(DataPlanUsageSummary.KEY_MOBILE_DATA_USAGE_TOGGLE);
|
||||
|
||||
// Wifi keys
|
||||
assertThat(keys).contains(DataPlanUsageSummary.KEY_WIFI_DATA_USAGE);
|
||||
assertThat(keys).contains(DataPlanUsageSummary.KEY_NETWORK_RESTRICTIONS);
|
||||
assertThat(keys).contains(DataPlanUsageSummary.KEY_WIFI_USAGE_TITLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowDataUsageUtils.class)
|
||||
public void testNonIndexableKeys_noMobile_noWifi_limitedNonIndexableKeys() {
|
||||
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
|
||||
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = true;
|
||||
List<String> keys = DataPlanUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(mContext);
|
||||
|
||||
assertThat(keys).containsExactly(DataPlanUsageSummary.KEY_WIFI_USAGE_TITLE);
|
||||
}
|
||||
|
||||
private void initTest() {
|
||||
mDataUsageSummary = new DataPlanUsageSummary();
|
||||
mPolicyEditor = mock(NetworkPolicyEditor.class);
|
||||
ReflectionHelpers.setField(mDataUsageSummary, "mPolicyEditor", mPolicyEditor);
|
||||
mWifiConfiguration = mock(WifiConfiguration.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
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;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class DataPlansSyncTimePreferenceTest {
|
||||
private static final String SYNC_TIME = "Today 12:24pm";
|
||||
|
||||
private Preference mPreference;
|
||||
private PreferenceViewHolder mHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Context context = RuntimeEnvironment.application;
|
||||
mPreference = new Preference(context);
|
||||
mPreference.setLayoutResource(R.layout.data_plans_sync_time_preference);
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View view = inflater.inflate(mPreference.getLayoutResource(),
|
||||
new LinearLayout(context), false);
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRender_withData() {
|
||||
mPreference.setTitle(SYNC_TIME);
|
||||
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
|
||||
TextView syncTimeTextView = (TextView) mHolder.findViewById(android.R.id.title);
|
||||
assertThat(syncTimeTextView.getText()).isEqualTo(SYNC_TIME);
|
||||
}
|
||||
}
|
||||
@@ -16,20 +16,26 @@
|
||||
|
||||
package com.android.settings.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkPolicy;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
|
||||
import com.android.settings.testutils.shadow.ShadowDataUsageSummary;
|
||||
import com.android.settingslib.NetworkPolicyEditor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -40,18 +46,6 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DataUsageSummaryTest {
|
||||
@@ -72,12 +66,6 @@ public class DataUsageSummaryTest {
|
||||
when(mManager.isNetworkSupported(anyInt())).thenReturn(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMobileDataStatus() {
|
||||
boolean hasMobileData = DataUsageSummary.hasMobileData(mContext);
|
||||
assertThat(hasMobileData).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateNetworkRestrictionSummary_shouldSetSummary() {
|
||||
final DataUsageSummary dataUsageSummary = spy(new DataUsageSummary());
|
||||
@@ -94,106 +82,4 @@ public class DataUsageSummaryTest {
|
||||
verify(preference).setSummary(mContext.getResources().getQuantityString(
|
||||
R.plurals.network_restrictions_summary, 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_noSsid_shouldReturnFalse() {
|
||||
final DataUsageSummary dataUsageSummary = new DataUsageSummary();
|
||||
final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
|
||||
ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
|
||||
WifiConfiguration config = mock(WifiConfiguration.class);
|
||||
|
||||
assertThat(dataUsageSummary.isMetered(config)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_noNetworkPolicy_shouldReturnFalse() {
|
||||
final DataUsageSummary dataUsageSummary = new DataUsageSummary();
|
||||
final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
|
||||
ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
|
||||
WifiConfiguration config = mock(WifiConfiguration.class);
|
||||
config.SSID = "network1";
|
||||
doReturn(null).when(policyEditor).getPolicyMaybeUnquoted(any());
|
||||
|
||||
assertThat(dataUsageSummary.isMetered(config)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_policyHasLimit_shouldReturnTrue() {
|
||||
final DataUsageSummary dataUsageSummary = new DataUsageSummary();
|
||||
final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
|
||||
ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
|
||||
WifiConfiguration config = mock(WifiConfiguration.class);
|
||||
config.SSID = "network1";
|
||||
NetworkPolicy policy = mock(NetworkPolicy.class);
|
||||
policy.limitBytes = 100;
|
||||
doReturn(policy).when(policyEditor).getPolicyMaybeUnquoted(any());
|
||||
|
||||
assertThat(dataUsageSummary.isMetered(config)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_noPolicyLimit_shouldReturnMeteredValue() {
|
||||
final DataUsageSummary dataUsageSummary = new DataUsageSummary();
|
||||
final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
|
||||
ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
|
||||
WifiConfiguration config = mock(WifiConfiguration.class);
|
||||
config.SSID = "network1";
|
||||
NetworkPolicy policy = mock(NetworkPolicy.class);
|
||||
policy.limitBytes = NetworkPolicy.LIMIT_DISABLED;
|
||||
doReturn(policy).when(policyEditor).getPolicyMaybeUnquoted(any());
|
||||
|
||||
policy.metered = true;
|
||||
assertThat(dataUsageSummary.isMetered(config)).isTrue();
|
||||
|
||||
policy.metered = false;
|
||||
assertThat(dataUsageSummary.isMetered(config)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowDataUsageSummary.class)
|
||||
public void testNonIndexableKeys_existInXmlLayout() {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
ShadowDataUsageSummary.IS_WIFI_SUPPORTED = true;
|
||||
ShadowDataUsageSummary.IS_MOBILE_DATA_SUPPORTED = true;
|
||||
final List<String> niks = DataUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(context);
|
||||
final List<String> keys = new ArrayList<>();
|
||||
|
||||
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage_wifi));
|
||||
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage));
|
||||
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage_cellular));
|
||||
|
||||
assertThat(keys).containsAllIn(niks);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowDataUsageSummary.class)
|
||||
public void testNonIndexableKeys_hasMobileData_hasWifi_allNonIndexableKeysAdded() {
|
||||
ShadowDataUsageSummary.IS_WIFI_SUPPORTED = false;
|
||||
ShadowDataUsageSummary.IS_MOBILE_DATA_SUPPORTED = false;
|
||||
List<String> keys = DataUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(mContext);
|
||||
|
||||
// Mobile data keys
|
||||
assertThat(keys).contains(DataUsageSummary.KEY_MOBILE_CATEGORY);
|
||||
assertThat(keys).contains(DataUsageSummary.KEY_MOBILE_DATA_USAGE_TOGGLE);
|
||||
assertThat(keys).contains(DataUsageSummary.KEY_MOBILE_DATA_USAGE);
|
||||
assertThat(keys).contains(DataUsageSummary.KEY_MOBILE_BILLING_CYCLE);
|
||||
|
||||
// Wifi keys
|
||||
assertThat(keys).contains(DataUsageSummary.KEY_WIFI_DATA_USAGE);
|
||||
assertThat(keys).contains(DataUsageSummary.KEY_NETWORK_RESTRICTIONS);
|
||||
assertThat(keys).contains(DataUsageSummary.KEY_WIFI_USAGE_TITLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowDataUsageSummary.class)
|
||||
public void testNonIndexableKeys_noMobile_noWifi_limitedNonIndexableKeys() {
|
||||
ShadowDataUsageSummary.IS_WIFI_SUPPORTED = true;
|
||||
ShadowDataUsageSummary.IS_MOBILE_DATA_SUPPORTED = true;
|
||||
List<String> keys = DataUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(mContext);
|
||||
|
||||
assertThat(keys).containsExactly(DataUsageSummary.KEY_WIFI_USAGE_TITLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class DataUsageUtilsTest {
|
||||
@Mock private ConnectivityManager mManager;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
ShadowApplication shadowContext = ShadowApplication.getInstance();
|
||||
mContext = shadowContext.getApplicationContext();
|
||||
shadowContext.setSystemService(Context.CONNECTIVITY_SERVICE, mManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mobileDataStatus_whenNetworkIsSupported() {
|
||||
when(mManager.isNetworkSupported(anyInt())).thenReturn(true);
|
||||
boolean hasMobileData = DataUsageUtils.hasMobileData(mContext);
|
||||
assertThat(hasMobileData).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mobileDataStatus_whenNetworkIsNotSupported() {
|
||||
when(mManager.isNetworkSupported(anyInt())).thenReturn(false);
|
||||
boolean hasMobileData = DataUsageUtils.hasMobileData(mContext);
|
||||
assertThat(hasMobileData).isFalse();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
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;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class ManageDataPlansPreferenceTest {
|
||||
private Preference mPreference;
|
||||
private PreferenceViewHolder mHolder;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference.setLayoutResource(R.layout.manage_data_plans_preference);
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
View view = inflater.inflate(mPreference.getLayoutResource(),
|
||||
new LinearLayout(mContext), false);
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRender_withData() {
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
Button managePlanButton = (Button) mHolder.findViewById(R.id.manage_data_plans);
|
||||
assertThat(managePlanButton.getText())
|
||||
.isEqualTo(mContext.getString(R.string.data_plan_usage_manage_plans_button_text));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.android.settings.deletionhelper;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AutomaticStorageManagerDescriptionPreferenceControllerTest {
|
||||
@Mock private PreferenceScreen mScreen;
|
||||
@Mock private Preference mPreference;
|
||||
private AutomaticStorageManagerDescriptionPreferenceController mController;
|
||||
private Context mContext = RuntimeEnvironment.application;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new AutomaticStorageManagerDescriptionPreferenceController(mContext);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||
when(mPreference.getContext()).thenReturn(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_asmDisabled_shouldHaveDescription() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setSummary(eq(R.string.automatic_storage_manager_text));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_asmEnabledButUnused_shouldHaveDescription() {
|
||||
Settings.Secure.putInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED,
|
||||
1);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setSummary(eq(R.string.automatic_storage_manager_text));
|
||||
}
|
||||
|
||||
@Ignore("Robolectric doesn't do locale switching for date localization -- yet.")
|
||||
@Test
|
||||
@Config(qualifiers = "en")
|
||||
public void displayPreference_asmEnabledAndUsed_shouldHaveDescriptionFilledOut() {
|
||||
Settings.Secure.putInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED,
|
||||
1);
|
||||
Settings.Secure.putLong(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.AUTOMATIC_STORAGE_MANAGER_BYTES_CLEARED,
|
||||
10);
|
||||
Settings.Secure.putLong(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.AUTOMATIC_STORAGE_MANAGER_LAST_RUN,
|
||||
43200000); // January 1, 1970 12:00:00 PM to avoid timezone issues.
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference)
|
||||
.setSummary(eq("10.00B total made available\n\nLast ran on January 1, 1970"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.development;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {SettingsShadowSystemProperties.class})
|
||||
public class CameraHalHdrplusPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
static final String USERDEBUG_BUILD = "userdebug";
|
||||
|
||||
private CameraHalHdrplusPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new CameraHalHdrplusPreferenceController(mContext);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowSystemProperties.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withConfigNoShow_shouldReturnFalse() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus))
|
||||
.thenReturn(false);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_cameraHalHdrplusEnabled_shouldCheckedPreference() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus))
|
||||
.thenReturn(true);
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraHalHdrplusPreferenceController.PROPERTY_CAMERA_HAL_HDRPLUS,
|
||||
CameraHalHdrplusPreferenceController.ENABLED);
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraHalHdrplusPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_cameraHalHdrplusEnabled_shouldUncheckedPreference() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus))
|
||||
.thenReturn(true);
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraHalHdrplusPreferenceController.PROPERTY_CAMERA_HAL_HDRPLUS,
|
||||
CameraHalHdrplusPreferenceController.DISABLED);
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraHalHdrplusPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_preferenceChecked_shouldEnableCameraHalHdrplus() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus))
|
||||
.thenReturn(true);
|
||||
|
||||
when(mPreference.isChecked()).thenReturn(true);
|
||||
|
||||
when(mContext.getResources().getString(R.string.camera_hal_hdrplus_toast)).thenReturn(
|
||||
RuntimeEnvironment.application.getString(R.string.camera_hal_hdrplus_toast));
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(CameraHalHdrplusPreferenceController.ENABLED.equals(
|
||||
SystemProperties.get(
|
||||
CameraHalHdrplusPreferenceController.PROPERTY_CAMERA_HAL_HDRPLUS,
|
||||
CameraHalHdrplusPreferenceController.DISABLED))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_preferenceUnchecked_shouldDisableCameraHalHdrplus() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus))
|
||||
.thenReturn(true);
|
||||
|
||||
when(mPreference.isChecked()).thenReturn(false);
|
||||
|
||||
when(mContext.getResources().getString(R.string.camera_hal_hdrplus_toast)).thenReturn(
|
||||
RuntimeEnvironment.application.getString(R.string.camera_hal_hdrplus_toast));
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(CameraHalHdrplusPreferenceController.DISABLED.equals(
|
||||
SystemProperties.get(
|
||||
CameraHalHdrplusPreferenceController.PROPERTY_CAMERA_HAL_HDRPLUS,
|
||||
CameraHalHdrplusPreferenceController.DISABLED))).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.development;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {SettingsShadowSystemProperties.class})
|
||||
public class CameraLaserSensorPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
static final String USERDEBUG_BUILD = "userdebug";
|
||||
static final String ENG_BUILD = "eng";
|
||||
static final String USER_BUILD = "user";
|
||||
|
||||
private CameraLaserSensorPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new CameraLaserSensorPreferenceController(mContext);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowSystemProperties.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withConfigNoShow_shouldReturnFalse() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(false);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withUserdebugBuild_shouldReturnTrue() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(true);
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraLaserSensorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withEngBuild_shouldReturnTrue() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(true);
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraLaserSensorPreferenceController.BUILD_TYPE, ENG_BUILD);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withUserBuild_shouldReturnFalse() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(true);
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraLaserSensorPreferenceController.BUILD_TYPE, USER_BUILD);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_cameraLaserSensorEnabled_shouldCheckedPreference() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(true);
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
|
||||
Integer.toString(CameraLaserSensorPreferenceController.ENABLED));
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraLaserSensorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_cameraLaserSensorEnabled_shouldUncheckedPreference() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(true);
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
|
||||
Integer.toString(CameraLaserSensorPreferenceController.DISABLED));
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraLaserSensorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_preferenceChecked_shouldEnableCameraLaserSensor() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(true);
|
||||
|
||||
when(mPreference.isChecked()).thenReturn(true);
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(Integer.toString(CameraLaserSensorPreferenceController.ENABLED).equals(
|
||||
SystemProperties.get(
|
||||
CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
|
||||
Integer.toString(CameraLaserSensorPreferenceController.ENABLED)))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_preferenceUnchecked_shouldDisableCameraLaserSensor() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(true);
|
||||
|
||||
when(mPreference.isChecked()).thenReturn(false);
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(Integer.toString(CameraLaserSensorPreferenceController.DISABLED).equals(
|
||||
SystemProperties.get(
|
||||
CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
|
||||
Integer.toString(CameraLaserSensorPreferenceController.ENABLED)))).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,14 @@
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -33,8 +35,6 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DevelopmentSettingsEnablerTest {
|
||||
@@ -52,6 +52,16 @@ public class DevelopmentSettingsEnablerTest {
|
||||
ReflectionHelpers.setField(mEnabler, "mDevelopmentPreferences", mDevelopmentPreferences);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructor_shouldInitEnabledState() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
|
||||
|
||||
mEnabler = new DevelopmentSettingsEnabler(mContext, null);
|
||||
|
||||
assertThat(mEnabler.getLastEnabledState()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_shouldReadStateFromSettingProvider() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.development;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.After;
|
||||
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.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
ShadowUtils.class
|
||||
})
|
||||
public class DevelopmentSwitchBarControllerTest {
|
||||
|
||||
@Mock
|
||||
private DevelopmentSettings mSettings;
|
||||
private Lifecycle mLifecycle;
|
||||
private SwitchBar mSwitchBar;
|
||||
private DevelopmentSwitchBarController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mLifecycle = new Lifecycle();
|
||||
mSwitchBar = new SwitchBar(RuntimeEnvironment.application);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowUtils.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runThroughLifecycle_isMonkeyRun_shouldNotRegisterListener() {
|
||||
ShadowUtils.setIsUserAMonkey(true);
|
||||
mController = new DevelopmentSwitchBarController(mSettings, mSwitchBar,
|
||||
true /* isAvailable */, mLifecycle);
|
||||
final ArrayList<SwitchBar.OnSwitchChangeListener> listeners =
|
||||
ReflectionHelpers.getField(mSwitchBar, "mSwitchChangeListeners");
|
||||
|
||||
mLifecycle.onStart();
|
||||
assertThat(listeners).doesNotContain(mSettings);
|
||||
|
||||
mLifecycle.onStop();
|
||||
assertThat(listeners).doesNotContain(mSettings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runThroughLifecycle_isNotMonkeyRun_shouldRegisterAndRemoveListener() {
|
||||
ShadowUtils.setIsUserAMonkey(false);
|
||||
mController = new DevelopmentSwitchBarController(mSettings, mSwitchBar,
|
||||
true /* isAvailable */, mLifecycle);
|
||||
final ArrayList<SwitchBar.OnSwitchChangeListener> listeners =
|
||||
ReflectionHelpers.getField(mSwitchBar, "mSwitchChangeListeners");
|
||||
|
||||
mLifecycle.onStart();
|
||||
assertThat(listeners).contains(mSettings);
|
||||
|
||||
mLifecycle.onStop();
|
||||
assertThat(listeners).doesNotContain(mSettings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildController_unavailable_shouldDisableSwitchBar() {
|
||||
ShadowUtils.setIsUserAMonkey(false);
|
||||
mController = new DevelopmentSwitchBarController(mSettings, mSwitchBar,
|
||||
false /* isAvailable */, mLifecycle);
|
||||
|
||||
assertThat(mSwitchBar.isEnabled()).isFalse();
|
||||
}
|
||||
}
|
||||
@@ -16,33 +16,6 @@
|
||||
|
||||
package com.android.settings.deviceinfo;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.development.DevelopmentSettings;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search.DatabaseIndexingManager;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Matchers.any;
|
||||
@@ -53,8 +26,41 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.BidiFormatter;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.development.DevelopmentSettings;
|
||||
import com.android.settings.search.DatabaseIndexingManager;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
ShadowUtils.class
|
||||
})
|
||||
public class BuildNumberPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@@ -76,8 +82,7 @@ public class BuildNumberPreferenceControllerTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mFactory = FakeFeatureFactory.setupForTest(mContext);
|
||||
mLifecycle = new Lifecycle();
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
mController = new BuildNumberPreferenceController(
|
||||
@@ -87,11 +92,17 @@ public class BuildNumberPreferenceControllerTest {
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowUtils.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPref_shouldAlwaysDisplay() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mScreen.findPreference(mController.getPreferenceKey())).setSummary(Build.DISPLAY);
|
||||
verify(mScreen.findPreference(mController.getPreferenceKey()))
|
||||
.setSummary(BidiFormatter.getInstance().unicodeWrap(Build.DISPLAY));
|
||||
verify(mScreen, never()).removePreference(any(Preference.class));
|
||||
}
|
||||
|
||||
@@ -125,6 +136,18 @@ public class BuildNumberPreferenceControllerTest {
|
||||
eq(MetricsProto.MetricsEvent.ACTION_SETTINGS_BUILD_NUMBER_PREF));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePrefTreeClick_isMonkeyRun_doNothing() {
|
||||
final Context context = spy(RuntimeEnvironment.application);
|
||||
Settings.Global.putInt(context.getContentResolver(),
|
||||
Settings.Global.DEVICE_PROVISIONED, 1);
|
||||
ShadowUtils.setIsUserAMonkey(true);
|
||||
mController = new BuildNumberPreferenceController(
|
||||
context, mActivity, mFragment, mLifecycle);
|
||||
|
||||
assertThat(mController.handlePreferenceTreeClick(mPreference)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePrefTreeClick_userHasRestriction_doNothing() {
|
||||
final Context context = spy(RuntimeEnvironment.application);
|
||||
|
||||
@@ -18,16 +18,27 @@ package com.android.settings.deviceinfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.deviceinfo.storage.CachedStorageValuesHelper;
|
||||
import com.android.settings.deviceinfo.storage.StorageAsyncLoader;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -68,6 +79,128 @@ public class StorageDashboardFragmentTest {
|
||||
verify(activity).invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_cacheProviderProvidesValuesIfBothCached() {
|
||||
CachedStorageValuesHelper helper = mock(CachedStorageValuesHelper.class);
|
||||
PrivateStorageInfo info = new PrivateStorageInfo(0, 0);
|
||||
when(helper.getCachedPrivateStorageInfo()).thenReturn(info);
|
||||
SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
|
||||
when(helper.getCachedAppsStorageResult()).thenReturn(result);
|
||||
|
||||
mFragment.setCachedStorageValuesHelper(helper);
|
||||
mFragment.initializeCachedValues();
|
||||
|
||||
assertThat(mFragment.getPrivateStorageInfo()).isEqualTo(info);
|
||||
assertThat(mFragment.getAppsStorageResult()).isEqualTo(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_cacheProviderDoesntProvideValuesIfAppsMissing() {
|
||||
CachedStorageValuesHelper helper = mock(CachedStorageValuesHelper.class);
|
||||
PrivateStorageInfo info = new PrivateStorageInfo(0, 0);
|
||||
when(helper.getCachedPrivateStorageInfo()).thenReturn(info);
|
||||
|
||||
mFragment.setCachedStorageValuesHelper(helper);
|
||||
mFragment.initializeCachedValues();
|
||||
|
||||
assertThat(mFragment.getPrivateStorageInfo()).isNull();
|
||||
assertThat(mFragment.getAppsStorageResult()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_cacheProviderDoesntProvideValuesIfVolumeInfoMissing() {
|
||||
CachedStorageValuesHelper helper = mock(CachedStorageValuesHelper.class);
|
||||
SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
|
||||
when(helper.getCachedAppsStorageResult()).thenReturn(result);
|
||||
|
||||
mFragment.setCachedStorageValuesHelper(helper);
|
||||
mFragment.initializeCachedValues();
|
||||
|
||||
assertThat(mFragment.getPrivateStorageInfo()).isNull();
|
||||
assertThat(mFragment.getAppsStorageResult()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_loadWhenQuotaOffIfVolumeInfoNotLoaded() {
|
||||
View fakeView = mock(View.class, RETURNS_DEEP_STUBS);
|
||||
RecyclerView fakeRecyclerView = mock(RecyclerView.class, RETURNS_DEEP_STUBS);
|
||||
when(fakeView.findViewById(anyInt())).thenReturn(fakeView);
|
||||
mFragment = spy(mFragment);
|
||||
when(mFragment.getView()).thenReturn(fakeView);
|
||||
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
|
||||
|
||||
mFragment.maybeSetLoading(false);
|
||||
|
||||
verify(mFragment).setLoading(true, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_dontLoadWhenQuotaOffIfVolumeInfoNotLoaded() {
|
||||
View fakeView = mock(View.class, RETURNS_DEEP_STUBS);
|
||||
RecyclerView fakeRecyclerView = mock(RecyclerView.class, RETURNS_DEEP_STUBS);
|
||||
when(fakeView.findViewById(anyInt())).thenReturn(fakeView);
|
||||
mFragment = spy(mFragment);
|
||||
when(mFragment.getView()).thenReturn(fakeView);
|
||||
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
|
||||
|
||||
PrivateStorageInfo info = new PrivateStorageInfo(0, 0);
|
||||
mFragment.setPrivateStorageInfo(info);
|
||||
|
||||
mFragment.maybeSetLoading(false);
|
||||
|
||||
verify(mFragment, never()).setLoading(true, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_loadWhenQuotaOnAndVolumeInfoLoadedButAppsMissing() {
|
||||
View fakeView = mock(View.class, RETURNS_DEEP_STUBS);
|
||||
RecyclerView fakeRecyclerView = mock(RecyclerView.class, RETURNS_DEEP_STUBS);
|
||||
when(fakeView.findViewById(anyInt())).thenReturn(fakeView);
|
||||
mFragment = spy(mFragment);
|
||||
when(mFragment.getView()).thenReturn(fakeView);
|
||||
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
|
||||
|
||||
PrivateStorageInfo info = new PrivateStorageInfo(0, 0);
|
||||
mFragment.setPrivateStorageInfo(info);
|
||||
|
||||
mFragment.maybeSetLoading(true);
|
||||
|
||||
verify(mFragment).setLoading(true, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_loadWhenQuotaOnAndAppsLoadedButVolumeInfoMissing() {
|
||||
View fakeView = mock(View.class, RETURNS_DEEP_STUBS);
|
||||
RecyclerView fakeRecyclerView = mock(RecyclerView.class, RETURNS_DEEP_STUBS);
|
||||
when(fakeView.findViewById(anyInt())).thenReturn(fakeView);
|
||||
mFragment = spy(mFragment);
|
||||
when(mFragment.getView()).thenReturn(fakeView);
|
||||
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
|
||||
mFragment.setAppsStorageResult(new SparseArray<>());
|
||||
|
||||
mFragment.maybeSetLoading(true);
|
||||
|
||||
verify(mFragment).setLoading(true, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_dontLoadWhenQuotaOnAndAllLoaded() {
|
||||
View fakeView = mock(View.class, RETURNS_DEEP_STUBS);
|
||||
RecyclerView fakeRecyclerView = mock(RecyclerView.class, RETURNS_DEEP_STUBS);
|
||||
when(fakeView.findViewById(anyInt())).thenReturn(fakeView);
|
||||
mFragment = spy(mFragment);
|
||||
when(mFragment.getView()).thenReturn(fakeView);
|
||||
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
|
||||
|
||||
mFragment.setAppsStorageResult(new SparseArray<>());
|
||||
PrivateStorageInfo storageInfo = new PrivateStorageInfo(0, 0);
|
||||
mFragment.setPrivateStorageInfo(storageInfo);
|
||||
|
||||
mFragment.maybeSetLoading(true);
|
||||
|
||||
verify(mFragment, never()).setLoading(true, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_shouldIndexResource() {
|
||||
final List<SearchIndexableResource> indexRes =
|
||||
|
||||
@@ -55,7 +55,7 @@ public class StorageItemPreferenceTest {
|
||||
@Test
|
||||
public void testAfterLoad() {
|
||||
mPreference.setStorageSize(MEGABYTE_IN_BYTES * 10, MEGABYTE_IN_BYTES * 100);
|
||||
assertThat(((String) mPreference.getSummary())).isEqualTo("0.01GB");
|
||||
assertThat(((String) mPreference.getSummary())).isEqualTo("0.01 GB");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.deviceinfo.storage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -33,17 +32,15 @@ import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.deletionhelper.ActivationWarningFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
|
||||
import com.android.settings.widget.MasterSwitchPreference;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -55,7 +52,11 @@ import org.robolectric.annotation.Config;
|
||||
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {SettingsShadowSystemProperties.class}
|
||||
)
|
||||
public class AutomaticStorageManagementSwitchPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
@@ -84,10 +85,17 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_shouldAlwaysReturnTrue() {
|
||||
public void isAvailable_shouldReturnTrue_forHighRamDevice() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_shouldAlwaysReturnFalse_forLowRamDevice() {
|
||||
SettingsShadowSystemProperties.set("ro.config.low_ram", "true");
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
SettingsShadowSystemProperties.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_shouldReflectEnabledStatus() {
|
||||
mController.displayPreference(mScreen);
|
||||
@@ -155,7 +163,6 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {
|
||||
}
|
||||
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void togglingOnShouldNotTriggerWarningFragmentIfEnabledByDefault() {
|
||||
FragmentTransaction transaction = mock(FragmentTransaction.class);
|
||||
@@ -169,7 +176,6 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {
|
||||
verify(transaction, never()).add(any(), eq(ActivationWarningFragment.TAG));
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void togglingOnShouldTriggerWarningFragmentIfEnabledByDefaultAndDisabledByPolicy() {
|
||||
FragmentTransaction transaction = mock(FragmentTransaction.class);
|
||||
|
||||
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.storage;
|
||||
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.CACHE_APPS_SIZE_KEY;
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.EXTERNAL_APP_BYTES;
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.EXTERNAL_AUDIO_BYTES;
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.EXTERNAL_IMAGE_BYTES;
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.EXTERNAL_TOTAL_BYTES;
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.EXTERNAL_VIDEO_BYTES;
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.FREE_BYTES_KEY;
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.GAME_APPS_SIZE_KEY;
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.MUSIC_APPS_SIZE_KEY;
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.OTHER_APPS_SIZE_KEY;
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.PHOTO_APPS_SIZE_KEY;
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.SHARED_PREFERENCES_NAME;
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.TIMESTAMP_KEY;
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.TOTAL_BYTES_KEY;
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.USER_ID_KEY;
|
||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.VIDEO_APPS_SIZE_KEY;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
|
||||
|
||||
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.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class CachedStorageValuesHelperTest {
|
||||
private Context mContext;
|
||||
|
||||
@Mock private CachedStorageValuesHelper.Clock mMockClock;
|
||||
private CachedStorageValuesHelper mCachedValuesHelper;
|
||||
private SharedPreferences mSharedPreferences;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application.getApplicationContext();
|
||||
mSharedPreferences = mContext.getSharedPreferences(SHARED_PREFERENCES_NAME, 0);
|
||||
mCachedValuesHelper = new CachedStorageValuesHelper(mContext, 0);
|
||||
mCachedValuesHelper.mClock = mMockClock;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCachedPrivateStorageInfo_cachedValuesAreLoaded() throws Exception {
|
||||
when(mMockClock.getCurrentTime()).thenReturn(10001L);
|
||||
mSharedPreferences
|
||||
.edit()
|
||||
.putLong(GAME_APPS_SIZE_KEY, 0)
|
||||
.putLong(MUSIC_APPS_SIZE_KEY, 10)
|
||||
.putLong(VIDEO_APPS_SIZE_KEY, 100)
|
||||
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
|
||||
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
||||
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
||||
.putLong(EXTERNAL_TOTAL_BYTES, 2)
|
||||
.putLong(EXTERNAL_AUDIO_BYTES, 22)
|
||||
.putLong(EXTERNAL_VIDEO_BYTES, 222)
|
||||
.putLong(EXTERNAL_IMAGE_BYTES, 2222)
|
||||
.putLong(EXTERNAL_APP_BYTES, 22222)
|
||||
.putLong(FREE_BYTES_KEY, 1000L)
|
||||
.putLong(TOTAL_BYTES_KEY, 6000L)
|
||||
.putInt(USER_ID_KEY, 0)
|
||||
.putLong(TIMESTAMP_KEY, 10000L)
|
||||
.apply();
|
||||
|
||||
PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
|
||||
|
||||
assertThat(info.freeBytes).isEqualTo(1000L);
|
||||
assertThat(info.totalBytes).isEqualTo(6000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCachedAppsStorageResult_cachedValuesAreLoaded() throws Exception {
|
||||
when(mMockClock.getCurrentTime()).thenReturn(10001L);
|
||||
mSharedPreferences
|
||||
.edit()
|
||||
.putLong(GAME_APPS_SIZE_KEY, 1)
|
||||
.putLong(MUSIC_APPS_SIZE_KEY, 10)
|
||||
.putLong(VIDEO_APPS_SIZE_KEY, 100)
|
||||
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
|
||||
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
||||
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
||||
.putLong(EXTERNAL_TOTAL_BYTES, 222222)
|
||||
.putLong(EXTERNAL_AUDIO_BYTES, 22)
|
||||
.putLong(EXTERNAL_VIDEO_BYTES, 222)
|
||||
.putLong(EXTERNAL_IMAGE_BYTES, 2222)
|
||||
.putLong(EXTERNAL_APP_BYTES, 22222)
|
||||
.putLong(FREE_BYTES_KEY, 1000L)
|
||||
.putLong(TOTAL_BYTES_KEY, 5000L)
|
||||
.putInt(USER_ID_KEY, 0)
|
||||
.putLong(TIMESTAMP_KEY, 10000L)
|
||||
.apply();
|
||||
|
||||
SparseArray<StorageAsyncLoader.AppsStorageResult> result =
|
||||
mCachedValuesHelper.getCachedAppsStorageResult();
|
||||
|
||||
StorageAsyncLoader.AppsStorageResult primaryResult = result.get(0);
|
||||
assertThat(primaryResult.gamesSize).isEqualTo(1L);
|
||||
assertThat(primaryResult.musicAppsSize).isEqualTo(10L);
|
||||
assertThat(primaryResult.videoAppsSize).isEqualTo(100L);
|
||||
assertThat(primaryResult.photosAppsSize).isEqualTo(1000L);
|
||||
assertThat(primaryResult.otherAppsSize).isEqualTo(10000L);
|
||||
assertThat(primaryResult.cacheSize).isEqualTo(100000L);
|
||||
assertThat(primaryResult.externalStats.totalBytes).isEqualTo(222222L);
|
||||
assertThat(primaryResult.externalStats.audioBytes).isEqualTo(22L);
|
||||
assertThat(primaryResult.externalStats.videoBytes).isEqualTo(222L);
|
||||
assertThat(primaryResult.externalStats.imageBytes).isEqualTo(2222L);
|
||||
assertThat(primaryResult.externalStats.appBytes).isEqualTo(22222L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCachedPrivateStorageInfo_nullIfDataIsStale() throws Exception {
|
||||
when(mMockClock.getCurrentTime()).thenReturn(10000000L);
|
||||
mSharedPreferences
|
||||
.edit()
|
||||
.putLong(GAME_APPS_SIZE_KEY, 0)
|
||||
.putLong(MUSIC_APPS_SIZE_KEY, 10)
|
||||
.putLong(VIDEO_APPS_SIZE_KEY, 100)
|
||||
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
|
||||
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
||||
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
||||
.putLong(EXTERNAL_TOTAL_BYTES, 2)
|
||||
.putLong(EXTERNAL_AUDIO_BYTES, 22)
|
||||
.putLong(EXTERNAL_VIDEO_BYTES, 222)
|
||||
.putLong(EXTERNAL_IMAGE_BYTES, 2222)
|
||||
.putLong(EXTERNAL_APP_BYTES, 22222)
|
||||
.putLong(FREE_BYTES_KEY, 1000L)
|
||||
.putLong(TOTAL_BYTES_KEY, 5000L)
|
||||
.putInt(USER_ID_KEY, 0)
|
||||
.putLong(TIMESTAMP_KEY, 10000L)
|
||||
.apply();
|
||||
|
||||
PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
|
||||
assertThat(info).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCachedAppsStorageResult_nullIfDataIsStale() throws Exception {
|
||||
when(mMockClock.getCurrentTime()).thenReturn(10000000L);
|
||||
mSharedPreferences
|
||||
.edit()
|
||||
.putLong(GAME_APPS_SIZE_KEY, 0)
|
||||
.putLong(MUSIC_APPS_SIZE_KEY, 10)
|
||||
.putLong(VIDEO_APPS_SIZE_KEY, 100)
|
||||
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
|
||||
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
||||
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
||||
.putLong(EXTERNAL_TOTAL_BYTES, 2)
|
||||
.putLong(EXTERNAL_AUDIO_BYTES, 22)
|
||||
.putLong(EXTERNAL_VIDEO_BYTES, 222)
|
||||
.putLong(EXTERNAL_IMAGE_BYTES, 2222)
|
||||
.putLong(EXTERNAL_APP_BYTES, 22222)
|
||||
.putLong(FREE_BYTES_KEY, 1000L)
|
||||
.putLong(TOTAL_BYTES_KEY, 5000L)
|
||||
.putInt(USER_ID_KEY, 0)
|
||||
.putLong(TIMESTAMP_KEY, 10000L)
|
||||
.apply();
|
||||
|
||||
SparseArray<StorageAsyncLoader.AppsStorageResult> result =
|
||||
mCachedValuesHelper.getCachedAppsStorageResult();
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCachedPrivateStorageInfo_nullIfWrongUser() throws Exception {
|
||||
when(mMockClock.getCurrentTime()).thenReturn(10001L);
|
||||
mSharedPreferences
|
||||
.edit()
|
||||
.putLong(GAME_APPS_SIZE_KEY, 0)
|
||||
.putLong(MUSIC_APPS_SIZE_KEY, 10)
|
||||
.putLong(VIDEO_APPS_SIZE_KEY, 100)
|
||||
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
|
||||
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
||||
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
||||
.putLong(EXTERNAL_TOTAL_BYTES, 2)
|
||||
.putLong(EXTERNAL_AUDIO_BYTES, 22)
|
||||
.putLong(EXTERNAL_VIDEO_BYTES, 222)
|
||||
.putLong(EXTERNAL_IMAGE_BYTES, 2222)
|
||||
.putLong(EXTERNAL_APP_BYTES, 22222)
|
||||
.putLong(FREE_BYTES_KEY, 1000L)
|
||||
.putLong(TOTAL_BYTES_KEY, 5000L)
|
||||
.putInt(USER_ID_KEY, 1)
|
||||
.putLong(TIMESTAMP_KEY, 10000L)
|
||||
.apply();
|
||||
|
||||
PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
|
||||
assertThat(info).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCachedAppsStorageResult_nullIfWrongUser() throws Exception {
|
||||
when(mMockClock.getCurrentTime()).thenReturn(10001L);
|
||||
mSharedPreferences
|
||||
.edit()
|
||||
.putLong(GAME_APPS_SIZE_KEY, 0)
|
||||
.putLong(MUSIC_APPS_SIZE_KEY, 10)
|
||||
.putLong(VIDEO_APPS_SIZE_KEY, 100)
|
||||
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
|
||||
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
||||
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
||||
.putLong(EXTERNAL_TOTAL_BYTES, 2)
|
||||
.putLong(EXTERNAL_AUDIO_BYTES, 22)
|
||||
.putLong(EXTERNAL_VIDEO_BYTES, 222)
|
||||
.putLong(EXTERNAL_IMAGE_BYTES, 2222)
|
||||
.putLong(EXTERNAL_APP_BYTES, 22222)
|
||||
.putLong(FREE_BYTES_KEY, 1000L)
|
||||
.putLong(TOTAL_BYTES_KEY, 5000L)
|
||||
.putInt(USER_ID_KEY, 1)
|
||||
.putLong(TIMESTAMP_KEY, 10000L)
|
||||
.apply();
|
||||
|
||||
SparseArray<StorageAsyncLoader.AppsStorageResult> result =
|
||||
mCachedValuesHelper.getCachedAppsStorageResult();
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCachedPrivateStorageInfo_nullIfEmpty() throws Exception {
|
||||
PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
|
||||
assertThat(info).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCachedAppsStorageResult_nullIfEmpty() throws Exception {
|
||||
SparseArray<StorageAsyncLoader.AppsStorageResult> result =
|
||||
mCachedValuesHelper.getCachedAppsStorageResult();
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cacheResult_succeeds() throws Exception {
|
||||
when(mMockClock.getCurrentTime()).thenReturn(10000L);
|
||||
final StorageStatsSource.ExternalStorageStats externalStats =
|
||||
new StorageStatsSource.ExternalStorageStats(22222l, 2l, 20L, 200L, 2000L);
|
||||
final StorageAsyncLoader.AppsStorageResult result =
|
||||
new StorageAsyncLoader.AppsStorageResult();
|
||||
result.gamesSize = 1L;
|
||||
result.musicAppsSize = 10l;
|
||||
result.videoAppsSize = 100L;
|
||||
result.photosAppsSize = 1000L;
|
||||
result.otherAppsSize = 10000L;
|
||||
result.cacheSize = 100000l;
|
||||
result.externalStats = externalStats;
|
||||
final PrivateStorageInfo info = new PrivateStorageInfo(1000L, 6000L);
|
||||
|
||||
mCachedValuesHelper.cacheResult(info, result);
|
||||
|
||||
assertThat(mSharedPreferences.getLong(GAME_APPS_SIZE_KEY, -1)).isEqualTo(1L);
|
||||
assertThat(mSharedPreferences.getLong(MUSIC_APPS_SIZE_KEY, -1)).isEqualTo(10L);
|
||||
assertThat(mSharedPreferences.getLong(VIDEO_APPS_SIZE_KEY, -1)).isEqualTo(100L);
|
||||
assertThat(mSharedPreferences.getLong(PHOTO_APPS_SIZE_KEY, -1)).isEqualTo(1000L);
|
||||
assertThat(mSharedPreferences.getLong(OTHER_APPS_SIZE_KEY, -1)).isEqualTo(10000L);
|
||||
assertThat(mSharedPreferences.getLong(CACHE_APPS_SIZE_KEY, -1)).isEqualTo(100000L);
|
||||
assertThat(mSharedPreferences.getLong(EXTERNAL_TOTAL_BYTES, -1)).isEqualTo(22222L);
|
||||
assertThat(mSharedPreferences.getLong(EXTERNAL_AUDIO_BYTES, -1)).isEqualTo(2L);
|
||||
assertThat(mSharedPreferences.getLong(EXTERNAL_VIDEO_BYTES, -1)).isEqualTo(20L);
|
||||
assertThat(mSharedPreferences.getLong(EXTERNAL_IMAGE_BYTES, -1)).isEqualTo(200L);
|
||||
assertThat(mSharedPreferences.getLong(EXTERNAL_APP_BYTES, -1)).isEqualTo(2000L);
|
||||
assertThat(mSharedPreferences.getLong(FREE_BYTES_KEY, -1)).isEqualTo(1000L);
|
||||
assertThat(mSharedPreferences.getLong(TOTAL_BYTES_KEY, -1)).isEqualTo(6000L);
|
||||
assertThat(mSharedPreferences.getInt(USER_ID_KEY, -1)).isEqualTo(0);
|
||||
assertThat(mSharedPreferences.getLong(TIMESTAMP_KEY, -1)).isEqualTo(10000L);
|
||||
};
|
||||
}
|
||||
@@ -16,9 +16,10 @@
|
||||
|
||||
package com.android.settings.deviceinfo.storage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -36,9 +37,9 @@ import android.util.SparseArray;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.UserManagerWrapper;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settingslib.R;
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.drawable.UserIconDrawable;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -103,7 +104,7 @@ public class SecondaryUserControllerTest {
|
||||
verify(mGroup).addPreference(argumentCaptor.capture());
|
||||
|
||||
Preference preference = argumentCaptor.getValue();
|
||||
assertThat(preference.getSummary()).isEqualTo("0.01GB");
|
||||
assertThat(preference.getSummary()).isEqualTo("0.01 GB");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,7 +113,7 @@ public class SecondaryUserControllerTest {
|
||||
userInfos.add(mPrimaryUser);
|
||||
when(mUserManager.getPrimaryUser()).thenReturn(mPrimaryUser);
|
||||
when(mUserManager.getUsers()).thenReturn(userInfos);
|
||||
List<PreferenceController> controllers =
|
||||
List<AbstractPreferenceController> controllers =
|
||||
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager);
|
||||
|
||||
assertThat(controllers).hasSize(1);
|
||||
@@ -130,7 +131,7 @@ public class SecondaryUserControllerTest {
|
||||
userInfos.add(secondaryUser);
|
||||
when(mUserManager.getPrimaryUser()).thenReturn(mPrimaryUser);
|
||||
when(mUserManager.getUsers()).thenReturn(userInfos);
|
||||
List<PreferenceController> controllers =
|
||||
List<AbstractPreferenceController> controllers =
|
||||
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager);
|
||||
|
||||
assertThat(controllers).hasSize(1);
|
||||
@@ -147,7 +148,7 @@ public class SecondaryUserControllerTest {
|
||||
when(mUserManager.getPrimaryUser()).thenReturn(mPrimaryUser);
|
||||
when(mUserManager.getUsers()).thenReturn(userInfos);
|
||||
|
||||
List<PreferenceController> controllers =
|
||||
List<AbstractPreferenceController> controllers =
|
||||
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager);
|
||||
|
||||
assertThat(controllers).hasSize(2);
|
||||
@@ -176,7 +177,7 @@ public class SecondaryUserControllerTest {
|
||||
verify(mGroup).addPreference(argumentCaptor.capture());
|
||||
Preference preference = argumentCaptor.getValue();
|
||||
|
||||
assertThat(preference.getSummary()).isEqualTo("0.03GB");
|
||||
assertThat(preference.getSummary()).isEqualTo("0.03 GB");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -190,7 +191,7 @@ public class SecondaryUserControllerTest {
|
||||
userInfos.add(primaryUserRenamed);
|
||||
when(mUserManager.getPrimaryUser()).thenReturn(mPrimaryUser);
|
||||
when(mUserManager.getUsers()).thenReturn(userInfos);
|
||||
List<PreferenceController> controllers =
|
||||
List<AbstractPreferenceController> controllers =
|
||||
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager);
|
||||
|
||||
assertThat(controllers).hasSize(1);
|
||||
|
||||
@@ -16,12 +16,13 @@
|
||||
package com.android.settings.deviceinfo.storage;
|
||||
|
||||
|
||||
import static com.android.settings.applications.ManageApplications.EXTRA_WORK_ID;
|
||||
import static com.android.settings.applications.ManageApplications.EXTRA_WORK_ONLY;
|
||||
import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -84,8 +85,6 @@ public class StorageItemPreferenceControllerTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
SettingsShadowResources.overrideResource("android:string/fileSizeSuffix", "%1$s %2$s");
|
||||
SettingsShadowResources.overrideResource("android:string/gigabyteShort", "GB");
|
||||
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
@@ -123,9 +122,12 @@ public class StorageItemPreferenceControllerTest {
|
||||
nullable(UserHandle.class));
|
||||
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
assertThat(intent.getType()).isEqualTo("image/*");
|
||||
assertThat(intent.getAction()).isEqualTo(android.content.Intent.ACTION_VIEW);
|
||||
assertThat(intent.getBooleanExtra(Intent.EXTRA_FROM_STORAGE, false)).isTrue();
|
||||
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
|
||||
assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
|
||||
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||
.isEqualTo(ManageApplications.class.getName());
|
||||
assertThat(intent.getIntExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, 0))
|
||||
.isEqualTo(R.string.storage_photos_videos);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,6 +175,33 @@ public class StorageItemPreferenceControllerTest {
|
||||
.isEqualTo(R.string.apps_storage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClickAppsForWork() {
|
||||
mController = new StorageItemPreferenceController(mContext, mFragment, mVolume, mSvp, true);
|
||||
mPreference.setKey("pref_other_apps");
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment.getActivity())
|
||||
.startActivityAsUser(argumentCaptor.capture(), nullable(UserHandle.class));
|
||||
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
|
||||
assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
|
||||
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||
.isEqualTo(ManageApplications.class.getName());
|
||||
assertThat(intent.getIntExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, 0))
|
||||
.isEqualTo(R.string.apps_storage);
|
||||
assertThat(
|
||||
intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS)
|
||||
.getBoolean(EXTRA_WORK_ONLY))
|
||||
.isTrue();
|
||||
assertThat(
|
||||
intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS)
|
||||
.getInt(EXTRA_WORK_ID))
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_tappingAppsWhileUninitializedDoesntCrash() {
|
||||
mController.setVolume(null);
|
||||
@@ -287,12 +316,12 @@ public class StorageItemPreferenceControllerTest {
|
||||
results.put(0, result);
|
||||
mController.onLoadFinished(results, 0);
|
||||
|
||||
assertThat(audio.getSummary().toString()).isEqualTo("0.14GB");
|
||||
assertThat(image.getSummary().toString()).isEqualTo("0.35GB");
|
||||
assertThat(games.getSummary().toString()).isEqualTo("0.08GB");
|
||||
assertThat(movies.getSummary().toString()).isEqualTo("0.16GB");
|
||||
assertThat(apps.getSummary().toString()).isEqualTo("0.09GB");
|
||||
assertThat(files.getSummary().toString()).isEqualTo("0.05GB");
|
||||
assertThat(audio.getSummary().toString()).isEqualTo("0.14 GB");
|
||||
assertThat(image.getSummary().toString()).isEqualTo("0.35 GB");
|
||||
assertThat(games.getSummary().toString()).isEqualTo("0.08 GB");
|
||||
assertThat(movies.getSummary().toString()).isEqualTo("0.16 GB");
|
||||
assertThat(apps.getSummary().toString()).isEqualTo("0.09 GB");
|
||||
assertThat(files.getSummary().toString()).isEqualTo("0.05 GB");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -122,7 +122,7 @@ public class UserProfileControllerTest {
|
||||
verify(mScreen).addPreference(argumentCaptor.capture());
|
||||
Preference preference = argumentCaptor.getValue();
|
||||
|
||||
assertThat(preference.getSummary()).isEqualTo("0.10GB");
|
||||
assertThat(preference.getSummary()).isEqualTo("0.10 GB");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -45,7 +45,11 @@ import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = ShadowSystemSettings.class
|
||||
)
|
||||
public class AutoRotatePreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@@ -88,7 +92,6 @@ public class AutoRotatePreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowSystemSettings.class)
|
||||
public void updatePreference_settingsIsOff_shouldTurnOffToggle() {
|
||||
Settings.System.putIntForUser(mContentResolver,
|
||||
Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT);
|
||||
@@ -99,7 +102,6 @@ public class AutoRotatePreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowSystemSettings.class)
|
||||
public void updatePreference_settingsIsOn_shouldTurnOnToggle() {
|
||||
Settings.System.putIntForUser(mContentResolver,
|
||||
Settings.System.ACCELEROMETER_ROTATION, 1, UserHandle.USER_CURRENT);
|
||||
|
||||
@@ -79,14 +79,14 @@ public class BrightnessLevelPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_shouldRegisterObserver() {
|
||||
public void onStart_shouldRegisterObserver() {
|
||||
Context context = RuntimeEnvironment.application;
|
||||
BrightnessLevelPreferenceController controller =
|
||||
new BrightnessLevelPreferenceController(context, null, mPowerManager);
|
||||
ShadowContentResolver shadowContentResolver =
|
||||
(ShadowContentResolver) ShadowExtractor.extract(context.getContentResolver());
|
||||
|
||||
controller.onResume();
|
||||
controller.onStart();
|
||||
|
||||
assertThat(shadowContentResolver.getContentObservers(
|
||||
System.getUriFor(System.SCREEN_BRIGHTNESS_MODE))).isNotEmpty();
|
||||
@@ -99,7 +99,7 @@ public class BrightnessLevelPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_shouldUnregisterObserver() {
|
||||
public void onStop_shouldUnregisterObserver() {
|
||||
Context context = RuntimeEnvironment.application;
|
||||
BrightnessLevelPreferenceController controller =
|
||||
new BrightnessLevelPreferenceController(context, null, mPowerManager);
|
||||
@@ -107,8 +107,8 @@ public class BrightnessLevelPreferenceControllerTest {
|
||||
(ShadowContentResolver) ShadowExtractor.extract(context.getContentResolver());
|
||||
|
||||
controller.displayPreference(mScreen);
|
||||
controller.onResume();
|
||||
controller.onPause();
|
||||
controller.onStart();
|
||||
controller.onStop();
|
||||
|
||||
assertThat(shadowContentResolver.getContentObservers(
|
||||
System.getUriFor(System.SCREEN_BRIGHTNESS_MODE))).isEmpty();
|
||||
|
||||
@@ -16,6 +16,13 @@
|
||||
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import static com.android.settings.testutils.ApplicationTestUtils.buildInfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
@@ -27,7 +34,7 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.applications.UserAppInfo;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -40,11 +47,6 @@ import org.robolectric.shadows.ShadowApplication;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.android.settings.testutils.ApplicationTestUtils.buildInfo;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ApplicationListFragmentTest {
|
||||
@@ -84,7 +86,7 @@ public class ApplicationListFragmentTest {
|
||||
|
||||
@Test
|
||||
public void getPreferenceControllers() {
|
||||
final List<PreferenceController> controllers = mFragment.getPreferenceControllers(mContext);
|
||||
final List<AbstractPreferenceController> controllers = mFragment.getPreferenceControllers(mContext);
|
||||
assertThat(controllers).isNotNull();
|
||||
assertThat(controllers.size()).isEqualTo(1);
|
||||
int position = 0;
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.enterprise;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
/**
|
||||
* Tests for {@link CaCertsCurrentUserPreferenceController}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class CaCertsCurrentUserPreferenceControllerTest extends
|
||||
CaCertsPreferenceControllerTestBase {
|
||||
|
||||
private static final String CA_CERT_DEVICE = "CA certs";
|
||||
private static final String CA_CERT_PERSONAL = "CA certs in personal profile";
|
||||
|
||||
@Before
|
||||
public void mockGetString() {
|
||||
when(mContext.getString(R.string.enterprise_privacy_ca_certs_device))
|
||||
.thenReturn(CA_CERT_DEVICE);
|
||||
when(mContext.getString(R.string.enterprise_privacy_ca_certs_personal))
|
||||
.thenReturn(CA_CERT_PERSONAL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_nonCompMode() {
|
||||
assertUpdateState(false /* isCompMode */, CA_CERT_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_compMode() {
|
||||
assertUpdateState(true /* isCompMode */, CA_CERT_PERSONAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
void mockGetNumberOfCaCerts(int numOfCaCerts) {
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider
|
||||
.getNumberOfOwnerInstalledCaCertsForCurrentUser()).thenReturn(numOfCaCerts);
|
||||
}
|
||||
|
||||
@Override
|
||||
String getPreferenceKey() {
|
||||
return CaCertsCurrentUserPreferenceController.CA_CERTS_CURRENT_USER;
|
||||
}
|
||||
|
||||
@Override
|
||||
CaCertsPreferenceControllerBase createController() {
|
||||
return new CaCertsCurrentUserPreferenceController(mContext, null /* lifecycle */);
|
||||
}
|
||||
|
||||
private void assertUpdateState(boolean isCompMode, String expectedTitle) {
|
||||
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||
|
||||
mockGetNumberOfCaCerts(2);
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode())
|
||||
.thenReturn(isCompMode);
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.getTitle()).isEqualTo(expectedTitle);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.enterprise;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
/**
|
||||
* Tests for {@link CaCertsManagedProfilePreferenceController}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class CaCertsManagedProfilePreferenceControllerTest extends
|
||||
CaCertsPreferenceControllerTestBase {
|
||||
|
||||
@Override
|
||||
void mockGetNumberOfCaCerts(int numOfCaCerts) {
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider
|
||||
.getNumberOfOwnerInstalledCaCertsForManagedProfile()).thenReturn(numOfCaCerts);
|
||||
}
|
||||
|
||||
@Override
|
||||
String getPreferenceKey() {
|
||||
return CaCertsManagedProfilePreferenceController.CA_CERTS_MANAGED_PROFILE;
|
||||
}
|
||||
|
||||
@Override
|
||||
CaCertsPreferenceControllerBase createController() {
|
||||
return new CaCertsManagedProfilePreferenceController(mContext, null /* lifecycle */);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
/**
|
||||
* Tests for {@link CaCertsPreferenceControllerBase}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class CaCertsPreferenceControllerBaseTest extends CaCertsPreferenceControllerTestBase {
|
||||
private static final String PREF_KEY = "pref";
|
||||
|
||||
private int mNumOfCaCerts;
|
||||
|
||||
void mockGetNumberOfCaCerts(int numOfCaCerts) {
|
||||
mNumOfCaCerts = numOfCaCerts;
|
||||
}
|
||||
|
||||
String getPreferenceKey() {
|
||||
return PREF_KEY;
|
||||
}
|
||||
|
||||
CaCertsPreferenceControllerBase createController() {
|
||||
return new CaCertsPreferenceControllerBaseTestable(mContext);
|
||||
}
|
||||
|
||||
private class CaCertsPreferenceControllerBaseTestable extends
|
||||
CaCertsPreferenceControllerBase {
|
||||
|
||||
public CaCertsPreferenceControllerBaseTestable(Context context) {
|
||||
super(context, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return PREF_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getNumberOfCaCerts() {
|
||||
return mNumOfCaCerts;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,50 +16,42 @@
|
||||
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.android.settings.R;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceAvailabilityObserver;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link CaCertsPreferenceController}.
|
||||
* Base test class for testing {@link CaCertsPreferenceControllerBase}'s subclass.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class CaCertsPreferenceControllerTest {
|
||||
|
||||
private static final String KEY_CA_CERTS = "ca_certs";
|
||||
public abstract class CaCertsPreferenceControllerTestBase {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
@Mock private PreferenceAvailabilityObserver mObserver;
|
||||
|
||||
private CaCertsPreferenceController mController;
|
||||
protected Context mContext;
|
||||
protected FakeFeatureFactory mFeatureFactory;
|
||||
protected CaCertsPreferenceControllerBase mController;
|
||||
@Mock
|
||||
private PreferenceAvailabilityObserver mObserver;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mController = new CaCertsPreferenceController(mContext, null /* lifecycle */);
|
||||
mController = createController();
|
||||
mController.setAvailabilityObserver(mObserver);
|
||||
}
|
||||
|
||||
@@ -74,23 +66,20 @@ public final class CaCertsPreferenceControllerTest {
|
||||
|
||||
when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_ca_certs,
|
||||
10, 10)).thenReturn("10 certs");
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider
|
||||
.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()).thenReturn(10);
|
||||
mockGetNumberOfCaCerts(10);
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.getSummary()).isEqualTo("10 certs");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider
|
||||
.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()).thenReturn(0);
|
||||
mockGetNumberOfCaCerts(0);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
verify(mObserver).onPreferenceAvailabilityUpdated(KEY_CA_CERTS, false);
|
||||
verify(mObserver).onPreferenceAvailabilityUpdated(getPreferenceKey(), false);
|
||||
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider
|
||||
.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()).thenReturn(10);
|
||||
mockGetNumberOfCaCerts(10);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
verify(mObserver).onPreferenceAvailabilityUpdated(KEY_CA_CERTS, true);
|
||||
verify(mObserver).onPreferenceAvailabilityUpdated(getPreferenceKey(), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,6 +90,13 @@ public final class CaCertsPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testGetPreferenceKey() {
|
||||
assertThat(mController.getPreferenceKey()).isEqualTo(KEY_CA_CERTS);
|
||||
assertThat(mController.getPreferenceKey()).isEqualTo(getPreferenceKey());
|
||||
}
|
||||
|
||||
abstract void mockGetNumberOfCaCerts(int numOfCaCerts);
|
||||
|
||||
abstract String getPreferenceKey();
|
||||
|
||||
abstract CaCertsPreferenceControllerBase createController();
|
||||
|
||||
}
|
||||
@@ -288,7 +288,7 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile() {
|
||||
public void testGetNumberOfOwnerInstalledCaCertsForCurrent() {
|
||||
final UserHandle userHandle = new UserHandle(UserHandle.USER_SYSTEM);
|
||||
final UserHandle managedProfileUserHandle = new UserHandle(MANAGED_PROFILE_USER_ID);
|
||||
final UserInfo managedProfile =
|
||||
@@ -299,33 +299,44 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
|
||||
when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
|
||||
.thenReturn(null);
|
||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile())
|
||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUser())
|
||||
.isEqualTo(0);
|
||||
when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
|
||||
.thenReturn(new ArrayList<String>());
|
||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile())
|
||||
.thenReturn(new ArrayList<>());
|
||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUser())
|
||||
.isEqualTo(0);
|
||||
when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
|
||||
.thenReturn(Arrays.asList(new String[] {"ca1", "ca2"}));
|
||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile())
|
||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUser())
|
||||
.isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNumberOfOwnerInstalledCaCertsForManagedProfile() {
|
||||
final UserHandle userHandle = new UserHandle(UserHandle.USER_SYSTEM);
|
||||
final UserHandle managedProfileUserHandle = new UserHandle(MANAGED_PROFILE_USER_ID);
|
||||
final UserInfo managedProfile =
|
||||
new UserInfo(MANAGED_PROFILE_USER_ID, "", "", UserInfo.FLAG_MANAGED_PROFILE);
|
||||
|
||||
// Without a profile
|
||||
when(mDevicePolicyManager.getOwnerInstalledCaCerts(managedProfileUserHandle))
|
||||
.thenReturn(Arrays.asList(new String[] {"ca1", "ca2"}));
|
||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForManagedProfile())
|
||||
.isEqualTo(0);
|
||||
|
||||
// With a profile
|
||||
mProfiles.add(managedProfile);
|
||||
when(mDevicePolicyManager.getOwnerInstalledCaCerts(managedProfileUserHandle))
|
||||
.thenReturn(null);
|
||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile())
|
||||
.isEqualTo(2);
|
||||
when(mDevicePolicyManager.getOwnerInstalledCaCerts(managedProfileUserHandle))
|
||||
.thenReturn(new ArrayList<String>());
|
||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile())
|
||||
.isEqualTo(2);
|
||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForManagedProfile())
|
||||
.isEqualTo(0);
|
||||
when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
|
||||
.thenReturn(new ArrayList<>());
|
||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForManagedProfile())
|
||||
.isEqualTo(0);
|
||||
when(mDevicePolicyManager.getOwnerInstalledCaCerts(managedProfileUserHandle))
|
||||
.thenReturn(Arrays.asList(new String[] {"ca1", "ca2"}));
|
||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile())
|
||||
.isEqualTo(4);
|
||||
|
||||
mProfiles.remove(managedProfile);
|
||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile())
|
||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForManagedProfile())
|
||||
.isEqualTo(2);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,16 +16,20 @@
|
||||
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.XmlResourceParser;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.DynamicAvailabilityPreferenceController;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -42,9 +46,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link EnterprisePrivacySettings}.
|
||||
*/
|
||||
@@ -111,23 +112,23 @@ public final class EnterprisePrivacySettingsTest {
|
||||
|
||||
@Test
|
||||
public void getPreferenceControllers() throws Exception {
|
||||
final List<PreferenceController> controllers = mSettings.getPreferenceControllers(
|
||||
final List<AbstractPreferenceController> controllers = mSettings.getPreferenceControllers(
|
||||
ShadowApplication.getInstance().getApplicationContext());
|
||||
verifyPreferenceControllers(controllers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSearchIndexProviderPreferenceControllers() throws Exception {
|
||||
final List<PreferenceController> controllers
|
||||
final List<AbstractPreferenceController> controllers
|
||||
= EnterprisePrivacySettings.SEARCH_INDEX_DATA_PROVIDER.getPreferenceControllers(
|
||||
ShadowApplication.getInstance().getApplicationContext());
|
||||
verifyPreferenceControllers(controllers);
|
||||
}
|
||||
|
||||
private void verifyPreferenceControllers(List<PreferenceController> controllers)
|
||||
private void verifyPreferenceControllers(List<AbstractPreferenceController> controllers)
|
||||
throws Exception {
|
||||
assertThat(controllers).isNotNull();
|
||||
assertThat(controllers.size()).isEqualTo(16);
|
||||
assertThat(controllers.size()).isEqualTo(17);
|
||||
int position = 0;
|
||||
assertThat(controllers.get(position++)).isInstanceOf(NetworkLogsPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(BugReportsPreferenceController.class);
|
||||
@@ -151,8 +152,11 @@ public final class EnterprisePrivacySettingsTest {
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
GlobalHttpProxyPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
CaCertsPreferenceController.class);
|
||||
final PreferenceController exposureChangesCategoryController = controllers.get(position);
|
||||
CaCertsCurrentUserPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
CaCertsManagedProfilePreferenceController.class);
|
||||
final AbstractPreferenceController exposureChangesCategoryController =
|
||||
controllers.get(position);
|
||||
final int exposureChangesCategoryControllerIndex = position;
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
ExposureChangesCategoryPreferenceController.class);
|
||||
@@ -200,7 +204,7 @@ public final class EnterprisePrivacySettingsTest {
|
||||
final Set<String> actualObserved = new HashSet<>();
|
||||
int maxObservedIndex = -1;
|
||||
for (int i = 0; i < controllers.size(); i++) {
|
||||
final PreferenceController controller = controllers.get(i);
|
||||
final AbstractPreferenceController controller = controllers.get(i);
|
||||
if (controller instanceof DynamicAvailabilityPreferenceController &&
|
||||
((DynamicAvailabilityPreferenceController) controller).getAvailabilityObserver()
|
||||
== exposureChangesCategoryController) {
|
||||
|
||||
@@ -16,14 +16,21 @@
|
||||
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -34,10 +41,6 @@ import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class EnterpriseSetDefaultAppsListFragmentTest {
|
||||
@@ -77,7 +80,7 @@ public class EnterpriseSetDefaultAppsListFragmentTest {
|
||||
|
||||
@Test
|
||||
public void getPreferenceControllers() {
|
||||
final List<PreferenceController> controllers = mFragment.getPreferenceControllers(mContext);
|
||||
final List<AbstractPreferenceController> controllers = mFragment.getPreferenceControllers(mContext);
|
||||
assertThat(controllers).isNotNull();
|
||||
assertThat(controllers.size()).isEqualTo(1);
|
||||
int position = 0;
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.fingerprint;
|
||||
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.hardware.fingerprint.Fingerprint;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.fingerprint.FingerprintSettings.FingerprintSettingsFragment;
|
||||
import com.android.settings.fingerprint.FingerprintSettings.FingerprintSettingsFragment
|
||||
.DeleteFingerprintDialog;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.FragmentTestUtil;
|
||||
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
ShadowEventLogWriter.class
|
||||
})
|
||||
public class DeleteFingerprintDialogTest {
|
||||
|
||||
@Mock
|
||||
private FingerprintSettingsFragment mTarget;
|
||||
@Mock
|
||||
private Fingerprint mFingerprint;
|
||||
private DeleteFingerprintDialog mFragment;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFragment = DeleteFingerprintDialog.newInstance(mFingerprint, mTarget);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchDialog_clickPositive_shouldDeleteFingerprint() {
|
||||
FragmentTestUtil.startFragment(mFragment);
|
||||
|
||||
mFragment.onClick(mFragment.getDialog(), Dialog.BUTTON_POSITIVE);
|
||||
|
||||
verify(mTarget).deleteFingerPrint(mFingerprint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchDialog_clickNegative_shouldDoNothing() {
|
||||
FragmentTestUtil.startFragment(mFragment);
|
||||
|
||||
mFragment.onClick(mFragment.getDialog(), Dialog.BUTTON_NEGATIVE);
|
||||
|
||||
verify(mTarget, never()).deleteFingerPrint(mFingerprint);
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,6 @@ import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
import com.android.settings.password.IFingerprintManager;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
|
||||
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
|
||||
@@ -61,7 +60,6 @@ import org.robolectric.shadows.ShadowActivity.IntentForResult;
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class,
|
||||
ShadowDynamicIndexableContentMonitor.class,
|
||||
ShadowEventLogWriter.class,
|
||||
ShadowUtils.class
|
||||
})
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.fingerprint;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.fingerprint.FingerprintSettings.FingerprintPreference;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
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.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class FingerprintPreferenceTest {
|
||||
|
||||
@Mock
|
||||
private FingerprintPreference.OnDeleteClickListener mOnDeleteClickListener;
|
||||
|
||||
private Context mContext;
|
||||
private FingerprintPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPreference = new FingerprintPreference(mContext, mOnDeleteClickListener);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowDeleteButton() {
|
||||
assertThat(mPreference.getSecondTargetResId()).isEqualTo(R.layout.preference_widget_delete);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindAndClickDeleteButton_shouldInvokeOnDeleteListener() {
|
||||
final FrameLayout layout = new FrameLayout(mContext);
|
||||
final View deleteButton = LayoutInflater.from(mContext)
|
||||
.inflate(mPreference.getSecondTargetResId(), layout, true);
|
||||
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(layout);
|
||||
mPreference.onBindViewHolder(holder);
|
||||
|
||||
layout.findViewById(R.id.delete_button).performClick();
|
||||
|
||||
verify(mOnDeleteClickListener).onDeleteClick(mPreference);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Google Inc.
|
||||
*
|
||||
* 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.fingerprint;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.robolectric.RuntimeEnvironment.application;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Intent;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
import com.android.settings.password.IFingerprintManager;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowAlertDialog;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class,
|
||||
ShadowEventLogWriter.class,
|
||||
ShadowUtils.class
|
||||
})
|
||||
public class SetupFingerprintEnrollFindSensorTest {
|
||||
|
||||
@Mock
|
||||
private IFingerprintManager mFingerprintManager;
|
||||
|
||||
private SetupFingerprintEnrollFindSensor mActivity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
ShadowUtils.setFingerprintManager(mFingerprintManager);
|
||||
RuntimeEnvironment.getAppResourceLoader().getResourceIndex();
|
||||
|
||||
}
|
||||
|
||||
private void createActivity(Intent intent) {
|
||||
mActivity = Robolectric.buildActivity(
|
||||
SetupFingerprintEnrollFindSensor.class, intent)
|
||||
.setup().get();
|
||||
}
|
||||
|
||||
private Intent createIntent() {
|
||||
return new Intent()
|
||||
// Set the challenge token so the confirm screen will not be shown
|
||||
.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowUtils.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fingerprintEnroll_showsAlert_whenClickingSkip() {
|
||||
createActivity(createIntent());
|
||||
Button skipButton = mActivity.findViewById(R.id.skip_button);
|
||||
skipButton.performClick();
|
||||
AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
|
||||
assertNotNull(alertDialog);
|
||||
ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(alertDialog);
|
||||
int titleRes = R.string.setup_fingerprint_enroll_skip_title;
|
||||
assertEquals(application.getString(titleRes), shadowAlertDialog.getTitle());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,28 +23,38 @@ import static org.robolectric.RuntimeEnvironment.application;
|
||||
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.fingerprint.SetupFingerprintEnrollIntroductionTest
|
||||
.ShadowStorageManagerWrapper;
|
||||
import com.android.settings.password.SetupChooseLockGeneric.SetupChooseLockGenericFragment;
|
||||
import com.android.settings.password.SetupSkipDialog;
|
||||
import com.android.settings.password.StorageManagerWrapper;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
|
||||
import com.android.settings.testutils.shadow.ShadowFingerprintManager;
|
||||
import com.android.settings.testutils.shadow.ShadowLockPatternUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.shadows.ShadowActivity;
|
||||
import org.robolectric.shadows.ShadowActivity.IntentForResult;
|
||||
import org.robolectric.shadows.ShadowKeyguardManager;
|
||||
import org.robolectric.util.ActivityController;
|
||||
|
||||
@@ -54,7 +64,9 @@ import org.robolectric.util.ActivityController;
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
ShadowEventLogWriter.class,
|
||||
ShadowFingerprintManager.class,
|
||||
ShadowLockPatternUtils.class,
|
||||
ShadowStorageManagerWrapper.class,
|
||||
ShadowUserManager.class
|
||||
})
|
||||
public class SetupFingerprintEnrollIntroductionTest {
|
||||
@@ -68,12 +80,22 @@ public class SetupFingerprintEnrollIntroductionTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
RuntimeEnvironment.getRobolectricPackageManager()
|
||||
.setSystemFeature(PackageManager.FEATURE_FINGERPRINT, true);
|
||||
ShadowFingerprintManager.addToServiceMap();
|
||||
|
||||
final Intent intent = new Intent();
|
||||
mController = Robolectric.buildActivity(SetupFingerprintEnrollIntroduction.class, intent);
|
||||
|
||||
ShadowUserManager.getShadow().setUserInfo(0, mUserInfo);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowStorageManagerWrapper.reset();
|
||||
ShadowFingerprintManager.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeyguardNotSecure_shouldFinishWithSetupSkipDialogResultSkip() {
|
||||
getShadowKeyguardManager().setIsKeyguardSecure(false);
|
||||
@@ -188,8 +210,41 @@ public class SetupFingerprintEnrollIntroductionTest {
|
||||
assertThat(Shadows.shadowOf(activity).getResultIntent()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLockPattern() {
|
||||
ShadowStorageManagerWrapper.sIsFileEncrypted = false;
|
||||
|
||||
mController.create().postCreate(null).resume();
|
||||
|
||||
SetupFingerprintEnrollIntroduction activity = mController.get();
|
||||
|
||||
final Button nextButton = activity.findViewById(R.id.fingerprint_next_button);
|
||||
nextButton.performClick();
|
||||
|
||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||
IntentForResult startedActivity = shadowActivity.getNextStartedActivityForResult();
|
||||
assertThat(startedActivity).isNotNull();
|
||||
assertThat(startedActivity.intent.hasExtra(
|
||||
SetupChooseLockGenericFragment.EXTRA_PASSWORD_QUALITY)).isFalse();
|
||||
}
|
||||
|
||||
|
||||
private ShadowKeyguardManager getShadowKeyguardManager() {
|
||||
return Shadows.shadowOf(application.getSystemService(KeyguardManager.class));
|
||||
}
|
||||
|
||||
@Implements(StorageManagerWrapper.class)
|
||||
public static class ShadowStorageManagerWrapper {
|
||||
|
||||
private static boolean sIsFileEncrypted = true;
|
||||
|
||||
public static void reset() {
|
||||
sIsFileEncrypted = true;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static boolean isFileEncryptedNativeOrEmulated() {
|
||||
return sIsFileEncrypted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,10 +87,17 @@ public class AdvancedPowerUsageDetailTest {
|
||||
private static final int ICON_ID = 123;
|
||||
private static final int UID = 1;
|
||||
private static final int POWER_MAH = 150;
|
||||
private static final long BACKGROUND_TIME_US = 100 * 1000;
|
||||
private static final long FOREGROUND_TIME_US = 200 * 1000;
|
||||
private static final long BACKGROUND_TIME_MS = 100;
|
||||
private static final long FOREGROUND_TIME_MS = 200;
|
||||
private static final long FOREGROUND_ACTIVITY_TIME_MS = 123;
|
||||
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 PROCSTATE_TOP_TIME_MS = FOREGROUND_ACTIVITY_TIME_MS;
|
||||
private static final long BACKGROUND_TIME_US = BACKGROUND_TIME_MS * 1000;
|
||||
private static final long FOREGROUND_ACTIVITY_TIME_US = FOREGROUND_ACTIVITY_TIME_MS * 1000;
|
||||
private static final long FOREGROUND_SERVICE_TIME_US = FOREGROUND_SERVICE_TIME_MS * 1000;
|
||||
private static final long FOREGROUND_TIME_US = FOREGROUND_TIME_MS * 1000;
|
||||
private static final long PROCSTATE_TOP_TIME_US = PROCSTATE_TOP_TIME_MS * 1000;
|
||||
private static final long PHONE_FOREGROUND_TIME_MS = 250 * 1000;
|
||||
private static final long PHONE_BACKGROUND_TIME_MS = 0;
|
||||
|
||||
@@ -123,7 +130,9 @@ public class AdvancedPowerUsageDetailTest {
|
||||
@Mock
|
||||
private AnomalySummaryPreferenceController mAnomalySummaryPreferenceController;
|
||||
@Mock
|
||||
private BatteryStats.Timer mTimer;
|
||||
private BatteryStats.Timer mForegroundActivityTimer;
|
||||
@Mock
|
||||
private BatteryUtils mBatteryUtils;
|
||||
private Context mContext;
|
||||
private Preference mForegroundPreference;
|
||||
private Preference mBackgroundPreference;
|
||||
@@ -171,10 +180,11 @@ public class AdvancedPowerUsageDetailTest {
|
||||
doReturn(APP_LABEL).when(mBatteryEntry).getLabel();
|
||||
doReturn(BACKGROUND_TIME_US).when(mUid).getProcessStateTime(
|
||||
eq(BatteryStats.Uid.PROCESS_STATE_BACKGROUND), anyLong(), anyInt());
|
||||
doReturn(FOREGROUND_TIME_US).when(mUid).getProcessStateTime(
|
||||
doReturn(PROCSTATE_TOP_TIME_US).when(mUid).getProcessStateTime(
|
||||
eq(BatteryStats.Uid.PROCESS_STATE_TOP), anyLong(), anyInt());
|
||||
doReturn(mTimer).when(mUid).getForegroundActivityTimer();
|
||||
doReturn(FOREGROUND_TIME_US).when(mTimer).getTotalTimeLocked(anyLong(), anyInt());
|
||||
doReturn(mForegroundActivityTimer).when(mUid).getForegroundActivityTimer();
|
||||
doReturn(FOREGROUND_ACTIVITY_TIME_US).when(mForegroundActivityTimer)
|
||||
.getTotalTimeLocked(anyLong(), anyInt());
|
||||
ReflectionHelpers.setField(mBatteryEntry, "sipper", mBatterySipper);
|
||||
mBatteryEntry.iconId = ICON_ID;
|
||||
mBatterySipper.uidObj = mUid;
|
||||
@@ -189,6 +199,10 @@ public class AdvancedPowerUsageDetailTest {
|
||||
doReturn(mPackageManager).when(mTestActivity).getPackageManager();
|
||||
doReturn(mAppOpsManager).when(mTestActivity).getSystemService(Context.APP_OPS_SERVICE);
|
||||
|
||||
mBatteryUtils = spy(BatteryUtils.getInstance(mTestActivity));
|
||||
doReturn(FOREGROUND_SERVICE_TIME_US).when(mBatteryUtils).getForegroundServiceTotalTimeUs(
|
||||
any(BatteryStats.Uid.class), anyLong());
|
||||
|
||||
final ArgumentCaptor<Bundle> captor = ArgumentCaptor.forClass(Bundle.class);
|
||||
|
||||
Answer<Void> callable = invocation -> {
|
||||
@@ -263,8 +277,8 @@ public class AdvancedPowerUsageDetailTest {
|
||||
|
||||
@Test
|
||||
public void testStartBatteryDetailPage_hasBasicData() {
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, null, mBatteryStatsHelper, 0,
|
||||
mBatteryEntry, USAGE_PERCENT, mAnomalies);
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, mBatteryUtils, null,
|
||||
mBatteryStatsHelper, 0, mBatteryEntry, USAGE_PERCENT, mAnomalies);
|
||||
|
||||
assertThat(mBundle.getInt(AdvancedPowerUsageDetail.EXTRA_UID)).isEqualTo(UID);
|
||||
assertThat(mBundle.getLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME)).isEqualTo(
|
||||
@@ -282,8 +296,8 @@ public class AdvancedPowerUsageDetailTest {
|
||||
mBatterySipper.drainType = BatterySipper.DrainType.PHONE;
|
||||
mBatterySipper.usageTimeMs = PHONE_FOREGROUND_TIME_MS;
|
||||
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, null, mBatteryStatsHelper, 0,
|
||||
mBatteryEntry, USAGE_PERCENT, null);
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, mBatteryUtils, null,
|
||||
mBatteryStatsHelper, 0, mBatteryEntry, USAGE_PERCENT, null);
|
||||
|
||||
assertThat(mBundle.getInt(AdvancedPowerUsageDetail.EXTRA_UID)).isEqualTo(UID);
|
||||
assertThat(mBundle.getLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME)).isEqualTo(
|
||||
@@ -300,8 +314,8 @@ public class AdvancedPowerUsageDetailTest {
|
||||
public void testStartBatteryDetailPage_NormalApp() {
|
||||
mBatterySipper.mPackages = PACKAGE_NAME;
|
||||
mBatteryEntry.defaultPackageName = PACKAGE_NAME[0];
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, null, mBatteryStatsHelper, 0,
|
||||
mBatteryEntry, USAGE_PERCENT, mAnomalies);
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, mBatteryUtils, null,
|
||||
mBatteryStatsHelper, 0, mBatteryEntry, USAGE_PERCENT, mAnomalies);
|
||||
|
||||
assertThat(mBundle.getString(AdvancedPowerUsageDetail.EXTRA_PACKAGE_NAME)).isEqualTo(
|
||||
PACKAGE_NAME[0]);
|
||||
@@ -312,8 +326,8 @@ public class AdvancedPowerUsageDetailTest {
|
||||
@Test
|
||||
public void testStartBatteryDetailPage_SystemApp() {
|
||||
mBatterySipper.mPackages = null;
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, null, mBatteryStatsHelper, 0,
|
||||
mBatteryEntry, USAGE_PERCENT, null);
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, mBatteryUtils, null,
|
||||
mBatteryStatsHelper, 0, mBatteryEntry, USAGE_PERCENT, null);
|
||||
|
||||
assertThat(mBundle.getString(AdvancedPowerUsageDetail.EXTRA_LABEL)).isEqualTo(APP_LABEL);
|
||||
assertThat(mBundle.getInt(AdvancedPowerUsageDetail.EXTRA_ICON_ID)).isEqualTo(ICON_ID);
|
||||
@@ -327,8 +341,8 @@ public class AdvancedPowerUsageDetailTest {
|
||||
final int appUid = 1010019;
|
||||
mBatterySipper.mPackages = PACKAGE_NAME;
|
||||
doReturn(appUid).when(mBatterySipper).getUid();
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, null, mBatteryStatsHelper, 0,
|
||||
mBatteryEntry, USAGE_PERCENT, null);
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, mBatteryUtils, null,
|
||||
mBatteryStatsHelper, 0, mBatteryEntry, USAGE_PERCENT, null);
|
||||
|
||||
verify(mTestActivity).startPreferencePanelAsUser(
|
||||
nullable(Fragment.class), nullable(String.class), nullable(Bundle.class), anyInt(),
|
||||
@@ -355,12 +369,22 @@ public class AdvancedPowerUsageDetailTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartBatteryDetailPage_defaultPackageNull_choseFromBatterySipper() {
|
||||
public void testStartBatteryDetailPage_batteryEntryNotExisted_extractUidFromPackageName() throws
|
||||
PackageManager.NameNotFoundException{
|
||||
doReturn(UID).when(mPackageManager).getPackageUid(PACKAGE_NAME[0], 0 /* no flag */);
|
||||
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, null, PACKAGE_NAME[0]);
|
||||
|
||||
assertThat(mBundle.getInt(AdvancedPowerUsageDetail.EXTRA_UID)).isEqualTo(UID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartBatteryDetailPage_defaultPackageNull_chooseFromBatterySipper() {
|
||||
mBatteryEntry.defaultPackageName = null;
|
||||
mBatteryEntry.sipper.mPackages = PACKAGE_NAME;
|
||||
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, null, mBatteryStatsHelper, 0,
|
||||
mBatteryEntry, USAGE_PERCENT, null);
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, mBatteryUtils, null,
|
||||
mBatteryStatsHelper, 0, mBatteryEntry, USAGE_PERCENT, null);
|
||||
|
||||
assertThat(mBundle.getString(AdvancedPowerUsageDetail.EXTRA_PACKAGE_NAME)).isEqualTo(
|
||||
PACKAGE_NAME[0]);
|
||||
|
||||
@@ -17,14 +17,17 @@
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.UserManager;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.enterprise.DevicePolicyManagerWrapper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -62,6 +65,12 @@ public class BackgroundActivityPreferenceControllerTest {
|
||||
private ApplicationInfo mHighApplicationInfo;
|
||||
@Mock
|
||||
private ApplicationInfo mLowApplicationInfo;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
@Mock
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManagerWrapper;
|
||||
private BackgroundActivityPreferenceController mController;
|
||||
private SwitchPreference mPreference;
|
||||
private Context mShadowContext;
|
||||
@@ -73,6 +82,9 @@ public class BackgroundActivityPreferenceControllerTest {
|
||||
mShadowContext = RuntimeEnvironment.application;
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mAppOpsManager);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
when(mContext.getSystemService(Context.DEVICE_POLICY_SERVICE)).thenReturn(
|
||||
mDevicePolicyManager);
|
||||
when(mPackageManager.getPackagesForUid(UID_NORMAL)).thenReturn(PACKAGES_NORMAL);
|
||||
when(mPackageManager.getPackagesForUid(UID_SPECIAL)).thenReturn(PACKAGES_SPECIAL);
|
||||
|
||||
@@ -86,6 +98,7 @@ public class BackgroundActivityPreferenceControllerTest {
|
||||
mPreference = new SwitchPreference(mShadowContext);
|
||||
mController = spy(new BackgroundActivityPreferenceController(mContext, UID_NORMAL));
|
||||
mController.isAvailable();
|
||||
mController.mDpm = mDevicePolicyManagerWrapper;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,6 +194,7 @@ public class BackgroundActivityPreferenceControllerTest {
|
||||
@Test
|
||||
public void testMultiplePackages_ReturnStatusForTargetPackage() {
|
||||
mController = new BackgroundActivityPreferenceController(mContext, UID_SPECIAL);
|
||||
mController.mDpm = mDevicePolicyManagerWrapper;
|
||||
when(mAppOpsManager
|
||||
.checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_SPECIAL, LOW_SDK_PACKAGE))
|
||||
.thenReturn(AppOpsManager.MODE_ALLOWED);
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.os.Handler;
|
||||
import android.os.Process;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.internal.os.BatterySipper;
|
||||
@@ -46,9 +47,12 @@ import static org.mockito.Mockito.when;
|
||||
public class BatteryEntryTest {
|
||||
|
||||
private static final int APP_UID = 123;
|
||||
private static final int SYSTEM_UID = Process.SYSTEM_UID;
|
||||
private static final String APP_DEFAULT_PACKAGE_NAME = "com.android.test";
|
||||
private static final String APP_LABEL = "Test App Name";
|
||||
private static final String HIGH_DRAIN_PACKAGE = "com.android.test.screen";
|
||||
private static final String ANDROID_PACKAGE = "android";
|
||||
private static final String[] SYSTEM_PACKAGES = {HIGH_DRAIN_PACKAGE, ANDROID_PACKAGE};
|
||||
|
||||
@Rule public MockitoRule mocks = MockitoJUnit.rule();
|
||||
|
||||
@@ -84,6 +88,18 @@ public class BatteryEntryTest {
|
||||
return sipper;
|
||||
}
|
||||
|
||||
private BatteryEntry createBatteryEntryForSystem() {
|
||||
return new BatteryEntry(mockContext, mockHandler, mockUserManager, createSipperForSystem());
|
||||
}
|
||||
|
||||
private BatterySipper createSipperForSystem() {
|
||||
BatterySipper sipper =
|
||||
new BatterySipper(DrainType.APP, new FakeUid(SYSTEM_UID), 0 /* power use */);
|
||||
sipper.packageWithHighestDrain = HIGH_DRAIN_PACKAGE;
|
||||
sipper.mPackages = SYSTEM_PACKAGES;
|
||||
return sipper;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void batteryEntryForApp_shouldSetDefaultPackageNameAndLabel() throws Exception {
|
||||
BatteryEntry entry = createBatteryEntryForApp();
|
||||
@@ -118,7 +134,22 @@ public class BatteryEntryTest {
|
||||
new String[]{APP_DEFAULT_PACKAGE_NAME, "package2", "package3"});
|
||||
|
||||
BatteryEntry entry = createBatteryEntryForApp();
|
||||
|
||||
|
||||
assertThat(entry.getLabel()).isEqualTo(HIGH_DRAIN_PACKAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractPackageFromSipper_systemSipper_returnSystemPackage() {
|
||||
BatteryEntry entry = createBatteryEntryForSystem();
|
||||
|
||||
assertThat(entry.extractPackagesFromSipper(entry.sipper)).isEqualTo(
|
||||
new String[]{ANDROID_PACKAGE});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractPackageFromSipper_normalSipper_returnDefaultPakcage() {
|
||||
BatteryEntry entry = createBatteryEntryForApp();
|
||||
|
||||
assertThat(entry.extractPackagesFromSipper(entry.sipper)).isEqualTo(entry.sipper.mPackages);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,15 @@
|
||||
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
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.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -27,11 +36,10 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
|
||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -45,23 +53,12 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class,
|
||||
ShadowDynamicIndexableContentMonitor.class,
|
||||
ShadowEntityHeaderController.class
|
||||
})
|
||||
public class BatteryHeaderPreferenceControllerTest {
|
||||
|
||||
@@ -123,15 +123,18 @@ public class BatteryInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBatteryInfo_pluggedIn_dischargingFalse() {
|
||||
public void testGetBatteryInfo_pluggedInUsingShortString_usesCorrectData() {
|
||||
doReturn(TEST_CHARGE_TIME_REMAINING).when(mBatteryStats).computeChargeTimeRemaining(
|
||||
anyLong());
|
||||
BatteryInfo info = BatteryInfo.getBatteryInfoOld(mContext, mChargingBatteryBroadcast,
|
||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, true /* shortString */);
|
||||
|
||||
assertThat(info.discharging).isEqualTo(false);
|
||||
assertThat(info.chargeLabel.toString()).isEqualTo("50% - 1m until fully charged");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBatteryInfo_basedOnUsageTrue_usesUsageString() {
|
||||
public void testGetBatteryInfo_basedOnUsageTrue_usesCorrectString() {
|
||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, false /* shortString */,
|
||||
1000, true /* basedOnUsage */);
|
||||
@@ -139,8 +142,10 @@ public class BatteryInfoTest {
|
||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, true /* shortString */,
|
||||
1000, true /* basedOnUsage */);
|
||||
|
||||
// We only add special mention for the long string
|
||||
assertThat(info.remainingLabel.toString()).contains(ENHANCED_STRING_SUFFIX);
|
||||
assertThat(info2.remainingLabel.toString()).contains(ENHANCED_STRING_SUFFIX);
|
||||
// shortened string should not have extra text
|
||||
assertThat(info2.remainingLabel.toString()).doesNotContain(ENHANCED_STRING_SUFFIX);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,15 +16,17 @@
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
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 android.content.Context;
|
||||
import android.graphics.ColorFilter;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources.SettingsShadowTheme;
|
||||
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -34,10 +36,6 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
// TODO: Consider making the shadow class set global using a robolectric.properties file.
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH,
|
||||
@@ -45,7 +43,6 @@ import static org.mockito.Mockito.verify;
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowTheme.class,
|
||||
ShadowDynamicIndexableContentMonitor.class
|
||||
})
|
||||
public class BatteryMeterViewTest {
|
||||
private static final int BATTERY_LEVEL = 100;
|
||||
|
||||
@@ -195,6 +195,8 @@ public class BatteryUtilsTest {
|
||||
doReturn(mAppOpsManager).when(shadowContext).getSystemService(Context.APP_OPS_SERVICE);
|
||||
mBatteryUtils = spy(new BatteryUtils(shadowContext));
|
||||
mBatteryUtils.mPowerUsageFeatureProvider = mProvider;
|
||||
doReturn(0L).when(mBatteryUtils).getForegroundServiceTotalTimeUs(
|
||||
any(BatteryStats.Uid.class), anyLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -453,7 +455,7 @@ public class BatteryUtilsTest {
|
||||
if (!isUidNull) {
|
||||
final BatteryStats.Uid uid = mock(BatteryStats.Uid.class, RETURNS_DEEP_STUBS);
|
||||
doReturn(topTime).when(mBatteryUtils).getProcessTimeMs(
|
||||
eq(BatteryUtils.StatusType.FOREGROUND), eq(uid), anyInt());
|
||||
eq(BatteryUtils.StatusType.SCREEN_USAGE), eq(uid), anyInt());
|
||||
doReturn(uidCode).when(uid).getUid();
|
||||
sipper.uidObj = uid;
|
||||
}
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
*/
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.VectorDrawable;
|
||||
@@ -29,8 +25,8 @@ import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -39,6 +35,8 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class PowerGaugePreferenceTest {
|
||||
@@ -55,7 +53,7 @@ public class PowerGaugePreferenceTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mRootView = LayoutInflater.from(mContext).inflate(R.layout.preference_material_settings,
|
||||
mRootView = LayoutInflater.from(mContext).inflate(R.layout.preference,
|
||||
null);
|
||||
mWidgetView = LayoutInflater.from(mContext).inflate(R.layout.preference_widget_summary,
|
||||
null);
|
||||
|
||||
@@ -31,6 +31,7 @@ import static org.mockito.Mockito.when;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
@@ -91,6 +92,8 @@ public class PowerUsageAdvancedTest {
|
||||
private BatteryHistoryPreference mHistPref;
|
||||
@Mock
|
||||
private PreferenceGroup mUsageListGroup;
|
||||
@Mock
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
private PowerUsageAdvanced mPowerUsageAdvanced;
|
||||
private PowerUsageData mPowerUsageData;
|
||||
private Context mShadowContext;
|
||||
@@ -127,8 +130,10 @@ public class PowerUsageAdvancedTest {
|
||||
mPowerUsageAdvanced.setPowerUsageFeatureProvider(mPowerUsageFeatureProvider);
|
||||
mPowerUsageAdvanced.setUserManager(mUserManager);
|
||||
mPowerUsageAdvanced.setBatteryUtils(BatteryUtils.getInstance(mShadowContext));
|
||||
when(mShadowContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
|
||||
mConnectivityManager);
|
||||
|
||||
mPowerUsageData = new PowerUsageData(UsageType.SYSTEM);
|
||||
mPowerUsageData = new PowerUsageData(UsageType.USER);
|
||||
mMaxBatterySipper.totalPowerMah = TYPE_BLUETOOTH_USAGE;
|
||||
mMaxBatterySipper.drainType = DrainType.BLUETOOTH;
|
||||
mNormalBatterySipper.drainType = DrainType.SCREEN;
|
||||
@@ -296,6 +301,24 @@ public class PowerUsageAdvancedTest {
|
||||
assertThat(mPowerUsageAdvanced.shouldHideCategory(mPowerUsageData)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldHideCategory_typeCellWhileNotSupported_returnTrue() {
|
||||
mPowerUsageData.usageType = UsageType.CELL;
|
||||
doReturn(false).when(mConnectivityManager).isNetworkSupported(
|
||||
ConnectivityManager.TYPE_MOBILE);
|
||||
|
||||
assertThat(mPowerUsageAdvanced.shouldHideCategory(mPowerUsageData)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldHideCategory_typeCellWhileSupported_returnFalse() {
|
||||
mPowerUsageData.usageType = UsageType.CELL;
|
||||
doReturn(true).when(mConnectivityManager).isNetworkSupported(
|
||||
ConnectivityManager.TYPE_MOBILE);
|
||||
|
||||
assertThat(mPowerUsageAdvanced.shouldHideCategory(mPowerUsageData)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldHideCategory_typeUserAndMoreThanOne_returnFalse() {
|
||||
mPowerUsageData.usageType = UsageType.USER;
|
||||
@@ -318,6 +341,13 @@ public class PowerUsageAdvancedTest {
|
||||
assertThat(mPowerUsageAdvanced.shouldHideSummary(mPowerUsageData)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldHideSummary_typeSystem_returnTrue() {
|
||||
mPowerUsageData.usageType = UsageType.SYSTEM;
|
||||
|
||||
assertThat(mPowerUsageAdvanced.shouldHideSummary(mPowerUsageData)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldHideSummary_typeWifi_returnTrue() {
|
||||
mPowerUsageData.usageType = UsageType.WIFI;
|
||||
@@ -341,7 +371,7 @@ public class PowerUsageAdvancedTest {
|
||||
|
||||
@Test
|
||||
public void testShouldHideSummary_typeNormal_returnFalse() {
|
||||
mPowerUsageData.usageType = UsageType.SYSTEM;
|
||||
mPowerUsageData.usageType = UsageType.IDLE;
|
||||
|
||||
assertThat(mPowerUsageAdvanced.shouldHideSummary(mPowerUsageData)).isFalse();
|
||||
}
|
||||
|
||||
@@ -18,9 +18,7 @@ package com.android.settings.fuelgauge;
|
||||
import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_ADDITIONAL_BATTERY_INFO;
|
||||
import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_HIGH_POWER_APPS;
|
||||
import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_TOGGLE_APPS;
|
||||
|
||||
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;
|
||||
@@ -60,14 +58,13 @@ import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.fuelgauge.anomaly.Anomaly;
|
||||
import com.android.settings.fuelgauge.anomaly.AnomalyDetectionPolicy;
|
||||
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.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -93,7 +90,6 @@ import java.util.List;
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class,
|
||||
ShadowDynamicIndexableContentMonitor.class
|
||||
})
|
||||
public class PowerUsageSummaryTest {
|
||||
private static final String[] PACKAGE_NAMES = {"com.app1", "com.app2"};
|
||||
@@ -337,13 +333,13 @@ public class PowerUsageSummaryTest {
|
||||
@Test
|
||||
public void testSetUsageSummary_timeMoreThanOneMinute_normalApp_setScreenSummary() {
|
||||
mNormalBatterySipper.usageTimeMs = 2 * DateUtils.MINUTE_IN_MILLIS;
|
||||
doReturn(mRealContext.getText(R.string.battery_screen_usage)).when(mFragment).getText(
|
||||
R.string.battery_screen_usage);
|
||||
doReturn(mRealContext.getText(R.string.battery_used_for)).when(mFragment).getText(
|
||||
R.string.battery_used_for);
|
||||
doReturn(mRealContext).when(mFragment).getContext();
|
||||
|
||||
mFragment.setUsageSummary(mPreference, mNormalBatterySipper);
|
||||
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo("Screen usage 2m");
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo("Used for 2m");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -455,7 +451,7 @@ public class PowerUsageSummaryTest {
|
||||
fragment.getPreferenceScreenResId());
|
||||
final List<String> preferenceKeys = new ArrayList<>();
|
||||
|
||||
for (PreferenceController controller : fragment.getPreferenceControllers(context)) {
|
||||
for (AbstractPreferenceController controller : fragment.getPreferenceControllers(context)) {
|
||||
preferenceKeys.add(controller.getPreferenceKey());
|
||||
}
|
||||
|
||||
|
||||
@@ -40,11 +40,13 @@ import org.robolectric.annotation.Config;
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AnomalyDetectionPolicyTest {
|
||||
private static final String ANOMALY_DETECTION_CONSTANTS_VALUE = "anomaly_detection_enabled=true"
|
||||
private static final String ANOMALY_DETECTION_CONSTANTS_VALUE =
|
||||
"anomaly_detection_enabled=true"
|
||||
+ ",wakelock_enabled=false"
|
||||
+ ",wakelock_threshold=3000"
|
||||
+ ",wakeup_alarm_enabled=true"
|
||||
+ ",wakeup_alarm_threshold=100"
|
||||
+ ",wakeup_blacklisted_tags=tag1:tag2:with%2Ccomma:with%3Acolon"
|
||||
+ ",bluetooth_scan_enabled=true"
|
||||
+ ",bluetooth_scan_threshold=2000";
|
||||
private Context mContext;
|
||||
@@ -58,7 +60,7 @@ public class AnomalyDetectionPolicyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInit_containsDataFromSettings() {
|
||||
public void testInit_usesConfigValues() {
|
||||
AnomalyDetectionPolicy anomalyDetectionPolicy = createAnomalyPolicyWithConfig();
|
||||
|
||||
assertThat(anomalyDetectionPolicy.anomalyDetectionEnabled).isTrue();
|
||||
@@ -66,12 +68,14 @@ public class AnomalyDetectionPolicyTest {
|
||||
assertThat(anomalyDetectionPolicy.wakeLockThreshold).isEqualTo(3000);
|
||||
assertThat(anomalyDetectionPolicy.wakeupAlarmDetectionEnabled).isTrue();
|
||||
assertThat(anomalyDetectionPolicy.wakeupAlarmThreshold).isEqualTo(100);
|
||||
assertThat(anomalyDetectionPolicy.wakeupBlacklistedTags)
|
||||
.containsExactly("tag1", "tag2", "with,comma", "with:colon");
|
||||
assertThat(anomalyDetectionPolicy.bluetoothScanDetectionEnabled).isTrue();
|
||||
assertThat(anomalyDetectionPolicy.bluetoothScanThreshold).isEqualTo(2000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInit_containsDefaultData() {
|
||||
public void testInit_defaultValues() {
|
||||
Settings.Global.putString(mContext.getContentResolver(),
|
||||
Settings.Global.ANOMALY_DETECTION_CONSTANTS, "");
|
||||
// Mock it to avoid noSuchMethodError
|
||||
@@ -81,18 +85,19 @@ public class AnomalyDetectionPolicyTest {
|
||||
AnomalyDetectionPolicy anomalyDetectionPolicy = new AnomalyDetectionPolicy(mContext,
|
||||
mKeyValueListParserWrapper);
|
||||
|
||||
assertThat(anomalyDetectionPolicy.anomalyDetectionEnabled).isTrue();
|
||||
assertThat(anomalyDetectionPolicy.wakeLockDetectionEnabled).isTrue();
|
||||
assertThat(anomalyDetectionPolicy.anomalyDetectionEnabled).isFalse();
|
||||
assertThat(anomalyDetectionPolicy.wakeLockDetectionEnabled).isFalse();
|
||||
assertThat(anomalyDetectionPolicy.wakeLockThreshold).isEqualTo(DateUtils.HOUR_IN_MILLIS);
|
||||
assertThat(anomalyDetectionPolicy.wakeupAlarmDetectionEnabled).isFalse();
|
||||
assertThat(anomalyDetectionPolicy.wakeupAlarmThreshold).isEqualTo(60);
|
||||
assertThat(anomalyDetectionPolicy.bluetoothScanDetectionEnabled).isTrue();
|
||||
assertThat(anomalyDetectionPolicy.wakeupAlarmThreshold).isEqualTo(10);
|
||||
assertThat(anomalyDetectionPolicy.wakeupBlacklistedTags).isNull();
|
||||
assertThat(anomalyDetectionPolicy.bluetoothScanDetectionEnabled).isFalse();
|
||||
assertThat(anomalyDetectionPolicy.bluetoothScanThreshold).isEqualTo(
|
||||
30 * DateUtils.MINUTE_IN_MILLIS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAnomalyDetectorEnabled() {
|
||||
public void testIsAnomalyDetectorEnabled_usesConfigValues() {
|
||||
AnomalyDetectionPolicy anomalyDetectionPolicy = createAnomalyPolicyWithConfig();
|
||||
|
||||
assertThat(anomalyDetectionPolicy.isAnomalyDetectorEnabled(
|
||||
@@ -103,18 +108,37 @@ public class AnomalyDetectionPolicyTest {
|
||||
Anomaly.AnomalyType.BLUETOOTH_SCAN)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAnomalyDetectorEnabled_usesDefaultValues() {
|
||||
Settings.Global.putString(mContext.getContentResolver(),
|
||||
Settings.Global.ANOMALY_DETECTION_CONSTANTS, "");
|
||||
// Mock it to avoid noSuchMethodError
|
||||
doReturn(true).when(mKeyValueListParserWrapper).getBoolean(anyString(), eq(true));
|
||||
doReturn(false).when(mKeyValueListParserWrapper).getBoolean(anyString(), eq(false));
|
||||
|
||||
AnomalyDetectionPolicy anomalyDetectionPolicy = new AnomalyDetectionPolicy(mContext,
|
||||
mKeyValueListParserWrapper);
|
||||
|
||||
assertThat(anomalyDetectionPolicy.isAnomalyDetectorEnabled(
|
||||
Anomaly.AnomalyType.WAKE_LOCK)).isFalse();
|
||||
assertThat(anomalyDetectionPolicy.isAnomalyDetectorEnabled(
|
||||
Anomaly.AnomalyType.WAKEUP_ALARM)).isFalse();
|
||||
assertThat(anomalyDetectionPolicy.isAnomalyDetectorEnabled(
|
||||
Anomaly.AnomalyType.BLUETOOTH_SCAN)).isFalse();
|
||||
}
|
||||
|
||||
private AnomalyDetectionPolicy createAnomalyPolicyWithConfig() {
|
||||
Settings.Global.putString(mContext.getContentResolver(),
|
||||
Settings.Global.ANOMALY_DETECTION_CONSTANTS, ANOMALY_DETECTION_CONSTANTS_VALUE);
|
||||
// Mock it to avoid noSuchMethodError
|
||||
doReturn(true).when(mKeyValueListParserWrapper).getBoolean(
|
||||
AnomalyDetectionPolicy.KEY_ANOMALY_DETECTION_ENABLED, true);
|
||||
AnomalyDetectionPolicy.KEY_ANOMALY_DETECTION_ENABLED, false);
|
||||
doReturn(false).when(mKeyValueListParserWrapper).getBoolean(
|
||||
AnomalyDetectionPolicy.KEY_WAKELOCK_DETECTION_ENABLED, true);
|
||||
AnomalyDetectionPolicy.KEY_WAKELOCK_DETECTION_ENABLED, false);
|
||||
doReturn(true).when(mKeyValueListParserWrapper).getBoolean(
|
||||
AnomalyDetectionPolicy.KEY_WAKEUP_ALARM_DETECTION_ENABLED, false);
|
||||
doReturn(true).when(mKeyValueListParserWrapper).getBoolean(
|
||||
AnomalyDetectionPolicy.KEY_BLUETOOTH_SCAN_DETECTION_ENABLED, true);
|
||||
AnomalyDetectionPolicy.KEY_BLUETOOTH_SCAN_DETECTION_ENABLED, false);
|
||||
|
||||
return new AnomalyDetectionPolicy(mContext, mKeyValueListParserWrapper);
|
||||
}
|
||||
|
||||
@@ -106,6 +106,16 @@ public class AnomalySummaryPreferenceControllerTest {
|
||||
assertThat(mPreference.getSummary()).isEqualTo("Keeping device awake");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAnomalySummaryPreference_emptyAnomaly_preferenceInvisible() {
|
||||
mPreference.setVisible(true);
|
||||
mAnomalyList.clear();
|
||||
|
||||
mAnomalySummaryPreferenceController.updateAnomalySummaryPreference(mAnomalyList);
|
||||
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAnomalySummaryPreference_multipleAnomalies_showCorrectSummary() {
|
||||
mAnomalyList.add(createTestAnomaly());
|
||||
|
||||
@@ -30,6 +30,7 @@ import android.os.BatteryStats;
|
||||
import android.os.Build;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import com.android.internal.os.BatterySipper;
|
||||
import com.android.internal.os.BatteryStatsHelper;
|
||||
@@ -52,6 +53,7 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@@ -69,6 +71,7 @@ public class WakeupAlarmAnomalyDetectorTest {
|
||||
1 * DateUtils.HOUR_IN_MILLIS + 10 * DateUtils.MINUTE_IN_MILLIS;
|
||||
private static final int ANOMALY_WAKEUP_COUNT = 500;
|
||||
private static final int NORMAL_WAKEUP_COUNT = 61;
|
||||
private static final int BLACKLISTED_WAKEUP_COUNT = 37;
|
||||
private static final int ANOMALY_WAKEUP_FREQUENCY = 428; // count per hour
|
||||
@Mock
|
||||
private BatteryStatsHelper mBatteryStatsHelper;
|
||||
@@ -87,12 +90,12 @@ public class WakeupAlarmAnomalyDetectorTest {
|
||||
@Mock
|
||||
private BatteryUtils mBatteryUtils;
|
||||
@Mock
|
||||
private ApplicationInfo mApplicationInfo;
|
||||
@Mock
|
||||
private BatteryStats.Uid.Pkg mPkg;
|
||||
@Mock
|
||||
private BatteryStats.Counter mCounter;
|
||||
@Mock
|
||||
private BatteryStats.Counter mCounter2;
|
||||
@Mock
|
||||
private AnomalyDetectionPolicy mPolicy;
|
||||
@Mock
|
||||
private AnomalyAction mAnomalyAction;
|
||||
@@ -111,6 +114,9 @@ public class WakeupAlarmAnomalyDetectorTest {
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
ReflectionHelpers.setField(mPolicy, "wakeupAlarmThreshold", 60);
|
||||
final Set<String> blacklistedTags = new ArraySet<>();
|
||||
blacklistedTags.add("blacklistedTag");
|
||||
ReflectionHelpers.setField(mPolicy, "wakeupBlacklistedTags", blacklistedTags);
|
||||
|
||||
doReturn(false).when(mBatteryUtils).shouldHideSipper(any());
|
||||
doReturn(RUNNING_TIME_MS).when(mBatteryUtils).calculateRunningTimeBasedOnStatsType(any(),
|
||||
@@ -207,4 +213,20 @@ public class WakeupAlarmAnomalyDetectorTest {
|
||||
assertThat(mWakeupAlarmAnomalyDetector.getWakeupAlarmCountFromUid(mAnomalyUid)).isEqualTo(
|
||||
2 * NORMAL_WAKEUP_COUNT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWakeupAlarmCountFromUid_filterOutBlacklistedTags() {
|
||||
final ArrayMap<String, BatteryStats.Uid.Pkg> packageStats = new ArrayMap<>();
|
||||
final ArrayMap<String, BatteryStats.Counter> alarms = new ArrayMap<>();
|
||||
doReturn(alarms).when(mPkg).getWakeupAlarmStats();
|
||||
doReturn(NORMAL_WAKEUP_COUNT).when(mCounter).getCountLocked(anyInt());
|
||||
doReturn(BLACKLISTED_WAKEUP_COUNT).when(mCounter2).getCountLocked(anyInt());
|
||||
doReturn(packageStats).when(mAnomalyUid).getPackageStats();
|
||||
packageStats.put("", mPkg);
|
||||
alarms.put("allowedTag", mCounter);
|
||||
alarms.put("blacklistedTag", mCounter2);
|
||||
|
||||
assertThat(mWakeupAlarmAnomalyDetector.getWakeupAlarmCountFromUid(mAnomalyUid)).isEqualTo(
|
||||
NORMAL_WAKEUP_COUNT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import static android.provider.Settings.Secure.ASSIST_GESTURE_ENABLED;
|
||||
|
||||
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -26,17 +23,16 @@ import static org.mockito.Mockito.when;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import android.provider.Settings.Secure;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.display.AutoBrightnessPreferenceController;
|
||||
import com.android.settings.search.InlinePayload;
|
||||
import com.android.settings.search.InlineSwitchPayload;
|
||||
import com.android.settings.search.ResultPayload;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -45,16 +41,19 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AssistGesturePreferenceControllerTest {
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = ShadowSecureSettings.class
|
||||
)
|
||||
public class AssistGestureSettingsPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFactory;
|
||||
private AssistGesturePreferenceController mController;
|
||||
private AssistGestureSettingsPreferenceController mController;
|
||||
|
||||
private static final String KEY_ASSIST = "gesture_assist";
|
||||
|
||||
@@ -63,7 +62,8 @@ public class AssistGesturePreferenceControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mController = new AssistGesturePreferenceController(mContext, null, KEY_ASSIST, false);
|
||||
mController = new AssistGestureSettingsPreferenceController(mContext, null, KEY_ASSIST,
|
||||
false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,38 +79,17 @@ public class AssistGesturePreferenceControllerTest {
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
|
||||
// Set the setting to be enabled.
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 1);
|
||||
mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST, false);
|
||||
|
||||
assertThat(mController.isSwitchPrefEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
|
||||
// Set the setting to be disabled.
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 0);
|
||||
mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST, false);
|
||||
|
||||
assertThat(mController.isSwitchPrefEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreferenceController_ProperResultPayloadType() {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
AssistGesturePreferenceController controller =
|
||||
new AssistGesturePreferenceController(context, null /* lifecycle */, KEY_ASSIST,
|
||||
false /* assistOnly */);
|
||||
AssistGestureSettingsPreferenceController controller =
|
||||
new AssistGestureSettingsPreferenceController(context, null /* lifecycle */,
|
||||
KEY_ASSIST, false /* assistOnly */);
|
||||
ResultPayload payload = controller.getResultPayload();
|
||||
assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowSecureSettings.class)
|
||||
public void testSetValue_updatesCorrectly() {
|
||||
int newValue = 1;
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
@@ -123,7 +102,6 @@ public class AssistGesturePreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowSecureSettings.class)
|
||||
public void testGetValue_correctValueReturned() {
|
||||
int currentValue = 1;
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
@@ -16,42 +16,42 @@
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
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.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AssistGestureSettingsTest {
|
||||
@Mock
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFakeFeatureFactory;
|
||||
private AssistGestureFeatureProvider mFeatureProvider;
|
||||
private AssistGestureSettings mSettings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mFeatureProvider = mFakeFeatureFactory.getAssistGestureFeatureProvider();
|
||||
mSettings = new AssistGestureSettings();
|
||||
}
|
||||
|
||||
@@ -61,13 +61,6 @@ public class AssistGestureSettingsTest {
|
||||
.isEqualTo(R.xml.assist_gesture_settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreferenceControllers_shouldAllBeCreated() {
|
||||
final List<PreferenceController> controllers =
|
||||
mSettings.getPreferenceControllers(mContext);
|
||||
assertThat(controllers.isEmpty()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_shouldIndexResource() {
|
||||
final List<SearchIndexableResource> indexRes =
|
||||
@@ -78,5 +71,15 @@ public class AssistGestureSettingsTest {
|
||||
assertThat(indexRes).isNotNull();
|
||||
assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_noSensor_shouldDisablePageSearch() {
|
||||
when(mFakeFeatureFactory.assistGestureFeatureProvider.isSensorAvailable(any(Context.class)))
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(AssistGestureSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||
RuntimeEnvironment.application))
|
||||
.contains("gesture_assist_settings_page");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -65,11 +64,6 @@ public class DoubleTwistPreferenceControllerTest {
|
||||
mController = new DoubleTwistPreferenceController(mContext, null, KEY_DOUBLE_TWIST);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowSecureSettings.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_hasSensor_shouldReturnTrue() {
|
||||
// Mock sensors
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
@@ -34,10 +35,12 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -84,29 +87,72 @@ public class GesturePreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_shouldStartVideoPreference() {
|
||||
public void onResume_shouldStartVideoPreferenceWithVideoPauseState() {
|
||||
final VideoPreference videoPreference = mock(VideoPreference.class);
|
||||
when(mScreen.findPreference(mController.getVideoPrefKey())).thenReturn(videoPreference);
|
||||
mController.mIsPrefAvailable = true;
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onStart();
|
||||
final Bundle savedState = new Bundle();
|
||||
|
||||
verify(videoPreference).onViewVisible();
|
||||
mController.onCreate(null);
|
||||
mController.onResume();
|
||||
verify(videoPreference).onViewVisible(false);
|
||||
|
||||
reset(videoPreference);
|
||||
savedState.putBoolean(mController.KEY_VIDEO_PAUSED, true);
|
||||
mController.onCreate(savedState);
|
||||
mController.onResume();
|
||||
verify(videoPreference).onViewVisible(true);
|
||||
|
||||
reset(videoPreference);
|
||||
savedState.putBoolean(mController.KEY_VIDEO_PAUSED, false);
|
||||
mController.onCreate(savedState);
|
||||
mController.onResume();
|
||||
verify(videoPreference).onViewVisible(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStop_shouldStopVideoPreference() {
|
||||
public void onPause_shouldStopVideoPreference() {
|
||||
final VideoPreference videoPreference = mock(VideoPreference.class);
|
||||
when(mScreen.findPreference(mController.getVideoPrefKey())).thenReturn(videoPreference);
|
||||
mController.mIsPrefAvailable = true;
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onStop();
|
||||
mController.onPause();
|
||||
|
||||
verify(videoPreference).onViewInvisible();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_shouldUpdateVideoPauseState() {
|
||||
final VideoPreference videoPreference = mock(VideoPreference.class);
|
||||
when(mScreen.findPreference(mController.getVideoPrefKey())).thenReturn(videoPreference);
|
||||
mController.mIsPrefAvailable = true;
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
when(videoPreference.isVideoPaused()).thenReturn(true);
|
||||
mController.onPause();
|
||||
assertThat(mController.mVideoPaused).isTrue();
|
||||
|
||||
when(videoPreference.isVideoPaused()).thenReturn(false);
|
||||
mController.onPause();
|
||||
assertThat(mController.mVideoPaused).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSaveInstanceState_shouldSaveVideoPauseState() {
|
||||
final Bundle outState = mock(Bundle.class);
|
||||
|
||||
mController.mVideoPaused = true;
|
||||
mController.onSaveInstanceState(outState);
|
||||
verify(outState).putBoolean(mController.KEY_VIDEO_PAUSED, true);
|
||||
|
||||
mController.mVideoPaused = false;
|
||||
mController.onSaveInstanceState(outState);
|
||||
verify(outState).putBoolean(mController.KEY_VIDEO_PAUSED, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
|
||||
// Mock a TwoStatePreference
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class GesturesSettingsPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private Preference mPreference;
|
||||
|
||||
private GesturesSettingPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mActivity);
|
||||
mController = new GesturesSettingPreferenceController(mActivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_hasGesture_shouldReturnTrue() {
|
||||
final List<AbstractPreferenceController> mControllers = new ArrayList<>();
|
||||
mControllers.add(new AbstractPreferenceController(RuntimeEnvironment.application) {
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return "test_key";
|
||||
}
|
||||
});
|
||||
ReflectionHelpers.setField(mController, "mGestureControllers", mControllers);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_noGesture_shouldReturnFalse() {
|
||||
ReflectionHelpers.setField(mController, "mGestureControllers",
|
||||
new ArrayList<AbstractPreferenceController>());
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowSecureSettings.class})
|
||||
public void updateState_assistSupported_shouldSetToAssistGestureStatus() {
|
||||
final FakeFeatureFactory featureFactory =
|
||||
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
|
||||
when(featureFactory.assistGestureFeatureProvider.isSupported(any(Context.class)))
|
||||
.thenReturn(true);
|
||||
when(featureFactory.assistGestureFeatureProvider.isSensorAvailable(any(Context.class)))
|
||||
.thenReturn(true);
|
||||
|
||||
final ContentResolver cr = mActivity.getContentResolver();
|
||||
Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_ENABLED, 0);
|
||||
Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 0);
|
||||
mController.updateState(mPreference);
|
||||
verify(mActivity).getString(R.string.language_input_gesture_summary_off);
|
||||
|
||||
Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_ENABLED, 1);
|
||||
Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 0);
|
||||
mController.updateState(mPreference);
|
||||
verify(mActivity).getString(R.string.language_input_gesture_summary_on_with_assist);
|
||||
|
||||
Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_ENABLED, 0);
|
||||
Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1);
|
||||
mController.updateState(mPreference);
|
||||
verify(mActivity).getString(R.string.language_input_gesture_summary_on_non_assist);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowSecureSettings.class})
|
||||
public void updateState_sensorNotAvailable_shouldSetToEmptyStatus() {
|
||||
final FakeFeatureFactory featureFactory =
|
||||
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
|
||||
when(featureFactory.assistGestureFeatureProvider.isSensorAvailable(any(Context.class)))
|
||||
.thenReturn(false);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setSummary("");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,13 +16,15 @@
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -34,8 +36,6 @@ import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SwipeToNotificationSettingsTest {
|
||||
@@ -58,7 +58,8 @@ public class SwipeToNotificationSettingsTest {
|
||||
|
||||
@Test
|
||||
public void testGetPreferenceControllers_shouldAllBeCreated() {
|
||||
final List<PreferenceController> controllers = mFragment.getPreferenceControllers(mContext);
|
||||
final List<AbstractPreferenceController> controllers =
|
||||
mFragment.getPreferenceControllers(mContext);
|
||||
|
||||
assertThat(controllers.isEmpty()).isFalse();
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user