Skip to content

StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.

test: add compose backup preview benchmark host

David Nashash666c2dd78379
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index ad7d2789..963991ed 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -536,6 +536,7 @@ dependencies {
androidTestImplementation(libs.navigation.testing)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
+ androidTestImplementation(libs.uiautomator)
androidTestImplementation(libs.truth)
}
diff --git a/app/src/androidTest/java/com/streamvault/app/benchmark/BackupPreviewBenchmarkActivityTest.kt b/app/src/androidTest/java/com/streamvault/app/benchmark/BackupPreviewBenchmarkActivityTest.kt
new file mode 100644
index 00000000..83e52d6e
--- /dev/null
+++ b/app/src/androidTest/java/com/streamvault/app/benchmark/BackupPreviewBenchmarkActivityTest.kt
@@ -0,0 +1,35 @@
+package com.streamvault.app.benchmark
+
+import android.content.Intent
+import androidx.test.core.app.ActivityScenario
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.uiautomator.By
+import androidx.test.uiautomator.UiDevice
+import androidx.test.uiautomator.Until
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class BackupPreviewBenchmarkActivityTest {
+
+ @Test
+ fun composeModeRendersDeterministicPreview() {
+ val intent = Intent(
+ ApplicationProvider.getApplicationContext(),
+ BackupPreviewBenchmarkActivity::class.java,
+ ).putExtra(BackupPreviewBenchmarkActivity.EXTRA_PRESENTATION, "compose")
+
+ ActivityScenario.launch<BackupPreviewBenchmarkActivity>(intent).use {
+ val device = UiDevice.getInstance(
+ InstrumentationRegistry.getInstrumentation(),
+ )
+
+ assertThat(device.wait(Until.hasObject(By.text("Review Backup Import")), 20_000L))
+ .isTrue()
+ assertThat(device.hasObject(By.text("Preferences"))).isTrue()
+ }
+ }
+}
diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml
new file mode 100644
index 00000000..c1aab1d8
--- /dev/null
+++ b/app/src/debug/AndroidManifest.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android">
+ <application>
+ <activity
+ android:name=".benchmark.BackupPreviewBenchmarkActivity"
+ android:exported="true"
+ android:theme="@style/Theme.StreamVault">
+ <intent-filter>
+ <action android:name="com.streamvault.app.debug.BACKUP_PREVIEW_BENCHMARK" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
diff --git a/app/src/debug/java/com/streamvault/app/benchmark/BackupPreviewBenchmarkActivity.kt b/app/src/debug/java/com/streamvault/app/benchmark/BackupPreviewBenchmarkActivity.kt
new file mode 100644
index 00000000..1a5eec44
--- /dev/null
+++ b/app/src/debug/java/com/streamvault/app/benchmark/BackupPreviewBenchmarkActivity.kt
@@ -0,0 +1,61 @@
+package com.streamvault.app.benchmark
+
+import android.os.Bundle
+import androidx.activity.ComponentActivity
+import androidx.activity.compose.setContent
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import com.streamvault.core.ui.theme.StreamVaultTheme
+import com.streamvault.domain.manager.BackupConflictStrategy
+import com.streamvault.feature.settings.presentation.BackupImportPreviewDialog
+
+class BackupPreviewBenchmarkActivity : ComponentActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ check(intent.getStringExtra(EXTRA_PRESENTATION) == PRESENTATION_COMPOSE) {
+ "Only the Compose presentation is available before the Views experiment is wired."
+ }
+
+ setContent {
+ StreamVaultTheme {
+ var plan by remember { mutableStateOf(BackupPreviewBenchmarkFixture.plan) }
+ BackupImportPreviewDialog(
+ preview = BackupPreviewBenchmarkFixture.preview,
+ plan = plan,
+ onDismiss = ::finish,
+ onStrategySelected = { strategy: BackupConflictStrategy ->
+ plan = plan.copy(conflictStrategy = strategy)
+ },
+ onImportPreferencesChanged = { enabled ->
+ plan = plan.copy(importPreferences = enabled)
+ },
+ onImportProvidersChanged = { enabled ->
+ plan = plan.copy(importProviders = enabled)
+ },
+ onImportSavedLibraryChanged = { enabled ->
+ plan = plan.copy(importSavedLibrary = enabled)
+ },
+ onImportPlaybackHistoryChanged = { enabled ->
+ plan = plan.copy(importPlaybackHistory = enabled)
+ },
+ onImportMultiViewChanged = { enabled ->
+ plan = plan.copy(importMultiViewPresets = enabled)
+ },
+ onImportRecordingSchedulesChanged = { enabled ->
+ plan = plan.copy(importRecordingSchedules = enabled)
+ },
+ onConfirm = ::finish,
+ )
+ }
+ }
+ }
+
+ companion object {
+ const val EXTRA_PRESENTATION = "presentation"
+ const val PRESENTATION_COMPOSE = "compose"
+ const val PRESENTATION_VIEWS = "views"
+ }
+}
diff --git a/app/src/debug/java/com/streamvault/app/benchmark/BackupPreviewBenchmarkFixture.kt b/app/src/debug/java/com/streamvault/app/benchmark/BackupPreviewBenchmarkFixture.kt
new file mode 100644
index 00000000..84fcf0bf
--- /dev/null
+++ b/app/src/debug/java/com/streamvault/app/benchmark/BackupPreviewBenchmarkFixture.kt
@@ -0,0 +1,33 @@
+package com.streamvault.app.benchmark
+
+import com.streamvault.domain.manager.BackupImportPlan
+import com.streamvault.domain.manager.BackupPreview
+
+internal object BackupPreviewBenchmarkFixture {
+ val preview = BackupPreview(
+ version = 14,
+ providerCount = 3,
+ favoriteCount = 12,
+ groupCount = 4,
+ playbackHistoryCount = 8,
+ multiViewPresetCount = 2,
+ preferenceCount = 10,
+ protectedCategoryCount = 1,
+ scheduledRecordingCount = 3,
+ providerConflicts = 1,
+ favoriteConflicts = 2,
+ groupConflicts = 0,
+ historyConflicts = 1,
+ protectedCategoryConflicts = 0,
+ recordingConflicts = 1,
+ )
+
+ val plan = BackupImportPlan(
+ importPreferences = true,
+ importProviders = false,
+ importSavedLibrary = true,
+ importPlaybackHistory = false,
+ importMultiViewPresets = true,
+ importRecordingSchedules = false,
+ )
+}