For #18836: refactor test into forEachWarmStartEntries.

upstream-sync
Michael Comella 3 years ago committed by Michael Comella
parent a00fbbb6b3
commit a7f4aac6e8

@ -46,6 +46,13 @@ class StartupStateProviderTest {
}
}
@Test
fun `GIVEN the app started for an activity WHEN warm start THEN cold start is false`() {
forEachWarmStartEntries { index ->
assertFalse(provider.isColdStartForStartedActivity(homeActivityClass))
}
}
@Test
fun `GIVEN the app started for an activity WHEN we launched HA through a drawing IntentRA THEN start up is not cold`() {
// These entries mimic observed behavior for local code changes.
@ -75,19 +82,6 @@ class StartupStateProviderTest {
assertFalse(provider.isColdStartForStartedActivity(homeActivityClass))
}
@Test
fun `GIVEN the app started for an activity and we're truncating the log for optimization WHEN warm start THEN start up is not cold`() {
// These entries are from observed behavior.
logEntries.addAll(listOf(
LogEntry.AppStopped,
LogEntry.ActivityStopped(homeActivityClass),
LogEntry.ActivityCreated(homeActivityClass),
LogEntry.ActivityStarted(homeActivityClass),
LogEntry.AppStarted
))
assertFalse(provider.isColdStartForStartedActivity(homeActivityClass))
}
@Test
fun `GIVEN the app started for an activity and we're truncating the log for optimization WHEN hot start THEN start up is not cold`() {
// These entries are from observed behavior.
@ -100,23 +94,6 @@ class StartupStateProviderTest {
assertFalse(provider.isColdStartForStartedActivity(homeActivityClass))
}
@Test
fun `GIVEN the app started for an activity and we're not truncating the log for optimization WHEN warm start THEN start up is not cold`() {
// While the entries are from observed behavior, this log shouldn't occur in the wild due to
// our log optimizations. However, just in case the behavior changes, we check for it.
logEntries.addAll(listOf(
LogEntry.ActivityCreated(homeActivityClass),
LogEntry.ActivityStarted(homeActivityClass),
LogEntry.AppStarted,
LogEntry.AppStopped,
LogEntry.ActivityStopped(homeActivityClass),
LogEntry.ActivityCreated(homeActivityClass),
LogEntry.ActivityStarted(homeActivityClass),
LogEntry.AppStarted
))
assertFalse(provider.isColdStartForStartedActivity(homeActivityClass))
}
@Test
fun `GIVEN the app started for an activity and we're not truncating the log for optimization WHEN hot start THEN start up is not cold`() {
// This shouldn't occur in the wild due to the optimization but, just in case the behavior changes,
@ -224,6 +201,36 @@ class StartupStateProviderTest {
forEachStartEntry(coldStartEntries, block)
}
private fun forEachWarmStartEntries(block: (index: Int) -> Unit) {
// These entries mimic observed behavior. We test both truncated (i.e. the current behavior
// with the optimization to prevent an infinite log) and untruncated (the behavior without
// such an optimization).
//
// truncated MAIN: open HomeActivity directly.
val warmStartEntries = listOf(listOf(
LogEntry.AppStopped,
LogEntry.ActivityStopped(homeActivityClass),
LogEntry.ActivityCreated(homeActivityClass),
LogEntry.ActivityStarted(homeActivityClass),
LogEntry.AppStarted
// untruncated MAIN: open HomeActivity directly.
), listOf(
LogEntry.ActivityCreated(homeActivityClass),
LogEntry.ActivityStarted(homeActivityClass),
LogEntry.AppStarted,
LogEntry.AppStopped,
LogEntry.ActivityStopped(homeActivityClass),
LogEntry.ActivityCreated(homeActivityClass),
LogEntry.ActivityStarted(homeActivityClass),
LogEntry.AppStarted
))
// TODO: add VIEW.
forEachStartEntry(warmStartEntries, block)
}
private fun forEachStartEntry(entries: List<List<LogEntry>>, block: (index: Int) -> Unit) {
entries.forEachIndexed { index, startEntry ->
logEntries.clear()

Loading…
Cancel
Save