mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
Merge upstream shortcuts and dual-screen session updates
Preserve profile bindings, shared held-input ownership and custom panels alongside upstream physical shortcuts, mouse routing and docked menus. Add integration regressions and record the full 2,918-test JVM run.
This commit is contained in:
commit
d6b4b0589b
630 files changed
+42269
-1875
No files matched your search
@@ -0,0 +1,64 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.view.KeyEvent
|
||||
import androidx.compose.ui.text.TextRange
|
||||
import androidx.compose.ui.text.input.CommitTextCommand
|
||||
import androidx.compose.ui.text.input.DeleteAllCommand
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.ImeOptions
|
||||
import androidx.compose.ui.text.input.SetSelectionCommand
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(manifest = Config.NONE)
|
||||
class BottomScreenTypingTest {
|
||||
@Test fun editsReplaceTheWholeFieldAndKeepTheCursor() {
|
||||
val edits = TypingRequest.editsFor(TextFieldValue("fall", TextRange(2, 4)))
|
||||
assertEquals(3, edits.size)
|
||||
assertTrue(edits[0] is DeleteAllCommand)
|
||||
assertEquals("fall", (edits[1] as CommitTextCommand).text)
|
||||
val selection = edits[2] as SetSelectionCommand
|
||||
assertEquals(2, selection.start)
|
||||
assertEquals(4, selection.end)
|
||||
}
|
||||
|
||||
@Test fun requestForwardsTextActionAndClose() {
|
||||
val sent = mutableListOf<String>()
|
||||
val actions = mutableListOf<ImeAction>()
|
||||
var closed = 0
|
||||
val request = TypingRequest(
|
||||
TextFieldValue("a"), ImeOptions(imeAction = ImeAction.Search),
|
||||
{ sent += it.text }, { actions += it }, { closed++ },
|
||||
)
|
||||
request.send(TextFieldValue("ab"))
|
||||
request.action()
|
||||
request.close()
|
||||
assertEquals(listOf("ab"), sent)
|
||||
assertEquals("ab", request.value.text)
|
||||
assertEquals(listOf(ImeAction.Search), actions)
|
||||
assertEquals(1, closed)
|
||||
}
|
||||
|
||||
@Test fun panelStopsOnlyItsOwnRequest() {
|
||||
val first = TypingRequest(TextFieldValue(""), ImeOptions.Default, {}, {})
|
||||
val second = TypingRequest(TextFieldValue(""), ImeOptions.Default, {}, {})
|
||||
DualScreenPanel.startTyping(second)
|
||||
DualScreenPanel.stopTyping(first)
|
||||
assertEquals(second, DualScreenPanel.typing)
|
||||
DualScreenPanel.stopTyping(second)
|
||||
assertNull(DualScreenPanel.typing)
|
||||
}
|
||||
|
||||
@Test fun triggersStepThroughSections() {
|
||||
assertEquals(-1, dualPageStep(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BUTTON_L2)))
|
||||
assertEquals(1, dualPageStep(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BUTTON_R2)))
|
||||
assertNull(dualPageStep(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BUTTON_L1)))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import com.droiddeck.launcher.input.JoyConPadTest
|
||||
import com.droiddeck.launcher.input.PadBridge
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
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 {
|
||||
@Test fun takesTouchAtMatchesWhatATouchDoes() {
|
||||
val directory = Files.createTempDirectory("deck-panel").toFile()
|
||||
try {
|
||||
SessionState.deckPad = false
|
||||
// No pad: the Deck layouts (trackpads, grips). A pad without Deck controls: the gamepad layout
|
||||
// (sticks, d-pad, face buttons).
|
||||
for (pad in listOf(null, PadBridge(directory))) for (portraitDock in listOf(false, true)) {
|
||||
val name = "pad=${pad != null} portraitDock=$portraitDock"
|
||||
val panel = DeckControlsPanel(RuntimeEnvironment.getApplication(), onClose = {}, onSteamMenu = {}, onQam = {},
|
||||
pad = pad, portraitDock = portraitDock)
|
||||
assertEquals(name, pad == null, panel.deckControls)
|
||||
// The portrait dock sits under a portrait game; its gamepad layout needs a tall panel.
|
||||
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))
|
||||
panel.layout(0, 0, w, h)
|
||||
var taken = 0
|
||||
var missed = 0
|
||||
for (x in 0 until w step w / 40) for (y in 0 until h step h / 24) {
|
||||
val expected = panel.takesTouchAt(x.toFloat(), y.toFloat())
|
||||
val down = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, x.toFloat(), y.toFloat(), 0)
|
||||
assertEquals("$name ($x, $y)", expected, panel.dispatchTouchEvent(down))
|
||||
down.recycle()
|
||||
// Cancel rather than lift, so no button fires its action.
|
||||
MotionEvent.obtain(0L, 1L, MotionEvent.ACTION_CANCEL, x.toFloat(), y.toFloat(), 0).also { panel.dispatchTouchEvent(it); it.recycle() }
|
||||
if (expected) taken++ else missed++
|
||||
}
|
||||
assertTrue("$name: some points land on controls", taken > 0)
|
||||
assertTrue("$name: some points land between them", missed > 0)
|
||||
}
|
||||
} finally {
|
||||
directory.deleteRecursively()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class DualScreenPanelOwnerTest {
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
|
||||
@After fun clear() = DualScreenPanel.hide()
|
||||
|
||||
@Test fun aLauncherThatStopsLeavesThePanelOfTheOneThatTookItOver() {
|
||||
DualScreenPanel.show(app, 2, 10)
|
||||
DualScreenPanel.show(app, 2, 11)
|
||||
DualScreenPanel.hide(10)
|
||||
assertEquals(2, DualScreenPanel.shownOn)
|
||||
DualScreenPanel.hide(11)
|
||||
assertEquals(-1, DualScreenPanel.shownOn)
|
||||
}
|
||||
|
||||
@Test fun theOwnerHidesItsOwnPanel() {
|
||||
DualScreenPanel.show(app, 2, 10)
|
||||
DualScreenPanel.hide(10)
|
||||
assertEquals(-1, DualScreenPanel.shownOn)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.app.Application
|
||||
import android.content.res.Configuration
|
||||
import android.hardware.input.InputManager
|
||||
import android.view.InputDevice
|
||||
import android.view.KeyCharacterMap
|
||||
import android.view.KeyEvent
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.test.*
|
||||
import androidx.compose.ui.unit.Density
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.input.ControllerPrefs
|
||||
import com.droiddeck.launcher.input.PadBridgeRoutingTest
|
||||
import com.droiddeck.launcher.input.PhysicalShortcuts
|
||||
import org.junit.Assert.*
|
||||
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.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.shadows.InputDeviceBuilder
|
||||
import org.robolectric.shadows.ShadowDialog
|
||||
import java.util.Locale
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], application = Application::class, qualifiers = "w960dp-h640dp-land",
|
||||
shadows = [PadBridgeRoutingTest.RegisteredKeyEvent::class])
|
||||
class PhysicalShortcutsDialogTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
private val context get() = RuntimeEnvironment.getApplication()
|
||||
private lateinit var device: InputDevice
|
||||
|
||||
@Before fun setUp() {
|
||||
context.getSharedPreferences("controller", 0).edit().clear().commit()
|
||||
device = InputDeviceBuilder.newBuilder().setId(10).setName("Retroid extra buttons")
|
||||
.setDescriptor("retroid-extra").setSources(InputDevice.SOURCE_KEYBOARD)
|
||||
.setKeyboardType(InputDevice.KEYBOARD_TYPE_ALPHABETIC)
|
||||
.setKeyCharacterMap(KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD)).build()
|
||||
shadowOf(context.getSystemService(InputManager::class.java)).addInputDevice(device)
|
||||
}
|
||||
|
||||
@Test fun assignmentSavesAutomaticallyOnRelease() {
|
||||
var changes = 0
|
||||
compose.setContent { DroidDeckTheme { PhysicalShortcutRows(onChanged = { changes++ }) } }
|
||||
assign(PhysicalShortcuts.Action.STEAM)
|
||||
send(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_DOWN)
|
||||
compose.onNodeWithText(context.getString(R.string.shortcuts_release)).assertExists()
|
||||
compose.onNodeWithTag("shortcuts-save").assertDoesNotExist()
|
||||
assertTrue(PhysicalShortcuts.read(context).isEmpty())
|
||||
send(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_UP)
|
||||
compose.onNodeWithTag("shortcuts-save").assertDoesNotExist()
|
||||
compose.runOnIdle {
|
||||
val binding = PhysicalShortcuts.read(context).single()
|
||||
assertEquals(KeyEvent.KEYCODE_F1, binding.button.keyCode)
|
||||
assertEquals(PhysicalShortcuts.Action.STEAM, binding.action)
|
||||
assertEquals(1, changes)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun inputSettingsPageOpensPhysicalShortcutAssignments() {
|
||||
compose.setContent {
|
||||
DroidDeckTheme { InputSettingsPage(onBack = {}) }
|
||||
}
|
||||
compose.onNodeWithTag("shortcuts-assign-STEAM").assertExists()
|
||||
compose.onNodeWithTag("shortcuts-assign-QAM").assertExists()
|
||||
compose.onNodeWithTag("shortcuts-assign-DROIDDECK").assertExists()
|
||||
}
|
||||
|
||||
@Test fun backCancelsCaptureWithoutSaving() {
|
||||
compose.setContent { DroidDeckTheme { PhysicalShortcutRows() } }
|
||||
assign(PhysicalShortcuts.Action.QAM)
|
||||
send(KeyEvent.KEYCODE_BACK, KeyEvent.ACTION_DOWN)
|
||||
compose.onNodeWithTag("shortcuts-cancel").assertDoesNotExist()
|
||||
compose.runOnIdle {
|
||||
assertTrue(PhysicalShortcuts.read(context).isEmpty())
|
||||
}
|
||||
compose.onNodeWithTag("shortcuts-assign-QAM").assertExists()
|
||||
}
|
||||
|
||||
@Test fun controllerBCancelsCaptureWithoutSaving() {
|
||||
compose.setContent { DroidDeckTheme { PhysicalShortcutRows() } }
|
||||
assign(PhysicalShortcuts.Action.QAM)
|
||||
send(KeyEvent.KEYCODE_BUTTON_B, KeyEvent.ACTION_DOWN)
|
||||
compose.onNodeWithTag("shortcuts-assign-QAM").assertExists()
|
||||
assertTrue(PhysicalShortcuts.read(context).isEmpty())
|
||||
}
|
||||
|
||||
@Test fun closingConflictKeepsBothPreviousAssignments() {
|
||||
PhysicalShortcuts.assign(context, requireNotNull(PhysicalShortcuts.button(event(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_DOWN))),
|
||||
PhysicalShortcuts.Action.STEAM)
|
||||
PhysicalShortcuts.assign(context, requireNotNull(PhysicalShortcuts.button(event(KeyEvent.KEYCODE_F2, KeyEvent.ACTION_DOWN))),
|
||||
PhysicalShortcuts.Action.QAM)
|
||||
val previous = PhysicalShortcuts.read(context)
|
||||
compose.setContent { DroidDeckTheme { PhysicalShortcutRows() } }
|
||||
assign(PhysicalShortcuts.Action.QAM)
|
||||
send(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_DOWN)
|
||||
send(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_UP)
|
||||
compose.onNodeWithTag("shortcuts-save").assertExists()
|
||||
compose.onNodeWithTag("shortcuts-cancel").performScrollTo().performClick()
|
||||
assertEquals(previous, PhysicalShortcuts.read(context))
|
||||
}
|
||||
|
||||
@Test fun conflictingAssignmentIsNotReplacedUntilSave() {
|
||||
PhysicalShortcuts.assign(context, requireNotNull(PhysicalShortcuts.button(event(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_DOWN))),
|
||||
PhysicalShortcuts.Action.STEAM)
|
||||
compose.setContent { DroidDeckTheme { PhysicalShortcutRows() } }
|
||||
assign(PhysicalShortcuts.Action.QAM)
|
||||
send(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_DOWN)
|
||||
send(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_UP)
|
||||
compose.onNodeWithText(context.getString(R.string.shortcuts_conflict,
|
||||
context.getString(R.string.drawer_steam_menu))).assertExists()
|
||||
val button = requireNotNull(PhysicalShortcuts.button(event(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_DOWN)))
|
||||
compose.onAllNodesWithText("${button.label} · ${button.name}").assertCountEquals(2)
|
||||
assertEquals(PhysicalShortcuts.Action.STEAM, PhysicalShortcuts.read(context).single().action)
|
||||
compose.onNodeWithTag("shortcuts-save").performScrollTo().performClick()
|
||||
compose.runOnIdle { assertEquals(PhysicalShortcuts.Action.QAM, PhysicalShortcuts.read(context).single().action) }
|
||||
}
|
||||
|
||||
@Test fun removalRestoresDefaultAndPreservesOtherAssignmentsAndControllerSettings() {
|
||||
ControllerPrefs.setSelectSteam(context, true)
|
||||
PhysicalShortcuts.assign(context, requireNotNull(PhysicalShortcuts.button(event(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_DOWN))),
|
||||
PhysicalShortcuts.Action.STEAM)
|
||||
PhysicalShortcuts.assign(context, requireNotNull(PhysicalShortcuts.button(event(KeyEvent.KEYCODE_F2, KeyEvent.ACTION_DOWN))),
|
||||
PhysicalShortcuts.Action.QAM)
|
||||
compose.setContent { DroidDeckTheme { PhysicalShortcutRows() } }
|
||||
assign(PhysicalShortcuts.Action.STEAM)
|
||||
send(KeyEvent.KEYCODE_F3, KeyEvent.ACTION_DOWN)
|
||||
compose.onNodeWithTag("shortcuts-remove").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))
|
||||
}
|
||||
|
||||
@Test fun retryRecoversFromAMissingReleaseWithoutSavingTheOldButton() {
|
||||
compose.setContent { DroidDeckTheme { PhysicalShortcutRows() } }
|
||||
assign(PhysicalShortcuts.Action.STEAM)
|
||||
send(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_DOWN)
|
||||
compose.onNodeWithTag("shortcuts-retry").performScrollTo().performClick()
|
||||
send(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_UP)
|
||||
compose.onNodeWithTag("shortcuts-save").assertDoesNotExist()
|
||||
send(KeyEvent.KEYCODE_F2, KeyEvent.ACTION_DOWN)
|
||||
send(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_UP)
|
||||
compose.onNodeWithTag("shortcuts-save").assertDoesNotExist()
|
||||
send(KeyEvent.KEYCODE_F2, KeyEvent.ACTION_UP)
|
||||
compose.onNodeWithTag("shortcuts-save").assertDoesNotExist()
|
||||
val button = requireNotNull(PhysicalShortcuts.button(event(KeyEvent.KEYCODE_F2, KeyEvent.ACTION_DOWN)))
|
||||
compose.onNodeWithText("${button.label} · ${button.name}").assertExists()
|
||||
compose.runOnIdle { assertEquals(KeyEvent.KEYCODE_F2, PhysicalShortcuts.read(context).single().button.keyCode) }
|
||||
}
|
||||
|
||||
@Test fun longControllerNameDoesNotSqueezeTheMenuLabelInANarrowDrawer() {
|
||||
val button = requireNotNull(PhysicalShortcuts.button(event(KeyEvent.KEYCODE_BUTTON_SELECT, KeyEvent.ACTION_DOWN)))
|
||||
.copy(name = "Xbox Wireless Controller with a long device name")
|
||||
PhysicalShortcuts.assign(context, button, PhysicalShortcuts.Action.STEAM)
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
Box(Modifier.width(360.dp)) { PhysicalShortcutRows() }
|
||||
}
|
||||
}
|
||||
val control = compose.onNodeWithTag("shortcuts-assign-STEAM").getUnclippedBoundsInRoot()
|
||||
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.onNodeWithText("${button.label} · ${button.name}").assertExists()
|
||||
}
|
||||
|
||||
@Test fun replacingSameActionsButtonSavesWithoutConfirmation() {
|
||||
val oldButton = requireNotNull(PhysicalShortcuts.button(event(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_DOWN)))
|
||||
PhysicalShortcuts.assign(context, oldButton, PhysicalShortcuts.Action.STEAM)
|
||||
compose.setContent { DroidDeckTheme { PhysicalShortcutRows() } }
|
||||
assign(PhysicalShortcuts.Action.STEAM)
|
||||
send(KeyEvent.KEYCODE_F2, KeyEvent.ACTION_DOWN)
|
||||
assertEquals(oldButton, PhysicalShortcuts.read(context).single().button)
|
||||
send(KeyEvent.KEYCODE_F2, KeyEvent.ACTION_UP)
|
||||
compose.onNodeWithTag("shortcuts-save").assertDoesNotExist()
|
||||
compose.runOnIdle { assertEquals(KeyEvent.KEYCODE_F2, PhysicalShortcuts.read(context).single().button.keyCode) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "de-rDE-w400dp-h850dp-port")
|
||||
fun narrowLargeTextKeepsTranslatedCaptureReachableAndSavesOnRelease() {
|
||||
compose.setContent {
|
||||
val density = LocalDensity.current
|
||||
CompositionLocalProvider(LocalDensity provides Density(density.density, fontScale = 1.5f)) {
|
||||
DroidDeckTheme { PhysicalShortcutRows() }
|
||||
}
|
||||
}
|
||||
assign(PhysicalShortcuts.Action.DROIDDECK)
|
||||
compose.onNodeWithText(context.getString(R.string.shortcuts_capture,
|
||||
context.getString(R.string.shortcuts_dd_menu))).assertExists()
|
||||
send(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_DOWN)
|
||||
send(KeyEvent.KEYCODE_F1, KeyEvent.ACTION_UP)
|
||||
compose.onNodeWithTag("shortcuts-save").assertDoesNotExist()
|
||||
compose.runOnIdle { assertEquals(PhysicalShortcuts.Action.DROIDDECK, PhysicalShortcuts.read(context).single().action) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "ar-rEG-w400dp-h850dp-port")
|
||||
fun rightToLeftDialogKeepsCancelReachable() {
|
||||
compose.setContent { DroidDeckTheme { PhysicalShortcutRows() } }
|
||||
assign(PhysicalShortcuts.Action.QAM)
|
||||
compose.onNodeWithTag("shortcuts-cancel").performScrollTo().assertIsDisplayed().performClick()
|
||||
compose.onNodeWithTag("shortcuts-assign-QAM").assertExists()
|
||||
}
|
||||
|
||||
@Test fun everySupportedLanguageHasALocalizedShortcutTitleAndValidFormatArguments() {
|
||||
val languages = mutableListOf<String>()
|
||||
context.resources.getXml(R.xml.locales_config).use { xml ->
|
||||
while (xml.next() != org.xmlpull.v1.XmlPullParser.END_DOCUMENT) {
|
||||
if (xml.eventType == org.xmlpull.v1.XmlPullParser.START_TAG && xml.name == "locale") {
|
||||
languages.add(xml.getAttributeValue("http://schemas.android.com/apk/res/android", "name"))
|
||||
}
|
||||
}
|
||||
}
|
||||
val english = context.getString(R.string.shortcuts_title)
|
||||
for (language in languages) {
|
||||
val config = Configuration(context.resources.configuration).apply { setLocale(Locale.forLanguageTag(language)) }
|
||||
val localized = context.createConfigurationContext(config)
|
||||
if (language != "en") assertNotEquals(language, english, localized.getString(R.string.shortcuts_title))
|
||||
assertTrue(localized.getString(R.string.shortcuts_capture, "ACTION").contains("ACTION"))
|
||||
assertTrue(localized.getString(R.string.shortcuts_conflict, "ACTION").contains("ACTION"))
|
||||
val detected = localized.getString(R.string.shortcuts_detected, "DEVICE", "BUTTON")
|
||||
assertTrue(detected.contains("DEVICE"))
|
||||
assertTrue(detected.contains("BUTTON"))
|
||||
}
|
||||
}
|
||||
|
||||
private fun assign(action: PhysicalShortcuts.Action) {
|
||||
compose.onNodeWithTag("shortcuts-assign-${action.name}").performClick()
|
||||
}
|
||||
|
||||
private fun send(code: Int, action: Int) {
|
||||
compose.runOnIdle {
|
||||
assertTrue(ShadowDialog.getLatestDialog().window!!.callback.dispatchKeyEvent(event(code, action)))
|
||||
}
|
||||
compose.waitForIdle()
|
||||
}
|
||||
|
||||
private fun event(code: Int, action: Int) =
|
||||
KeyEvent(100L, 100L, action, code, 0, 0, device.id, 700, 0, InputDevice.SOURCE_KEYBOARD)
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
|
||||
fun createRobolectricComposeRule() = createComposeRule().also {
|
||||
RingVeil.reset()
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
shadowOf(context.packageManager).addActivityIfNotPresent(
|
||||
ComponentName(context, ComponentActivity::class.java),
|
||||
|
||||
@@ -19,7 +19,8 @@ class SessionDrawerPageTest {
|
||||
assertEquals(SessionDrawerPage.DISPLAY, connected.step(SessionDrawerPage.SECOND_SCREEN, 1))
|
||||
assertEquals(sessionDrawerPages(false), connected.filter { it != SessionDrawerPage.SECOND_SCREEN })
|
||||
for (pages in listOf(connected, sessionDrawerPages(false))) {
|
||||
assertEquals(SessionDrawerPage.EFFECTS, pages.step(SessionDrawerPage.DISPLAY, 1))
|
||||
assertEquals(SessionDrawerPage.HUD, pages.step(SessionDrawerPage.DISPLAY, 1))
|
||||
assertEquals(SessionDrawerPage.EFFECTS, pages.step(SessionDrawerPage.HUD, 1))
|
||||
assertEquals(SessionDrawerPage.VR, pages.step(SessionDrawerPage.EFFECTS, 1))
|
||||
assertEquals(SessionDrawerPage.GAMES, pages.step(SessionDrawerPage.VR, 1))
|
||||
assertEquals(SessionDrawerPage.SESSION, pages.step(SessionDrawerPage.GAMES, 1))
|
||||
|
||||
@@ -8,7 +8,7 @@ import android.view.KeyEvent
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import androidx.compose.ui.test.*
|
||||
import androidx.compose.ui.semantics.SemanticsProperties.StateDescription
|
||||
import androidx.compose.runtime.MutableState
|
||||
@@ -103,6 +103,28 @@ class SessionSecondScreenTest {
|
||||
} finally { panel.closeControls() }
|
||||
}
|
||||
|
||||
@Test fun trackpadMenuButtonOnlyAppearsWhenTheMenuCanMove() {
|
||||
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 label = context.getString(R.string.touch_droiddeck_menu)
|
||||
for (movable in listOf(false, true)) {
|
||||
var menus = 0
|
||||
val panel = SecondScreenPresentation(activity, display, { _, _, _, _ -> }, { _, _ -> }, {},
|
||||
{}, {}, {}, onMenu = if (movable) ({ menus++ }) else null)
|
||||
try {
|
||||
panel.create()
|
||||
panel.showMode(SecondScreenMode.KEYBOARD_TRACKPAD)
|
||||
val buttons = descendants(panel.window!!.decorView).filter { it.contentDescription == label }.toList()
|
||||
assertEquals(if (movable) 1 else 0, buttons.size)
|
||||
buttons.forEach { it.performClick() }
|
||||
assertEquals(if (movable) 1 else 0, menus)
|
||||
} finally {
|
||||
panel.closeControls()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(sdk = [34], shadows = [PadBridgeRoutingTest.RegisteredKeyEvent::class])
|
||||
fun controllerBumpersReachTheSecondScreenInBothSessionModes() {
|
||||
@@ -113,7 +135,7 @@ class SessionSecondScreenTest {
|
||||
SessionState.mode = mode
|
||||
val activity = Robolectric.buildActivity(SessionActivity::class.java).get()
|
||||
fun <T> state(name: String): MutableState<T> = ReflectionHelpers.getField(activity, "$name\$delegate")
|
||||
state<Boolean>("drawerOpen").value = true
|
||||
state<Boolean>("drawerOpenState").value = true
|
||||
state<Boolean>("drawerControllerActive").value = true
|
||||
state<List<SecondScreenDisplay>>("secondScreenDisplays").value = listOf(SecondScreenDisplay(1, "Bottom screen"))
|
||||
for ((button, page) in listOf(KeyEvent.KEYCODE_BUTTON_R1 to SessionDrawerPage.SECOND_SCREEN,
|
||||
@@ -133,7 +155,7 @@ class SessionSecondScreenTest {
|
||||
shadowOf(context.getSystemService(InputManager::class.java)).addInputDevice(device)
|
||||
SessionState.mode = SessionService.MODE_STEAM
|
||||
val activity = Robolectric.buildActivity(SessionActivity::class.java).get()
|
||||
val open: MutableState<Boolean> = ReflectionHelpers.getField(activity, "drawerOpen\$delegate")
|
||||
val open: MutableState<Boolean> = ReflectionHelpers.getField(activity, "drawerOpenState\$delegate")
|
||||
val controller: MutableState<Boolean> = ReflectionHelpers.getField(activity, "drawerControllerActive\$delegate")
|
||||
controller.value = true
|
||||
for (button in listOf(KeyEvent.KEYCODE_BUTTON_SELECT, KeyEvent.KEYCODE_BUTTON_START)) {
|
||||
@@ -215,9 +237,9 @@ class SessionSecondScreenTest {
|
||||
try {
|
||||
panel.create()
|
||||
panel.showMode(SecondScreenMode.KEYBOARD_TRACKPAD)
|
||||
val buttons = descendants(panel.window!!.decorView).filterIsInstance<Button>().toList()
|
||||
val buttons = descendants(panel.window!!.decorView).filterIsInstance<TextView>().filter { it.isClickable }.toList()
|
||||
assertTrue(buttons.any { it.text == context.getString(R.string.second_show_keyboard) })
|
||||
val shortcuts = buttons.filter { it.text == "STEAM" || it.text == "…" }
|
||||
val shortcuts = buttons.filter { it.text == "STEAM" || it.text == "•••" }
|
||||
if (steam) {
|
||||
assertEquals(2, shortcuts.size)
|
||||
shortcuts.forEach { it.performClick() }
|
||||
|
||||
Reference in new issue
Block a user