mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 11:07:10 +00:00
style(sidecar): trim non-load-bearing comments from this PR's driver code and tests
This commit is contained in:
1 parent
724230e8bb
commit
9597433cc0
3 files changed
+9
-34
No files matched your search
@@ -682,12 +682,9 @@ internal fun chunkForInput(text: String, size: Int): List<String> {
|
|||||||
return chunks
|
return chunks
|
||||||
}
|
}
|
||||||
|
|
||||||
// typeChunks sends each chunk via `send`, re-reading the foreground owner with
|
// typeChunks sends each chunk, stopping if the foreground owner changed from
|
||||||
// `currentForeground` before every chunk after the first. If the owner changed
|
// startOwner so the remaining keystrokes can't spray into a window that stole
|
||||||
// from `startOwner`, it stops (returning the count already typed) so keystrokes
|
// focus. The first chunk always sends; a null startOwner skips the check.
|
||||||
// never spray into a window that stole focus mid-type. The first chunk is always
|
|
||||||
// sent (there is nothing typed yet to leak), and a null startOwner (foreground
|
|
||||||
// unknown) disables the check so typing proceeds. Returns the chars sent.
|
|
||||||
internal fun typeChunks(
|
internal fun typeChunks(
|
||||||
chunks: List<String>,
|
chunks: List<String>,
|
||||||
startOwner: String?,
|
startOwner: String?,
|
||||||
@@ -712,11 +709,9 @@ internal fun typeChunks(
|
|||||||
private val resumedActivityPackage =
|
private val resumedActivityPackage =
|
||||||
Regex("""([a-zA-Z][a-zA-Z0-9_.]*)/[a-zA-Z0-9_.$]+""")
|
Regex("""([a-zA-Z][a-zA-Z0-9_.]*)/[a-zA-Z0-9_.$]+""")
|
||||||
|
|
||||||
// parseResumedPackage extracts the foreground package from `dumpsys activity
|
// parseResumedPackage reads the foreground package off any *ResumedActivity line,
|
||||||
// activities` output. It reads any *ResumedActivity line (topResumedActivity=,
|
// matching the Go guard's marker set so OEM wording can't disable the mid-type
|
||||||
// mResumedActivity:, ResumedActivity:) rather than one OEM-specific phrasing, so
|
// guard. Null if none present.
|
||||||
// a ROM that words the line differently does not silently disable the mid-type
|
|
||||||
// foreground guard. Returns null when no such line is present.
|
|
||||||
internal fun parseResumedPackage(dumpsys: String): String? {
|
internal fun parseResumedPackage(dumpsys: String): String? {
|
||||||
for (line in dumpsys.lineSequence()) {
|
for (line in dumpsys.lineSequence()) {
|
||||||
if (!line.contains("ResumedActivity")) continue
|
if (!line.contains("ResumedActivity")) continue
|
||||||
@@ -1101,10 +1096,8 @@ internal class WdaRecovery(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// maestroKeyFor resolves a logical key name to a maestro KeyCode. It lowercases
|
// maestroKeyFor rejects an unknown key (matching StubDriverBackend) so an
|
||||||
// and rejects an unknown name (matching StubDriverBackend's contract, so an
|
// unmapped or wrong-case key fails loudly instead of being silently dropped.
|
||||||
// unmapped or wrong-case key fails loudly instead of being silently dropped),
|
|
||||||
// and returns null only when the key is known but maestro has no enum for it.
|
|
||||||
internal fun maestroKeyFor(key: String): maestro.KeyCode? {
|
internal fun maestroKeyFor(key: String): maestro.KeyCode? {
|
||||||
val keyCode = StubDriverBackend.KEY_MAP[key.lowercase()]
|
val keyCode = StubDriverBackend.KEY_MAP[key.lowercase()]
|
||||||
?: throw IllegalArgumentException("unsupported pressKey value: $key")
|
?: throw IllegalArgumentException("unsupported pressKey value: $key")
|
||||||
|
|||||||
@@ -146,8 +146,6 @@ class InputTextTest {
|
|||||||
assertTrue("-5" == StubDriverBackend.escapeForAdbInputText("-5"))
|
assertTrue("-5" == StubDriverBackend.escapeForAdbInputText("-5"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// typeChunks sends every chunk while the foreground holds steady, so a normal
|
|
||||||
// type completes in full.
|
|
||||||
@Test fun typeChunksSendsAllChunksWhenForegroundStable() {
|
@Test fun typeChunksSendsAllChunksWhenForegroundStable() {
|
||||||
val sent = mutableListOf<String>()
|
val sent = mutableListOf<String>()
|
||||||
val typed =
|
val typed =
|
||||||
@@ -158,14 +156,10 @@ class InputTextTest {
|
|||||||
assertEquals(8, typed)
|
assertEquals(8, typed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The core guard: once the app under test loses the foreground mid-type, the
|
|
||||||
// remaining chunks must NOT be sent (they would spray into the window that
|
|
||||||
// stole focus, e.g. the launcher search box).
|
|
||||||
@Test fun typeChunksStopsWhenForegroundLeavesMidType() {
|
@Test fun typeChunksStopsWhenForegroundLeavesMidType() {
|
||||||
val sent = mutableListOf<String>()
|
val sent = mutableListOf<String>()
|
||||||
var calls = 0
|
var calls = 0
|
||||||
// Foreground holds for the check before chunk 2, then goes foreign before
|
// Foreground holds before chunk 2, then goes foreign before chunk 3.
|
||||||
// chunk 3: two chunks land, the third is suppressed.
|
|
||||||
val typed = typeChunks(listOf("aaa", "bbb", "ccc"), "app.folio", {
|
val typed = typeChunks(listOf("aaa", "bbb", "ccc"), "app.folio", {
|
||||||
calls++
|
calls++
|
||||||
if (calls == 1) "app.folio" else "com.android.launcher"
|
if (calls == 1) "app.folio" else "com.android.launcher"
|
||||||
@@ -178,8 +172,6 @@ class InputTextTest {
|
|||||||
assertEquals(6, typed)
|
assertEquals(6, typed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The first chunk is always sent: there is nothing typed yet to leak, so the
|
|
||||||
// guard must not check before the very first send.
|
|
||||||
@Test fun typeChunksAlwaysSendsFirstChunkEvenIfForegroundAlreadyForeign() {
|
@Test fun typeChunksAlwaysSendsFirstChunkEvenIfForegroundAlreadyForeign() {
|
||||||
val sent = mutableListOf<String>()
|
val sent = mutableListOf<String>()
|
||||||
val typed =
|
val typed =
|
||||||
@@ -190,17 +182,12 @@ class InputTextTest {
|
|||||||
assertEquals(3, typed)
|
assertEquals(3, typed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A null start owner (foreground unreadable) disables the guard so typing is
|
|
||||||
// not blocked where the signal is unavailable.
|
|
||||||
@Test fun typeChunksWithUnknownOwnerSendsEverything() {
|
@Test fun typeChunksWithUnknownOwnerSendsEverything() {
|
||||||
val sent = mutableListOf<String>()
|
val sent = mutableListOf<String>()
|
||||||
typeChunks(listOf("aaa", "bbb"), null, { "anything" }) { sent.add(it) }
|
typeChunks(listOf("aaa", "bbb"), null, { "anything" }) { sent.add(it) }
|
||||||
assertEquals(listOf("aaa", "bbb"), sent)
|
assertEquals(listOf("aaa", "bbb"), sent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseResumedPackage must read the foreground package off any *ResumedActivity
|
|
||||||
// wording, not one OEM-specific phrasing, or the mid-type guard silently
|
|
||||||
// no-ops on ROMs that word the line differently.
|
|
||||||
@Test fun parseResumedPackageReadsEachResumedActivityWording() {
|
@Test fun parseResumedPackageReadsEachResumedActivityWording() {
|
||||||
val cases = mapOf(
|
val cases = mapOf(
|
||||||
" topResumedActivity=ActivityRecord{8b u0 app.folio/.MainActivity t42}" to
|
" topResumedActivity=ActivityRecord{8b u0 app.folio/.MainActivity t42}" to
|
||||||
@@ -219,9 +206,6 @@ class InputTextTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// maestroKeyFor resolves the production pressKey path: it lowercases and
|
|
||||||
// rejects an unknown key (the Maestro backend used to silently drop both
|
|
||||||
// unknown and wrong-case keys).
|
|
||||||
@Test fun maestroKeyForResolvesAndRejects() {
|
@Test fun maestroKeyForResolvesAndRejects() {
|
||||||
assertEquals(maestro.KeyCode.BACK, maestroKeyFor("back"))
|
assertEquals(maestro.KeyCode.BACK, maestroKeyFor("back"))
|
||||||
assertEquals(maestro.KeyCode.BACK, maestroKeyFor("BACK"))
|
assertEquals(maestro.KeyCode.BACK, maestroKeyFor("BACK"))
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ class RetryOpenTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The exact failure this guards: a slow device that never opens must surface
|
|
||||||
// the last error after exhausting attempts, not loop forever or swallow it.
|
|
||||||
@Test fun rethrowsLastErrorAfterExhaustingAttempts() {
|
@Test fun rethrowsLastErrorAfterExhaustingAttempts() {
|
||||||
var opens = 0
|
var opens = 0
|
||||||
var sleeps = 0
|
var sleeps = 0
|
||||||
|
|||||||
Reference in new issue
Block a user