Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for interrupted UI loads #1775

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,30 @@ internal class UiLoadTraceEmitterTest {

@Config(sdk = [Build.VERSION_CODES.UPSIDE_DOWN_CAKE])
@Test
fun `verify cold ui load trace from background in U`() {
fun `verify cold ui load trace from an interrupted opening of another activity in U`() {
verifyOpen(
previousState = PreviousState.FROM_INTERRUPTED_LOAD,
uiLoadType = UiLoadType.COLD,
firePreAndPost = true,
hasRenderEvent = true,
)
}

@Config(sdk = [Build.VERSION_CODES.UPSIDE_DOWN_CAKE])
@Test
fun `verify cold ui load trace from an interrupted opening of the same activity in U`() {
verifyOpen(
lastActivityName = ACTIVITY_NAME,
previousState = PreviousState.FROM_INTERRUPTED_LOAD,
uiLoadType = UiLoadType.COLD,
firePreAndPost = true,
hasRenderEvent = true,
)
}

@Config(sdk = [Build.VERSION_CODES.UPSIDE_DOWN_CAKE])
@Test
fun `verify cold open trace from background in U`() {
verifyOpen(
previousState = PreviousState.FROM_BACKGROUND,
uiLoadType = UiLoadType.COLD,
Expand Down Expand Up @@ -95,6 +118,29 @@ internal class UiLoadTraceEmitterTest {
)
}

@Config(sdk = [Build.VERSION_CODES.LOLLIPOP])
@Test
fun `verify cold ui load trace from an interrupted opening of another activity in L`() {
verifyOpen(
previousState = PreviousState.FROM_INTERRUPTED_LOAD,
uiLoadType = UiLoadType.COLD,
firePreAndPost = false,
hasRenderEvent = false,
)
}

@Config(sdk = [Build.VERSION_CODES.LOLLIPOP])
@Test
fun `verify cold ui load trace from an interrupted opening of the same activity in L`() {
verifyOpen(
lastActivityName = ACTIVITY_NAME,
previousState = PreviousState.FROM_INTERRUPTED_LOAD,
uiLoadType = UiLoadType.COLD,
firePreAndPost = false,
hasRenderEvent = false,
)
}

@Config(sdk = [Build.VERSION_CODES.LOLLIPOP])
@Test
fun `verify cold ui load trace from background in L`() {
Expand Down Expand Up @@ -209,13 +255,14 @@ internal class UiLoadTraceEmitterTest {
val lastActivityExitMs = clock.now()
clock.tick(100L)

// set state of tracker to simulate that at least one activity has been opened
traceEmitter.abandon(lastInstanceId, lastActivityName, lastActivityExitMs)
when (previousState) {
PreviousState.FROM_ACTIVITY -> {
traceEmitter.abandon(lastInstanceId, lastActivityName, lastActivityExitMs)
// do nothing extra
}

PreviousState.FROM_BACKGROUND -> {
traceEmitter.abandon(lastInstanceId, lastActivityName, lastActivityExitMs)
traceEmitter.reset(lastInstanceId)
}

Expand Down Expand Up @@ -273,7 +320,7 @@ internal class UiLoadTraceEmitterTest {
events[LifecycleStage.RENDER] = this
}

val traceStartMs = if (previousState != PreviousState.FROM_BACKGROUND) {
val traceStartMs = if (previousState == PreviousState.FROM_ACTIVITY) {
lastActivityExitMs
} else {
createEvents?.run {
Expand Down
Loading