Search in sources :

Example 1 with ProducerContext

use of com.facebook.imagepipeline.producers.ProducerContext in project fresco by facebook.

the class ImagePipelineTest method testFetchNetworkEncodedImage.

@Test
public void testFetchNetworkEncodedImage() {
    Producer<CloseableReference<PooledByteBuffer>> encodedSequence = mock(Producer.class);
    when(mProducerSequenceFactory.getEncodedImageProducerSequence(mImageRequest)).thenReturn(encodedSequence);
    when(mImageRequest.getSourceUri()).thenReturn(Uri.parse("http://test"));
    DataSource<CloseableReference<PooledByteBuffer>> dataSource = mImagePipeline.fetchEncodedImage(mImageRequest, mCallerContext);
    assertFalse(dataSource.isFinished());
    ArgumentCaptor<ImageRequest> argumentCaptor = ArgumentCaptor.forClass(ImageRequest.class);
    verify(mRequestListener1).onRequestStart(argumentCaptor.capture(), eq(mCallerContext), eq("0"), eq(false));
    ImageRequest capturedImageRequest = argumentCaptor.getValue();
    assertSame(mImageRequest.getSourceUri(), capturedImageRequest.getSourceUri());
    verify(mRequestListener2).onRequestStart(argumentCaptor.capture(), eq(mCallerContext), eq("0"), eq(false));
    capturedImageRequest = argumentCaptor.getValue();
    assertSame(mImageRequest.getSourceUri(), capturedImageRequest.getSourceUri());
    ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class);
    verify(encodedSequence).produceResults(any(Consumer.class), producerContextArgumentCaptor.capture());
    assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected());
    assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH);
}
Also used : Consumer(com.facebook.imagepipeline.producers.Consumer) ProducerContext(com.facebook.imagepipeline.producers.ProducerContext) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) Test(org.junit.Test)

Example 2 with ProducerContext

use of com.facebook.imagepipeline.producers.ProducerContext in project fresco by facebook.

the class ImagePipelineTest method testFetchLocalEncodedImage.

@Test
public void testFetchLocalEncodedImage() {
    Producer<CloseableReference<PooledByteBuffer>> encodedSequence = mock(Producer.class);
    when(mProducerSequenceFactory.getEncodedImageProducerSequence(mImageRequest)).thenReturn(encodedSequence);
    when(mImageRequest.getSourceUri()).thenReturn(Uri.parse("file:///local/file"));
    DataSource<CloseableReference<PooledByteBuffer>> dataSource = mImagePipeline.fetchEncodedImage(mImageRequest, mCallerContext);
    assertFalse(dataSource.isFinished());
    ArgumentCaptor<ImageRequest> argumentCaptor = ArgumentCaptor.forClass(ImageRequest.class);
    verify(mRequestListener1).onRequestStart(argumentCaptor.capture(), eq(mCallerContext), eq("0"), eq(false));
    ImageRequest capturedImageRequest = argumentCaptor.getValue();
    assertSame(mImageRequest.getSourceUri(), capturedImageRequest.getSourceUri());
    verify(mRequestListener2).onRequestStart(argumentCaptor.capture(), eq(mCallerContext), eq("0"), eq(false));
    capturedImageRequest = argumentCaptor.getValue();
    assertSame(mImageRequest.getSourceUri(), capturedImageRequest.getSourceUri());
    ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class);
    verify(encodedSequence).produceResults(any(Consumer.class), producerContextArgumentCaptor.capture());
    assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected());
    assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH);
}
Also used : Consumer(com.facebook.imagepipeline.producers.Consumer) ProducerContext(com.facebook.imagepipeline.producers.ProducerContext) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) Test(org.junit.Test)

Aggregations

CloseableReference (com.facebook.common.references.CloseableReference)2 Consumer (com.facebook.imagepipeline.producers.Consumer)2 ProducerContext (com.facebook.imagepipeline.producers.ProducerContext)2 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)2 Test (org.junit.Test)2