1
0
Fork 0

For 4780: add DefaultBrowsingModeManager tests

master
Severin Rudie 2019-10-07 13:16:17 -07:00 committed by Emily Kager
parent c9e68bda31
commit 411ccc8f1f
6 changed files with 53 additions and 6 deletions

View File

@ -35,7 +35,6 @@ import org.mozilla.fenix.components.Components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.session.NotificationSessionObserver
import org.mozilla.fenix.session.VisibilityLifecycleCallback
import org.mozilla.fenix.utils.Settings
import java.io.File
@SuppressLint("Registered")

View File

@ -4,8 +4,6 @@
package org.mozilla.fenix.browser.browsingmode
import org.mozilla.fenix.utils.Settings
/**
* Enum that represents whether or not private browsing is active.
*/

View File

@ -22,7 +22,6 @@ import mozilla.components.support.utils.ThreadUtils
import org.mozilla.fenix.R
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.application
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.sessionsOfType

View File

@ -15,7 +15,6 @@ import android.util.TypedValue
import android.view.View
import android.view.Window
import androidx.annotation.StyleRes
import mozilla.components.support.utils.toSafeIntent
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.browsingmode.BrowsingMode

View File

@ -22,7 +22,6 @@ import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.Config
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
import org.mozilla.fenix.components.metrics.MozillaProductDetector
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.settings.PhoneFeature

View File

@ -0,0 +1,53 @@
/* 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.browser.browsingmode
import io.mockk.MockKAnnotations
import io.mockk.impl.annotations.MockK
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
class DefaultBrowsingModeManagerTest {
@MockK(relaxed = true) lateinit var callback: (BrowsingMode) -> Unit
lateinit var manager: BrowsingModeManager
private val initMode = BrowsingMode.Normal
@Before
fun before() {
MockKAnnotations.init(this)
manager = DefaultBrowsingModeManager(initMode, callback)
}
@Test
fun `WHEN mode is updated THEN callback is invoked`() {
verify(exactly = 0) { callback.invoke(any()) }
manager.mode = BrowsingMode.Private
manager.mode = BrowsingMode.Private
manager.mode = BrowsingMode.Private
verify(exactly = 3) { callback.invoke(any()) }
manager.mode = BrowsingMode.Normal
manager.mode = BrowsingMode.Normal
verify(exactly = 5) { callback.invoke(any()) }
}
@Test
fun `WHEN mode is updated THEN it should be returned from get`() {
assertEquals(BrowsingMode.Normal, manager.mode)
manager.mode = BrowsingMode.Private
assertEquals(BrowsingMode.Private, manager.mode)
manager.mode = BrowsingMode.Normal
assertEquals(BrowsingMode.Normal, manager.mode)
}
}