GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Unverified Commit 6518a604 authored by Stefan Arentz's avatar Stefan Arentz Committed by GitHub
Browse files

For #17655: Do not pass threshold if showTopFrecentSites is false. (#17657) (#17813)

* For #17655: Do not pass threshold if showTopFrecentSites is false.

* For #17655: Add unit tests for getTopSitesConfig.

(cherry picked from commit 8993a0ac

)
Co-authored-by: default avatarMihai Adrian Carare <48995920+mcarare@users.noreply.github.com>
parent d89d8914
......@@ -21,6 +21,7 @@ import android.view.accessibility.AccessibilityEvent
import android.widget.Button
import android.widget.LinearLayout
import android.widget.PopupWindow
import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.content.res.AppCompatResources
import androidx.constraintlayout.widget.ConstraintLayout
......@@ -273,11 +274,12 @@ class HomeFragment : Fragment() {
* Returns a [TopSitesConfig] which specifies how many top sites to display and whether or
* not frequently visited sites should be displayed.
*/
private fun getTopSitesConfig(): TopSitesConfig {
@VisibleForTesting
internal fun getTopSitesConfig(): TopSitesConfig {
val settings = requireContext().settings()
return TopSitesConfig(
settings.topSitesMaxLimit,
FrecencyThresholdOption.SKIP_ONE_TIME_PAGES
if (settings.showTopFrecentSites) FrecencyThresholdOption.SKIP_ONE_TIME_PAGES else null
)
}
......
/* 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 org.mozilla.fenix.home
import android.content.Context
import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.utils.Settings
@ExperimentalCoroutinesApi
@RunWith(FenixRobolectricTestRunner::class)
class HomeFragmentTest {
private lateinit var settings: Settings
private lateinit var context: Context
private lateinit var homeFragment: HomeFragment
@Before
fun setup() {
context = mockk(relaxed = true)
settings = mockk(relaxed = true)
homeFragment = spyk(HomeFragment())
every { homeFragment.context } returns context
every { context.settings() } returns settings
}
@Test
fun `GIVEN showTopFrecentSites is false WHEN getTopSitesConfig is called THEN it returns TopSitesConfig with null frecencyConfig`() {
every { settings.showTopFrecentSites } returns false
every { settings.topSitesMaxLimit } returns 10
val topSitesConfig = homeFragment.getTopSitesConfig()
Assert.assertNull(topSitesConfig.frecencyConfig)
}
@Test
fun `GIVEN showTopFrecentSites is true WHEN getTopSitesConfig is called THEN it returns TopSitesConfig with non-null frecencyConfig`() {
every { context.settings().showTopFrecentSites } returns true
every { settings.topSitesMaxLimit } returns 10
val topSitesConfig = homeFragment.getTopSitesConfig()
Assert.assertNotNull(topSitesConfig.frecencyConfig)
}
@Test
fun `GIVEN a topSitesMaxLimit WHEN getTopSitesConfig is called THEN it returns TopSitesConfig with totalSites = topSitesMaxLimit`() {
val topSitesMaxLimit = 10
every { settings.topSitesMaxLimit } returns topSitesMaxLimit
val topSitesConfig = homeFragment.getTopSitesConfig()
Assert.assertEquals(topSitesMaxLimit, topSitesConfig.totalSites)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment