mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
DataSourceContractTest: Add tests for resolved vs original URI
PiperOrigin-RevId: 688076205
(cherry picked from commit 74bbd7727d)
This commit is contained in:
parent
6f42f36c05
commit
ab4dff7530
4 changed files with 52 additions and 17 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
## 1.5.0-rc01 (2024-11-13)
|
## 1.5.0-rc01 (2024-11-13)
|
||||||
|
|
||||||
This release includes the following changes since the
|
This release includes the following changes since the
|
||||||
[1.5.0-beta01 release](#150-2024-10-30):
|
[1.5.0-beta01 release](#150-beta01-2024-10-30):
|
||||||
|
|
||||||
* Extractors:
|
* Extractors:
|
||||||
* Fix media duration parsing in `mdhd` box of MP4 files to handle `-1`
|
* Fix media duration parsing in `mdhd` box of MP4 files to handle `-1`
|
||||||
|
|
@ -27,7 +27,7 @@ This release includes the following changes since the
|
||||||
### 1.5.0-beta01 (2024-10-30)
|
### 1.5.0-beta01 (2024-10-30)
|
||||||
|
|
||||||
This release includes the following changes since the
|
This release includes the following changes since the
|
||||||
[1.5.0-alpha01 release](#150-2024-09-06):
|
[1.5.0-alpha01 release](#150-alpha01-2024-09-06):
|
||||||
|
|
||||||
* Common Library:
|
* Common Library:
|
||||||
* Remove `@DoNotInline` annotations from manually out-of-lined inner
|
* Remove `@DoNotInline` annotations from manually out-of-lined inner
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ public class ResolvingDataSourceContractTest extends DataSourceContractTest {
|
||||||
new TestResource.Builder()
|
new TestResource.Builder()
|
||||||
.setName("simple")
|
.setName("simple")
|
||||||
.setUri(URI)
|
.setUri(URI)
|
||||||
|
.setResolvedUri(RESOLVED_URI)
|
||||||
.setExpectedBytes(simpleData)
|
.setExpectedBytes(simpleData)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -540,7 +540,7 @@ public abstract class DataSourceContractTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getUri_returnsNonNullValueOnlyWhileOpen() throws Exception {
|
public void getUri_returnsExpectedValueOnlyWhileOpen() throws Exception {
|
||||||
forAllTestResourcesAndDataSources(
|
forAllTestResourcesAndDataSources(
|
||||||
(resource, dataSource) -> {
|
(resource, dataSource) -> {
|
||||||
try {
|
try {
|
||||||
|
|
@ -548,7 +548,7 @@ public abstract class DataSourceContractTest {
|
||||||
|
|
||||||
dataSource.open(new DataSpec(resource.getUri()));
|
dataSource.open(new DataSpec(resource.getUri()));
|
||||||
|
|
||||||
assertThat(dataSource.getUri()).isNotNull();
|
assertThat(dataSource.getUri()).isEqualTo(resource.getResolvedUri());
|
||||||
} finally {
|
} finally {
|
||||||
dataSource.close();
|
dataSource.close();
|
||||||
}
|
}
|
||||||
|
|
@ -740,11 +740,13 @@ public abstract class DataSourceContractTest {
|
||||||
|
|
||||||
@Nullable private final String name;
|
@Nullable private final String name;
|
||||||
private final Uri uri;
|
private final Uri uri;
|
||||||
|
private final Uri resolvedUri;
|
||||||
private final byte[] expectedBytes;
|
private final byte[] expectedBytes;
|
||||||
|
|
||||||
private TestResource(@Nullable String name, Uri uri, byte[] expectedBytes) {
|
private TestResource(@Nullable String name, Uri uri, Uri resolvedUri, byte[] expectedBytes) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
|
this.resolvedUri = resolvedUri;
|
||||||
this.expectedBytes = expectedBytes;
|
this.expectedBytes = expectedBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -754,11 +756,19 @@ public abstract class DataSourceContractTest {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the URI where the resource is available. */
|
/** Returns the URI where the resource should be requested from. */
|
||||||
public Uri getUri() {
|
public Uri getUri() {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the URI where the resource is served from. This is equal to {@link #getUri()} unless
|
||||||
|
* redirection occurred when opening the resource.
|
||||||
|
*/
|
||||||
|
public Uri getResolvedUri() {
|
||||||
|
return resolvedUri;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns the expected contents of this resource. */
|
/** Returns the expected contents of this resource. */
|
||||||
public byte[] getExpectedBytes() {
|
public byte[] getExpectedBytes() {
|
||||||
return expectedBytes;
|
return expectedBytes;
|
||||||
|
|
@ -768,6 +778,7 @@ public abstract class DataSourceContractTest {
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
private @MonotonicNonNull String name;
|
private @MonotonicNonNull String name;
|
||||||
private @MonotonicNonNull Uri uri;
|
private @MonotonicNonNull Uri uri;
|
||||||
|
private @MonotonicNonNull Uri resolvedUri;
|
||||||
private byte @MonotonicNonNull [] expectedBytes;
|
private byte @MonotonicNonNull [] expectedBytes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -779,19 +790,38 @@ public abstract class DataSourceContractTest {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the URI where this resource is located. */
|
/** Sets the URI where this resource should be requested from. */
|
||||||
@CanIgnoreReturnValue
|
@CanIgnoreReturnValue
|
||||||
public Builder setUri(String uri) {
|
public Builder setUri(String uri) {
|
||||||
return setUri(Uri.parse(uri));
|
return setUri(Uri.parse(uri));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the URI where this resource is located. */
|
/** Sets the URI where this resource should be requested from. */
|
||||||
@CanIgnoreReturnValue
|
@CanIgnoreReturnValue
|
||||||
public Builder setUri(Uri uri) {
|
public Builder setUri(Uri uri) {
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the URI where this resource is served from. This only needs to be explicitly set if
|
||||||
|
* it's different to {@link #setUri(Uri)}. See {@link #getResolvedUri()}.
|
||||||
|
*/
|
||||||
|
@CanIgnoreReturnValue
|
||||||
|
public Builder setResolvedUri(String uri) {
|
||||||
|
return setResolvedUri(Uri.parse(uri));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the URI where this resource is served from. This only needs to be explicitly set if
|
||||||
|
* it's different to {@link #setUri(Uri)}. See {@link #getResolvedUri()}.
|
||||||
|
*/
|
||||||
|
@CanIgnoreReturnValue
|
||||||
|
public Builder setResolvedUri(Uri uri) {
|
||||||
|
this.resolvedUri = uri;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the expected contents of this resource.
|
* Sets the expected contents of this resource.
|
||||||
*
|
*
|
||||||
|
|
@ -805,7 +835,11 @@ public abstract class DataSourceContractTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestResource build() {
|
public TestResource build() {
|
||||||
return new TestResource(name, checkNotNull(uri), checkNotNull(expectedBytes));
|
return new TestResource(
|
||||||
|
name,
|
||||||
|
checkNotNull(uri),
|
||||||
|
resolvedUri != null ? resolvedUri : uri,
|
||||||
|
checkNotNull(expectedBytes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,8 +93,13 @@ public class HttpDataSourceTestEnv extends ExternalResource {
|
||||||
"range not supported, length unknown", RANGE_NOT_SUPPORTED_LENGTH_UNKNOWN),
|
"range not supported, length unknown", RANGE_NOT_SUPPORTED_LENGTH_UNKNOWN),
|
||||||
createTestResource("gzip enabled", GZIP_ENABLED),
|
createTestResource("gzip enabled", GZIP_ENABLED),
|
||||||
createTestResource("gzip forced", GZIP_FORCED),
|
createTestResource("gzip forced", GZIP_FORCED),
|
||||||
createTestResource(
|
new DataSourceContractTest.TestResource.Builder()
|
||||||
"302 redirect", REDIRECTS_TO_RANGE_SUPPORTED, /* server= */ redirectionServer));
|
.setName("302 redirect")
|
||||||
|
.setUri(
|
||||||
|
Uri.parse(redirectionServer.url(REDIRECTS_TO_RANGE_SUPPORTED.getPath()).toString()))
|
||||||
|
.setResolvedUri(originServer.url(RANGE_SUPPORTED.getPath()).toString())
|
||||||
|
.setExpectedBytes(REDIRECTS_TO_RANGE_SUPPORTED.getData())
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNonexistentUrl() {
|
public String getNonexistentUrl() {
|
||||||
|
|
@ -142,14 +147,9 @@ public class HttpDataSourceTestEnv extends ExternalResource {
|
||||||
|
|
||||||
private DataSourceContractTest.TestResource createTestResource(
|
private DataSourceContractTest.TestResource createTestResource(
|
||||||
String name, WebServerDispatcher.Resource resource) {
|
String name, WebServerDispatcher.Resource resource) {
|
||||||
return createTestResource(name, resource, originServer);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DataSourceContractTest.TestResource createTestResource(
|
|
||||||
String name, WebServerDispatcher.Resource resource, MockWebServer server) {
|
|
||||||
return new DataSourceContractTest.TestResource.Builder()
|
return new DataSourceContractTest.TestResource.Builder()
|
||||||
.setName(name)
|
.setName(name)
|
||||||
.setUri(Uri.parse(server.url(resource.getPath()).toString()))
|
.setUri(Uri.parse(originServer.url(resource.getPath()).toString()))
|
||||||
.setExpectedBytes(resource.getData())
|
.setExpectedBytes(resource.getData())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue