mirror of
https://github.com/samsonjs/media.git
synced 2026-03-26 09:35:47 +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();
|
||||
Files.write(Paths.get(file.getAbsolutePath()), DATA);
|
||||
simpleUri = Uri.fromFile(file);
|
||||
fileDataSource = new FileDataSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -74,6 +73,7 @@ public class CacheDataSourceContractTest extends DataSourceContractTest {
|
|||
Util.createTempDirectory(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
|
||||
SimpleCache cache =
|
||||
new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
|
||||
fileDataSource = new 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
|
||||
* 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
|
||||
protected DataSource getTransferListenerDataSource() {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static com.google.android.exoplayer2.testutil.WebServerDispatcher.getRequestPath;
|
||||
|
||||
import android.net.Uri;
|
||||
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
|
@ -115,7 +117,7 @@ public class HttpDataSourceTestEnv extends ExternalResource {
|
|||
new Dispatcher() {
|
||||
@Override
|
||||
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()
|
||||
.setResponseCode(302)
|
||||
.setHeader("Location", originServer.url(RANGE_SUPPORTED.getPath()).toString());
|
||||
|
|
|
|||
|
|
@ -235,6 +235,11 @@ public class WebServerDispatcher extends Dispatcher {
|
|||
|
||||
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.
|
||||
*/
|
||||
|
|
@ -248,11 +253,12 @@ public class WebServerDispatcher extends Dispatcher {
|
|||
|
||||
@Override
|
||||
public MockResponse dispatch(RecordedRequest request) {
|
||||
String requestPath = getRequestPath(request);
|
||||
MockResponse response = new MockResponse();
|
||||
if (!resourcesByPath.containsKey(request.getPath())) {
|
||||
if (!resourcesByPath.containsKey(requestPath)) {
|
||||
return response.setResponseCode(404);
|
||||
}
|
||||
Resource resource = checkNotNull(resourcesByPath.get(request.getPath()));
|
||||
Resource resource = checkNotNull(resourcesByPath.get(requestPath));
|
||||
byte[] resourceData = resource.getData();
|
||||
if (resource.supportsRangeRequests()) {
|
||||
response.setHeader("Accept-ranges", "bytes");
|
||||
|
|
|
|||
Loading…
Reference in a new issue