1919package androidx.window.layout
2020
2121import android.content.Context
22+ import android.content.pm.ActivityInfo
23+ import androidx.test.core.app.ActivityScenario
2224import androidx.test.core.app.ApplicationProvider
2325import androidx.test.ext.junit.runners.AndroidJUnit4
2426import androidx.test.filters.LargeTest
27+ import androidx.window.TestConfigChangeHandlingActivity
2528import androidx.window.WindowTestBase
2629import androidx.window.core.Version
2730import androidx.window.layout.ExtensionInterfaceCompat.ExtensionCallbackInterface
@@ -34,6 +37,9 @@ import com.nhaarman.mockitokotlin2.argThat
3437import com.nhaarman.mockitokotlin2.atLeastOnce
3538import com.nhaarman.mockitokotlin2.mock
3639import com.nhaarman.mockitokotlin2.verify
40+ import kotlinx.coroutines.ExperimentalCoroutinesApi
41+ import kotlinx.coroutines.test.TestCoroutineScope
42+ import kotlinx.coroutines.test.runBlockingTest
3743import org.junit.Assert.assertNotNull
3844import org.junit.Assume.assumeTrue
3945import org.junit.Before
@@ -47,6 +53,7 @@ import org.mockito.ArgumentMatcher
4753 */
4854@LargeTest
4955@RunWith(AndroidJUnit4 ::class )
56+ @OptIn(ExperimentalCoroutinesApi ::class )
5057public class SidecarCompatDeviceTest : WindowTestBase (), CompatDeviceTestInterface {
5158
5259 private lateinit var sidecarCompat: SidecarCompat
@@ -73,6 +80,49 @@ public class SidecarCompatDeviceTest : WindowTestBase(), CompatDeviceTestInterfa
7380 }
7481 }
7582
83+ @Test
84+ fun testWindowLayoutCallbackOnConfigChange () {
85+ val testScope = TestCoroutineScope ()
86+ testScope.runBlockingTest {
87+ val scenario = ActivityScenario .launch(TestConfigChangeHandlingActivity ::class .java)
88+ val callbackInterface = mock<ExtensionCallbackInterface >()
89+ scenario.onActivity { activity ->
90+ val windowToken = getActivityWindowToken(activity)
91+ assertNotNull(windowToken)
92+ sidecarCompat.setExtensionCallback(callbackInterface)
93+ sidecarCompat.onWindowLayoutChangeListenerAdded(activity)
94+ activity.resetLayoutCounter()
95+ activity.requestedOrientation = ActivityInfo .SCREEN_ORIENTATION_PORTRAIT
96+ activity.waitForLayout()
97+ }
98+ scenario.onActivity { activity ->
99+ val windowToken = getActivityWindowToken(activity)
100+ assertNotNull(windowToken)
101+ val sidecarWindowLayoutInfo =
102+ sidecarCompat.sidecar!! .getWindowLayoutInfo(windowToken)
103+ verify(callbackInterface, atLeastOnce()).onWindowLayoutChanged(
104+ any(),
105+ argThat(SidecarMatcher (sidecarWindowLayoutInfo))
106+ )
107+ }
108+ scenario.onActivity { activity ->
109+ activity.resetLayoutCounter()
110+ activity.requestedOrientation = ActivityInfo .SCREEN_ORIENTATION_LANDSCAPE
111+ activity.waitForLayout()
112+ }
113+ scenario.onActivity { activity ->
114+ val windowToken = getActivityWindowToken(activity)
115+ assertNotNull(windowToken)
116+ val updatedSidecarWindowLayoutInfo =
117+ sidecarCompat.sidecar!! .getWindowLayoutInfo(windowToken)
118+ verify(callbackInterface, atLeastOnce()).onWindowLayoutChanged(
119+ any(),
120+ argThat(SidecarMatcher (updatedSidecarWindowLayoutInfo))
121+ )
122+ }
123+ }
124+ }
125+
76126 private fun assumeExtensionV01 () {
77127 val sidecarVersion = SidecarCompat .sidecarVersion
78128 assumeTrue(Version .VERSION_0_1 == sidecarVersion)
0 commit comments