Search in sources :

Example 26 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class BranchOnSeparateImagesProducerTest method testFirstProducerFails.

@Test
public void testFirstProducerFails() {
    mFirstProducerConsumer.onFailure(mException);
    verify(mConsumer, never()).onFailure(mException);
    EncodedImage finalEncodedImage = new EncodedImage(mIntermediateResult.getByteBufferRef());
    mSecondProducerConsumer.onNewResult(finalEncodedImage, true);
    verify(mConsumer).onNewResult(finalEncodedImage, true);
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 27 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class DecodeProducerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    mProgressiveJpegConfig = new SimpleProgressiveJpegConfig(new SimpleProgressiveJpegConfig.DynamicValueConfig() {

        public List<Integer> getScansToDecode() {
            return Arrays.asList(PREVIEW_SCAN, GOOD_ENOUGH_SCAN);
        }

        public int getGoodEnoughScanNumber() {
            return GOOD_ENOUGH_SCAN;
        }
    });
    PowerMockito.mockStatic(ProgressiveJpegParser.class);
    PowerMockito.whenNew(ProgressiveJpegParser.class).withAnyArguments().thenReturn(mProgressiveJpegParser);
    PowerMockito.mockStatic(JobScheduler.class);
    PowerMockito.whenNew(JobScheduler.class).withAnyArguments().thenReturn(mJobScheduler);
    mDecodeProducer = new DecodeProducer(mByteArrayPool, mExecutor, mImageDecoder, mProgressiveJpegConfig, false, /* Set downsampleEnabled to false */
    false, /* Set resizeAndRotateForNetwork to false */
    false, /* We don't cancel when the request is cancelled */
    mInputProducer);
    PooledByteBuffer pooledByteBuffer = mockPooledByteBuffer(IMAGE_SIZE);
    mByteBufferRef = CloseableReference.of(pooledByteBuffer);
    mEncodedImage = new EncodedImage(mByteBufferRef);
}
Also used : SimpleProgressiveJpegConfig(com.facebook.imagepipeline.decoder.SimpleProgressiveJpegConfig) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 28 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class DiskCacheWriteProducerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mDiskCacheWriteProducer = new DiskCacheWriteProducer(mInputProducer, mDiskCachePolicy);
    mForceSmallCacheProducer = new DiskCacheWriteProducer(mInputProducer, mDiskCachePolicy);
    List<CacheKey> keys = new ArrayList<>(1);
    keys.add(new SimpleCacheKey("http://dummy.uri"));
    mCacheKey = new MultiCacheKey(keys);
    mIntermediatePooledByteBuffer = mock(PooledByteBuffer.class);
    mFinalPooledByteBuffer = mock(PooledByteBuffer.class);
    mIntermediateImageReference = CloseableReference.of(mIntermediatePooledByteBuffer);
    mFinalImageReference = CloseableReference.of(mFinalPooledByteBuffer);
    mIntermediateEncodedImage = new EncodedImage(mIntermediateImageReference);
    mFinalEncodedImage = new EncodedImage(mFinalImageReference);
    mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mCallerContext, ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM);
    mLowestLevelProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mCallerContext, ImageRequest.RequestLevel.DISK_CACHE, false, true, Priority.MEDIUM);
    when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true);
    when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey);
    when(mImageRequest.getCacheChoice()).thenReturn(ImageRequest.CacheChoice.DEFAULT);
    when(mImageRequest.isDiskCacheEnabled()).thenReturn(true);
}
Also used : MultiCacheKey(com.facebook.cache.common.MultiCacheKey) ArrayList(java.util.ArrayList) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) CacheKey(com.facebook.cache.common.CacheKey) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey)

Example 29 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class MediaVariationsFallbackProducerTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    mMediaVariationsFallbackProducer = new MediaVariationsFallbackProducer(mDefaultBufferedDiskCache, mSmallImageBufferedDiskCache, mCacheKeyFactory, mMediaVariationsIndex, mMediaIdExtractor, mDiskCachePolicy, mInputProducer);
    mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mCallerContext, ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM);
    mMediaVariationsWithVariants = MediaVariations.newBuilderForMediaId(MEDIA_ID).addVariant(URI_S, SIZE_S, SIZE_S).addVariant(URI_M, SIZE_M, SIZE_M).addVariant(URI_L, SIZE_L, SIZE_L).build();
    mEmptyMediaVariations = MediaVariations.newBuilderForMediaId(MEDIA_ID).build();
    when(mImageRequest.getSourceUri()).thenReturn(URI_ORIGINAL);
    when(mImageRequest.getCacheChoice()).thenReturn(CacheChoice.DEFAULT);
    when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(SIZE_M, SIZE_M));
    when(mImageRequest.isDiskCacheEnabled()).thenReturn(true);
    when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true);
    when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(CACHE_KEY_ORIGINAL);
    when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, URI_S, mCallerContext)).thenReturn(CACHE_KEY_S);
    when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, URI_M, mCallerContext)).thenReturn(CACHE_KEY_M);
    when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, URI_L, mCallerContext)).thenReturn(CACHE_KEY_L);
    whenIndexDbContainsNoMatchingVariants();
    when(mMediaIdExtractor.getMediaIdFrom(any(Uri.class))).thenReturn(null);
    when(mDiskCachePolicy.getCacheChoiceForResult(any(ImageRequest.class), any(EncodedImage.class))).thenReturn(CacheChoice.DEFAULT);
    when(mDefaultBufferedDiskCache.get(any(CacheKey.class), any(AtomicBoolean.class))).thenReturn(Task.<EncodedImage>forResult(null));
    when(mSmallImageBufferedDiskCache.get(any(CacheKey.class), any(AtomicBoolean.class))).thenReturn(Task.<EncodedImage>forResult(null));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Uri(android.net.Uri) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) CacheKey(com.facebook.cache.common.CacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) Before(org.junit.Before)

Example 30 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class ThumbnailBranchProducerTest method testFinalProducerUsedIfFirstTwoReturnTooSmallImages.

@Test
public void testFinalProducerUsedIfFirstTwoReturnTooSmallImages() {
    int desiredWidth = THUMBNAIL_WIDTHS[0] - 50;
    int desiredHeight = THUMBNAIL_HEIGHTS[0] - 50;
    mockRequestWithResizeOptions(desiredWidth, desiredHeight);
    EncodedImage thirdImage = mockEncodedImage(THUMBNAIL_WIDTHS[2], THUMBNAIL_HEIGHTS[2], 0);
    mockProducersToProduce(mockEncodedImage(desiredWidth / 2, desiredHeight / 2, 0), mockEncodedImage(desiredWidth / 2, desiredHeight / 2, 0), thirdImage);
    mProducer.produceResults(mImageConsumer, mProducerContext);
    verify(mImageConsumer).onNewResult(thirdImage, true);
    verifyAllProducersRequestedForResults();
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Test(org.junit.Test)

Aggregations

EncodedImage (com.facebook.imagepipeline.image.EncodedImage)91 Test (org.junit.Test)24 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)19 CacheKey (com.facebook.cache.common.CacheKey)9 TrivialPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)9 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)9 InputStream (java.io.InputStream)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 Bitmap (android.graphics.Bitmap)7 SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)7 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)6 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)6 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)6 FakeClock (com.facebook.imagepipeline.testing.FakeClock)6 TestExecutorService (com.facebook.imagepipeline.testing.TestExecutorService)6 Before (org.junit.Before)6 Rect (android.graphics.Rect)5 MultiCacheKey (com.facebook.cache.common.MultiCacheKey)5 ArrayList (java.util.ArrayList)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5