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);
}
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);
}
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();
}
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");
}
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();
}
Aggregations