Java 类android.app.Instrumentation.ActivityResult 实例源码

项目:Red-Calorie    文件:AddIngredientActivityTest.java   
@Before
public void onSetUp() {
    CaloriesCounterApplication applicationContext = (CaloriesCounterApplication) getTargetContext()
            .getApplicationContext();
    ApplicationTestComponent component = (ApplicationTestComponent) applicationContext.getComponent();
    TagDao tagDao = component.getDaoSession().getTagDao();
    tagDao.deleteAll();
    tagDao.insertInTx(exampleTags);
    assertEquals(3, tagDao.loadAll().size());

    main.launchActivity(new Intent(AddIngredientType.DRINK.getAction()));

    // By default Espresso Intents does not stub any Intents. Stubbing needs to be setup before
    // every test run. In this case all external Intents will be blocked.
    intending(not(isInternal())).respondWith(new ActivityResult(Activity.RESULT_OK, null));
}
项目:Red-Calorie    文件:AddIngredientActivityTest.java   
@Test
public void testSelectImageFromGallery() {
    Intent intent = new Intent();
    intent.setData(resourceToUri(getContext(), android.R.drawable.ic_input_add));
    intending(galleryIntentMatcher).respondWith(new ActivityResult(Activity.RESULT_OK, intent));
    RxImageLoadingIdlingResource rxImageLoadingIdlingResource = RxImageLoadingIdlingResource.registerAndGet();
    onView(withId(R.id.image_header_image_view)).check(matches(isDisplayed()))
            .perform(click());
    PermissionHelper.allowPermissionsIfNeeded();
    onView(withText(R.string.add_ingredient_image_select_from_camera))
            .check(matches(isDisplayed()));
    onView(withText(R.string.add_ingredient_image_select_title))
            .check(matches(isDisplayed()));
    onView(withText(R.string.add_ingredient_image_select_from_gallery))
            .check(matches(isDisplayed()))
            .perform(click());
    intended(galleryIntentMatcher);
    onView(withId(R.id.image_header_image_view))
            .check(matches(isDisplayed()))
            .check(matches(withDrawable(any(BitmapDrawable.class))));
    rxImageLoadingIdlingResource.unregister();
}
项目:Red-Calorie    文件:AddIngredientActivityTest.java   
@Test
public void testSelectImageFromCamera() throws Exception {
    AddIngredientActivity activity = main.getActivity();
    final Uri uri = resourceToUri(activity, android.R.drawable.ic_input_add);
    final Matcher<Intent> cameraIntentMatcher = allOf(
            hasAction(MediaStore.ACTION_IMAGE_CAPTURE),
            injectUriOnMatch(activity, uri)
    );

    intending(cameraIntentMatcher).respondWith(new ActivityResult(Activity.RESULT_OK, null));
    RxImageLoadingIdlingResource rxImageLoadingIdlingResource = RxImageLoadingIdlingResource.registerAndGet();
    onView(withId(R.id.image_header_image_view)).check(matches(isDisplayed()))
            .perform(click());
    PermissionHelper.allowPermissionsIfNeeded();
    onView(withText(R.string.add_ingredient_image_select_from_camera))
            .check(matches(isDisplayed()))
            .perform(click());
    intended(cameraIntentMatcher);
    onView(withId(R.id.image_header_image_view))
            .check(matches(isDisplayed()))
            .check(matches(withDrawable(any(BitmapDrawable.class))));
    rxImageLoadingIdlingResource.unregister();
}
项目:Red-Calorie    文件:AddMealActivityTest.java   
@Test
public void testSelectImageFromGallery() {
    onView(withId(R.id.add_meal_name)).perform(closeSoftKeyboard());
    Intent intent = new Intent();
    intent.setData(TestPicturePicker.resourceToUri(getContext(), android.R.drawable.ic_input_add));
    intending(galleryIntentMatcher).respondWith(new ActivityResult(Activity.RESULT_OK, intent));
    RxImageLoadingIdlingResource rxImageLoadingIdlingResource = RxImageLoadingIdlingResource.registerAndGet();
    onView(withId(R.id.image_header_image_view)).check(matches(isDisplayed()))
            .perform(click());
    PermissionHelper.allowPermissionsIfNeeded();
    onView(withText(R.string.add_meal_image_select_from_camera))
            .check(matches(isDisplayed()));
    onView(withText(R.string.add_meal_image_select_title))
            .check(matches(isDisplayed()));
    onView(withText(R.string.add_meal_image_select_from_gallery))
            .check(matches(isDisplayed()))
            .perform(click());
    intended(galleryIntentMatcher);
    onView(withId(R.id.image_header_image_view))
            .check(matches(isDisplayed()))
            .check(matches(withDrawable(any(BitmapDrawable.class))));
    rxImageLoadingIdlingResource.unregister();
}
项目:Red-Calorie    文件:AddMealActivityTest.java   
@Test
public void testSelectImageFromCamera() {
    onView(withId(R.id.add_meal_name)).perform(closeSoftKeyboard());
    AddMealActivity activity = main.getActivity();
    final Uri uri = TestPicturePicker.resourceToUri(activity, android.R.drawable.ic_input_add);
    final Matcher<Intent> cameraIntentMatcher = allOf(
            hasAction(MediaStore.ACTION_IMAGE_CAPTURE),
            injectUriOnMatch(activity, uri)
    );
    intending(cameraIntentMatcher).respondWith(new ActivityResult(Activity.RESULT_OK, null));
    RxImageLoadingIdlingResource rxImageLoadingIdlingResource = RxImageLoadingIdlingResource.registerAndGet();
    onView(withId(R.id.image_header_image_view)).check(matches(isDisplayed()))
            .perform(click());
    PermissionHelper.allowPermissionsIfNeeded();
    onView(withText(R.string.add_meal_image_select_from_camera))
            .check(matches(isDisplayed()))
            .perform(click());
    intended(cameraIntentMatcher);
    onView(withId(R.id.image_header_image_view))
            .check(matches(isDisplayed()))
            .check(matches(withDrawable(any(BitmapDrawable.class))));
    rxImageLoadingIdlingResource.unregister();
}
项目:FlightSearch    文件:SearchFlightsTest.java   
@Test
public void testOriginResultOk() {
    // Build a result to return when a particular AutocompleteActivity is launched.
    Intent resultData = new Intent();
    resultData.putExtra(AutocompleteActivity.AIRPORT_CODE_EXTRA, "DEN");
    ActivityResult activityResult = new ActivityResult(Activity.RESULT_OK, resultData);

    // Set up result stubbing when an intent sent to AutocompleteActivity is seen.
    intending(hasComponent(AutocompleteActivity.class.getName())).respondWith(activityResult);

    // Launching AutocompleteActivity expects airport code to be returned and displays it on the screen.
    onView(withId(R.id.originTextView)).perform(click());

    // test result
    onView(withId(R.id.originTextView)).check(matches(withText("DEN")));
}
项目:FlightSearch    文件:SearchFlightsTest.java   
@Test
public void testOriginResultCanceled() {
    // Build a result to return when a particular AutocompleteActivity is launched.
    Intent resultData = new Intent();
    resultData.putExtra(AutocompleteActivity.AIRPORT_CODE_EXTRA, "DEN");
    ActivityResult activityResult = new ActivityResult(Activity.RESULT_CANCELED, resultData);

    // Set up result stubbing when an intent sent to AutocompleteActivity is seen.
    intending(hasComponent(AutocompleteActivity.class.getName())).respondWith(activityResult);

    // Launching AutocompleteActivity expects airport code to be returned and displays it on the screen.
    onView(withId(R.id.originTextView)).perform(click());

    // test result
    onView(withId(R.id.originTextView)).check(matches(withText("")));
}
项目:FlightSearch    文件:SearchFlightsTest.java   
@Test
public void testDestinationResultOK() {
    // Build a result to return when a particular AutocompleteActivity is launched.
    Intent resultData = new Intent();
    resultData.putExtra(AutocompleteActivity.AIRPORT_CODE_EXTRA, "LAX");
    ActivityResult activityResult = new ActivityResult(Activity.RESULT_OK, resultData);

    // Set up result stubbing when an intent sent to AutocompleteActivity is seen.
    intending(hasComponent(AutocompleteActivity.class.getName())).respondWith(activityResult);

    // Launching AutocompleteActivity expects airport code to be returned and displays it on the screen.
    onView(withId(R.id.destinationTextView)).perform(click());

    // test result
    onView(withId(R.id.destinationTextView)).check(matches(withText("LAX")));
}
项目:FlightSearch    文件:SearchFlightsTest.java   
@Test
public void testDestinationResultCanceled() {
    // Build a result to return when a particular AutocompleteActivity is launched.
    Intent resultData = new Intent();
    resultData.putExtra(AutocompleteActivity.AIRPORT_CODE_EXTRA, "LAX");
    ActivityResult activityResult = new ActivityResult(Activity.RESULT_CANCELED, resultData);

    // Set up result stubbing when an intent sent to AutocompleteActivity is seen.
    intending(hasComponent(AutocompleteActivity.class.getName())).respondWith(activityResult);

    // Launching AutocompleteActivity expects airport code to be returned and displays it on the screen.
    onView(withId(R.id.destinationTextView)).perform(click());

    // test result
    onView(withId(R.id.destinationTextView)).check(matches(withText("")));
}
项目:friendspell    文件:MainActivityTest.java   
@Test
public void signIn() {
  setupGoogleApiClientBridge(googleApiClientBridge, false);

  Activity activity = activityRule.launchActivity(null);

  ActivityResult result = createSignInResult();
  intending(hasAction("com.google.android.gms.auth.GOOGLE_SIGN_IN")).respondWith(result);

  onView(withId(R.id.signed_out_pane))
      .check(matches(isDisplayed()));
  TestUtil.matchToolbarTitle(activity.getString(R.string.app_name));

  onView(withId(R.id.sign_in_button))
      .perform(click());

  onView(withId(R.id.signed_out_pane))
      .check(matches(not(isDisplayed())));
  TestUtil.matchToolbarTitle(activity.getString(R.string.title_word_sets));

  Mockito.verify(googleApiClientBridge, Mockito.times(2)).isSignedIn();
}
项目:androidtestdebug    文件:AddNoteScreenTest.java   
@Test
public void addImageToNote_ShowsThumbnailInUi() {
    // Create an Activity Result which can be used to stub the camera Intent
    ActivityResult result = createImageCaptureActivityResultStub();
    // If there is an Intent with ACTION_IMAGE_CAPTURE, intercept the Intent and respond with
    // a stubbed result.
    intending(hasAction(MediaStore.ACTION_IMAGE_CAPTURE)).respondWith(result);

    // Check thumbnail view is not displayed
    onView(withId(R.id.add_note_image_thumbnail)).check(matches(not(isDisplayed())));

    selectTakeImageFromMenu();

    // Check that the stubbed thumbnail is displayed in the UI
    onView(withId(R.id.add_note_image_thumbnail))
            .perform(scrollTo()) // Scroll to thumbnail
            .check(matches(allOf(
                    hasDrawable(), // Check ImageView has a drawable set with a custom matcher
                    isDisplayed())));
}
项目:androidtestdebug    文件:AddNoteScreenTest.java   
@Test
public void addImageToNote_ShowsThumbnailInUi() {
    // Create an Activity Result which can be used to stub the camera Intent
    ActivityResult result = createImageCaptureActivityResultStub();
    // If there is an Intent with ACTION_IMAGE_CAPTURE, intercept the Intent and respond with
    // a stubbed result.
    intending(hasAction(MediaStore.ACTION_IMAGE_CAPTURE)).respondWith(result);

    // Check thumbnail view is not displayed
    onView(withId(R.id.add_note_image_thumbnail)).check(matches(not(isDisplayed())));

    selectTakeImageFromMenu();

    // Check that the stubbed thumbnail is displayed in the UI
    onView(withId(R.id.add_note_image_thumbnail))
            .perform(scrollTo()) // Scroll to thumbnail
            .check(matches(allOf(
                    hasDrawable(), // Check ImageView has a drawable set with a custom matcher
                    isDisplayed())));
}
项目:Red-Calorie    文件:AddIngredientActivityTest.java   
@Test
public void testSelectImageFromGalleryUserCanceled() {
    intending(galleryIntentMatcher).respondWith(new ActivityResult(Activity.RESULT_CANCELED, null));
    onView(withId(R.id.image_header_image_view)).check(matches(isDisplayed()))
            .perform(click());
    PermissionHelper.allowPermissionsIfNeeded();
    onView(withText(R.string.add_ingredient_image_select_from_gallery))
            .check(matches(isDisplayed()))
            .perform(click());
    intended(galleryIntentMatcher);
    //If doesn't crash is good
}
项目:Red-Calorie    文件:AddIngredientActivityTest.java   
@Test
public void testSelectImageFromCameraUserCanceled() {
    final Matcher<Intent> cameraIntentMatcher = hasAction(MediaStore.ACTION_IMAGE_CAPTURE);
    intending(cameraIntentMatcher).respondWith(new ActivityResult(Activity.RESULT_CANCELED, null));
    onView(withId(R.id.image_header_image_view)).check(matches(isDisplayed()))
            .perform(click());
    PermissionHelper.allowPermissionsIfNeeded();
    onView(withText(R.string.add_ingredient_image_select_from_camera))
            .check(matches(isDisplayed()))
            .perform(click());
    intended(cameraIntentMatcher);
    //If doesn't crash is good
}
项目:Red-Calorie    文件:AddIngredientActivityTest.java   
@Test
public void testSearchIngredientOnTheInternet() throws Exception {
    onView(withHint(R.string.add_ingredient_name_hint)).perform(typeTextIntoFocusedView("Eggs"));
    closeSoftKeyboard();
    onView(withId(R.id.add_ingredient_name_search)).perform(click());
    Matcher<Intent> intentMatcher = allOf(hasAction(Intent.ACTION_VIEW),
            hasData("https://google.com/search?q=Eggs+calories"));
    intending(intentMatcher).respondWith(new ActivityResult(Activity.RESULT_CANCELED, null));
    intended(intentMatcher);
}
项目:Red-Calorie    文件:AddMealActivityTest.java   
@Before
public void onSetUp() {
    // By default Espresso Intents does not stub any Intents. Stubbing needs to be setup before
    // every test run. In this case all external Intents will be blocked.
    intending(not(isInternal())).respondWith(new ActivityResult(Activity.RESULT_OK, null));

    ApplicationTestComponent component = (ApplicationTestComponent) ((CaloriesCounterApplication) getTargetContext().getApplicationContext()).getComponent();
    DaoSession session = component.getDaoSession();
    IngredientActivityTest.addExampleIngredientsTagsAndJoin(session);
    session.getIngredientTemplateDao();
}
项目:Red-Calorie    文件:AddMealActivityTest.java   
@Test
public void testSelectImageFromGalleryUserCanceled() {
    intending(galleryIntentMatcher).respondWith(new ActivityResult(Activity.RESULT_CANCELED, null));
    onView(withId(R.id.image_header_image_view)).check(matches(isDisplayed()))
            .perform(click());
    PermissionHelper.allowPermissionsIfNeeded();
    onView(withText(R.string.add_meal_image_select_from_gallery))
            .check(matches(isDisplayed()))
            .perform(click());
    intended(galleryIntentMatcher);
    //If doesn't crash is good
}
项目:Red-Calorie    文件:AddMealActivityTest.java   
@Test
public void testSelectImageFromCameraUserCanceled() {
    onView(withId(R.id.add_meal_name)).perform(closeSoftKeyboard());
    final Matcher<Intent> cameraIntentMatcher = hasAction(MediaStore.ACTION_IMAGE_CAPTURE);
    intending(cameraIntentMatcher).respondWith(new ActivityResult(Activity.RESULT_CANCELED, null));
    onView(withId(R.id.image_header_image_view)).check(matches(isDisplayed()))
            .perform(click());
    PermissionHelper.allowPermissionsIfNeeded();
    onView(withText(R.string.add_meal_image_select_from_camera))
            .check(matches(isDisplayed()))
            .perform(click());
    intended(cameraIntentMatcher);
    //If doesn't crash is good
}
项目:ribot-app-android    文件:SignInActivityTest.java   
private void stubAccountPickerIntent() {
    // Stub the account picker using Espresso intents.
    // It requires the test devices to be signed in into at least 1 Google account.
    Intent data = new Intent();
    data.putExtra(AccountManager.KEY_ACCOUNT_NAME, mSelectedAccount.name);
    ActivityResult result = new ActivityResult(Activity.RESULT_OK, data);
    // The account picker intent is a bit special and it doesn't seem to have an Action or
    // package, so we have to match it by some of the extra keys.
    // This is not ideal but I couldn't find a better way.
    intending(hasExtraWithKey("allowableAccountTypes"))
            .respondWith(result);
}
项目:friendspell    文件:MainActivityTest.java   
private ActivityResult createSignInResult() {
  return new ActivityResult(Activity.RESULT_OK, null);
}
项目:AtlasForAndroid    文件:InstrumentationHook.java   
public ActivityResult execStartActivity() {
    return InstrumentationHook.this.mBase.execStartActivity(this.val$who, this.val$contextThread, this.val$token, this.val$target, this.val$intent, this.val$requestCode);
}
项目:AtlasForAndroid    文件:InstrumentationHook.java   
public ActivityResult execStartActivity() {
    return InstrumentationHook.this.mBase.execStartActivity(this.val$who, this.val$contextThread, this.val$token, this.val$target, this.val$intent, this.val$requestCode, this.val$options);
}
项目:AtlasForAndroid    文件:InstrumentationHook.java   
public ActivityResult execStartActivity() {
    return InstrumentationHook.this.mBase.execStartActivity(this.val$who, this.val$contextThread, this.val$token, this.val$target, this.val$intent, this.val$requestCode);
}
项目:AtlasForAndroid    文件:InstrumentationHook.java   
public ActivityResult execStartActivity() {
    return InstrumentationHook.this.mBase.execStartActivity(this.val$who, this.val$contextThread, this.val$token, this.val$target, this.val$intent, this.val$requestCode, this.val$options);
}
项目:AtlasForAndroid    文件:InstrumentationHook.java   
public ActivityResult execStartActivity(Context context, IBinder iBinder, IBinder iBinder2, Activity activity, Intent intent, int i) {
    return execStartActivityInternal(this.context, intent, new AnonymousClass_1(context, iBinder, iBinder2, activity, intent, i));
}
项目:AtlasForAndroid    文件:InstrumentationHook.java   
@TargetApi(16)
public ActivityResult execStartActivity(Context context, IBinder iBinder, IBinder iBinder2, Activity activity, Intent intent, int i, Bundle bundle) {
    return execStartActivityInternal(this.context, intent, new AnonymousClass_2(context, iBinder, iBinder2, activity, intent, i, bundle));
}
项目:AtlasForAndroid    文件:InstrumentationHook.java   
@TargetApi(14)
public ActivityResult execStartActivity(Context context, IBinder iBinder, IBinder iBinder2, Fragment fragment, Intent intent, int i) {
    return execStartActivityInternal(this.context, intent, new AnonymousClass_3(context, iBinder, iBinder2, fragment, intent, i));
}
项目:AtlasForAndroid    文件:InstrumentationHook.java   
@TargetApi(16)
public ActivityResult execStartActivity(Context context, IBinder iBinder, IBinder iBinder2, Fragment fragment, Intent intent, int i, Bundle bundle) {
    return execStartActivityInternal(this.context, intent, new AnonymousClass_4(context, iBinder, iBinder2, fragment, intent, i, bundle));
}
项目:AtlasForAndroid    文件:InstrumentationHook.java   
private ActivityResult execStartActivityInternal(Context context, Intent intent, ExecStartActivityCallback execStartActivityCallback) {
    String packageName;
    Object className;
    if (intent.getComponent() != null) {
        packageName = intent.getComponent().getPackageName();
        className = intent.getComponent().getClassName();
    } else {
        ResolveInfo resolveActivity = context.getPackageManager().resolveActivity(intent, 0);
        if (resolveActivity == null || resolveActivity.activityInfo == null) {
            className = null;
            packageName = null;
        } else {
            packageName = resolveActivity.activityInfo.packageName;
            className = resolveActivity.activityInfo.name;
        }
    }
    if (!StringUtils.equals(context.getPackageName(), packageName)) {
        return execStartActivityCallback.execStartActivity();
    }
    if (DelegateComponent.locateComponent(className) != null) {
        return execStartActivityCallback.execStartActivity();
    }
    try {
        if (ClassLoadFromBundle.loadFromUninstalledBundles(className) != null) {
            return execStartActivityCallback.execStartActivity();
        }
    } catch (ClassNotFoundException e) {
        log.info("Can't find class " + className + " in all bundles.");
    }
    try {
        if (Framework.getSystemClassLoader().loadClass(className) != null) {
            return execStartActivityCallback.execStartActivity();
        }
        return null;
    } catch (ClassNotFoundException e2) {
        log.error("Can't find class " + className);
        if (Framework.getClassNotFoundCallback() == null) {
            return null;
        }
        if (intent.getComponent() == null && !TextUtils.isEmpty(className)) {
            intent.setClassName(context, className);
        }
        if (intent.getComponent() == null) {
            return null;
        }
        Framework.getClassNotFoundCallback().returnIntent(intent);
        return null;
    }
}
项目:AtlasForAndroid    文件:InstrumentationHook.java   
public ActivityMonitor addMonitor(IntentFilter intentFilter, ActivityResult activityResult, boolean z) {
    return this.mBase.addMonitor(intentFilter, activityResult, z);
}
项目:AtlasForAndroid    文件:InstrumentationHook.java   
public ActivityMonitor addMonitor(String str, ActivityResult activityResult, boolean z) {
    return this.mBase.addMonitor(str, activityResult, z);
}
项目:androidtestdebug    文件:AddNoteScreenTest.java   
private ActivityResult createImageCaptureActivityResultStub() {
    // Create the ActivityResult, with a null Intent since we do not want to return any data
    // back to the Activity.
    return new ActivityResult(Activity.RESULT_OK, null);
}
项目:androidtestdebug    文件:AddNoteScreenTest.java   
private ActivityResult createImageCaptureActivityResultStub() {
    // Create the ActivityResult, with a null Intent since we do not want to return any data
    // back to the Activity.
    return new ActivityResult(Activity.RESULT_OK, null);
}
项目:android-test-kit    文件:IntentSpy.java   
/**
 * Returns the first matching stubbed result for the given activity if stubbed result was set by
 * test author using the {@link #setActivityResultForIntent(Matcher, ActivityResult)} method. The
 * method searches the list of existing matcher/response pairs in the order in which they were
 * entered. If no stubbed result matching the given intent is found, a default RESULT_OK result
 * with null data is returned.
 */
public ActivityResult getActivityResultForIntent(Intent intent);
项目:AtlasForAndroid    文件:InstrumentationHook.java   
ActivityResult execStartActivity();