Issue #20664: Do not consider newly created tabs as inactive
This commit is contained in:
parent
dcd7deffc4
commit
ca51ac6168
|
@ -21,7 +21,7 @@ import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
|
|||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.components.metrics.MetricController
|
||||
import org.mozilla.fenix.home.HomeFragment
|
||||
import org.mozilla.fenix.tabstray.browser.DEFAULT_INACTIVE_DAYS
|
||||
import org.mozilla.fenix.tabstray.browser.DEFAULT_ACTIVE_DAYS
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
interface TabsTrayController {
|
||||
|
@ -67,7 +67,7 @@ interface TabsTrayController {
|
|||
*/
|
||||
fun forceTabsAsInactive(
|
||||
tabs: Collection<Tab>,
|
||||
numOfDays: Long = DEFAULT_INACTIVE_DAYS + 1
|
||||
numOfDays: Long = DEFAULT_ACTIVE_DAYS + 1
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.util.concurrent.TimeUnit
|
|||
/**
|
||||
* The time until which a tab is considered in-active (in days).
|
||||
*/
|
||||
const val DEFAULT_INACTIVE_DAYS = 4L
|
||||
const val DEFAULT_ACTIVE_DAYS = 4L
|
||||
|
||||
class NormalBrowserTrayList @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -31,7 +31,7 @@ class NormalBrowserTrayList @JvmOverloads constructor(
|
|||
/**
|
||||
* The maximum time from when a tab was created or accessed until it is considered "inactive".
|
||||
*/
|
||||
var maxActiveTime = TimeUnit.DAYS.toMillis(DEFAULT_INACTIVE_DAYS)
|
||||
var maxActiveTime = TimeUnit.DAYS.toMillis(DEFAULT_ACTIVE_DAYS)
|
||||
|
||||
private val concatAdapter by lazy { adapter as ConcatAdapter }
|
||||
|
||||
|
|
|
@ -7,8 +7,9 @@ package org.mozilla.fenix.tabstray.ext
|
|||
import mozilla.components.browser.state.state.TabSessionState
|
||||
|
||||
private fun TabSessionState.isActive(maxActiveTime: Long): Boolean {
|
||||
val lastActiveTime = maxOf(lastAccess, createdAt)
|
||||
val now = System.currentTimeMillis()
|
||||
return (now - lastAccess <= maxActiveTime)
|
||||
return (now - lastActiveTime <= maxActiveTime)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
/* 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.tabstray.ext
|
||||
|
||||
import mozilla.components.browser.state.state.createTab
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.tabstray.browser.DEFAULT_ACTIVE_DAYS
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class TabSessionStateKtTest {
|
||||
|
||||
private val maxTime = TimeUnit.DAYS.toMillis(DEFAULT_ACTIVE_DAYS)
|
||||
private var inactiveTimestamp = 0L
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
// Subtracting an extra 10 seconds in case the test runner is loopy.
|
||||
inactiveTimestamp = System.currentTimeMillis() - maxTime - 10_000
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN tab was recently accessed THEN isActive is true`() {
|
||||
val tab = createTab(
|
||||
url = "https://mozilla.org",
|
||||
lastAccess = System.currentTimeMillis(),
|
||||
createdAt = 0
|
||||
)
|
||||
assertTrue(tab.isNormalTabActive(maxTime))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN tab was recently created THEN isActive is true`() {
|
||||
val tab = createTab(
|
||||
url = "https://mozilla.org",
|
||||
lastAccess = 0,
|
||||
createdAt = System.currentTimeMillis()
|
||||
)
|
||||
assertTrue(tab.isNormalTabActive(maxTime))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN tab either was not created or accessed recently THEN isActive is true`() {
|
||||
val tab = createTab(
|
||||
url = "https://mozilla.org",
|
||||
lastAccess = 0,
|
||||
createdAt = inactiveTimestamp
|
||||
)
|
||||
assertFalse(tab.isNormalTabActive(maxTime))
|
||||
|
||||
val tab2 = createTab(
|
||||
url = "https://mozilla.org",
|
||||
lastAccess = inactiveTimestamp,
|
||||
createdAt = 0
|
||||
)
|
||||
assertFalse(tab2.isNormalTabActive(maxTime))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN tab has not been accessed or recently created THEN isActive is false`() {
|
||||
val tab = createTab(
|
||||
url = "https://mozilla.org",
|
||||
lastAccess = inactiveTimestamp,
|
||||
createdAt = inactiveTimestamp
|
||||
)
|
||||
assertFalse(tab.isNormalTabActive(maxTime))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN normal tab is recently used THEN return true`() {
|
||||
val tab = createTab(
|
||||
url = "https://mozilla.org",
|
||||
lastAccess = System.currentTimeMillis(),
|
||||
createdAt = System.currentTimeMillis(),
|
||||
private = false
|
||||
)
|
||||
val test = tab.isNormalTabActive(maxTime)
|
||||
assertTrue(test)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN tabs are private THEN always false`() {
|
||||
val tab = createTab(
|
||||
url = "https://mozilla.org",
|
||||
lastAccess = System.currentTimeMillis(),
|
||||
createdAt = System.currentTimeMillis(),
|
||||
private = true
|
||||
)
|
||||
assertFalse(tab.isNormalTabActive(maxTime))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN inactive tabs are private THEN always false`() {
|
||||
val tab = createTab(
|
||||
url = "https://mozilla.org",
|
||||
lastAccess = inactiveTimestamp,
|
||||
createdAt = inactiveTimestamp,
|
||||
private = true
|
||||
)
|
||||
assertFalse(tab.isNormalTabActive(maxTime))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue