[fenix] For https://github.com/mozilla-mobile/fenix/issues/18836: shorten isColdStart... and rm questionable test.

The test failed with the rewrite of the code because it violates
one of our assumptions that only one Activity will be started. However,
since it doesn't rely on observed behavior and we made up the events,
it's value is questionable so it seems okay to remove, especially for
the gain of conciseness in the code.
pull/600/head
Michael Comella 3 years ago committed by Michael Comella
parent 895f8efe13
commit d7ad0bb813

@ -44,20 +44,11 @@ class StartupStateProvider(
return false
}
val firstActivityStartedIndex = startupLog.log.indexOfFirst { it is LogEntry.ActivityStarted }
if (firstActivityStartedIndex < 0) {
return false // if no activities are started, then we haven't started up yet.
}
val firstActivityStartedAndAfter = startupLog.log.subList(firstActivityStartedIndex, startupLog.log.size)
val isFirstActivityStartedStillForegrounded = firstActivityStartedAndAfter == listOf(
val isLastStartedActivityStillStarted = startupLog.log.takeLast(2) == listOf(
LogEntry.ActivityStarted(activityClass),
LogEntry.AppStarted
)
val hasAppBeenStopped = startupLog.log.contains(LogEntry.AppStopped)
return isFirstActivityStartedStillForegrounded && !hasAppBeenStopped
return !startupLog.log.contains(LogEntry.AppStopped) && isLastStartedActivityStillStarted
}
/**

@ -89,42 +89,6 @@ class StartupStateProviderTest {
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)) }
// Since we've never observed this, there are multiple ways the events could
// theoretically be ordered: we try a few.
logEntries.addAll(listOf(
LogEntry.ActivityCreated(irActivityClass),
LogEntry.ActivityStarted(irActivityClass),
LogEntry.AppStarted,
LogEntry.ActivityCreated(homeActivityClass),
LogEntry.ActivityStarted(homeActivityClass)
))
assertIsNotCold()
logEntries.clear()
logEntries.addAll(listOf(
LogEntry.ActivityCreated(irActivityClass),
LogEntry.ActivityStarted(irActivityClass),
LogEntry.ActivityCreated(homeActivityClass),
LogEntry.ActivityStarted(homeActivityClass),
LogEntry.AppStarted
))
assertIsNotCold()
logEntries.clear()
logEntries.addAll(listOf(
LogEntry.ActivityCreated(irActivityClass),
LogEntry.ActivityCreated(homeActivityClass),
LogEntry.ActivityStarted(irActivityClass),
LogEntry.ActivityStarted(homeActivityClass),
LogEntry.AppStarted
))
assertIsNotCold()
}
@Test
fun `GIVEN the app started for an activity WHEN an activity hasn't been created yet THEN start up is not cold`() {
assertFalse(provider.isColdStartForStartedActivity(homeActivityClass))

Loading…
Cancel
Save