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
df251ad1
authored
Oct 31, 2019
by
aquilescanta
Committed by
Oliver Woodman
Nov 05, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add tests for SampleQueue isReady
PiperOrigin-RevId: 277691935
parent
2d530478
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
22 deletions
library/core/src/test/java/com/google/android/exoplayer2/source/SampleQueueTest.java
library/core/src/test/java/com/google/android/exoplayer2/source/SampleQueueTest.java
View file @
df251ad1
...
@@ -22,6 +22,7 @@ import static com.google.android.exoplayer2.source.SampleQueue.ADVANCE_FAILED;
...
@@ -22,6 +22,7 @@ import static com.google.android.exoplayer2.source.SampleQueue.ADVANCE_FAILED;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
java
.
lang
.
Long
.
MIN_VALUE
;
import
static
java
.
lang
.
Long
.
MIN_VALUE
;
import
static
java
.
util
.
Arrays
.
copyOfRange
;
import
static
java
.
util
.
Arrays
.
copyOfRange
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.Nullable
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
...
@@ -141,8 +142,7 @@ public final class SampleQueueTest {
...
@@ -141,8 +142,7 @@ public final class SampleQueueTest {
mockDrmSessionManager
=
mockDrmSessionManager
=
(
DrmSessionManager
<
ExoMediaCrypto
>)
Mockito
.
mock
(
DrmSessionManager
.
class
);
(
DrmSessionManager
<
ExoMediaCrypto
>)
Mockito
.
mock
(
DrmSessionManager
.
class
);
mockDrmSession
=
(
DrmSession
<
ExoMediaCrypto
>)
Mockito
.
mock
(
DrmSession
.
class
);
mockDrmSession
=
(
DrmSession
<
ExoMediaCrypto
>)
Mockito
.
mock
(
DrmSession
.
class
);
Mockito
.
when
(
when
(
mockDrmSessionManager
.
acquireSession
(
ArgumentMatchers
.
any
(),
ArgumentMatchers
.
any
()))
mockDrmSessionManager
.
acquireSession
(
ArgumentMatchers
.
any
(),
ArgumentMatchers
.
any
()))
.
thenReturn
(
mockDrmSession
);
.
thenReturn
(
mockDrmSession
);
sampleQueue
=
new
SampleQueue
(
allocator
,
mockDrmSessionManager
);
sampleQueue
=
new
SampleQueue
(
allocator
,
mockDrmSessionManager
);
formatHolder
=
new
FormatHolder
();
formatHolder
=
new
FormatHolder
();
...
@@ -308,20 +308,52 @@ public final class SampleQueueTest {
...
@@ -308,20 +308,52 @@ public final class SampleQueueTest {
}
}
@Test
@Test
public
void
testEmptyQueueReturnsLoadingFinished
()
{
sampleQueue
.
sampleData
(
new
ParsableByteArray
(
DATA
),
DATA
.
length
);
assertThat
(
sampleQueue
.
isReady
(
/* loadingFinished= */
false
)).
isFalse
();
assertThat
(
sampleQueue
.
isReady
(
/* loadingFinished= */
true
)).
isTrue
();
}
@Test
public
void
testIsReadyWithUpstreamFormatOnlyReturnsTrue
()
{
sampleQueue
.
format
(
FORMAT_ENCRYPTED
);
assertThat
(
sampleQueue
.
isReady
(
/* loadingFinished= */
false
)).
isTrue
();
}
@Test
public
void
testIsReadyReturnsTrueForValidDrmSession
()
{
writeTestDataWithEncryptedSections
();
assertReadFormat
(
/* formatRequired= */
false
,
FORMAT_ENCRYPTED
);
assertThat
(
sampleQueue
.
isReady
(
/* loadingFinished= */
false
)).
isFalse
();
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED_WITH_KEYS
);
assertThat
(
sampleQueue
.
isReady
(
/* loadingFinished= */
false
)).
isTrue
();
}
@Test
public
void
testIsReadyReturnsTrueForClearSampleAndPlayClearSamplesWithoutKeysIsTrue
()
{
when
(
mockDrmSessionManager
.
getFlags
())
.
thenReturn
(
DrmSessionManager
.
FLAG_PLAY_CLEAR_SAMPLES_WITHOUT_KEYS
);
// We recreate the queue to ensure the mock DRM session manager flags are taken into account.
sampleQueue
=
new
SampleQueue
(
allocator
,
mockDrmSessionManager
);
writeTestDataWithEncryptedSections
();
assertThat
(
sampleQueue
.
isReady
(
/* loadingFinished= */
false
)).
isTrue
();
}
@Test
public
void
testReadEncryptedSectionsWaitsForKeys
()
{
public
void
testReadEncryptedSectionsWaitsForKeys
()
{
Mockito
.
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED
);
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED
);
write
EncryptedTestData
();
write
TestDataWithEncryptedSections
();
assertReadFormat
(
/* formatRequired= */
false
,
FORMAT_ENCRYPTED
);
assertReadFormat
(
/* formatRequired= */
false
,
FORMAT_ENCRYPTED
);
assertReadNothing
(
/* formatRequired= */
false
);
assertReadNothing
(
/* formatRequired= */
false
);
Mockito
.
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED_WITH_KEYS
);
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED_WITH_KEYS
);
assertReadEncryptedSample
(
/* sampleIndex= */
0
);
assertReadEncryptedSample
(
/* sampleIndex= */
0
);
}
}
@Test
@Test
public
void
testReadEncryptedSectionsPopulatesDrmSession
()
{
public
void
testReadEncryptedSectionsPopulatesDrmSession
()
{
Mockito
.
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED_WITH_KEYS
);
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED_WITH_KEYS
);
write
EncryptedTestData
();
write
TestDataWithEncryptedSections
();
int
result
=
int
result
=
sampleQueue
.
read
(
sampleQueue
.
read
(
...
@@ -360,14 +392,13 @@ public final class SampleQueueTest {
...
@@ -360,14 +392,13 @@ public final class SampleQueueTest {
@Test
@Test
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
public
void
testAllowPlaceholderSessionPopulatesDrmSession
()
{
public
void
testAllowPlaceholderSessionPopulatesDrmSession
()
{
Mockito
.
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED_WITH_KEYS
);
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED_WITH_KEYS
);
DrmSession
<
ExoMediaCrypto
>
mockPlaceholderDrmSession
=
DrmSession
<
ExoMediaCrypto
>
mockPlaceholderDrmSession
=
(
DrmSession
<
ExoMediaCrypto
>)
Mockito
.
mock
(
DrmSession
.
class
);
(
DrmSession
<
ExoMediaCrypto
>)
Mockito
.
mock
(
DrmSession
.
class
);
Mockito
.
when
(
mockPlaceholderDrmSession
.
getState
())
when
(
mockPlaceholderDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED_WITH_KEYS
);
.
thenReturn
(
DrmSession
.
STATE_OPENED_WITH_KEYS
);
when
(
mockDrmSessionManager
.
acquirePlaceholderSession
(
ArgumentMatchers
.
any
()))
Mockito
.
when
(
mockDrmSessionManager
.
acquirePlaceholderSession
(
ArgumentMatchers
.
any
()))
.
thenReturn
(
mockPlaceholderDrmSession
);
.
thenReturn
(
mockPlaceholderDrmSession
);
write
EncryptedTestData
();
write
TestDataWithEncryptedSections
();
int
result
=
int
result
=
sampleQueue
.
read
(
sampleQueue
.
read
(
...
@@ -405,15 +436,14 @@ public final class SampleQueueTest {
...
@@ -405,15 +436,14 @@ public final class SampleQueueTest {
@Test
@Test
public
void
testReadWithErrorSessionReadsNothingAndThrows
()
throws
IOException
{
public
void
testReadWithErrorSessionReadsNothingAndThrows
()
throws
IOException
{
Mockito
.
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED
);
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED
);
write
EncryptedTestData
();
write
TestDataWithEncryptedSections
();
assertReadFormat
(
/* formatRequired= */
false
,
FORMAT_ENCRYPTED
);
assertReadFormat
(
/* formatRequired= */
false
,
FORMAT_ENCRYPTED
);
assertReadNothing
(
/* formatRequired= */
false
);
assertReadNothing
(
/* formatRequired= */
false
);
sampleQueue
.
maybeThrowError
();
sampleQueue
.
maybeThrowError
();
Mockito
.
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_ERROR
);
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_ERROR
);
Mockito
.
when
(
mockDrmSession
.
getError
())
when
(
mockDrmSession
.
getError
()).
thenReturn
(
new
DrmSession
.
DrmSessionException
(
new
Exception
()));
.
thenReturn
(
new
DrmSession
.
DrmSessionException
(
new
Exception
()));
assertReadNothing
(
/* formatRequired= */
false
);
assertReadNothing
(
/* formatRequired= */
false
);
try
{
try
{
sampleQueue
.
maybeThrowError
();
sampleQueue
.
maybeThrowError
();
...
@@ -421,18 +451,18 @@ public final class SampleQueueTest {
...
@@ -421,18 +451,18 @@ public final class SampleQueueTest {
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
// Expected.
// Expected.
}
}
Mockito
.
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED_WITH_KEYS
);
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED_WITH_KEYS
);
assertReadEncryptedSample
(
/* sampleIndex= */
0
);
assertReadEncryptedSample
(
/* sampleIndex= */
0
);
}
}
@Test
@Test
public
void
testAllowPlayClearSamplesWithoutKeysReadsClearSamples
()
{
public
void
testAllowPlayClearSamplesWithoutKeysReadsClearSamples
()
{
Mockito
.
when
(
mockDrmSessionManager
.
getFlags
())
when
(
mockDrmSessionManager
.
getFlags
())
.
thenReturn
(
DrmSessionManager
.
FLAG_PLAY_CLEAR_SAMPLES_WITHOUT_KEYS
);
.
thenReturn
(
DrmSessionManager
.
FLAG_PLAY_CLEAR_SAMPLES_WITHOUT_KEYS
);
// We recreate the queue to ensure the mock DRM session manager flags are taken into account.
// We recreate the queue to ensure the mock DRM session manager flags are taken into account.
sampleQueue
=
new
SampleQueue
(
allocator
,
mockDrmSessionManager
);
sampleQueue
=
new
SampleQueue
(
allocator
,
mockDrmSessionManager
);
Mockito
.
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED
);
when
(
mockDrmSession
.
getState
()).
thenReturn
(
DrmSession
.
STATE_OPENED
);
write
EncryptedTestData
();
write
TestDataWithEncryptedSections
();
assertReadFormat
(
/* formatRequired= */
false
,
FORMAT_ENCRYPTED
);
assertReadFormat
(
/* formatRequired= */
false
,
FORMAT_ENCRYPTED
);
assertReadEncryptedSample
(
/* sampleIndex= */
0
);
assertReadEncryptedSample
(
/* sampleIndex= */
0
);
...
@@ -794,7 +824,7 @@ public final class SampleQueueTest {
...
@@ -794,7 +824,7 @@ public final class SampleQueueTest {
DATA
,
SAMPLE_SIZES
,
SAMPLE_OFFSETS
,
SAMPLE_TIMESTAMPS
,
SAMPLE_FORMATS
,
SAMPLE_FLAGS
);
DATA
,
SAMPLE_SIZES
,
SAMPLE_OFFSETS
,
SAMPLE_TIMESTAMPS
,
SAMPLE_FORMATS
,
SAMPLE_FLAGS
);
}
}
private
void
write
EncryptedTestData
()
{
private
void
write
TestDataWithEncryptedSections
()
{
writeTestData
(
writeTestData
(
ENCRYPTED_SAMPLES_DATA
,
ENCRYPTED_SAMPLES_DATA
,
ENCRYPTED_SAMPLES_SIZES
,
ENCRYPTED_SAMPLES_SIZES
,
...
...
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