Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Test that ACTION_AUDIO_BECOMING_NOISY pause the playback.
Browse files Browse the repository at this point in the history
  • Loading branch information
padenot authored and mergify[bot] committed Apr 7, 2022
1 parent 550097e commit 82c8137
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ private class BecomingNoisyReceiver(private val controller: MediaSession.Control
controller?.pause()
}
}
@VisibleForTesting
fun deviceIsBecomingNoisy(context: Context) {
val becomingNoisyIntent = Intent(AudioManager.ACTION_AUDIO_BECOMING_NOISY)
onReceive(context, becomingNoisyIntent)
}
}

/**
Expand Down Expand Up @@ -212,4 +217,9 @@ internal class MediaSessionServiceDelegate(
mediaSession.release()
service.stopSelf()
}

@VisibleForTesting
internal fun deviceBecomingNoisy(context: Context) {
noisyAudioStreamReceiver?.deviceIsBecomingNoisy(context)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,30 @@ class MediaSessionServiceDelegateTest {
verify(service, never()).stopSelf()
verify(delegate).destroy()
}

@Test
fun `when device is becoming noisy, playback is paused`() {
val controller: MediaSession.Controller = mock()

val initialState = BrowserState(
tabs = listOf(
createTab(
"https://www.mozilla.org",
mediaSessionState = MediaSessionState(controller, playbackState = MediaSession.PlaybackState.PLAYING)
)
)
)
val store = BrowserStore(initialState)
val service: AbstractMediaSessionService = mock()
val delegate = spy(MediaSessionServiceDelegate(testContext, service, store))

delegate.onCreate()

verify(service, never()).stopSelf()
verify(delegate, never()).shutdown()

delegate.deviceBecomingNoisy(testContext)

verify(controller).pause()
}
}

0 comments on commit 82c8137

Please sign in to comment.