Search in sources :

Example 1 with CronetDataSource

use of com.google.android.exoplayer2.ext.cronet.CronetDataSource in project ExoPlayer by google.

the class CronetDataSourceTest method testRedirectParseAndAttachCookie_dataSourceHandlesSetCookie_andPreservesOriginalRequestHeadersIncludingByteRangeHeader.

@Test
public void testRedirectParseAndAttachCookie_dataSourceHandlesSetCookie_andPreservesOriginalRequestHeadersIncludingByteRangeHeader() throws HttpDataSourceException {
    testDataSpec = new DataSpec(Uri.parse(TEST_URL), 1000, 5000);
    dataSourceUnderTest = (CronetDataSource) new CronetDataSource.Factory(mockCronetEngine, executorService).setConnectionTimeoutMs(TEST_CONNECT_TIMEOUT_MS).setReadTimeoutMs(TEST_READ_TIMEOUT_MS).setResetTimeoutOnRedirects(true).setHandleSetCookieRequests(true).createDataSource();
    dataSourceUnderTest.addTransferListener(mockTransferListener);
    dataSourceUnderTest.setRequestProperty("Content-Type", TEST_CONTENT_TYPE);
    mockSingleRedirectSuccess(/*responseCode=*/
    300);
    mockReadSuccess(0, 1000);
    testResponseHeader.put("Set-Cookie", "testcookie=testcookie; Path=/video");
    dataSourceUnderTest.open(testDataSpec);
    verify(mockUrlRequestBuilder).addHeader(eq("Cookie"), any(String.class));
    verify(mockUrlRequestBuilder, times(2)).addHeader("Range", "bytes=1000-5999");
    verify(mockUrlRequestBuilder, times(2)).addHeader("Content-Type", TEST_CONTENT_TYPE);
    verify(mockUrlRequest, never()).followRedirect();
    verify(mockUrlRequest, times(2)).start();
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with CronetDataSource

use of com.google.android.exoplayer2.ext.cronet.CronetDataSource in project ExoPlayer by google.

the class CronetDataSourceTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    Map<String, String> defaultRequestProperties = new HashMap<>();
    defaultRequestProperties.put("defaultHeader1", "defaultValue1");
    defaultRequestProperties.put("defaultHeader2", "defaultValue2");
    executorService = Executors.newSingleThreadExecutor();
    dataSourceUnderTest = (CronetDataSource) new CronetDataSource.Factory(mockCronetEngine, executorService).setConnectionTimeoutMs(TEST_CONNECT_TIMEOUT_MS).setReadTimeoutMs(TEST_READ_TIMEOUT_MS).setResetTimeoutOnRedirects(true).setDefaultRequestProperties(defaultRequestProperties).createDataSource();
    dataSourceUnderTest.addTransferListener(mockTransferListener);
    when(mockCronetEngine.newUrlRequestBuilder(anyString(), any(UrlRequest.Callback.class), any(Executor.class))).thenReturn(mockUrlRequestBuilder);
    when(mockUrlRequestBuilder.setPriority(anyInt())).thenReturn(mockUrlRequestBuilder);
    when(mockUrlRequestBuilder.allowDirectExecutor()).thenReturn(mockUrlRequestBuilder);
    when(mockUrlRequestBuilder.build()).thenReturn(mockUrlRequest);
    mockStatusResponse();
    testDataSpec = new DataSpec(Uri.parse(TEST_URL));
    testPostDataSpec = new DataSpec.Builder().setUri(TEST_URL).setHttpMethod(DataSpec.HTTP_METHOD_POST).setHttpBody(TEST_POST_BODY).build();
    testHeadDataSpec = new DataSpec.Builder().setUri(TEST_URL).setHttpMethod(DataSpec.HTTP_METHOD_HEAD).build();
    testResponseHeader = new HashMap<>();
    testResponseHeader.put("Content-Type", TEST_CONTENT_TYPE);
    // This value can be anything since the DataSpec is unset.
    testResponseHeader.put("Content-Length", Long.toString(TEST_CONTENT_LENGTH));
    // statusCode
    testUrlResponseInfo = createUrlResponseInfo(200);
}
Also used : Executor(java.util.concurrent.Executor) HashMap(java.util.HashMap) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Before(org.junit.Before)

Aggregations

DataSpec (com.google.android.exoplayer2.upstream.DataSpec)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 HashMap (java.util.HashMap)1 Executor (java.util.concurrent.Executor)1 Before (org.junit.Before)1 Test (org.junit.Test)1