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
653d180d
authored
Dec 23, 2020
by
ibaker
Committed by
Oliver Woodman
Dec 23, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add 302 redirect test to DefaultHttpDataSourceContractTest
PiperOrigin-RevId: 348760170
parent
f44e5bd2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
13 deletions
library/core/src/test/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSourceContractTest.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/WebServerDispatcher.java
library/core/src/test/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSourceContractTest.java
View file @
653d180d
...
...
@@ -21,7 +21,12 @@ import com.google.android.exoplayer2.testutil.DataSourceContractTest;
import
com.google.android.exoplayer2.testutil.TestUtil
;
import
com.google.android.exoplayer2.testutil.WebServerDispatcher
;
import
com.google.common.collect.ImmutableList
;
import
java.util.function.Function
;
import
okhttp3.HttpUrl
;
import
okhttp3.mockwebserver.Dispatcher
;
import
okhttp3.mockwebserver.MockResponse
;
import
okhttp3.mockwebserver.MockWebServer
;
import
okhttp3.mockwebserver.RecordedRequest
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.runner.RunWith
;
...
...
@@ -61,23 +66,43 @@ public class DefaultHttpDataSourceContractTest extends DataSourceContractTest {
.
resolvesToUnknownLength
(
true
)
.
build
();
private
final
MockWebServer
mockWebServer
=
new
MockWebServer
();
private
static
final
WebServerDispatcher
.
Resource
REDIRECTS_TO_RANGE_SUPPORTED
=
RANGE_SUPPORTED
.
buildUpon
().
setPath
(
"/redirects/to/range/supported"
).
build
();
private
final
MockWebServer
originServer
=
new
MockWebServer
();
private
final
MockWebServer
redirectionServer
=
new
MockWebServer
();
@Before
public
void
startServer
()
throws
Exception
{
mockWeb
Server
.
start
();
mockWeb
Server
.
setDispatcher
(
public
void
startServer
s
()
throws
Exception
{
origin
Server
.
start
();
origin
Server
.
setDispatcher
(
WebServerDispatcher
.
forResources
(
ImmutableList
.
of
(
RANGE_SUPPORTED
,
RANGE_SUPPORTED_LENGTH_UNKNOWN
,
RANGE_NOT_SUPPORTED
,
RANGE_NOT_SUPPORTED_LENGTH_UNKNOWN
)));
redirectionServer
.
start
();
redirectionServer
.
setDispatcher
(
new
Dispatcher
()
{
@Override
public
MockResponse
dispatch
(
RecordedRequest
request
)
{
if
(
request
.
getPath
().
equals
(
REDIRECTS_TO_RANGE_SUPPORTED
.
getPath
()))
{
return
new
MockResponse
()
.
setResponseCode
(
302
)
.
setHeader
(
"Location"
,
originServer
.
url
(
RANGE_SUPPORTED
.
getPath
()).
toString
());
}
else
{
return
new
MockResponse
().
setResponseCode
(
404
);
}
}
});
}
@After
public
void
shutdownServer
()
throws
Exception
{
mockWebServer
.
shutdown
();
public
void
shutdownServers
()
throws
Exception
{
originServer
.
shutdown
();
redirectionServer
.
shutdown
();
}
@Override
...
...
@@ -88,21 +113,27 @@ public class DefaultHttpDataSourceContractTest extends DataSourceContractTest {
@Override
protected
ImmutableList
<
TestResource
>
getTestResources
()
{
return
ImmutableList
.
of
(
toTestResource
(
"range supported"
,
RANGE_SUPPORTED
),
toTestResource
(
"range supported, length unknown"
,
RANGE_SUPPORTED_LENGTH_UNKNOWN
),
toTestResource
(
"range not supported"
,
RANGE_NOT_SUPPORTED
),
toTestResource
(
"range not supported, length unknown"
,
RANGE_NOT_SUPPORTED_LENGTH_UNKNOWN
));
toTestResource
(
"range supported"
,
RANGE_SUPPORTED
,
originServer:
:
url
),
toTestResource
(
"range supported, length unknown"
,
RANGE_SUPPORTED_LENGTH_UNKNOWN
,
originServer:
:
url
),
toTestResource
(
"range not supported"
,
RANGE_NOT_SUPPORTED
,
originServer:
:
url
),
toTestResource
(
"range not supported, length unknown"
,
RANGE_NOT_SUPPORTED_LENGTH_UNKNOWN
,
originServer:
:
url
),
toTestResource
(
"302 redirect"
,
REDIRECTS_TO_RANGE_SUPPORTED
,
redirectionServer:
:
url
));
}
@Override
protected
Uri
getNotFoundUri
()
{
return
Uri
.
parse
(
mockWeb
Server
.
url
(
"/not/a/real/path"
).
toString
());
return
Uri
.
parse
(
origin
Server
.
url
(
"/not/a/real/path"
).
toString
());
}
private
TestResource
toTestResource
(
String
name
,
WebServerDispatcher
.
Resource
resource
)
{
private
static
TestResource
toTestResource
(
String
name
,
WebServerDispatcher
.
Resource
resource
,
Function
<
String
,
HttpUrl
>
urlResolver
)
{
return
new
TestResource
.
Builder
()
.
setName
(
name
)
.
setUri
(
Uri
.
parse
(
mockWebServer
.
url
(
resource
.
getPath
()).
toString
()))
.
setUri
(
Uri
.
parse
(
urlResolver
.
apply
(
resource
.
getPath
()).
toString
()))
.
setExpectedBytes
(
resource
.
getData
())
.
setResolvesToUnknownLength
(
resource
.
resolvesToUnknownLength
())
.
setEndOfInputExpected
(!
resource
.
resolvesToUnknownLength
())
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/WebServerDispatcher.java
View file @
653d180d
...
...
@@ -48,6 +48,16 @@ public class WebServerDispatcher extends Dispatcher {
private
boolean
supportsRangeRequests
;
private
boolean
resolvesToUnknownLength
;
/** Constructs an instance. */
public
Builder
()
{}
private
Builder
(
Resource
resource
)
{
this
.
path
=
resource
.
getPath
();
this
.
data
=
resource
.
getData
();
this
.
supportsRangeRequests
=
resource
.
supportsRangeRequests
();
this
.
resolvesToUnknownLength
=
resource
.
resolvesToUnknownLength
();
}
/**
* Sets the path this data should be served at. This is required.
*
...
...
@@ -132,6 +142,11 @@ public class WebServerDispatcher extends Dispatcher {
public
boolean
resolvesToUnknownLength
()
{
return
resolvesToUnknownLength
;
}
/** Returns a new {@link Builder} initialized with the values from this instance. */
public
Builder
buildUpon
()
{
return
new
Builder
(
this
);
}
}
private
final
ImmutableMap
<
String
,
Resource
>
resourcesByPath
;
...
...
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