mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Merge remote-tracking branch 'origin/main' into fix/update-channel-guess
This commit is contained in:
commit
97480e5e83
262 files changed
+15340
-1290
No files matched your search
@@ -0,0 +1,268 @@
|
||||
package com.droiddeck.launcher
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.Looper
|
||||
import com.droiddeck.launcher.session.LoadingState
|
||||
import com.droiddeck.launcher.session.ProtonExtras
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.ui.LaunchOrigin
|
||||
import java.time.Duration
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.TimeUnit
|
||||
import org.junit.After
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.util.ReflectionHelpers
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], manifest = Config.NONE)
|
||||
class CompatLaunchTest {
|
||||
private lateinit var activity: FrontEndActivity
|
||||
private lateinit var protons: ProtonMenu
|
||||
|
||||
@Before fun setUp() {
|
||||
installing(false)
|
||||
LaunchOrigin.take()
|
||||
activity = Robolectric.buildActivity(FrontEndActivity::class.java).get()
|
||||
protons = ReflectionHelpers.getField(activity, "protons")
|
||||
ReflectionHelpers.setField(activity, "compatLaunchVisible", true)
|
||||
protons.protonBusyId = "droiddeck"
|
||||
protons.protonProblem = null
|
||||
protons.protonStage = "Downloading DroidDeck Proton"
|
||||
protons.protonPercent = 37
|
||||
setString("setPkgStage", null)
|
||||
}
|
||||
|
||||
@After fun cleanUp() {
|
||||
cancel()
|
||||
protons.protonBusyId = null
|
||||
protons.protonProblem = null
|
||||
protons.protonStage = null
|
||||
protons.protonPercent = -1
|
||||
setString("setPkgStage", null)
|
||||
installing(false)
|
||||
LaunchOrigin.take()
|
||||
}
|
||||
|
||||
@Test fun waitingShowsRealProgressThenStartsTheOriginalRequestOnce() {
|
||||
activity.startActivity(request("steam://rungameid/42"))
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
assertEquals(37, loading().percent)
|
||||
assertTrue(loading().step.contains("37%"))
|
||||
protons.protonStage = "Verifying download"
|
||||
protons.protonPercent = -1
|
||||
advance()
|
||||
assertEquals("Verifying download", loading().step)
|
||||
assertEquals(-1, loading().percent)
|
||||
protons.protonBusyId = null
|
||||
advance()
|
||||
assertEquals("steam://rungameid/42", shadowOf(activity).nextStartedActivity.getStringExtra(SessionService.EXTRA_STEAM_URL))
|
||||
assertNull(waiting())
|
||||
advance()
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
}
|
||||
|
||||
@Test fun cancellingTheLaunchLeavesTheInstallRunningAndPreventsALateStart() {
|
||||
activity.startActivity(request("first"))
|
||||
cancel()
|
||||
assertEquals("droiddeck", protons.protonBusyId)
|
||||
protons.protonBusyId = null
|
||||
advance()
|
||||
assertNull(waiting())
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
}
|
||||
|
||||
@Test fun installationFailureStaysOnTheLoadingErrorWithoutStarting() {
|
||||
activity.startActivity(request("first"))
|
||||
protons.protonProblem = "Checksum verification failed"
|
||||
protons.protonBusyId = null
|
||||
advance()
|
||||
assertTrue(loading().ended)
|
||||
assertEquals("Checksum verification failed", loading().step)
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
}
|
||||
|
||||
@Test fun repeatedLaunchesDoNotReplaceThePendingGame() {
|
||||
activity.startActivity(request("first"))
|
||||
activity.startActivity(request("second"))
|
||||
protons.protonBusyId = null
|
||||
advance()
|
||||
assertEquals("first", shadowOf(activity).nextStartedActivity.getStringExtra(SessionService.EXTRA_STEAM_URL))
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
}
|
||||
|
||||
@Test fun anInstallOutsideTheLauncherUsesIndeterminateProgress() {
|
||||
protons.protonBusyId = null
|
||||
installing(true)
|
||||
activity.startActivity(request("first"))
|
||||
assertEquals(-1, loading().percent)
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
installing(false)
|
||||
advance()
|
||||
assertNotNull(shadowOf(activity).nextStartedActivity)
|
||||
}
|
||||
|
||||
@Test fun finishingInTheBackgroundWaitsUntilTheLauncherIsVisible() {
|
||||
activity.startActivity(request("first"))
|
||||
ReflectionHelpers.setField(activity, "compatLaunchVisible", false)
|
||||
protons.protonBusyId = null
|
||||
advance()
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
ReflectionHelpers.setField(activity, "compatLaunchVisible", true)
|
||||
advance()
|
||||
assertNotNull(shadowOf(activity).nextStartedActivity)
|
||||
}
|
||||
|
||||
@Test fun aRestoredCompletedRequestWaitsForResume() {
|
||||
activity.startActivity(request("first"))
|
||||
val saved = save()
|
||||
cancel()
|
||||
protons.protonBusyId = null
|
||||
recreate(saved)
|
||||
advance()
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
ReflectionHelpers.setField(activity, "compatLaunchVisible", true)
|
||||
advance()
|
||||
assertEquals("first", shadowOf(activity).nextStartedActivity.getStringExtra(SessionService.EXTRA_STEAM_URL))
|
||||
}
|
||||
|
||||
@Test fun overlappingPackageWorkKeepsTheOriginalLaunchUntilItFinishes() {
|
||||
activity.startActivity(request("first"))
|
||||
setString("setPkgStage", "Installing desktop")
|
||||
ReflectionHelpers.callInstanceMethod<Void>(activity, "setPkgPercent", ReflectionHelpers.ClassParameter.from(Int::class.javaPrimitiveType, 64))
|
||||
protons.protonBusyId = null
|
||||
advance()
|
||||
assertNotNull(waiting())
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
assertEquals("Installing desktop", loading().step)
|
||||
assertEquals(64, loading().percent)
|
||||
setString("setPkgStage", null)
|
||||
advance()
|
||||
assertEquals("first", shadowOf(activity).nextStartedActivity.getStringExtra(SessionService.EXTRA_STEAM_URL))
|
||||
advance()
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
}
|
||||
|
||||
@Test fun overlappingRuntimeWorkDoesNotDropThePendingLaunch() {
|
||||
activity.startActivity(request("first"))
|
||||
setString("setStage", "Updating runtime")
|
||||
ReflectionHelpers.callInstanceMethod<Void>(activity, "setBusy", ReflectionHelpers.ClassParameter.from(Boolean::class.javaPrimitiveType, true))
|
||||
protons.protonBusyId = null
|
||||
advance()
|
||||
assertNotNull(waiting())
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
assertEquals("Updating runtime", loading().step)
|
||||
ReflectionHelpers.callInstanceMethod<Void>(activity, "setBusy", ReflectionHelpers.ClassParameter.from(Boolean::class.javaPrimitiveType, false))
|
||||
advance()
|
||||
assertEquals("first", shadowOf(activity).nextStartedActivity.getStringExtra(SessionService.EXTRA_STEAM_URL))
|
||||
}
|
||||
|
||||
@Test fun aPackageDownloadStillBlocksTheLaunchAfterRecreationAndReportsOldWorkerProgress() {
|
||||
activity.startActivity(request("first"))
|
||||
setString("setPkgStage", "Downloading AppImage")
|
||||
ReflectionHelpers.callInstanceMethod<Void>(activity, "setPkgPercent", ReflectionHelpers.ClassParameter.from(Int::class.javaPrimitiveType, 23))
|
||||
val workerActivity = activity
|
||||
val saved = save()
|
||||
cancel()
|
||||
recreate(saved)
|
||||
ReflectionHelpers.setField(activity, "compatLaunchVisible", true)
|
||||
protons.protonBusyId = null
|
||||
advance()
|
||||
assertNotNull(waiting())
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
assertEquals("Downloading AppImage", loading().step)
|
||||
assertEquals(23, loading().percent)
|
||||
android.os.Handler(Looper.getMainLooper()).post {
|
||||
setString("setPkgStage", "Placing AppImage", workerActivity)
|
||||
ReflectionHelpers.callInstanceMethod<Void>(workerActivity, "setPkgPercent", ReflectionHelpers.ClassParameter.from(Int::class.javaPrimitiveType, 90))
|
||||
}
|
||||
advance()
|
||||
assertEquals("Placing AppImage", loading().step)
|
||||
assertEquals(90, loading().percent)
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
android.os.Handler(Looper.getMainLooper()).post { setString("setPkgStage", null, workerActivity) }
|
||||
advance()
|
||||
assertEquals("first", shadowOf(activity).nextStartedActivity.getStringExtra(SessionService.EXTRA_STEAM_URL))
|
||||
advance()
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
}
|
||||
|
||||
@Test fun aFailedInstallAfterRecreationKeepsItsProgressAndError() = recreationFailure(false)
|
||||
|
||||
@Test fun aFailedInstallBeforeRestorationStillShowsItsError() = recreationFailure(true)
|
||||
|
||||
private fun recreationFailure(finishBeforeRestore: Boolean) {
|
||||
val entered = CountDownLatch(1)
|
||||
val finish = CountDownLatch(1)
|
||||
protons.protonBusyId = null
|
||||
protons.installer = { _, progress ->
|
||||
progress("Verifying download", 64)
|
||||
entered.countDown()
|
||||
check(finish.await(5, TimeUnit.SECONDS))
|
||||
"Checksum verification failed"
|
||||
}
|
||||
try {
|
||||
protons.installProton("droiddeck")
|
||||
assertTrue(entered.await(5, TimeUnit.SECONDS))
|
||||
activity.startActivity(request("first"))
|
||||
val saved = save()
|
||||
cancel()
|
||||
if (finishBeforeRestore) {
|
||||
finish.countDown()
|
||||
waitForInstall()
|
||||
}
|
||||
recreate(saved)
|
||||
if (!finishBeforeRestore) {
|
||||
advance()
|
||||
assertEquals(64, loading().percent)
|
||||
finish.countDown()
|
||||
waitForInstall()
|
||||
}
|
||||
ReflectionHelpers.setField(activity, "compatLaunchVisible", true)
|
||||
advance()
|
||||
assertEquals("Checksum verification failed", loading().step)
|
||||
assertTrue(loading().ended)
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
} finally {
|
||||
finish.countDown()
|
||||
waitForInstall()
|
||||
}
|
||||
}
|
||||
|
||||
private fun waitForInstall() {
|
||||
val deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(5)
|
||||
while (protons.protonBusyId != null && System.nanoTime() < deadline) {
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
Thread.sleep(10)
|
||||
}
|
||||
assertNull(protons.protonBusyId)
|
||||
}
|
||||
|
||||
private fun save() = Bundle().also {
|
||||
ReflectionHelpers.callInstanceMethod<Void>(activity, "saveCompatLaunch", ReflectionHelpers.ClassParameter.from(Bundle::class.java, it))
|
||||
}
|
||||
|
||||
private fun recreate(saved: Bundle) {
|
||||
activity = Robolectric.buildActivity(FrontEndActivity::class.java).get()
|
||||
protons = ReflectionHelpers.getField(activity, "protons")
|
||||
ReflectionHelpers.callInstanceMethod<Void>(activity, "restoreCompatLaunch", ReflectionHelpers.ClassParameter.from(Bundle::class.java, saved))
|
||||
}
|
||||
|
||||
private fun setString(method: String, value: String?, target: FrontEndActivity = activity) {
|
||||
ReflectionHelpers.callInstanceMethod<Void>(target, method, ReflectionHelpers.ClassParameter.from(String::class.java, value))
|
||||
}
|
||||
|
||||
private fun request(url: String) = Intent(activity, SessionActivity::class.java).putExtra(SessionService.EXTRA_STEAM_URL, url)
|
||||
private fun installing(on: Boolean) = ReflectionHelpers.setStaticField(ProtonExtras::class.java, "installInProgress", on)
|
||||
private fun waiting(): Any? = ReflectionHelpers.callInstanceMethod(activity, "getCompatLaunch")
|
||||
private fun loading(): LoadingState = ReflectionHelpers.getField(requireNotNull(waiting()), "loading")
|
||||
private fun cancel() { ReflectionHelpers.callInstanceMethod<Void>(activity, "cancelCompatLaunch") }
|
||||
private fun advance() = shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(250))
|
||||
}
|
||||
@@ -56,6 +56,10 @@ class ProtonMenuAutoTest {
|
||||
.put("tag", "${tool.prefix}-11-12").put("at", System.currentTimeMillis()))
|
||||
File(activity.filesDir, "proton-latest.json").writeText(latest.toString())
|
||||
menu = ProtonMenu(activity, Handler(Looper.getMainLooper())) { idle }
|
||||
menu.protonBusyId = null
|
||||
menu.protonProblem = null
|
||||
menu.protonStage = null
|
||||
menu.protonPercent = -1
|
||||
menu.installer = { tool, progress ->
|
||||
progress("Installing ${tool.name}", 50)
|
||||
install("${tool.prefix}-11-12")
|
||||
@@ -64,6 +68,10 @@ class ProtonMenuAutoTest {
|
||||
}
|
||||
|
||||
@After fun reset() {
|
||||
menu.protonBusyId = null
|
||||
menu.protonProblem = null
|
||||
menu.protonStage = null
|
||||
menu.protonPercent = -1
|
||||
AutoComponents.online = online
|
||||
AutoComponents.unfavourable = constrained
|
||||
SessionState.running = false
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.droiddeck.launcher.glasses
|
||||
|
||||
import android.content.Context
|
||||
import android.database.ContentObserver
|
||||
import android.provider.Settings
|
||||
import android.hardware.display.DisplayManager
|
||||
import android.view.Display
|
||||
import androidx.compose.runtime.MutableState
|
||||
import com.droiddeck.launcher.SessionActivity
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
@@ -36,10 +39,12 @@ class GlassesMirrorPacingTest {
|
||||
val panel = Shadow.extract<ModeDisplay>(activity.display)
|
||||
panel.supported = arrayOf(mode(1, 60f), mode(2, 90f), mode(3, 120f))
|
||||
panel.current = panel.supported.last()
|
||||
SessionState.fpsLimit = 0
|
||||
activity.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
}
|
||||
|
||||
@After fun cleanup() { SessionState.fpsLimit = 0 }
|
||||
@After fun cleanup() {
|
||||
activity.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
}
|
||||
|
||||
@Test fun connectingChangingRateAndDisconnectingUpdatePhonePacingWithoutSavingPreferences() {
|
||||
apply(connected, settings)
|
||||
@@ -47,25 +52,33 @@ class GlassesMirrorPacingTest {
|
||||
apply(connected, settings.copy(refreshHz = 90))
|
||||
expect(2, 90f, 90)
|
||||
apply(GlassesState(), settings)
|
||||
expect(3, 120f, 0)
|
||||
assertEquals(0, SessionState.fpsLimit)
|
||||
expect(3, 120f, SessionPrefs.FPS_UNPACED)
|
||||
}
|
||||
|
||||
@Test fun lowerSavedLimitSurvivesMirroringAndStalePhoneRefreshReports() {
|
||||
SessionState.fpsLimit = 30
|
||||
@Test fun retiredSavedLimitsDoNotCapThePhoneOrMirroredOutput() {
|
||||
activity.getSharedPreferences("session", Context.MODE_PRIVATE).edit()
|
||||
.putInt("fpsLimit.steam", 30).putInt("fpsLimit.desktop", 40).commit()
|
||||
apply(connected, settings)
|
||||
expect(1, 60f, 30)
|
||||
expect(1, 60f, 60)
|
||||
apply(connected.copy(hz = 120f), settings)
|
||||
expect(1, 60f, 30)
|
||||
expect(1, 60f, 60)
|
||||
apply(GlassesState(), settings)
|
||||
expect(3, 120f, 30)
|
||||
assertEquals(30, SessionState.fpsLimit)
|
||||
expect(3, 120f, SessionPrefs.FPS_UNPACED)
|
||||
}
|
||||
|
||||
@Test fun pacingFollowsThePanelWhenTheSystemKeepsALowerRateThanRequested() {
|
||||
Shadow.extract<ModeDisplay>(activity.display).current = mode(2, 90f)
|
||||
apply(GlassesState(), settings)
|
||||
expect(3, 90f, 0)
|
||||
expect(3, 90f, SessionPrefs.FPS_UNPACED)
|
||||
}
|
||||
|
||||
@Test fun aHigherRefreshSettingChoosesTheFasterModeAgain() {
|
||||
Settings.System.putFloat(activity.contentResolver, "peak_refresh_rate", 60f)
|
||||
apply(GlassesState(), settings)
|
||||
assertEquals(1, activity.window.attributes.preferredDisplayModeId)
|
||||
Settings.System.putFloat(activity.contentResolver, "peak_refresh_rate", 120f)
|
||||
ReflectionHelpers.getField<ContentObserver>(activity, "refreshSettingObserver").onChange(false)
|
||||
assertEquals(3, activity.window.attributes.preferredDisplayModeId)
|
||||
}
|
||||
|
||||
private fun apply(state: GlassesState, config: GlassesSettings) {
|
||||
|
||||
@@ -58,13 +58,6 @@ class GlassesRenderingTest {
|
||||
assertEquals(0, GlassesRendering.mirrorRefreshLimit(settings, ultra, true))
|
||||
}
|
||||
|
||||
@Test fun mirrorCapPreservesLowerLimitsAndRestoresTheRequestedLimitAfterDisconnect() {
|
||||
for (requested in listOf(0, 30, 60, 90, 120)) {
|
||||
assertEquals(if (requested == 30) 30 else 60, GlassesRendering.fpsLimit(requested, 60))
|
||||
assertEquals(requested, GlassesRendering.fpsLimit(requested, 0))
|
||||
}
|
||||
}
|
||||
|
||||
private fun render(settings: GlassesSettings, state: GlassesState = ultra, steamVr: Boolean = false) =
|
||||
GlassesRendering.cardboard(base, settings, state, outputActive = true, steamVrRunning = steamVr)
|
||||
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.os.Looper
|
||||
import android.view.KeyEvent
|
||||
import java.time.Duration
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], manifest = Config.NONE)
|
||||
class BackQamInputTest {
|
||||
private val changes = mutableListOf<Boolean>()
|
||||
private val taps = mutableListOf<Boolean>()
|
||||
private val input = BackQamInput(changes::add, taps::add)
|
||||
|
||||
@Test fun singleTapWaitsForTheDoubleTapWindowWithoutPressingQam() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(100)
|
||||
send(KeyEvent.ACTION_UP)
|
||||
advance(499)
|
||||
assertTrue(taps.isEmpty())
|
||||
advance(1)
|
||||
assertEquals(listOf(false), taps)
|
||||
assertTrue(changes.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun doubleTapProducesOnlyTheDoubleAction() {
|
||||
repeat(2) {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(100)
|
||||
send(KeyEvent.ACTION_UP)
|
||||
advance(100)
|
||||
}
|
||||
advance(1000)
|
||||
assertEquals(listOf(true), taps)
|
||||
assertTrue(changes.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun theConfiguredWindowControlsSingleAndDoubleTaps() {
|
||||
for (window in listOf(100L, 800L)) {
|
||||
taps.clear()
|
||||
val configured = BackQamInput(changes::add, taps::add, doubleTapMs = { window })
|
||||
fun press(action: Int) = configured.onKeyEvent(KeyEvent(action, KeyEvent.KEYCODE_BACK), true)
|
||||
press(KeyEvent.ACTION_DOWN)
|
||||
press(KeyEvent.ACTION_UP)
|
||||
advance(window - 1)
|
||||
assertTrue(taps.isEmpty())
|
||||
press(KeyEvent.ACTION_DOWN)
|
||||
press(KeyEvent.ACTION_UP)
|
||||
assertEquals(listOf(true), taps)
|
||||
taps.clear()
|
||||
press(KeyEvent.ACTION_DOWN)
|
||||
press(KeyEvent.ACTION_UP)
|
||||
advance(window - 1)
|
||||
assertTrue(taps.isEmpty())
|
||||
advance(1)
|
||||
assertEquals(listOf(false), taps)
|
||||
assertTrue(changes.isEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aHoldStartsAt700msAndNeverProducesATap() {
|
||||
assertTrue(send(KeyEvent.ACTION_DOWN))
|
||||
advance(699)
|
||||
assertTrue(changes.isEmpty())
|
||||
advance(1)
|
||||
for (repeat in 1..10) assertTrue(send(KeyEvent.ACTION_DOWN, repeat = repeat))
|
||||
advance(4000)
|
||||
assertEquals(listOf(true), changes)
|
||||
assertTrue(send(KeyEvent.ACTION_UP))
|
||||
advance(1000)
|
||||
assertEquals(listOf(true, false), changes)
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun releasingBetween500And700msStillProducesASingleTap() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(600)
|
||||
send(KeyEvent.ACTION_UP)
|
||||
advance(500)
|
||||
assertEquals(listOf(false), taps)
|
||||
assertTrue(changes.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun holdingTheSecondPressCancelsTheFirstTap() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
send(KeyEvent.ACTION_UP)
|
||||
advance(400)
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(699)
|
||||
assertTrue(taps.isEmpty())
|
||||
advance(1)
|
||||
assertEquals(listOf(true), changes)
|
||||
send(KeyEvent.ACTION_UP)
|
||||
advance(1000)
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun otherButtonsAndSelectPassThroughWhileBackIsHeld() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(700)
|
||||
for (code in listOf(KeyEvent.KEYCODE_BUTTON_X, KeyEvent.KEYCODE_BUTTON_SELECT)) {
|
||||
for (action in listOf(KeyEvent.ACTION_DOWN, KeyEvent.ACTION_UP)) {
|
||||
assertFalse(input.onKeyEvent(KeyEvent(action, code), true))
|
||||
}
|
||||
}
|
||||
assertEquals(listOf(true), changes)
|
||||
send(KeyEvent.ACTION_UP)
|
||||
assertEquals(listOf(true, false), changes)
|
||||
}
|
||||
|
||||
@Test fun aChordImmediatelyStartsAHoldAndSuppressesTheTap() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(25)
|
||||
input.onChordInput()
|
||||
assertEquals(listOf(true), changes)
|
||||
input.onChordInput()
|
||||
send(KeyEvent.ACTION_UP)
|
||||
advance(1000)
|
||||
assertEquals(listOf(true, false), changes)
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun aChordOnTheSecondPressCancelsBothTapActions() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
send(KeyEvent.ACTION_UP)
|
||||
advance(100)
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
input.onChordInput()
|
||||
send(KeyEvent.ACTION_UP)
|
||||
advance(1000)
|
||||
assertEquals(listOf(true, false), changes)
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun controllerInputAfterBackIsReleasedOrCancelledCannotStartAHold() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
send(KeyEvent.ACTION_UP)
|
||||
input.onChordInput()
|
||||
advance(500)
|
||||
assertEquals(listOf(false), taps)
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
input.cancel()
|
||||
input.onChordInput()
|
||||
advance(1000)
|
||||
assertTrue(changes.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun anImmediateChordKeepsAllBackOwnersUntilTheLastRelease() {
|
||||
send(KeyEvent.ACTION_DOWN, device = 4)
|
||||
send(KeyEvent.ACTION_DOWN, device = 5)
|
||||
input.onChordInput()
|
||||
input.onDeviceRemoved(4)
|
||||
assertEquals(listOf(true), changes)
|
||||
send(KeyEvent.ACTION_UP, device = 5)
|
||||
advance(1000)
|
||||
assertEquals(listOf(true, false), changes)
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun disabledRoutingPreservesBackNavigation() {
|
||||
assertFalse(send(KeyEvent.ACTION_DOWN, enabled = false))
|
||||
assertFalse(send(KeyEvent.ACTION_UP, enabled = false))
|
||||
assertTrue(changes.isEmpty())
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun losingFocusReleasesQamAndConsumesTheLateRelease() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(700)
|
||||
input.cancel()
|
||||
input.cancel()
|
||||
assertTrue(send(KeyEvent.ACTION_DOWN, repeat = 1, enabled = false))
|
||||
assertTrue(send(KeyEvent.ACTION_UP, enabled = false))
|
||||
advance(1000)
|
||||
assertEquals(listOf(true, false), changes)
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun cancellationBeforeTheThresholdPreventsBothHoldAndTap() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(100)
|
||||
input.cancel()
|
||||
send(KeyEvent.ACTION_UP)
|
||||
advance(1000)
|
||||
assertTrue(changes.isEmpty())
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun cancellationAlsoDiscardsAPendingSingleTap() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
send(KeyEvent.ACTION_UP)
|
||||
input.cancel()
|
||||
advance(1000)
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun openingAnOverlayReleasesQamBeforeRoutingItsNextKey() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(700)
|
||||
assertFalse(input.onKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BUTTON_B), false))
|
||||
assertTrue(send(KeyEvent.ACTION_UP, enabled = false))
|
||||
assertEquals(listOf(true, false), changes)
|
||||
}
|
||||
|
||||
@Test fun repeatsAfterCancellationCannotReassertQam() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(700)
|
||||
input.cancel()
|
||||
assertTrue(send(KeyEvent.ACTION_DOWN, repeat = 1))
|
||||
advance(1000)
|
||||
assertEquals(listOf(true, false), changes)
|
||||
assertTrue(send(KeyEvent.ACTION_DOWN))
|
||||
advance(700)
|
||||
assertTrue(send(KeyEvent.ACTION_UP))
|
||||
assertEquals(listOf(true, false, true, false), changes)
|
||||
}
|
||||
|
||||
@Test fun cancelledReleaseNeverProducesATap() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
assertTrue(input.onKeyEvent(KeyEvent(0, 100, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK,
|
||||
0, 0, 4, 0, KeyEvent.FLAG_CANCELED), true))
|
||||
advance(1000)
|
||||
assertTrue(changes.isEmpty())
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun removingOneDeviceDoesNotReleaseAnotherDevicesHold() {
|
||||
send(KeyEvent.ACTION_DOWN, device = 4)
|
||||
send(KeyEvent.ACTION_DOWN, device = 5)
|
||||
advance(700)
|
||||
input.onDeviceRemoved(4)
|
||||
assertEquals(listOf(true), changes)
|
||||
send(KeyEvent.ACTION_UP, device = 5)
|
||||
assertEquals(listOf(true, false), changes)
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
private fun advance(millis: Long) = shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(millis))
|
||||
|
||||
private fun send(action: Int, repeat: Int = 0, device: Int = 4, enabled: Boolean = true) =
|
||||
input.onKeyEvent(KeyEvent(0, 100, action, KeyEvent.KEYCODE_BACK, repeat, 0, device, 0), enabled)
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.app.Application
|
||||
import android.view.KeyEvent
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28, 33], manifest = Config.NONE, application = Application::class)
|
||||
class HomeGuideInputTest {
|
||||
private val states = mutableListOf<Boolean>()
|
||||
private var cancellations = 0
|
||||
private val input = HomeGuideInput({ states.add(it) }, { cancellations++ })
|
||||
|
||||
private fun home(action: Int, device: Int = 10, repeat: Int = 0, down: Long = 10) =
|
||||
KeyEvent(down, down + 100, action, KeyEvent.KEYCODE_HOME, repeat, 0, device, 102)
|
||||
|
||||
@Test fun guideIsHeldImmediatelyAndReleaseDoesNotDependOnAndroidDownTime() {
|
||||
assertTrue(input.onKeyEvent(home(KeyEvent.ACTION_DOWN), true))
|
||||
assertEquals(listOf(true), states)
|
||||
assertTrue(input.onKeyEvent(home(KeyEvent.ACTION_DOWN, repeat = 1), true))
|
||||
assertFalse(input.onKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BUTTON_X), true))
|
||||
assertTrue(input.onKeyEvent(home(KeyEvent.ACTION_UP, down = 77), true))
|
||||
assertEquals(listOf(true, false), states)
|
||||
}
|
||||
|
||||
@Test fun genericLayoutMoveHomeHoldsGuideLikeHome() {
|
||||
val down = KeyEvent(10, 110, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MOVE_HOME, 0, 0, 10, 102)
|
||||
val up = KeyEvent(10, 200, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MOVE_HOME, 0, 0, 10, 102)
|
||||
assertTrue(input.onKeyEvent(down, true))
|
||||
assertTrue(input.onKeyEvent(up, true))
|
||||
assertEquals(listOf(true, false), states)
|
||||
}
|
||||
|
||||
@Test fun anUnownedHomePressKeepsAndroidBehaviorEvenIfSessionBecomesEligibleBeforeRelease() {
|
||||
assertFalse(input.onKeyEvent(home(KeyEvent.ACTION_DOWN), false))
|
||||
assertFalse(input.onKeyEvent(home(KeyEvent.ACTION_UP), true))
|
||||
assertTrue(states.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun focusLossReleasesGuideAndConsumesTheOwnedReleaseWithoutAnotherTap() {
|
||||
input.onKeyEvent(home(KeyEvent.ACTION_DOWN), true)
|
||||
input.cancel()
|
||||
assertEquals(1, cancellations)
|
||||
assertTrue(input.onKeyEvent(home(KeyEvent.ACTION_DOWN, repeat = 2), false))
|
||||
assertTrue(input.onKeyEvent(home(KeyEvent.ACTION_UP), false))
|
||||
assertEquals(listOf(true, false), states)
|
||||
assertFalse(input.onKeyEvent(home(KeyEvent.ACTION_UP), false))
|
||||
}
|
||||
|
||||
@Test fun disablingDuringAHoldReleasesItAndDoesNotStealTheNextAndroidHomePress() {
|
||||
input.onKeyEvent(home(KeyEvent.ACTION_DOWN), true)
|
||||
assertTrue(input.onKeyEvent(home(KeyEvent.ACTION_UP), false))
|
||||
assertEquals(listOf(true, false), states)
|
||||
assertFalse(input.onKeyEvent(home(KeyEvent.ACTION_DOWN), false))
|
||||
}
|
||||
|
||||
@Test fun guideStaysHeldUntilAllOwnersReleaseAndDisconnectCancelsTheLastOwner() {
|
||||
input.onKeyEvent(home(KeyEvent.ACTION_DOWN), true)
|
||||
input.onKeyEvent(home(KeyEvent.ACTION_DOWN, device = 11), true)
|
||||
input.onKeyEvent(home(KeyEvent.ACTION_UP), true)
|
||||
assertEquals(listOf(true), states)
|
||||
input.onDeviceRemoved(11)
|
||||
assertEquals(listOf(true, false), states)
|
||||
assertEquals(1, cancellations)
|
||||
}
|
||||
}
|
||||
@@ -236,6 +236,53 @@ class OnScreenControlsTest {
|
||||
assertEquals(-1, field(control("ls"), "pressedBy"))
|
||||
}
|
||||
|
||||
@Test fun trackpadFingerKeepsItsOwnStreamWhileAStickIsHeld() {
|
||||
val forwarded = mutableListOf<Triple<Int, Int, Float>>()
|
||||
view.onTouchMiss = { forwarded += Triple(it.actionMasked, it.getPointerId(0), it.getX(0)) }
|
||||
touch(MotionEvent.ACTION_DOWN, 7 to (540f to 400f))
|
||||
assertTrue(touch(MotionEvent.ACTION_POINTER_DOWN or (1 shl 8), 7 to (540f to 400f), 9 to (600f to 200f)))
|
||||
touch(MotionEvent.ACTION_MOVE, 7 to (500f to 400f), 9 to (650f to 200f))
|
||||
touch(MotionEvent.ACTION_POINTER_UP or (1 shl 8), 7 to (500f to 400f), 9 to (650f to 200f))
|
||||
assertEquals(listOf(
|
||||
Triple(MotionEvent.ACTION_DOWN, 9, 600f),
|
||||
Triple(MotionEvent.ACTION_MOVE, 9, 650f),
|
||||
Triple(MotionEvent.ACTION_UP, 9, 650f),
|
||||
), forwarded)
|
||||
assertEquals(7, field(control("ls"), "pressedBy"))
|
||||
assertTrue(value(control("ls"), "kx") < 0f)
|
||||
}
|
||||
|
||||
@Test fun stickPressedAfterTrackpadFingerReachesTheControls() {
|
||||
val received = mutableListOf<Triple<Int, Int, Int>>()
|
||||
val trackpad = View(context).apply {
|
||||
setOnTouchListener { _, event -> received += Triple(event.actionMasked, event.pointerCount, event.getPointerId(0)); true }
|
||||
}
|
||||
val root = FrameLayout(context).apply {
|
||||
isMotionEventSplittingEnabled = true
|
||||
addView(trackpad, FrameLayout.LayoutParams(1200, 800))
|
||||
addView(view, FrameLayout.LayoutParams(1200, 800))
|
||||
measure(View.MeasureSpec.makeMeasureSpec(1200, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.EXACTLY))
|
||||
layout(0, 0, 1200, 800)
|
||||
}
|
||||
fun dispatch(action: Int, vararg pointers: Pair<Int, Pair<Float, Float>>) {
|
||||
val properties = pointers.map { (id, _) -> MotionEvent.PointerProperties().apply { this.id = id; toolType = MotionEvent.TOOL_TYPE_FINGER } }.toTypedArray()
|
||||
val coords = pointers.map { (_, position) -> MotionEvent.PointerCoords().apply { x = position.first; y = position.second; pressure = 1f; size = 1f } }.toTypedArray()
|
||||
val event = MotionEvent.obtain(1000L, time++, action, pointers.size, properties, coords, 0, 0, 1f, 1f, 0, 0, 0, 0)
|
||||
try { assertTrue(root.dispatchTouchEvent(event)) } finally { event.recycle() }
|
||||
}
|
||||
dispatch(MotionEvent.ACTION_DOWN, 0 to (600f to 200f))
|
||||
dispatch(MotionEvent.ACTION_POINTER_DOWN or (1 shl 8), 0 to (600f to 200f), 1 to (540f to 400f))
|
||||
dispatch(MotionEvent.ACTION_MOVE, 0 to (640f to 220f), 1 to (500f to 400f))
|
||||
assertEquals(1, field(control("ls"), "pressedBy"))
|
||||
assertTrue(value(control("ls"), "kx") < 0f)
|
||||
dispatch(MotionEvent.ACTION_POINTER_UP or (1 shl 8), 0 to (640f to 220f), 1 to (500f to 400f))
|
||||
dispatch(MotionEvent.ACTION_UP, 0 to (640f to 220f))
|
||||
assertEquals(-1, field(control("ls"), "pressedBy"))
|
||||
assertEquals(Triple(MotionEvent.ACTION_DOWN, 1, 0), received.first())
|
||||
assertEquals(Triple(MotionEvent.ACTION_UP, 1, 0), received.last())
|
||||
assertTrue(received.all { it.second == 1 && it.third == 0 })
|
||||
}
|
||||
|
||||
@Test fun adaptiveActivationLeavesFivePixelsAroundButtonHitTargets() {
|
||||
for (id in listOf("a", "rb")) {
|
||||
val button = control(id)
|
||||
|
||||
@@ -0,0 +1,463 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.hardware.input.InputManager
|
||||
import android.view.InputDevice
|
||||
import android.view.KeyEvent
|
||||
import android.view.MotionEvent
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import java.nio.file.Files
|
||||
import java.time.Duration
|
||||
import org.junit.After
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
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.util.ReflectionHelpers
|
||||
import org.robolectric.shadows.InputDeviceBuilder
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], manifest = Config.NONE, instrumentedPackages = ["com.droiddeck.launcher.input.FakeInputWriter", "com.droiddeck.launcher.wayland.WaylandCompositor"],
|
||||
shadows = [JoyConPadTest.RecordingWriter::class, PadBridgeRoutingTest.RegisteredKeyEvent::class,
|
||||
PadBridgeRoutingTest.RegisteredMotionEvent::class, SessionGestureRoutingTest.CompositorShadow::class])
|
||||
class PadBridgeQamTest {
|
||||
private val directory = Files.createTempDirectory("qam-pad").toFile()
|
||||
private lateinit var bridge: PadBridge
|
||||
|
||||
@Before fun start() {
|
||||
JoyConPadTest.RecordingWriter.pads.clear()
|
||||
ReflectionHelpers.setStaticField(FakeInputWriter::class.java, "padType", FakeInputWriter.PAD_TYPE_DECK)
|
||||
SessionState.deckPad = true
|
||||
bridge = PadBridge(directory)
|
||||
assertTrue(bridge.start())
|
||||
}
|
||||
|
||||
@After fun stop() {
|
||||
bridge.stop()
|
||||
SessionState.deckPad = false
|
||||
directory.deleteRecursively()
|
||||
}
|
||||
|
||||
@Test fun onlyNativeQamControllersAcceptAHeldBack() {
|
||||
for (type in listOf(-1, FakeInputWriter.PAD_TYPE_DECK, FakeInputWriter.PAD_TYPE_STEAM,
|
||||
FakeInputWriter.PAD_TYPE_XBOX, FakeInputWriter.PAD_TYPE_DS4, FakeInputWriter.PAD_TYPE_DUALSENSE)) {
|
||||
ReflectionHelpers.setStaticField(FakeInputWriter::class.java, "padType", type)
|
||||
val supported = type <= FakeInputWriter.PAD_TYPE_STEAM
|
||||
assertEquals(supported, bridge.canHoldQam())
|
||||
bridge.setBackQamPressed(true)
|
||||
bridge.applyExternal({}, false)
|
||||
assertEquals(supported, pad().isDown(PadState.QAM))
|
||||
bridge.setBackQamPressed(false)
|
||||
advanceTime()
|
||||
}
|
||||
SessionState.deckPad = false
|
||||
assertFalse(bridge.canHoldQam())
|
||||
}
|
||||
|
||||
@Test fun qamAndOtherButtonsShareAReportUntilBackIsReleased() {
|
||||
bridge.setBackQamPressed(true)
|
||||
advanceTime()
|
||||
bridge.applyExternal({ it.press(PadState.X, true); it.press(PadState.SELECT, true) }, true)
|
||||
advanceTime()
|
||||
assertTrue(pad().isDown(PadState.QAM))
|
||||
assertTrue(pad().isDown(PadState.X))
|
||||
assertTrue(pad().isDown(PadState.SELECT))
|
||||
bridge.setBackQamPressed(false)
|
||||
advanceTime()
|
||||
assertFalse(pad().isDown(PadState.QAM))
|
||||
assertTrue(pad().isDown(PadState.X))
|
||||
assertTrue(pad().isDown(PadState.SELECT))
|
||||
}
|
||||
|
||||
@Test fun touchQamAndBackHaveIndependentReleases() {
|
||||
bridge.setBackQamPressed(true)
|
||||
bridge.setSystemButtons(false, true)
|
||||
bridge.setBackQamPressed(false)
|
||||
assertTrue(pad().isDown(PadState.QAM))
|
||||
bridge.setBackQamPressed(true)
|
||||
bridge.setSystemButtons(false, false)
|
||||
assertTrue(pad().isDown(PadState.QAM))
|
||||
bridge.setBackQamPressed(false)
|
||||
advanceTime()
|
||||
assertFalse(pad().isDown(PadState.QAM))
|
||||
}
|
||||
|
||||
@Test fun aTimedQamTapCannotReleaseAHeldBack() {
|
||||
bridge.triggerQam()
|
||||
bridge.setBackQamPressed(true)
|
||||
advanceTime()
|
||||
assertTrue(pad().isDown(PadState.QAM))
|
||||
bridge.setBackQamPressed(false)
|
||||
assertFalse(pad().isDown(PadState.QAM))
|
||||
}
|
||||
|
||||
@Test fun releasingAllOrStoppingClearsTheHold() {
|
||||
bridge.setBackQamPressed(true)
|
||||
bridge.releaseAll()
|
||||
assertFalse(pad().isDown(PadState.QAM))
|
||||
bridge.setBackQamPressed(true)
|
||||
bridge.stop()
|
||||
bridge.start()
|
||||
bridge.applyExternal({}, false)
|
||||
assertFalse(pad().isDown(PadState.QAM))
|
||||
}
|
||||
|
||||
@Test fun disablingTheBuiltinPadClearsAndRejectsTheHold() {
|
||||
bridge.setBackQamPressed(true)
|
||||
bridge.setBuiltinPad(false)
|
||||
assertFalse(bridge.canHoldQam())
|
||||
assertFalse(pad().isDown(PadState.QAM))
|
||||
bridge.setBackQamPressed(true)
|
||||
bridge.setBuiltinPad(true)
|
||||
bridge.applyExternal({}, false)
|
||||
assertFalse(pad().isDown(PadState.QAM))
|
||||
}
|
||||
|
||||
@Test fun aQuickPartnerPressReachesSteamWithQamAndReleasesIndependently() {
|
||||
val device = controller()
|
||||
val taps = mutableListOf<Boolean>()
|
||||
val input = BackQamInput(bridge::setBackQamPressed, taps::add)
|
||||
bridge.setOnChordInput {
|
||||
assertFalse(pad().isDown(PadState.X))
|
||||
input.onChordInput()
|
||||
}
|
||||
input.onKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK), true)
|
||||
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(25))
|
||||
assertTrue(bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_BUTTON_X)))
|
||||
assertTrue(pad().isDown(PadState.QAM))
|
||||
assertFalse(pad().isDown(PadState.X))
|
||||
advance(79)
|
||||
assertFalse(pad().isDown(PadState.X))
|
||||
advance(1)
|
||||
assertTrue(pad().isDown(PadState.X))
|
||||
input.onKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK), true)
|
||||
assertFalse(pad().isDown(PadState.QAM))
|
||||
assertTrue(pad().isDown(PadState.X))
|
||||
bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_BUTTON_X, KeyEvent.ACTION_UP))
|
||||
advance(80)
|
||||
assertFalse(pad().isDown(PadState.X))
|
||||
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(1))
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun onlyFreshAcceptedPrimaryControllerPressesPromoteAChord() {
|
||||
val device = controller()
|
||||
val second = controller(11)
|
||||
val promoted = mutableListOf<Boolean>()
|
||||
bridge.setOnChordInput { promoted.add(true) }
|
||||
bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_BUTTON_X, KeyEvent.ACTION_UP))
|
||||
bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_BUTTON_X, repeat = 1))
|
||||
bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_A))
|
||||
bridge.onKeyEvent(key(second, KeyEvent.KEYCODE_BUTTON_X))
|
||||
bridge.setExcluded { it == device.id }
|
||||
bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_BUTTON_X))
|
||||
assertTrue(promoted.isEmpty())
|
||||
bridge.setExcluded { false }
|
||||
for (code in listOf(KeyEvent.KEYCODE_BUTTON_X, KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_BUTTON_L2)) {
|
||||
bridge.onKeyEvent(key(device, code))
|
||||
}
|
||||
assertEquals(3, promoted.size)
|
||||
}
|
||||
|
||||
@Test fun aQuickChordKeepsItsPressAndReleaseAfterTheModifierLead() {
|
||||
bridge.setBackQamPressed(true)
|
||||
bridge.applyExternal({ it.press(PadState.X, true) }, true)
|
||||
advance(20)
|
||||
bridge.applyExternal({ it.press(PadState.X, false) }, true)
|
||||
bridge.setBackQamPressed(false)
|
||||
assertTrue(pad().isDown(PadState.QAM))
|
||||
assertFalse(pad().isDown(PadState.X))
|
||||
advance(60)
|
||||
assertTrue(pad().isDown(PadState.QAM))
|
||||
assertTrue(pad().isDown(PadState.X))
|
||||
advance(19)
|
||||
assertTrue(pad().isDown(PadState.X))
|
||||
advance(1)
|
||||
assertFalse(pad().isDown(PadState.X))
|
||||
assertFalse(pad().isDown(PadState.QAM))
|
||||
}
|
||||
|
||||
@Test fun cancellationDiscardsQueuedPartnersAndTheirReleases() {
|
||||
val input = BackQamInput(bridge::setBackQamPressed, {}, onCancel = bridge::cancelBackQam)
|
||||
input.onKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK), true)
|
||||
input.onChordInput()
|
||||
bridge.applyExternal({ it.press(PadState.LB, true) }, true)
|
||||
input.onKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK), true)
|
||||
input.cancel()
|
||||
advance(1000)
|
||||
assertFalse(pad().isDown(PadState.LB))
|
||||
assertFalse(pad().isDown(PadState.QAM))
|
||||
bridge.applyExternal({ it.press(PadState.X, true) }, true)
|
||||
input.cancel()
|
||||
assertTrue(pad().isDown(PadState.X))
|
||||
}
|
||||
|
||||
@Test fun aSettledHoldDoesNotDelayLaterPartnerInput() {
|
||||
bridge.setBackQamPressed(true)
|
||||
advance(80)
|
||||
bridge.applyExternal({ it.press(PadState.LB, true) }, true)
|
||||
assertTrue(pad().isDown(PadState.LB))
|
||||
bridge.setBackQamPressed(false)
|
||||
assertFalse(pad().isDown(PadState.QAM))
|
||||
}
|
||||
|
||||
@Test fun disconnectingThePartnerControllerDiscardsItsQueuedPress() {
|
||||
val device = controller()
|
||||
bridge.setBackQamPressed(true)
|
||||
bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_BUTTON_L1))
|
||||
advance(20)
|
||||
bridge.onDeviceRemoved(device.id)
|
||||
assertTrue(pad().isDown(PadState.QAM))
|
||||
assertFalse(pad().isDown(PadState.LB))
|
||||
advance(60)
|
||||
assertFalse(pad().isDown(PadState.LB))
|
||||
advance(1000)
|
||||
assertFalse(pad().isDown(PadState.LB))
|
||||
assertTrue(pad().isDown(PadState.QAM))
|
||||
}
|
||||
|
||||
@Test fun disconnectingThePartnerControllerImmediatelyReleasesADeliveredPress() {
|
||||
val device = controller()
|
||||
bridge.setBackQamPressed(true)
|
||||
bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_BUTTON_L1))
|
||||
advance(80)
|
||||
assertTrue(pad().isDown(PadState.LB))
|
||||
bridge.onDeviceRemoved(device.id)
|
||||
assertFalse(pad().isDown(PadState.LB))
|
||||
assertTrue(pad().isDown(PadState.QAM))
|
||||
advance(1000)
|
||||
assertFalse(pad().isDown(PadState.LB))
|
||||
}
|
||||
|
||||
@Test fun removingAnotherPlayerDoesNotDiscardThePrimaryPlayersQueuedChord() {
|
||||
val device = controller()
|
||||
bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_BUTTON_L1, KeyEvent.ACTION_UP))
|
||||
val other = controller(11)
|
||||
bridge.onKeyEvent(key(other, KeyEvent.KEYCODE_BUTTON_X, KeyEvent.ACTION_UP))
|
||||
bridge.setBackQamPressed(true)
|
||||
bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_BUTTON_L1))
|
||||
bridge.onDeviceRemoved(other.id)
|
||||
advance(80)
|
||||
assertTrue(pad().isDown(PadState.LB))
|
||||
assertTrue(pad().isDown(PadState.QAM))
|
||||
}
|
||||
|
||||
@Test fun pairingOnAnIgnoredRailKeyImmediatelyReleasesDeliveredButtonsAndDropsQueuedOnes() {
|
||||
val left = controller(product = 0x2006)
|
||||
bridge.setBackQamPressed(true)
|
||||
bridge.onKeyEvent(key(left, KeyEvent.KEYCODE_BUTTON_L1))
|
||||
advance(80)
|
||||
assertTrue(pad().isDown(PadState.LB))
|
||||
bridge.onKeyEvent(key(left, KeyEvent.KEYCODE_BUTTON_X))
|
||||
val right = controller(11, product = 0x2007)
|
||||
assertTrue(bridge.onKeyEvent(key(right, KeyEvent.KEYCODE_BUTTON_L1, scan = 0x136)))
|
||||
assertFalse(pad().isDown(PadState.LB))
|
||||
assertFalse(pad().isDown(PadState.X))
|
||||
assertTrue(pad().isDown(PadState.QAM))
|
||||
advance(1000)
|
||||
assertFalse(pad().isDown(PadState.LB))
|
||||
assertFalse(pad().isDown(PadState.X))
|
||||
}
|
||||
|
||||
@Test fun queuedReportsUseTheLiveStickAndStopItImmediatelyOnBackRelease() {
|
||||
bridge.setBackQamPressed(true)
|
||||
bridge.applyExternal({ it.press(PadState.X, true); it.leftY = -1f }, true)
|
||||
advance(20)
|
||||
bridge.applyExternal({ it.leftY = -0.25f }, true)
|
||||
advance(60)
|
||||
assertEquals(-0.25f, pad().leftY)
|
||||
bridge.setBackQamPressed(false)
|
||||
assertEquals(0f, pad().leftY)
|
||||
advance(1000)
|
||||
assertEquals(0f, pad().leftY)
|
||||
bridge.applyExternal({ it.leftY = 0f }, true)
|
||||
bridge.applyExternal({ it.leftY = 0.75f }, true)
|
||||
assertEquals(0.75f, pad().leftY)
|
||||
}
|
||||
|
||||
@Test fun releasingBackDuringTheLeadNeverReplaysAnOldStickMovement() {
|
||||
bridge.setBackQamPressed(true)
|
||||
bridge.applyExternal({ it.leftY = -1f }, true)
|
||||
advance(20)
|
||||
bridge.setBackQamPressed(false)
|
||||
advance(1000)
|
||||
assertEquals(0f, pad().leftY)
|
||||
assertFalse(pad().isDown(PadState.QAM))
|
||||
}
|
||||
|
||||
@Test fun theInitialPartnerKeepsItsDurationWhenReleasedAfterTheLead() {
|
||||
bridge.setBackQamPressed(true)
|
||||
bridge.applyExternal({ it.press(PadState.X, true) }, true)
|
||||
advance(100)
|
||||
bridge.applyExternal({ it.press(PadState.X, false) }, true)
|
||||
assertTrue(pad().isDown(PadState.X))
|
||||
advance(79)
|
||||
assertTrue(pad().isDown(PadState.X))
|
||||
advance(1)
|
||||
assertFalse(pad().isDown(PadState.X))
|
||||
}
|
||||
|
||||
@Test fun deliberateStickTriggerAndHatMotionPromoteChordsButNeutralAndDriftDoNot() {
|
||||
val device = controller()
|
||||
val promoted = mutableListOf<Boolean>()
|
||||
bridge.setOnChordInput { promoted.add(true) }
|
||||
for ((axis, value) in listOf(MotionEvent.AXIS_X to 0f, MotionEvent.AXIS_X to 0.1f,
|
||||
MotionEvent.AXIS_LTRIGGER to 0f, MotionEvent.AXIS_HAT_Y to 0f)) motion(device, axis, value)
|
||||
assertTrue(promoted.isEmpty())
|
||||
for ((axis, value) in listOf(MotionEvent.AXIS_X to -0.15f, MotionEvent.AXIS_LTRIGGER to 0.75f,
|
||||
MotionEvent.AXIS_HAT_Y to -1f)) motion(device, axis, value)
|
||||
assertEquals(3, promoted.size)
|
||||
}
|
||||
|
||||
private fun controller(id: Int = 10, product: Int = 0): InputDevice {
|
||||
val builder = InputDeviceBuilder.newBuilder().setId(id).setName("QAM pad $id")
|
||||
.setVendorId(if (product == 0) 0 else 0x057e).setProductId(product)
|
||||
.setDescriptor("qam-pad-$id").setExternal(true).setKeyboardType(InputDevice.KEYBOARD_TYPE_NON_ALPHABETIC)
|
||||
.setSources(InputDevice.SOURCE_GAMEPAD or InputDevice.SOURCE_JOYSTICK)
|
||||
for (axis in listOf(MotionEvent.AXIS_X, MotionEvent.AXIS_LTRIGGER, MotionEvent.AXIS_HAT_Y)) {
|
||||
builder.addMotionRange(axis, InputDevice.SOURCE_JOYSTICK, 0f, 1f, 0f, 0f, 0f)
|
||||
}
|
||||
return builder.build().also {
|
||||
shadowOf(RuntimeEnvironment.getApplication().getSystemService(InputManager::class.java)).addInputDevice(it)
|
||||
bridge.applyExternal({}, false)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun homeGuidePrecedesEarlyPartnerInputAndDoesNotGenerateABareButton() {
|
||||
bridge.setHomeGuidePressed(true)
|
||||
assertTrue(pad().isDown(PadState.GUIDE))
|
||||
bridge.applyExternal({ it.press(PadState.X, true) }, true)
|
||||
assertFalse(pad().isDown(PadState.X))
|
||||
advance(80)
|
||||
assertTrue(pad().isDown(PadState.GUIDE))
|
||||
assertTrue(pad().isDown(PadState.X))
|
||||
bridge.applyExternal({ it.press(PadState.X, false) }, true)
|
||||
bridge.setHomeGuidePressed(false)
|
||||
advance(1000)
|
||||
assertFalse(pad().isDown(PadState.GUIDE))
|
||||
assertFalse(pad().isDown(PadState.X))
|
||||
}
|
||||
|
||||
@Test fun homeGuideHoldsOnThePrimaryPlayerWithoutABuiltinPad() {
|
||||
PadBridge.setFirstSlot(1)
|
||||
try {
|
||||
bridge.setBuiltinPad(false)
|
||||
bridge.setHomeGuidePressed(true)
|
||||
assertTrue(requireNotNull(JoyConPadTest.RecordingWriter.pads[1]).isDown(PadState.GUIDE))
|
||||
bridge.setHomeGuidePressed(false)
|
||||
assertFalse(requireNotNull(JoyConPadTest.RecordingWriter.pads[1]).isDown(PadState.GUIDE))
|
||||
} finally {
|
||||
PadBridge.setFirstSlot(0)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun homeGuideAndControllerGuideReleaseIndependentlyOnThePrimaryPlayer() {
|
||||
PadBridge.setFirstSlot(1)
|
||||
try {
|
||||
bridge.setBuiltinPad(false)
|
||||
val device = controller()
|
||||
bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_BUTTON_MODE))
|
||||
bridge.setHomeGuidePressed(true)
|
||||
bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_BUTTON_MODE, KeyEvent.ACTION_UP))
|
||||
assertTrue(requireNotNull(JoyConPadTest.RecordingWriter.pads[1]).isDown(PadState.GUIDE))
|
||||
bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_BUTTON_MODE))
|
||||
bridge.setHomeGuidePressed(false)
|
||||
assertTrue(requireNotNull(JoyConPadTest.RecordingWriter.pads[1]).isDown(PadState.GUIDE))
|
||||
bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_BUTTON_MODE, KeyEvent.ACTION_UP))
|
||||
assertFalse(requireNotNull(JoyConPadTest.RecordingWriter.pads[1]).isDown(PadState.GUIDE))
|
||||
} finally {
|
||||
PadBridge.setFirstSlot(0)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun removingThePrimaryPlayerForgetsItsHomeGuide() {
|
||||
PadBridge.setFirstSlot(1)
|
||||
try {
|
||||
bridge.setBuiltinPad(false)
|
||||
val device = controller()
|
||||
bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_BUTTON_A, KeyEvent.ACTION_UP))
|
||||
bridge.setHomeGuidePressed(true)
|
||||
bridge.onDeviceRemoved(device.id)
|
||||
JoyConPadTest.RecordingWriter.pads.remove(1)
|
||||
bridge.cancelHomeGuide()
|
||||
bridge.setHomeGuidePressed(false)
|
||||
assertNull(JoyConPadTest.RecordingWriter.pads[1])
|
||||
} finally {
|
||||
PadBridge.setFirstSlot(0)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun cancellingHomeGuideOnAPlayerSlotKeepsItsHeldControls() {
|
||||
PadBridge.setFirstSlot(1)
|
||||
try {
|
||||
bridge.setBuiltinPad(false)
|
||||
val device = controller()
|
||||
bridge.onKeyEvent(key(device, KeyEvent.KEYCODE_BUTTON_A))
|
||||
bridge.setHomeGuidePressed(true)
|
||||
bridge.cancelHomeGuide()
|
||||
val pad = requireNotNull(JoyConPadTest.RecordingWriter.pads[1])
|
||||
assertFalse(pad.isDown(PadState.GUIDE))
|
||||
assertTrue(pad.isDown(PadState.A))
|
||||
} finally {
|
||||
PadBridge.setFirstSlot(0)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun cancellingHomeDiscardsQueuedPartnersAndReleasesGuideImmediately() {
|
||||
bridge.setHomeGuidePressed(true)
|
||||
bridge.applyExternal({ it.press(PadState.LB, true); it.leftY = -1f }, true)
|
||||
bridge.cancelHomeGuide()
|
||||
advance(1000)
|
||||
assertFalse(pad().isDown(PadState.GUIDE))
|
||||
assertFalse(pad().isDown(PadState.LB))
|
||||
assertEquals(0f, pad().leftY)
|
||||
}
|
||||
|
||||
@Test fun homeAndTouchGuideHaveIndependentReleases() {
|
||||
bridge.setHomeGuidePressed(true)
|
||||
bridge.setSystemButtons(true, false)
|
||||
bridge.setHomeGuidePressed(false)
|
||||
advance(1000)
|
||||
assertTrue(pad().isDown(PadState.GUIDE))
|
||||
bridge.setSystemButtons(false, false)
|
||||
advance(1000)
|
||||
assertFalse(pad().isDown(PadState.GUIDE))
|
||||
}
|
||||
|
||||
@Test fun releasingHomeStopsHeldAxesFromBecomingNavigation() {
|
||||
bridge.setHomeGuidePressed(true)
|
||||
bridge.applyExternal({ it.leftY = -1f }, true)
|
||||
advance(80)
|
||||
assertEquals(-1f, pad().leftY)
|
||||
bridge.setHomeGuidePressed(false)
|
||||
advance(1000)
|
||||
assertEquals(0f, pad().leftY)
|
||||
assertFalse(pad().isDown(PadState.GUIDE))
|
||||
}
|
||||
|
||||
private fun key(device: InputDevice, code: Int, action: Int = KeyEvent.ACTION_DOWN, repeat: Int = 0, scan: Int = 0) =
|
||||
KeyEvent(0L, 0L, action, code, repeat, 0, device.id, scan, 0, InputDevice.SOURCE_GAMEPAD)
|
||||
|
||||
private fun motion(device: InputDevice, axis: Int, value: Float) {
|
||||
val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_MOVE, 1,
|
||||
arrayOf(MotionEvent.PointerProperties().apply { id = 0 }),
|
||||
arrayOf(MotionEvent.PointerCoords().apply { setAxisValue(axis, value) }),
|
||||
0, 0, 1f, 1f, device.id, 0, InputDevice.SOURCE_JOYSTICK, 0)
|
||||
try { assertTrue(bridge.onMotionEvent(event)) } finally { event.recycle() }
|
||||
}
|
||||
|
||||
private fun pad() = requireNotNull(JoyConPadTest.RecordingWriter.pads[0])
|
||||
|
||||
private fun advanceTime() {
|
||||
val handler = ReflectionHelpers.getStaticField<Handler>(PadBridge::class.java, "chordHandler")
|
||||
shadowOf(handler.looper).idleFor(Duration.ofSeconds(2))
|
||||
advance(2000)
|
||||
}
|
||||
|
||||
private fun advance(ms: Long) = shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(ms))
|
||||
}
|
||||
@@ -84,6 +84,20 @@ class PadBridgeRoutingTest {
|
||||
assertFalse(PadBridge.anyControllerConnected())
|
||||
}
|
||||
|
||||
@Test fun homeShortcutsIgnoreHomeFromSystemKeys() {
|
||||
val gpio = device(InputDevice.SOURCE_KEYBOARD, InputDevice.KEYBOARD_TYPE_NON_ALPHABETIC, name = "gpio-keys")
|
||||
val pad = device(InputDevice.SOURCE_GAMEPAD or InputDevice.SOURCE_KEYBOARD, InputDevice.KEYBOARD_TYPE_NON_ALPHABETIC)
|
||||
assertFalse(PadBridge.isControllerKeyEvent(key(gpio, KeyEvent.KEYCODE_HOME, KeyEvent.ACTION_DOWN)))
|
||||
assertTrue(PadBridge.isControllerKeyEvent(key(pad, KeyEvent.KEYCODE_HOME, KeyEvent.ACTION_DOWN)))
|
||||
val owner = Any()
|
||||
HomeButtonShortcuts.attach(owner, { true }, { fail("system Home must not press Guide") }, {})
|
||||
try {
|
||||
for (action in listOf(KeyEvent.ACTION_DOWN, KeyEvent.ACTION_UP)) {
|
||||
assertFalse(HomeButtonShortcuts.onKeyEvent(RuntimeEnvironment.getApplication(), key(gpio, KeyEvent.KEYCODE_HOME, action)))
|
||||
}
|
||||
} finally { HomeButtonShortcuts.detach(owner) }
|
||||
}
|
||||
|
||||
@Test fun keyAndMotionOwnershipDoesNotFollowEverySourceOnTheDevice() {
|
||||
val keyboard = device(InputDevice.SOURCE_KEYBOARD, InputDevice.KEYBOARD_TYPE_ALPHABETIC)
|
||||
val composite = device(COMPOSITE, InputDevice.KEYBOARD_TYPE_ALPHABETIC)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.media.AudioManager
|
||||
import android.view.KeyEvent
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28, 33])
|
||||
class SteamVolumeKeysTest {
|
||||
private val adjustments = mutableListOf<Int>()
|
||||
|
||||
private fun key(code: Int, action: Int = KeyEvent.ACTION_DOWN, repeat: Int = 0) =
|
||||
KeyEvent(0L, 0L, action, code, repeat)
|
||||
|
||||
private fun dispatch(code: Int, enabled: Boolean = true, action: Int = KeyEvent.ACTION_DOWN, repeat: Int = 0) =
|
||||
SteamVolumeKeys.dispatch(key(code, action, repeat), enabled, adjustments::add)
|
||||
|
||||
@Test fun enabledKeysAdjustOncePerDownAndConsumeRelease() {
|
||||
assertTrue(dispatch(KeyEvent.KEYCODE_VOLUME_UP))
|
||||
assertTrue(dispatch(KeyEvent.KEYCODE_VOLUME_UP, repeat = 1))
|
||||
assertTrue(dispatch(KeyEvent.KEYCODE_VOLUME_UP, action = KeyEvent.ACTION_UP))
|
||||
assertTrue(dispatch(KeyEvent.KEYCODE_VOLUME_DOWN))
|
||||
assertTrue(dispatch(KeyEvent.KEYCODE_VOLUME_DOWN, action = KeyEvent.ACTION_UP))
|
||||
assertEquals(listOf(AudioManager.ADJUST_RAISE, AudioManager.ADJUST_RAISE, AudioManager.ADJUST_LOWER), adjustments)
|
||||
}
|
||||
|
||||
@Test fun muteTogglesOnlyOnInitialPress() {
|
||||
assertTrue(dispatch(KeyEvent.KEYCODE_VOLUME_MUTE))
|
||||
assertTrue(dispatch(KeyEvent.KEYCODE_VOLUME_MUTE, repeat = 1))
|
||||
assertTrue(dispatch(KeyEvent.KEYCODE_VOLUME_MUTE, action = KeyEvent.ACTION_UP))
|
||||
assertEquals(listOf(AudioManager.ADJUST_TOGGLE_MUTE), adjustments)
|
||||
}
|
||||
|
||||
@Test fun disabledAndNonVolumeKeysFallThrough() {
|
||||
for (code in listOf(KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_MUTE)) {
|
||||
assertFalse(dispatch(code, enabled = false))
|
||||
assertFalse(dispatch(code, enabled = false, action = KeyEvent.ACTION_UP))
|
||||
}
|
||||
assertFalse(dispatch(KeyEvent.KEYCODE_BUTTON_A))
|
||||
assertTrue(adjustments.isEmpty())
|
||||
}
|
||||
}
|
||||
@@ -212,8 +212,26 @@ class BattleNetTest {
|
||||
)
|
||||
assertEquals(listOf("agent" to "C:/ProgramData/Battle.net/Agent", "hs_beta" to "C:/Program Files (x86)/Hearthstone", "wow_classic_anniversary" to "Z:/root/Games/World of Warcraft"),
|
||||
BattleNet.productDbEntries(db))
|
||||
assertEquals(emptyList<Pair<String, String>>(), BattleNet.productDbEntries(db.copyOf(db.size - 3)))
|
||||
assertEquals(emptyList<Pair<String, String>>(), BattleNet.productDbEntries(byteArrayOf(0x0a, 0x7f, 0x01)))
|
||||
assertNull(BattleNet.productDbEntries(db.copyOf(db.size - 3)))
|
||||
assertNull(BattleNet.productDbEntries(byteArrayOf(0x0a, 0x7f, 0x01)))
|
||||
assertNull(BattleNet.productDbEntries(ByteArray(0)))
|
||||
assertNull(BattleNet.productDbEntries(byteArrayOf(0x0a, 0x03, 0x0a, 0x7f, 0x01)))
|
||||
assertEquals(emptyList<Pair<String, String>>(), BattleNet.productDbEntries(message(field(1, message(field(1, "s1"), field(3, message(field(1, "Z:/Games/StarCraft"))), field(4, message(field(1, message(varintField(1, 0))))))))))
|
||||
}
|
||||
|
||||
@Test fun theAgentDoesNotStartWithoutTheGameStorageCard() {
|
||||
val card = Files.createTempDirectory("card").toFile()
|
||||
com.droiddeck.launcher.session.SessionPrefs.setGameStorage(context, card.path, "SD Card")
|
||||
assertTrue(com.droiddeck.launcher.stores.battlenet.BattleNetInstall.binds(context).any { it.endsWith(":/mnt/droiddeck-sd") })
|
||||
card.deleteRecursively()
|
||||
assertThrows(IllegalStateException::class.java) { com.droiddeck.launcher.stores.battlenet.BattleNetInstall.binds(context) }
|
||||
}
|
||||
|
||||
@Test fun aGameTheAgentNoLongerTracksIsNotInstalled() {
|
||||
val registry = listOf("wow" to "Z:\\mnt\\droiddeck-sd\\Games\\Battle.net\\World of Warcraft", "hs_beta" to "C:\\Hearthstone")
|
||||
assertEquals(listOf("hs_beta" to "C:\\Hearthstone", "HS_BETA" to "C:/Hearthstone"), BattleNet.installs(registry, listOf("HS_BETA" to "C:/Hearthstone")))
|
||||
assertEquals(registry, BattleNet.installs(registry, null))
|
||||
assertEquals(emptyList<Pair<String, String>>(), BattleNet.installs(registry, emptyList()))
|
||||
}
|
||||
|
||||
@Test fun theGamesAreTheTitlesInstalledInTheirFolders() {
|
||||
@@ -229,9 +247,11 @@ class BattleNetTest {
|
||||
File(pfx, "drive_c/$folder").mkdirs()
|
||||
}
|
||||
val games = BattleNet.games(context)
|
||||
assertEquals(listOf("Fen", "OSI", "WTCG", "WoWC"), games.map { it.code })
|
||||
assertEquals(listOf("Diablo IV", "Diablo II: Resurrected", "Hearthstone", "World of Warcraft Classic"), games.map { it.name })
|
||||
assertEquals(File(pfx, "drive_c/Games/Diablo II Resurrected"), games[1].folder)
|
||||
assertEquals(listOf("Fen", "WTCG", "WoWC"), games.map { it.code })
|
||||
assertEquals(listOf("Diablo IV", "Hearthstone", "World of Warcraft Classic"), games.map { it.name })
|
||||
assertEquals(File(pfx, "drive_c/Program Files (x86)/Hearthstone"), games[1].folder)
|
||||
File(pfx, "drive_c/ProgramData/Battle.net/Agent/product.db").delete()
|
||||
assertEquals(listOf("Fen", "OSI"), BattleNet.games(context).map { it.code })
|
||||
assertNull(BattleNet.hostFolder(context, "D:\\Games\\X"))
|
||||
assertNull(BattleNet.hostFolder(context, "C:\\..\\..\\etc"))
|
||||
assertNull(BattleNet.hostFolder(context, "Z:\\root\\..\\..\\etc"))
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.droiddeck.launcher.runtime
|
||||
|
||||
import android.app.Application
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.media.AudioManager
|
||||
import android.os.Looper
|
||||
import android.provider.Settings
|
||||
import java.io.File
|
||||
import java.time.Duration
|
||||
import org.json.JSONObject
|
||||
import org.junit.After
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
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.annotation.Implements
|
||||
import org.robolectric.annotation.Implementation
|
||||
import org.robolectric.shadows.ShadowSettings
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28, 33], manifest = Config.NONE, application = Application::class, shadows = [WriteSettingsShadow::class])
|
||||
class DeviceControlsComponentTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
private val context get() = RuntimeEnvironment.getApplication()
|
||||
private val audio get() = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
private lateinit var component: DeviceControlsComponent
|
||||
private lateinit var directory: File
|
||||
private var visible = true
|
||||
|
||||
@Before fun start() {
|
||||
WriteSettingsShadow.writable = true
|
||||
Settings.System.putInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS, 128)
|
||||
val root = tmp.newFolder()
|
||||
directory = DeviceControlsComponent.directory(root)
|
||||
component = DeviceControlsComponent(context, root) { visible }
|
||||
component.publish()
|
||||
component.start()
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
}
|
||||
|
||||
@After fun stop() {
|
||||
component.stop()
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
}
|
||||
|
||||
private fun tick() = shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(300))
|
||||
private fun request(name: String, text: String) {
|
||||
File(directory, "$name.request").writeText(text)
|
||||
tick()
|
||||
}
|
||||
|
||||
@Test fun androidChangesArePublishedAndRequestsUseDeviceVolumeSteps() {
|
||||
request("volume", "999")
|
||||
assertEquals(audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC), audio.getStreamVolume(AudioManager.STREAM_MUSIC))
|
||||
audio.setStreamVolume(AudioManager.STREAM_MUSIC, 3, 0)
|
||||
tick()
|
||||
assertEquals("3", File(directory, "volume.state").readText().split(" ").first())
|
||||
request("volume", "invalid")
|
||||
assertEquals(3, audio.getStreamVolume(AudioManager.STREAM_MUSIC))
|
||||
}
|
||||
|
||||
@Test fun deniedBrightnessDoesNotOpenSettingsOrReplayAnOldSliderValueAfterPermission() {
|
||||
WriteSettingsShadow.writable = false
|
||||
request("brightness", "0.75")
|
||||
assertEquals(128, Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
|
||||
assertNull(shadowOf(context).nextStartedActivity)
|
||||
assertFalse(JSONObject(File(directory, "state.json").readText()).getBoolean("brightnessWritable"))
|
||||
WriteSettingsShadow.writable = true
|
||||
tick()
|
||||
assertEquals(128, Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
|
||||
request("brightness", "0.75")
|
||||
assertEquals(192, Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
|
||||
}
|
||||
|
||||
@Test fun brightnessIsBoundedAndExternalChangesAreReadBack() {
|
||||
for (invalid in listOf("NaN", "Infinity", "-0.1", "1.1")) request("brightness", invalid)
|
||||
assertEquals(128, Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
|
||||
request("brightness", "0")
|
||||
assertEquals(1, Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
|
||||
Settings.System.putInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS, 255)
|
||||
tick()
|
||||
assertEquals(1.0, JSONObject(File(directory, "state.json").readText()).getDouble("brightness"), 0.0001)
|
||||
}
|
||||
|
||||
@Test fun permissionNotificationOpensOptionalLauncherSetupOnlyWhenSelected() {
|
||||
visible = false
|
||||
WriteSettingsShadow.writable = false
|
||||
request("brightness", "0.25")
|
||||
request("brightness", "0.75")
|
||||
assertNull(shadowOf(context).nextStartedActivity)
|
||||
val notifications = context.getSystemService(NotificationManager::class.java)
|
||||
val notification = notifications.activeNotifications.single().notification
|
||||
notification.contentIntent.send()
|
||||
val intent = shadowOf(context).nextStartedActivity
|
||||
assertEquals(com.droiddeck.launcher.core.SteamIntegration.ACTION_SETUP, intent.action)
|
||||
assertEquals("BRIGHTNESS", intent.getStringExtra(com.droiddeck.launcher.core.SteamIntegration.EXTRA_FEATURE))
|
||||
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(121))
|
||||
WriteSettingsShadow.writable = true
|
||||
tick()
|
||||
assertEquals(128, Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
|
||||
assertTrue(notifications.activeNotifications.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun stoppingClearsThePermissionNotificationAndPendingRequest() {
|
||||
visible = false
|
||||
WriteSettingsShadow.writable = false
|
||||
request("brightness", "0.75")
|
||||
component.stop()
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertTrue(context.getSystemService(NotificationManager::class.java).activeNotifications.isEmpty())
|
||||
WriteSettingsShadow.writable = true
|
||||
tick()
|
||||
assertEquals(128, Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
|
||||
}
|
||||
|
||||
@Test fun stoppedSessionsDoNotConsumeNewCommands() {
|
||||
component.stop()
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
request("brightness", "0.2")
|
||||
assertEquals(128, Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
|
||||
}
|
||||
|
||||
@Test fun repeatedSliderChangesDoNotInterruptTheSession() {
|
||||
WriteSettingsShadow.writable = false
|
||||
request("brightness", "0.75")
|
||||
assertNull(shadowOf(context).nextStartedActivity)
|
||||
request("brightness", "0.8")
|
||||
assertNull(shadowOf(context).nextStartedActivity)
|
||||
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(5))
|
||||
request("brightness", "0.8")
|
||||
assertNull(shadowOf(context).nextStartedActivity)
|
||||
}
|
||||
|
||||
@Test fun oversizedRequestsAreDiscardedAndDoNotBlockLaterCommands() {
|
||||
request("brightness", "0".repeat(1000))
|
||||
assertFalse(File(directory, "brightness.request.processing").exists())
|
||||
request("brightness", "0.75")
|
||||
assertEquals(192, Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
|
||||
}
|
||||
}
|
||||
|
||||
@Implements(Settings.System::class)
|
||||
class WriteSettingsShadow : ShadowSettings.ShadowSystem() {
|
||||
companion object {
|
||||
@JvmField var writable = true
|
||||
@JvmStatic @Implementation fun canWrite(context: Context) = writable
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.droiddeck.launcher.runtime
|
||||
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
|
||||
@@ -17,4 +19,12 @@ class ProotFastPathTest {
|
||||
val binds = (1..ProotFastPath.MAX_BINDS + 1).map { "/host/$it:/guest/$it" }
|
||||
assertNull(ProotFastPath.key(root, binds))
|
||||
}
|
||||
|
||||
@Test fun fastPathStaysOffForTheRootfsProot() {
|
||||
assertTrue(ProotFastPath.allows(preference = true, noSeccomp = false, source = LinuxRuntime.PROOT_PACK))
|
||||
assertFalse(ProotFastPath.allows(preference = true, noSeccomp = false, source = LinuxRuntime.PROOT_ROOTFS))
|
||||
assertFalse(ProotFastPath.allows(preference = true, noSeccomp = false, source = LinuxRuntime.PROOT_MISSING))
|
||||
assertFalse(ProotFastPath.allows(preference = false, noSeccomp = false, source = LinuxRuntime.PROOT_PACK))
|
||||
assertFalse(ProotFastPath.allows(preference = true, noSeccomp = true, source = LinuxRuntime.PROOT_PACK))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import com.github.luben.zstd.ZstdOutputStream
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], manifest = Config.NONE)
|
||||
class ComponentsRepublishTest {
|
||||
private val fex = "FEXCore-2610-d2rfix28-linux.wcp"
|
||||
private val scope = "2596113170"
|
||||
private val dll = "files/lib/wine/aarch64-windows/libwow64fex.dll"
|
||||
private lateinit var context: Context
|
||||
|
||||
@Before fun setUp() {
|
||||
context = RuntimeEnvironment.getApplication()
|
||||
File(context.filesDir, "components").deleteRecursively()
|
||||
LinuxRuntime.rootDir(context).deleteRecursively()
|
||||
}
|
||||
|
||||
@Test fun aGameFexChoiceReachesAProtonInstalledAfterIt() {
|
||||
proton("DroidDeck-Proton 11-11.7", "DroidDeck-Proton-11-11.7")
|
||||
packageFile()
|
||||
ComponentsManager.setGameComponent(context, scope, "fex", fex)
|
||||
assertEquals(setOf("DroidDeck-Proton 11-11.7"), scopedTools())
|
||||
|
||||
proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8")
|
||||
assertEquals(setOf("DroidDeck-Proton 11-11.7"), scopedTools())
|
||||
|
||||
assertTrue(ComponentsManager.republish(context))
|
||||
assertEquals(setOf("DroidDeck-Proton 11-11.7", "DroidDeck-Proton 11-11.8"), scopedTools())
|
||||
val row = rows().single { it[0] == scope && it[1] == "DroidDeck-Proton 11-11.8" && it[4] == dll }
|
||||
assertEquals("DroidDeck-Proton-11-11.8", row[2])
|
||||
assertEquals("d2rfix28 wow64", File(LinuxRuntime.rootDir(context), row[6].removePrefix("/")).readText())
|
||||
assertEquals(fex, ComponentsManager.gameComponents(context, scope)["fex"])
|
||||
}
|
||||
|
||||
@Test fun nothingIsRewrittenWhileTheToolsAreUnchanged() {
|
||||
proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8")
|
||||
packageFile()
|
||||
ComponentsManager.setGameComponent(context, scope, "fex", fex)
|
||||
val published = launchState().readText()
|
||||
val modified = launchState().lastModified()
|
||||
|
||||
assertFalse(ComponentsManager.republish(context))
|
||||
assertEquals(published, launchState().readText())
|
||||
assertEquals(modified, launchState().lastModified())
|
||||
}
|
||||
|
||||
@Test fun anUnreadableStateLeavesThePublishedSelectionsAlone() {
|
||||
proton("DroidDeck-Proton 11-11.7", "DroidDeck-Proton-11-11.7")
|
||||
packageFile()
|
||||
ComponentsManager.setGameComponent(context, scope, "fex", fex)
|
||||
val published = launchState().readText()
|
||||
val state = File(context.filesDir, "components/state.json").apply { writeText("{\"active\": ") }
|
||||
proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8")
|
||||
|
||||
assertFalse(ComponentsManager.republish(context))
|
||||
assertEquals(published, launchState().readText())
|
||||
assertEquals("{\"active\": ", state.readText())
|
||||
}
|
||||
|
||||
@Test fun withNoSelectionsNothingIsPublished() {
|
||||
proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8")
|
||||
|
||||
assertFalse(ComponentsManager.republish(context))
|
||||
assertFalse(launchState().exists())
|
||||
}
|
||||
|
||||
private fun scopedTools() = rows().filter { it[0] == scope }.map { it[1] }.toSet()
|
||||
|
||||
private fun rows() = launchState().readLines().filter { it.isNotEmpty() }.map { it.split('\t') }
|
||||
|
||||
private fun launchState() = File(LinuxRuntime.rootDir(context), "root/.local/share/droiddeck-components/desired.tsv")
|
||||
|
||||
private fun proton(name: String, version: String) {
|
||||
val dir = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/steamapps/common/$name")
|
||||
File(dir, "files/lib/wine").mkdirs()
|
||||
File(dir, "proton").writeText("#!/bin/sh\n")
|
||||
File(dir, "version").writeText("1 $version\n")
|
||||
File(dir, dll).apply { parentFile!!.mkdirs(); writeText("bundled FEX $version") }
|
||||
}
|
||||
|
||||
private fun packageFile() {
|
||||
val out = File(context.filesDir, "components/packages/$fex").apply { parentFile!!.mkdirs() }
|
||||
val profile = JSONObject().put("type", "FEXCore-Linux").put("versionName", "2610-d2rfix28").toString().toByteArray()
|
||||
val body = "d2rfix28 wow64".toByteArray()
|
||||
TarArchiveOutputStream(ZstdOutputStream(out.outputStream())).use { tar ->
|
||||
tar.putArchiveEntry(TarArchiveEntry("profile.json").apply { size = profile.size.toLong() })
|
||||
tar.write(profile)
|
||||
tar.closeArchiveEntry()
|
||||
tar.putArchiveEntry(TarArchiveEntry(dll).apply { size = body.size.toLong() })
|
||||
tar.write(body)
|
||||
tar.closeArchiveEntry()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.ActivityInfo
|
||||
import com.droiddeck.launcher.core.AppUiPrefs
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
@@ -17,15 +18,12 @@ class OrientationTest {
|
||||
|
||||
@Before fun clearOrientation() {
|
||||
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
context.getSharedPreferences("app-ui", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
}
|
||||
|
||||
@Test fun landscapeChoicesPersistGloballyAndCanRestoreAutomaticRotation() {
|
||||
@Test fun sessionChoicesPersistGloballyWithLandscapeAsTheDefault() {
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context))
|
||||
for (value in listOf(
|
||||
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
|
||||
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
|
||||
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
|
||||
)) {
|
||||
for ((value, _) in SessionPrefs.orientationOptions) {
|
||||
SessionPrefs.setOrientation(context, value)
|
||||
assertEquals(value, SessionPrefs.orientation(context.createConfigurationContext(context.resources.configuration)))
|
||||
}
|
||||
@@ -33,12 +31,61 @@ class OrientationTest {
|
||||
|
||||
@Test fun invalidStoredOrientationFallsBackAndInvalidChoicePreservesTheSavedValue() {
|
||||
val prefs = context.getSharedPreferences("session", Context.MODE_PRIVATE)
|
||||
prefs.edit().putInt("orientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT).commit()
|
||||
prefs.edit().putInt("orientation", 999).commit()
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context))
|
||||
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE)
|
||||
assertThrows(IllegalArgumentException::class.java) {
|
||||
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
|
||||
SessionPrefs.setOrientation(context, 999)
|
||||
}
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE, SessionPrefs.orientation(context))
|
||||
}
|
||||
|
||||
@Test fun launcherFollowsDeviceRotationAndPortraitDoesNotChangeSessions() {
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_USER, AppUiPrefs.orientation(context))
|
||||
for ((value, _) in AppUiPrefs.orientationOptions) {
|
||||
AppUiPrefs.setOrientation(context, value)
|
||||
assertEquals(value, AppUiPrefs.orientation(context))
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context))
|
||||
}
|
||||
AppUiPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
|
||||
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE)
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, AppUiPrefs.orientation(context))
|
||||
AppUiPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
|
||||
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, AppUiPrefs.orientation(context))
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, SessionPrefs.orientation(context))
|
||||
}
|
||||
|
||||
@Test fun explicitOrientationTakesPriorityOverLargeFollowScreenWindows() {
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_USER, SessionPrefs.windowOrientation(context, true, 700))
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.windowOrientation(context, true, 400))
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.windowOrientation(context, false, 700))
|
||||
for ((value, _) in SessionPrefs.orientationOptions) {
|
||||
SessionPrefs.setOrientation(context, value)
|
||||
assertEquals(value, SessionPrefs.windowOrientation(context, true, 700))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun sessionPortraitUsesItsOwnLockOrTheCurrentRotation() {
|
||||
val config = android.content.res.Configuration(context.resources.configuration)
|
||||
config.orientation = android.content.res.Configuration.ORIENTATION_PORTRAIT
|
||||
val portrait = context.createConfigurationContext(config)
|
||||
config.orientation = android.content.res.Configuration.ORIENTATION_LANDSCAPE
|
||||
val landscape = context.createConfigurationContext(config)
|
||||
assertFalse(SessionPrefs.portrait(portrait))
|
||||
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
|
||||
assertTrue(SessionPrefs.portrait(landscape))
|
||||
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_USER)
|
||||
assertTrue(SessionPrefs.portrait(portrait))
|
||||
assertFalse(SessionPrefs.portrait(landscape))
|
||||
}
|
||||
|
||||
@Test fun invalidLauncherOrientationFallsBackAndInvalidChoicePreservesPreference() {
|
||||
context.getSharedPreferences("app-ui", Context.MODE_PRIVATE).edit().putInt("orientation", 999).commit()
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_USER, AppUiPrefs.orientation(context))
|
||||
AppUiPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
|
||||
assertThrows(IllegalArgumentException::class.java) { AppUiPrefs.setOrientation(context, 999) }
|
||||
assertEquals(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, AppUiPrefs.orientation(context))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class OutputPacingTest {
|
||||
@Test fun phoneOutputIsUnpaced() {
|
||||
assertEquals(SessionPrefs.FPS_UNPACED, SessionPrefs.compositorFpsLimit(0))
|
||||
}
|
||||
|
||||
@Test fun mirroringKeepsTheGlassesRate() {
|
||||
assertEquals(60, SessionPrefs.compositorFpsLimit(60))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class PerfHudGraphTest {
|
||||
@Test fun theGraphShowsOnlyFramesFromThisHudRun() {
|
||||
val samples = floatArrayOf(9f, 9f, 9f, 9f, 9f, 16.7f, 33.4f, 16.6f)
|
||||
assertArrayEquals(floatArrayOf(16.7f, 33.4f, 16.6f), PerfHud.recent(samples, 105, 102), 0f)
|
||||
assertEquals(0, PerfHud.recent(samples, 103, 102).size)
|
||||
}
|
||||
|
||||
@Test fun anEarlySessionShowsWhatWasShownSoFar() {
|
||||
val samples = floatArrayOf(16.6f, 16.7f, 120f, 0f, 0f, 0f)
|
||||
assertArrayEquals(floatArrayOf(16.6f, 16.7f, 50f), PerfHud.recent(samples, 3, 0), 0f)
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
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 PerformanceModeTest {
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
private val session get() = app.getSharedPreferences("session", Context.MODE_PRIVATE)
|
||||
|
||||
@Before fun clear() { session.edit().clear().commit() }
|
||||
|
||||
@Test fun offByDefaultAndPerMode() {
|
||||
assertFalse(SessionPrefs.performanceMode(app, SessionService.MODE_STEAM))
|
||||
SessionPrefs.setPerformanceMode(app, SessionService.MODE_STEAM, true)
|
||||
assertTrue(SessionPrefs.performanceMode(app, SessionService.MODE_STEAM))
|
||||
assertFalse(SessionPrefs.performanceMode(app, SessionService.MODE_DESKTOP))
|
||||
}
|
||||
|
||||
@Test fun offKeepsTodaysPacing() {
|
||||
assertEquals(0, SessionPrefs.compositorFpsLimit(0, false))
|
||||
assertEquals(60, SessionPrefs.compositorFpsLimit(60, false))
|
||||
}
|
||||
|
||||
@Test fun onWithoutALimitIsUnpacedAndAChosenLimitStillPaces() {
|
||||
assertEquals(SessionPrefs.FPS_UNPACED, SessionPrefs.compositorFpsLimit(0, true))
|
||||
assertEquals(60, SessionPrefs.compositorFpsLimit(60, true))
|
||||
}
|
||||
|
||||
@Test fun anOldUncappedFrameLimitReadsAsOff() {
|
||||
session.edit().putInt("fpsLimit.steam", -1).commit()
|
||||
assertEquals(0, SessionPrefs.fpsLimit(app, SessionService.MODE_STEAM))
|
||||
assertFalse(SessionPrefs.fpsLimitChoices.any { it.first < 0 })
|
||||
}
|
||||
}
|
||||
@@ -115,6 +115,22 @@ class RumbleComponentTest {
|
||||
assertFalse(pad.vibrating)
|
||||
}
|
||||
|
||||
@Test fun quietingStopsAHeldEffectAndDropsEffectsUntilLifted() {
|
||||
val pad = FakeMotors()
|
||||
rumble.controllerMotors = { pad }
|
||||
activeController(PAD_ID)
|
||||
effect(strong = 40000, weak = 20000, ms = RumbleComponent.HOLD_MS)
|
||||
rumble.quiet(true)
|
||||
assertFalse(pad.vibrating)
|
||||
idle(RumbleComponent.KEEPALIVE_MS * 4 + 100)
|
||||
assertEquals("the keepalive restarted the motors while quiet", 1, pad.played.size)
|
||||
effect(strong = 40000, weak = 20000)
|
||||
assertFalse("an effect played while quiet", pad.vibrating)
|
||||
rumble.quiet(false)
|
||||
effect(strong = 40000, weak = 20000)
|
||||
assertTrue(pad.vibrating)
|
||||
}
|
||||
|
||||
@Test fun aHeldEffectFollowsTheGamesNewStrength() {
|
||||
val pad = FakeMotors()
|
||||
rumble.controllerMotors = { pad }
|
||||
|
||||
@@ -4,6 +4,23 @@ import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class SessionDisplayTest {
|
||||
@Test fun portraitPresetsSwapTheOutputAndRetainTheResolutionCap() {
|
||||
assertEquals(720 to 1280, SessionDisplay.resolveChoice(1920 to 1080, "720p", portrait = true))
|
||||
assertEquals(900 to 1600, SessionDisplay.resolveChoice(1080 to 1920, "900p", portrait = true))
|
||||
assertEquals(720 to 1280, SessionDisplay.resolveChoice(1440 to 1080, "720p", portrait = true))
|
||||
assertEquals(720 to 1600, SessionDisplay.resolveChoice(2400 to 1080, "720p", portrait = true))
|
||||
assertEquals(1080 to 1920, SessionDisplay.resolveChoice(1921 to 1081, SessionDisplay.MATCH_SCREEN, portrait = true))
|
||||
assertEquals(1080 to 2400, SessionDisplay.resolveChoice(2400 to 1080, SessionDisplay.FOLLOW_SCREEN, portrait = true))
|
||||
assertEquals(720 to 1280, SessionDisplay.resolveChoice(1920 to 1080, "invalid", portrait = true))
|
||||
}
|
||||
|
||||
@Test fun customDimensionsStayExplicitInEitherOrientation() {
|
||||
for (portrait in listOf(false, true)) {
|
||||
assertEquals(1280 to 720, SessionDisplay.resolveChoice(1920 to 1080, "1280x720", portrait))
|
||||
assertEquals(720 to 1280, SessionDisplay.resolveChoice(1920 to 1080, "720x1280", portrait))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun fixedSizesAndMatchScreenResolveWithoutAnyAspectSetting() {
|
||||
assertEquals(1280 to 720, SessionDisplay.resolveChoice(1440 to 1080, "1280x720"))
|
||||
assertEquals(1600 to 900, SessionDisplay.resolveChoice(1280 to 720, "1600x900"))
|
||||
@@ -35,6 +52,7 @@ class SessionDisplayTest {
|
||||
}
|
||||
|
||||
@Test fun unfoldedControlsKeepTheGameSixteenByNineAcrossTheWidth() {
|
||||
assertEquals(606, SessionDisplay.unfoldedGameHeight(1080, 1920))
|
||||
assertEquals(1376, SessionDisplay.unfoldedGameHeight(2448, 1848))
|
||||
assertEquals(1038, SessionDisplay.unfoldedGameHeight(1848, 2448))
|
||||
assertEquals(864, SessionDisplay.unfoldedGameHeight(1920, 1080))
|
||||
@@ -67,6 +85,18 @@ class SessionDisplayTest {
|
||||
assertFalse(SessionDisplay.unfoldedControlsWanted(true, true, true, true, true, false, 0, 1848, 700))
|
||||
}
|
||||
|
||||
@Test fun portraitControlsWorkOnHandheldsAndPhonesWithoutAHinge() {
|
||||
fun wanted(width: Int = 1080, height: Int = 1920, controller: Boolean = false,
|
||||
keep: Boolean = false, pad: Boolean = true, pip: Boolean = false) =
|
||||
SessionDisplay.unfoldedControlsWanted(true, false, controller, keep, pad, pip, width, height, 393)
|
||||
assertTrue(wanted())
|
||||
assertFalse(wanted(width = 1920, height = 1080))
|
||||
assertFalse(wanted(controller = true))
|
||||
assertTrue(wanted(controller = true, keep = true))
|
||||
assertFalse(wanted(pad = false))
|
||||
assertFalse(wanted(pip = true))
|
||||
}
|
||||
|
||||
|
||||
@Test fun followScreenKeepsTheWindowShapeAndSkipsTinyWindows() {
|
||||
assertEquals(2520 to 1080, SessionDisplay.resolveChoice(1080 to 2520, SessionDisplay.FOLLOW_SCREEN))
|
||||
@@ -75,6 +105,13 @@ class SessionDisplayTest {
|
||||
assertNull(SessionDisplay.followSize(640, 360))
|
||||
}
|
||||
|
||||
@Test fun aPhoneCanFollowTheShortGameAreaAboveItsControls() {
|
||||
assertNull(SessionDisplay.followSize(720, 404))
|
||||
assertEquals(720 to 404, SessionDisplay.followSize(720, 404, controlsBelow = true))
|
||||
assertNull(SessionDisplay.followSize(320, 180, controlsBelow = true))
|
||||
assertNull(SessionDisplay.followSize(720, 0, controlsBelow = true))
|
||||
}
|
||||
|
||||
@Test fun resolutionCapsPreserveTheSelectedShapeWithoutExceedingPanelHeight() {
|
||||
assertEquals(1280 to 720, SessionDisplay.resolve(1920 to 1080, 720, SessionPrefs.SHAPE_AUTO))
|
||||
assertEquals(960 to 720, SessionDisplay.resolve(1440 to 1080, 720, SessionPrefs.SHAPE_EXACT))
|
||||
|
||||
@@ -13,6 +13,16 @@ import org.robolectric.annotation.Config
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], manifest = Config.NONE)
|
||||
class SessionScalingPrefsTest {
|
||||
@Test fun legacyAutomaticResolutionsRemainRotatablePresets() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val prefs = context.getSharedPreferences("session", Context.MODE_PRIVATE)
|
||||
prefs.edit().putString("shape", SessionPrefs.SHAPE_AUTO).putInt("resolutionCap.steam", 900).commit()
|
||||
assertEquals("900p", SessionPrefs.resolutionChoice(context, "steam", 1920 to 1080))
|
||||
val desktop = SessionPrefs.resolutionChoice(context, "lxqt", 1920 to 1080)
|
||||
assertEquals("720p", desktop)
|
||||
assertEquals(720 to 1280, SessionDisplay.resolveChoice(1920 to 1080, desktop, portrait = true))
|
||||
}
|
||||
|
||||
@Before fun clearSettings() {
|
||||
RuntimeEnvironment.getApplication().getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
}
|
||||
|
||||
@@ -27,9 +27,10 @@ class SettingsResetTest {
|
||||
|
||||
@Test fun settingsGoBackToTheirDefaults() {
|
||||
SessionPrefs.setTheme(app, "ocean")
|
||||
SessionPrefs.setBackDoubleTapMs(app, 100)
|
||||
SessionPrefs.setUnfoldedControlsWithController(app, true)
|
||||
SessionPrefs.setNoXalia(app, false)
|
||||
SessionPrefs.setFpsLimit(app, SessionService.MODE_STEAM, 30)
|
||||
session.edit().putInt("fpsLimit.steam", 30).commit()
|
||||
SessionPrefs.setHdr(app, SessionService.MODE_DESKTOP, true)
|
||||
SessionPrefs.setResolutionChoice(app, SessionService.MODE_STEAM, "1280x800")
|
||||
SessionPrefs.setGuestHostname(app, "MyDeck")
|
||||
@@ -46,9 +47,10 @@ class SettingsResetTest {
|
||||
assertTrue(SettingsReset.resetAll(app, gameProfiles = false))
|
||||
|
||||
assertEquals("graphite", SessionPrefs.theme(app))
|
||||
assertEquals(500, SessionPrefs.backDoubleTapMs(app))
|
||||
assertFalse(SessionPrefs.unfoldedControlsWithController(app))
|
||||
assertTrue(SessionPrefs.noXalia(app))
|
||||
assertEquals(0, SessionPrefs.fpsLimit(app, SessionService.MODE_STEAM))
|
||||
assertFalse(session.contains("fpsLimit.steam"))
|
||||
assertFalse(SessionPrefs.hdr(app, SessionService.MODE_DESKTOP))
|
||||
assertFalse(SessionPrefs.resolutionChosen(app, SessionService.MODE_STEAM))
|
||||
assertEquals(SessionPrefs.DEFAULT_GUEST_HOSTNAME, SessionPrefs.guestHostname(app))
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.droiddeck.launcher.stores.battlenet
|
||||
|
||||
import com.droiddeck.launcher.runtime.BattleNet
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.nio.file.Files
|
||||
import java.util.Locale
|
||||
|
||||
class BattleNetInstallTest {
|
||||
private val buildInfo = """
|
||||
Branch!STRING:0|Active!DEC:1|Build Key!HEX:16|CDN Key!HEX:16|Install Key!HEX:16|IM Size!DEC:4|Version!STRING:0|Product!STRING:0
|
||||
eu|0|11111111111111111111111111111111|db0583272ed15286569b5f24ce516876|||16.1.1.1|gryphon
|
||||
us|1|e474008a3535d8ea978949a90d9873e6|db0583272ed15286569b5f24ce516876|||16.1.2.119725|gryphon
|
||||
""".trimIndent()
|
||||
|
||||
private val versions = """
|
||||
Region!STRING:0|BuildConfig!HEX:16|CDNConfig!HEX:16|KeyRing!HEX:16|BuildId!DEC:4|VersionsName!String:0|ProductConfig!HEX:16
|
||||
## seqn = 4048130
|
||||
us|f00d008a3535d8ea978949a90d9873e6|db0583272ed15286569b5f24ce516876||119800|16.1.3.119800|f6a454799d25791e5a37a7547d75ce49
|
||||
eu|e474008a3535d8ea978949a90d9873e6|db0583272ed15286569b5f24ce516876||119725|16.1.2.119725|f6a454799d25791e5a37a7547d75ce49
|
||||
""".trimIndent()
|
||||
|
||||
@Test fun theActiveRowGivesTheRegionAndBuildOnDisk() {
|
||||
assertEquals("us" to "e474008a3535d8ea978949a90d9873e6", BattleNetInstall.buildKey(buildInfo))
|
||||
assertNull(BattleNetInstall.buildKey("Branch!STRING:0|Active!DEC:1\n"))
|
||||
assertNull(BattleNetInstall.buildKey("Branch!STRING:0|Active!DEC:1|Build Key!HEX:16\nus|1|not-a-key\n"))
|
||||
}
|
||||
|
||||
@Test fun theLiveBuildIsReadForTheSameRegion() {
|
||||
assertEquals("f00d008a3535d8ea978949a90d9873e6", BattleNetInstall.latestBuild(versions, "us"))
|
||||
assertEquals("e474008a3535d8ea978949a90d9873e6", BattleNetInstall.latestBuild(versions, "eu"))
|
||||
assertNull(BattleNetInstall.latestBuild(versions, "kr"))
|
||||
assertNull(BattleNetInstall.latestBuild("", "us"))
|
||||
}
|
||||
|
||||
@Test fun theDeviceLanguagePicksABlizzardLocale() {
|
||||
assertEquals("enUS", BattleNetInstall.locale(Locale.US))
|
||||
assertEquals("enGB", BattleNetInstall.locale(Locale.UK))
|
||||
assertEquals("enUS", BattleNetInstall.locale(Locale("en", "AU")))
|
||||
assertEquals("deDE", BattleNetInstall.locale(Locale.GERMANY))
|
||||
assertEquals("ptBR", BattleNetInstall.locale(Locale("pt", "BR")))
|
||||
assertEquals("ptPT", BattleNetInstall.locale(Locale("pt", "PT")))
|
||||
assertEquals("zhTW", BattleNetInstall.locale(Locale.forLanguageTag("zh-Hant-HK")))
|
||||
assertEquals("zhCN", BattleNetInstall.locale(Locale.SIMPLIFIED_CHINESE))
|
||||
assertEquals("enUS", BattleNetInstall.locale(Locale("nl", "NL")))
|
||||
}
|
||||
|
||||
@Test fun theCountryIsSentInBothForms() {
|
||||
assertEquals("DEU" to "DE", BattleNetInstall.country(Locale.GERMANY))
|
||||
assertEquals("USA" to "US", BattleNetInstall.country(Locale("en")))
|
||||
}
|
||||
|
||||
@Test fun everyStoreTitleWithAProductInstallsHeadless() {
|
||||
val products = BattleNet.TITLES.mapNotNull { it.product }
|
||||
assertTrue(products.all { Regex("[a-z0-9_]{1,32}").matches(it) })
|
||||
assertTrue(BattleNetInstall.headless(CatalogItem(Store.BATTLENET, "gryphon", "Warcraft Rumble", null)))
|
||||
assertEquals("hsb", BattleNetInstall.product("hs_beta"))
|
||||
assertEquals("d3", BattleNetInstall.product("diablo3_enus"))
|
||||
assertFalse(BattleNetInstall.headless(CatalogItem(Store.BATTLENET, "d3cn", "Diablo III", null)))
|
||||
assertFalse(BattleNetInstall.headless(CatalogItem(Store.EPIC, "gryphon", "Warcraft Rumble", null)))
|
||||
}
|
||||
|
||||
@Test fun aCheckThatCouldNotRunIsTriedAgainNextTime() {
|
||||
val folder = Files.createTempDirectory("bnet").toFile()
|
||||
try {
|
||||
BattleNetInstall.check("gryphon", folder, false)
|
||||
BattleNetInstall.checks.submit {}.get()
|
||||
assertFalse(synchronized(BattleNetInstall.checkedAt) { "gryphon" in BattleNetInstall.checkedAt })
|
||||
} finally {
|
||||
folder.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theAgentStatusPicksTheDownloadStep() {
|
||||
assertEquals(BattleNetInstall.Step.PREPARING, BattleNetInstall.step(1008, 0, 0, 0))
|
||||
assertEquals(BattleNetInstall.Step.PREPARING, BattleNetInstall.step(1003, 500, 0, 0))
|
||||
assertEquals(BattleNetInstall.Step.DOWNLOADING, BattleNetInstall.step(1003, 500, 31405777, 6746574227))
|
||||
assertEquals(BattleNetInstall.Step.APPLYING, BattleNetInstall.step(1003, 500, 6746574227, 6746574227))
|
||||
assertEquals(BattleNetInstall.Step.APPLYING, BattleNetInstall.step(1003, 2000, 1, 9))
|
||||
assertEquals(BattleNetInstall.Step.APPLYING, BattleNetInstall.step(1004, 1000, 0, 0))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.droiddeck.launcher.stores.itch
|
||||
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
@org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class)
|
||||
@org.robolectric.annotation.Config(sdk = [33], application = android.app.Application::class)
|
||||
class ItchCollectionsTest {
|
||||
@Test fun collectionsKeepTheirIdTitleAndCount() {
|
||||
val body = JSONArray()
|
||||
.put(JSONObject().put("id", 8356509).put("title", "library").put("games_count", 12))
|
||||
.put(JSONObject().put("id", 7).put("title", "").put("games_count", 3))
|
||||
.put(JSONObject().put("title", "no id"))
|
||||
val list = ItchCollections.parseCollections(body)
|
||||
assertEquals(listOf("8356509"), list.map { it.id })
|
||||
assertEquals("library", list.single().title)
|
||||
assertEquals(12, list.single().count)
|
||||
}
|
||||
|
||||
@Test fun collectionGamesReadBothKeyStylesAndSkipRowsWithoutAGame() {
|
||||
val game = JSONObject().put("id", 99).put("title", "Celeste 64").put("url", "https://noel.itch.io/celeste64")
|
||||
val snake = JSONObject().put("collection_games", JSONArray().put(JSONObject().put("game", game)).put(JSONObject().put("position", 1)))
|
||||
val camel = JSONObject().put("collectionGames", JSONArray().put(JSONObject().put("game", game)))
|
||||
assertEquals(listOf("noel.itch.io/celeste64"), ItchCollections.parseGames(snake).map { it.id })
|
||||
assertEquals(1, ItchCollections.parseGames(camel).size)
|
||||
assertEquals(false, ItchCollections.parseGames(snake).single().owned)
|
||||
assertEquals(0, ItchCollections.parseGames(JSONObject()).size)
|
||||
}
|
||||
}
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ class GlobalGlassesSettingsTest {
|
||||
onRoms = {}, onFiles = {}, onLogs = {}, onOffline = {},
|
||||
onWirelessAdbPair = { _, _, _, _ -> }, onWirelessAdbApply = { _, _, _, _ -> },
|
||||
onSetPhantomProcessLimit = { _, _ -> },
|
||||
), onOpenDeveloperOptions = {}, onRequestWirelessAdb = {})
|
||||
), onOpenDeveloperOptions = {}, onRequestWirelessAdb = {}, onPairWirelessDebugging = {})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ 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
|
||||
@@ -36,11 +37,56 @@ class LibraryEntriesTest {
|
||||
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) }
|
||||
@@ -48,4 +94,23 @@ class LibraryEntriesTest {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
@@ -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 = { _, _ -> },
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user