Search in sources :

Example 11 with ActivityResult

use of android.app.Instrumentation.ActivityResult in project platform_packages_apps_Settings by BlissRoms.

the class FingerprintEnrollFinishTest method clickAddAnother_shouldPropagateResults.

@Test
public void clickAddAnother_shouldPropagateResults() {
    final ComponentName enrollingComponent = new ComponentName(getTargetContext(), FingerprintEnrollEnrolling.class);
    intending(hasComponent(enrollingComponent)).respondWith(new ActivityResult(Activity.RESULT_OK, null));
    onView(withId(R.id.add_another_button)).perform(click());
    intended(hasComponent(enrollingComponent));
    assertTrue(mActivityRule.getActivity().isFinishing());
}
Also used : ComponentName(android.content.ComponentName) ActivityResult(android.app.Instrumentation.ActivityResult) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest)

Example 12 with ActivityResult

use of android.app.Instrumentation.ActivityResult in project robolectric by robolectric.

the class LocalActivityInvoker method getActivityResult.

@Override
public ActivityResult getActivityResult() {
    checkNotNull(controller);
    checkState(controller.get().isFinishing(), "You must finish your Activity first");
    ShadowActivity shadowActivity = Shadow.extract(controller.get());
    return new ActivityResult(shadowActivity.getResultCode(), shadowActivity.getResultIntent());
}
Also used : ShadowActivity(org.robolectric.shadows.ShadowActivity) ActivityResult(android.app.Instrumentation.ActivityResult)

Example 13 with ActivityResult

use of android.app.Instrumentation.ActivityResult in project robolectric by robolectric.

the class IntentsTest method intending_callsOnActivityResult.

@Test
public void intending_callsOnActivityResult() {
    intending(hasComponent(hasClassName(DummyActivity.class.getName()))).respondWith(new ActivityResult(Activity.RESULT_OK, new Intent().putExtra("key", 123)));
    ActivityScenario<ResultCapturingActivity> activityScenario = ActivityScenario.launch(ResultCapturingActivity.class);
    activityScenario.onActivity(activity -> activity.startActivityForResult(new Intent(activity, DummyActivity.class), 0));
    activityScenario.onActivity(activity -> {
        assertThat(activity.activityResult.getResultCode()).isEqualTo(Activity.RESULT_OK);
        assertThat(activity.activityResult.getResultData()).extras().containsKey("key");
    });
}
Also used : Intent(android.content.Intent) ActivityResult(android.app.Instrumentation.ActivityResult) Test(org.junit.Test)

Example 14 with ActivityResult

use of android.app.Instrumentation.ActivityResult in project android-testing by googlesamples.

the class ImageViewerActivityTest method createImageCaptureActivityResultStub.

private ActivityResult createImageCaptureActivityResultStub() {
    // Put the drawable in a bundle.
    Bundle bundle = new Bundle();
    bundle.putParcelable(ImageViewerActivity.KEY_IMAGE_DATA, BitmapFactory.decodeResource(InstrumentationRegistry.getInstrumentation().getTargetContext().getResources(), R.drawable.ic_launcher));
    // Create the Intent that will include the bundle.
    Intent resultData = new Intent();
    resultData.putExtras(bundle);
    // Create the ActivityResult with the Intent.
    return new ActivityResult(Activity.RESULT_OK, resultData);
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) ActivityResult(android.app.Instrumentation.ActivityResult)

Example 15 with ActivityResult

use of android.app.Instrumentation.ActivityResult in project android-testing by googlesamples.

the class DialerActivityTest method pickContactButton_click_SelectsPhoneNumber.

@Test
public void pickContactButton_click_SelectsPhoneNumber() {
    // Stub all Intents to ContactsActivity to return VALID_PHONE_NUMBER. Note that the Activity
    // is never launched and result is stubbed.
    intending(hasComponent(hasShortClassName(".ContactsActivity"))).respondWith(new ActivityResult(Activity.RESULT_OK, ContactsActivity.createResultData(VALID_PHONE_NUMBER)));
    // Click the pick contact button.
    onView(withId(R.id.button_pick_contact)).perform(click());
    // Check that the number is displayed in the UI.
    onView(withId(R.id.edit_text_caller_number)).check(matches(withText(VALID_PHONE_NUMBER)));
}
Also used : ActivityResult(android.app.Instrumentation.ActivityResult) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Aggregations

ActivityResult (android.app.Instrumentation.ActivityResult)25 Test (org.junit.Test)18 ComponentName (android.content.ComponentName)14 SmallTest (android.support.test.filters.SmallTest)12 Intent (android.content.Intent)6 RandomString (net.bytebuddy.utility.RandomString)3 SmallTest (androidx.test.filters.SmallTest)2 PartnerCustomizationLayout (com.google.android.setupcompat.PartnerCustomizationLayout)2 Instrumentation (android.app.Instrumentation)1 Bundle (android.os.Bundle)1 LargeTest (android.support.test.filters.LargeTest)1 DocumentFile (androidx.documentfile.provider.DocumentFile)1 LargeTest (androidx.test.filters.LargeTest)1 HookAnnotation (com.kunpeng.pit.HookAnnotation)1 OrgzlyTest (com.orgzly.android.OrgzlyTest)1 File (java.io.File)1 Before (org.junit.Before)1 ShadowActivity (org.robolectric.shadows.ShadowActivity)1