Search in sources :

Example 31 with FragmentActivity

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

the class RemoveAccountPreferenceControllerTest method confirmRemove_shouldRemoveAccount.

@Test
@Config(shadows = { ShadowAccountManager.class, ShadowContentResolver.class })
public void confirmRemove_shouldRemoveAccount() throws AuthenticatorException, OperationCanceledException, IOException {
    when(mFragment.isAdded()).thenReturn(true);
    FragmentActivity activity = mock(FragmentActivity.class);
    when(activity.getSystemService(Context.ACCOUNT_SERVICE)).thenReturn(mAccountManager);
    when(mFragment.getActivity()).thenReturn(activity);
    Account account = new Account("Account11", "com.acct1");
    UserHandle userHandle = new UserHandle(10);
    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).finish();
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) Account(android.accounts.Account) 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 32 with FragmentActivity

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

the class RemoveAccountPreferenceControllerTest method confirmRemove_activityGone_shouldSilentlyRemoveAccount.

@Test
@Config(shadows = { ShadowAccountManager.class, ShadowContentResolver.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 33 with FragmentActivity

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

the class AccountDetailDashboardFragmentTest method refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent.

@Test
public void refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent() {
    final DashboardFeatureProviderImpl dashboardFeatureProvider = new DashboardFeatureProviderImpl(mContext);
    final PackageManager packageManager = mock(PackageManager.class);
    ReflectionHelpers.setField(dashboardFeatureProvider, "mPackageManager", packageManager);
    when(packageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(mock(ResolveInfo.class));
    final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
    mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
    mActivityInfo.metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
    mActivityInfo.metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
    mActivityInfo.metaData.putString(META_DATA_PREFERENCE_TITLE, "summary");
    mActivityInfo.metaData.putString("com.android.settings.intent.action", Intent.ACTION_ASSIST);
    tile.userHandle = null;
    mFragment.displayTile(tile);
    final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
    final Preference preference = new Preference(mContext);
    dashboardFeatureProvider.bindPreferenceToTile(activity, false, /* forceRoundedIcon */
    MetricsProto.MetricsEvent.DASHBOARD_SUMMARY, preference, tile, null, /* key */
    Preference.DEFAULT_ORDER);
    assertThat(preference.getKey()).isEqualTo(tile.getKey(mContext));
    preference.performClick();
    final Intent intent = Shadows.shadowOf(activity).getNextStartedActivityForResult().intent;
    assertThat(intent.getStringExtra("extra.accountName")).isEqualTo("name1@abc.com");
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) FragmentActivity(androidx.fragment.app.FragmentActivity) PackageManager(android.content.pm.PackageManager) Preference(androidx.preference.Preference) DashboardFeatureProviderImpl(com.android.settings.dashboard.DashboardFeatureProviderImpl) Tile(com.android.settingslib.drawer.Tile) Intent(android.content.Intent) Test(org.junit.Test)

Example 34 with FragmentActivity

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

the class UtilsTest method setActionBarShadowAnimation_shouldSetElevationToZero.

@Test
public void setActionBarShadowAnimation_shouldSetElevationToZero() {
    final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
    final ActionBar actionBar = activity.getActionBar();
    Utils.setActionBarShadowAnimation(activity, activity.getLifecycle(), new ScrollView(mContext));
    assertThat(actionBar.getElevation()).isEqualTo(0.f);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) ScrollView(android.widget.ScrollView) ActionBar(android.app.ActionBar) Test(org.junit.Test)

Example 35 with FragmentActivity

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

the class HeaderPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    ShadowApplication shadowApplication = ShadowApplication.getInstance();
    shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
    shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
    mContext = RuntimeEnvironment.application;
    DashboardFragment fragment = mock(DashboardFragment.class);
    when(fragment.getContext()).thenReturn(mContext);
    FragmentActivity activity = mock(FragmentActivity.class);
    when(activity.getApplicationContext()).thenReturn(mContext);
    when(fragment.getActivity()).thenReturn(activity);
    mController = spy(new HeaderPreferenceController(mContext, fragment));
    when(mPreference.findViewById(anyInt())).thenReturn(mView);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) DashboardFragment(com.android.settings.dashboard.DashboardFragment) ShadowApplication(org.robolectric.shadows.ShadowApplication) Before(org.junit.Before)

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