Search in sources :

Example 91 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project android_packages_apps_Settings by omnirom.

the class WifiSettingsTest method setUpForOnCreate.

private void setUpForOnCreate() {
    final FragmentActivity activity = mock(FragmentActivity.class);
    when(mWifiSettings.getActivity()).thenReturn(activity);
    final Resources.Theme theme = mContext.getTheme();
    when(activity.getTheme()).thenReturn(theme);
    UserManager userManager = mock(UserManager.class);
    when(activity.getSystemService(Context.USER_SERVICE)).thenReturn(userManager);
    when(mWifiSettings.findPreference(WifiSettings.PREF_KEY_DATA_USAGE)).thenReturn(mDataUsagePreference);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) UserManager(android.os.UserManager) Resources(android.content.res.Resources)

Example 92 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project android_packages_apps_Settings by omnirom.

the class InstantAppButtonDialogFragmentTest method setUp.

@Before
public void setUp() {
    final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
    mContext = spy(RuntimeEnvironment.application);
    mFragment = spy(InstantAppButtonDialogFragment.newInstance(TEST_PACKAGE));
    mFragment.show(activity.getSupportFragmentManager(), "InstantAppButtonDialogFragment");
    doReturn(mContext).when(mFragment).getContext();
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) Before(org.junit.Before)

Example 93 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project android_packages_apps_Settings by omnirom.

the class SurveyMixinTest method onPause_removesReceiverIfPreviouslySet.

@Test
public void onPause_removesReceiverIfPreviouslySet() {
    // Pretend there is a survey in memory
    when(mProvider.getSurveyExpirationDate(any(), any())).thenReturn(-1L);
    // Pretend we are an activity that starts and stops
    FragmentActivity temp = Robolectric.setupActivity(FragmentActivity.class);
    when(mFragment.getActivity()).thenReturn(temp);
    when(mProvider.createAndRegisterReceiver(any())).thenReturn(mReceiver);
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(temp);
    SurveyMixin mixin = new SurveyMixin(mFragment, FAKE_KEY);
    mixin.onResume();
    manager.registerReceiver(mReceiver, new IntentFilter());
    mixin.onPause();
    // Verify we remove the receiver
    HashMap<BroadcastReceiver, ArrayList<IntentFilter>> map = ReflectionHelpers.getField(manager, "mReceivers");
    assertThat(map.containsKey(mReceiver)).isFalse();
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) IntentFilter(android.content.IntentFilter) ArrayList(java.util.ArrayList) BroadcastReceiver(android.content.BroadcastReceiver) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager) Test(org.junit.Test)

Example 94 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project android_packages_apps_Settings by omnirom.

the class DashboardFeatureProviderImplTest method clickPreference_withUnresolvableIntent_shouldNotLaunchAnything.

@Test
public void clickPreference_withUnresolvableIntent_shouldNotLaunchAnything() {
    ReflectionHelpers.setField(mImpl, "mPackageManager", RuntimeEnvironment.application.getPackageManager());
    FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).get();
    final Preference preference = new Preference(RuntimeEnvironment.application);
    final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
    mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
    mActivityInfo.metaData.putString("com.android.settings.intent.action", "TestAction");
    tile.userHandle = null;
    mImpl.bindPreferenceToTileAndGetObservers(activity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
    preference.performClick();
    final ShadowActivity.IntentForResult launchIntent = Shadows.shadowOf(activity).getNextStartedActivityForResult();
    assertThat(launchIntent).isNull();
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) ActivityTile(com.android.settingslib.drawer.ActivityTile) ProviderTile(com.android.settingslib.drawer.ProviderTile) Tile(com.android.settingslib.drawer.Tile) ShadowActivity(org.robolectric.shadows.ShadowActivity) ActivityTile(com.android.settingslib.drawer.ActivityTile) Test(org.junit.Test)

Example 95 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project android_packages_apps_Settings by omnirom.

the class EntityHeaderControllerTest method bindButton_hasAppInfo_shouldAttachClickListener.

@Test
public void bindButton_hasAppInfo_shouldAttachClickListener() {
    final View appLinks = mLayoutInflater.inflate(R.layout.settings_entity_header, null);
    final FragmentActivity activity = mock(FragmentActivity.class);
    when(mFragment.getActivity()).thenReturn(activity);
    when(mContext.getString(eq(R.string.application_info_label))).thenReturn("App Info");
    mController = EntityHeaderController.newInstance(mActivity, mFragment, appLinks);
    mController.setPackageName("123").setUid(123321).setHasAppInfoLink(true).setButtonActions(EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE, EntityHeaderController.ActionType.ACTION_NONE);
    mController.done(mActivity);
    appLinks.findViewById(R.id.entity_header_content).performClick();
    verify(activity).startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) UserHandle(android.os.UserHandle) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) Test(org.junit.Test)

Aggregations

FragmentActivity (androidx.fragment.app.FragmentActivity)185 Test (org.junit.Test)71 Intent (android.content.Intent)25 Bundle (android.os.Bundle)19 View (android.view.View)11 Config (org.robolectric.annotation.Config)11 TextView (android.widget.TextView)10 Before (org.junit.Before)10 BroadcastReceiver (android.content.BroadcastReceiver)8 Fragment (androidx.fragment.app.Fragment)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 Activity (android.app.Activity)7 Resources (android.content.res.Resources)7 FragmentManager (androidx.fragment.app.FragmentManager)7 IntentFilter (android.content.IntentFilter)6 UserHandle (android.os.UserHandle)6 Preference (androidx.preference.Preference)6 SwitchPreference (androidx.preference.SwitchPreference)6 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)6 Tile (com.android.settingslib.drawer.Tile)6