feat(input): Settings Controller is the in-game page for the default, with per-game layouts, Just this game and a direct remap page

This commit is contained in:
Kurt Himebauch committed 2026-11-18 23:45:46 -05:00
1 parent afa696cef2
commit 446480aa19
15 files changed
+561 -570

No files matched your search

@@ -0,0 +1,125 @@
package com.droiddeck.launcher.input
import android.content.Context
import androidx.compose.runtime.MutableState
import com.droiddeck.launcher.R
import com.droiddeck.launcher.SessionActivity
import com.droiddeck.launcher.session.SessionService
import com.droiddeck.launcher.session.SessionState
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.RuntimeEnvironment
import org.robolectric.annotation.Config
import org.robolectric.util.ReflectionHelpers
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], shadows = [JoyConPadTest.RecordingWriter::class])
class ControlsChoiceTest {
private val context: Context get() = RuntimeEnvironment.getApplication()
@Before fun reset() {
for (name in listOf("session", "game-controls", "input-profiles", "input-surfaces", "controller")) context.getSharedPreferences(name, Context.MODE_PRIVATE).edit().clear().commit()
}
@After fun mode() { SessionState.mode = SessionService.MODE_STEAM }
private fun bigSticks(): String {
val id = "big-sticks"
InputLibraries.update(context) { library ->
val stick = InputSurfaceElement(InputControl.A, .4f, .4f, .1f, .1f, "jump", InputElementKind.BUTTON, "Jump")
library.withLayout(SavedInputLayout(id, "Big sticks", listOf(stick), screen = InputLayoutScreen.MAIN))
.withPreset(SavedInputBindings("big-sticks.actions", "Big sticks", false, id, elements = mapOf("jump" to InputAction.Keys(listOf(57)))))
}
return id
}
@Test fun aNewLayoutForOneGameCopiesTheLayoutAndItsActionsForThatGameOnly() {
val source = bigSticks()
ControlsChoice.choose(context, null, source, desktop = false)
val (layoutId, bindingsId) = ControlsChoice.newForGame(context, 7, "Castle Crashers", desktop = false)
val library = InputLibraries.read(context)
val copy = library.layouts.first { it.id == layoutId }
assertEquals("Castle Crashers", copy.name)
assertEquals(library.layouts.first { it.id == source }.elements, copy.elements)
assertEquals(InputAction.Keys(listOf(57)), library.preset(bindingsId).elements["jump"])
assertEquals(layoutId, library.preset(bindingsId).layoutId)
assertEquals(bindingsId, GameControls.bindings(context, 7))
assertEquals(layoutId, ControlsChoice.current(context, 7, steamMode = true))
assertEquals(source, ControlsChoice.current(context, 8, steamMode = true))
assertEquals(source, ControlsChoice.current(context, null, steamMode = true))
assertEquals(Triple(InputProfile.GAME, layoutId, bindingsId), ControlsChoice.editTarget(context, 7, desktop = false))
}
@Test fun aCopyOfTheBuiltInGamepadKeepsFollowingTheKit() {
val extra = InputSurfaceElement(InputControl.A, .45f, .1f, .08f, .1f, "extra", InputElementKind.BUTTON, "Extra")
InputLibraries.update(context) { it.withLayout(it.layouts.first { l -> l.id == InputLibraries.OVERLAY }.copy(elements = listOf(extra), aspect = 2f)) }
val (layoutId, _) = ControlsChoice.newForGame(context, 7, "Castle Crashers", desktop = false)
val copy = InputLibraries.read(context).layouts.first { it.id == layoutId }
assertEquals(InputLibraries.OVERLAY, copy.origin)
assertTrue(OnScreenLayout.generated(copy))
assertEquals(listOf(extra), copy.elements)
assertEquals(InputLibraries.OVERLAY, ControlsChoice.current(context, null, steamMode = false))
}
@Test fun onlyAGameWithItsOwnUnsharedLayoutEditsWithoutChangingOthers() {
assertFalse(ControlsChoice.shared(context, null))
assertTrue(ControlsChoice.shared(context, 7))
ControlsChoice.choose(context, 7, InputLibraries.OVERLAY, desktop = false)
assertTrue(ControlsChoice.shared(context, 7))
ControlsChoice.newForGame(context, 7, "Castle Crashers", desktop = false)
assertFalse(ControlsChoice.shared(context, 7))
ControlsChoice.choose(context, 8, ControlsChoice.current(context, 7, steamMode = false), desktop = false)
assertTrue(ControlsChoice.shared(context, 7))
}
@Test fun useDefaultForgetsTheGamesChoice() {
ControlsChoice.newForGame(context, 7, "Castle Crashers", desktop = false)
ControlsChoice.choose(context, 9, GameControls.STEAM, desktop = false, gameName = "Portal")
assertEquals(listOf("Castle Crashers" to "Castle Crashers", "Portal" to context.getString(R.string.osc_layout_steam)),
ControlsChoice.games(context).map { it.name to it.layout })
ControlsChoice.useDefault(context, 7)
assertNull(GameControls.bindings(context, 7))
assertEquals(InputLibraries.OVERLAY, ControlsChoice.current(context, 7, steamMode = true))
assertEquals(listOf(9L), ControlsChoice.games(context).map { it.id })
}
@Test fun newIsOfferedOnlyForAGame() {
assertTrue(ControlsChoice.options(context, null, steamMode = true).none { it.first == ControlsChoice.NEW })
assertEquals(ControlsChoice.NEW to context.getString(R.string.osc_layout_new_for, "Castle Crashers"),
ControlsChoice.options(context, 7, steamMode = true, gameName = "Castle Crashers").last())
assertEquals(listOf(InputLibraries.OVERLAY, GameControls.STEAM), ControlsChoice.options(context, null, steamMode = true).map { it.first }.take(2))
}
@Test fun newForTheGameInTheControllerPageCopiesTheLayoutAndOpensTheEditorOnIt() {
SessionState.mode = SessionService.MODE_STEAM
val activity = Robolectric.buildActivity(SessionActivity::class.java).get()
ReflectionHelpers.getField<MutableState<Long?>>(activity, "frameGenActiveGameId\$delegate").value = 77L
ReflectionHelpers.getField<MutableState<String?>>(activity, "frameGenActiveGameName\$delegate").value = "Castle Crashers"
ReflectionHelpers.callInstanceMethod<Any?>(activity, "refreshInputProfile")
val options = ReflectionHelpers.getField<MutableState<List<Pair<String, String>>>>(activity, "layoutOptions\$delegate").value
assertEquals(ControlsChoice.NEW to "+ New for Castle Crashers", options.last())
ReflectionHelpers.callInstanceMethod<Any?>(activity, "chooseLayout", ReflectionHelpers.ClassParameter.from(String::class.java, ControlsChoice.NEW))
val editor = ReflectionHelpers.getField<MutableState<Triple<String, String, String>?>>(activity, "layoutEditor\$delegate").value!!
assertEquals(GameControls.bindings(activity, 77), editor.third)
assertEquals("Castle Crashers", InputLibraries.read(activity).layouts.first { it.id == editor.second }.name)
assertEquals(editor.second, ReflectionHelpers.getField<MutableState<String>>(activity, "layoutChoice\$delegate").value)
assertEquals("Saved for Castle Crashers", ReflectionHelpers.getField<String>(activity, "layoutEditorScope"))
assertNull(ReflectionHelpers.getField<Any?>(activity, "layoutEditorSplit"))
assertNull(GameControls.bindings(activity, 78))
assertEquals(InputLibraries.OVERLAY, ControlsChoice.current(activity, null, steamMode = true))
}
@Test fun aGameWithItsOwnLayoutCanGoBackToTheDefault() {
assertTrue(ControlsChoice.options(context, 42L, steamMode = true, gameName = "Game").none { it.first == ControlsChoice.DEFAULT })
ControlsChoice.newForGame(context, 42L, "Game", desktop = false)
assertTrue(ControlsChoice.options(context, 42L, steamMode = true, gameName = "Game").first().first == ControlsChoice.DEFAULT)
ControlsChoice.choose(context, 42L, ControlsChoice.DEFAULT, desktop = false)
assertFalse(ControlsChoice.hasOwn(context, 42L))
assertTrue(ControlsChoice.options(context, 42L, steamMode = true, gameName = "Game").none { it.first == ControlsChoice.DEFAULT })
}
}
@@ -234,8 +234,9 @@ class KitLayoutTest {
val density = context.resources.displayMetrics.density
for (kit in PadKit.entries) {
val placed = KitLayout.dock(context, kit, 1080, 1300, true, InputControl.LS, InputControl.RS)
val boxes = GamepadGeometry.layout(1080f, 1300f, density, true)
val boxes = GamepadGeometry.layout(1080f, 1300f, density, true, grips = kit.steam, trackpads = kit.steam)
assertEquals(kit.name, kit.steam && boxes.containsKey(GamepadGeometry.Slot.L4), placed.any { it.control == InputControl.L4 })
assertEquals(kit.name, kit.steam, placed.any { it.control == InputControl.L4 })
assertNull(placed.firstOrNull { it.control == InputControl.GUIDE || it.control == InputControl.QAM })
assertEquals(1, placed.count { it.id == KitLayout.DPAD_ID })
assertTrue(placed.none { it.floating })
@@ -272,4 +273,13 @@ class KitLayoutTest {
assertTrue("$kit stick", e.getValue("legacy:ls").width * 1920 / 2 >= 40 * dp)
}
}
@Test fun aTopCutoutNeverPushesTheShoulderRowIntoTheMiddleControls() {
for (kit in PadKit.entries) for (top in listOf(0, 20, 60, 120)) {
val elements = KitLayout.elements(context, kit, 1600, 900, Rect(0, top, 0, 0))
val lb = elements.single { it.id == "legacy:lb" }
val middle = elements.filter { it.id == KitLayout.DPAD_ID || it.id == "legacy:y" }
for (m in middle) assertTrue("$kit $top ${m.id}", m.y * 900 >= (lb.y + lb.height) * 900 - .5f || m.x * 1600 >= (lb.x + lb.width) * 1600)
}
}
}
@@ -150,7 +150,7 @@ class OnScreenLayoutTest {
assertEquals(box.height, ls.height * h, 1f)
assertSquare(placed.first { it.id == "legacy:a" }, w, h)
assertNull(placed.firstOrNull { it.control == InputControl.GUIDE || it.control == InputControl.QAM })
assertEquals(portrait, placed.any { it.control == InputControl.L4 })
assertEquals(steam && GamepadGeometry.Slot.L4 in boxes, placed.any { it.control == InputControl.L4 })
assertInside(placed, w, h)
val solid = placed.filter { it.kind != InputElementKind.STICK }
for (a in solid) for (b in solid) if (a !== b) {
@@ -33,7 +33,7 @@ class GamepadGeometryTest {
private val grips = setOf(Slot.L4, Slot.L5, Slot.R5, Slot.R4)
private val portraitPanels get() = panels.take(3) + Panel("312dp phone portrait", 720, 1280, 369 / 160f)
private fun portraitBoxes(panel: Panel) =
GamepadGeometry.layout(panel.width.toFloat(), panel.controlsHeight.toFloat(), panel.density, portraitDock = true)
GamepadGeometry.layout(panel.width.toFloat(), panel.controlsHeight.toFloat(), panel.density, portraitDock = true, grips = true)
@Test fun everyControlIsPlacedAndPanelsOnlyWhenUpright() {
for (panel in panels) {
@@ -173,4 +173,15 @@ class GamepadGeometryTest {
for ((slot, box) in b) assertTrue("${panel.name}: $slot", box.bottom <= panel.controlsHeight + .5f && box.right <= panel.width + .5f)
}
}
@Test fun landscapePanelsGiveTheGripsSlotsWithoutOverlap() {
for (panel in panels.filter { it.width > it.height }) {
val b = GamepadGeometry.layout(panel.width.toFloat(), panel.controlsHeight.toFloat(), panel.density, grips = true)
assertTrue(panel.name, grips.all { it in b })
val placed = b.entries.toList()
for (i in placed.indices) for (j in i + 1 until placed.size)
assertFalse("${panel.name}: ${placed[i].key} overlaps ${placed[j].key}", placed[i].value.overlaps(placed[j].value))
for ((slot, box) in b) assertTrue("${panel.name}: $slot", box.top >= -.5f && box.bottom <= panel.controlsHeight + .5f)
}
}
}
@@ -9,6 +9,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.ui.test.*
import com.droiddeck.launcher.input.*
import com.droiddeck.launcher.R
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.session.SessionState
import com.droiddeck.launcher.session.SessionService
import org.junit.Assert.*
@@ -35,6 +36,8 @@ class InputSettingsTest {
context.getSharedPreferences("input-profiles", Context.MODE_PRIVATE).edit().clear().commit()
context.getSharedPreferences("input-surfaces", Context.MODE_PRIVATE).edit().clear().commit()
context.getSharedPreferences("controller", Context.MODE_PRIVATE).edit().clear().commit()
context.getSharedPreferences("game-controls", Context.MODE_PRIVATE).edit().clear().commit()
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
}
@Test fun commandSymbolsAreSelectableForAnyCustomButton() {
@@ -84,8 +87,7 @@ class InputSettingsTest {
@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-remap").performScrollTo().performClick()
compose.onNodeWithTag("input-binding-a").performScrollTo().performClick()
compose.onNodeWithText("Disabled", substring = false).performScrollTo().performClick()
compose.runOnIdle { assertFalse(changed) }
@@ -116,43 +118,94 @@ class InputSettingsTest {
}
}
@Test fun aNewProfileIsIndependentAndDoesNotBecomeActive() {
@Test fun remapButtonsOpensThePhysicalControllerAndBackReturnsToTheControllerPage() {
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.onNodeWithTag("input-remap").performScrollTo().performClick()
compose.onNodeWithText(context.getString(R.string.input_physical).uppercase()).assertExists()
compose.onNodeWithTag("input-binding-a").performScrollTo().performClick()
compose.onNodeWithText("Disabled", substring = false).performScrollTo().performClick()
compose.onNodeWithTag("input-action-save").performClick()
compose.onNodeWithTag("input-remap-reset").performScrollTo().assertExists()
compose.onNodeWithText(context.getString(R.string.mode_back)).performClick()
compose.onNodeWithTag("osc-edit").assertExists()
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)
assertEquals(InputProfiles.AUTO, InputLibraries.read(context).selected)
assertEquals(InputAction.Disabled, InputProfiles.read(context, InputProfile.GAME).action(InputRole.PHYSICAL, InputControl.A))
}
}
@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()
@Test fun inGameRemapOpensStraightOnThePhysicalController() {
var closed = false
compose.setContent { DroidDeckTheme { InputSettingsPage({ closed = true }, remapOnly = true) } }
compose.onNodeWithTag("input-binding-a").assertExists()
compose.onNodeWithTag("osc-edit").assertDoesNotExist()
compose.onNodeWithText(context.getString(R.string.mode_back)).performClick()
compose.onNodeWithTag("input-part-secondary").assertExists()
compose.runOnIdle { assertEquals(InputProfiles.AUTO, InputLibraries.read(context).selected) }
compose.runOnIdle { assertTrue(closed) }
}
@Test fun profileCreationCanExplicitlyShareOnlyPhysicalControls() {
@Test fun settingsShowTheInGameControllerPageForTheDefault() {
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.onNodeWithText(context.getString(R.string.osc_group_for, context.getString(R.string.osc_default)).uppercase()).assertExists()
for (label in listOf(R.string.osc_layout, R.string.osc_edit_layout, R.string.osc_show, R.string.input_touches, R.string.unfolded_controls,
R.string.input_virtual_controller, R.string.ctrl_rumble, R.string.ctrl_dead_zone, R.string.input_remap_buttons))
compose.onNodeWithText(context.getString(label)).performScrollTo().assertExists()
for (removed in listOf(R.string.input_default_profiles, R.string.input_profiles, R.string.input_new_profile))
compose.onNodeWithText(context.getString(removed)).assertDoesNotExist()
compose.onNodeWithTag("input-profile-game").assertDoesNotExist()
compose.onNodeWithTag("osc-${SessionPrefs.OSC_NEVER}").performScrollTo().performClick()
compose.runOnIdle { assertEquals(SessionPrefs.OSC_NEVER, SessionPrefs.oscMode(context)) }
}
@Test fun choosingTheDefaultLayoutAppliesToGamesWithoutTheirOwn() {
InputLibraries.update(context) { it.copyLayout(InputLibraries.OVERLAY, "Big sticks", "big-sticks") }
ControlsChoice.newForGame(context, 7, "Castle Crashers", desktop = false)
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
compose.onNodeWithTag("setting-osc-layout").performScrollTo().performClick()
compose.onNodeWithText(context.getString(R.string.osc_layout_steam)).assertExists()
compose.onNodeWithText("Big sticks").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))
assertEquals("big-sticks", ControlsChoice.current(context, null, steamMode = true))
assertEquals("big-sticks", ControlsChoice.current(context, 8, steamMode = true))
assertNotEquals("big-sticks", ControlsChoice.current(context, 7, steamMode = true))
assertEquals("big-sticks", InputLibraries.read(context).activeLayout(false, InputRole.PRIMARY)!!.id)
}
compose.onNodeWithTag("osc-edit").performScrollTo().performClick()
compose.onNodeWithText(context.getString(R.string.osc_scope_default, "Big sticks")).assertExists()
compose.onNodeWithTag("input-editor-split").assertDoesNotExist()
}
@Test fun useDefaultReturnsAGameToTheDefaultLayout() {
ControlsChoice.newForGame(context, 42, "Castle Crashers", desktop = false)
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
compose.onNodeWithText(context.getString(R.string.osc_games_own).uppercase()).performScrollTo().assertExists()
compose.onNodeWithTag("osc-use-default-42").performScrollTo().performClick()
compose.runOnIdle { assertNull(GameControls.bindings(context, 42)) }
compose.onNodeWithText(context.getString(R.string.osc_games_own).uppercase()).assertDoesNotExist()
}
@Test fun justThisGameSavesTheEditIntoTheGamesOwnCopy() {
val library = InputLibraries.read(context)
val layout = library.layout("game", InputRole.PRIMARY)!!
var closed = false
compose.setContent { DroidDeckTheme { InputSurfaceDialog("game", { closed = true }, {}, role = InputRole.PRIMARY,
layoutId = layout.id, bindingsId = library.profile("game").binding(InputRole.PRIMARY),
scope = context.getString(R.string.osc_scope_default, layout.name),
split = InputEditorSplit(context.getString(R.string.osc_just_this_game), "Gamepad · saved for Castle Crashers") {
ControlsChoice.newForGame(context, 7, "Castle Crashers", desktop = false)
}) } }
compose.onNodeWithTag("input-editor-split").performClick()
compose.onNodeWithText("Gamepad · saved for Castle Crashers").assertExists()
compose.onNodeWithTag("input-editor-split").assertDoesNotExist()
pressPlus(2)
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performScrollTo().performClick()
compose.runOnIdle {
assertTrue(closed)
val saved = InputLibraries.read(context)
assertTrue(OnScreenLayout.generated(saved.layouts.first { it.id == layout.id }))
val own = saved.layouts.first { it.id == ControlsChoice.current(context, 7, steamMode = false) }
assertNotEquals(layout.id, own.id)
assertFalse(OnScreenLayout.generated(own))
assertEquals(layout.id, ControlsChoice.current(context, 8, steamMode = false))
}
}
@@ -231,59 +284,6 @@ class InputSettingsTest {
compose.runOnIdle { assertEquals(InputAction.Keys(listOf(103)), InputLibraries.read(context).preset(bindingsId).elements["legacy:up"]) }
}
@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.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)
@@ -294,8 +294,8 @@ class InputSettingsTest {
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.onNodeWithText(context.getString(R.string.input_read_timing)).performScrollTo().performClick()
compose.onNodeWithText(context.getString(R.string.common_close)).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 }
@@ -452,40 +452,6 @@ class InputSettingsTest {
com.droiddeck.launcher.input.ControllerPrefs.setSnap(context, true)
}
@Test fun layoutsCanBeImportedAndExported() {
val source = java.io.File(context.cacheDir, "jump.icp").apply {
writeText("""{"name":"Jump keys","elements":[{"type":"BUTTON","shape":"CIRCLE","bindings":["KEY_SPACE"],"scale":1.0,"x":0.8,"y":0.7,"text":"Jump"}]}""")
}
val target = java.io.File(context.cacheDir, "out.icp").apply { delete() }
val registry = object : androidx.activity.result.ActivityResultRegistry() {
override fun <I, O> onLaunch(requestCode: Int, contract: androidx.activity.result.contract.ActivityResultContract<I, O>, input: I,
options: androidx.core.app.ActivityOptionsCompat?) {
dispatchResult(requestCode, android.net.Uri.fromFile(if (input is String) target else source))
}
}
val owner = object : androidx.activity.result.ActivityResultRegistryOwner { override val activityResultRegistry = registry }
compose.setContent { androidx.compose.runtime.CompositionLocalProvider(androidx.activity.compose.LocalActivityResultRegistryOwner provides owner) {
DroidDeckTheme { InputSettingsPage({}) }
} }
compose.onNodeWithTag("input-profile-game").performScrollTo().performClick()
compose.onNodeWithTag("input-part-primary").performScrollTo().performClick()
compose.onNodeWithText(context.getString(R.string.input_saved_layouts)).performScrollTo().performClick()
compose.onNodeWithTag("layout-manage-${InputLibraries.OVERLAY}").performScrollTo().performClick()
compose.onNodeWithText(context.getString(R.string.screen_key_layout_export)).assertDoesNotExist()
compose.onNodeWithText(context.getString(R.string.common_close)).performClick()
compose.onNodeWithTag("input-layout-import").performScrollTo().performClick()
compose.waitUntil(5_000) { InputLibraries.read(context).layout("game", InputRole.PRIMARY)!!.name == "Jump keys" }
val imported = InputLibraries.read(context).layout("game", InputRole.PRIMARY)!!
assertEquals(InputLayoutScreen.MAIN, imported.screen)
assertEquals(InputAction.Keys(listOf(57)), InputLibraries.read(context).compile("game").elementAction(InputRole.PRIMARY, imported.elements.single().id, InputControl.A))
compose.onNodeWithText(context.getString(R.string.input_saved_layouts)).performScrollTo().performClick()
compose.onNodeWithTag("layout-manage-${imported.id}").performScrollTo().performClick()
compose.onNodeWithText(context.getString(R.string.screen_key_layout_export)).performClick()
compose.waitUntil(5_000) { target.isFile && target.length() > 0 }
assertEquals(source.readText().let { org.json.JSONObject(it).getString("name") }, org.json.JSONObject(target.readText()).getString("name"))
assertEquals("KEY_SPACE", org.json.JSONObject(target.readText()).getJSONArray("elements").getJSONObject(0).getJSONArray("bindings").getString(0))
}
private fun pressPlus(times: Int) = repeat(times) { compose.onNodeWithText("+").performScrollTo().performClick() }
@Test fun sizeButtonsScaleTheWholeGamepadAndUndoAsOneStep() {
@@ -55,12 +55,12 @@ class InputUiLayoutTest {
}
@Test @Config(qualifiers = "w360dp-h800dp")
fun phoneKeepsLibraryNavigationAndProfileEditingReachable() {
fun phoneKeepsTheControllerPageAndRemappingReachable() {
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("osc-edit").performScrollTo().assertIsDisplayed()
compose.onNodeWithTag("input-remap").performScrollTo().assertIsDisplayed().performClick()
compose.onNodeWithTag("input-binding-a").performScrollTo().assertIsDisplayed().performClick()
compose.onNodeWithTag("input-action-save").assertIsDisplayed()
screenshot("phone-properties")
@@ -75,10 +75,10 @@ class InputUiLayoutTest {
}
@Test @Config(qualifiers = "w960dp-h600dp")
fun largeScreenShowsTheProfileLibraryInTheExistingTheme() {
fun largeScreenShowsTheControllerPageInTheExistingTheme() {
compose.setContent { root = LocalView.current; DroidDeckTheme { Surface { InputSettingsPage({}) } } }
compose.onNodeWithTag("input-profile-game").assertIsDisplayed()
screenshot("profiles")
compose.onNodeWithTag("osc-edit").assertIsDisplayed()
screenshot("controller")
}
@Test @Config(qualifiers = "w960dp-h600dp")
@@ -108,11 +108,11 @@ class InputUiLayoutTest {
}
}
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.onNodeWithTag("osc-edit").assertIsDisplayed()
compose.onAllNodesWithText(context.getString(R.string.osc_edit_layout)).assertCountEquals(1)
screenshot("controller-tab")
compose.onNodeWithTag("input-profile-game").performClick()
compose.onNodeWithTag("input-part-physical").performScrollTo().performClick()
compose.onNodeWithTag("input-remap").performScrollTo().performClick()
compose.onNodeWithTag("input-binding-a").assertExists()
compose.onNodeWithText(context.getString(R.string.setup_tab_launcher)).assertIsDisplayed()
screenshot("controller-physical")
compose.runOnIdle { assertEquals(InputProfiles.AUTO, InputLibraries.read(context).selected) }