web: extract WebStores interface from WebRepository for testability
- Commit
b2c6d41751cd7ee02f7f98aae9107b20aa9345e9- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 03:55 UTC (29 days ago)
- Parents
2968049
WebViewModel depended on the concrete WebRepository, whose Room database is SQLCipher-backed through an AndroidKeyStore key that does not exist under Robolectric, so no view-model or page test could construct it on the JVM. WebRepository now implements the new WebStores interface (the seven per-domain stores) and WebViewModel depends on that interface. Production wiring is unchanged; tests supply stores backed by an in-memory WebDatabase. (cherry picked from commit edca27501cd53ffd0be6408cf1329d27b27a07a1)
Diff
web/src/main/java/com/vayunmathur/web/data/WebRepository.kt
diff --git a/web/src/main/java/com/vayunmathur/web/data/WebRepository.kt b/web/src/main/java/com/vayunmathur/web/data/WebRepository.ktindex 5f8eec89e7..4df0119c68 100644--- a/web/src/main/java/com/vayunmathur/web/data/WebRepository.kt+++ b/web/src/main/java/com/vayunmathur/web/data/WebRepository.kt@@ -7,16 +7,32 @@ import com.vayunmathur.library.room.RoomRepository * Single owner of [WebDatabase]. Per-domain stores hang off here so no single * class exceeds the function-count budget; call sites use `repository.<domain>`. */+/**+ * The per-domain stores [com.vayunmathur.web.platform.WebViewModel] reads and writes.+ * Split out from [WebRepository] so view-model and page tests can supply stores backed+ * by an in-memory database instead of the SQLCipher-backed production database (whose+ * AndroidKeyStore key does not exist under Robolectric).+ */+interface WebStores {+ val history: WebHistoryStore+ val bookmarks: WebBookmarkStore+ val permissions: WebSitePermissionStore+ val storage: WebStorageStore+ val downloads: WebDownloadStore+ val installed: WebInstalledSiteStore+ val shields: WebShieldStore+}+ class WebRepository private constructor(context: Context) :- RoomRepository<WebDatabase>(context, WebDatabase::class, DB_NAME) {+ RoomRepository<WebDatabase>(context, WebDatabase::class, DB_NAME), WebStores { - val history = WebHistoryStore(db.historyDao())- val bookmarks = WebBookmarkStore(db.bookmarkDao())- val permissions = WebSitePermissionStore(db.sitePermissionDao())- val storage = WebStorageStore(db.storageInfoDao())- val downloads = WebDownloadStore(db.downloadDao())- val installed = WebInstalledSiteStore(db.installedSiteDao())- val shields = WebShieldStore(db.shieldSettingDao())+ override val history = WebHistoryStore(db.historyDao())+ override val bookmarks = WebBookmarkStore(db.bookmarkDao())+ override val permissions = WebSitePermissionStore(db.sitePermissionDao())+ override val storage = WebStorageStore(db.storageInfoDao())+ override val downloads = WebDownloadStore(db.downloadDao())+ override val installed = WebInstalledSiteStore(db.installedSiteDao())+ override val shields = WebShieldStore(db.shieldSettingDao()) companion object { @Volatile private var instance: WebRepository? = null
web/src/main/java/com/vayunmathur/web/platform/WebViewModel.kt
diff --git a/web/src/main/java/com/vayunmathur/web/platform/WebViewModel.kt b/web/src/main/java/com/vayunmathur/web/platform/WebViewModel.ktindex 0c1fdfa534..497123fea6 100644--- a/web/src/main/java/com/vayunmathur/web/platform/WebViewModel.kt+++ b/web/src/main/java/com/vayunmathur/web/platform/WebViewModel.kt@@ -23,7 +23,7 @@ import com.vayunmathur.web.data.HistoryEntry import com.vayunmathur.web.data.InstalledSite import com.vayunmathur.web.data.SitePermission import com.vayunmathur.web.data.TabThumbnailStore-import com.vayunmathur.web.data.WebRepository+import com.vayunmathur.web.data.WebStores import com.vayunmathur.web.data.ShieldSetting import com.vayunmathur.web.data.StorageInfo import com.vayunmathur.web.domain.ShieldLevel@@ -55,7 +55,7 @@ internal const val P_LOCAL_NETWORK_DENIED = "web_local_network_denied" internal const val P_SEARCH_BAR_BOTTOM = "web_search_bar_bottom" class WebViewModel(- internal val repository: WebRepository,+ internal val repository: WebStores, internal val context: Context, /** Identifies this window's independent tab set; the default window keeps the legacy pref keys. */ private val windowId: String = DEFAULT_WINDOW_ID,