Merge upstream PC input and dual-screen updates

This commit is contained in:
Delete228 committed 2026-11-05 00:00:34 +03:00
commit 68b0396dfe
819 files changed
+43953 -6186

No files matched your search

@@ -0,0 +1,25 @@
package com.droiddeck.launcher.ui
import android.graphics.Color
import android.view.ContextThemeWrapper
import com.droiddeck.launcher.R
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34])
class AppThemeTest {
@Test fun theNavigationBarIsOpaqueAndDarkSoNothingLightShowsThroughIt() {
val themed = ContextThemeWrapper(RuntimeEnvironment.getApplication(), R.style.AppTheme)
val attrs = themed.obtainStyledAttributes(intArrayOf(android.R.attr.navigationBarColor))
val color = attrs.getColor(0, Color.TRANSPARENT)
attrs.recycle()
assertEquals(0xFF, Color.alpha(color))
assertTrue(Color.luminance(color) < 0.1f)
}
}
@@ -0,0 +1,42 @@
package com.droiddeck.launcher.ui
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class BottomChatPageTest {
@Test fun steamSitesOpenOthersDoNot() {
assertTrue(steamChatAllows("steamcommunity.com"))
assertTrue(steamChatAllows("login.steampowered.com"))
assertTrue(steamChatAllows("steam-chat.com"))
assertTrue(steamChatAllows("community.cloudflare.steamstatic.com"))
assertFalse(steamChatAllows("steamcommunity.com.example.net"))
assertFalse(steamChatAllows("evilsteamcommunity.com"))
assertFalse(steamChatAllows(null))
}
@Test fun chatFitScriptUsesADotDecimalInEveryLocale() {
val before = java.util.Locale.getDefault()
try {
java.util.Locale.setDefault(java.util.Locale.GERMANY)
val js = steamChatFitScript(821, 0.75f)
assertTrue(js.contains("m.content='width=821, initial-scale=0.75'"))
assertTrue(js.contains("s.textContent='$STEAM_CHAT_FIT_CSS'"))
assertFalse(STEAM_CHAT_FIT_CSS.contains('\''))
} finally {
java.util.Locale.setDefault(before)
}
}
@Test fun theGroupChatListLeavesRoomForTheOnlineFriends() {
assertTrue(STEAM_CHAT_FIT_CSS.contains(".ChatRoomList_Empty{display:none!important}"))
assertTrue(STEAM_CHAT_FIT_CSS.contains(".chatRoomListContainer{height:auto!important;max-height:25vh!important}"))
assertTrue(STEAM_CHAT_FIT_CSS.contains(".chat_main>:has(~.chat_main_flex){display:none!important}"))
}
@Test fun desktopAgentKeepsTheWebViewChromeVersion() {
val ua = desktopUserAgent("Mozilla/5.0 (Linux; Android 15; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/141.0.7390.122 Mobile Safari/537.36")
assertEquals("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.7390.122 Safari/537.36", ua)
}
}
@@ -0,0 +1,63 @@
package com.droiddeck.launcher.ui
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
class BottomDashboardTest {
@Test fun theRememberedPageOpensAgain() {
assertEquals("shots", pickBottomPage("shots", listOf("downloads", "shots")))
}
@Test fun aGoneOrMissingPageFallsBackToTheFirst() {
assertEquals("downloads", pickBottomPage("gone", listOf("downloads", "shots")))
assertEquals("downloads", pickBottomPage(null, listOf("downloads", "shots")))
assertNull(pickBottomPage("shots", emptyList()))
}
@Test fun withNothingPickedTheStatsOpen() {
val ids = listOf("telemetry", "downloads", "notifications", "screenshots", "chat")
assertEquals("telemetry", pickBottomPage(null, ids))
assertEquals("telemetry", pickBottomPage("gone", ids))
assertEquals("chat", pickBottomPage("chat", ids))
assertEquals("telemetry", pickBottomPage("telemetry", ids))
assertEquals("screenshots", pickBottomPage("screenshots", ids))
}
@Test fun aGameStartShowsTheInGameStats() {
assertEquals("telemetry", pageForGameStart(listOf("telemetry", "downloads", "chat")))
assertNull(pageForGameStart(listOf("downloads", "chat")))
}
}
class BottomDownloadsRateTest {
@Test fun rateIsBytesPerSecondBetweenReads() {
assertEquals(1_000_000L, downloadRate(0L, 0L, 2_000_000L, 2_000L))
}
@Test fun noMovementOrARestartIsZero() {
assertEquals(0L, downloadRate(500L, 0L, 500L, 2_000L))
assertEquals(0L, downloadRate(500L, 0L, 100L, 2_000L))
assertEquals(0L, downloadRate(-1L, 0L, 100L, 2_000L))
}
}
class BottomTelemetryLapTimeTest {
@Test fun lapTimesReadAsMinutesSecondsMillis() {
assertEquals("1:23.456", lapTime(83.456f))
assertEquals("0:05.000", lapTime(5f))
}
@Test fun eachSessionStartsWithoutAPickedTab() {
SessionBottomTab.pick("2026-11-01-01-steam", "screenshots")
assertEquals("screenshots", SessionBottomTab.picked("2026-11-01-01-steam"))
assertNull(SessionBottomTab.picked("2026-11-01-02-steam"))
assertNull(SessionBottomTab.picked(null))
assertEquals("telemetry", pickBottomPage(SessionBottomTab.picked("2026-11-01-02-steam"), listOf("telemetry", "chat", "screenshots")))
}
@Test fun theStripNamesTheSteamClient() {
assertEquals(com.droiddeck.launcher.R.string.stats_steam_client_x86, steamClientLabel("x86_64"))
assertEquals(com.droiddeck.launcher.R.string.stats_steam_client_arm, steamClientLabel("arm64"))
}
}
@@ -0,0 +1,21 @@
package com.droiddeck.launcher.ui
import org.junit.Assert.assertEquals
import org.junit.Test
class BottomDesktopFitTest {
@Test fun aDesktopOfThePanelsShapeFillsThePanel() {
assertEquals(1280 to 870, fitDesktop(1280, 870, 1280, 870))
assertEquals(1280 to 870, fitDesktop(1280, 870, 1278, 868))
}
@Test fun aDesktopOfAnotherShapeIsFittedNotStretched() {
val (w, h) = fitDesktop(1920, 1016, 1280, 870)
assertEquals(1016, h)
assertEquals(1494, w)
}
@Test fun nothingToFitLeavesThePanelSize() {
assertEquals(1920 to 1016, fitDesktop(1920, 1016, 0, 0))
}
}
@@ -0,0 +1,78 @@
package com.droiddeck.launcher.ui
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.performClick
import com.droiddeck.launcher.R
import com.droiddeck.launcher.session.SessionService
import com.droiddeck.launcher.session.SessionState
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
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.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], qualifiers = "w640dp-h480dp-land", application = android.app.Application::class)
class BottomScreenBarTest {
@get:Rule val compose = createRobolectricComposeRule()
private val context = RuntimeEnvironment.getApplication()
@After fun reset() {
SessionState.mode = SessionService.MODE_DESKTOP
}
@Test fun steamSessionsGetSteamAndQuickAccess() {
SessionState.mode = SessionService.MODE_STEAM
var steam = 0
var qam = 0
val model = sessionBarModel("Trackpad", {}, {}, { steam++ }, { qam++ })
assertNotNull(model.onSteam)
assertNotNull(model.onQam)
model.onSteam?.invoke()
model.onQam?.invoke()
assertEquals(1, steam)
assertEquals(1, qam)
}
@Test fun otherSessionsLeaveSteamOut() {
SessionState.mode = SessionService.MODE_DESKTOP
val model = sessionBarModel("Trackpad", {}, {}, {}, {})
assertNull(model.onSteam)
assertNull(model.onQam)
}
@Test fun everyButtonOnTheBarReachesItsAction() {
var closes = 0
var menus = 0
var steam = 0
var qam = 0
var keyboard = 0
compose.setContent {
DroidDeckTheme {
BottomScreenBar(BottomBarModel("Trackpad", { closes++ }, { menus++ }, { steam++ }, { qam++ },
listOf(BarExtra(context.getString(R.string.second_show_keyboard), icon = R.drawable.ic_bottom_keyboard) { keyboard++ })))
}
}
for (label in listOf(R.string.common_close, R.string.touch_droiddeck_menu, R.string.drawer_steam_menu, R.string.drawer_open_qam,
R.string.second_show_keyboard)) {
compose.onNodeWithContentDescription(context.getString(label)).performClick()
}
compose.waitForIdle()
assertEquals(listOf(1, 1, 1, 1, 1), listOf(closes, menus, steam, qam, keyboard))
}
@Test fun aBarWithoutMenuOrSteamShowsOnlyClose() {
compose.setContent {
DroidDeckTheme { BottomScreenBar(BottomBarModel("Terminal", {}, null, null, null)) }
}
compose.onNodeWithContentDescription(context.getString(R.string.common_close)).assertExists()
compose.onNodeWithContentDescription(context.getString(R.string.touch_droiddeck_menu)).assertDoesNotExist()
compose.onNodeWithContentDescription(context.getString(R.string.drawer_steam_menu)).assertDoesNotExist()
compose.onNodeWithContentDescription(context.getString(R.string.drawer_open_qam)).assertDoesNotExist()
}
}
@@ -0,0 +1,35 @@
package com.droiddeck.launcher.ui
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
class BuildWatermarkTest {
@Test
fun stableAndPreviewBuildsHaveNoWatermark() {
assertNull(BuildWatermark.lines(pr = 0, ci = true, commit = "abcdef0123", title = "", branch = ""))
}
@Test
fun prBuildShowsNumberHashAndTitle() {
assertEquals(
listOf("PR-1234 | abcdef0", "Fix: foo the bar"),
BuildWatermark.lines(pr = 1234, ci = true, commit = "abcdef0123", title = "Fix: foo the bar", branch = "x"),
)
}
@Test
fun longTitlesTruncateAtEightyCharacters() {
val lines = BuildWatermark.lines(pr = 7, ci = true, commit = "abcdef0", title = "a".repeat(120), branch = "")!!
assertEquals(80, lines[1].length)
assertEquals('…', lines[1].last())
}
@Test
fun localBuildShowsBranch() {
assertEquals(
listOf("LOCAL | abcdef0", "feat/thing"),
BuildWatermark.lines(pr = 0, ci = false, commit = "abcdef0123", title = "", branch = "feat/thing"),
)
}
}
@@ -1,6 +1,6 @@
package com.droiddeck.launcher.ui
import android.app.Activity
import androidx.activity.ComponentActivity
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
@@ -26,7 +26,7 @@ import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], shadows = [JoyConPadTest.RecordingWriter::class])
class DeckControlsPanelOwnershipTest {
private val controller = Robolectric.buildActivity(Activity::class.java).setup()
private val controller = Robolectric.buildActivity(ComponentActivity::class.java).setup()
private val activity = controller.get()
private val root = FrameLayout(activity)
private val bridge = PadBridge(File(activity.cacheDir, "panel-ownership"))
@@ -1,6 +1,8 @@
package com.droiddeck.launcher.ui
import android.content.ComponentName
import android.view.MotionEvent
import androidx.activity.ComponentActivity
import android.view.View
import com.droiddeck.launcher.input.JoyConPadTest
import com.droiddeck.launcher.input.PadBridge
@@ -9,8 +11,10 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
import java.nio.file.Files
@@ -22,14 +26,15 @@ class DeckControlsPanelTest {
val directory = Files.createTempDirectory("deck-panel").toFile()
try {
SessionState.deckPad = false
// No pad: the Deck layouts (trackpads, grips). A pad without Deck controls: the gamepad layout
// (sticks, d-pad, face buttons).
val app = RuntimeEnvironment.getApplication()
shadowOf(app.packageManager).addActivityIfNotPresent(ComponentName(app, ComponentActivity::class.java))
val activity = Robolectric.buildActivity(ComponentActivity::class.java).setup().get()
for (pad in listOf(null, PadBridge(directory))) for (portraitDock in listOf(false, true)) {
val name = "pad=${pad != null} portraitDock=$portraitDock"
val panel = DeckControlsPanel(RuntimeEnvironment.getApplication(), onClose = {}, onSteamMenu = {}, onQam = {},
val panel = DeckControlsPanel(activity, onClose = {}, onSteamMenu = {}, onQam = {},
pad = pad, portraitDock = portraitDock)
activity.setContentView(panel)
assertEquals(name, pad == null, panel.deckControls)
// The portrait dock sits under a portrait game; its gamepad layout needs a tall panel.
val (w, h) = if (portraitDock) 720 to 1000 else 1200 to 480
panel.measure(View.MeasureSpec.makeMeasureSpec(w, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(h, View.MeasureSpec.EXACTLY))
@@ -41,7 +46,6 @@ class DeckControlsPanelTest {
val down = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, x.toFloat(), y.toFloat(), 0)
assertEquals("$name ($x, $y)", expected, panel.dispatchTouchEvent(down))
down.recycle()
// Cancel rather than lift, so no button fires its action.
MotionEvent.obtain(0L, 1L, MotionEvent.ACTION_CANCEL, x.toFloat(), y.toFloat(), 0).also { panel.dispatchTouchEvent(it); it.recycle() }
if (expected) taken++ else missed++
}
@@ -2,6 +2,9 @@ package com.droiddeck.launcher.ui
import org.junit.After
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 org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@@ -29,4 +32,53 @@ class DualScreenPanelOwnerTest {
DualScreenPanel.hide(10)
assertEquals(-1, DualScreenPanel.shownOn)
}
@Test fun aPausedLauncherIsOnlyBroughtBackWhenThePanelTookFocusItself() {
DualScreenPanel.show(app, 2, 10)
assertEquals(10, DualScreenPanel.focusTask(fromPanel = false))
DualScreenPanel.ownerPaused(10, true)
assertNull(DualScreenPanel.focusTask(fromPanel = false))
assertEquals(10, DualScreenPanel.focusTask(fromPanel = true))
DualScreenPanel.ownerPaused(10, false)
assertEquals(10, DualScreenPanel.focusTask(fromPanel = false))
}
@Test fun anAppTheLauncherOpenedKeepsItsScreenEvenAfterABottomScreenTouch() {
DualScreenPanel.show(app, 2, 10)
DualScreenPanel.yieldTo(10, true)
DualScreenPanel.ownerPaused(10, true)
assertNull(DualScreenPanel.focusTask(fromPanel = true))
DualScreenPanel.yieldTo(10, false)
assertEquals(10, DualScreenPanel.focusTask(fromPanel = true))
}
@Test fun aScreenFromAnotherAppKeepsTheTopScreenAfterABottomScreenTouch() {
DualScreenPanel.show(app, 2, 10)
assertTrue(DualScreenPanel.opensOutside("com.droiddeck.launcher", "com.android.packageinstaller"))
DualScreenPanel.yieldTo(10, true)
DualScreenPanel.ownerPaused(10, true)
assertNull(DualScreenPanel.focusTask(fromPanel = true))
DualScreenPanel.ownerPaused(10, false)
DualScreenPanel.yieldTo(10, false)
assertEquals(10, DualScreenPanel.focusTask(fromPanel = true))
}
@Test fun droidDecksOwnScreensAndUnresolvedIntentsDoNotYield() {
assertFalse(DualScreenPanel.opensOutside("com.droiddeck.launcher", "com.droiddeck.launcher"))
assertFalse(DualScreenPanel.opensOutside("com.droiddeck.launcher", null))
}
@Test fun anotherTasksPauseDoesNotStopThePanelReturningFocus() {
DualScreenPanel.show(app, 2, 10)
DualScreenPanel.ownerPaused(11, true)
assertEquals(10, DualScreenPanel.focusTask(fromPanel = false))
}
@Test fun aNewPanelForgetsThatTheLastLauncherWasPaused() {
DualScreenPanel.show(app, 2, 10)
DualScreenPanel.ownerPaused(10, true)
DualScreenPanel.hide()
DualScreenPanel.show(app, 2, 10)
assertEquals(10, DualScreenPanel.focusTask(fromPanel = false))
}
}
@@ -0,0 +1,35 @@
package com.droiddeck.launcher.ui
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class GameScreenSwapTest {
private fun wanted(
requested: Boolean = true,
activityStarted: Boolean = true,
sessionEnded: Boolean = false,
inPip: Boolean = false,
glassesOutput: Boolean = false,
bottomScreenFree: Boolean = true,
) = GameScreenSwap.wanted(requested, activityStarted, sessionEnded, inPip, glassesOutput, bottomScreenFree)
@Test fun thePickedSwapPutsTheGameOnTheBottomScreen() {
assertTrue(wanted())
}
@Test fun withoutAPickTheGameStaysOnTop() {
assertFalse(wanted(requested = false))
}
@Test fun theGameComesBackToTheTopWhenTheSessionIsHiddenOrEnds() {
assertFalse(wanted(activityStarted = false))
assertFalse(wanted(sessionEnded = true))
assertFalse(wanted(inPip = true))
}
@Test fun glassesAndAHeldBottomScreenWin() {
assertFalse(wanted(glassesOutput = true))
assertFalse(wanted(bottomScreenFree = false))
}
}
@@ -0,0 +1,33 @@
package com.droiddeck.launcher.ui
import org.junit.Assert.assertEquals
import org.junit.Test
class HistoryTest {
@Test fun theSpanIsTheTimeTheKeptReadingsCover() {
val h = History(3)
h.add(1f, 1_000L)
h.add(2f, 1_500L)
assertEquals(1, h.spanSeconds())
h.add(3f, 2_000L)
h.add(4f, 4_000L)
assertEquals(listOf(2f, 3f, 4f), h.snapshot())
assertEquals(3, h.spanSeconds())
}
@Test fun aHistoryThatStopsBeingFedKeepsItsSpan() {
val h = History(4)
h.add(1f, 10_000L)
h.add(2f, 20_000L)
assertEquals(10, h.spanSeconds())
assertEquals(10, h.spanSeconds())
}
@Test fun readingsWithoutATimeHaveNoSpan() {
val h = History(2)
h.add(1f)
assertEquals(0, h.spanSeconds())
assertEquals(0, History(2).spanSeconds())
assertEquals(0, History(2).apply { add(1f, 5_000L) }.spanSeconds())
}
}
@@ -87,6 +87,11 @@ class LibraryEntriesTest {
assertEquals(listOf("epic", "gog", "battlenet"), librarySources(entries, listOf("missing", "epic", "epic", "amazon")))
}
@Test fun aSignedInStoreWithNoGamesKeepsItsPlaceInTheStoreOrder() {
val entries = listOf("steam", "xbox").map { LibraryEntry(it, it, it, null, null, true) }
assertEquals(listOf("steam", "xbox", "itch", "gamejolt"), librarySources(entries, listOf("xbox", "itch", "gamejolt"), setOf("itch", "gamejolt")))
}
@Test fun gameKeysNameEitherAnAppOrAStoreProduct() {
GameRef.parse("app:440").let { assertEquals(440, it.appId); assertNull(it.store) }
GameRef.parse("app:-12").let { assertEquals(-12, it.appId) }
@@ -24,6 +24,7 @@ import com.droiddeck.launcher.session.SessionService
import com.droiddeck.launcher.session.SessionState
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
@@ -74,9 +75,32 @@ class SessionSecondScreenTest {
compose.onNodeWithText(context.getString(R.string.second_mode_keyboard_trackpad)).assertDoesNotExist()
}
@Test fun desktopTrackpadOmitsSteamShortcuts() = checkShortcuts(steam = false)
@Test fun steamTrackpadKeepsWorkingSteamShortcuts() = checkShortcuts(steam = true)
@Test fun provisionalBottomScreenPanelSettlesOnlyOnceTheSessionIsInFront() {
SessionState.mode = SessionService.MODE_STEAM
val previousMode = SessionState.secondScreenMode
val previousProvisional = SessionState.secondScreenProvisional
SessionState.secondScreenMode = SecondScreenMode.NONE
try {
val activity = Robolectric.buildActivity(SessionActivity::class.java).get()
val pip: MutableState<Boolean> = ReflectionHelpers.getField(activity, "pipUi\$delegate")
fun settle() = ReflectionHelpers.callInstanceMethod<Unit>(activity, "settleDualScreenControls")
SessionState.secondScreenProvisional = true
ReflectionHelpers.setField(activity, "started", true)
pip.value = true
settle()
assertTrue(SessionState.secondScreenProvisional)
pip.value = false
ReflectionHelpers.setField(activity, "started", false)
settle()
assertTrue(SessionState.secondScreenProvisional)
ReflectionHelpers.setField(activity, "started", true)
settle()
assertFalse(SessionState.secondScreenProvisional)
} finally {
SessionState.secondScreenMode = previousMode
SessionState.secondScreenProvisional = previousProvisional
}
}
@Test fun trackpadTapUsesPositionLeftByAnotherPointerSource() {
val activity = Robolectric.buildActivity(SessionActivity::class.java).get()
@@ -89,7 +113,7 @@ class SessionSecondScreenTest {
try {
panel.create()
panel.showMode(SecondScreenMode.KEYBOARD_TRACKPAD)
val trackpad = descendants(panel.window!!.decorView).first { it.javaClass.simpleName == "TrackpadView" }
val trackpad = descendants(panel.window!!.decorView).first { it is SessionTrackpadView }
trackpad.layout(0, 0, 1000, 600)
for (next in listOf(Offset(0.2f, 0.7f), Offset(0.8f, 0.1f))) {
position = next
@@ -103,25 +127,26 @@ class SessionSecondScreenTest {
} finally { panel.closeControls() }
}
@Test fun trackpadMenuButtonOnlyAppearsWhenTheMenuCanMove() {
@Test fun terminalOpenedBeforeItWasReadyIsRetriedButOtherPanelsAreLeftAlone() {
SessionState.mode = SessionService.MODE_STEAM
val activity = Robolectric.buildActivity(SessionActivity::class.java).get()
val display = activity.getSystemService(DisplayManager::class.java).getDisplay(Display.DEFAULT_DISPLAY)
val label = context.getString(R.string.touch_droiddeck_menu)
for (movable in listOf(false, true)) {
var menus = 0
val panel = SecondScreenPresentation(activity, display, { _, _, _, _ -> }, { _, _ -> }, {},
{}, {}, {}, onMenu = if (movable) ({ menus++ }) else null)
try {
panel.create()
panel.showMode(SecondScreenMode.KEYBOARD_TRACKPAD)
val buttons = descendants(panel.window!!.decorView).filter { it.contentDescription == label }.toList()
assertEquals(if (movable) 1 else 0, buttons.size)
buttons.forEach { it.performClick() }
assertEquals(if (movable) 1 else 0, menus)
} finally {
panel.closeControls()
}
val panel = SecondScreenPresentation(activity, display, { _, _, _, _ -> }, { _, _ -> }, {}, {}, {}, {})
try {
panel.show()
panel.showMode(SecondScreenMode.KEYBOARD_TRACKPAD)
val root = panel.window!!.decorView
val trackpad = descendants(root).toList()
panel.retryTerminal()
assertEquals(trackpad, descendants(root).toList())
panel.showMode(SecondScreenMode.TERMINAL)
val notReady = context.getString(R.string.second_terminal_not_ready)
val before = descendants(root).filter { (it as? TextView)?.text == notReady }.single()
panel.retryTerminal()
val after = descendants(root).filter { (it as? TextView)?.text == notReady }.single()
assertTrue(before !== after)
} finally {
panel.closeControls()
}
}
@@ -219,38 +244,12 @@ class SessionSecondScreenTest {
SessionDrawer(true, SessionDrawerPage.SECOND_SCREEN, false, {}, actions(steam, displays) { selected += it })
}
}
for (mode in listOf(SecondScreenMode.KEYBOARD_TRACKPAD, SecondScreenMode.TERMINAL)) {
val modes = listOf(SecondScreenMode.KEYBOARD_TRACKPAD, SecondScreenMode.CUSTOM_CONTROLS, SecondScreenMode.TERMINAL)
for (mode in modes) {
compose.onNodeWithText(context.getString(mode.label)).performScrollTo().assertIsDisplayed().performClick()
}
compose.onNodeWithText(context.getString(SecondScreenMode.DECK_CONTROLS.label)).assertDoesNotExist()
assertEquals(listOf(SecondScreenMode.KEYBOARD_TRACKPAD, SecondScreenMode.TERMINAL), selected)
}
private fun checkShortcuts(steam: Boolean) {
SessionState.mode = if (steam) SessionService.MODE_STEAM else SessionService.MODE_DESKTOP
val activity = Robolectric.buildActivity(SessionActivity::class.java).get()
val display = activity.getSystemService(DisplayManager::class.java).getDisplay(Display.DEFAULT_DISPLAY)
var menus = 0
var qams = 0
val panel = SecondScreenPresentation(activity, display, { _, _, _, _ -> }, { _, _ -> }, {},
{ menus++ }, { qams++ }, {})
try {
panel.create()
panel.showMode(SecondScreenMode.KEYBOARD_TRACKPAD)
val buttons = descendants(panel.window!!.decorView).filterIsInstance<TextView>().filter { it.isClickable }.toList()
assertTrue(buttons.any { it.text == context.getString(R.string.second_show_keyboard) })
val shortcuts = buttons.filter { it.text == "STEAM" || it.text == "•••" }
if (steam) {
assertEquals(2, shortcuts.size)
shortcuts.forEach { it.performClick() }
assertEquals(1, menus)
assertEquals(1, qams)
} else {
assertTrue(shortcuts.isEmpty())
}
} finally {
panel.closeControls()
}
assertEquals(modes, selected)
}
private fun descendants(view: View): Sequence<View> = sequence {
@@ -53,11 +53,8 @@ class SteamIntegrationGroupTest {
compose.onNodeWithText("3 of 4 on").assertExists()
}
@Test fun shortcutsWaitForHome() {
@Test fun shortcutsDoNotNeedHome() {
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()
}
@@ -37,6 +37,34 @@ class StepOutTest {
assertEquals(300f, b.bottom, 0.5f)
}
@Test fun aLeftMenuWithRoomStaysLeft() {
assertEquals(StepSide.Left, fitStepSide(StepSide.Left, Rect(1900f, 20f, 1980f, 80f), hostWidth = 2400f, wanted = 840f))
}
@Test fun aLeftMenuNearTheLeftEdgeOpensRight() {
assertEquals(StepSide.Right, fitStepSide(StepSide.Left, Rect(300f, 20f, 420f, 80f), hostWidth = 1080f, wanted = 840f))
}
@Test fun aRightMenuNearTheRightEdgeOpensLeft() {
assertEquals(StepSide.Left, fitStepSide(StepSide.Right, Rect(900f, 20f, 1000f, 80f), hostWidth = 1080f, wanted = 840f))
}
@Test fun aSqueezedMenuKeepsItsSideWhenTheOtherSideIsNarrower() {
assertEquals(StepSide.Left, fitStepSide(StepSide.Left, Rect(600f, 20f, 700f, 80f), hostWidth = 1080f, wanted = 840f))
}
@Test fun theOutlineReachFollowsTheChosenSide() {
val wide = Rect(600f, 20f, 700f, 80f)
assertEquals(600f to 300f, stepReach(StepSide.Left, wide, hostWidth = 1080f, width = 400))
assertEquals(700f to 1000f, stepReach(StepSide.Right, wide, hostWidth = 1080f, width = 400))
}
@Test fun theOutlineReachStaysInsideTheHost() {
val near = Rect(100f, 20f, 200f, 80f)
assertEquals(100f to 0f, stepReach(StepSide.Left, near, hostWidth = 1080f, width = 400))
assertEquals(200f to 1080f, stepReach(StepSide.Right, near, hostWidth = 1080f, width = 1200))
}
@Test fun aClosedOutlineIsJustThePill() {
val path = Path()
stepPathRight(path, pill, right = pill.right, bottom = pill.bottom, pullTop = pill.bottom + 6f, box = 16f, fillet = 10f, pillCorner = 12f)
@@ -0,0 +1,26 @@
package com.droiddeck.launcher.ui
import org.junit.Assert.assertArrayEquals
import org.junit.Test
class StripFitTest {
@Test fun everythingFitsOnAWideLine() {
assertArrayEquals(booleanArrayOf(true, true, true), fitByPriority(intArrayOf(10, 20, 30), intArrayOf(0, 1, 2), 5, 100))
}
@Test fun theLeastImportantItemsAreLeftOutFirst() {
assertArrayEquals(booleanArrayOf(true, false, true), fitByPriority(intArrayOf(10, 20, 30), intArrayOf(0, 2, 1), 5, 60))
}
@Test fun anItemThatDoesNotFitEndsTheLine() {
assertArrayEquals(booleanArrayOf(true, false, false), fitByPriority(intArrayOf(10, 50, 5), intArrayOf(0, 1, 2), 2, 40))
}
@Test fun equalPrioritiesKeepTheirOrder() {
assertArrayEquals(booleanArrayOf(true, true, false), fitByPriority(intArrayOf(10, 10, 10), intArrayOf(0, 0, 0), 0, 25))
}
@Test fun nothingFitsInNoRoom() {
assertArrayEquals(booleanArrayOf(false, false), fitByPriority(intArrayOf(10, 10), intArrayOf(0, 1), 0, 5))
}
}
@@ -78,7 +78,6 @@ class TrackingRecoveryViewTest {
difference+=abs(((actual ushr 16) and 255)-((reference ushr 16) and 255))
}
}
// Native text rasterization can round a translated glyph edge differently.
assertTrue("Eye at x=$x changed $changed pixels",changed<pixels/1000)
assertTrue("Eye at x=$x has different content",difference.toDouble()/(pixels*3)<0.1)
}