Search in sources :

Example 16 with FakeFeatureFactory

use of com.android.settings.testutils.FakeFeatureFactory in project platform_packages_apps_Settings by BlissRoms.

the class AutomaticStorageManagementSwitchPreferenceControllerTest method togglingShouldCauseMetricsEvent.

@Test
public void togglingShouldCauseMetricsEvent() {
    // FakeFeatureFactory uses mock contexts, so this test scaffolds itself rather than using
    // the instance variables.
    FakeFeatureFactory.setupForTest(mMockContext);
    FakeFeatureFactory factory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mMockContext);
    AutomaticStorageManagementSwitchPreferenceController controller = new AutomaticStorageManagementSwitchPreferenceController(mMockContext, factory.metricsFeatureProvider, mFragmentManager);
    controller.onSwitchToggled(true);
    verify(factory.metricsFeatureProvider, times(1)).action(any(Context.class), eq(MetricsEvent.ACTION_TOGGLE_STORAGE_MANAGER), eq(true));
}
Also used : Context(android.content.Context) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) Test(org.junit.Test)

Example 17 with FakeFeatureFactory

use of com.android.settings.testutils.FakeFeatureFactory in project platform_packages_apps_Settings by BlissRoms.

the class AdvancedPowerUsageDetailTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    FakeFeatureFactory.setupForTest(mContext);
    mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
    mFragment = spy(new AdvancedPowerUsageDetail());
    doReturn(mContext).when(mFragment).getContext();
    doReturn(mActivity).when(mFragment).getActivity();
    doReturn(SUMMARY).when(mFragment).getString(anyInt());
    doReturn(APP_LABEL).when(mBundle).getString(nullable(String.class));
    doReturn(mBundle).when(mFragment).getArguments();
    doReturn(mLoaderManager).when(mFragment).getLoaderManager();
    ShadowEntityHeaderController.setUseMock(mEntityHeaderController);
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setRecyclerView(nullable(RecyclerView.class), nullable(Lifecycle.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setButtonActions(anyInt(), anyInt());
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(Drawable.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(ApplicationsState.AppEntry.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(String.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(String.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(ApplicationsState.AppEntry.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setSummary(nullable(String.class));
    doReturn(UID).when(mBatterySipper).getUid();
    doReturn(APP_LABEL).when(mBatteryEntry).getLabel();
    doReturn(BACKGROUND_TIME_US).when(mUid).getProcessStateTime(eq(BatteryStats.Uid.PROCESS_STATE_BACKGROUND), anyLong(), anyInt());
    doReturn(PROCSTATE_TOP_TIME_US).when(mUid).getProcessStateTime(eq(BatteryStats.Uid.PROCESS_STATE_TOP), 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;
    mBatterySipper.drainType = BatterySipper.DrainType.APP;
    mFragment.mHeaderPreference = mHeaderPreference;
    mFragment.mState = mState;
    mFragment.mBatteryUtils = new BatteryUtils(RuntimeEnvironment.application);
    mAppEntry.info = mock(ApplicationInfo.class);
    mTestActivity = spy(new SettingsActivity());
    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 -> {
        mBundle = captor.getValue();
        return null;
    };
    doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(nullable(Fragment.class), nullable(String.class), captor.capture(), anyInt(), nullable(CharSequence.class), nullable(UserHandle.class));
    mForegroundPreference = new Preference(mContext);
    mBackgroundPreference = new Preference(mContext);
    mPowerUsagePreference = new Preference(mContext);
    mFragment.mForegroundPreference = mForegroundPreference;
    mFragment.mBackgroundPreference = mBackgroundPreference;
    mFragment.mPowerUsagePreference = mPowerUsagePreference;
    mFragment.mAnomalySummaryPreferenceController = mAnomalySummaryPreferenceController;
    mAnomalies = new ArrayList<>();
    mAnomalies.add(new Anomaly.Builder().setUid(UID).setType(Anomaly.AnomalyType.WAKE_LOCK).build());
}
Also used : AppOpsManager(android.app.AppOpsManager) Bundle(android.os.Bundle) SettingsRobolectricTestRunner(com.android.settings.testutils.SettingsRobolectricTestRunner) PackageManager(android.content.pm.PackageManager) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) Drawable(android.graphics.drawable.Drawable) MockitoAnnotations(org.mockito.MockitoAnnotations) ReflectionHelpers(org.robolectric.util.ReflectionHelpers) AppUtils(com.android.settingslib.applications.AppUtils) Matchers.eq(org.mockito.Matchers.eq) Mockito.doAnswer(org.mockito.Mockito.doAnswer) After(org.junit.After) Matchers.anyInt(org.mockito.Matchers.anyInt) Mockito.doReturn(org.mockito.Mockito.doReturn) R(com.android.settings.R) Anomaly(com.android.settings.fuelgauge.anomaly.Anomaly) BatteryStatsHelper(com.android.internal.os.BatteryStatsHelper) RuntimeEnvironment(org.robolectric.RuntimeEnvironment) Matchers.any(org.mockito.Matchers.any) List(java.util.List) SettingsActivity(com.android.settings.SettingsActivity) EntityHeaderController(com.android.settings.widget.EntityHeaderController) ApplicationInfo(android.content.pm.ApplicationInfo) ShadowEntityHeaderController(com.android.settings.testutils.shadow.ShadowEntityHeaderController) Mockito.mock(org.mockito.Mockito.mock) Context(android.content.Context) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) TestConfig(com.android.settings.TestConfig) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) UserHandle(android.os.UserHandle) Matchers.anyLong(org.mockito.Matchers.anyLong) LayoutPreference(com.android.settings.applications.LayoutPreference) LoaderManager(android.app.LoaderManager) Before(org.junit.Before) Fragment(android.app.Fragment) Answers(org.mockito.Answers) AnomalySummaryPreferenceController(com.android.settings.fuelgauge.anomaly.AnomalySummaryPreferenceController) Test(org.junit.Test) ApplicationsState(com.android.settingslib.applications.ApplicationsState) Truth.assertThat(com.google.common.truth.Truth.assertThat) InstantAppDataProvider(com.android.settingslib.applications.instantapps.InstantAppDataProvider) Mockito.verify(org.mockito.Mockito.verify) Preference(android.support.v7.preference.Preference) RecyclerView(android.support.v7.widget.RecyclerView) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) BatterySipper(com.android.internal.os.BatterySipper) BatteryStats(android.os.BatteryStats) Activity(android.app.Activity) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) Bundle(android.os.Bundle) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) Drawable(android.graphics.drawable.Drawable) ApplicationInfo(android.content.pm.ApplicationInfo) Fragment(android.app.Fragment) LayoutPreference(com.android.settings.applications.LayoutPreference) Preference(android.support.v7.preference.Preference) UserHandle(android.os.UserHandle) RecyclerView(android.support.v7.widget.RecyclerView) SettingsActivity(com.android.settings.SettingsActivity) Before(org.junit.Before)

Example 18 with FakeFeatureFactory

use of com.android.settings.testutils.FakeFeatureFactory in project platform_packages_apps_Settings by BlissRoms.

the class GesturesSettingsPreferenceControllerTest method updateState_sensorNotAvailable_shouldSetToEmptyStatus.

@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("");
}
Also used : Context(android.content.Context) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) Test(org.junit.Test) Config(org.robolectric.annotation.Config) TestConfig(com.android.settings.TestConfig)

Example 19 with FakeFeatureFactory

use of com.android.settings.testutils.FakeFeatureFactory in project platform_packages_apps_Settings by BlissRoms.

the class InstalledAppResultLoaderTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    final FakeFeatureFactory factory = FakeFeatureFactory.setupForTest(mContext);
    when(factory.searchFeatureProvider.getSiteMapManager()).thenReturn(mSiteMapManager);
    final List<UserInfo> infos = new ArrayList<>();
    infos.add(new UserInfo(1, "user 1", 0));
    when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
    when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
    when(mContext.getString(R.string.applications_settings)).thenReturn("app");
    when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt())).thenReturn(Arrays.asList(ApplicationTestUtils.buildInfo(0, /* uid */
    "app1", FLAG_SYSTEM, 0), ApplicationTestUtils.buildInfo(0, /* uid */
    "app2", FLAG_SYSTEM, 0), ApplicationTestUtils.buildInfo(0, /* uid */
    "app3", FLAG_SYSTEM, 0), ApplicationTestUtils.buildInfo(0, /* uid */
    "app4", 0, /* flags */
    0), ApplicationTestUtils.buildInfo(0, /* uid */
    "app", 0, /* flags */
    0), ApplicationTestUtils.buildInfo(0, /* uid */
    "appBuffer", 0, /* flags */
    0)));
}
Also used : ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) Before(org.junit.Before)

Example 20 with FakeFeatureFactory

use of com.android.settings.testutils.FakeFeatureFactory in project android_packages_apps_Settings by omnirom.

the class GesturesSettingsPreferenceControllerTest method updateState_assistSupported_shouldSetToAssistGestureStatus.

@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);
}
Also used : Context(android.content.Context) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) ContentResolver(android.content.ContentResolver) Test(org.junit.Test) Config(org.robolectric.annotation.Config) TestConfig(com.android.settings.TestConfig)

Aggregations

FakeFeatureFactory (com.android.settings.testutils.FakeFeatureFactory)58 Test (org.junit.Test)35 Before (org.junit.Before)28 Context (android.content.Context)26 Config (org.robolectric.annotation.Config)22 TestConfig (com.android.settings.TestConfig)17 Bundle (android.os.Bundle)12 ArrayList (java.util.ArrayList)11 Activity (android.app.Activity)10 PackageManager (android.content.pm.PackageManager)10 Preference (android.support.v7.preference.Preference)10 ContentResolver (android.content.ContentResolver)7 AppOpsManager (android.app.AppOpsManager)5 Fragment (android.app.Fragment)5 LoaderManager (android.app.LoaderManager)5 ApplicationInfo (android.content.pm.ApplicationInfo)5 Drawable (android.graphics.drawable.Drawable)5 BatteryStats (android.os.BatteryStats)5 UserHandle (android.os.UserHandle)5 RecyclerView (android.support.v7.widget.RecyclerView)5