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
8e98187a
authored
Mar 04, 2022
by
christosts
Committed by
Ian Baker
Mar 04, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Misc cleanup in session tests
PiperOrigin-RevId: 432430345
parent
c2a3249f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
63 deletions
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaSessionKeyEventTest.java
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaSessionPermissionTest.java
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaSessionPlayerTest.java
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaSessionTest.java
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaSessionKeyEventTest.java
View file @
8e98187a
...
...
@@ -119,7 +119,7 @@ public class MediaSessionKeyEventTest {
}
@After
public
void
cleanUp
()
throws
Exception
{
public
void
tearDown
()
throws
Exception
{
handler
.
postAndSync
(
()
->
{
if
(
mediaPlayer
!=
null
)
{
...
...
@@ -130,15 +130,6 @@ public class MediaSessionKeyEventTest {
session
.
release
();
}
private
void
dispatchMediaKeyEvent
(
int
keyCode
,
boolean
doubleTap
)
{
audioManager
.
dispatchMediaKeyEvent
(
new
KeyEvent
(
KeyEvent
.
ACTION_DOWN
,
keyCode
));
audioManager
.
dispatchMediaKeyEvent
(
new
KeyEvent
(
KeyEvent
.
ACTION_UP
,
keyCode
));
if
(
doubleTap
)
{
audioManager
.
dispatchMediaKeyEvent
(
new
KeyEvent
(
KeyEvent
.
ACTION_DOWN
,
keyCode
));
audioManager
.
dispatchMediaKeyEvent
(
new
KeyEvent
(
KeyEvent
.
ACTION_UP
,
keyCode
));
}
}
@Test
public
void
playKeyEvent
()
throws
Exception
{
dispatchMediaKeyEvent
(
KeyEvent
.
KEYCODE_MEDIA_PLAY
,
false
);
...
...
@@ -202,6 +193,15 @@ public class MediaSessionKeyEventTest {
assertThat
(
player
.
hasMethodBeenCalled
(
MockPlayer
.
METHOD_PAUSE
)).
isFalse
();
}
private
void
dispatchMediaKeyEvent
(
int
keyCode
,
boolean
doubleTap
)
{
audioManager
.
dispatchMediaKeyEvent
(
new
KeyEvent
(
KeyEvent
.
ACTION_DOWN
,
keyCode
));
audioManager
.
dispatchMediaKeyEvent
(
new
KeyEvent
(
KeyEvent
.
ACTION_UP
,
keyCode
));
if
(
doubleTap
)
{
audioManager
.
dispatchMediaKeyEvent
(
new
KeyEvent
(
KeyEvent
.
ACTION_DOWN
,
keyCode
));
audioManager
.
dispatchMediaKeyEvent
(
new
KeyEvent
(
KeyEvent
.
ACTION_UP
,
keyCode
));
}
}
private
static
class
TestSessionCallback
implements
MediaSession
.
SessionCallback
{
@Override
...
...
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaSessionPermissionTest.java
View file @
8e98187a
...
...
@@ -88,7 +88,7 @@ public class MediaSessionPermissionTest {
}
@After
public
void
cleanUp
()
{
public
void
tearDown
()
{
if
(
session
!=
null
)
{
session
.
release
();
session
=
null
;
...
...
@@ -97,54 +97,6 @@ public class MediaSessionPermissionTest {
callback
=
null
;
}
private
void
createSessionWithAvailableCommands
(
SessionCommands
sessionCommands
,
Player
.
Commands
playerCommands
)
{
player
=
new
MockPlayer
.
Builder
()
.
setApplicationLooper
(
threadTestRule
.
getHandler
().
getLooper
())
.
build
();
callback
=
new
MySessionCallback
()
{
@Override
public
MediaSession
.
ConnectionResult
onConnect
(
MediaSession
session
,
ControllerInfo
controller
)
{
if
(!
TextUtils
.
equals
(
SUPPORT_APP_PACKAGE_NAME
,
controller
.
getPackageName
()))
{
return
MediaSession
.
ConnectionResult
.
reject
();
}
return
MediaSession
.
ConnectionResult
.
accept
(
sessionCommands
,
playerCommands
);
}
};
if
(
this
.
session
!=
null
)
{
this
.
session
.
release
();
}
this
.
session
=
new
MediaSession
.
Builder
(
context
,
player
)
.
setId
(
SESSION_ID
)
.
setSessionCallback
(
callback
)
.
build
();
}
private
SessionCommands
createSessionCommandsWith
(
SessionCommand
command
)
{
return
new
SessionCommands
.
Builder
().
add
(
command
).
build
();
}
private
void
testOnCommandRequest
(
int
commandCode
,
PermissionTestTask
runnable
)
throws
Exception
{
createSessionWithAvailableCommands
(
SessionCommands
.
EMPTY
,
createPlayerCommandsWith
(
commandCode
));
runnable
.
run
(
controllerTestRule
.
createRemoteController
(
session
.
getToken
()));
assertThat
(
callback
.
countDownLatch
.
await
(
TIMEOUT_MS
,
MILLISECONDS
)).
isTrue
();
assertThat
(
callback
.
onCommandRequestCalled
).
isTrue
();
assertThat
(
callback
.
command
).
isEqualTo
(
commandCode
);
createSessionWithAvailableCommands
(
SessionCommands
.
EMPTY
,
createPlayerCommandsWithout
(
commandCode
));
runnable
.
run
(
controllerTestRule
.
createRemoteController
(
session
.
getToken
()));
assertThat
(
callback
.
countDownLatch
.
await
(
NO_RESPONSE_TIMEOUT_MS
,
MILLISECONDS
)).
isFalse
();
assertThat
(
callback
.
onCommandRequestCalled
).
isFalse
();
}
@Test
public
void
play
()
throws
Exception
{
testOnCommandRequest
(
COMMAND_PLAY_PAUSE
,
RemoteMediaController:
:
play
);
...
...
@@ -408,4 +360,52 @@ public class MediaSessionPermissionTest {
return
Futures
.
immediateFuture
(
new
SessionResult
(
RESULT_SUCCESS
));
}
}
private
void
createSessionWithAvailableCommands
(
SessionCommands
sessionCommands
,
Player
.
Commands
playerCommands
)
{
player
=
new
MockPlayer
.
Builder
()
.
setApplicationLooper
(
threadTestRule
.
getHandler
().
getLooper
())
.
build
();
callback
=
new
MySessionCallback
()
{
@Override
public
MediaSession
.
ConnectionResult
onConnect
(
MediaSession
session
,
ControllerInfo
controller
)
{
if
(!
TextUtils
.
equals
(
SUPPORT_APP_PACKAGE_NAME
,
controller
.
getPackageName
()))
{
return
MediaSession
.
ConnectionResult
.
reject
();
}
return
MediaSession
.
ConnectionResult
.
accept
(
sessionCommands
,
playerCommands
);
}
};
if
(
this
.
session
!=
null
)
{
this
.
session
.
release
();
}
this
.
session
=
new
MediaSession
.
Builder
(
context
,
player
)
.
setId
(
SESSION_ID
)
.
setSessionCallback
(
callback
)
.
build
();
}
private
SessionCommands
createSessionCommandsWith
(
SessionCommand
command
)
{
return
new
SessionCommands
.
Builder
().
add
(
command
).
build
();
}
private
void
testOnCommandRequest
(
int
commandCode
,
PermissionTestTask
runnable
)
throws
Exception
{
createSessionWithAvailableCommands
(
SessionCommands
.
EMPTY
,
createPlayerCommandsWith
(
commandCode
));
runnable
.
run
(
controllerTestRule
.
createRemoteController
(
session
.
getToken
()));
assertThat
(
callback
.
countDownLatch
.
await
(
TIMEOUT_MS
,
MILLISECONDS
)).
isTrue
();
assertThat
(
callback
.
onCommandRequestCalled
).
isTrue
();
assertThat
(
callback
.
command
).
isEqualTo
(
commandCode
);
createSessionWithAvailableCommands
(
SessionCommands
.
EMPTY
,
createPlayerCommandsWithout
(
commandCode
));
runnable
.
run
(
controllerTestRule
.
createRemoteController
(
session
.
getToken
()));
assertThat
(
callback
.
countDownLatch
.
await
(
NO_RESPONSE_TIMEOUT_MS
,
MILLISECONDS
)).
isFalse
();
assertThat
(
callback
.
onCommandRequestCalled
).
isFalse
();
}
}
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaSessionPlayerTest.java
View file @
8e98187a
...
...
@@ -84,10 +84,9 @@ public class MediaSessionPlayerTest {
}
@After
public
void
cleanUp
()
{
if
(
session
!=
null
)
{
session
.
release
();
}
public
void
tearDown
()
throws
Exception
{
controller
.
release
();
session
.
release
();
}
@Test
...
...
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaSessionTest.java
View file @
8e98187a
...
...
@@ -47,6 +47,7 @@ import java.util.concurrent.ExecutionException;
import
java.util.concurrent.Future
;
import
java.util.concurrent.TimeoutException
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.ClassRule
;
import
org.junit.Rule
;
...
...
@@ -106,6 +107,16 @@ public class MediaSessionTest {
.
get
(
TIMEOUT_MS
,
MILLISECONDS
);
}
@After
public
void
tearDown
()
throws
Exception
{
if
((
controller
!=
null
))
{
threadTestRule
.
getHandler
().
postAndSync
(()
->
controller
.
release
());
}
if
(
session
!=
null
)
{
session
.
release
();
}
}
@Test
public
void
builder
()
{
MediaSession
.
Builder
builder
;
...
...
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