2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/17917: Use View binding in tracking protection(2)

This commit is contained in:
codrut.topliceanu 2021-08-17 13:10:14 +03:00 committed by mergify[bot]
parent c80a53f93e
commit 5e0b094e4f
11 changed files with 141 additions and 124 deletions

View File

@ -7,11 +7,10 @@ package org.mozilla.fenix.exceptions
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.annotation.VisibleForTesting
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.component_exceptions.*
import org.mozilla.fenix.R
import org.mozilla.fenix.databinding.ComponentExceptionsBinding
/**
* View that contains and configures the Exceptions List
@ -19,23 +18,28 @@ import org.mozilla.fenix.R
abstract class ExceptionsView<T : Any>(
container: ViewGroup,
protected val interactor: ExceptionsInteractor<T>
) : LayoutContainer {
) {
override val containerView: FrameLayout = LayoutInflater.from(container.context)
.inflate(R.layout.component_exceptions, container, true)
.findViewById(R.id.exceptions_wrapper)
@VisibleForTesting
internal val binding = ComponentExceptionsBinding.inflate(
LayoutInflater.from(container.context),
container,
true
)
val containerView: FrameLayout = binding.exceptionsWrapper
protected abstract val exceptionsAdapter: ExceptionsAdapter<T>
init {
exceptions_list.apply {
binding.exceptionsList.apply {
layoutManager = LinearLayoutManager(containerView.context)
}
}
fun update(items: List<T>) {
exceptions_empty_view.isVisible = items.isEmpty()
exceptions_list.isVisible = items.isNotEmpty()
binding.exceptionsEmptyView.isVisible = items.isEmpty()
binding.exceptionsList.isVisible = items.isNotEmpty()
exceptionsAdapter.updateData(items)
}
}

View File

@ -6,7 +6,6 @@ package org.mozilla.fenix.exceptions.login
import android.view.ViewGroup
import androidx.core.view.isVisible
import kotlinx.android.synthetic.main.component_exceptions.*
import mozilla.components.feature.logins.exceptions.LoginException
import org.mozilla.fenix.R
import org.mozilla.fenix.exceptions.ExceptionsView
@ -19,10 +18,10 @@ class LoginExceptionsView(
override val exceptionsAdapter = LoginExceptionsAdapter(interactor)
init {
exceptions_learn_more.isVisible = false
exceptions_empty_message.text =
binding.exceptionsLearnMore.isVisible = false
binding.exceptionsEmptyMessage.text =
containerView.context.getString(R.string.preferences_passwords_exceptions_description_empty)
exceptions_list.apply {
binding.exceptionsList.apply {
adapter = exceptionsAdapter
}
}

View File

@ -9,12 +9,12 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.fragment_exceptions.view.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.components.lib.state.ext.consumeFrom
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.databinding.FragmentExceptionsBinding
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.showToolbar
@ -37,8 +37,12 @@ class TrackingProtectionExceptionsFragment : Fragment() {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_exceptions, container, false)
): View {
val binding = FragmentExceptionsBinding.inflate(
inflater,
container,
false
)
exceptionsStore = StoreProvider.get(this) {
ExceptionsFragmentStore(
ExceptionsFragmentState(items = emptyList())
@ -50,11 +54,11 @@ class TrackingProtectionExceptionsFragment : Fragment() {
trackingProtectionUseCases = requireComponents.useCases.trackingProtectionUseCases
)
exceptionsView = TrackingProtectionExceptionsView(
view.exceptionsLayout,
binding.exceptionsLayout,
exceptionsInteractor
)
exceptionsInteractor.reloadExceptions()
return view
return binding.root
}
@ExperimentalCoroutinesApi

View File

@ -6,7 +6,6 @@ package org.mozilla.fenix.exceptions.trackingprotection
import android.text.method.LinkMovementMethod
import android.view.ViewGroup
import kotlinx.android.synthetic.main.component_exceptions.*
import mozilla.components.concept.engine.content.blocking.TrackingProtectionException
import org.mozilla.fenix.exceptions.ExceptionsView
import org.mozilla.fenix.ext.addUnderline
@ -19,11 +18,11 @@ class TrackingProtectionExceptionsView(
override val exceptionsAdapter = TrackingProtectionExceptionsAdapter(interactor)
init {
exceptions_list.apply {
binding.exceptionsList.apply {
adapter = exceptionsAdapter
}
with(exceptions_learn_more) {
with(binding.exceptionsLearnMore) {
addUnderline()
movementMethod = LinkMovementMethod.getInstance()

View File

@ -9,8 +9,8 @@ import android.view.View
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.navArgs
import kotlinx.android.synthetic.main.fragment_tracking_protection_blocking.*
import org.mozilla.fenix.R
import org.mozilla.fenix.databinding.FragmentTrackingProtectionBlockingBinding
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar
@ -23,23 +23,24 @@ class TrackingProtectionBlockingFragment :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val binding = FragmentTrackingProtectionBlockingBinding.bind(view)
when (args.protectionMode) {
TrackingProtectionMode.STANDARD -> {
category_tracking_content.isVisible = false
binding.categoryTrackingContent.isVisible = false
}
TrackingProtectionMode.STRICT -> {}
TrackingProtectionMode.CUSTOM -> {
category_fingerprinters.isVisible =
binding.categoryFingerprinters.isVisible =
settings.blockFingerprintersInCustomTrackingProtection
category_cryptominers.isVisible =
binding.categoryCryptominers.isVisible =
settings.blockCryptominersInCustomTrackingProtection
category_cookies.isVisible =
binding.categoryCookies.isVisible =
settings.blockCookiesInCustomTrackingProtection
category_tracking_content.isVisible =
binding.categoryTrackingContent.isVisible =
settings.blockTrackingContentInCustomTrackingProtection
category_redirect_trackers.isVisible =
binding.categoryRedirectTrackers.isVisible =
settings.blockRedirectTrackersInCustomTrackingProtection
}
}

View File

@ -9,8 +9,8 @@ import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.withStyledAttributes
import kotlinx.android.synthetic.main.tracking_protection_category.view.*
import org.mozilla.fenix.R
import org.mozilla.fenix.databinding.TrackingProtectionCategoryBinding
class TrackingProtectionCategoryItem @JvmOverloads constructor(
context: Context,
@ -18,7 +18,10 @@ class TrackingProtectionCategoryItem @JvmOverloads constructor(
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
init {
LayoutInflater.from(context).inflate(R.layout.tracking_protection_category, this, true)
val binding = TrackingProtectionCategoryBinding.inflate(
LayoutInflater.from(context),
this
)
context.withStyledAttributes(
attrs,
@ -26,13 +29,13 @@ class TrackingProtectionCategoryItem @JvmOverloads constructor(
defStyleAttr,
0
) {
trackingProtectionCategoryTitle?.text = resources.getString(
binding.trackingProtectionCategoryTitle.text = resources.getString(
getResourceId(
R.styleable.TrackingProtectionCategory_categoryItemTitle,
R.string.etp_cookies_title
)
)
trackingProtectionCategoryItemDescription?.text = resources.getString(
binding.trackingProtectionCategoryItemDescription.text = resources.getString(
getResourceId(
R.styleable.TrackingProtectionCategory_categoryItemDescription,
R.string.etp_cookies_description

View File

@ -23,7 +23,6 @@ import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import kotlinx.android.synthetic.main.fragment_tracking_protection.view.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.mapNotNull
@ -42,6 +41,7 @@ import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.databinding.FragmentTrackingProtectionBinding
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.requireComponents
@ -79,7 +79,7 @@ class TrackingProtectionPanelDialogFragment : AppCompatDialogFragment(), UserInt
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {
val store = requireComponents.core.store
val view = inflateRootView(container)
val tab = store.state.findTabOrCustomTab(provideTabId())
@ -106,8 +106,9 @@ class TrackingProtectionPanelDialogFragment : AppCompatDialogFragment(), UserInt
gravity = args.gravity,
getCurrentTab = ::getCurrentTab
)
val binding = FragmentTrackingProtectionBinding.bind(view)
trackingProtectionView =
TrackingProtectionPanelView(view.fragment_tp, trackingProtectionInteractor)
TrackingProtectionPanelView(binding.fragmentTp, trackingProtectionInteractor)
tab?.let { updateTrackers(it) }
return view
}

View File

@ -8,17 +8,17 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.accessibility.AccessibilityEvent
import androidx.annotation.VisibleForTesting
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.AccessibilityDelegateCompat
import androidx.core.view.ViewCompat
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat
import androidx.core.view.isGone
import androidx.core.view.isVisible
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.component_tracking_protection_panel.*
import mozilla.components.browser.state.state.CustomTabSessionState
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.databinding.ComponentTrackingProtectionPanelBinding
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.CROSS_SITE_TRACKING_COOKIES
import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.CRYPTOMINERS
@ -60,13 +60,18 @@ interface TrackingProtectionPanelViewInteractor {
*/
@SuppressWarnings("TooManyFunctions")
class TrackingProtectionPanelView(
override val containerView: ViewGroup,
val containerView: ViewGroup,
val interactor: TrackingProtectionPanelInteractor
) : LayoutContainer, View.OnClickListener {
) : View.OnClickListener {
val view: ConstraintLayout = LayoutInflater.from(containerView.context)
.inflate(R.layout.component_tracking_protection_panel, containerView, true)
.findViewById(R.id.panel_wrapper)
@VisibleForTesting
internal val binding = ComponentTrackingProtectionPanelBinding.inflate(
LayoutInflater.from(containerView.context),
containerView,
true
)
val view: ConstraintLayout = binding.panelWrapper
private var mode: TrackingProtectionState.Mode = TrackingProtectionState.Mode.Normal
@ -75,15 +80,15 @@ class TrackingProtectionPanelView(
private var shouldFocusAccessibilityView: Boolean = true
init {
protection_settings.setOnClickListener {
binding.protectionSettings.setOnClickListener {
interactor.selectTrackingProtectionSettings()
}
details_back.setOnClickListener {
binding.detailsBack.setOnClickListener {
interactor.onExitDetailMode()
}
navigate_back.setOnClickListener {
binding.navigateBack.setOnClickListener {
interactor.onBackPressed()
}
@ -102,16 +107,16 @@ class TrackingProtectionPanelView(
)
}
setAccessibilityViewHierarchy(details_back, category_title)
setAccessibilityViewHierarchy(binding.detailsBack, binding.categoryTitle)
}
private fun setUIForNormalMode(state: TrackingProtectionState) {
details_mode.visibility = View.GONE
normal_mode.visibility = View.VISIBLE
binding.detailsMode.visibility = View.GONE
binding.normalMode.visibility = View.VISIBLE
protection_settings.isGone = state.tab is CustomTabSessionState
not_blocking_header.isGone = bucketedTrackers.loadedIsEmpty()
blocking_header.isGone = bucketedTrackers.blockedIsEmpty()
binding.protectionSettings.isGone = state.tab is CustomTabSessionState
binding.notBlockingHeader.isGone = bucketedTrackers.loadedIsEmpty()
binding.blockingHeader.isGone = bucketedTrackers.blockedIsEmpty()
updateCategoryVisibility()
focusAccessibilityLastUsedCategory(state.lastAccessedCategory)
@ -121,12 +126,12 @@ class TrackingProtectionPanelView(
category: TrackingProtectionCategory,
categoryBlocked: Boolean
) {
normal_mode.visibility = View.GONE
details_mode.visibility = View.VISIBLE
category_title.setText(category.title)
blocking_text_list.text = bucketedTrackers.get(category, categoryBlocked).joinToString("\n")
category_description.setText(category.description)
details_blocking_header.setText(
binding.normalMode.visibility = View.GONE
binding.detailsMode.visibility = View.VISIBLE
binding.categoryTitle.setText(category.title)
binding.blockingTextList.text = bucketedTrackers.get(category, categoryBlocked).joinToString("\n")
binding.categoryDescription.setText(category.description)
binding.detailsBlockingHeader.setText(
if (categoryBlocked) {
R.string.enhanced_tracking_protection_blocked
} else {
@ -134,8 +139,8 @@ class TrackingProtectionPanelView(
}
)
details_back.requestFocus()
details_back.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
binding.detailsBack.requestFocus()
binding.detailsBack.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
}
/**
@ -159,58 +164,59 @@ class TrackingProtectionPanelView(
*/
private fun getLastUsedCategoryView(categoryTitle: String) = when (categoryTitle) {
CROSS_SITE_TRACKING_COOKIES.name -> {
if (cross_site_tracking.isGone) cross_site_tracking_loaded else cross_site_tracking
if (binding.crossSiteTracking.isGone) binding.crossSiteTrackingLoaded else binding.crossSiteTracking
}
SOCIAL_MEDIA_TRACKERS.name -> {
if (social_media_trackers.isGone) social_media_trackers_loaded else social_media_trackers
if (binding.socialMediaTrackers.isGone) binding.socialMediaTrackersLoaded else binding.socialMediaTrackers
}
FINGERPRINTERS.name -> {
if (fingerprinters.isGone) fingerprinters_loaded else fingerprinters
if (binding.fingerprinters.isGone) binding.fingerprintersLoaded else binding.fingerprinters
}
TRACKING_CONTENT.name -> {
if (tracking_content.isGone) tracking_content_loaded else tracking_content
if (binding.trackingContent.isGone) binding.trackingContentLoaded else binding.trackingContent
}
CRYPTOMINERS.name -> {
if (cryptominers.isGone) cryptominers_loaded else cryptominers
if (binding.cryptominers.isGone) binding.cryptominersLoaded else binding.cryptominers
}
REDIRECT_TRACKERS.name -> {
if (redirect_trackers.isGone) redirect_trackers_loaded else redirect_trackers
if (binding.redirectTrackers.isGone) binding.redirectTrackersLoaded else binding.redirectTrackers
}
else -> null
}
private fun updateCategoryVisibility() {
cross_site_tracking.isGone =
binding.crossSiteTracking.isGone =
bucketedTrackers.get(CROSS_SITE_TRACKING_COOKIES, true).isEmpty()
social_media_trackers.isGone =
binding.socialMediaTrackers.isGone =
bucketedTrackers.get(SOCIAL_MEDIA_TRACKERS, true).isEmpty()
fingerprinters.isGone = bucketedTrackers.get(FINGERPRINTERS, true).isEmpty()
tracking_content.isGone = bucketedTrackers.get(TRACKING_CONTENT, true).isEmpty()
cryptominers.isGone = bucketedTrackers.get(CRYPTOMINERS, true).isEmpty()
redirect_trackers.isGone = bucketedTrackers.get(REDIRECT_TRACKERS, true).isEmpty()
binding.fingerprinters.isGone = bucketedTrackers.get(FINGERPRINTERS, true).isEmpty()
binding.trackingContent.isGone = bucketedTrackers.get(TRACKING_CONTENT, true).isEmpty()
binding.cryptominers.isGone = bucketedTrackers.get(CRYPTOMINERS, true).isEmpty()
binding.redirectTrackers.isGone = bucketedTrackers.get(REDIRECT_TRACKERS, true).isEmpty()
cross_site_tracking_loaded.isGone =
binding.crossSiteTrackingLoaded.isGone =
bucketedTrackers.get(CROSS_SITE_TRACKING_COOKIES, false).isEmpty()
social_media_trackers_loaded.isGone =
binding.socialMediaTrackersLoaded.isGone =
bucketedTrackers.get(SOCIAL_MEDIA_TRACKERS, false).isEmpty()
fingerprinters_loaded.isGone = bucketedTrackers.get(FINGERPRINTERS, false).isEmpty()
tracking_content_loaded.isGone = bucketedTrackers.get(TRACKING_CONTENT, false).isEmpty()
cryptominers_loaded.isGone = bucketedTrackers.get(CRYPTOMINERS, false).isEmpty()
redirect_trackers_loaded.isGone = bucketedTrackers.get(REDIRECT_TRACKERS, false).isEmpty()
binding.fingerprintersLoaded.isGone = bucketedTrackers.get(FINGERPRINTERS, false).isEmpty()
binding.trackingContentLoaded.isGone = bucketedTrackers.get(TRACKING_CONTENT, false).isEmpty()
binding.cryptominersLoaded.isGone = bucketedTrackers.get(CRYPTOMINERS, false).isEmpty()
binding.redirectTrackersLoaded.isGone = bucketedTrackers.get(REDIRECT_TRACKERS, false).isEmpty()
}
private fun setCategoryClickListeners() {
social_media_trackers.setOnClickListener(this)
fingerprinters.setOnClickListener(this)
cross_site_tracking.setOnClickListener(this)
tracking_content.setOnClickListener(this)
cryptominers.setOnClickListener(this)
cross_site_tracking_loaded.setOnClickListener(this)
social_media_trackers_loaded.setOnClickListener(this)
fingerprinters_loaded.setOnClickListener(this)
tracking_content_loaded.setOnClickListener(this)
cryptominers_loaded.setOnClickListener(this)
redirect_trackers_loaded.setOnClickListener(this)
binding.socialMediaTrackers.setOnClickListener(this)
binding.fingerprinters.setOnClickListener(this)
binding.crossSiteTracking.setOnClickListener(this)
binding.trackingContent.setOnClickListener(this)
binding.cryptominers.setOnClickListener(this)
binding.crossSiteTrackingLoaded.setOnClickListener(this)
binding.socialMediaTrackersLoaded.setOnClickListener(this)
binding.fingerprintersLoaded.setOnClickListener(this)
binding.trackingContentLoaded.setOnClickListener(this)
binding.cryptominersLoaded.setOnClickListener(this)
binding.redirectTrackersLoaded.setOnClickListener(this)
}
override fun onClick(v: View) {

View File

@ -9,7 +9,6 @@ import android.widget.FrameLayout
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import io.mockk.mockk
import kotlinx.android.synthetic.main.component_exceptions.*
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
@ -40,25 +39,25 @@ class LoginExceptionsViewTest {
fun `sets empty message text`() {
assertEquals(
"Logins and passwords that are not saved will be shown here.",
view.exceptions_empty_message.text
view.binding.exceptionsEmptyMessage.text
)
assertTrue(view.exceptions_list.adapter is LoginExceptionsAdapter)
assertTrue(view.exceptions_list.layoutManager is LinearLayoutManager)
assertTrue(view.binding.exceptionsList.adapter is LoginExceptionsAdapter)
assertTrue(view.binding.exceptionsList.layoutManager is LinearLayoutManager)
}
@Test
fun `hide list when there are no items`() {
view.update(emptyList())
assertTrue(view.exceptions_empty_view.isVisible)
assertFalse(view.exceptions_list.isVisible)
assertTrue(view.binding.exceptionsEmptyView.isVisible)
assertFalse(view.binding.exceptionsList.isVisible)
}
@Test
fun `shows list when there are items`() {
view.update(listOf(mockk()))
assertFalse(view.exceptions_empty_view.isVisible)
assertTrue(view.exceptions_list.isVisible)
assertFalse(view.binding.exceptionsEmptyView.isVisible)
assertTrue(view.binding.exceptionsList.isVisible)
}
}

View File

@ -16,7 +16,6 @@ import io.mockk.mockk
import io.mockk.mockkConstructor
import io.mockk.unmockkConstructor
import io.mockk.verify
import kotlinx.android.synthetic.main.component_exceptions.*
import mozilla.components.concept.engine.content.blocking.TrackingProtectionException
import mozilla.components.support.test.robolectric.testContext
import org.junit.After
@ -26,6 +25,7 @@ import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.databinding.ComponentExceptionsBinding
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
@ -34,6 +34,7 @@ class TrackingProtectionExceptionsViewTest {
private lateinit var container: ViewGroup
private lateinit var interactor: TrackingProtectionExceptionsInteractor
private lateinit var exceptionsView: TrackingProtectionExceptionsView
private lateinit var binding: ComponentExceptionsBinding
@Before
fun setup() {
@ -47,6 +48,7 @@ class TrackingProtectionExceptionsViewTest {
container,
interactor
)
binding = ComponentExceptionsBinding.bind(container)
}
@After
@ -56,12 +58,12 @@ class TrackingProtectionExceptionsViewTest {
@Test
fun `binds exception text`() {
assertTrue(exceptionsView.exceptions_learn_more.movementMethod is LinkMovementMethod)
assertTrue(exceptionsView.exceptions_learn_more.text is Spannable)
assertEquals("Learn more", exceptionsView.exceptions_learn_more.text.toString())
assertTrue(binding.exceptionsLearnMore.movementMethod is LinkMovementMethod)
assertTrue(binding.exceptionsLearnMore.text is Spannable)
assertEquals("Learn more", binding.exceptionsLearnMore.text.toString())
every { interactor.onLearnMore() } just Runs
exceptionsView.exceptions_learn_more.performClick()
binding.exceptionsLearnMore.performClick()
verify { interactor.onLearnMore() }
}
@ -69,8 +71,8 @@ class TrackingProtectionExceptionsViewTest {
fun `binds empty list to adapter`() {
exceptionsView.update(emptyList())
assertTrue(exceptionsView.exceptions_empty_view.isVisible)
assertFalse(exceptionsView.exceptions_list.isVisible)
assertTrue(binding.exceptionsEmptyView.isVisible)
assertFalse(binding.exceptionsList.isVisible)
verify { anyConstructed<TrackingProtectionExceptionsAdapter>().updateData(emptyList()) }
}
@ -80,8 +82,8 @@ class TrackingProtectionExceptionsViewTest {
val items = listOf<TrackingProtectionException>(mockk(), mockk())
exceptionsView.update(items)
assertFalse(exceptionsView.exceptions_empty_view.isVisible)
assertTrue(exceptionsView.exceptions_list.isVisible)
assertFalse(binding.exceptionsEmptyView.isVisible)
assertTrue(binding.exceptionsList.isVisible)
verify { anyConstructed<TrackingProtectionExceptionsAdapter>().updateData(items) }
}
}

View File

@ -9,7 +9,6 @@ import android.widget.FrameLayout
import androidx.core.view.isVisible
import io.mockk.mockk
import io.mockk.verify
import kotlinx.android.synthetic.main.component_tracking_protection_panel.*
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
@ -47,11 +46,11 @@ class TrackingProtectionPanelViewTest {
@Test
fun testNormalModeUi() {
view.update(baseState.copy(mode = TrackingProtectionState.Mode.Normal))
assertFalse(view.details_mode.isVisible)
assertTrue(view.normal_mode.isVisible)
assertTrue(view.protection_settings.isVisible)
assertFalse(view.not_blocking_header.isVisible)
assertFalse(view.blocking_header.isVisible)
assertFalse(view.binding.detailsMode.isVisible)
assertTrue(view.binding.normalMode.isVisible)
assertTrue(view.binding.protectionSettings.isVisible)
assertFalse(view.binding.notBlockingHeader.isVisible)
assertFalse(view.binding.blockingHeader.isVisible)
}
@Test
@ -64,55 +63,55 @@ class TrackingProtectionPanelViewTest {
)
)
)
assertTrue(view.details_mode.isVisible)
assertFalse(view.normal_mode.isVisible)
assertTrue(view.binding.detailsMode.isVisible)
assertFalse(view.binding.normalMode.isVisible)
assertEquals(
testContext.getString(R.string.etp_tracking_content_title),
view.category_title.text
view.binding.categoryTitle.text
)
assertEquals(
testContext.getString(R.string.etp_tracking_content_description),
view.category_description.text
view.binding.categoryDescription.text
)
assertEquals(
testContext.getString(R.string.enhanced_tracking_protection_allowed),
view.details_blocking_header.text
view.binding.detailsBlockingHeader.text
)
}
@Test
fun testProtectionSettings() {
view.protection_settings.performClick()
view.binding.protectionSettings.performClick()
verify { interactor.selectTrackingProtectionSettings() }
}
@Test
fun testExistDetailModed() {
view.details_back.performClick()
view.binding.detailsBack.performClick()
verify { interactor.onExitDetailMode() }
}
@Test
fun testDetailsBack() {
view.navigate_back.performClick()
view.binding.navigateBack.performClick()
verify { interactor.onBackPressed() }
}
@Test
fun testSocialMediaTrackerClick() {
view.social_media_trackers.performClick()
view.binding.socialMediaTrackers.performClick()
verify { interactor.openDetails(SOCIAL_MEDIA_TRACKERS, categoryBlocked = true) }
view.social_media_trackers_loaded.performClick()
view.binding.socialMediaTrackersLoaded.performClick()
verify { interactor.openDetails(SOCIAL_MEDIA_TRACKERS, categoryBlocked = false) }
}
@Test
fun testCrossSiteTrackerClick() {
view.cross_site_tracking.performClick()
view.binding.crossSiteTracking.performClick()
verify { interactor.openDetails(CROSS_SITE_TRACKING_COOKIES, categoryBlocked = true) }
view.cross_site_tracking_loaded.performClick()
view.binding.crossSiteTrackingLoaded.performClick()
verify { interactor.openDetails(CROSS_SITE_TRACKING_COOKIES, categoryBlocked = false) }
}
}