[Media] Add some tests in ResumeMediaBrowserTest to ensure we're

disconnecting old browsers.

Bug: 225403871
Test: atest ResumeMediaBrowserTest
Change-Id: I8706451edacf7ed530582cc034843d365401b66a
This commit is contained in:
Caitlin Cassidy
2022-05-03 20:40:36 +00:00
parent a11e1711e0
commit 4c0c32d03c

View File

@@ -27,6 +27,7 @@ import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.util.mockito.mock
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -135,6 +136,24 @@ public class ResumeMediaBrowserTest : SysuiTestCase() {
verify(callback).addTrack(eq(description), eq(component), eq(resumeBrowser))
}
@Test
fun testConnection_calledTwice_oldBrowserDisconnected() {
val oldBrowser = mock<MediaBrowser>()
whenever(browserFactory.create(any(), any(), any())).thenReturn(oldBrowser)
// When testConnection can connect to the service
setupBrowserConnection()
resumeBrowser.testConnection()
// And testConnection is called again
val newBrowser = mock<MediaBrowser>()
whenever(browserFactory.create(any(), any(), any())).thenReturn(newBrowser)
resumeBrowser.testConnection()
// Then we disconnect the old browser
verify(oldBrowser).disconnect()
}
@Test
fun testFindRecentMedia_connectionFails_error() {
// When findRecentMedia is called and we cannot connect
@@ -168,6 +187,24 @@ public class ResumeMediaBrowserTest : SysuiTestCase() {
verify(callback).onConnected()
}
@Test
fun testFindRecentMedia_calledTwice_oldBrowserDisconnected() {
val oldBrowser = mock<MediaBrowser>()
whenever(browserFactory.create(any(), any(), any())).thenReturn(oldBrowser)
// When findRecentMedia is called and we connect
setupBrowserConnection()
resumeBrowser.findRecentMedia()
// And findRecentMedia is called again
val newBrowser = mock<MediaBrowser>()
whenever(browserFactory.create(any(), any(), any())).thenReturn(newBrowser)
resumeBrowser.findRecentMedia()
// Then we disconnect the old browser
verify(oldBrowser).disconnect()
}
@Test
fun testFindRecentMedia_noChildren_error() {
// When findRecentMedia is called and we connect, but do not get any results
@@ -223,6 +260,24 @@ public class ResumeMediaBrowserTest : SysuiTestCase() {
verify(transportControls).play()
}
@Test
fun testRestart_calledTwice_oldBrowserDisconnected() {
val oldBrowser = mock<MediaBrowser>()
whenever(browserFactory.create(any(), any(), any())).thenReturn(oldBrowser)
// When restart is called and we connect successfully
setupBrowserConnection()
resumeBrowser.restart()
// And restart is called again
val newBrowser = mock<MediaBrowser>()
whenever(browserFactory.create(any(), any(), any())).thenReturn(newBrowser)
resumeBrowser.restart()
// Then we disconnect the old browser
verify(oldBrowser).disconnect()
}
/**
* Helper function to mock a failed connection
*/