Unify configurable control surfaces and profile management

This commit is contained in:
Delete228 committed 2026-11-06 19:11:58 +03:00
1 parent aa3757eff1
commit 63004567fd
73 files changed
+5237 -5015

No files matched your search

@@ -1,7 +1,8 @@
package com.droiddeck.launcher.ui
import com.droiddeck.launcher.session.SessionDisplay
import com.droiddeck.launcher.ui.GamepadGeometry.Slot
import com.droiddeck.launcher.input.GamepadGeometry
import com.droiddeck.launcher.input.GamepadGeometry.Slot
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
@@ -1,8 +1,15 @@
package com.droiddeck.launcher.ui
import android.content.Context
import android.app.Presentation
import android.hardware.display.DisplayManager
import android.view.Display
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.test.*
import com.droiddeck.launcher.input.*
import com.droiddeck.launcher.R
import com.droiddeck.launcher.session.SessionState
import com.droiddeck.launcher.session.SessionService
import org.junit.Assert.*
import org.junit.Before
import org.junit.Rule
@@ -10,6 +17,10 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.Shadows.shadowOf
import org.robolectric.shadows.ShadowDialog
import org.robolectric.shadows.ShadowDisplayManager
import org.robolectric.util.ReflectionHelpers
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
@@ -25,11 +36,75 @@ class InputSettingsTest {
context.getSharedPreferences("controller", Context.MODE_PRIVATE).edit().clear().commit()
}
@Test fun steamAndDesktopQuickSettingsOpenTheSameInputLibrary() {
val mode = mutableStateOf(SessionService.MODE_STEAM)
var opened = 0
compose.setContent { DroidDeckTheme {
ModeSheetRows(ModeSettings(mode = mode.value, resolution = "auto", hdr = false, hdrReason = null,
touchMode = "auto", suspendPolicy = "auto", oscMode = "auto", directAudio = null, mic = null),
ModeSettingsActions(onResolution = {}, onHdr = {}, onTouch = {}, onSuspendPolicy = {}, onOsc = {},
onInputSettings = { opened++ }, onDirectAudio = {}, onMic = {}, onDismiss = {}), SheetTab.CONTROLS)
} }
compose.onNodeWithTag("input-profile-expand").performClick()
compose.onNodeWithText(context.getString(R.string.ctrl_edit)).performClick()
compose.runOnIdle { assertEquals(1, opened); mode.value = SessionService.MODE_DESKTOP }
compose.onNodeWithText(context.getString(R.string.ctrl_edit)).performClick()
compose.runOnIdle { assertEquals(2, opened) }
}
@Test fun quickMenuCombinesPartsWithoutChangingTheSavedProfile() {
val original = InputLibraries.read(context)
compose.setContent { DroidDeckTheme {
androidx.compose.foundation.layout.Column { InputQuickSettings(rememberMenuHost(), desktop = true) }
} }
compose.onNodeWithTag("setting-input-profile").assertExists()
compose.onNodeWithTag("setting-input-part-PHYSICAL").assertDoesNotExist()
compose.onNodeWithTag("input-profile-expand").performClick()
compose.onNodeWithTag("setting-input-part-PHYSICAL").assertExists()
compose.onNodeWithTag("setting-input-part-PRIMARY").assertExists()
compose.onNodeWithTag("setting-input-part-SECONDARY").performClick()
compose.onNodeWithText("Left Deck trackpad").performScrollTo().performClick()
compose.runOnIdle {
val changed = InputLibraries.read(context)
assertEquals(InputStockLayouts.LEFT, changed.activePart(true, InputRole.SECONDARY).bindings)
assertEquals(original.profiles, changed.profiles)
assertEquals(original.compileActive(false), changed.compileActive(false))
}
compose.onNodeWithText(context.getString(R.string.input_save_combination)).performClick()
compose.onNode(hasSetTextAction()).performTextInput("Reading")
compose.onNodeWithText(context.getString(R.string.gesture_save_changes)).performClick()
compose.runOnIdle {
val saved = InputLibraries.read(context)
assertEquals("Reading", saved.profile(saved.activeId(true)).name)
assertTrue(saved.selection(true).parts.isEmpty())
assertEquals(original.profile("desktop"), saved.profile("desktop"))
}
}
@Test fun actionDraftSurvivesRouteAndTypeChanges() {
var saved: InputAction? = null
compose.setContent { DroidDeckTheme { InputActionEditor(InputControl.RS, InputAction.Scroll(27f, true), "Right stick", {}, { saved = it }) } }
compose.onNodeWithText(context.getString(R.string.input_route_controller), substring = false).performClick()
compose.onNodeWithText(context.getString(R.string.input_disabled), substring = false).performClick()
compose.onNodeWithText(context.getString(R.string.input_route_local), substring = false).performClick()
compose.onNodeWithText(context.getString(R.string.input_scroll_speed, 27)).assertExists()
compose.onNodeWithTag("setting-action-type").performClick()
compose.onNodeWithText(context.getString(R.string.input_mouse_click)).performClick()
compose.onNodeWithTag("setting-action-type").performClick()
compose.onNodeWithText(context.getString(R.string.input_scroll)).performClick()
compose.onNodeWithTag("input-action-save").performClick()
compose.runOnIdle { assertEquals(InputAction.Scroll(27f, true), saved) }
}
@Test fun bindingEditorPersistsDisabledWithoutChangingTouchControls() {
var changed = false
compose.setContent { DroidDeckTheme { InputSettingsPage({}, { changed = true }) } }
compose.onNodeWithTag("input-profile-game").performScrollTo().performClick()
compose.onNodeWithTag("input-part-physical").performScrollTo().performClick()
compose.onNodeWithTag("input-binding-a").performScrollTo().performClick()
compose.onNodeWithText("Disabled", substring = false).performScrollTo().performClick()
compose.runOnIdle { assertFalse(changed) }
compose.onNodeWithTag("input-action-save").performClick()
compose.runOnIdle {
assertTrue(changed)
val profile = InputProfiles.read(context, InputProfile.GAME)
@@ -38,15 +113,240 @@ class InputSettingsTest {
}
}
@Test fun customLayoutAddsExistingControlAndKeepsProfileBindings() {
@Test fun addingCreatesAnUnassignedElementAtTheCanvasCenterWithoutAnotherTouch() {
var changed = false
compose.setContent { DroidDeckTheme { InputSurfaceDialog(InputProfile.GAME, {}, { changed = true }) } }
compose.onNodeWithText("Add control").performScrollTo().performClick()
compose.onNodeWithText("R1", substring = false).performScrollTo().performClick()
compose.onNodeWithText("Save changes").performClick()
val library = InputLibraries.read(context)
val layout = library.layout(InputProfile.GAME, InputRole.SECONDARY)!!
compose.setContent { DroidDeckTheme { InputSurfaceDialog(InputProfile.GAME, {}, { changed = true },
role = InputRole.PRIMARY, layoutId = layout.id, bindingsId = library.profile(InputProfile.GAME).binding(InputRole.SECONDARY)) } }
compose.onNodeWithTag("input-editor-tools").performClick()
compose.onNodeWithText(context.getString(R.string.input_editor_add)).performClick()
compose.onNodeWithText(context.getString(R.string.input_element_button), substring = false).performClick()
compose.onNodeWithTag("input-editor-tools").performClick()
compose.onNodeWithText(context.getString(R.string.input_properties)).assertExists()
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performClick()
compose.runOnIdle {
assertTrue(changed)
assertTrue(InputSurfaceLayout.read(context, InputProfile.GAME).any { it.control == InputControl.RB })
val updated = InputLibraries.read(context)
val added = updated.layout(InputProfile.GAME, InputRole.SECONDARY)!!.elements.single { e -> layout.elements.none { it.id == e.id } }
assertEquals(InputAction.Disabled, updated.compile(InputProfile.GAME).elementAction(InputRole.SECONDARY, added.id, added.control))
assertEquals(.5f, added.x + added.width / 2, .01f)
}
}
@Test fun aNewProfileIsIndependentAndDoesNotBecomeActive() {
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
compose.onNodeWithText(context.getString(R.string.input_new_profile)).performScrollTo().performClick()
compose.onNodeWithTag("input-name").performTextInput("Minecraft")
compose.onNodeWithText(context.getString(R.string.gesture_save_changes)).performClick()
compose.runOnIdle {
val library = InputLibraries.read(context)
val created = library.profiles.single { it.name == "Minecraft" }
for (role in InputRole.entries) assertNotEquals(library.profile(InputProfile.GAME).binding(role), created.binding(role))
assertNotEquals(library.layout(InputProfile.GAME, InputRole.SECONDARY)!!.id, library.layout(created.id, InputRole.SECONDARY)!!.id)
assertEquals(InputProfiles.AUTO, library.selected)
}
}
@Test fun openingAProfileDoesNotActivateItAndBackKeepsItsContext() {
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
compose.onNodeWithTag("input-profile-desktop").performScrollTo().performClick()
compose.onNodeWithTag("input-part-physical").performScrollTo().performClick()
compose.onNodeWithTag("input-binding-a").performScrollTo().performClick()
compose.onNodeWithTag("input-action-save").performClick()
compose.onNodeWithTag("input-binding-a").assertExists()
compose.onNodeWithText(context.getString(R.string.mode_back)).performClick()
compose.onNodeWithTag("input-part-secondary").assertExists()
compose.runOnIdle { assertEquals(InputProfiles.AUTO, InputLibraries.read(context).selected) }
}
@Test fun profileCreationCanExplicitlyShareOnlyPhysicalControls() {
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
compose.onNodeWithText(context.getString(R.string.input_new_profile)).performScrollTo().performClick()
compose.onNodeWithTag("input-name").performTextInput("Shared controls")
compose.onNodeWithTag("input-share-physical").performClick()
compose.onNodeWithText(context.getString(R.string.gesture_save_changes)).performClick()
compose.runOnIdle {
val library = InputLibraries.read(context)
val created = library.profiles.single { it.name == "Shared controls" }
assertEquals(library.profile("game").binding(InputRole.PHYSICAL), created.binding(InputRole.PHYSICAL))
assertNotEquals(library.profile("game").binding(InputRole.SECONDARY), created.binding(InputRole.SECONDARY))
}
}
@Test fun hidingEditorToolsPreservesPlacedElements() {
val library = InputLibraries.read(context)
val layout = library.layout("game", InputRole.SECONDARY)!!
compose.setContent { DroidDeckTheme { InputSurfaceDialog("game", {}, {}, role = InputRole.PRIMARY,
layoutId = layout.id, bindingsId = library.profile("game").binding(InputRole.SECONDARY)) } }
compose.onNodeWithTag("input-editor-tools").performClick()
compose.onNodeWithText(context.getString(R.string.input_editor_add)).performClick()
compose.onNodeWithText(context.getString(R.string.input_element_button)).performClick()
compose.onNodeWithTag("input-layout-canvas").performTouchInput { click(center) }
compose.onNodeWithTag("input-editor-tools").performClick()
compose.onNodeWithText(context.getString(R.string.input_hide_tools)).performClick()
compose.onNodeWithText(context.getString(R.string.input_editor_add)).assertDoesNotExist()
compose.onNodeWithTag("input-editor-tools").performClick()
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performClick()
compose.runOnIdle { assertEquals(layout.elements.size + 1, InputLibraries.read(context).layout("game", InputRole.SECONDARY)!!.elements.size) }
}
@Test fun localToolsCanMoveAndExpandWithoutMovingTheCanvas() {
val library = InputLibraries.read(context)
compose.setContent { DroidDeckTheme { InputSurfaceDialog("game", {}, {}, role = InputRole.PRIMARY,
layoutId = library.layout("game", InputRole.SECONDARY)!!.id, bindingsId = library.profile("game").binding(InputRole.SECONDARY)) } }
compose.runOnIdle {
val window = ShadowDialog.getLatestDialog().window!!
assertEquals(android.view.WindowManager.LayoutParams.MATCH_PARENT, window.attributes.width)
assertEquals(android.view.WindowManager.LayoutParams.MATCH_PARENT, window.attributes.height)
}
val canvas = compose.onNodeWithTag("input-layout-canvas").fetchSemanticsNode().boundsInRoot
val before = compose.onNodeWithTag("input-editor-tools").fetchSemanticsNode().boundsInRoot
compose.onNodeWithTag("input-editor-tools").performTouchInput { swipe(center, center + androidx.compose.ui.geometry.Offset(250f, 150f), 500) }
val after = compose.onNodeWithTag("input-editor-tools").fetchSemanticsNode().boundsInRoot
assertTrue(after.left > before.left + 100f)
compose.onNodeWithTag("input-editor-tools").performClick()
compose.onNodeWithText(context.getString(R.string.input_editor_add)).assertIsDisplayed()
assertEquals(canvas, compose.onNodeWithTag("input-layout-canvas").fetchSemanticsNode().boundsInRoot)
compose.onNodeWithTag("input-editor-tools").performClick()
compose.onNodeWithText(context.getString(R.string.input_editor_add)).assertDoesNotExist()
}
@Test fun deckPresetOffersItsRealElementsAndTheCommonEditor() {
InputLibraries.update(context) { it.useLayout("game", InputRole.SECONDARY, InputLibraries.DECK, shared = true) }
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
compose.onNodeWithTag("input-profile-game").performScrollTo().performClick()
compose.onNodeWithTag("input-part-secondary").performScrollTo().performClick()
compose.onNodeWithTag("input-element-legacy:l4").performScrollTo().assertIsDisplayed()
compose.onNodeWithTag("input-binding-a").assertDoesNotExist()
}
@Test fun mouseTrackpadPresetIsEditableLikeAnyOtherLayout() {
InputLibraries.update(context) { it.useLayout("game", InputRole.SECONDARY, InputLibraries.TRACKPAD, shared = true) }
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
compose.onNodeWithTag("input-profile-game").performScrollTo().performClick()
compose.onNodeWithTag("input-part-secondary").performScrollTo().performClick()
compose.onNodeWithTag("input-element-legacy:right-pad").performScrollTo().assertIsDisplayed()
compose.onNodeWithTag("input-surface-secondary").performScrollTo().assertIsDisplayed()
compose.onNodeWithTag("input-binding-a").assertDoesNotExist()
}
@Test fun primaryScreenOffersItsActualElementsAndTheCommonEditor() {
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
compose.onNodeWithTag("input-profile-game").performScrollTo().performClick()
compose.onNodeWithTag("input-part-primary").performScrollTo().performClick()
compose.onNodeWithTag("input-element-legacy:a").performScrollTo().assertIsDisplayed()
compose.onNodeWithTag("input-binding-a").assertDoesNotExist()
compose.onNodeWithTag("input-surface-primary").performScrollTo().performClick()
compose.onNodeWithTag("input-editor-tools").performClick()
compose.onNodeWithText(context.getString(R.string.input_editor_add)).assertIsDisplayed()
compose.onNodeWithTag("input-layout-canvas").assertExists()
}
@Test fun deviceSettingsAreInlineBelowProfiles() {
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
compose.onNodeWithTag("input-more").assertDoesNotExist()
compose.onNodeWithText(context.getString(R.string.ctrl_dead_zone)).performScrollTo().assertIsDisplayed()
compose.onNodeWithTag("input-profile-game").performScrollTo().assertIsDisplayed()
}
@Test fun migratedPadClicksRemainEditableWithoutChangingMovement() {
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
compose.onNodeWithTag("input-profile-desktop").performScrollTo().performClick()
compose.onNodeWithTag("input-part-secondary").performScrollTo().performClick()
compose.onNodeWithTag("input-click-legacy:right-pad").performScrollTo().performClick()
compose.onNodeWithText("Disabled", substring = false).performScrollTo().performClick()
compose.onNodeWithTag("input-action-save").performClick()
compose.runOnIdle {
val library = InputLibraries.read(context)
val pad = library.layout("desktop", InputRole.SECONDARY)!!.elements.first { it.control == InputControl.RIGHT_PAD }
val profile = library.compile("desktop")
assertEquals(InputAction.Disabled, profile.elementClickAction(InputRole.SECONDARY, pad))
assertEquals(InputAction.Pointer(), profile.elementAction(InputRole.SECONDARY, pad.id, pad.control))
}
}
@Test @Config(sdk = [34]) fun secondarySettingsCanOpenAnActivityDialogAndCloseCleanly() {
val displayId = ShadowDisplayManager.addDisplay("w640dp-h480dp", ReflectionHelpers.getStaticField<Int>(Display::class.java, "TYPE_EXTERNAL"))
val display = context.getSystemService(DisplayManager::class.java).getDisplay(displayId)
shadowOf(display).setFlags(Display.FLAG_PRESENTATION)
val open = mutableStateOf(true)
try {
compose.setContent { DroidDeckTheme {
val host = androidx.compose.ui.platform.LocalContext.current.findActivity() as androidx.activity.ComponentActivity
if (open.value) InputDisplayContent(host, display, { open.value = false }) { InputSettingsPage({ open.value = false }) }
} }
compose.onNodeWithText(context.getString(R.string.input_new_profile)).performScrollTo().performClick()
compose.onNodeWithTag("input-name").assertExists()
compose.runOnIdle {
assertTrue(ShadowDialog.getShownDialogs().filterIsInstance<Presentation>().any { it.isShowing && it.display.displayId == displayId })
val dialog = ShadowDialog.getShownDialogs().last { it !is Presentation && it.isShowing }
assertEquals(Display.DEFAULT_DISPLAY, dialog.window?.decorView?.display?.displayId)
open.value = false
}
compose.runOnIdle { assertTrue(ShadowDialog.getShownDialogs().none { it.isShowing }) }
} finally { ShadowDisplayManager.removeDisplay(displayId) }
}
@Test @Config(sdk = [34]) fun mainEditorOpenedFromSecondarySettingsUsesAnActivityWindow() {
val displayId = ShadowDisplayManager.addDisplay("w640dp-h480dp", ReflectionHelpers.getStaticField<Int>(Display::class.java, "TYPE_EXTERNAL"))
val display = context.getSystemService(DisplayManager::class.java).getDisplay(displayId)
shadowOf(display).setFlags(Display.FLAG_PRESENTATION)
val open = mutableStateOf(true)
try {
compose.setContent { DroidDeckTheme {
val host = androidx.compose.ui.platform.LocalContext.current.findActivity() as androidx.activity.ComponentActivity
if (open.value) InputDisplayContent(host, display, { open.value = false }) {
InputSurfaceDialog("game", { open.value = false }, {}, role = InputRole.PRIMARY)
}
} }
compose.onNodeWithTag("input-layout-canvas").assertExists()
compose.runOnIdle {
assertTrue(ShadowDialog.getShownDialogs().none { it is Presentation && it.display.displayId == Display.DEFAULT_DISPLAY })
val editor = ShadowDialog.getShownDialogs().last { it !is Presentation && it.isShowing }
assertEquals(Display.DEFAULT_DISPLAY, editor.window?.decorView?.display?.displayId)
open.value = false
}
compose.runOnIdle { assertTrue(ShadowDialog.getShownDialogs().none { it.isShowing }) }
} finally { ShadowDisplayManager.removeDisplay(displayId) }
}
@Test @Config(sdk = [34]) fun auxiliaryEditorUsesThatDisplayAndSurvivesItsRemoval() {
val displayId = ShadowDisplayManager.addDisplay("w640dp-h480dp", ReflectionHelpers.getStaticField<Int>(Display::class.java, "TYPE_EXTERNAL"))
val display = context.getSystemService(DisplayManager::class.java).getDisplay(displayId)
shadowOf(display).setFlags(Display.FLAG_PRESENTATION)
assertTrue(SecondScreenDisplays.available(context.getSystemService(DisplayManager::class.java)).any { it.id == displayId })
val previous = SessionState.secondScreenDisplay
SessionState.secondScreenDisplay = displayId
val open = mutableStateOf(true)
try {
compose.setContent { DroidDeckTheme { if (open.value) InputSurfaceDialog("game", { open.value = false }, {}) } }
compose.onNodeWithText(context.getString(R.string.input_editor_remote)).assertExists()
compose.onAllNodesWithText(context.getString(R.string.input_editor_add)).assertCountEquals(1)
compose.onNodeWithText(context.getString(R.string.input_hide_tools)).assertDoesNotExist()
assertEquals(0f, compose.onNodeWithTag("input-layout-canvas").fetchSemanticsNode().boundsInRoot.top, 1f)
compose.runOnIdle {
assertTrue(ShadowDialog.getShownDialogs().filterIsInstance<Presentation>().any { it.isShowing && it.display.displayId == displayId })
}
compose.onNodeWithTag("input-layout-canvas").performTouchInput { click(percentOffset(.25f, .25f)) }
compose.onAllNodesWithText(context.getString(R.string.input_properties)).onFirst().performClick()
compose.onNodeWithTag("input-action-save").assertIsDisplayed()
compose.onNodeWithText("Disabled", substring = false).performScrollTo().performClick()
compose.runOnIdle {
assertTrue(ShadowDialog.getShownDialogs().any { it !is Presentation && it.isShowing && it.window?.decorView?.display?.displayId == Display.DEFAULT_DISPLAY })
ShadowDisplayManager.removeDisplay(displayId)
}
compose.onNodeWithTag("input-action-save").assertIsDisplayed()
compose.onNodeWithTag("input-action-save").performClick()
compose.onNodeWithText(context.getString(R.string.input_display_unavailable)).assertExists()
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performScrollTo().performClick()
compose.runOnIdle {
assertFalse(open.value)
assertEquals(InputAction.Disabled, InputProfiles.read(context, "game").elementAction(InputRole.SECONDARY, "legacy:left-pad", InputControl.LEFT_PAD))
}
} finally {
SessionState.secondScreenDisplay = previous
if (display.isValid) ShadowDisplayManager.removeDisplay(displayId)
}
}
}
@@ -0,0 +1,120 @@
package com.droiddeck.launcher.ui
import android.os.Looper
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import androidx.activity.ComponentActivity
import com.droiddeck.launcher.input.*
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
import java.time.Duration
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], shadows = [JoyConPadTest.RecordingWriter::class])
class InputSurfaceGesturesTest {
private val controller = Robolectric.buildActivity(ComponentActivity::class.java).setup()
private val activity = controller.get()
private val events = mutableListOf<String>()
private val moves = mutableListOf<Pair<Float, Float>>()
private val bridge = PadBridge(activity.cacheDir)
private val router = InputRouter(object : InputOutput {
override fun key(code: Int, down: Boolean) { events += "key:$code:$down" }
override fun button(code: Int, down: Boolean) { events += "button:$code:$down" }
override fun pointer(dx: Float, dy: Float) { moves += dx to dy }
override fun scroll(steps: Int) { events += "scroll:$steps" }
override fun command(command: InputCommand) {}
override fun requestMotion() { error("Touchpad must not schedule stick frames") }
})
private lateinit var panel: InputSurfaceView
private lateinit var pad: View
private var time = 1000L
private val element = InputSurfaceElement(InputControl.RIGHT_PAD, 0f, 0f, 1f, 1f, mouseGestures = true)
private fun profile(action: InputAction = InputAction.Pointer()) = InputProfile("test",
elements = mapOf(InputRole.SECONDARY to mapOf(element.id to action)),
clicks = mapOf(InputRole.SECONDARY to mapOf(element.id to InputAction.MouseButton(272))))
@Before fun setup() {
bridge.setInputRouter(router)
bridge.setInputProfile(profile())
panel = InputSurfaceView(activity, bridge, listOf(element))
activity.setContentView(panel)
panel.measure(View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(600, View.MeasureSpec.EXACTLY))
panel.layout(0, 0, 1000, 600)
pad = descendants(panel).first { it.javaClass.simpleName == "TrackpadView" }
}
@After fun close() { panel.releaseInputs(); bridge.stop(); controller.pause().stop().destroy() }
@Test fun tapClicksWithoutRepositioningCursorFromAnotherSource() {
touch(MotionEvent.ACTION_DOWN); touch(MotionEvent.ACTION_UP)
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(100))
assertEquals(listOf("button:272:true", "button:272:false"), events)
assertTrue(moves.isEmpty())
val other = router.channel(InputRole.PHYSICAL, InputControl.LS, fixedAction = InputAction.Pointer())
other.update(0f, 0f, true); other.pointerDelta(.1f, .2f); other.update(0f)
val positionChanges = moves.toList()
time += 1000
touch(MotionEvent.ACTION_DOWN); touch(MotionEvent.ACTION_UP)
assertEquals(positionChanges, moves)
other.close()
}
@Test fun tapUsesTheConfiguredElementClick() {
bridge.setInputProfile(profile().copy(clicks = mapOf(InputRole.SECONDARY to mapOf(element.id to InputAction.Keys(listOf(57))))))
touch(MotionEvent.ACTION_DOWN); touch(MotionEvent.ACTION_UP)
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(100))
assertEquals(listOf("key:57:true", "key:57:false"), events)
}
@Test fun motionDeliversImmediatelyAndTwoFingerScrollDoesNotMoveThePointer() {
touch(MotionEvent.ACTION_DOWN)
touch(MotionEvent.ACTION_MOVE, y = 230f)
assertTrue(moves.isNotEmpty())
touch(MotionEvent.ACTION_UP)
time += 1000
touch(MotionEvent.ACTION_DOWN)
touch(MotionEvent.ACTION_POINTER_DOWN or (1 shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), fingers = 2)
val before = moves.size
touch(MotionEvent.ACTION_MOVE, y = 270f, fingers = 2)
assertEquals(before, moves.size)
assertTrue(events.any { it.startsWith("scroll:") })
}
@Test fun profileChangeAndMenuSuspensionSuppressPendingGesturePresses() {
touch(MotionEvent.ACTION_DOWN)
bridge.setInputEnabled(false)
bridge.setInputEnabled(true)
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(1000))
assertTrue(events.isEmpty())
touch(MotionEvent.ACTION_CANCEL)
time += 1000
touch(MotionEvent.ACTION_DOWN)
bridge.setInputProfile(profile(InputAction.Disabled))
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(1000))
assertTrue(events.isEmpty())
panel.releaseInputs()
bridge.setInputProfile(profile())
time += 1000
touch(MotionEvent.ACTION_DOWN); touch(MotionEvent.ACTION_UP)
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(100))
assertEquals(listOf("button:272:true", "button:272:false"), events)
}
private fun touch(action: Int, y: Float = 200f, fingers: Int = 1) {
val properties = Array(fingers) { i -> MotionEvent.PointerProperties().apply { id = i; toolType = MotionEvent.TOOL_TYPE_FINGER } }
val coords = Array(fingers) { i -> MotionEvent.PointerCoords().apply { x = 200f + 100 * i; this.y = y; pressure = 1f; size = 1f } }
val event = MotionEvent.obtain(time - 20, time, action, fingers, properties, coords, 0, 0, 1f, 1f, 0, 0, 0, 0)
try { assertTrue(pad.onTouchEvent(event)) } finally { event.recycle(); time += 10 }
}
private fun descendants(view: View): Sequence<View> = sequence {
yield(view)
if (view is ViewGroup) for (i in 0 until view.childCount) yieldAll(descendants(view.getChildAt(i)))
}
}
@@ -7,7 +7,7 @@ import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.TextView
import com.droiddeck.launcher.R
import com.droiddeck.launcher.input.DeckControls
import com.droiddeck.launcher.input.*
import com.droiddeck.launcher.input.JoyConPadTest
import com.droiddeck.launcher.input.PadBridge
import com.droiddeck.launcher.input.PadState
@@ -25,23 +25,32 @@ import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], shadows = [JoyConPadTest.RecordingWriter::class])
class DeckControlsPanelOwnershipTest {
class InputSurfaceOwnershipTest {
private val controller = Robolectric.buildActivity(ComponentActivity::class.java).setup()
private val activity = controller.get()
private val root = FrameLayout(activity)
private val bridge = PadBridge(File(activity.cacheDir, "panel-ownership"))
private lateinit var panel: DeckControlsPanel
private lateinit var panel: InputSurfaceView
private val previousDeckPad = SessionState.deckPad
@Before fun setUp() {
SessionState.deckPad = true
DeckControls.releaseAll()
SessionPrefs.setGamepadSurface(activity, false, SessionPrefs.SURFACE_STICK)
SessionPrefs.setGamepadSurface(activity, true, SessionPrefs.SURFACE_TRACKPAD)
bridge.setInputRouter(InputRouter(object : InputOutput {
override fun key(code: Int, down: Boolean) {}
override fun button(code: Int, down: Boolean) {}
override fun pointer(dx: Float, dy: Float) {}
override fun scroll(steps: Int) {}
override fun command(command: InputCommand) {}
override fun requestMotion() {}
}))
val elements = listOf(InputControl.RIGHT_PAD, InputControl.LS, InputControl.A).mapIndexed { i, c ->
InputSurfaceElement(c, .02f + i * .3f, .1f, .28f, .4f)
} + InputSurfaceElement(InputControl.LS, .02f, .6f, .28f, .3f, "dpad", InputElementKind.DPAD)
bridge.setInputProfile(InputProfile("native", elements = mapOf(InputRole.SECONDARY to mapOf("dpad" to InputAction.Native()))))
activity.setContentView(root)
panel = DeckControlsPanel(activity, {}, {}, {}, bridge)
panel = InputSurfaceView(activity, bridge, elements)
root.addView(panel)
descendants(panel).filterIsInstance<TextView>().first { it.text == activity.getString(R.string.deck_tab_gamepad) }.performClick()
val trackpad = child("TrackpadView")
trackpad.layout(0, 0, 300, 300)
touch(trackpad, MotionEvent.ACTION_DOWN, 200f, 100f)
@@ -57,14 +66,14 @@ class DeckControlsPanelOwnershipTest {
SessionState.deckPad = previousDeckPad
}
@Test fun switchingTheOtherStickKeepsTrackpadContactAndClickHeld() {
@Test fun removingTheStickKeepsTrackpadContactAndClickHeld() {
val stick = child("StickView")
stick.layout(0, 0, 300, 300)
touch(stick, MotionEvent.ACTION_DOWN, 150f, 150f)
touch(stick, MotionEvent.ACTION_MOVE, 240f, 150f)
assertTrue(state().leftX > 0f)
val position = JoyConPadTest.RecordingWriter.deckPads.copyOf()
descendants(stick.parent as View).first { it.contentDescription == activity.getString(R.string.deck_surface_switch) }.performClick()
(stick.parent as ViewGroup).removeView(stick)
assertEquals(0f, state().leftX)
assertTrackpadStillHeld(position)
root.removeView(panel)
@@ -82,8 +91,8 @@ class DeckControlsPanelOwnershipTest {
assertTrackpadStillHeld(position)
}
@Test fun removingFaceButtonsReleasesOnlyTheirOwnInput() {
val buttons = child("FaceButtons")
@Test fun removingAButtonReleasesOnlyItsOwnInput() {
val buttons = child("HoldButton")
buttons.layout(0, 0, 300, 300)
touch(buttons, MotionEvent.ACTION_DOWN, 150f, 240f)
assertTrue(state().isDown(PadState.A))
@@ -93,49 +102,31 @@ class DeckControlsPanelOwnershipTest {
assertTrackpadStillHeld(position)
}
@Test fun switchingTabsRemovesTheOldTouchSourceAfterChildrenRelease() {
val routed = recordTouchRoute()
@Test fun replacingTheLayoutReleasesEveryOldControl() {
holdFaceButton()
assertTrue(routed.last().isDown(PadState.A))
descendants(panel).filterIsInstance<TextView>().first { it.text == activity.getString(R.string.deck_tab_grips) }.performClick()
assertFalse(routed.last().isDown(PadState.A))
assertTrue(state().isDown(PadState.A))
panel.updateCustomLayout(emptyList())
assertFalse(state().isDown(PadState.A))
assertEquals(0, JoyConPadTest.RecordingWriter.grips)
routed.clear()
bridge.applyExternal({ it.press(PadState.B, true) }, true)
assertTrue("removed tab still forwards a neutral touch source", routed.isEmpty())
assertTrue(state().isDown(PadState.B))
descendants(panel).filterIsInstance<TextView>().first { it.text == activity.getString(R.string.deck_tab_gamepad) }.performClick()
holdFaceButton()
assertTrue(routed.last().isDown(PadState.A))
assertFalse(state().isDown(PadState.A))
}
@Test fun removingThePanelLeavesNoTouchSourceForLaterPhysicalInput() {
val routed = recordTouchRoute()
holdFaceButton()
root.removeView(panel)
assertFalse(routed.last().isDown(PadState.A))
routed.clear()
assertFalse(state().isDown(PadState.A))
bridge.applyExternal({ it.press(PadState.B, true) }, true)
assertTrue("removed panel still forwards a neutral touch source", routed.isEmpty())
assertTrue(state().isDown(PadState.B))
}
private fun holdFaceButton() {
val buttons = child("FaceButtons")
val buttons = child("HoldButton")
buttons.layout(0, 0, 300, 300)
touch(buttons, MotionEvent.ACTION_DOWN, 150f, 240f)
}
private fun recordTouchRoute(): MutableList<PadState> {
val routed = mutableListOf<PadState>()
bridge.setTouchRoute(object : PadBridge.TouchRoute {
override fun active() = true
override fun accept(state: PadState) { routed += PadState().apply { copyFrom(state) } }
})
return routed
}
private fun assertTrackpadStillHeld(position: ShortArray) {
assertEquals(32 or 128, JoyConPadTest.RecordingWriter.grips)
assertArrayEquals(position, JoyConPadTest.RecordingWriter.deckPads)
@@ -4,6 +4,8 @@ import android.content.ComponentName
import android.view.MotionEvent
import androidx.activity.ComponentActivity
import android.view.View
import android.widget.FrameLayout
import com.droiddeck.launcher.input.*
import com.droiddeck.launcher.input.JoyConPadTest
import com.droiddeck.launcher.input.PadBridge
import com.droiddeck.launcher.session.SessionState
@@ -20,8 +22,42 @@ import java.nio.file.Files
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], manifest = Config.NONE, instrumentedPackages = ["com.droiddeck.launcher.input.FakeInputWriter"],
shadows = [JoyConPadTest.RecordingWriter::class])
class DeckControlsPanelTest {
shadows = [JoyConPadTest.RecordingWriter::class, SessionInputPointerTest.CompositorShadow::class])
class InputSurfaceViewTest {
@Test fun customControlsReleaseOnDetachAndWorkWhenTheSameViewReturns() {
val controller = Robolectric.buildActivity(ComponentActivity::class.java).setup()
val activity = controller.get()
val events = mutableListOf<Boolean>()
val bridge = PadBridge(activity.cacheDir)
val router = InputRouter(object : InputOutput {
override fun key(code: Int, down: Boolean) { events += down }
override fun button(code: Int, down: Boolean) {}
override fun pointer(dx: Float, dy: Float) {}
override fun scroll(steps: Int) {}
override fun command(command: InputCommand) {}
override fun requestMotion() {}
})
bridge.setInputRouter(router)
bridge.setInputProfile(InputProfile("test", elements = mapOf(InputRole.SECONDARY to mapOf("one" to InputAction.Keys(listOf(57))))))
val root = FrameLayout(activity)
activity.setContentView(root)
val panel = InputSurfaceView(activity, bridge,
listOf(InputSurfaceElement(InputControl.A, .2f, .2f, .2f, .2f, "one")))
try {
repeat(2) {
root.addView(panel)
panel.measure(View.MeasureSpec.makeMeasureSpec(600, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(600, View.MeasureSpec.EXACTLY))
panel.layout(0, 0, 600, 600)
val down = MotionEvent.obtain(0, 1, MotionEvent.ACTION_DOWN, 150f, 150f, 0)
try { assertTrue(panel.dispatchTouchEvent(down)) } finally { down.recycle() }
assertEquals(true, events.last())
root.removeView(panel)
assertEquals(false, events.last())
}
assertEquals(listOf(true, false, true, false), events)
} finally { root.removeAllViews(); bridge.stop(); controller.pause().stop().destroy() }
}
@Test fun takesTouchAtMatchesWhatATouchDoes() {
val directory = Files.createTempDirectory("deck-panel").toFile()
try {
@@ -29,12 +65,10 @@ class DeckControlsPanelTest {
val app = RuntimeEnvironment.getApplication()
shadowOf(app.packageManager).addActivityIfNotPresent(ComponentName(app, ComponentActivity::class.java))
val activity = Robolectric.buildActivity(ComponentActivity::class.java).setup().get()
for (pad in listOf(null, PadBridge(directory))) for (portraitDock in listOf(false, true)) {
for (pad in listOf(null, PadBridge(directory))) for (portraitDock in listOf(false, true)) for (layout in InputStockLayouts.layouts()) {
val name = "pad=${pad != null} portraitDock=$portraitDock"
val panel = DeckControlsPanel(activity, onClose = {}, onSteamMenu = {}, onQam = {},
pad = pad, portraitDock = portraitDock)
val panel = InputSurfaceView(activity, pad, layout.elements)
activity.setContentView(panel)
assertEquals(name, pad == null, panel.deckControls)
val (w, h) = if (portraitDock) 720 to 1000 else 1200 to 480
panel.measure(View.MeasureSpec.makeMeasureSpec(w, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(h, View.MeasureSpec.EXACTLY))
@@ -0,0 +1,131 @@
package com.droiddeck.launcher.ui
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.view.View
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.material3.Surface
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.semantics.SemanticsActions
import androidx.compose.ui.test.*
import androidx.compose.ui.unit.dp
import com.droiddeck.launcher.R
import com.droiddeck.launcher.input.ControllerPrefs
import com.droiddeck.launcher.input.InputLibraries
import com.droiddeck.launcher.input.InputProfiles
import org.junit.Assert.assertEquals
import com.droiddeck.launcher.input.InputAction
import com.droiddeck.launcher.input.InputControl
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
import java.io.File
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28])
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class InputUiLayoutTest {
@get:Rule val compose = createRobolectricComposeRule()
private lateinit var root: View
@Before fun reset() {
val context = RuntimeEnvironment.getApplication()
for (name in listOf("input-profiles", "input-surfaces", "controller")) context.getSharedPreferences(name, Context.MODE_PRIVATE).edit().clear().commit()
}
@Test fun layoutThumbnailDoesNotPaintOverItsRowOrAdjacentControls() {
val context = RuntimeEnvironment.getApplication()
val library = InputLibraries.read(context)
val preview = InputLayoutPreviewView(context)
preview.update(library.layout("game", com.droiddeck.launcher.input.InputRole.SECONDARY)!!, com.droiddeck.launcher.input.InputRole.SECONDARY)
preview.measure(View.MeasureSpec.makeMeasureSpec(112, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(76, View.MeasureSpec.EXACTLY))
preview.layout(0, 0, 112, 76)
val bitmap = Bitmap.createBitmap(240, 160, Bitmap.Config.ARGB_8888)
bitmap.eraseColor(android.graphics.Color.MAGENTA)
preview.draw(Canvas(bitmap))
assertEquals(android.graphics.Color.MAGENTA, bitmap.getPixel(150, 30))
assertEquals(android.graphics.Color.MAGENTA, bitmap.getPixel(30, 120))
bitmap.recycle()
}
@Test @Config(qualifiers = "w360dp-h800dp")
fun phoneKeepsLibraryNavigationAndProfileEditingReachable() {
compose.setContent { root = LocalView.current; DroidDeckTheme { Surface { BoxWithConstraints {
CompositionLocalProvider(LocalNarrowPane provides (maxWidth < 600.dp)) { InputSettingsPage({}) }
} } } }
compose.onNodeWithTag("input-profile-desktop").performScrollTo().assertIsDisplayed().performClick()
compose.onNodeWithTag("input-part-physical").performScrollTo().assertIsDisplayed().performClick()
compose.onNodeWithTag("input-binding-a").performScrollTo().assertIsDisplayed().performClick()
compose.onNodeWithTag("input-action-save").assertIsDisplayed()
screenshot("phone-properties")
}
@Test @Config(qualifiers = "w640dp-h360dp")
fun handheldPropertiesLeaveSaveVisibleAboveScrollableContent() {
compose.setContent { root = LocalView.current; DroidDeckTheme { Surface { InputActionEditor(InputControl.LS, InputAction.Pointer(), "Left stick", {}, {}) } } }
compose.onNodeWithTag("input-action-save").assertIsDisplayed()
compose.onNode(SemanticsMatcher.keyIsDefined(SemanticsActions.SetProgress)).performScrollTo().assertIsDisplayed()
screenshot("handheld-properties")
}
@Test @Config(qualifiers = "w960dp-h600dp")
fun largeScreenShowsTheProfileLibraryInTheExistingTheme() {
compose.setContent { root = LocalView.current; DroidDeckTheme { Surface { InputSettingsPage({}) } } }
compose.onNodeWithTag("input-profile-game").assertIsDisplayed()
screenshot("profiles")
}
@Test @Config(qualifiers = "w960dp-h600dp")
fun controllerTabKeepsSetupNavigationWithoutDuplicateEditors() {
val context = RuntimeEnvironment.getApplication()
compose.setContent {
root = LocalView.current
DroidDeckTheme {
CompositionLocalProvider(LocalFrontFocus provides FrontFocus(), LocalNarrowPane provides false) {
FocusGlideHost {
SetupPanel(FrontEndState(
installed = null, ready = false, available = null, busy = false, stage = "", percent = -1,
desktopInstalled = false, offlineAccount = null, offline = false, frameGenLabel = "",
romsDir = null, logsEnabled = false, steamGames = emptyList(), emulators = emptyList(), running = null,
controller = ControllerPrefs.read(context),
), FrontEndActions(
onPlay = {}, onPlayDesktopUi = {}, onSteamGame = {}, onDesktop = {}, onEmulator = {},
onRom = {}, onResume = {}, onSteamSettings = {}, onDesktopSettings = {},
onInstallPackage = {}, onRemovePackage = {}, onRuntime = {}, onFrameGenPick = {},
onImportLossless = {}, onProtons = {}, onComponents = {}, onPerformance = {},
onRoms = {}, onFiles = {}, onLogs = {}, onOffline = {},
onWirelessAdbPair = { _, _, _, _ -> }, onWirelessAdbApply = { _, _, _, _ -> },
onSetPhantomProcessLimit = { _, _ -> }, controller = ControllerActions({}),
), onOpenDeveloperOptions = {}, onRequestWirelessAdb = {}, onPairWirelessDebugging = {})
}
}
}
}
compose.onNodeWithText(context.getString(R.string.setup_tab_controller)).performClick()
compose.onNodeWithTag("input-profile-game").assertIsDisplayed()
compose.onNodeWithText(context.getString(R.string.ctrl_layout)).assertDoesNotExist()
compose.onNodeWithText(context.getString(R.string.ctrl_configure)).assertDoesNotExist()
screenshot("controller-tab")
compose.onNodeWithTag("input-profile-game").performClick()
compose.onNodeWithTag("input-part-physical").performScrollTo().performClick()
compose.onNodeWithText(context.getString(R.string.setup_tab_launcher)).assertIsDisplayed()
screenshot("controller-physical")
compose.runOnIdle { assertEquals(InputProfiles.AUTO, InputLibraries.read(context).selected) }
}
private fun screenshot(name: String) {
compose.runOnIdle {
val image = Bitmap.createBitmap(root.width, root.height, Bitmap.Config.ARGB_8888)
root.draw(Canvas(image))
val file = File("build/reports/input-ui/$name.png").apply { parentFile?.mkdirs() }
file.outputStream().use { image.compress(Bitmap.CompressFormat.PNG, 100, it) }
image.recycle()
}
}
}
@@ -70,6 +70,7 @@ class PhysicalShortcutsDialogTest {
compose.setContent {
DroidDeckTheme { InputSettingsPage(onBack = {}) }
}
compose.onNodeWithTag("shortcuts-assign-STEAM").performScrollTo()
compose.onNodeWithTag("shortcuts-assign-STEAM").assertExists()
compose.onNodeWithTag("shortcuts-assign-QAM").assertExists()
compose.onNodeWithTag("shortcuts-assign-DROIDDECK").assertExists()
@@ -134,12 +135,12 @@ class PhysicalShortcutsDialogTest {
compose.setContent { DroidDeckTheme { PhysicalShortcutRows() } }
assign(PhysicalShortcuts.Action.STEAM)
send(KeyEvent.KEYCODE_F3, KeyEvent.ACTION_DOWN)
compose.onNodeWithTag("shortcuts-remove").performScrollTo().performClick()
compose.onNodeWithTag("shortcuts-restore-default").performScrollTo().performClick()
compose.runOnIdle {
assertEquals(PhysicalShortcuts.Action.QAM, PhysicalShortcuts.read(context).single().action)
assertTrue(ControllerPrefs.read(context).selectSteam)
}
compose.onNodeWithTag("shortcuts-assign-STEAM").assertTextContains(context.getString(R.string.game_settings_default))
compose.onNodeWithTag("shortcuts-assign-STEAM").assertTextContains(context.getString(R.string.input_shortcut_guide))
}
@Test fun retryRecoversFromAMissingReleaseWithoutSavingTheOldButton() {
@@ -172,7 +173,7 @@ class PhysicalShortcutsDialogTest {
val label = compose.onNodeWithText(context.getString(R.string.drawer_steam_menu)).getUnclippedBoundsInRoot()
assertTrue(control.right - control.left < 200.dp)
assertTrue("Menu label must not wrap vertically: $label", label.bottom - label.top <= 48.dp)
compose.onNodeWithTag("shortcuts-assign-STEAM").assertTextContains(context.getString(R.string.ctrl_custom))
compose.onNodeWithTag("shortcuts-assign-STEAM").assertTextContains(button.label)
compose.onNodeWithText("${button.label} · ${button.name}").assertExists()
}
@@ -63,6 +63,22 @@ class SessionSecondScreenTest {
@Test fun steamMenuKeepsTheExistingTrackpadAndTerminal() = checkModes(steam = true)
@Test fun closingTheDockedDrawerKeepsTheSelectedControlsPanel() {
SessionState.mode = SessionService.MODE_STEAM
var closes = 0
var selected = SecondScreenMode.CUSTOM_CONTROLS
compose.setContent {
DroidDeckTheme {
SessionDrawer(true, SessionDrawerPage.SECOND_SCREEN, false, {},
actions(true, listOf(SecondScreenDisplay(1, "Bottom screen")),
onClose = { closes++ }, select = { selected = it }), docked = true)
}
}
compose.onNodeWithContentDescription(context.getString(R.string.common_close)).performClick()
assertEquals(1, closes)
assertEquals(SecondScreenMode.CUSTOM_CONTROLS, selected)
}
@Test fun desktopWithoutASecondDisplayFallsBackToController() {
SessionState.mode = SessionService.MODE_DESKTOP
var page = SessionDrawerPage.SECOND_SCREEN
@@ -102,36 +118,11 @@ class SessionSecondScreenTest {
}
}
@Test fun trackpadTapUsesPositionLeftByAnotherPointerSource() {
val activity = Robolectric.buildActivity(SessionActivity::class.java).get()
val display = activity.getSystemService(DisplayManager::class.java).getDisplay(Display.DEFAULT_DISPLAY)
val positions = mutableListOf<Pair<Float, Float>>()
var position = Offset(0.2f, 0.7f)
val panel = SecondScreenPresentation(activity, display,
{ x, y, w, h -> positions += x / w to y / h }, { _, _ -> }, {}, {}, {}, {},
pointerPosition = { position })
try {
panel.create()
panel.showMode(SecondScreenMode.KEYBOARD_TRACKPAD)
val trackpad = descendants(panel.window!!.decorView).first { it is SessionTrackpadView }
trackpad.layout(0, 0, 1000, 600)
for (next in listOf(Offset(0.2f, 0.7f), Offset(0.8f, 0.1f))) {
position = next
for ((action, time) in listOf(MotionEvent.ACTION_DOWN to 1000L, MotionEvent.ACTION_UP to 1010L)) {
val event = MotionEvent.obtain(1000, time, action, 300f, 300f, 0)
try { trackpad.onTouchEvent(event) } finally { event.recycle() }
}
assertEquals(next.x, positions.last().first, 0.001f)
assertEquals(next.y, positions.last().second, 0.001f)
}
} finally { panel.closeControls() }
}
@Test fun terminalOpenedBeforeItWasReadyIsRetriedButOtherPanelsAreLeftAlone() {
SessionState.mode = SessionService.MODE_STEAM
val activity = Robolectric.buildActivity(SessionActivity::class.java).get()
val display = activity.getSystemService(DisplayManager::class.java).getDisplay(Display.DEFAULT_DISPLAY)
val panel = SecondScreenPresentation(activity, display, { _, _, _, _ -> }, { _, _ -> }, {}, {}, {}, {})
val panel = SecondScreenPresentation(activity, display, {}, {}, {})
try {
panel.show()
panel.showMode(SecondScreenMode.KEYBOARD_TRACKPAD)
@@ -244,7 +235,7 @@ class SessionSecondScreenTest {
SessionDrawer(true, SessionDrawerPage.SECOND_SCREEN, false, {}, actions(steam, displays) { selected += it })
}
}
val modes = listOf(SecondScreenMode.KEYBOARD_TRACKPAD, SecondScreenMode.CUSTOM_CONTROLS, SecondScreenMode.TERMINAL)
val modes = listOf(SecondScreenMode.CUSTOM_CONTROLS, SecondScreenMode.TERMINAL)
for (mode in modes) {
compose.onNodeWithText(context.getString(mode.label)).performScrollTo().assertIsDisplayed().performClick()
}
@@ -259,6 +250,7 @@ class SessionSecondScreenTest {
private fun actions(steam: Boolean, displays: List<SecondScreenDisplay>,
micAvailable: Boolean = false, micEnabled: Boolean = false, onMic: (Boolean) -> Unit = {},
onClose: () -> Unit = {},
select: (SecondScreenMode) -> Unit = {}) =
DrawerActions(steam = steam, isHomeApp = false, androidApps = emptyList(), hudOn = false,
micAvailable = micAvailable, micEnabled = micEnabled, onMicEnabled = onMic,
@@ -269,5 +261,5 @@ class SessionSecondScreenTest {
onHud = {}, onFrameGenPick = {}, onImportLossless = {}, onKeyboard = {}, onHardwareKeyboard = {},
onSteamMenu = null, onQam = null, onOsc = {}, onSuspendPolicy = {}, onBackActionsInverted = {},
onTouch = {}, onFexPreset = {}, onSecondScreenMode = select, onSecondScreenDisplay = {},
onLaunchAndroidApp = { _, _ -> }, onBackground = {}, onShareLogs = {}, onStop = {}, onClose = {})
onLaunchAndroidApp = { _, _ -> }, onBackground = {}, onShareLogs = {}, onStop = {}, onClose = onClose)
}