1+ /*
2+ * Copyright (c) Microsoft Corporation. All rights reserved.
3+ * Licensed under the MIT License.
4+ */
5+
16package com.microsoft.device.display.samples.photoeditor
27
38import android.content.Intent
@@ -18,8 +23,12 @@ import androidx.test.rule.ActivityTestRule
1823import androidx.test.uiautomator.By
1924import androidx.test.uiautomator.UiDevice
2025import androidx.test.uiautomator.Until
21- import com.microsoft.device.dualscreen.layout.ScreenHelper
26+ import com.microsoft.device.display.samples.photoeditor.utils.ScreenInfoListenerImpl
27+ import com.microsoft.device.dualscreen.ScreenManagerProvider
2228import org.hamcrest.CoreMatchers.not
29+ import org.junit.After
30+ import org.junit.Assert
31+ import org.junit.Before
2332import org.junit.Rule
2433import org.junit.Test
2534import org.junit.runner.RunWith
@@ -34,6 +43,21 @@ import org.hamcrest.CoreMatchers.`is` as iz
3443class PhotoEditorUITest {
3544 @get:Rule
3645 val activityRule = ActivityTestRule (MainActivity ::class .java)
46+ private var screenInfoListener = ScreenInfoListenerImpl ()
47+
48+ @Before
49+ fun setup () {
50+ val screenManager = ScreenManagerProvider .getScreenManager()
51+ screenManager.addScreenInfoListener(screenInfoListener)
52+ }
53+
54+ @After
55+ fun tearDown () {
56+ val screenManager = ScreenManagerProvider .getScreenManager()
57+ screenManager.removeScreenInfoListener(screenInfoListener)
58+ screenInfoListener.resetScreenInfo()
59+ screenInfoListener.resetScreenInfoCounter()
60+ }
3761
3862 /* *
3963 * Tests visibility of controls when app spanned vs. unspanned
@@ -53,7 +77,7 @@ class PhotoEditorUITest {
5377 onView(withId(R .id.warmth)).check(matches(withEffectiveVisibility(Visibility .INVISIBLE )))
5478
5579 spanFromLeft()
56- assertThat (isSpanned(), iz( true ))
80+ waitForScreenInfoAndAssert { Assert .assertTrue (isSpanned()) }
5781
5882 // Switched to dual-screen mode, so dropdown should not exist and all sliders should be visible
5983 onView(withId(R .id.controls)).check(doesNotExist())
@@ -100,7 +124,10 @@ class PhotoEditorUITest {
100124 device.wait(Until .hasObject(By .pkg(filesPackage).depth(0 )), 3000 ) // timeout at 3 seconds
101125
102126 // Before import, drawable is equal to prev
103- assertThat(prev, iz(activityRule.activity.findViewById<ImageFilterView >(R .id.image).drawable))
127+ assertThat(
128+ prev,
129+ iz(activityRule.activity.findViewById<ImageFilterView >(R .id.image).drawable)
130+ )
104131
105132 // Hardcoded to select most recently saved file in Files app - must be an image file
106133 device.swipe(1550 , 1230 , 1550 , 1230 , 100 )
@@ -207,8 +234,13 @@ class PhotoEditorUITest {
207234 device.swipe(rightX, bottomY, rightX, middleY, closeSteps)
208235 }
209236
237+ private fun waitForScreenInfoAndAssert (assert : () -> Unit ) {
238+ screenInfoListener.waitForScreenInfoChanges()
239+ assert ()
240+ screenInfoListener.resetScreenInfo()
241+ }
242+
210243 private fun isSpanned (): Boolean {
211- onIdle() // wait until layout changes have been fully processed before checking
212- return ScreenHelper .isDualMode(activityRule.activity)
244+ return screenInfoListener.screenInfo?.isDualMode() == true
213245 }
214246}
0 commit comments