Loading src/com/android/documentsui/JobPanelViewModel.kt +0 −18 Original line number Diff line number Diff line Loading @@ -17,19 +17,16 @@ package com.android.documentsui import android.os.Parcelable import android.util.Log import androidx.annotation.VisibleForTesting import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.android.documentsui.base.SharedMinimal.DEBUG import com.android.documentsui.services.JobProgress import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch /** * Manages the UI state for the [JobPanelController]. Loading @@ -40,10 +37,6 @@ import kotlinx.coroutines.launch class JobPanelViewModel(scopeOverride: CoroutineScope? = null) : ViewModel() { companion object { private const val TAG = "JobPanelViewModel" private const val AUTO_DISMISS_DELAY = 3000L @VisibleForTesting var disableAutoDismiss = false } /** Loading Loading @@ -129,17 +122,6 @@ class JobPanelViewModel(scopeOverride: CoroutineScope? = null) : ViewModel() { _currentJobs.merge(jobProgress.id, ProgressViewModel(jobProgress)) { old, new -> ProgressViewModel(new.jobProgress, old.expanded) } if (jobProgress.isFinal && !jobProgress.hasFailures && !pendingRemoves.contains(jobProgress.id)) { if (!disableAutoDismiss) { scope.launch { delay(AUTO_DISMISS_DELAY) dismissProgress(jobProgress.id) pendingRemoves.remove(jobProgress.id) } } } } _currentJobs.entries.removeAll { (id, model) -> !model.jobProgress.isFinal && id !in seen } Loading tests/functional/com/android/documentsui/JobPanelUiTest.kt +0 −14 Original line number Diff line number Diff line Loading @@ -52,10 +52,8 @@ import org.hamcrest.Description import org.hamcrest.Matcher import org.hamcrest.Matchers.allOf import org.hamcrest.Matchers.not import org.junit.After import org.junit.Assert.assertTrue import org.junit.Assume.assumeTrue import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith Loading Loading @@ -110,18 +108,6 @@ class JobPanelUiTest : ActivityTestJunit4<FilesActivity>() { onView(withId(R.id.job_progress_panel_title)).check(matches(isDisplayed())) } @Before fun disableAutoDismiss() { // The auto dismiss behaviour will cause some tests to flake depending on how fast the test // is run, so just disable it. JobPanelViewModel.disableAutoDismiss = true } @After fun reenableAutoDismiss() { JobPanelViewModel.disableAutoDismiss = false } @Test fun testInProgressItems() { onView(withId(R.id.job_progress_toolbar_indicator)).check(doesNotExist()) Loading tests/unit/com/android/documentsui/JobPanelViewModelTest.kt +0 −61 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ import com.android.documentsui.rules.OverrideFlagsRule import com.android.documentsui.services.FileOperationService import com.android.documentsui.services.Job import com.android.documentsui.testing.MutableJobProgress import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.launch import kotlinx.coroutines.test.UnconfinedTestDispatcher Loading Loading @@ -241,66 +240,6 @@ class JobPanelViewModelTest { ) } @Test fun testAutoDismiss() = runTest { val viewModel = JobPanelViewModel(this) val inProgress = MutableJobProgress( id = "in_progress_job", operationType = FileOperationService.OPERATION_COPY, state = Job.STATE_SET_UP, msg = "Job in progress", hasFailures = false, currentBytes = 40, requiredBytes = 100, ) val succeeded = MutableJobProgress( id = "succeeded_job", operationType = FileOperationService.OPERATION_COPY, state = Job.STATE_COMPLETED, msg = "Job succeeded", hasFailures = false, ) val failed = MutableJobProgress( id = "failed_job", operationType = FileOperationService.OPERATION_COPY, state = Job.STATE_COMPLETED, msg = "Job failed", hasFailures = true, ) val start = testScheduler.timeSource.markNow() viewModel.updateProgress(listOf(inProgress, succeeded, failed).toJobProgressList()) testScheduler.advanceTimeBy(2.seconds) assertEquals( listOf(inProgress, succeeded, failed) .withExpandStates(false, false, false), ArrayList(viewModel.currentJobs.values) ) inProgress.state = Job.STATE_CANCELED viewModel.updateProgress(listOf(inProgress).toJobProgressList()) // After three seconds from first update, the succeeded job should auto dismiss. testScheduler.advanceTimeBy(1.seconds) testScheduler.runCurrent() assertEquals( listOf(inProgress, failed) .withExpandStates(false, false), ArrayList(viewModel.currentJobs.values) ) // The previously in progress job should auto dismiss at five seconds. testScheduler.advanceUntilIdle() assertEquals(5.seconds, start.elapsedNow()) assertEquals( listOf(failed).withExpandStates(false), ArrayList(viewModel.currentJobs.values) ) } @OptIn(ExperimentalCoroutinesApi::class) @Test fun testDismissCompleted() = runTest { Loading Loading
src/com/android/documentsui/JobPanelViewModel.kt +0 −18 Original line number Diff line number Diff line Loading @@ -17,19 +17,16 @@ package com.android.documentsui import android.os.Parcelable import android.util.Log import androidx.annotation.VisibleForTesting import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.android.documentsui.base.SharedMinimal.DEBUG import com.android.documentsui.services.JobProgress import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch /** * Manages the UI state for the [JobPanelController]. Loading @@ -40,10 +37,6 @@ import kotlinx.coroutines.launch class JobPanelViewModel(scopeOverride: CoroutineScope? = null) : ViewModel() { companion object { private const val TAG = "JobPanelViewModel" private const val AUTO_DISMISS_DELAY = 3000L @VisibleForTesting var disableAutoDismiss = false } /** Loading Loading @@ -129,17 +122,6 @@ class JobPanelViewModel(scopeOverride: CoroutineScope? = null) : ViewModel() { _currentJobs.merge(jobProgress.id, ProgressViewModel(jobProgress)) { old, new -> ProgressViewModel(new.jobProgress, old.expanded) } if (jobProgress.isFinal && !jobProgress.hasFailures && !pendingRemoves.contains(jobProgress.id)) { if (!disableAutoDismiss) { scope.launch { delay(AUTO_DISMISS_DELAY) dismissProgress(jobProgress.id) pendingRemoves.remove(jobProgress.id) } } } } _currentJobs.entries.removeAll { (id, model) -> !model.jobProgress.isFinal && id !in seen } Loading
tests/functional/com/android/documentsui/JobPanelUiTest.kt +0 −14 Original line number Diff line number Diff line Loading @@ -52,10 +52,8 @@ import org.hamcrest.Description import org.hamcrest.Matcher import org.hamcrest.Matchers.allOf import org.hamcrest.Matchers.not import org.junit.After import org.junit.Assert.assertTrue import org.junit.Assume.assumeTrue import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith Loading Loading @@ -110,18 +108,6 @@ class JobPanelUiTest : ActivityTestJunit4<FilesActivity>() { onView(withId(R.id.job_progress_panel_title)).check(matches(isDisplayed())) } @Before fun disableAutoDismiss() { // The auto dismiss behaviour will cause some tests to flake depending on how fast the test // is run, so just disable it. JobPanelViewModel.disableAutoDismiss = true } @After fun reenableAutoDismiss() { JobPanelViewModel.disableAutoDismiss = false } @Test fun testInProgressItems() { onView(withId(R.id.job_progress_toolbar_indicator)).check(doesNotExist()) Loading
tests/unit/com/android/documentsui/JobPanelViewModelTest.kt +0 −61 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ import com.android.documentsui.rules.OverrideFlagsRule import com.android.documentsui.services.FileOperationService import com.android.documentsui.services.Job import com.android.documentsui.testing.MutableJobProgress import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.launch import kotlinx.coroutines.test.UnconfinedTestDispatcher Loading Loading @@ -241,66 +240,6 @@ class JobPanelViewModelTest { ) } @Test fun testAutoDismiss() = runTest { val viewModel = JobPanelViewModel(this) val inProgress = MutableJobProgress( id = "in_progress_job", operationType = FileOperationService.OPERATION_COPY, state = Job.STATE_SET_UP, msg = "Job in progress", hasFailures = false, currentBytes = 40, requiredBytes = 100, ) val succeeded = MutableJobProgress( id = "succeeded_job", operationType = FileOperationService.OPERATION_COPY, state = Job.STATE_COMPLETED, msg = "Job succeeded", hasFailures = false, ) val failed = MutableJobProgress( id = "failed_job", operationType = FileOperationService.OPERATION_COPY, state = Job.STATE_COMPLETED, msg = "Job failed", hasFailures = true, ) val start = testScheduler.timeSource.markNow() viewModel.updateProgress(listOf(inProgress, succeeded, failed).toJobProgressList()) testScheduler.advanceTimeBy(2.seconds) assertEquals( listOf(inProgress, succeeded, failed) .withExpandStates(false, false, false), ArrayList(viewModel.currentJobs.values) ) inProgress.state = Job.STATE_CANCELED viewModel.updateProgress(listOf(inProgress).toJobProgressList()) // After three seconds from first update, the succeeded job should auto dismiss. testScheduler.advanceTimeBy(1.seconds) testScheduler.runCurrent() assertEquals( listOf(inProgress, failed) .withExpandStates(false, false), ArrayList(viewModel.currentJobs.values) ) // The previously in progress job should auto dismiss at five seconds. testScheduler.advanceUntilIdle() assertEquals(5.seconds, start.elapsedNow()) assertEquals( listOf(failed).withExpandStates(false), ArrayList(viewModel.currentJobs.values) ) } @OptIn(ExperimentalCoroutinesApi::class) @Test fun testDismissCompleted() = runTest { Loading