mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 22:05:59 +00:00
Merge upstream main into unified input profiles
Integrate screen keys, portrait controls, and Home/Back shortcuts with routed input. Preserve remapped axes, neutral gating, and explicit Back bindings; discard stale queued chord reports when routing changes. Validation: 2,632 debug JVM tests across 385 suites pass with Java 17 and skipRust. Device testing and latency measurements were not repeated for this merge.
This commit is contained in:
commit
92b4361100
525 files changed
+40912
-3336
No files matched your search
@@ -12,6 +12,7 @@ import com.droiddeck.launcher.input.JoyConPadTest
|
||||
import com.droiddeck.launcher.input.PadBridge
|
||||
import com.droiddeck.launcher.input.PadState
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import java.io.File
|
||||
import org.junit.After
|
||||
import org.junit.Assert.*
|
||||
@@ -30,8 +31,10 @@ class DeckControlsPanelOwnershipTest {
|
||||
private val root = FrameLayout(activity)
|
||||
private val bridge = PadBridge(File(activity.cacheDir, "panel-ownership"))
|
||||
private lateinit var panel: DeckControlsPanel
|
||||
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)
|
||||
@@ -51,6 +54,7 @@ class DeckControlsPanelOwnershipTest {
|
||||
bridge.stop()
|
||||
DeckControls.releaseAll()
|
||||
controller.pause().stop().destroy()
|
||||
SessionState.deckPad = previousDeckPad
|
||||
}
|
||||
|
||||
@Test fun switchingTheOtherStickKeepsTrackpadContactAndClickHeld() {
|
||||
|
||||
@@ -20,8 +20,8 @@ class FexVersionTest {
|
||||
}
|
||||
|
||||
@Test fun theShippedLauncherHasOne() {
|
||||
val script = java.io.File("../tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64").takeIf { it.isFile }
|
||||
?: java.io.File("tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64")
|
||||
val script = java.io.File("../tools/linuxfs/overlay/usr/local/bin/droiddeck-fex-update").takeIf { it.isFile }
|
||||
?: java.io.File("tools/linuxfs/overlay/usr/local/bin/droiddeck-fex-update")
|
||||
assertEquals(true, fexVersionOf(script.readText()) != null)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.view.View
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.focusable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.geometry.Rect
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.RectangleShape
|
||||
import androidx.compose.ui.layout.boundsInRoot
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
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
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], qualifiers = "w960dp-h540dp-land")
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
class FocusGlideRenderingTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
|
||||
@Test fun largeJumpCollapsesIntoABallAndExpandsAtTheDestination() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
SessionPrefs.setAnimationsEnabled(context, true)
|
||||
Motion.refresh(context)
|
||||
compose.mainClock.autoAdvance = false
|
||||
lateinit var view: View
|
||||
val from = FocusRequester()
|
||||
val to = FocusRequester()
|
||||
compose.setContent {
|
||||
view = LocalView.current
|
||||
FocusGlideHost(Modifier.fillMaxSize().background(Color.Black)) {
|
||||
Box(Modifier.offset(10.dp, 10.dp).size(80.dp, 40.dp).focusRequester(from)
|
||||
.focusGlide(RectangleShape, Color.White).focusable())
|
||||
Box(Modifier.offset(650.dp, 400.dp).size(80.dp, 40.dp).focusRequester(to)
|
||||
.focusGlide(RectangleShape, Color.White).focusable())
|
||||
}
|
||||
}
|
||||
fun ringBounds(): Rect = compose.runOnIdle {
|
||||
val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
|
||||
view.draw(Canvas(bitmap))
|
||||
var left = view.width
|
||||
var top = view.height
|
||||
var right = 0
|
||||
var bottom = 0
|
||||
for (y in 0 until bitmap.height) for (x in 0 until bitmap.width) {
|
||||
if (android.graphics.Color.red(bitmap.getPixel(x, y)) > 200) {
|
||||
left = minOf(left, x); top = minOf(top, y)
|
||||
right = maxOf(right, x + 1); bottom = maxOf(bottom, y + 1)
|
||||
}
|
||||
}
|
||||
bitmap.recycle()
|
||||
Rect(left.toFloat(), top.toFloat(), right.toFloat(), bottom.toFloat())
|
||||
}
|
||||
compose.runOnIdle { from.requestFocus() }
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
assertTrue(ringBounds().width > 60f)
|
||||
compose.runOnIdle { to.requestFocus() }
|
||||
compose.mainClock.advanceTimeBy(160)
|
||||
val ball = ringBounds()
|
||||
assertTrue("Ball bounds: $ball", ball.width in 8f..16f && ball.height in 8f..16f)
|
||||
compose.mainClock.advanceTimeBy(1_500)
|
||||
val landed = ringBounds()
|
||||
assertTrue("Landed bounds: $landed", landed.width > 60f && landed.left > 600f)
|
||||
}
|
||||
|
||||
@Test fun hollowGlideKeepsItsOutlineWithoutTintingTheContent() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
SessionPrefs.setAnimationsEnabled(context, false)
|
||||
Motion.refresh(context)
|
||||
try {
|
||||
lateinit var view: View
|
||||
var bounds = Rect.Zero
|
||||
var hollow by mutableStateOf(true)
|
||||
compose.setContent {
|
||||
view = LocalView.current
|
||||
FocusGlideHost {
|
||||
Box(Modifier.size(120.dp).background(Color.Black)
|
||||
.glideBorder(true, RectangleShape, Color.White, hotFillAlpha = if (hollow) 0f else 0.14f)
|
||||
.onGloballyPositioned { bounds = it.boundsInRoot() })
|
||||
}
|
||||
}
|
||||
fun sample(): Pair<Int, Int> = compose.runOnIdle {
|
||||
val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
|
||||
view.draw(Canvas(bitmap))
|
||||
val center = bitmap.getPixel(bounds.center.x.toInt(), bounds.center.y.toInt())
|
||||
val edge = bitmap.getPixel(bounds.left.toInt(), bounds.center.y.toInt())
|
||||
bitmap.recycle()
|
||||
center to edge
|
||||
}
|
||||
val (center, edge) = sample()
|
||||
assertEquals(android.graphics.Color.BLACK, center)
|
||||
assertEquals(android.graphics.Color.WHITE, edge)
|
||||
compose.runOnIdle { hollow = false }
|
||||
assertTrue(android.graphics.Color.red(sample().first) > 0)
|
||||
} finally {
|
||||
SessionPrefs.setAnimationsEnabled(context, true)
|
||||
Motion.refresh(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import com.droiddeck.launcher.stores.xbox.XboxMenuEntry
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNotSame
|
||||
import org.junit.Assert.assertSame
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], qualifiers = "w960dp-h540dp-land")
|
||||
class FocusGlideWindowsTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
|
||||
@Test fun standaloneThemedControlsShareTheGlide() {
|
||||
lateinit var glide: FocusGlide
|
||||
val focus = List(6) { FocusRequester() }
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
glide = LocalFocusGlide.current!!
|
||||
Column {
|
||||
TextButton(onClick = {}, modifier = Modifier.focusRequester(focus[0]).focusGlide()) { Text("Action") }
|
||||
IconButton(onClick = {}, modifier = Modifier.focusRequester(focus[1]).focusGlide()) { Text("Icon") }
|
||||
Switch(false, {}, modifier = Modifier.focusRequester(focus[2]).focusGlide())
|
||||
Slider(0.5f, {}, modifier = Modifier.focusRequester(focus[3]).focusGlide())
|
||||
OutlinedTextField("Value", {}, modifier = Modifier.focusRequester(focus[4]).focusGlide())
|
||||
XboxMenuEntry("Xbox action", null, focus = focus[5], onClick = {})
|
||||
}
|
||||
}
|
||||
}
|
||||
var previous: GlideSource? = null
|
||||
for (requester in focus) {
|
||||
compose.runOnIdle { requester.requestFocus() }
|
||||
compose.runOnIdle {
|
||||
val source = glide.current
|
||||
assertNotNull(source)
|
||||
assertNotSame(previous, source)
|
||||
assertEquals(1, glide.hot.size)
|
||||
assertNotNull(glide.boundsOf(source!!))
|
||||
previous = source
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun alertDialogButtonsShareTheirOwnWindowGlide() {
|
||||
lateinit var parent: FocusGlide
|
||||
lateinit var dialog: FocusGlide
|
||||
val focus = List(2) { FocusRequester() }
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
parent = LocalFocusGlide.current!!
|
||||
GlideAlertDialog(
|
||||
onDismissRequest = {},
|
||||
title = { Text("Dialog") },
|
||||
confirmButton = {
|
||||
dialog = LocalFocusGlide.current!!
|
||||
val view = LocalView.current
|
||||
SideEffect { assertSame(view, dialog.view) }
|
||||
TextButton(onClick = {}, modifier = Modifier.focusRequester(focus[0]).focusGlide()) { Text("Confirm") }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = {}, modifier = Modifier.focusRequester(focus[1]).focusGlide()) { Text("Cancel") }
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
assertNotSame(parent, dialog)
|
||||
assertWindowHandoff(dialog, focus)
|
||||
}
|
||||
|
||||
@Test fun customDialogsHaveAHostInsideTheirWindow() {
|
||||
lateinit var parent: FocusGlide
|
||||
lateinit var dialog: FocusGlide
|
||||
val focus = List(2) { FocusRequester() }
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
parent = LocalFocusGlide.current!!
|
||||
GlideDialog(onDismissRequest = {}) {
|
||||
dialog = LocalFocusGlide.current!!
|
||||
Column {
|
||||
SecondaryButton("First", modifier = Modifier.focusRequester(focus[0])) {}
|
||||
SecondaryButton("Second", modifier = Modifier.focusRequester(focus[1])) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertNotSame(parent, dialog)
|
||||
assertWindowHandoff(dialog, focus)
|
||||
}
|
||||
|
||||
@Test fun dropdownItemsShareTheirOwnWindowGlide() {
|
||||
lateinit var parent: FocusGlide
|
||||
lateinit var menu: FocusGlide
|
||||
val focus = List(2) { FocusRequester() }
|
||||
var expanded by mutableStateOf(true)
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
parent = LocalFocusGlide.current!!
|
||||
GlideDropdownMenu(expanded = expanded, onDismissRequest = {}) {
|
||||
menu = LocalFocusGlide.current!!
|
||||
for (i in focus.indices) DropdownMenuItem(
|
||||
text = { Text("Item $i") }, onClick = {},
|
||||
modifier = Modifier.focusRequester(focus[i]).focusGlide(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
assertNotSame(parent, menu)
|
||||
assertWindowHandoff(menu, focus)
|
||||
compose.runOnIdle { expanded = false }
|
||||
compose.waitForIdle()
|
||||
compose.runOnIdle { expanded = true }
|
||||
compose.waitForIdle()
|
||||
assertWindowHandoff(menu, focus)
|
||||
}
|
||||
|
||||
private fun assertWindowHandoff(glide: FocusGlide, focus: List<FocusRequester>) {
|
||||
var previous: GlideSource? = null
|
||||
for (requester in focus) {
|
||||
compose.runOnIdle { requester.requestFocus() }
|
||||
compose.runOnIdle {
|
||||
assertNotNull(glide.host)
|
||||
val current = glide.current
|
||||
assertNotNull(current)
|
||||
assertNotSame(previous, current)
|
||||
assertTrue(glide.boundsOf(current!!)!!.width > 0f)
|
||||
previous = current
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.compose.ui.input.InputMode
|
||||
import androidx.compose.ui.input.InputModeManager
|
||||
import androidx.compose.ui.input.key.Key
|
||||
import androidx.compose.ui.platform.LocalInputModeManager
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.assertIsFocused
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performKeyInput
|
||||
import androidx.compose.ui.test.pressKey
|
||||
import androidx.compose.ui.test.requestFocus
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import org.junit.Assert.assertEquals
|
||||
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
|
||||
|
||||
@OptIn(androidx.compose.ui.test.ExperimentalTestApi::class, androidx.compose.ui.ExperimentalComposeUiApi::class)
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], qualifiers = "w360dp-h640dp-port", application = android.app.Application::class)
|
||||
class GameResourcesRowTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
private val ctx get() = RuntimeEnvironment.getApplication()
|
||||
private val game = Library.SteamGame(292030, "The Witcher 3", null, "/steam")
|
||||
|
||||
@Test fun everyResourceIsReachableOnANarrowPageAndOpensTheExpectedBrowserUrl() {
|
||||
compose.setContent { DroidDeckTheme { GameResourcesRow(game.name, game) } }
|
||||
for (link in gameResources(game.name, game)) {
|
||||
compose.onNodeWithText(ctx.getString(link.label)).assertIsDisplayed().performClick()
|
||||
val intent = shadowOf(ctx).nextStartedActivity
|
||||
assertEquals(Intent.ACTION_VIEW, intent.action)
|
||||
assertEquals(link.url, intent.dataString)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun controllerCanMoveBetweenLinksAndOpenAResource() {
|
||||
lateinit var inputMode: InputModeManager
|
||||
compose.setContent { DroidDeckTheme {
|
||||
inputMode = LocalInputModeManager.current
|
||||
GameResourcesRow(game.name, game)
|
||||
} }
|
||||
compose.runOnIdle { inputMode.requestInputMode(InputMode.Keyboard) }
|
||||
compose.onNodeWithText(ctx.getString(R.string.game_resource_pcgw)).requestFocus().assertIsFocused().performKeyInput { pressKey(Key.DirectionRight) }
|
||||
compose.onNodeWithText(ctx.getString(R.string.game_resource_guides)).assertIsFocused().performKeyInput { pressKey(Key.ButtonA) }
|
||||
assertEquals(gameResources(game.name, game)[1].url, shadowOf(ctx).nextStartedActivity.dataString)
|
||||
}
|
||||
|
||||
@Test @Config(qualifiers = "w640dp-h360dp-land")
|
||||
fun shortLandscapeWindowsKeepEveryResourceVisible() {
|
||||
compose.setContent { DroidDeckTheme { GameResourcesRow(game.name, game) } }
|
||||
for (link in gameResources(game.name, game)) {
|
||||
compose.onNodeWithText(ctx.getString(link.label)).assertIsDisplayed()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.net.URI
|
||||
import java.net.URLDecoder
|
||||
|
||||
class GameResourcesTest {
|
||||
@Test fun searchesPreserveUnicodeAndEscapeQueryDelimiters() {
|
||||
val title = "Ōkami HD & friends + 100% #1?"
|
||||
val links = gameResources(" $title ", null)
|
||||
assertEquals(3, links.size)
|
||||
links.forEach { link ->
|
||||
val uri = URI(link.url)
|
||||
assertEquals("https", uri.scheme)
|
||||
assertEquals(null, uri.fragment)
|
||||
assertEquals(title, URLDecoder.decode(uri.rawQuery.substringAfter('='), "UTF-8"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun onlySteamClientGamesGetAppSpecificSteamResources() {
|
||||
val steam = Library.SteamGame(292030, "The Witcher 3", null, "/steam")
|
||||
val links = gameResources(steam.name, steam)
|
||||
assertEquals("https://www.protondb.com/app/292030", links.single { it.label == R.string.game_resource_protondb }.url)
|
||||
assertEquals("https://store.steampowered.com/account/remotestorageapp/?appid=292030", links.single { it.label == R.string.game_resource_steam_cloud }.url)
|
||||
val others = listOf(
|
||||
Library.SteamGame(292030, steam.name, null, Library.ADDED),
|
||||
Library.SteamGame(292030, steam.name, null, Library.ADDED, source = "gog", storeId = "292030"),
|
||||
Library.SteamGame(292030, steam.name, null, Library.XBOX_CLOUD, source = "xbox"),
|
||||
Library.SteamGame(-1, steam.name, null, "/steam"),
|
||||
)
|
||||
others.forEach { game ->
|
||||
assertEquals(3, gameResources(game.name, game).size)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun loadingPagesHaveNoResourcesUntilTheyHaveATitle() {
|
||||
assertTrue(gameResources(" ", null).isEmpty())
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,9 @@ class GamepadGeometryTest {
|
||||
}
|
||||
|
||||
private val panels = listOf(
|
||||
Panel("Thor portrait", 1080, 1920, 369 / 160f),
|
||||
Panel("720p phone portrait", 720, 1280, 2f),
|
||||
Panel("Phone portrait", 1080, 2400, 2.75f),
|
||||
Panel("Fold 8 upright", 1848, 2448, 2.625f),
|
||||
Panel("Fold 8 as a tablet", 2448, 1848, 2.625f),
|
||||
Panel("Pixel Fold upright", 1840, 2208, 2.625f),
|
||||
@@ -26,10 +29,15 @@ class GamepadGeometryTest {
|
||||
private fun boxes(panel: Panel) =
|
||||
GamepadGeometry.layout(panel.width.toFloat(), panel.controlsHeight.toFloat(), panel.density)
|
||||
|
||||
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)
|
||||
|
||||
@Test fun everyControlIsPlacedAndPanelsOnlyWhenUpright() {
|
||||
for (panel in panels) {
|
||||
val upright = panel.height > panel.width
|
||||
val expected = Slot.values().toSet() - if (upright) emptySet() else setOf(Slot.PANELS)
|
||||
val expected = Slot.values().toSet() - grips - if (upright) emptySet() else setOf(Slot.PANELS)
|
||||
assertEquals(panel.name, expected, boxes(panel).keys)
|
||||
}
|
||||
}
|
||||
@@ -81,4 +89,56 @@ class GamepadGeometryTest {
|
||||
assertTrue(panel.name, before(Slot.STEAM, Slot.QAM))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun portraitDockPlacesAllControlsWithinThePanel() {
|
||||
for (panel in portraitPanels) {
|
||||
val b = portraitBoxes(panel)
|
||||
assertEquals(panel.name, Slot.values().toSet(), b.keys)
|
||||
for ((slot, box) in b) {
|
||||
val where = "${panel.name}: $slot $box"
|
||||
assertTrue(where, box.left >= 0f && box.top >= 0f)
|
||||
assertTrue(where, box.right <= panel.width && box.bottom <= panel.controlsHeight)
|
||||
assertTrue(where, box.width >= 44 * panel.density - 1 && box.height >= 44 * panel.density - 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun portraitDockControlsDoNotOverlap() {
|
||||
for (panel in portraitPanels) {
|
||||
val placed = portraitBoxes(panel).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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun portraitDockUsesMoreSpaceForTheThumbSurfaces() {
|
||||
for (panel in portraitPanels) {
|
||||
val old = boxes(panel)
|
||||
val b = portraitBoxes(panel)
|
||||
for (slot in listOf(Slot.LEFT_MAIN, Slot.RIGHT_MAIN, Slot.LEFT_SECOND, Slot.RIGHT_SECOND)) {
|
||||
assertTrue("${panel.name}: $slot", b.getValue(slot).width >= old.getValue(slot).width * 1.2f)
|
||||
}
|
||||
assertEquals(panel.name, b.getValue(Slot.LEFT_MAIN).cx, b.getValue(Slot.LEFT_SECOND).cx, 0.5f)
|
||||
assertEquals(panel.name, panel.width - b.getValue(Slot.LEFT_MAIN).cx, b.getValue(Slot.RIGHT_MAIN).cx, 0.5f)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun portraitDockMovesUtilitiesAndGripsAboveTheGamepad() {
|
||||
for (panel in portraitPanels) {
|
||||
val b = portraitBoxes(panel)
|
||||
assertEquals(panel.name, 8 * panel.density, b.getValue(Slot.VIEW).top, 0.5f)
|
||||
assertTrue(panel.name, b.getValue(Slot.MENU).bottom < b.getValue(Slot.L4).top)
|
||||
assertTrue(panel.name, b.getValue(Slot.L4).bottom < b.getValue(Slot.LEFT_OUTER_SHOULDER).top)
|
||||
assertTrue(panel.name, b.getValue(Slot.LEFT_OUTER_SHOULDER).bottom < b.getValue(Slot.LEFT_SECOND).top)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun shortPanelsKeepTheExistingLayoutEvenWhenPortraitDockIsRequested() {
|
||||
for ((width, height, density) in listOf(Triple(1920f, 1080f, 2f), Triple(720f, 600f, 2.3f))) {
|
||||
assertEquals(GamepadGeometry.layout(width, height, density),
|
||||
GamepadGeometry.layout(width, height, density, portraitDock = true))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ class GamesClientTagTest {
|
||||
DroidDeckTheme {
|
||||
CompositionLocalProvider(LocalFrontFocus provides FrontFocus(), LocalNarrowPane provides narrow) {
|
||||
FocusGlideHost {
|
||||
GamesPage(FrontEndState(
|
||||
LibraryPage(FrontEndState(
|
||||
installed = "r9", ready = true, available = null, busy = false, stage = "", percent = -1,
|
||||
desktopInstalled = true, offlineAccount = null, offline = false, frameGenLabel = "",
|
||||
romsDir = null, logsEnabled = false, steamGames = games, steamGamesX64 = x64, emulators = emptyList(), running = null,
|
||||
@@ -60,7 +60,7 @@ class GamesClientTagTest {
|
||||
onRoms = {}, onFiles = {}, onLogs = {}, onOffline = {},
|
||||
onWirelessAdbPair = { _, _, _, _ -> }, onWirelessAdbApply = { _, _, _, _ -> },
|
||||
onSetPhantomProcessLimit = { _, _ -> },
|
||||
), selected = "app:440", onSelect = {}, modifier = Modifier.fillMaxSize())
|
||||
), selected = "games", onSelect = {}, modifier = Modifier.fillMaxSize())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.xbox.XboxLibraryFilter
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class LibraryEntriesTest {
|
||||
private fun owned(store: Store, id: String, title: String = id) = CatalogItem(store, id, title, imageUrl = null, owned = true)
|
||||
|
||||
@Test fun anInstalledStoreGameClaimsItsOwnedProductSoItShowsOnce() {
|
||||
val games = listOf(
|
||||
Library.SteamGame(440, "Team Fortress 2", null, "Steam library"),
|
||||
Library.SteamGame(-5, "Cyberpunk", null, Library.ADDED, source = "gog", storeId = "1423049311"),
|
||||
)
|
||||
val library = mapOf(Store.GOG to listOf(owned(Store.GOG, "1423049311", "Cyberpunk 2077"), owned(Store.GOG, "1207658924", "Witcher")))
|
||||
val entries = libraryEntries(games, library, emptySet())
|
||||
assertEquals(listOf("app:440", "app:-5", "app:gog:1207658924"), entries.map { it.key })
|
||||
assertEquals("gog:1423049311", entries[1].item?.key)
|
||||
assertTrue(entries[1].installed)
|
||||
assertFalse(entries[2].installed)
|
||||
assertNull(entries[2].game)
|
||||
}
|
||||
|
||||
@Test fun theEpicLauncherIsNotAGame() {
|
||||
val launcher = Library.SteamGame(0, Library.EPIC_LAUNCHER_NAME, null, Library.EPIC_LAUNCHER)
|
||||
assertEquals(emptyList<String>(), libraryEntries(listOf(launcher), emptyMap(), emptySet()).map { it.key })
|
||||
}
|
||||
|
||||
@Test fun aStoreInstallTheLibraryHasNotScannedYetCountsAsInstalled() {
|
||||
val entries = libraryEntries(emptyList(), mapOf(Store.EPIC to listOf(owned(Store.EPIC, "fn"))), setOf("epic:fn"))
|
||||
assertTrue(entries.single().installed)
|
||||
}
|
||||
|
||||
@Test fun aSavedCloudGameStaysNotInstalledAndKeepsItsLicenseFilters() {
|
||||
val game = Library.SteamGame(-20, "Cloud game", null, Library.XBOX_CLOUD, source = "xbox", storeId = "cloud")
|
||||
val product = owned(Store.XBOX, "cloud").copy(subscription = true, extra = mapOf("cloud" to "1"))
|
||||
val entries = libraryEntries(listOf(game), mapOf(Store.XBOX to listOf(product)), emptySet())
|
||||
val entry = entries.single()
|
||||
assertFalse(entry.installed)
|
||||
for (filter in XboxLibraryFilter.ALL_FILTERS) assertTrue(filter, keepsXbox(filter, entry))
|
||||
assertEquals(listOf("local", entry.key), installedFirst(listOf(entry, LibraryEntry("local", "steam", "Local", null, null, true))).map { it.key })
|
||||
}
|
||||
|
||||
@Test fun anInstalledPcCopyTakesPrecedenceOverTheSavedCloudRow() {
|
||||
val local = Library.SteamGame(-5, "PC game", null, Library.ADDED, source = "xbox", storeId = "same")
|
||||
val cloud = Library.SteamGame(-20, "PC game", null, Library.XBOX_CLOUD, source = "xbox", storeId = "same")
|
||||
val entries = libraryEntries(listOf(cloud, local), mapOf(Store.XBOX to listOf(owned(Store.XBOX, "same"))), setOf("xbox:same"))
|
||||
assertEquals(1, entries.size)
|
||||
assertEquals(local, entries.single().game)
|
||||
assertTrue(entries.single().installed)
|
||||
}
|
||||
|
||||
@Test fun aSavedCloudGameWithoutACatalogStillAppearsInTheCloudFilter() {
|
||||
val cloud = Library.SteamGame(-20, "Cloud game", null, Library.XBOX_CLOUD, source = "xbox", storeId = "cloud")
|
||||
val entry = libraryEntries(listOf(cloud), emptyMap(), emptySet()).single()
|
||||
assertFalse(entry.installed)
|
||||
assertTrue(keepsXbox(XboxLibraryFilter.CLOUD, entry))
|
||||
assertFalse(keepsXbox(XboxLibraryFilter.OWNED, entry))
|
||||
}
|
||||
|
||||
@Test fun distinctLocalShortcutsForTheSameProductArePreserved() {
|
||||
val first = Library.SteamGame(-5, "First install", null, Library.ADDED, source = "xbox", storeId = "same")
|
||||
val second = Library.SteamGame(-6, "Second install", null, Library.ADDED, source = "xbox", storeId = "same")
|
||||
val cloud = Library.SteamGame(-20, "Cloud game", null, Library.XBOX_CLOUD, source = "xbox", storeId = "same")
|
||||
val entries = libraryEntries(listOf(cloud, first, second), mapOf(Store.XBOX to listOf(owned(Store.XBOX, "same"))), setOf("xbox:same"))
|
||||
assertEquals(listOf(first, second), entries.map { it.game })
|
||||
}
|
||||
|
||||
@Test fun installedGamesComeFirstKeepingTheirSortedOrder() {
|
||||
val entries = listOf("a", "b", "c", "d").map { LibraryEntry(it, "steam", it, null, null, installed = it == "b" || it == "d") }
|
||||
assertEquals(listOf("b", "d", "a", "c"), installedFirst(entries).map { it.key })
|
||||
}
|
||||
|
||||
@Test fun librarySourcesFollowTheConfiguredStoreOrderWithSteamFirstAndAddedLast() {
|
||||
val entries = listOf("added", "gog", "steam", "epic", "xbox").map { LibraryEntry(it, it, it, null, null, true) }
|
||||
assertEquals(listOf("steam", "xbox", "epic", "gog", "added"), librarySources(entries, listOf("xbox", "epic", "gog")))
|
||||
}
|
||||
|
||||
@Test fun librarySourcesIgnoreUnknownAndDuplicateOrderEntriesAndAppendNewStores() {
|
||||
val entries = listOf("epic", "gog", "battlenet").map { LibraryEntry(it, it, it, null, null, false) }
|
||||
assertEquals(listOf("epic", "gog", "battlenet"), librarySources(entries, listOf("missing", "epic", "epic", "amazon")))
|
||||
}
|
||||
|
||||
@Test fun gameKeysNameEitherAnAppOrAStoreProduct() {
|
||||
GameRef.parse("app:440").let { assertEquals(440, it.appId); assertNull(it.store) }
|
||||
GameRef.parse("app:-12").let { assertEquals(-12, it.appId) }
|
||||
GameRef.parse("app:gog:1207658924").let { assertEquals(Store.GOG, it.store); assertEquals("1207658924", it.storeId); assertNull(it.appId) }
|
||||
GameRef.parse("xbox:9NBLGGH4R315").let { assertEquals(Store.XBOX, it.store); assertEquals("9NBLGGH4R315", it.storeId) }
|
||||
GameRef.parse("app:nope:1").let { assertNull(it.store); assertNull(it.appId) }
|
||||
}
|
||||
|
||||
@Test fun aCollectionKeepsItsInstalledGamesAndListsTheRestAsNotInstalled() {
|
||||
val games = listOf(
|
||||
Library.SteamGame(440, "Team Fortress 2", null, "Steam library"),
|
||||
Library.SteamGame(-5, "Celeste", null, Library.ADDED, source = "itch", storeId = "a/celeste"),
|
||||
Library.SteamGame(-6, "Other", null, Library.ADDED, source = "itch", storeId = "a/other"),
|
||||
)
|
||||
val library = mapOf(Store.ITCH to listOf(owned(Store.ITCH, "a/celeste"), owned(Store.ITCH, "a/other"), owned(Store.ITCH, "b/owned")))
|
||||
val all = libraryEntries(games, library, setOf("itch:a/celeste", "itch:a/other"))
|
||||
val collection = listOf(owned(Store.ITCH, "a/celeste"), owned(Store.ITCH, "b/owned"), owned(Store.ITCH, "c/new"))
|
||||
val out = collectionEntries(all, collection)
|
||||
assertEquals(listOf("app:-5", "app:itch:b/owned", "app:itch:c/new"), out.map { it.key })
|
||||
assertEquals(listOf(true, false, false), out.map { it.installed })
|
||||
}
|
||||
|
||||
@Test fun anEmptyCollectionHidesEveryGame() {
|
||||
val all = libraryEntries(listOf(Library.SteamGame(440, "Team Fortress 2", null, "Steam library")), emptyMap(), emptySet())
|
||||
assertEquals(emptyList<String>(), collectionEntries(all, emptyList()).map { it.key })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.key
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshots.Snapshot
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.assertCountEquals
|
||||
import androidx.compose.ui.test.onAllNodesWithText
|
||||
import androidx.compose.ui.test.onNodeWithContentDescription
|
||||
import androidx.compose.ui.test.onNodeWithTag
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.CredentialCipher
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.StoreAccounts
|
||||
import com.droiddeck.launcher.stores.StoresState
|
||||
import com.droiddeck.launcher.stores.xbox.XboxLibraryFilter
|
||||
import org.json.JSONObject
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
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 javax.crypto.spec.SecretKeySpec
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], qualifiers = "w1200dp-h752dp-land", application = android.app.Application::class)
|
||||
class LibraryVisibilityTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
private val ctx get() = RuntimeEnvironment.getApplication()
|
||||
private var generation by mutableIntStateOf(0)
|
||||
|
||||
@Before fun prepare() {
|
||||
StoreAccounts.keys = CredentialCipher.KeyProvider { SecretKeySpec(ByteArray(32) { 7 }, "AES") }
|
||||
StoreAccounts.keystoreFailed = false
|
||||
ctx.getSharedPreferences("session", 0).edit().clear().commit()
|
||||
LibraryView.source = LIBRARY_ALL
|
||||
LibraryView.query = ""
|
||||
LibraryView.focusFirst = false
|
||||
StoresState.library.clear()
|
||||
StoresState.accounts.clear()
|
||||
for (store in listOf(Store.GOG, Store.EPIC)) {
|
||||
StoreAccounts.write(ctx, store, JSONObject().put("access_token", "test-only").put("display_name", "Library test"))
|
||||
StoresState.accounts[store] = "Library test"
|
||||
StoresState.library[store] = listOf(CatalogItem(store, "owned", "Uninstalled ${store.shortLabel}", null, owned = true, sizeBytes = 1024))
|
||||
}
|
||||
}
|
||||
|
||||
@After fun clear() {
|
||||
Steps.drop()
|
||||
XboxLibraryFilter.set(ctx, XboxLibraryFilter.ALL)
|
||||
for (store in listOf(Store.GOG, Store.EPIC)) StoreAccounts.clear(ctx, store)
|
||||
StoreAccounts.keys = CredentialCipher.Keystore
|
||||
StoreAccounts.keystoreFailed = false
|
||||
StoresState.library.clear()
|
||||
StoresState.accounts.clear()
|
||||
ctx.getSharedPreferences("session", 0).edit().clear().commit()
|
||||
LibraryView.source = LIBRARY_ALL
|
||||
LibraryView.query = ""
|
||||
LibraryView.focusFirst = false
|
||||
}
|
||||
|
||||
@Test fun uninstalledGamesAreHiddenUntilSelectedInTheFilterAndTheChoiceSurvivesReopeningLibrary() {
|
||||
show()
|
||||
compose.onNodeWithText("Installed Steam game").assertExists()
|
||||
compose.onNodeWithText("Uninstalled GOG").assertDoesNotExist()
|
||||
chooseVisibility(true)
|
||||
compose.onNodeWithText("Uninstalled GOG").assertExists()
|
||||
assertTrue(SessionPrefs.libraryShowUninstalled(ctx))
|
||||
compose.runOnIdle { generation++; Snapshot.sendApplyNotifications() }
|
||||
compose.mainClock.advanceTimeBy(2_000)
|
||||
compose.onNodeWithText("Uninstalled GOG").assertExists()
|
||||
chooseVisibility(false)
|
||||
compose.onNodeWithText("Uninstalled GOG").assertDoesNotExist()
|
||||
assertFalse(SessionPrefs.libraryShowUninstalled(ctx))
|
||||
}
|
||||
|
||||
@Test fun theFilterExpandsBesideSortWithoutChangingTheSelectionOnOpen() {
|
||||
show()
|
||||
val filter = compose.onNodeWithContentDescription("Filter · Installed only")
|
||||
val sort = compose.onNodeWithContentDescription("Sort")
|
||||
assertTrue(filter.fetchSemanticsNode().boundsInRoot.right <= sort.fetchSemanticsNode().boundsInRoot.left)
|
||||
filter.performClick()
|
||||
compose.mainClock.advanceTimeBy(2_000)
|
||||
compose.onNodeWithText("Installed only").assertIsDisplayed()
|
||||
compose.onNodeWithText("All owned games").assertIsDisplayed()
|
||||
compose.onAllNodesWithText("Filter").assertCountEquals(1)
|
||||
compose.onNodeWithText("Uninstalled GOG").assertDoesNotExist()
|
||||
assertFalse(SessionPrefs.libraryShowUninstalled(ctx))
|
||||
compose.runOnIdle { Steps.fold(); Snapshot.sendApplyNotifications() }
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
sort.performClick()
|
||||
compose.mainClock.advanceTimeBy(2_000)
|
||||
compose.onAllNodesWithText("Sort").assertCountEquals(1)
|
||||
compose.onNodeWithText("Recently played").assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test fun theXboxAccessChoicesShareTheLibraryFilter() {
|
||||
StoreAccounts.write(ctx, Store.XBOX, JSONObject().put("username", "Library test"))
|
||||
StoresState.accounts[Store.XBOX] = "Library test"
|
||||
StoresState.library[Store.XBOX] = listOf(CatalogItem(Store.XBOX, "owned", "Uninstalled Xbox", null, owned = true))
|
||||
LibraryView.source = Store.XBOX.id
|
||||
try {
|
||||
show()
|
||||
compose.onNodeWithContentDescription("Filter · Installed only").performClick()
|
||||
compose.mainClock.advanceTimeBy(2_000)
|
||||
compose.onNodeWithText("Installed only").assertIsDisplayed()
|
||||
compose.onNodeWithText("All owned games").assertIsDisplayed()
|
||||
compose.onNodeWithText("Game Pass").assertIsDisplayed().performClick()
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
assertEquals(XboxLibraryFilter.GAME_PASS, XboxLibraryFilter.current)
|
||||
assertFalse(SessionPrefs.libraryShowUninstalled(ctx))
|
||||
} finally {
|
||||
StoreAccounts.clear(ctx, Store.XBOX)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aSearchWithOnlyUninstalledMatchesOffersToRevealThem() {
|
||||
LibraryView.query = "Uninstalled GOG"
|
||||
show()
|
||||
compose.onNodeWithText("Uninstalled GOG").assertDoesNotExist()
|
||||
compose.onNodeWithTag("library-browse-owned").performClick()
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
compose.onNodeWithText("Uninstalled GOG").assertExists()
|
||||
assertEquals("Uninstalled GOG", LibraryView.query)
|
||||
}
|
||||
|
||||
@Test fun aHiddenStoreRemainsReachableInLibraryInItsConfiguredOrder() {
|
||||
SessionPrefs.setStoresTabOrder(ctx, listOf("epic", "gog"))
|
||||
SessionPrefs.setStoresTabHidden(ctx, setOf("gog"))
|
||||
show()
|
||||
val steam = compose.onNodeWithTag("library-source-steam").fetchSemanticsNode().boundsInRoot.left
|
||||
val epic = compose.onNodeWithTag("library-source-epic").fetchSemanticsNode().boundsInRoot.left
|
||||
val gog = compose.onNodeWithTag("library-source-gog").fetchSemanticsNode().boundsInRoot.left
|
||||
assertTrue(steam < epic && epic < gog)
|
||||
compose.onNodeWithTag("library-source-gog").performClick()
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
compose.onNodeWithTag("library-browse-owned").assertIsDisplayed().performClick()
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
compose.onNodeWithText("Uninstalled GOG").assertExists()
|
||||
}
|
||||
|
||||
@Test fun theStoresOwnedGamesLinkRevealsOwnedGamesDespiteTheSavedInstalledOnlyView() {
|
||||
assertFalse(SessionPrefs.libraryShowUninstalled(ctx))
|
||||
LibraryView.showOwned(ctx, Store.GOG)
|
||||
show()
|
||||
compose.onNodeWithText("Uninstalled GOG").assertExists()
|
||||
compose.onNodeWithText("Installed Steam game").assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test fun theStoresOwnedGamesLinkUpdatesALibraryPageThatIsStillComposed() {
|
||||
LibraryView.source = Store.GOG.id
|
||||
show()
|
||||
compose.onNodeWithText("Uninstalled GOG").assertDoesNotExist()
|
||||
compose.runOnIdle { LibraryView.showOwned(ctx, Store.GOG); Snapshot.sendApplyNotifications() }
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
compose.onNodeWithText("Uninstalled GOG").assertExists()
|
||||
}
|
||||
|
||||
private fun show() {
|
||||
compose.mainClock.autoAdvance = false
|
||||
compose.setContent { key(generation) {
|
||||
DroidDeckTheme {
|
||||
CompositionLocalProvider(LocalFrontFocus provides FrontFocus()) {
|
||||
FocusGlideHost { Box(Modifier.fillMaxSize()) {
|
||||
LibraryPage(state(), actions(), "games", {}, Modifier.fillMaxSize())
|
||||
StepsLayer(Offset.Zero)
|
||||
} }
|
||||
}
|
||||
}
|
||||
} }
|
||||
compose.mainClock.advanceTimeBy(2_000)
|
||||
}
|
||||
|
||||
private fun chooseVisibility(show: Boolean) {
|
||||
compose.onNodeWithContentDescription("Filter · " + if (SessionPrefs.libraryShowUninstalled(ctx)) "All owned games" else "Installed only")
|
||||
.performClick()
|
||||
compose.mainClock.advanceTimeBy(2_000)
|
||||
assertTrue(Steps.open)
|
||||
compose.onNodeWithText(if (show) "All owned games" else "Installed only")
|
||||
.performClick()
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
assertEquals(show, SessionPrefs.libraryShowUninstalled(ctx))
|
||||
}
|
||||
|
||||
private fun state() = FrontEndState(
|
||||
installed = "r9", ready = true, available = null, busy = false, stage = "", percent = -1,
|
||||
desktopInstalled = true, offlineAccount = null, offline = false, frameGenLabel = "",
|
||||
romsDir = null, logsEnabled = false,
|
||||
steamGames = listOf(Library.SteamGame(440, "Installed Steam game", null, "internal")),
|
||||
emulators = emptyList(), running = null,
|
||||
)
|
||||
|
||||
private fun actions() = 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 = { _, _ -> },
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.test.*
|
||||
import androidx.compose.ui.unit.dp
|
||||
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.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], qualifiers = "w960dp-h900dp-mdpi")
|
||||
class PortraitLayoutTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
|
||||
@Before fun freezeAnimations() {
|
||||
compose.mainClock.autoAdvance = false
|
||||
Hops.railPreview = null
|
||||
}
|
||||
|
||||
@Test fun navigationSitsAtBottomAndRotatingPreservesContentState() {
|
||||
val portrait = mutableStateOf(true)
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
LauncherLayout(portrait.value, Color.Gray,
|
||||
Modifier.size(if (portrait.value) 480.dp else 800.dp, if (portrait.value) 800.dp else 480.dp).testTag("launcher"),
|
||||
navigation = {
|
||||
if (portrait.value) BottomBar(state, "steam", {}, {}, actions, Modifier)
|
||||
else SideRail(state, "steam", {}, {}, actions, Modifier.fillMaxHeight())
|
||||
},
|
||||
) {
|
||||
var count by remember { mutableIntStateOf(0) }
|
||||
Box(Modifier.fillMaxSize().testTag("pane")) {
|
||||
TextButton(onClick = { count++ }) { Text("Count $count") }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
val root = compose.onNodeWithTag("launcher").getUnclippedBoundsInRoot()
|
||||
val pane = compose.onNodeWithTag("pane").getUnclippedBoundsInRoot()
|
||||
val steam = compose.onNodeWithTag("rail-steam").getUnclippedBoundsInRoot()
|
||||
assertEquals(root.left, pane.left)
|
||||
assertEquals(root.right, pane.right)
|
||||
assertTrue(steam.top >= pane.bottom)
|
||||
assertEquals(root.bottom - 4.dp, steam.bottom)
|
||||
compose.onNodeWithText("Count 0").performClick()
|
||||
compose.runOnIdle { portrait.value = false }
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
compose.onNodeWithText("Count 1").assertExists()
|
||||
val landscapePane = compose.onNodeWithTag("pane").getUnclippedBoundsInRoot()
|
||||
val rail = compose.onNodeWithTag("rail-steam").getUnclippedBoundsInRoot()
|
||||
assertTrue(landscapePane.left > rail.right)
|
||||
assertEquals(0.dp, landscapePane.top)
|
||||
compose.runOnIdle { portrait.value = true }
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
compose.onNodeWithText("Count 1").assertExists()
|
||||
}
|
||||
|
||||
@Test fun narrowBottomBarScrollsToEveryDestinationWithAppsAndResumeVisible() {
|
||||
val selected = mutableStateOf("steam")
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
BottomBar(stateWithAppsAndSession, selected.value, { selected.value = it }, {}, actions, Modifier.size(320.dp, 64.dp))
|
||||
}
|
||||
}
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
for (key in listOf("games", "stores", "desktop", "components", "android-apps", "setup", "updates", "steam")) {
|
||||
compose.onNodeWithTag("rail-$key").performScrollTo()
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
compose.onNodeWithTag("rail-$key").assertIsDisplayed().performClick()
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
compose.runOnIdle { assertEquals(key, selected.value); assertNull(Hops.railPreview) }
|
||||
compose.onNodeWithTag("rail-$key").assertIsSelected().assertHeightIsAtLeast(48.dp).assertWidthIsAtLeast(48.dp)
|
||||
}
|
||||
compose.onNodeWithContentDescription("Resume Steam").assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test fun compactHeaderKeepsAllActionsReachable() {
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
CompositionLocalProvider(LocalNarrowPane provides true) {
|
||||
Box(Modifier.size(320.dp, 240.dp)) {
|
||||
ModeHeader("Library", "", {}, "Search library") {
|
||||
for (label in listOf("Filter", "Sort", "View", "Frontend files", "Add game")) {
|
||||
SecondaryButton(label) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
compose.onNodeWithText("Add game").performScrollTo()
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
compose.onNodeWithText("Add game").assertIsDisplayed()
|
||||
compose.onNodeWithText("Filter").performScrollTo()
|
||||
compose.mainClock.advanceTimeBy(1_000)
|
||||
compose.onNodeWithText("Filter").assertIsDisplayed()
|
||||
}
|
||||
|
||||
private fun state(home: Boolean = false, running: String? = null) = FrontEndState(
|
||||
installed = "r9", ready = true, available = null, busy = false, stage = "", percent = -1,
|
||||
desktopInstalled = true, offlineAccount = null, offline = false, frameGenLabel = "",
|
||||
romsDir = null, logsEnabled = false, steamGames = emptyList(), emulators = emptyList(), running = running,
|
||||
isHomeApp = home,
|
||||
)
|
||||
private val state get() = state()
|
||||
private val stateWithAppsAndSession get() = state(home = true, running = "Steam")
|
||||
|
||||
private val actions = 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 = { _, _ -> },
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
@@ -9,7 +10,9 @@ import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performSemanticsAction
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNotSame
|
||||
import org.junit.Assert.assertSame
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@@ -21,7 +24,7 @@ import org.robolectric.annotation.Config
|
||||
class PrimaryButtonFocusContrastTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
|
||||
@Test fun focusedPrimaryButtonDoesNotClaimAColorOverlayAboveItsLabel() {
|
||||
@Test fun focusedPrimaryButtonClaimsTheGlideWithoutAColorOverlayAboveItsLabel() {
|
||||
lateinit var glide: FocusGlide
|
||||
var clicks = 0
|
||||
compose.setContent {
|
||||
@@ -36,11 +39,51 @@ class PrimaryButtonFocusContrastTest {
|
||||
val button = compose.onNodeWithText("Play")
|
||||
button.performSemanticsAction(SemanticsActions.RequestFocus)
|
||||
button.assertIsFocused()
|
||||
compose.runOnIdle { assertNull(glide.current) }
|
||||
compose.runOnIdle {
|
||||
assertNotNull(glide.current)
|
||||
assertEquals(0f, glide.current!!.fillAlpha)
|
||||
}
|
||||
button.performClick()
|
||||
compose.runOnIdle {
|
||||
assertEquals(1, clicks)
|
||||
assertNull(glide.current)
|
||||
assertNotNull(glide.current)
|
||||
assertEquals(0f, glide.current!!.fillAlpha)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun focusCanGlideIntoAndBackOutOfPrimaryButtons() {
|
||||
lateinit var glide: FocusGlide
|
||||
val focus = FrontFocus()
|
||||
compose.setContent {
|
||||
val view = LocalView.current
|
||||
glide = remember(view) { FocusGlide(view) }
|
||||
DroidDeckTheme {
|
||||
CompositionLocalProvider(LocalFocusGlide provides glide, LocalFrontFocus provides focus) {
|
||||
Column {
|
||||
SecondaryButton("Tab") {}
|
||||
PrimaryButton("Play Steam", main = true, large = true) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val tab = compose.onNodeWithText("Tab")
|
||||
val play = compose.onNodeWithText("Play Steam")
|
||||
tab.performSemanticsAction(SemanticsActions.RequestFocus)
|
||||
tab.assertIsFocused()
|
||||
val tabSource = compose.runOnIdle { glide.current!! }
|
||||
compose.runOnIdle { focus.primary.requestFocus() }
|
||||
play.assertIsFocused()
|
||||
compose.runOnIdle {
|
||||
assertNotNull(glide.current)
|
||||
assertNotSame(tabSource, glide.current)
|
||||
assertEquals(0f, glide.current!!.fillAlpha)
|
||||
assertEquals(1, glide.hot.size)
|
||||
}
|
||||
tab.performSemanticsAction(SemanticsActions.RequestFocus)
|
||||
tab.assertIsFocused()
|
||||
compose.runOnIdle {
|
||||
assertSame(tabSource, glide.current)
|
||||
assertEquals(1, glide.hot.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import androidx.compose.ui.test.*
|
||||
import androidx.compose.ui.semantics.SemanticsProperties.StateDescription
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import com.droiddeck.launcher.R
|
||||
@@ -124,6 +125,69 @@ class SessionSecondScreenTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(sdk = [34], shadows = [PadBridgeRoutingTest.RegisteredKeyEvent::class])
|
||||
fun drawerShortcutsConsumeRepeatsAndReleasesAfterClosing() {
|
||||
val device = InputDeviceBuilder.newBuilder().setId(43).setName("Drawer shortcut test pad")
|
||||
.setDescriptor("drawer-shortcut-pad").setExternal(true).setSources(InputDevice.SOURCE_GAMEPAD).build()
|
||||
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 controller: MutableState<Boolean> = ReflectionHelpers.getField(activity, "drawerControllerActive\$delegate")
|
||||
controller.value = true
|
||||
for (button in listOf(KeyEvent.KEYCODE_BUTTON_SELECT, KeyEvent.KEYCODE_BUTTON_START)) {
|
||||
fun event(action: Int, repeat: Int = 0) = KeyEvent(0L, 0L, action, button, repeat, 0,
|
||||
device.id, 0, 0, InputDevice.SOURCE_GAMEPAD)
|
||||
open.value = true
|
||||
assertTrue(activity.dispatchKeyEvent(event(KeyEvent.ACTION_DOWN)))
|
||||
assertEquals(false, open.value)
|
||||
open.value = true
|
||||
assertTrue(activity.dispatchKeyEvent(event(KeyEvent.ACTION_DOWN, 1)))
|
||||
assertEquals(true, open.value)
|
||||
open.value = false
|
||||
assertTrue(activity.dispatchKeyEvent(event(KeyEvent.ACTION_UP)))
|
||||
val held: Set<Pair<Int, Int>> = ReflectionHelpers.getField(activity, "drawerShortcutKeysDown")
|
||||
assertTrue(held.isEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun sessionMicrophoneCanBeTurnedOff() {
|
||||
val changes = mutableListOf<Boolean>()
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
SessionDrawer(true, SessionDrawerPage.SESSION, false, {},
|
||||
actions(true, emptyList(), micAvailable = true, micEnabled = true, onMic = changes::add))
|
||||
}
|
||||
}
|
||||
compose.onNodeWithTag("setting-microphone").assertIsEnabled()
|
||||
.assert(SemanticsMatcher.expectValue(StateDescription, context.getString(R.string.widgets_on))).performClick()
|
||||
assertEquals(listOf(false), changes)
|
||||
}
|
||||
|
||||
@Test fun sessionMicrophoneCanBeTurnedBackOn() {
|
||||
val changes = mutableListOf<Boolean>()
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
SessionDrawer(true, SessionDrawerPage.SESSION, false, {},
|
||||
actions(true, emptyList(), micAvailable = true, onMic = changes::add))
|
||||
}
|
||||
}
|
||||
compose.onNodeWithTag("setting-microphone").assertIsEnabled()
|
||||
.assert(SemanticsMatcher.expectValue(StateDescription, context.getString(R.string.widgets_off))).performClick()
|
||||
assertEquals(listOf(true), changes)
|
||||
}
|
||||
|
||||
@Test fun sessionWithoutMicrophoneOmitsCaptureControl() {
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
SessionDrawer(true, SessionDrawerPage.SESSION, false, {}, actions(false, emptyList()))
|
||||
}
|
||||
}
|
||||
compose.onNodeWithTag("setting-microphone").assertDoesNotExist()
|
||||
compose.onNodeWithText(context.getString(R.string.mode_mic)).assertDoesNotExist()
|
||||
}
|
||||
|
||||
private fun checkModes(steam: Boolean) {
|
||||
SessionState.mode = if (steam) SessionService.MODE_STEAM else SessionService.MODE_DESKTOP
|
||||
val selected = mutableListOf<SecondScreenMode>()
|
||||
@@ -172,8 +236,11 @@ class SessionSecondScreenTest {
|
||||
if (view is ViewGroup) for (index in 0 until view.childCount) yieldAll(descendants(view.getChildAt(index)))
|
||||
}
|
||||
|
||||
private fun actions(steam: Boolean, displays: List<SecondScreenDisplay>, select: (SecondScreenMode) -> Unit = {}) =
|
||||
private fun actions(steam: Boolean, displays: List<SecondScreenDisplay>,
|
||||
micAvailable: Boolean = false, micEnabled: Boolean = false, onMic: (Boolean) -> Unit = {},
|
||||
select: (SecondScreenMode) -> Unit = {}) =
|
||||
DrawerActions(steam = steam, isHomeApp = false, androidApps = emptyList(), hudOn = false,
|
||||
micAvailable = micAvailable, micEnabled = micEnabled, onMicEnabled = onMic,
|
||||
frameGen = FrameGen.Mode.OFF, lossless = Lossless.State.NONE, oscMode = "never",
|
||||
onScreenButtonsVisible = false, suspendPolicy = "auto", backActionsInverted = false,
|
||||
touchMode = "auto", touchAuto = "trackpad", fexPreset = "default",
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.ui.test.assertIsEnabled
|
||||
import androidx.compose.ui.test.assertIsNotEnabled
|
||||
import androidx.compose.ui.semantics.SemanticsProperties
|
||||
import androidx.compose.ui.test.SemanticsMatcher
|
||||
import androidx.compose.ui.test.assert
|
||||
import androidx.compose.ui.test.onNodeWithTag
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import com.droiddeck.launcher.core.SteamIntegration
|
||||
import com.droiddeck.launcher.core.SteamIntegration.Feature
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33], qualifiers = "w960dp-h540dp-land")
|
||||
class SteamIntegrationGroupTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
private val state = mutableStateOf(SteamIntegration.State())
|
||||
private val requests = mutableListOf<Feature>()
|
||||
private var appInfo = 0
|
||||
private var location = 0
|
||||
|
||||
private fun stateIs(value: String) = SemanticsMatcher.expectValue(SemanticsProperties.StateDescription, value)
|
||||
|
||||
private fun show() = compose.setContent {
|
||||
DroidDeckTheme {
|
||||
SteamIntegrationGroup(state.value, onFeature = { requests.add(it) }, onAppInfo = { appInfo++ }, onLocation = { location++ })
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun everySwitchRequestsOnlyItsOwnFeature() {
|
||||
state.value = SteamIntegration.State(home = true)
|
||||
show()
|
||||
compose.onNodeWithTag("integration-action-brightness").performClick()
|
||||
compose.onNodeWithTag("integration-action-home").performClick()
|
||||
compose.onNodeWithTag("integration-action-shortcuts").performClick()
|
||||
assertEquals(listOf(Feature.BRIGHTNESS, Feature.HOME, Feature.SHORTCUTS), requests)
|
||||
}
|
||||
|
||||
@Test fun switchesReflectAndroidGrants() {
|
||||
state.value = SteamIntegration.State(brightness = true, home = true, shortcuts = true)
|
||||
show()
|
||||
compose.onNodeWithTag("integration-action-brightness").assert(stateIs("On"))
|
||||
compose.onNodeWithTag("integration-action-shortcuts").assert(stateIs("On"))
|
||||
compose.onNodeWithTag("integration-action-wifi").assert(stateIs("Off"))
|
||||
compose.onNodeWithText("3 of 4 on").assertExists()
|
||||
}
|
||||
|
||||
@Test fun shortcutsWaitForHome() {
|
||||
show()
|
||||
compose.onNodeWithTag("integration-action-shortcuts").assertIsNotEnabled()
|
||||
compose.onNodeWithText("Needs DroidDeck as Home").assertExists()
|
||||
compose.runOnIdle { state.value = state.value.copy(home = true) }
|
||||
compose.onNodeWithTag("integration-action-shortcuts").assertIsEnabled()
|
||||
}
|
||||
|
||||
@Test fun restrictedShortcutsPointToAppInfo() {
|
||||
state.value = SteamIntegration.State(home = true, shortcutsRestricted = true)
|
||||
show()
|
||||
compose.onNodeWithTag("integration-action-shortcuts").assertIsNotEnabled()
|
||||
compose.onNodeWithText("App info").performClick()
|
||||
assertEquals(1, appInfo)
|
||||
compose.runOnIdle { state.value = state.value.copy(shortcutsRestricted = false) }
|
||||
compose.onNodeWithText("App info").assertDoesNotExist()
|
||||
compose.onNodeWithTag("integration-action-shortcuts").assertIsEnabled()
|
||||
}
|
||||
|
||||
@Test fun unconfirmedRestrictionOffersAppInfoAfterAnAttempt() {
|
||||
state.value = SteamIntegration.State(home = true)
|
||||
show()
|
||||
compose.onNodeWithText("App info").assertDoesNotExist()
|
||||
compose.runOnIdle { state.value = state.value.copy(shortcutsTried = true) }
|
||||
compose.onNodeWithTag("integration-action-shortcuts").assertIsEnabled()
|
||||
compose.onNodeWithText("App info").performClick()
|
||||
assertEquals(1, appInfo)
|
||||
}
|
||||
|
||||
@Test fun deniedLocationPointsToAppInfoWithoutTogglingWifi() {
|
||||
state.value = SteamIntegration.State(locationBlocked = true)
|
||||
show()
|
||||
compose.onNodeWithText("Location denied · allow it in App info").assertExists()
|
||||
compose.onNodeWithText("App info").performClick()
|
||||
assertEquals(1, location)
|
||||
assertTrue(requests.isEmpty())
|
||||
}
|
||||
}
|
||||
@@ -46,9 +46,4 @@ class StoreGridNavigationTest {
|
||||
assertEquals(10, storeGridNeighbor(6, 11, 4, 1, split = 6))
|
||||
assertNull(storeGridNeighbor(1, 11, 4, -1, split = 6))
|
||||
}
|
||||
|
||||
@Test fun installedGamesComeFirstKeepingTheirSortedOrder() {
|
||||
val items = listOf("a", "b", "c", "d").map { com.droiddeck.launcher.stores.CatalogItem(com.droiddeck.launcher.stores.Store.GOG, it, it, null) }
|
||||
assertEquals(listOf("b", "d", "a", "c"), installedFirst(items, setOf("d", "b")).map { it.id })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performScrollTo
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.InstalledStoreGame
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.StoreGameSidecar
|
||||
import com.droiddeck.launcher.stores.StoreInstallRoot
|
||||
import com.droiddeck.launcher.stores.StoreSizes
|
||||
import com.droiddeck.launcher.stores.StoresState
|
||||
import com.droiddeck.launcher.stores.download.DownloadEntry
|
||||
import com.droiddeck.launcher.stores.download.DownloadState
|
||||
import com.droiddeck.launcher.stores.xbox.XboxBackend
|
||||
import com.droiddeck.launcher.stores.xbox.XboxContent
|
||||
import org.json.JSONObject
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertNull
|
||||
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 java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], qualifiers = "w1200dp-h752dp-land", application = android.app.Application::class)
|
||||
class StoreRestorationTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
private val ctx get() = RuntimeEnvironment.getApplication()
|
||||
private val product = CatalogItem(Store.XBOX, "9NBLGGH4R315", "Test game", null, owned = true, sizeBytes = 10_485_760L, extra = mapOf("cloud" to "1"))
|
||||
private val cloud = Library.SteamGame(-20, product.title, null, Library.XBOX_CLOUD, source = "xbox", storeId = product.id)
|
||||
|
||||
@After fun clear() {
|
||||
StoresState.publishDownloads(emptyList())
|
||||
StoresState.unfinished = emptyList()
|
||||
StoreSizes.onDisk.clear()
|
||||
XboxContent.dismiss()
|
||||
}
|
||||
|
||||
@Test fun manageContentReportsItsResultWithoutComposingTheStoresPage() {
|
||||
val base = InstalledStoreGame(StoreGameSidecar(Store.XBOX, product.id, product.title, "game.exe"), File(ctx.cacheDir, "missing-xbox-manifest"))
|
||||
compose.mainClock.autoAdvance = false
|
||||
compose.setContent {
|
||||
DroidDeckTheme { FrontEndScreen(state(), actions(), page = { Text("Library game page") }) }
|
||||
}
|
||||
compose.mainClock.advanceTimeBy(2_000)
|
||||
compose.runOnIdle { XboxContent.manage(ctx, base) }
|
||||
compose.waitUntil(5_000) {
|
||||
shadowOf(android.os.Looper.getMainLooper()).idle()
|
||||
XboxContent.plan != null
|
||||
}
|
||||
compose.mainClock.advanceTimeBy(100)
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_xbox_content_title)).assertExists()
|
||||
compose.onNodeWithText("Missing or ambiguous MicrosoftGame.config.").assertExists()
|
||||
compose.onNodeWithText(ctx.getString(android.R.string.ok)).performClick()
|
||||
compose.runOnIdle { assertNull(XboxContent.plan) }
|
||||
}
|
||||
|
||||
@Test fun packageChoicesRenderOutsideTheStoresPage() {
|
||||
val choices = (1..24).map { JSONObject().put("title", "Package $it").put("kind", "Game") }
|
||||
val pending = XboxBackend.PackageChoice(product, ctx.cacheDir, choices)
|
||||
compose.setContent { DroidDeckTheme { XboxStoreDialogs(content = null, pending = pending) } }
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_xbox_choose_content)).assertExists()
|
||||
choices.forEach { compose.onNodeWithText(ctx.getString(R.string.stores_xbox_choice, it.getString("title"), "Game")).performScrollTo().assertIsDisplayed() }
|
||||
compose.onNodeWithText(ctx.getString(android.R.string.cancel)).assertExists()
|
||||
}
|
||||
|
||||
@Test fun everyContentOfferCanBeReachedInALandscapeDialog() {
|
||||
val base = InstalledStoreGame(StoreGameSidecar(Store.XBOX, product.id, product.title, "game.exe"), ctx.cacheDir)
|
||||
val offers = (1..24).map { XboxContent.Offer(product.copy(id = "dlc-$it", title = "Content $it"), installed = false) }
|
||||
val plan = XboxContent.Plan(base, offers)
|
||||
compose.setContent { DroidDeckTheme { XboxStoreDialogs(content = plan, pending = null) } }
|
||||
offers.forEach { compose.onNodeWithText(ctx.getString(R.string.stores_xbox_content_install, it.item.title)).performScrollTo().assertIsDisplayed() }
|
||||
}
|
||||
|
||||
@Test fun libraryCardsShowDownloadAndInstalledSizes() {
|
||||
val owned = LibraryEntry("owned", "xbox", product.title, null, product, false)
|
||||
val installed = LibraryEntry("installed", "xbox", product.title, null, product.copy(id = "installed"), true)
|
||||
StoreSizes.onDisk["xbox:installed"] = 20_971_520L
|
||||
compose.setContent { DroidDeckTheme { Column {
|
||||
LibraryMarker(owned, null)
|
||||
LibraryMarker(installed, null)
|
||||
} } }
|
||||
compose.onNodeWithText("10.0 MB").assertExists()
|
||||
compose.onNodeWithText("20.0 MB").assertExists()
|
||||
}
|
||||
|
||||
@Test fun aSavedCloudGamesDownloadKeepsPauseResumeCancelAndFailureRecovery() {
|
||||
val entry = DownloadEntry(Store.XBOX, product.id, product.title, state = DownloadState.RUNNING)
|
||||
StoresState.publishDownloads(listOf(entry))
|
||||
compose.setContent { DroidDeckTheme { GameActions(Store.XBOX, product.id, cloud, product, null, state(), actions(), Modifier) } }
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_dl_pause)).assertExists()
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_dl_cancel)).assertExists()
|
||||
compose.onNodeWithText(ctx.getString(R.string.game_stream)).assertExists()
|
||||
compose.runOnIdle { StoresState.publishDownloads(listOf(entry.copy(state = DownloadState.PAUSED))) }
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_dl_resume)).assertExists()
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_dl_cancel)).assertExists()
|
||||
compose.runOnIdle { StoresState.publishDownloads(listOf(entry.copy(state = DownloadState.FAILED))) }
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_dl_resume)).assertExists()
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_dl_clear)).assertExists()
|
||||
compose.onNodeWithText(ctx.getString(R.string.game_stream)).assertExists()
|
||||
}
|
||||
|
||||
@Test fun aConsoleOnlyCloudGameDoesNotOfferAPcInstall() {
|
||||
compose.setContent { DroidDeckTheme { GameActions(Store.XBOX, product.id, cloud, product.copy(sizeBytes = 0, extra = mapOf("pc" to "0", "cloud" to "1")), null, state(), actions(), Modifier) } }
|
||||
compose.onNodeWithText(ctx.getString(R.string.game_stream)).assertExists()
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_install)).assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test fun anInterruptedCloudDownloadCanBeClearedAfterItsLicenseOrPcMetadataChanges() {
|
||||
StoresState.unfinished = listOf(StoreInstallRoot.Unfinished(Store.XBOX, product.id, File(ctx.cacheDir, "partial")))
|
||||
var item by mutableStateOf(product)
|
||||
compose.setContent { DroidDeckTheme { GameActions(Store.XBOX, product.id, cloud, item, null, state(), actions(), Modifier) } }
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_resume_install)).assertExists()
|
||||
for (changed in listOf(product.copy(owned = false), product.copy(extra = mapOf("pc" to "0", "cloud" to "1")))) {
|
||||
compose.runOnIdle { item = changed }
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_dl_clear)).assertExists()
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_resume_install)).assertDoesNotExist()
|
||||
}
|
||||
}
|
||||
|
||||
private fun state() = FrontEndState(
|
||||
installed = "r9", ready = true, available = null, busy = false, stage = "", percent = -1,
|
||||
desktopInstalled = true, offlineAccount = null, offline = false, frameGenLabel = "",
|
||||
romsDir = null, logsEnabled = false, steamGames = emptyList(), emulators = emptyList(), running = null,
|
||||
pageKey = "test-game", navigate = "games",
|
||||
)
|
||||
|
||||
private fun actions() = 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 = { _, _ -> },
|
||||
)
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class StoreTabsTest {
|
||||
@Test fun libraryAndStoreAmazonLibraryOnly() {
|
||||
assertEquals(listOf("library", "store"), tabsFor(Store.GOG))
|
||||
assertEquals(listOf("library", "store"), tabsFor(Store.ITCH))
|
||||
assertEquals(listOf("library"), tabsFor(Store.AMAZON))
|
||||
assertEquals("library", tabFor(Store.AMAZON, "store"))
|
||||
assertEquals("library", tabFor(Store.GOG, "all"))
|
||||
assertEquals("library", tabFor(Store.EPIC, "installed"))
|
||||
assertEquals("store", tabFor(Store.GOG, "store"))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user