Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ded68ed9
authored
Nov 10, 2021
by
ibaker
Committed by
Ian Baker
Nov 19, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add contract tests for DataSource#getResponseHeaders
PiperOrigin-RevId: 408840409
parent
d1e12dcd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
0 deletions
libraries/datasource/src/androidTest/java/androidx/media3/datasource/DefaultHttpDataSourceContractTest.java
libraries/test_utils/src/main/java/androidx/media3/test/utils/DataSourceContractTest.java
libraries/datasource/src/androidTest/java/androidx/media3/datasource/DefaultHttpDataSourceContractTest.java
View file @
ded68ed9
...
...
@@ -20,6 +20,7 @@ import androidx.media3.test.utils.DataSourceContractTest;
import
androidx.media3.test.utils.HttpDataSourceTestEnv
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.common.collect.ImmutableList
;
import
org.junit.Ignore
;
import
org.junit.Rule
;
import
org.junit.runner.RunWith
;
...
...
@@ -43,4 +44,8 @@ public class DefaultHttpDataSourceContractTest extends DataSourceContractTest {
protected
Uri
getNotFoundUri
()
{
return
Uri
.
parse
(
httpDataSourceTestEnv
.
getNonexistentUrl
());
}
@Override
@Ignore
(
"internal b/205811776"
)
public
void
getResponseHeaders_noNullKeysOrValues
()
{}
}
libraries/test_utils/src/main/java/androidx/media3/test/utils/DataSourceContractTest.java
View file @
ded68ed9
...
...
@@ -19,6 +19,7 @@ import static androidx.media3.common.util.Assertions.checkArgument;
import
static
androidx
.
media3
.
common
.
util
.
Assertions
.
checkNotNull
;
import
static
androidx
.
media3
.
common
.
util
.
Util
.
castNonNull
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertWithMessage
;
import
static
org
.
junit
.
Assert
.
assertThrows
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyBoolean
;
...
...
@@ -40,10 +41,12 @@ import androidx.media3.datasource.DataSourceException;
import
androidx.media3.datasource.DataSourceUtil
;
import
androidx.media3.datasource.DataSpec
;
import
androidx.media3.datasource.TransferListener
;
import
com.google.common.base.Ascii
;
import
com.google.common.collect.ImmutableList
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
org.checkerframework.checker.nullness.qual.MonotonicNonNull
;
import
org.junit.Ignore
;
import
org.junit.Rule
;
...
...
@@ -506,6 +509,62 @@ public abstract class DataSourceContractTest {
}
@Test
public
void
getResponseHeaders_noNullKeysOrValues
()
throws
Exception
{
ImmutableList
<
TestResource
>
resources
=
getTestResources
();
Assertions
.
checkArgument
(!
resources
.
isEmpty
(),
"Must provide at least one test resource."
);
for
(
int
i
=
0
;
i
<
resources
.
size
();
i
++)
{
additionalFailureInfo
.
setInfo
(
getFailureLabel
(
resources
,
i
));
TestResource
resource
=
resources
.
get
(
i
);
DataSource
dataSource
=
createDataSource
();
try
{
dataSource
.
open
(
new
DataSpec
(
resource
.
getUri
()));
Map
<
String
,
List
<
String
>>
responseHeaders
=
dataSource
.
getResponseHeaders
();
assertThat
(
responseHeaders
).
doesNotContainKey
(
null
);
assertThat
(
responseHeaders
.
values
()).
doesNotContain
(
null
);
for
(
List
<
String
>
value
:
responseHeaders
.
values
())
{
assertThat
(
value
).
doesNotContain
(
null
);
}
}
finally
{
dataSource
.
close
();
}
additionalFailureInfo
.
setInfo
(
null
);
}
}
@Test
public
void
getResponseHeaders_caseInsensitive
()
throws
Exception
{
ImmutableList
<
TestResource
>
resources
=
getTestResources
();
Assertions
.
checkArgument
(!
resources
.
isEmpty
(),
"Must provide at least one test resource."
);
for
(
int
i
=
0
;
i
<
resources
.
size
();
i
++)
{
additionalFailureInfo
.
setInfo
(
getFailureLabel
(
resources
,
i
));
TestResource
resource
=
resources
.
get
(
i
);
DataSource
dataSource
=
createDataSource
();
try
{
dataSource
.
open
(
new
DataSpec
(
resource
.
getUri
()));
Map
<
String
,
List
<
String
>>
responseHeaders
=
dataSource
.
getResponseHeaders
();
for
(
String
key
:
responseHeaders
.
keySet
())
{
// TODO(internal b/205811776): Remove this when DefaultHttpDataSource is fixed to not
// return a null key.
if
(
key
==
null
)
{
continue
;
}
String
caseFlippedKey
=
invertAsciiCaseOfEveryOtherCharacter
(
key
);
assertWithMessage
(
"key='%s', caseFlippedKey='%s'"
,
key
,
caseFlippedKey
)
.
that
(
responseHeaders
.
get
(
caseFlippedKey
))
.
isEqualTo
(
responseHeaders
.
get
(
key
));
}
}
finally
{
dataSource
.
close
();
}
additionalFailureInfo
.
setInfo
(
null
);
}
}
@Test
public
void
getResponseHeaders_isEmptyWhileNotOpen
()
throws
Exception
{
ImmutableList
<
TestResource
>
resources
=
getTestResources
();
Assertions
.
checkArgument
(!
resources
.
isEmpty
(),
"Must provide at least one test resource."
);
...
...
@@ -550,6 +609,28 @@ public abstract class DataSourceContractTest {
}
}
private
static
String
invertAsciiCaseOfEveryOtherCharacter
(
String
input
)
{
StringBuilder
result
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
input
.
length
();
i
++)
{
result
.
append
(
i
%
2
==
0
?
invertAsciiCase
(
input
.
charAt
(
i
))
:
input
.
charAt
(
i
));
}
return
result
.
toString
();
}
/**
* Returns {@code c} in the opposite case if it's an ASCII character, otherwise returns {@code c}
* unchanged.
*/
private
static
char
invertAsciiCase
(
char
c
)
{
if
(
Ascii
.
isUpperCase
(
c
))
{
return
Ascii
.
toLowerCase
(
c
);
}
else
if
(
Ascii
.
isLowerCase
(
c
))
{
return
Ascii
.
toUpperCase
(
c
);
}
else
{
return
c
;
}
}
/** Information about a resource that can be used to test the {@link DataSource} instance. */
public
static
final
class
TestResource
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment