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
6eb70600
authored
Jul 20, 2020
by
olly
Committed by
Oliver Woodman
Jul 24, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Migrate to Robolectric PAUSED looper mode: AudioFocusManagerTest
PiperOrigin-RevId: 322154193
parent
576ef821
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
4 deletions
library/core/src/test/java/com/google/android/exoplayer2/AudioFocusManagerTest.java
library/core/src/test/java/com/google/android/exoplayer2/AudioFocusManagerTest.java
View file @
6eb70600
...
...
@@ -20,8 +20,8 @@ import static com.google.android.exoplayer2.AudioFocusManager.PLAYER_COMMAND_PLA
import
static
com
.
google
.
android
.
exoplayer2
.
AudioFocusManager
.
PLAYER_COMMAND_WAIT_FOR_CALLBACK
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
robolectric
.
Shadows
.
shadowOf
;
import
static
org
.
robolectric
.
annotation
.
Config
.
TARGET_SDK
;
import
static
org
.
robolectric
.
annotation
.
LooperMode
.
Mode
.
LEGACY
;
import
android.content.Context
;
import
android.media.AudioFocusRequest
;
...
...
@@ -37,11 +37,9 @@ import org.junit.Test;
import
org.junit.runner.RunWith
;
import
org.robolectric.Shadows
;
import
org.robolectric.annotation.Config
;
import
org.robolectric.annotation.LooperMode
;
import
org.robolectric.shadows.ShadowAudioManager
;
/** Unit tests for {@link AudioFocusManager}. */
@LooperMode
(
LEGACY
)
@RunWith
(
AndroidJUnit4
.
class
)
public
class
AudioFocusManagerTest
{
private
static
final
int
NO_COMMAND_RECEIVED
=
~
PLAYER_COMMAND_WAIT_FOR_CALLBACK
;
...
...
@@ -231,8 +229,9 @@ public class AudioFocusManagerTest {
audioFocusManager
.
getFocusListener
()
.
onAudioFocusChange
(
AudioManager
.
AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK
);
assertThat
(
testPlayerControl
.
lastVolumeMultiplier
).
isLessThan
(
1.0f
);
shadowOf
(
Looper
.
getMainLooper
()).
idle
(
);
assertThat
(
testPlayerControl
.
lastVolumeMultiplier
).
isLessThan
(
1.0f
);
// Focus should be re-requested, rather than staying in a state of transient ducking. This
// should restore the volume to 1.0. See https://github.com/google/ExoPlayer/issues/7182 for
// context.
...
...
@@ -254,6 +253,8 @@ public class AudioFocusManagerTest {
audioFocusManager
.
getFocusListener
()
.
onAudioFocusChange
(
AudioManager
.
AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK
);
shadowOf
(
Looper
.
getMainLooper
()).
idle
();
assertThat
(
testPlayerControl
.
lastVolumeMultiplier
).
isLessThan
(
1.0f
);
// Configure the manager to no longer handle focus.
...
...
@@ -354,6 +355,8 @@ public class AudioFocusManagerTest {
audioFocusManager
.
getFocusListener
()
.
onAudioFocusChange
(
AudioManager
.
AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK
);
shadowOf
(
Looper
.
getMainLooper
()).
idle
();
assertThat
(
testPlayerControl
.
lastVolumeMultiplier
).
isLessThan
(
1.0f
);
audioFocusManager
.
release
();
...
...
@@ -374,10 +377,14 @@ public class AudioFocusManagerTest {
audioFocusManager
.
getFocusListener
()
.
onAudioFocusChange
(
AudioManager
.
AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK
);
shadowOf
(
Looper
.
getMainLooper
()).
idle
();
assertThat
(
testPlayerControl
.
lastVolumeMultiplier
).
isLessThan
(
1.0f
);
assertThat
(
testPlayerControl
.
lastPlayerCommand
).
isEqualTo
(
NO_COMMAND_RECEIVED
);
audioFocusManager
.
getFocusListener
().
onAudioFocusChange
(
AudioManager
.
AUDIOFOCUS_GAIN
);
shadowOf
(
Looper
.
getMainLooper
()).
idle
();
assertThat
(
testPlayerControl
.
lastVolumeMultiplier
).
isEqualTo
(
1.0f
);
}
...
...
@@ -399,9 +406,14 @@ public class AudioFocusManagerTest {
audioFocusManager
.
getFocusListener
()
.
onAudioFocusChange
(
AudioManager
.
AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK
);
shadowOf
(
Looper
.
getMainLooper
()).
idle
();
assertThat
(
testPlayerControl
.
lastPlayerCommand
).
isEqualTo
(
PLAYER_COMMAND_WAIT_FOR_CALLBACK
);
assertThat
(
testPlayerControl
.
lastVolumeMultiplier
).
isEqualTo
(
1.0f
);
audioFocusManager
.
getFocusListener
().
onAudioFocusChange
(
AudioManager
.
AUDIOFOCUS_GAIN
);
shadowOf
(
Looper
.
getMainLooper
()).
idle
();
assertThat
(
testPlayerControl
.
lastPlayerCommand
).
isEqualTo
(
PLAYER_COMMAND_PLAY_WHEN_READY
);
}
...
...
@@ -415,6 +427,8 @@ public class AudioFocusManagerTest {
.
isEqualTo
(
PLAYER_COMMAND_PLAY_WHEN_READY
);
audioFocusManager
.
getFocusListener
().
onAudioFocusChange
(
AudioManager
.
AUDIOFOCUS_LOSS_TRANSIENT
);
shadowOf
(
Looper
.
getMainLooper
()).
idle
();
assertThat
(
testPlayerControl
.
lastVolumeMultiplier
).
isEqualTo
(
1.0f
);
assertThat
(
testPlayerControl
.
lastPlayerCommand
).
isEqualTo
(
PLAYER_COMMAND_WAIT_FOR_CALLBACK
);
}
...
...
@@ -433,6 +447,8 @@ public class AudioFocusManagerTest {
ShadowAudioManager
.
AudioFocusRequest
request
=
Shadows
.
shadowOf
(
audioManager
).
getLastAudioFocusRequest
();
request
.
listener
.
onAudioFocusChange
(
AudioManager
.
AUDIOFOCUS_LOSS
);
shadowOf
(
Looper
.
getMainLooper
()).
idle
();
assertThat
(
testPlayerControl
.
lastPlayerCommand
).
isEqualTo
(
PLAYER_COMMAND_DO_NOT_PLAY
);
assertThat
(
Shadows
.
shadowOf
(
audioManager
).
getLastAbandonedAudioFocusListener
())
.
isEqualTo
(
request
.
listener
);
...
...
@@ -450,6 +466,8 @@ public class AudioFocusManagerTest {
assertThat
(
Shadows
.
shadowOf
(
audioManager
).
getLastAbandonedAudioFocusRequest
()).
isNull
();
audioFocusManager
.
getFocusListener
().
onAudioFocusChange
(
AudioManager
.
AUDIOFOCUS_LOSS
);
shadowOf
(
Looper
.
getMainLooper
()).
idle
();
assertThat
(
testPlayerControl
.
lastPlayerCommand
).
isEqualTo
(
PLAYER_COMMAND_DO_NOT_PLAY
);
assertThat
(
Shadows
.
shadowOf
(
audioManager
).
getLastAbandonedAudioFocusRequest
())
.
isEqualTo
(
Shadows
.
shadowOf
(
audioManager
).
getLastAudioFocusRequest
().
audioFocusRequest
);
...
...
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