Update Robolectric and Truth.
PiperOrigin-RevId: 233612344
This commit is contained in:
parent
f299a65a33
commit
edabbd52d0
@ -23,8 +23,8 @@ project.ext {
|
|||||||
dexmakerVersion = '1.2'
|
dexmakerVersion = '1.2'
|
||||||
mockitoVersion = '1.9.5'
|
mockitoVersion = '1.9.5'
|
||||||
junitVersion = '4.12'
|
junitVersion = '4.12'
|
||||||
truthVersion = '0.39'
|
truthVersion = '0.42'
|
||||||
robolectricVersion = '3.7.1'
|
robolectricVersion = '4.1'
|
||||||
autoValueVersion = '1.6'
|
autoValueVersion = '1.6'
|
||||||
checkerframeworkVersion = '2.5.0'
|
checkerframeworkVersion = '2.5.0'
|
||||||
testRunnerVersion = '1.1.0-alpha3'
|
testRunnerVersion = '1.1.0-alpha3'
|
||||||
|
@ -26,6 +26,8 @@ android {
|
|||||||
minSdkVersion project.ext.minSdkVersion
|
minSdkVersion project.ext.minSdkVersion
|
||||||
targetSdkVersion project.ext.targetSdkVersion
|
targetSdkVersion project.ext.targetSdkVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -1 +0,0 @@
|
|||||||
manifest=src/test/AndroidManifest.xml
|
|
@ -26,6 +26,8 @@ android {
|
|||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -1 +0,0 @@
|
|||||||
manifest=src/test/AndroidManifest.xml
|
|
@ -32,6 +32,8 @@ android {
|
|||||||
jniLibs.srcDir 'src/main/libs'
|
jniLibs.srcDir 'src/main/libs'
|
||||||
jni.srcDirs = [] // Disable the automatic ndk-build call by Android Studio.
|
jni.srcDirs = [] // Disable the automatic ndk-build call by Android Studio.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -1 +0,0 @@
|
|||||||
manifest=src/test/AndroidManifest.xml
|
|
@ -33,6 +33,8 @@ android {
|
|||||||
jniLibs.srcDir 'src/main/libs'
|
jniLibs.srcDir 'src/main/libs'
|
||||||
jni.srcDirs = [] // Disable the automatic ndk-build call by Android Studio.
|
jni.srcDirs = [] // Disable the automatic ndk-build call by Android Studio.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -1 +0,0 @@
|
|||||||
manifest=src/test/AndroidManifest.xml
|
|
@ -26,6 +26,8 @@ android {
|
|||||||
minSdkVersion 19
|
minSdkVersion 19
|
||||||
targetSdkVersion project.ext.targetSdkVersion
|
targetSdkVersion project.ext.targetSdkVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -27,6 +27,8 @@ android {
|
|||||||
targetSdkVersion project.ext.targetSdkVersion
|
targetSdkVersion project.ext.targetSdkVersion
|
||||||
consumerProguardFiles 'proguard-rules.txt'
|
consumerProguardFiles 'proguard-rules.txt'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -1 +0,0 @@
|
|||||||
manifest=src/test/AndroidManifest.xml
|
|
@ -28,6 +28,8 @@ android {
|
|||||||
minSdkVersion project.ext.minSdkVersion
|
minSdkVersion project.ext.minSdkVersion
|
||||||
targetSdkVersion project.ext.targetSdkVersion
|
targetSdkVersion project.ext.targetSdkVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -26,6 +26,8 @@ android {
|
|||||||
minSdkVersion 17
|
minSdkVersion 17
|
||||||
targetSdkVersion project.ext.targetSdkVersion
|
targetSdkVersion project.ext.targetSdkVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -26,6 +26,8 @@ android {
|
|||||||
minSdkVersion project.ext.minSdkVersion
|
minSdkVersion project.ext.minSdkVersion
|
||||||
targetSdkVersion project.ext.targetSdkVersion
|
targetSdkVersion project.ext.targetSdkVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -27,6 +27,8 @@ android {
|
|||||||
targetSdkVersion project.ext.targetSdkVersion
|
targetSdkVersion project.ext.targetSdkVersion
|
||||||
consumerProguardFiles 'proguard-rules.txt'
|
consumerProguardFiles 'proguard-rules.txt'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -33,6 +33,8 @@ android {
|
|||||||
jniLibs.srcDir 'src/main/libs'
|
jniLibs.srcDir 'src/main/libs'
|
||||||
jni.srcDirs = [] // Disable the automatic ndk-build call by Android Studio.
|
jni.srcDirs = [] // Disable the automatic ndk-build call by Android Studio.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -1 +0,0 @@
|
|||||||
manifest=src/test/AndroidManifest.xml
|
|
@ -26,6 +26,8 @@ android {
|
|||||||
minSdkVersion project.ext.minSdkVersion
|
minSdkVersion project.ext.minSdkVersion
|
||||||
targetSdkVersion project.ext.targetSdkVersion
|
targetSdkVersion project.ext.targetSdkVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -33,6 +33,8 @@ android {
|
|||||||
jniLibs.srcDir 'src/main/libs'
|
jniLibs.srcDir 'src/main/libs'
|
||||||
jni.srcDirs = [] // Disable the automatic ndk-build call by Android Studio.
|
jni.srcDirs = [] // Disable the automatic ndk-build call by Android Studio.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -1 +0,0 @@
|
|||||||
manifest=src/test/AndroidManifest.xml
|
|
@ -1,3 +1,4 @@
|
|||||||
## Project-wide Gradle settings.
|
## Project-wide Gradle settings.
|
||||||
android.useDeprecatedNdk=true
|
android.useDeprecatedNdk=true
|
||||||
|
android.enableUnitTestBinaryResources=true
|
||||||
buildDir=buildout
|
buildDir=buildout
|
||||||
|
@ -53,6 +53,8 @@ android {
|
|||||||
// testCoverageEnabled = true
|
// testCoverageEnabled = true
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -21,6 +21,7 @@ import android.media.AudioManager;
|
|||||||
import android.support.annotation.IntDef;
|
import android.support.annotation.IntDef;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.RequiresApi;
|
import android.support.annotation.RequiresApi;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.ExoPlayer;
|
import com.google.android.exoplayer2.ExoPlayer;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
@ -195,6 +196,11 @@ public final class AudioFocusManager {
|
|||||||
|
|
||||||
// Internal methods.
|
// Internal methods.
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
/* package */ AudioManager.OnAudioFocusChangeListener getFocusListener() {
|
||||||
|
return focusListener;
|
||||||
|
}
|
||||||
|
|
||||||
@PlayerCommand
|
@PlayerCommand
|
||||||
private int handleIdle(boolean playWhenReady) {
|
private int handleIdle(boolean playWhenReady) {
|
||||||
return playWhenReady ? PLAYER_COMMAND_PLAY_WHEN_READY : PLAYER_COMMAND_DO_NOT_PLAY;
|
return playWhenReady ? PLAYER_COMMAND_PLAY_WHEN_READY : PLAYER_COMMAND_DO_NOT_PLAY;
|
||||||
|
@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.SurfaceTexture;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import com.google.android.exoplayer2.Player.DiscontinuityReason;
|
import com.google.android.exoplayer2.Player.DiscontinuityReason;
|
||||||
@ -2593,8 +2594,8 @@ public final class ExoPlayerTest {
|
|||||||
// Internal methods.
|
// Internal methods.
|
||||||
|
|
||||||
private static ActionSchedule.Builder addSurfaceSwitch(ActionSchedule.Builder builder) {
|
private static ActionSchedule.Builder addSurfaceSwitch(ActionSchedule.Builder builder) {
|
||||||
final Surface surface1 = new Surface(null);
|
final Surface surface1 = new Surface(new SurfaceTexture(/* texName= */ 0));
|
||||||
final Surface surface2 = new Surface(null);
|
final Surface surface2 = new Surface(new SurfaceTexture(/* texName= */ 1));
|
||||||
return builder
|
return builder
|
||||||
.executeRunnable(
|
.executeRunnable(
|
||||||
new PlayerRunnable() {
|
new PlayerRunnable() {
|
||||||
|
@ -22,15 +22,18 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.media.AudioFocusRequest;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.Shadows;
|
import org.robolectric.Shadows;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.shadows.ShadowAudioManager;
|
import org.robolectric.shadows.ShadowAudioManager;
|
||||||
|
|
||||||
/** Unit tests for {@link AudioFocusManager}. */
|
/** Unit tests for {@link AudioFocusManager}. */
|
||||||
@ -69,6 +72,7 @@ public class AudioFocusManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Config(maxSdk = 25)
|
||||||
public void setAudioAttributes_withNullUsage_releasesAudioFocus() {
|
public void setAudioAttributes_withNullUsage_releasesAudioFocus() {
|
||||||
// Create attributes and request audio focus.
|
// Create attributes and request audio focus.
|
||||||
AudioAttributes media = new AudioAttributes.Builder().setUsage(C.USAGE_MEDIA).build();
|
AudioAttributes media = new AudioAttributes.Builder().setUsage(C.USAGE_MEDIA).build();
|
||||||
@ -92,6 +96,31 @@ public class AudioFocusManagerTest {
|
|||||||
assertThat(lastRequest).isNotNull();
|
assertThat(lastRequest).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(minSdk = 26)
|
||||||
|
public void setAudioAttributes_withNullUsage_releasesAudioFocus_v26() {
|
||||||
|
// Create attributes and request audio focus.
|
||||||
|
AudioAttributes media = new AudioAttributes.Builder().setUsage(C.USAGE_MEDIA).build();
|
||||||
|
Shadows.shadowOf(audioManager)
|
||||||
|
.setNextFocusRequestResponse(AudioManager.AUDIOFOCUS_REQUEST_GRANTED);
|
||||||
|
assertThat(
|
||||||
|
audioFocusManager.setAudioAttributes(
|
||||||
|
media, /* playWhenReady= */ true, Player.STATE_READY))
|
||||||
|
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
||||||
|
ShadowAudioManager.AudioFocusRequest request =
|
||||||
|
Shadows.shadowOf(audioManager).getLastAudioFocusRequest();
|
||||||
|
assertThat(getAudioFocusGainFromRequest(request)).isEqualTo(AudioManager.AUDIOFOCUS_GAIN);
|
||||||
|
|
||||||
|
// Ensure that setting null audio attributes with audio focus releases audio focus.
|
||||||
|
assertThat(
|
||||||
|
audioFocusManager.setAudioAttributes(
|
||||||
|
/* audioAttributes= */ null, /* playWhenReady= */ true, Player.STATE_READY))
|
||||||
|
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
||||||
|
AudioFocusRequest lastRequest =
|
||||||
|
Shadows.shadowOf(audioManager).getLastAbandonedAudioFocusRequest();
|
||||||
|
assertThat(lastRequest).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setAudioAttributes_withUsageAlarm_throwsIllegalArgumentException() {
|
public void setAudioAttributes_withUsageAlarm_throwsIllegalArgumentException() {
|
||||||
// Ensure that audio attributes that map to AUDIOFOCUS_GAIN_TRANSIENT* throw
|
// Ensure that audio attributes that map to AUDIOFOCUS_GAIN_TRANSIENT* throw
|
||||||
@ -117,7 +146,7 @@ public class AudioFocusManagerTest {
|
|||||||
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
||||||
ShadowAudioManager.AudioFocusRequest request =
|
ShadowAudioManager.AudioFocusRequest request =
|
||||||
Shadows.shadowOf(audioManager).getLastAudioFocusRequest();
|
Shadows.shadowOf(audioManager).getLastAudioFocusRequest();
|
||||||
assertThat(request.durationHint).isEqualTo(AudioManager.AUDIOFOCUS_GAIN);
|
assertThat(getAudioFocusGainFromRequest(request)).isEqualTo(AudioManager.AUDIOFOCUS_GAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -133,7 +162,7 @@ public class AudioFocusManagerTest {
|
|||||||
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
||||||
ShadowAudioManager.AudioFocusRequest request =
|
ShadowAudioManager.AudioFocusRequest request =
|
||||||
Shadows.shadowOf(audioManager).getLastAudioFocusRequest();
|
Shadows.shadowOf(audioManager).getLastAudioFocusRequest();
|
||||||
assertThat(request.durationHint).isEqualTo(AudioManager.AUDIOFOCUS_GAIN);
|
assertThat(getAudioFocusGainFromRequest(request)).isEqualTo(AudioManager.AUDIOFOCUS_GAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -189,12 +218,12 @@ public class AudioFocusManagerTest {
|
|||||||
media, /* playWhenReady= */ true, Player.STATE_READY))
|
media, /* playWhenReady= */ true, Player.STATE_READY))
|
||||||
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
||||||
|
|
||||||
ShadowAudioManager.AudioFocusRequest request =
|
audioFocusManager
|
||||||
Shadows.shadowOf(audioManager).getLastAudioFocusRequest();
|
.getFocusListener()
|
||||||
request.listener.onAudioFocusChange(AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK);
|
.onAudioFocusChange(AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK);
|
||||||
assertThat(testPlayerControl.lastVolumeMultiplier).isLessThan(1.0f);
|
assertThat(testPlayerControl.lastVolumeMultiplier).isLessThan(1.0f);
|
||||||
assertThat(testPlayerControl.lastPlayerCommand).isEqualTo(NO_COMMAND_RECEIVED);
|
assertThat(testPlayerControl.lastPlayerCommand).isEqualTo(NO_COMMAND_RECEIVED);
|
||||||
request.listener.onAudioFocusChange(AudioManager.AUDIOFOCUS_GAIN);
|
audioFocusManager.getFocusListener().onAudioFocusChange(AudioManager.AUDIOFOCUS_GAIN);
|
||||||
assertThat(testPlayerControl.lastVolumeMultiplier).isEqualTo(1.0f);
|
assertThat(testPlayerControl.lastVolumeMultiplier).isEqualTo(1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,12 +244,12 @@ public class AudioFocusManagerTest {
|
|||||||
media, /* playWhenReady= */ true, Player.STATE_READY))
|
media, /* playWhenReady= */ true, Player.STATE_READY))
|
||||||
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
||||||
|
|
||||||
ShadowAudioManager.AudioFocusRequest request =
|
audioFocusManager
|
||||||
Shadows.shadowOf(audioManager).getLastAudioFocusRequest();
|
.getFocusListener()
|
||||||
request.listener.onAudioFocusChange(AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK);
|
.onAudioFocusChange(AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK);
|
||||||
assertThat(testPlayerControl.lastPlayerCommand).isEqualTo(PLAYER_COMMAND_WAIT_FOR_CALLBACK);
|
assertThat(testPlayerControl.lastPlayerCommand).isEqualTo(PLAYER_COMMAND_WAIT_FOR_CALLBACK);
|
||||||
assertThat(testPlayerControl.lastVolumeMultiplier).isEqualTo(1.0f);
|
assertThat(testPlayerControl.lastVolumeMultiplier).isEqualTo(1.0f);
|
||||||
request.listener.onAudioFocusChange(AudioManager.AUDIOFOCUS_GAIN);
|
audioFocusManager.getFocusListener().onAudioFocusChange(AudioManager.AUDIOFOCUS_GAIN);
|
||||||
assertThat(testPlayerControl.lastPlayerCommand).isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
assertThat(testPlayerControl.lastPlayerCommand).isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,14 +266,13 @@ public class AudioFocusManagerTest {
|
|||||||
media, /* playWhenReady= */ true, Player.STATE_READY))
|
media, /* playWhenReady= */ true, Player.STATE_READY))
|
||||||
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
||||||
|
|
||||||
ShadowAudioManager.AudioFocusRequest request =
|
audioFocusManager.getFocusListener().onAudioFocusChange(AudioManager.AUDIOFOCUS_LOSS_TRANSIENT);
|
||||||
Shadows.shadowOf(audioManager).getLastAudioFocusRequest();
|
|
||||||
request.listener.onAudioFocusChange(AudioManager.AUDIOFOCUS_LOSS_TRANSIENT);
|
|
||||||
assertThat(testPlayerControl.lastVolumeMultiplier).isEqualTo(1.0f);
|
assertThat(testPlayerControl.lastVolumeMultiplier).isEqualTo(1.0f);
|
||||||
assertThat(testPlayerControl.lastPlayerCommand).isEqualTo(PLAYER_COMMAND_WAIT_FOR_CALLBACK);
|
assertThat(testPlayerControl.lastPlayerCommand).isEqualTo(PLAYER_COMMAND_WAIT_FOR_CALLBACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Config(maxSdk = 25)
|
||||||
public void onAudioFocusChange_withAudioFocusLost_sendsDoNotPlayAndAbandondsFocus() {
|
public void onAudioFocusChange_withAudioFocusLost_sendsDoNotPlayAndAbandondsFocus() {
|
||||||
// Ensure that AUDIOFOCUS_LOSS causes AudioFocusManager to pause playback and abandon audio
|
// Ensure that AUDIOFOCUS_LOSS causes AudioFocusManager to pause playback and abandon audio
|
||||||
// focus.
|
// focus.
|
||||||
@ -271,6 +299,32 @@ public class AudioFocusManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Config(minSdk = 26)
|
||||||
|
public void onAudioFocusChange_withAudioFocusLost_sendsDoNotPlayAndAbandondsFocus_v26() {
|
||||||
|
// Ensure that AUDIOFOCUS_LOSS causes AudioFocusManager to pause playback and abandon audio
|
||||||
|
// focus.
|
||||||
|
AudioAttributes media =
|
||||||
|
new AudioAttributes.Builder()
|
||||||
|
.setUsage(C.USAGE_MEDIA)
|
||||||
|
.setContentType(C.CONTENT_TYPE_SPEECH)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Shadows.shadowOf(audioManager)
|
||||||
|
.setNextFocusRequestResponse(AudioManager.AUDIOFOCUS_REQUEST_GRANTED);
|
||||||
|
assertThat(
|
||||||
|
audioFocusManager.setAudioAttributes(
|
||||||
|
media, /* playWhenReady= */ true, Player.STATE_READY))
|
||||||
|
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
||||||
|
assertThat(Shadows.shadowOf(audioManager).getLastAbandonedAudioFocusRequest()).isNull();
|
||||||
|
|
||||||
|
audioFocusManager.getFocusListener().onAudioFocusChange(AudioManager.AUDIOFOCUS_LOSS);
|
||||||
|
assertThat(testPlayerControl.lastPlayerCommand).isEqualTo(PLAYER_COMMAND_DO_NOT_PLAY);
|
||||||
|
assertThat(Shadows.shadowOf(audioManager).getLastAbandonedAudioFocusRequest())
|
||||||
|
.isEqualTo(Shadows.shadowOf(audioManager).getLastAudioFocusRequest().audioFocusRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(maxSdk = 25)
|
||||||
public void handleStop_withAudioFocus_abandonsAudioFocus() {
|
public void handleStop_withAudioFocus_abandonsAudioFocus() {
|
||||||
// Ensure that handleStop causes AudioFocusManager to abandon audio focus.
|
// Ensure that handleStop causes AudioFocusManager to abandon audio focus.
|
||||||
AudioAttributes media =
|
AudioAttributes media =
|
||||||
@ -295,6 +349,32 @@ public class AudioFocusManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Config(minSdk = 26)
|
||||||
|
public void handleStop_withAudioFocus_abandonsAudioFocus_v26() {
|
||||||
|
// Ensure that handleStop causes AudioFocusManager to abandon audio focus.
|
||||||
|
AudioAttributes media =
|
||||||
|
new AudioAttributes.Builder()
|
||||||
|
.setUsage(C.USAGE_MEDIA)
|
||||||
|
.setContentType(C.CONTENT_TYPE_SPEECH)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Shadows.shadowOf(audioManager)
|
||||||
|
.setNextFocusRequestResponse(AudioManager.AUDIOFOCUS_REQUEST_GRANTED);
|
||||||
|
assertThat(
|
||||||
|
audioFocusManager.setAudioAttributes(
|
||||||
|
media, /* playWhenReady= */ true, Player.STATE_READY))
|
||||||
|
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
||||||
|
assertThat(Shadows.shadowOf(audioManager).getLastAbandonedAudioFocusRequest()).isNull();
|
||||||
|
|
||||||
|
ShadowAudioManager.AudioFocusRequest request =
|
||||||
|
Shadows.shadowOf(audioManager).getLastAudioFocusRequest();
|
||||||
|
audioFocusManager.handleStop();
|
||||||
|
assertThat(Shadows.shadowOf(audioManager).getLastAbandonedAudioFocusRequest())
|
||||||
|
.isEqualTo(request.audioFocusRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(maxSdk = 25)
|
||||||
public void handleStop_withoutAudioFocus_stillAbandonsFocus() {
|
public void handleStop_withoutAudioFocus_stillAbandonsFocus() {
|
||||||
// Ensure that handleStop causes AudioFocusManager to call through to abandon audio focus
|
// Ensure that handleStop causes AudioFocusManager to call through to abandon audio focus
|
||||||
// even if focus wasn't requested.
|
// even if focus wasn't requested.
|
||||||
@ -320,6 +400,7 @@ public class AudioFocusManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Config(maxSdk = 25)
|
||||||
public void handleStop_withoutHandlingAudioFocus_isNoOp() {
|
public void handleStop_withoutHandlingAudioFocus_isNoOp() {
|
||||||
// Ensure that handleStop is a no-op if audio focus isn't handled.
|
// Ensure that handleStop is a no-op if audio focus isn't handled.
|
||||||
Shadows.shadowOf(audioManager)
|
Shadows.shadowOf(audioManager)
|
||||||
@ -337,6 +418,31 @@ public class AudioFocusManagerTest {
|
|||||||
assertThat(Shadows.shadowOf(audioManager).getLastAbandonedAudioFocusListener()).isNull();
|
assertThat(Shadows.shadowOf(audioManager).getLastAbandonedAudioFocusListener()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(minSdk = 26)
|
||||||
|
public void handleStop_withoutHandlingAudioFocus_isNoOp_v26() {
|
||||||
|
// Ensure that handleStop is a no-op if audio focus isn't handled.
|
||||||
|
Shadows.shadowOf(audioManager)
|
||||||
|
.setNextFocusRequestResponse(AudioManager.AUDIOFOCUS_REQUEST_GRANTED);
|
||||||
|
assertThat(
|
||||||
|
audioFocusManager.setAudioAttributes(
|
||||||
|
/* audioAttributes= */ null, /* playWhenReady= */ false, Player.STATE_READY))
|
||||||
|
.isEqualTo(PLAYER_COMMAND_DO_NOT_PLAY);
|
||||||
|
assertThat(Shadows.shadowOf(audioManager).getLastAbandonedAudioFocusRequest()).isNull();
|
||||||
|
ShadowAudioManager.AudioFocusRequest request =
|
||||||
|
Shadows.shadowOf(audioManager).getLastAudioFocusRequest();
|
||||||
|
assertThat(request).isNull();
|
||||||
|
|
||||||
|
audioFocusManager.handleStop();
|
||||||
|
assertThat(Shadows.shadowOf(audioManager).getLastAbandonedAudioFocusRequest()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getAudioFocusGainFromRequest(ShadowAudioManager.AudioFocusRequest audioFocusRequest) {
|
||||||
|
return Util.SDK_INT >= 26
|
||||||
|
? audioFocusRequest.audioFocusRequest.getFocusGain()
|
||||||
|
: audioFocusRequest.durationHint;
|
||||||
|
}
|
||||||
|
|
||||||
private static class TestPlayerControl implements AudioFocusManager.PlayerControl {
|
private static class TestPlayerControl implements AudioFocusManager.PlayerControl {
|
||||||
private float lastVolumeMultiplier = 1.0f;
|
private float lastVolumeMultiplier = 1.0f;
|
||||||
private int lastPlayerCommand = NO_COMMAND_RECEIVED;
|
private int lastPlayerCommand = NO_COMMAND_RECEIVED;
|
||||||
|
@ -1 +0,0 @@
|
|||||||
manifest=src/test/AndroidManifest.xml
|
|
@ -35,6 +35,8 @@ android {
|
|||||||
// testCoverageEnabled = true
|
// testCoverageEnabled = true
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -1 +0,0 @@
|
|||||||
manifest=src/test/AndroidManifest.xml
|
|
@ -35,6 +35,8 @@ android {
|
|||||||
// testCoverageEnabled = true
|
// testCoverageEnabled = true
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -1 +0,0 @@
|
|||||||
manifest=src/test/AndroidManifest.xml
|
|
@ -35,6 +35,8 @@ android {
|
|||||||
// testCoverageEnabled = true
|
// testCoverageEnabled = true
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -1 +0,0 @@
|
|||||||
manifest=src/test/AndroidManifest.xml
|
|
@ -34,6 +34,8 @@ android {
|
|||||||
// testCoverageEnabled = true
|
// testCoverageEnabled = true
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -1 +0,0 @@
|
|||||||
manifest=src/test/AndroidManifest.xml
|
|
@ -27,6 +27,8 @@ android {
|
|||||||
targetSdkVersion project.ext.targetSdkVersion
|
targetSdkVersion project.ext.targetSdkVersion
|
||||||
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
|
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -33,6 +33,8 @@ android {
|
|||||||
// See: https://github.com/junit-team/junit4/pull/1187.
|
// See: https://github.com/junit-team/junit4/pull/1187.
|
||||||
disable 'InvalidPackage'
|
disable 'InvalidPackage'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -1 +0,0 @@
|
|||||||
manifest=src/test/AndroidManifest.xml
|
|
@ -32,6 +32,8 @@ android {
|
|||||||
// which is not part of Android.
|
// which is not part of Android.
|
||||||
disable 'InvalidPackage'
|
disable 'InvalidPackage'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests.includeAndroidResources = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -165,7 +165,7 @@ public final class RobolectricUtil {
|
|||||||
public boolean enqueueMessage(Message msg, long when) {
|
public boolean enqueueMessage(Message msg, long when) {
|
||||||
Looper looper = ShadowLooper.getLooperForThread(looperThread);
|
Looper looper = ShadowLooper.getLooperForThread(looperThread);
|
||||||
if (shadowOf(looper) instanceof CustomLooper
|
if (shadowOf(looper) instanceof CustomLooper
|
||||||
&& shadowOf(looper) != ShadowLooper.getShadowMainLooper()) {
|
&& shadowOf(looper) != shadowOf(Looper.getMainLooper())) {
|
||||||
((CustomLooper) shadowOf(looper)).addPendingMessage(msg, when);
|
((CustomLooper) shadowOf(looper)).addPendingMessage(msg, when);
|
||||||
} else {
|
} else {
|
||||||
super.enqueueMessage(msg, when);
|
super.enqueueMessage(msg, when);
|
||||||
@ -177,7 +177,7 @@ public final class RobolectricUtil {
|
|||||||
public void removeMessages(Handler handler, int what, Object object) {
|
public void removeMessages(Handler handler, int what, Object object) {
|
||||||
Looper looper = ShadowLooper.getLooperForThread(looperThread);
|
Looper looper = ShadowLooper.getLooperForThread(looperThread);
|
||||||
if (shadowOf(looper) instanceof CustomLooper
|
if (shadowOf(looper) instanceof CustomLooper
|
||||||
&& shadowOf(looper) != ShadowLooper.getShadowMainLooper()) {
|
&& shadowOf(looper) != shadowOf(Looper.getMainLooper())) {
|
||||||
((CustomLooper) shadowOf(looper)).removeMessages(handler, what, object);
|
((CustomLooper) shadowOf(looper)).removeMessages(handler, what, object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,7 +186,7 @@ public final class RobolectricUtil {
|
|||||||
public void removeCallbacksAndMessages(Handler handler, Object object) {
|
public void removeCallbacksAndMessages(Handler handler, Object object) {
|
||||||
Looper looper = ShadowLooper.getLooperForThread(looperThread);
|
Looper looper = ShadowLooper.getLooperForThread(looperThread);
|
||||||
if (shadowOf(looper) instanceof CustomLooper
|
if (shadowOf(looper) instanceof CustomLooper
|
||||||
&& shadowOf(looper) != ShadowLooper.getShadowMainLooper()) {
|
&& shadowOf(looper) != shadowOf(Looper.getMainLooper())) {
|
||||||
((CustomLooper) shadowOf(looper)).removeMessages(handler, ANY_MESSAGE, object);
|
((CustomLooper) shadowOf(looper)).removeMessages(handler, ANY_MESSAGE, object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user