forked from mozilla-mobile/android-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For mozilla-mobile#12469 - Cancel previous queries before new suggest…
…ions requests
- Loading branch information
Showing
4 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...test/java/mozilla/components/compose/browser/awesomebar/internal/SuggestionFetcherTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.compose.browser.awesomebar.internal | ||
|
||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.Job | ||
import mozilla.components.concept.awesomebar.AwesomeBar.SuggestionProvider | ||
import mozilla.components.concept.awesomebar.AwesomeBar.SuggestionProviderGroup | ||
import mozilla.components.support.test.any | ||
import mozilla.components.support.test.mock | ||
import mozilla.components.support.test.rule.MainCoroutineRule | ||
import mozilla.components.support.test.rule.runTestOnMain | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.mockito.Mockito.doAnswer | ||
import org.mockito.Mockito.inOrder | ||
import org.mockito.Mockito.spy | ||
|
||
@ExperimentalCoroutinesApi // for runTestOnMain | ||
class SuggestionFetcherTest { | ||
@get:Rule | ||
val coroutinesTestRule = MainCoroutineRule() | ||
|
||
@Test | ||
fun `GIVEN a new fetch request THEN all previous queries are cancelled`() = runTestOnMain { | ||
val provider: SuggestionProvider = mock() | ||
val providerGroup = SuggestionProviderGroup(listOf(provider)) | ||
val fetcher = spy(SuggestionFetcher(listOf(providerGroup), null)) | ||
val previousFetchJob: Job = mock() | ||
fetcher.fetchJob = previousFetchJob | ||
doAnswer {}.`when`(fetcher).fetchFrom(any(), any(), any(), any()) | ||
val orderVerifier = inOrder(previousFetchJob, fetcher) | ||
|
||
fetcher.fetch("test") | ||
|
||
orderVerifier.verify(previousFetchJob)!!.cancel() | ||
orderVerifier.verify(fetcher).fetchFrom(providerGroup, provider, "test", null) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters