Search in sources :

Example 26 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SetNewPasswordActivityTest method testLaunchChooseLock_setNewParentProfilePasswordExtraWithPermission.

@Test
@Config(shadows = { ShadowPasswordUtils.class })
public void testLaunchChooseLock_setNewParentProfilePasswordExtraWithPermission() {
    ShadowPasswordUtils.setCallingAppLabel(APP_LABEL);
    ShadowPasswordUtils.setCallingAppPackageName(PKG_NAME);
    ShadowPasswordUtils.addGrantedPermission(REQUEST_PASSWORD_COMPLEXITY);
    Settings.Global.putInt(RuntimeEnvironment.application.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
    Intent intent = new Intent(ACTION_SET_NEW_PARENT_PROFILE_PASSWORD);
    intent.putExtra(EXTRA_PASSWORD_COMPLEXITY, PASSWORD_COMPLEXITY_HIGH);
    SetNewPasswordActivity activity = Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent actualIntent = getLaunchChooseLockIntent(shadowActivity);
    assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PARENT_PROFILE_PASSWORD);
    assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
    assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
    assertThat(actualIntent.getStringExtra(EXTRA_KEY_CALLER_APP_NAME)).isEqualTo(APP_LABEL);
    verify(mockMetricsProvider).action(SettingsEnums.PAGE_UNKNOWN, SettingsEnums.ACTION_SET_NEW_PARENT_PROFILE_PASSWORD, SettingsEnums.SET_NEW_PASSWORD_ACTIVITY, PKG_NAME, PASSWORD_COMPLEXITY_HIGH);
}
Also used : ShadowActivity(org.robolectric.shadows.ShadowActivity) Intent(android.content.Intent) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 27 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SetNewPasswordActivityTest method testLaunchChooseLock_setNewPasswordExtraInvalidValue.

@Test
@Config(shadows = { ShadowPasswordUtils.class })
public void testLaunchChooseLock_setNewPasswordExtraInvalidValue() {
    ShadowPasswordUtils.setCallingAppLabel(APP_LABEL);
    ShadowPasswordUtils.setCallingAppPackageName(PKG_NAME);
    ShadowPasswordUtils.addGrantedPermission(REQUEST_PASSWORD_COMPLEXITY);
    Settings.Global.putInt(RuntimeEnvironment.application.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
    Intent intent = new Intent(ACTION_SET_NEW_PASSWORD);
    intent.putExtra(EXTRA_PASSWORD_COMPLEXITY, -1);
    SetNewPasswordActivity activity = Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent actualIntent = getLaunchChooseLockIntent(shadowActivity);
    assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PASSWORD);
    assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
    assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
    assertThat(actualIntent.getStringExtra(EXTRA_KEY_CALLER_APP_NAME)).isEqualTo(APP_LABEL);
    verify(mockMetricsProvider).action(SettingsEnums.PAGE_UNKNOWN, SettingsEnums.ACTION_SET_NEW_PASSWORD, SettingsEnums.SET_NEW_PASSWORD_ACTIVITY, PKG_NAME, -1);
}
Also used : ShadowActivity(org.robolectric.shadows.ShadowActivity) Intent(android.content.Intent) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 28 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DefaultAppShortcutPreferenceControllerBaseTest method handlePreferenceTreeClick_shouldStartManageDefaultAppIntent.

@Test
public void handlePreferenceTreeClick_shouldStartManageDefaultAppIntent() {
    final ShadowActivity shadowActivity = shadowOf(mActivity);
    mController.handlePreferenceTreeClick(mPreference);
    final Intent intent = shadowActivity.getNextStartedActivity();
    assertThat(intent).isNotNull();
    assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MANAGE_DEFAULT_APP);
    assertThat(intent.getStringExtra(Intent.EXTRA_ROLE_NAME)).isEqualTo(TEST_ROLE_NAME);
}
Also used : ShadowActivity(org.robolectric.shadows.ShadowActivity) Intent(android.content.Intent) Test(org.junit.Test)

Example 29 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity 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 30 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BackgroundDataConditionControllerTest method onPrimaryClick_shouldReturn2SummaryActivity.

@Test
public void onPrimaryClick_shouldReturn2SummaryActivity() {
    final ComponentName componentName = new ComponentName(mActivity, Settings.DataUsageSummaryActivity.class);
    mController.onPrimaryClick(mActivity);
    final ShadowActivity shadowActivity = Shadow.extract(mActivity);
    assertThat(shadowActivity.getNextStartedActivity().getComponent()).isEqualTo(componentName);
}
Also used : ShadowActivity(org.robolectric.shadows.ShadowActivity) ComponentName(android.content.ComponentName) Settings(com.android.settings.Settings) Test(org.junit.Test)

Aggregations

ShadowActivity (org.robolectric.shadows.ShadowActivity)343 Test (org.junit.Test)330 Intent (android.content.Intent)163 ComponentName (android.content.ComponentName)100 Button (android.widget.Button)67 Config (org.robolectric.annotation.Config)53 IntentForResult (org.robolectric.shadows.ShadowActivity.IntentForResult)53 Activity (android.app.Activity)41 EnrollmentCallback (android.hardware.fingerprint.FingerprintManager.EnrollmentCallback)33 Bundle (android.os.Bundle)32 PartnerCustomizationLayout (com.google.android.setupcompat.PartnerCustomizationLayout)30 FooterBarMixin (com.google.android.setupcompat.template.FooterBarMixin)20 FragmentActivity (androidx.fragment.app.FragmentActivity)11 Tile (com.android.settingslib.drawer.Tile)11 Settings (com.android.settings.Settings)10 ContextualCardsFragment (com.android.settings.homepage.contextualcards.ContextualCardsFragment)10 IntentBuilder (com.android.settings.password.ChooseLockPassword.IntentBuilder)7 SetupChooseLockPasswordFragment (com.android.settings.password.SetupChooseLockPassword.SetupChooseLockPasswordFragment)7 ShadowIntent (org.robolectric.shadows.ShadowIntent)7 Preference (android.support.v7.preference.Preference)6