mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add BandaidHttpDataSourceContractTest
Also fix a bug where BandaidHttpDataSource would pass -1 to TransferListener.onBytesTransferred! PiperOrigin-RevId: 359722821
This commit is contained in:
parent
b050391467
commit
c319220354
4 changed files with 14 additions and 5 deletions
|
|
@ -50,7 +50,6 @@ public class CacheDataSourceContractTest extends DataSourceContractTest {
|
||||||
File file = tempFolder.newFile();
|
File file = tempFolder.newFile();
|
||||||
Files.write(Paths.get(file.getAbsolutePath()), DATA);
|
Files.write(Paths.get(file.getAbsolutePath()), DATA);
|
||||||
simpleUri = Uri.fromFile(file);
|
simpleUri = Uri.fromFile(file);
|
||||||
fileDataSource = new FileDataSource();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -74,6 +73,7 @@ public class CacheDataSourceContractTest extends DataSourceContractTest {
|
||||||
Util.createTempDirectory(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
|
Util.createTempDirectory(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
|
||||||
SimpleCache cache =
|
SimpleCache cache =
|
||||||
new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
|
new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
|
||||||
|
fileDataSource = new FileDataSource();
|
||||||
return new CacheDataSource(cache, fileDataSource);
|
return new CacheDataSource(cache, fileDataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,8 @@ public abstract class DataSourceContractTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link DataSource} that will be included in the {@link TransferListener} callbacks
|
* Returns the {@link DataSource} that will be included in the {@link TransferListener} callbacks
|
||||||
* if different from the {@link DataSource} under test, otherwise null.
|
* for the {@link DataSource} most recently created by {@link #createDataSource()}. If it's the
|
||||||
|
* same {@link DataSource} then {@code null} can be returned.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected DataSource getTransferListenerDataSource() {
|
protected DataSource getTransferListenerDataSource() {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package com.google.android.exoplayer2.testutil;
|
package com.google.android.exoplayer2.testutil;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.testutil.WebServerDispatcher.getRequestPath;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
@ -115,7 +117,7 @@ public class HttpDataSourceTestEnv extends ExternalResource {
|
||||||
new Dispatcher() {
|
new Dispatcher() {
|
||||||
@Override
|
@Override
|
||||||
public MockResponse dispatch(RecordedRequest request) {
|
public MockResponse dispatch(RecordedRequest request) {
|
||||||
if (request.getPath().equals(REDIRECTS_TO_RANGE_SUPPORTED.getPath())) {
|
if (getRequestPath(request).equals(REDIRECTS_TO_RANGE_SUPPORTED.getPath())) {
|
||||||
return new MockResponse()
|
return new MockResponse()
|
||||||
.setResponseCode(302)
|
.setResponseCode(302)
|
||||||
.setHeader("Location", originServer.url(RANGE_SUPPORTED.getPath()).toString());
|
.setHeader("Location", originServer.url(RANGE_SUPPORTED.getPath()).toString());
|
||||||
|
|
|
||||||
|
|
@ -235,6 +235,11 @@ public class WebServerDispatcher extends Dispatcher {
|
||||||
|
|
||||||
private final ImmutableMap<String, Resource> resourcesByPath;
|
private final ImmutableMap<String, Resource> resourcesByPath;
|
||||||
|
|
||||||
|
/** Returns the path for a given {@link RecordedRequest}, stripping any query parameters. */
|
||||||
|
public static String getRequestPath(RecordedRequest request) {
|
||||||
|
return Util.splitAtFirst(request.getPath(), "\\?")[0];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a dispatcher that handles requests based the provided {@link Resource} instances.
|
* Constructs a dispatcher that handles requests based the provided {@link Resource} instances.
|
||||||
*/
|
*/
|
||||||
|
|
@ -248,11 +253,12 @@ public class WebServerDispatcher extends Dispatcher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MockResponse dispatch(RecordedRequest request) {
|
public MockResponse dispatch(RecordedRequest request) {
|
||||||
|
String requestPath = getRequestPath(request);
|
||||||
MockResponse response = new MockResponse();
|
MockResponse response = new MockResponse();
|
||||||
if (!resourcesByPath.containsKey(request.getPath())) {
|
if (!resourcesByPath.containsKey(requestPath)) {
|
||||||
return response.setResponseCode(404);
|
return response.setResponseCode(404);
|
||||||
}
|
}
|
||||||
Resource resource = checkNotNull(resourcesByPath.get(request.getPath()));
|
Resource resource = checkNotNull(resourcesByPath.get(requestPath));
|
||||||
byte[] resourceData = resource.getData();
|
byte[] resourceData = resource.getData();
|
||||||
if (resource.supportsRangeRequests()) {
|
if (resource.supportsRangeRequests()) {
|
||||||
response.setHeader("Accept-ranges", "bytes");
|
response.setHeader("Accept-ranges", "bytes");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue