Skip to content

Commit

Permalink
Issue mozilla-mobile#10335: Update appcompat and fragment dependencie…
Browse files Browse the repository at this point in the history
…s to 1.3.x.
  • Loading branch information
rocketsroger authored and Grisha Kruglov committed Sep 11, 2021
1 parent 6660d3f commit 019470e
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 13 deletions.
4 changes: 2 additions & 2 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ object Versions {

object AndroidX {
const val annotation = "1.1.0"
const val appcompat = "1.2.0"
const val appcompat = "1.3.0"
const val browser = "1.3.0"
const val biometric = "1.1.0"
const val cardview = "1.0.0"
const val constraintlayout = "2.0.4"
const val coordinatorlayout = "1.1.0"
const val core = "1.3.2"
const val fragment = "1.2.5"
const val fragment = "1.3.4"
const val recyclerview = "1.2.0"
const val test = "1.3.0"
const val test_ext = "1.1.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ internal sealed class PromptContainer {

override val context get() = fragment.requireContext()

@Suppress("DEPRECATION")
// https://github.com/mozilla-mobile/android-components/issues/10357
override fun startActivityForResult(intent: Intent, code: Int) =
fragment.startActivityForResult(intent, code)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class PromptContainerTest {
assertEquals(mockContext, container.context)
}

@Suppress("DEPRECATION")
// https://github.com/mozilla-mobile/android-components/issues/10357
@Test
fun `startActivityForResult must delegate its calls either to an activity or a fragment`() {
val intent: Intent = mock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ package mozilla.components.feature.tabs.toolbar
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import mozilla.components.browser.state.state.CustomTabSessionState
import mozilla.components.browser.state.state.ContentState
import mozilla.components.browser.state.state.BrowserState
Expand All @@ -18,26 +22,40 @@ import mozilla.components.support.test.any
import mozilla.components.support.test.mock
import mozilla.components.support.test.rule.MainCoroutineRule
import mozilla.components.ui.tabcounter.TabCounterMenu
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.never
import org.mockito.Mockito.verify

@RunWith(AndroidJUnit4::class)
@ExperimentalCoroutinesApi
class TabsToolbarFeatureTest {
private val testDispatcher = TestCoroutineDispatcher()

@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)

@Before
fun setup() {
Dispatchers.setMain(testDispatcher)
}

@After
fun teardown() {
Dispatchers.resetMain()
testDispatcher.cleanupTestCoroutines()
}

private val showTabs: () -> Unit = mock()
private val tabCounterMenu: TabCounterMenu = mock()
val toolbar: Toolbar = mock()

private lateinit var tabsToolbarFeature: TabsToolbarFeature
private lateinit var lifecycleOwner: MockedLifecycleOwner

private val testDispatcher = TestCoroutineDispatcher()

@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)

internal class MockedLifecycleOwner(initialState: Lifecycle.State) : LifecycleOwner {
val lifecycleRegistry = LifecycleRegistry(this).apply {
currentState = initialState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ internal class CrashListFragment : Fragment(R.layout.mozac_lib_crash_crashlist)
}

private fun onSelection(url: String) {
(activity!! as AbstractCrashListActivity).onCrashServiceSelected(url)
(requireActivity() as AbstractCrashListActivity).onCrashServiceSelected(url)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import mozilla.components.lib.state.Store
import mozilla.components.lib.state.TestAction
Expand All @@ -23,23 +26,39 @@ import mozilla.components.support.test.argumentCaptor
import mozilla.components.support.test.ext.joinBlocking
import mozilla.components.support.test.mock
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.doNothing
import org.mockito.Mockito.doReturn
import org.mockito.Mockito.verify
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import kotlin.coroutines.CoroutineContext

@RunWith(AndroidJUnit4::class)
@ExperimentalCoroutinesApi
class FragmentKtTest {
private val testDispatcher = TestCoroutineDispatcher()

@get:Rule
val coroutinesTestRule = MainCoroutineRule()
val coroutinesTestRule = MainCoroutineRule(testDispatcher)

@Before
fun setup() {
Dispatchers.setMain(testDispatcher)
}

@After
fun teardown() {
Dispatchers.resetMain()
testDispatcher.cleanupTestCoroutines()
}

@Test
@Synchronized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.cancel
Expand All @@ -19,16 +20,22 @@ import kotlinx.coroutines.channels.consumeEach
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.TestCoroutineScope
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import mozilla.components.lib.state.Store
import mozilla.components.lib.state.TestAction
import mozilla.components.lib.state.TestState
import mozilla.components.lib.state.reducer
import mozilla.components.support.test.ext.joinBlocking
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -37,11 +44,23 @@ import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit

@RunWith(AndroidJUnit4::class)
@ExperimentalCoroutinesApi
class StoreExtensionsKtTest {
private val testDispatcher = TestCoroutineDispatcher()

@ExperimentalCoroutinesApi
@get:Rule
val coroutinesTestRule = MainCoroutineRule()
val coroutinesTestRule = MainCoroutineRule(testDispatcher)

@Before
fun setup() {
Dispatchers.setMain(testDispatcher)
}

@After
fun teardown() {
Dispatchers.resetMain()
testDispatcher.cleanupTestCoroutines()
}

@Test
fun `Observer will not get registered if lifecycle is already destroyed`() {
Expand Down Expand Up @@ -216,7 +235,7 @@ class StoreExtensionsKtTest {

val flow = store.flow(owner)

val job = GlobalScope.launch {
val job = TestCoroutineScope(testDispatcher).launch {
flow.collect { state ->
receivedValue = state.counter
latch.countDown()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package mozilla.components.lib.state.ext

import android.view.View
import androidx.lifecycle.Lifecycle
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.lib.state.Store
import mozilla.components.lib.state.TestAction
import mozilla.components.lib.state.TestState
Expand All @@ -20,15 +22,18 @@ import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.doNothing
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit

@RunWith(AndroidJUnit4::class)
@ExperimentalCoroutinesApi
class ViewKtTest {
private val testDispatcher = TestCoroutineDispatcher()

@get:Rule
val coroutinesTestRule = MainCoroutineRule()
val coroutinesTestRule = MainCoroutineRule(testDispatcher)

@Test
@Synchronized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
),
tabId = sessionId,
onNeedToRequestPermissions = { permissions ->
@Suppress("DEPRECATION") // https://github.com/mozilla-mobile/android-components/issues/10358
requestPermissions(permissions, REQUEST_CODE_DOWNLOAD_PERMISSIONS)
}),
owner = this,
Expand Down Expand Up @@ -163,6 +164,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
customTabId = sessionId,
fragmentManager = parentFragmentManager,
onNeedToRequestPermissions = { permissions ->
@Suppress("DEPRECATION") // https://github.com/mozilla-mobile/android-components/issues/10358
requestPermissions(permissions, REQUEST_CODE_PROMPT_PERMISSIONS)
}),
owner = this,
Expand All @@ -185,6 +187,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
mediaKeySystemAccess = SitePermissionsRules.Action.ASK_TO_ALLOW
),
onNeedToRequestPermissions = { permissions ->
@Suppress("DEPRECATION") // https://github.com/mozilla-mobile/android-components/issues/10358
requestPermissions(permissions, REQUEST_CODE_APP_PERMISSIONS)
},
onShouldShowRequestPermissionRationale = { shouldShowRequestPermissionRationale(it) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ open class MainActivity : AppCompatActivity(), LoginFragment.OnLoginCompleteList
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
when (requestCode) {
REQUEST_CODE_CAMERA_PERMISSIONS -> qrFeature.onPermissionsResult(permissions, grantResults)
else -> super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}
}

Expand Down

0 comments on commit 019470e

Please sign in to comment.