a8e277145d
This is to help prevent test crashes with workspace items out of place when using TestWorkspaceBuilder. Adds ModelTestExtensions to move common methods for clearing Launcher DB. Bug: 296620387 Test: running ReorderWidgets test Flag: none Change-Id: I677b1b8fa09aa13aee43651bf66d28ced410a681
31 lines
1.1 KiB
Kotlin
31 lines
1.1 KiB
Kotlin
package com.android.launcher3.util
|
|
|
|
import com.android.launcher3.LauncherModel
|
|
import com.android.launcher3.model.BgDataModel
|
|
|
|
object ModelTestExtensions {
|
|
/** Clears and reloads Launcher db to cleanup the workspace */
|
|
fun LauncherModel.clearModelDb() {
|
|
// Load the model once so that there is no pending migration:
|
|
loadModelSync()
|
|
TestUtil.runOnExecutorSync(Executors.MODEL_EXECUTOR) {
|
|
modelDbController.run {
|
|
tryMigrateDB()
|
|
createEmptyDB()
|
|
clearEmptyDbFlag()
|
|
}
|
|
}
|
|
// Reload model
|
|
TestUtil.runOnExecutorSync(Executors.MAIN_EXECUTOR) { forceReload() }
|
|
loadModelSync()
|
|
}
|
|
|
|
fun LauncherModel.loadModelSync() {
|
|
val mockCb: BgDataModel.Callbacks = object : BgDataModel.Callbacks {}
|
|
TestUtil.runOnExecutorSync(Executors.MAIN_EXECUTOR) { addCallbacksAndLoad(mockCb) }
|
|
TestUtil.runOnExecutorSync(Executors.MODEL_EXECUTOR) {}
|
|
TestUtil.runOnExecutorSync(Executors.MAIN_EXECUTOR) {}
|
|
TestUtil.runOnExecutorSync(Executors.MAIN_EXECUTOR) { removeCallbacks(mockCb) }
|
|
}
|
|
}
|