Search in sources :

Example 81 with FragmentActivity

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

the class TetherSettingsTest method onReceive_mediaIsUnshared_tetheringPreferenceIsEnabled.

@Test
public void onReceive_mediaIsUnshared_tetheringPreferenceIsEnabled() {
    RestrictedSwitchPreference tetheringPreference = mock(RestrictedSwitchPreference.class);
    FragmentActivity mockActivity = mock(FragmentActivity.class);
    ArgumentCaptor<BroadcastReceiver> captor = ArgumentCaptor.forClass(BroadcastReceiver.class);
    setupUsbStateComponents(tetheringPreference, captor, mockActivity);
    BroadcastReceiver receiver = captor.getValue();
    Intent mediaIsShared = new Intent(ACTION_MEDIA_UNSHARED);
    Intent usbStateChanged = new Intent(ACTION_USB_STATE);
    usbStateChanged.putExtra(UsbManager.USB_CONNECTED, true);
    receiver.onReceive(mockActivity, usbStateChanged);
    receiver.onReceive(mockActivity, mediaIsShared);
    verify(tetheringPreference, times(2)).setEnabled(true);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) Test(org.junit.Test)

Example 82 with FragmentActivity

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

the class TetherSettingsTest method onReceive_usbIsDisconnected_tetheringPreferenceIsDisabled.

@Test
public void onReceive_usbIsDisconnected_tetheringPreferenceIsDisabled() {
    RestrictedSwitchPreference tetheringPreference = mock(RestrictedSwitchPreference.class);
    FragmentActivity mockActivity = mock(FragmentActivity.class);
    ArgumentCaptor<BroadcastReceiver> captor = ArgumentCaptor.forClass(BroadcastReceiver.class);
    setupUsbStateComponents(tetheringPreference, captor, mockActivity);
    BroadcastReceiver receiver = captor.getValue();
    Intent usbStateChanged = new Intent(ACTION_USB_STATE);
    usbStateChanged.putExtra(UsbManager.USB_CONNECTED, false);
    receiver.onReceive(mockActivity, usbStateChanged);
    verify(tetheringPreference).setEnabled(false);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) Test(org.junit.Test)

Example 83 with FragmentActivity

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

the class RemoveAccountPreferenceControllerTest method confirmRemove_activityGone_shouldSilentlyRemoveAccount.

@Test
@Config(shadows = { ShadowAccountManager.class, ShadowContentResolver.class, ShadowFragment.class })
public void confirmRemove_activityGone_shouldSilentlyRemoveAccount() throws AuthenticatorException, OperationCanceledException, IOException {
    final Account account = new Account("Account11", "com.acct1");
    final UserHandle userHandle = new UserHandle(10);
    final FragmentActivity activity = mock(FragmentActivity.class);
    when(mFragment.isAdded()).thenReturn(true);
    when(activity.getSystemService(Context.ACCOUNT_SERVICE)).thenReturn(mAccountManager);
    when(mFragment.getActivity()).thenReturn(activity).thenReturn(null);
    final RemoveAccountPreferenceController.ConfirmRemoveAccountDialog dialog = RemoveAccountPreferenceController.ConfirmRemoveAccountDialog.show(mFragment, account, userHandle);
    dialog.onCreate(new Bundle());
    dialog.onClick(null, 0);
    ArgumentCaptor<AccountManagerCallback<Bundle>> callbackCaptor = ArgumentCaptor.forClass(AccountManagerCallback.class);
    verify(mAccountManager).removeAccountAsUser(eq(account), nullable(Activity.class), callbackCaptor.capture(), nullable(Handler.class), eq(userHandle));
    AccountManagerCallback<Bundle> callback = callbackCaptor.getValue();
    assertThat(callback).isNotNull();
    AccountManagerFuture<Bundle> future = mock(AccountManagerFuture.class);
    Bundle resultBundle = new Bundle();
    resultBundle.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
    when(future.getResult()).thenReturn(resultBundle);
    callback.run(future);
    verify(activity, never()).finish();
}
Also used : Account(android.accounts.Account) FragmentActivity(androidx.fragment.app.FragmentActivity) AccountManagerCallback(android.accounts.AccountManagerCallback) Bundle(android.os.Bundle) UserHandle(android.os.UserHandle) FragmentActivity(androidx.fragment.app.FragmentActivity) Activity(android.app.Activity) Handler(android.os.Handler) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 84 with FragmentActivity

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

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

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

the class NetworkProviderSettingsTest method onNumSavedSubscriptionsChanged_isFinishing_ShouldNotCrash.

@Test
public void onNumSavedSubscriptionsChanged_isFinishing_ShouldNotCrash() {
    final FragmentActivity activity = mock(FragmentActivity.class);
    when(activity.isFinishing()).thenReturn(true);
    when(mNetworkProviderSettings.getActivity()).thenReturn(activity);
    when(mNetworkProviderSettings.getContext()).thenReturn(null);
    mNetworkProviderSettings.onNumSavedSubscriptionsChanged();
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) 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