Search in sources :

Example 1 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) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 2 with ActivityResult

use of android.app.Instrumentation.ActivityResult in project collect by opendatakit.

the class AllWidgetsFormTest method testExIntegerWidget.

public void testExIntegerWidget() {
    // Manually input the value:
    String exIntegerFirstValue = randomIntegerString();
    when(activityAvailability.isActivityAvailable(any(Intent.class))).thenReturn(false);
    onView(withText("Launch")).perform(click());
    onVisibleEditText().perform(replaceText(exIntegerFirstValue));
    Screengrab.screenshot("ex-integer");
    openWidgetList();
    onView(withText("Ex integer widget")).perform(click());
    onVisibleEditText().check(matches(withText(exIntegerFirstValue)));
    // Replace with Intent value:
    String exIntegerSecondValue = randomIntegerString();
    Intent stringIntent = new Intent();
    stringIntent.putExtra("value", Integer.parseInt(exIntegerSecondValue));
    ActivityResult exStringResult = new ActivityResult(RESULT_OK, stringIntent);
    intending(allOf(hasAction("change.uw.android.BREATHCOUNT"), hasExtra("value", Integer.parseInt(exIntegerFirstValue)))).respondWith(exStringResult);
    when(activityAvailability.isActivityAvailable(any(Intent.class))).thenReturn(true);
    onView(withText("Launch")).perform(click());
    onView(withText(exIntegerSecondValue)).check(matches(isDisplayed()));
    Screengrab.screenshot("ex-integer2");
    openWidgetList();
    onView(withText("Ex integer widget")).perform(click());
    onVisibleEditText().check(matches(withText(exIntegerSecondValue)));
    onView(withText("Ex integer widget")).perform(swipeLeft());
}
Also used : Intent(android.content.Intent) RandomString(net.bytebuddy.utility.RandomString) ActivityResult(android.app.Instrumentation.ActivityResult)

Example 3 with ActivityResult

use of android.app.Instrumentation.ActivityResult in project collect by opendatakit.

the class AllWidgetsFormTest method testExDecimalWidget.

public void testExDecimalWidget() {
    // Manually input the value:
    String exDecimalFirstValue = randomDecimalString();
    when(activityAvailability.isActivityAvailable(any(Intent.class))).thenReturn(false);
    onView(withText("Launch")).perform(click());
    onVisibleEditText().perform(replaceText(exDecimalFirstValue));
    Screengrab.screenshot("ex-decimal");
    openWidgetList();
    onView(withText("Ex decimal widget")).perform(click());
    onVisibleEditText().check(matches(withText(exDecimalFirstValue)));
    // Replace with Intent value:
    String exDecimalSecondValue = randomDecimalString();
    Intent stringIntent = new Intent();
    stringIntent.putExtra("value", Double.parseDouble(exDecimalSecondValue));
    ActivityResult exStringResult = new ActivityResult(RESULT_OK, stringIntent);
    intending(allOf(hasAction("change.uw.android.BREATHCOUNT"), hasExtra("value", Double.parseDouble(exDecimalFirstValue)))).respondWith(exStringResult);
    when(activityAvailability.isActivityAvailable(any(Intent.class))).thenReturn(true);
    onView(withText("Launch")).perform(click());
    onView(withText(exDecimalSecondValue)).check(matches(isDisplayed()));
    Screengrab.screenshot("ex-decimal2");
    openWidgetList();
    onView(withText("Ex decimal widget")).perform(click());
    onVisibleEditText().check(matches(withText(exDecimalSecondValue)));
    onView(withText("Ex decimal widget")).perform(swipeLeft());
}
Also used : Intent(android.content.Intent) RandomString(net.bytebuddy.utility.RandomString) ActivityResult(android.app.Instrumentation.ActivityResult)

Example 4 with ActivityResult

use of android.app.Instrumentation.ActivityResult in project android_packages_apps_Settings by LineageOS.

the class FingerprintEnrollFinishTest method clickAddAnother_shouldLaunchEnrolling.

@Test
public void clickAddAnother_shouldLaunchEnrolling() {
    final ComponentName enrollingComponent = new ComponentName(getTargetContext(), FingerprintEnrollEnrolling.class);
    intending(hasComponent(enrollingComponent)).respondWith(new ActivityResult(Activity.RESULT_CANCELED, null));
    onView(withId(R.id.add_another_button)).perform(click());
    intended(hasComponent(enrollingComponent));
    assertFalse(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 5 with ActivityResult

use of android.app.Instrumentation.ActivityResult in project android_packages_apps_Settings by LineageOS.

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)

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