Skip to content

Commit

Permalink
fix: don't allow negative swipe duration (#2073)
Browse files Browse the repository at this point in the history
* fix: don't allow negative swipe duration

* update ios driver
  • Loading branch information
axelniklasson authored Oct 3, 2024
1 parent fd0927d commit 7efc075
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<string>maestro-driver-iosUITests</string>
<key>BlueprintProviderName</key>
<string>maestro-driver-ios</string>
<key>BlueprintProviderRelativePath</key>
<string>maestro-driver-ios.xcodeproj</string>
<key>BundleIdentifiersForCrashReportEmphasis</key>
<array>
<string>dev.mobile.maestro-driver-ios</string>
Expand All @@ -39,6 +41,8 @@
<integer>1</integer>
<key>EnvironmentVariables</key>
<dict>
<key>APP_DISTRIBUTOR_ID_OVERRIDE</key>
<string>com.apple.AppStore</string>
<key>OS_ACTIVITY_DT_MODE</key>
<string>YES</string>
<key>SQLITE_ENABLE_THREAD_ASSERTIONS</key>
Expand All @@ -48,6 +52,8 @@
<true/>
<key>IsXCTRunnerHostedTestBundle</key>
<true/>
<key>PreferredScreenCaptureFormat</key>
<string>screenRecording</string>
<key>ProductModuleName</key>
<string>maestro_driver_iosUITests</string>
<key>RunOrder</key>
Expand Down Expand Up @@ -85,6 +91,8 @@
<array/>
<key>UITargetAppEnvironmentVariables</key>
<dict>
<key>APP_DISTRIBUTOR_ID_OVERRIDE</key>
<string>com.apple.AppStore</string>
<key>DYLD_FRAMEWORK_PATH</key>
<string>__TESTROOT__/Debug-iphonesimulator:__TESTROOT__/Debug-iphonesimulator/PackageFrameworks</string>
<key>DYLD_LIBRARY_PATH</key>
Expand Down
Binary file modified maestro-ios-driver/src/main/resources/maestro-driver-ios.zip
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ struct SwipeRouteHandlerV2: HTTPHandler {
return AppError(type: .precondition, message: "incorrect request body provided for swipe request v2").httpResponse
}

if (requestBody.duration < 0) {
return AppError(type: .precondition, message: "swipe duration can not be negative").httpResponse
}

do {
try await swipePrivateAPI(requestBody)
return HTTPResponse(statusCode: .ok)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ data class ScrollUntilVisibleCommand(
val visibilityPercentageNormalized = (visibilityPercentage / 100).toDouble()

private fun String.speedToDuration(): String {
return ((1000 * (100 - this.toLong()).toDouble() / 100).toLong() + 1).toString()
val duration = ((1000 * (100 - this.toLong()).toDouble() / 100).toLong() + 1)
return if (duration < 0) { DEFAULT_SCROLL_DURATION } else duration.toString()
}

private fun String.timeoutToMillis(): String {
Expand Down
36 changes: 36 additions & 0 deletions maestro-test/src/test/kotlin/maestro/test/IntegrationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3135,6 +3135,42 @@ class IntegrationTest {
)
}

@Test
fun `Case 118 - Scroll until view is visible - no negative values allowed`() {
// Given
val commands = readCommands("118_scroll_until_visible_negative")
val expectedDuration = "40"
val expectedTimeout = "20000"
val info = driver { }.deviceInfo()

val elementBounds = Bounds(0, 0 + info.heightGrid, 100, 100 + info.heightGrid)
val driver = driver {
element {
id = "maestro"
bounds = elementBounds
}
}

// When
var scrollDuration = "0"
var timeout = "0"
Maestro(driver).use {
orchestra(it, onCommandMetadataUpdate = { _, metaData ->
scrollDuration = metaData.evaluatedCommand?.scrollUntilVisible?.scrollDuration.toString()
timeout = metaData.evaluatedCommand?.scrollUntilVisible?.timeout.toString()
}).runFlow(commands)
}

// Then
assertThat(scrollDuration).isEqualTo(expectedDuration)
assertThat(timeout).isEqualTo(expectedTimeout)
driver.assertEvents(
listOf(
Event.SwipeElementWithDirection(Point(270, 480), SwipeDirection.UP, expectedDuration.toLong()),
)
)
}

private fun orchestra(
maestro: Maestro,
) = Orchestra(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
appId: com.example.app
---
- scrollUntilVisible:
element:
id: "maestro"
direction: DOWN
speed: 110
timeout: -200

0 comments on commit 7efc075

Please sign in to comment.