Search in sources :

Example 36 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppNotificationPreferenceControllerTest method getArguments_containsChannelId.

@Test
public void getArguments_containsChannelId() {
    FragmentActivity activity = mock(FragmentActivity.class);
    Intent intent = new Intent();
    intent.putExtra(EXTRA_FRAGMENT_ARG_KEY, "test");
    when(mFragment.getActivity()).thenReturn(activity);
    when(activity.getIntent()).thenReturn(intent);
    AppNotificationPreferenceController controller = new AppNotificationPreferenceController(mContext, "test");
    controller.setParentFragment(mFragment);
    assertThat(controller.getArguments().containsKey(EXTRA_FRAGMENT_ARG_KEY)).isTrue();
    assertThat(controller.getArguments().getString(EXTRA_FRAGMENT_ARG_KEY)).isEqualTo("test");
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) Intent(android.content.Intent) Test(org.junit.Test)

Example 37 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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 38 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BillingCycleSettingsTest method onCreate_emptyArguments_shouldSetDefaultNetworkTemplate.

@Test
public void onCreate_emptyArguments_shouldSetDefaultNetworkTemplate() {
    final BillingCycleSettings billingCycleSettings = spy(new BillingCycleSettings());
    when(billingCycleSettings.getContext()).thenReturn(mContext);
    when(billingCycleSettings.getArguments()).thenReturn(Bundle.EMPTY);
    final FragmentActivity activity = mock(FragmentActivity.class);
    when(billingCycleSettings.getActivity()).thenReturn(activity);
    final Resources.Theme theme = mContext.getTheme();
    when(activity.getTheme()).thenReturn(theme);
    doNothing().when(billingCycleSettings).onCreatePreferences(any(Bundle.class), nullable(String.class));
    when(mContext.getSystemService(Context.NETWORK_POLICY_SERVICE)).thenReturn(mNetworkPolicyManager);
    when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(mConnectivityManager);
    when(mConnectivityManager.isNetworkSupported(anyInt())).thenReturn(true);
    final SwitchPreference preference = mock(SwitchPreference.class);
    when(billingCycleSettings.findPreference(anyString())).thenReturn(preference);
    final FooterPreferenceMixinCompat footer = mock(FooterPreferenceMixinCompat.class);
    ReflectionHelpers.setField(billingCycleSettings, "mFooterPreferenceMixin", footer);
    when(footer.createFooterPreference()).thenReturn(mock(FooterPreference.class));
    billingCycleSettings.onCreate(Bundle.EMPTY);
    assertThat(billingCycleSettings.mNetworkTemplate).isNotNull();
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) SwitchPreference(androidx.preference.SwitchPreference) Bundle(android.os.Bundle) FooterPreferenceMixinCompat(com.android.settingslib.widget.FooterPreferenceMixinCompat) Resources(android.content.res.Resources) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FooterPreference(com.android.settingslib.widget.FooterPreference) Test(org.junit.Test)

Example 39 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DashboardFeatureProviderImplTest method bindPreference_withIntentActionMetadata_shouldSetLaunchAction.

@Test
public void bindPreference_withIntentActionMetadata_shouldSetLaunchAction() {
    FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).get();
    final Preference preference = new Preference(RuntimeEnvironment.application);
    final Tile tile = new Tile(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.bindPreferenceToTile(activity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
    preference.performClick();
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    final Intent launchIntent = shadowActivity.getNextStartedActivityForResult().intent;
    assertThat(launchIntent.getAction()).isEqualTo("TestAction");
    assertThat(launchIntent.getIntExtra(MetricsFeatureProvider.EXTRA_SOURCE_METRICS_CATEGORY, 0)).isEqualTo(MetricsEvent.SETTINGS_GESTURES);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) Preference(androidx.preference.Preference) Tile(com.android.settingslib.drawer.Tile) ShadowActivity(org.robolectric.shadows.ShadowActivity) Intent(android.content.Intent) Test(org.junit.Test)

Example 40 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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 Tile(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.bindPreferenceToTile(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) Preference(androidx.preference.Preference) Tile(com.android.settingslib.drawer.Tile) ShadowActivity(org.robolectric.shadows.ShadowActivity) Test(org.junit.Test)

Aggregations

FragmentActivity (androidx.fragment.app.FragmentActivity)181 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 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 Resources (android.content.res.Resources)7 Fragment (androidx.fragment.app.Fragment)7 FragmentManager (androidx.fragment.app.FragmentManager)7 Activity (android.app.Activity)6 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