Search in sources :

Example 1 with UrlRequest

use of org.chromium.net.UrlRequest in project ExoPlayer by google.

the class CronetDataSourceTest method testCallbackFromPreviousRequest.

@Test
public void testCallbackFromPreviousRequest() throws HttpDataSourceException {
    mockResponseStartSuccess();
    dataSourceUnderTest.open(testDataSpec);
    dataSourceUnderTest.close();
    // Prepare a mock UrlRequest to be used in the second open() call.
    final UrlRequest mockUrlRequest2 = mock(UrlRequest.class);
    when(mockUrlRequestBuilder.build()).thenReturn(mockUrlRequest2);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            // Invoke the callback for the previous request.
            dataSourceUnderTest.onFailed(mockUrlRequest, testUrlResponseInfo, mockNetworkException);
            dataSourceUnderTest.onResponseStarted(mockUrlRequest2, testUrlResponseInfo);
            return null;
        }
    }).when(mockUrlRequest2).start();
    dataSourceUnderTest.open(testDataSpec);
}
Also used : UrlRequest(org.chromium.net.UrlRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Example 2 with UrlRequest

use of org.chromium.net.UrlRequest in project ExoPlayer by google.

the class CronetDataSource method getStatus.

private static int getStatus(UrlRequest request) {
    final ConditionVariable conditionVariable = new ConditionVariable();
    final int[] statusHolder = new int[1];
    request.getStatus(new UrlRequest.StatusListener() {

        @Override
        public void onStatus(int status) {
            statusHolder[0] = status;
            conditionVariable.open();
        }
    });
    conditionVariable.block();
    return statusHolder[0];
}
Also used : ConditionVariable(android.os.ConditionVariable) UrlRequest(org.chromium.net.UrlRequest)

Aggregations

UrlRequest (org.chromium.net.UrlRequest)2 ConditionVariable (android.os.ConditionVariable)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1