diff --git a/app/src/test/java/org/mozilla/fenix/perf/StartupStateProviderTest.kt b/app/src/test/java/org/mozilla/fenix/perf/StartupStateProviderTest.kt index 26f7fd1aa4..988927d6fa 100644 --- a/app/src/test/java/org/mozilla/fenix/perf/StartupStateProviderTest.kt +++ b/app/src/test/java/org/mozilla/fenix/perf/StartupStateProviderTest.kt @@ -49,7 +49,14 @@ 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)) + assertFalse("$index", provider.isColdStartForStartedActivity(homeActivityClass)) + } + } + + @Test + fun `GIVEN the app started for an activity WHEN hot start THEN cold start is false` () { + forEachHotStartEntries { index -> + assertFalse("$index", provider.isColdStartForStartedActivity(homeActivityClass)) } } @@ -82,34 +89,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 hot start THEN start up is not cold`() { - // These entries are from observed behavior. - logEntries.addAll(listOf( - LogEntry.AppStopped, - LogEntry.ActivityStopped(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, - // we check for it. - logEntries.addAll(listOf( - LogEntry.ActivityCreated(homeActivityClass), - LogEntry.ActivityStarted(homeActivityClass), - LogEntry.AppStarted, - LogEntry.AppStopped, - LogEntry.ActivityStopped(homeActivityClass), - LogEntry.ActivityStarted(homeActivityClass), - LogEntry.AppStarted - )) - assertFalse(provider.isColdStartForStartedActivity(homeActivityClass)) - } - @Test fun `GIVEN the app started for an activity WHEN multiple activities are started but not stopped (maybe impossible) THEN start up is not cold`() { fun assertIsNotCold() { assertFalse(provider.isColdStartForStartedActivity(homeActivityClass)) } @@ -231,6 +210,34 @@ class StartupStateProviderTest { forEachStartEntry(warmStartEntries, block) } + private fun forEachHotStartEntries(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 hotStartEntries = listOf(listOf( + LogEntry.AppStopped, + LogEntry.ActivityStopped(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.ActivityStarted(homeActivityClass), + LogEntry.AppStarted + )) + + // TODO: add VIEW. + + forEachStartEntry(hotStartEntries, block) + } + private fun forEachStartEntry(entries: List>, block: (index: Int) -> Unit) { entries.forEachIndexed { index, startEntry -> logEntries.clear()