Search in sources :

Example 91 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity in project platform_packages_apps_Settings by BlissRoms.

the class SetupChooseLockPasswordTest method createActivity_clickDifferentOption_extrasShouldBePropagated.

@Test
public void createActivity_clickDifferentOption_extrasShouldBePropagated() {
    Bundle bundle = new Bundle();
    bundle.putString("foo", "bar");
    Intent intent = new IntentBuilder(application).build();
    intent.putExtra(ChooseLockGenericFragment.EXTRA_CHOOSE_LOCK_GENERIC_EXTRAS, bundle);
    intent = SetupChooseLockPassword.modifyIntentForSetup(application, intent);
    intent.putExtra(ChooseLockGenericFragment.EXTRA_SHOW_OPTIONS_BUTTON, true);
    SetupChooseLockPassword activity = Robolectric.buildActivity(SetupChooseLockPassword.class, intent).setup().get();
    SetupChooseLockPasswordFragment fragment = (SetupChooseLockPasswordFragment) activity.getFragmentManager().findFragmentById(R.id.main_content);
    fragment.onLockTypeSelected(ScreenLockType.PATTERN);
    ShadowActivity shadowActivity = shadowOf(activity);
    IntentForResult chooseLockIntent = shadowActivity.getNextStartedActivityForResult();
    assertThat(chooseLockIntent).isNotNull();
    assertThat(chooseLockIntent.requestCode).isEqualTo(SetupChooseLockPasswordFragment.REQUEST_SCREEN_LOCK_OPTIONS);
    assertThat(chooseLockIntent.intent.getStringExtra("foo")).named("Foo extra").isEqualTo("bar");
}
Also used : Bundle(android.os.Bundle) IntentBuilder(com.android.settings.password.ChooseLockPassword.IntentBuilder) SetupChooseLockPasswordFragment(com.android.settings.password.SetupChooseLockPassword.SetupChooseLockPasswordFragment) ShadowActivity(org.robolectric.shadows.ShadowActivity) Intent(android.content.Intent) IntentForResult(org.robolectric.shadows.ShadowActivity.IntentForResult) Test(org.junit.Test)

Example 92 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity in project platform_packages_apps_Settings by BlissRoms.

the class DashboardFeatureProviderImplTest method bindPreference_withIntentActionMetatdata_shouldSetLaunchAction.

@Test
public void bindPreference_withIntentActionMetatdata_shouldSetLaunchAction() {
    Activity activity = Robolectric.buildActivity(Activity.class).get();
    final ShadowApplication application = ShadowApplication.getInstance();
    final Preference preference = new Preference(application.getApplicationContext());
    final Tile tile = new Tile();
    tile.key = "key";
    tile.intent = new Intent();
    tile.intent.setComponent(new ComponentName("pkg", "class"));
    tile.metaData = new Bundle();
    tile.metaData.putString("com.android.settings.intent.action", "TestAction");
    tile.userHandle = null;
    mImpl.bindPreferenceToTile(activity, MetricsProto.MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
    preference.performClick();
    ShadowActivity shadowActivity = shadowOf(activity);
    final Intent launchIntent = shadowActivity.getNextStartedActivityForResult().intent;
    assertThat(launchIntent.getAction()).isEqualTo("TestAction");
    assertThat(launchIntent.getIntExtra(SettingsActivity.EXTRA_SOURCE_METRICS_CATEGORY, 0)).isEqualTo(MetricsProto.MetricsEvent.SETTINGS_GESTURES);
}
Also used : Preference(android.support.v7.preference.Preference) Bundle(android.os.Bundle) ShadowActivity(org.robolectric.shadows.ShadowActivity) SettingsActivity(com.android.settings.SettingsActivity) Activity(android.app.Activity) Tile(com.android.settingslib.drawer.Tile) ShadowActivity(org.robolectric.shadows.ShadowActivity) Intent(android.content.Intent) ComponentName(android.content.ComponentName) ShadowApplication(org.robolectric.shadows.ShadowApplication) Test(org.junit.Test)

Example 93 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity in project edx-app-android by edx.

the class BaseVideosDownloadStateActivityTest method downloadProgressViewTest.

/**
 * Testing download progress menu visibility states and click behaviour
 * (starting DownloadActivity). Only when both AppConstants.offline_flag
 * is true and there is a downloading entry in the database, should the
 * progress bar be visible.
 */
@Test
public void downloadProgressViewTest() {
    connectToNetwork();
    assertFalse(Shadows.shadowOf(Robolectric.buildActivity(getActivityClass()).withIntent(getIntent()).setup().get()).getOptionsMenu().findItem(R.id.download_progress).isVisible());
    disconnectFromNetwork();
    assertFalse(Shadows.shadowOf(Robolectric.buildActivity(getActivityClass()).withIntent(getIntent()).setup().get()).getOptionsMenu().findItem(R.id.download_progress).isVisible());
    IDatabase db = environment.getDatabase();
    DownloadEntry de = new DownloadEntry();
    de.username = "unittest";
    de.title = "title";
    de.videoId = "videoId-" + System.currentTimeMillis();
    de.size = 1024;
    de.duration = 3600;
    de.filepath = "/fakepath";
    de.url = "http://fake/url";
    de.eid = "fake_eid";
    de.chapter = "fake_chapter";
    de.section = "fake_section";
    de.lastPlayedOffset = 0;
    de.lmsUrl = "http://fake/lms/url";
    de.isCourseActive = 1;
    de.downloaded = DownloadEntry.DownloadedState.DOWNLOADING;
    Long rowId = db.addVideoData(de, null);
    assertNotNull(rowId);
    assertThat(rowId).isGreaterThan(0);
    assertFalse(Shadows.shadowOf(Robolectric.buildActivity(getActivityClass()).withIntent(getIntent()).setup().get()).getOptionsMenu().findItem(R.id.download_progress).isVisible());
    connectToNetwork();
    BaseVideosDownloadStateActivity activity = Robolectric.buildActivity(getActivityClass()).withIntent(getIntent()).setup().get();
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    MenuItem downloadProgressMenuItem = shadowActivity.getOptionsMenu().findItem(R.id.download_progress);
    assertTrue(downloadProgressMenuItem.isVisible());
    assertTrue(downloadProgressMenuItem.getActionView().performClick());
    assertNextStartedActivity(activity, DownloadListActivity.class);
}
Also used : IDatabase(org.edx.mobile.module.db.IDatabase) BaseVideosDownloadStateActivity(org.edx.mobile.base.BaseVideosDownloadStateActivity) ShadowActivity(org.robolectric.shadows.ShadowActivity) MenuItem(android.view.MenuItem) DownloadEntry(org.edx.mobile.model.db.DownloadEntry) Test(org.junit.Test)

Example 94 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity in project android_packages_apps_Settings by omnirom.

the class FingerprintEnrollFindSensorTest method layoutWithoutAnimation_shouldNotCrash.

// Use a non-default resource qualifier to load the test layout in
// robotests/res/layout-mcc999/fingerprint_enroll_find_sensor. This layout is a copy of the
// regular find sensor layout, with the animation removed.
@Config(qualifiers = "mcc999")
@Test
public void layoutWithoutAnimation_shouldNotCrash() {
    EnrollmentCallback enrollmentCallback = verifyAndCaptureEnrollmentCallback();
    enrollmentCallback.onEnrollmentProgress(123);
    enrollmentCallback.onEnrollmentError(FingerprintManager.FINGERPRINT_ERROR_CANCELED, "test");
    ShadowActivity shadowActivity = Shadows.shadowOf(mActivity);
    IntentForResult startedActivity = shadowActivity.getNextStartedActivityForResult();
    assertThat(startedActivity).named("Next activity").isNotNull();
    assertThat(startedActivity.intent.getComponent()).isEqualTo(new ComponentName(application, FingerprintEnrollEnrolling.class));
}
Also used : ShadowActivity(org.robolectric.shadows.ShadowActivity) ComponentName(android.content.ComponentName) IntentForResult(org.robolectric.shadows.ShadowActivity.IntentForResult) EnrollmentCallback(android.hardware.fingerprint.FingerprintManager.EnrollmentCallback) Test(org.junit.Test) Config(org.robolectric.annotation.Config) TestConfig(com.android.settings.TestConfig)

Example 95 with ShadowActivity

use of org.robolectric.shadows.ShadowActivity in project android_packages_apps_Settings by omnirom.

the class FingerprintEnrollFindSensorTest method enrollFingerprint_shouldProceed.

@Test
public void enrollFingerprint_shouldProceed() {
    EnrollmentCallback enrollmentCallback = verifyAndCaptureEnrollmentCallback();
    enrollmentCallback.onEnrollmentProgress(123);
    enrollmentCallback.onEnrollmentError(FingerprintManager.FINGERPRINT_ERROR_CANCELED, "test");
    ShadowActivity shadowActivity = Shadows.shadowOf(mActivity);
    IntentForResult startedActivity = shadowActivity.getNextStartedActivityForResult();
    assertThat(startedActivity).named("Next activity 1").isNotNull();
    assertThat(startedActivity.intent.getComponent()).isEqualTo(new ComponentName(application, FingerprintEnrollEnrolling.class));
}
Also used : ShadowActivity(org.robolectric.shadows.ShadowActivity) ComponentName(android.content.ComponentName) IntentForResult(org.robolectric.shadows.ShadowActivity.IntentForResult) EnrollmentCallback(android.hardware.fingerprint.FingerprintManager.EnrollmentCallback) 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