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);
}
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);
}
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);
}
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));
}
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();
}
Aggregations