2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/24229 - Remove unused MigrationTipProvider

This commit is contained in:
Gabriel Luong 2022-03-11 18:27:34 -05:00 committed by mergify[bot]
parent 3d282cb3b3
commit e7ecd285a6
6 changed files with 9 additions and 349 deletions

View File

@ -1,111 +0,0 @@
/* 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.components.tips.providers
import android.content.Context
import android.content.Intent
import android.net.Uri
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.MozillaProductDetector
import org.mozilla.fenix.components.metrics.MozillaProductDetector.MozillaProducts.FENIX
import org.mozilla.fenix.components.metrics.MozillaProductDetector.MozillaProducts.FENIX_NIGHTLY
import org.mozilla.fenix.components.metrics.MozillaProductDetector.MozillaProducts.FIREFOX_NIGHTLY
import org.mozilla.fenix.components.tips.Tip
import org.mozilla.fenix.components.tips.TipProvider
import org.mozilla.fenix.components.tips.TipType
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.settings.SupportUtils
/**
* Tip explaining to users the migration of Fenix channels
*/
class MigrationTipProvider(private val context: Context) : TipProvider {
override val tip: Tip? =
when (context.packageName) {
FENIX.productName -> firefoxPreviewMovedTip()
FIREFOX_NIGHTLY.productName -> getNightlyMigrationTip()
FENIX_NIGHTLY.productName -> getNightlyMigrationTip()
else -> null
}
override val shouldDisplay: Boolean = context.settings().shouldDisplayFenixMovingTip()
private fun firefoxPreviewMovedTip(): Tip =
Tip(
type = TipType.Button(
text = context.getString(R.string.tip_firefox_preview_moved_button_2),
action = ::getFirefoxMovedButtonAction
),
identifier = getIdentifier(),
title = context.getString(R.string.tip_firefox_preview_moved_header),
description = context.getString(R.string.tip_firefox_preview_moved_description),
learnMoreURL = SupportUtils.getGenericSumoURLForTopic(SupportUtils.SumoTopic.FENIX_MOVING)
)
private fun firefoxPreviewMovedPreviewInstalledTip(): Tip =
Tip(
type = TipType.Button(
text = context.getString(R.string.tip_firefox_preview_moved_button_preview_installed),
action = ::getFirefoxMovedButtonAction
),
identifier = getIdentifier(),
title = context.getString(R.string.tip_firefox_preview_moved_header_preview_installed),
description = context.getString(R.string.tip_firefox_preview_moved_description_preview_installed),
learnMoreURL = SupportUtils.getGenericSumoURLForTopic(SupportUtils.SumoTopic.FENIX_MOVING)
)
private fun firefoxPreviewMovedPreviewNotInstalledTip(): Tip =
Tip(
type = TipType.Button(
text = context.getString(R.string.tip_firefox_preview_moved_button_preview_not_installed),
action = ::getFirefoxMovedButtonAction
),
identifier = getIdentifier(),
title = context.getString(R.string.tip_firefox_preview_moved_header_preview_not_installed),
description = context.getString(R.string.tip_firefox_preview_moved_description_preview_not_installed),
learnMoreURL = SupportUtils.getGenericSumoURLForTopic(SupportUtils.SumoTopic.FENIX_MOVING)
)
private fun getNightlyMigrationTip(): Tip? {
return if (MozillaProductDetector.packageIsInstalled(context, FENIX.productName)) {
firefoxPreviewMovedPreviewInstalledTip()
} else {
firefoxPreviewMovedPreviewNotInstalledTip()
}
}
private fun getFirefoxMovedButtonAction() {
when (context.packageName) {
FENIX.productName -> context.startActivity(
Intent(Intent.ACTION_VIEW, Uri.parse(SupportUtils.FIREFOX_BETA_PLAY_STORE_URL))
)
FIREFOX_NIGHTLY.productName -> getNightlyMigrationAction()
FENIX_NIGHTLY.productName -> getNightlyMigrationAction()
else -> { }
}
}
private fun getNightlyMigrationAction() {
return if (MozillaProductDetector.packageIsInstalled(context, FENIX.productName)) {
context.startActivity(context.packageManager.getLaunchIntentForPackage(FENIX.productName))
} else {
context.startActivity(
Intent(
Intent.ACTION_VIEW, Uri.parse(SupportUtils.FIREFOX_NIGHTLY_PLAY_STORE_URL)
)
)
}
}
private fun getIdentifier(): String {
return when (context.packageName) {
FENIX.productName -> context.getString(R.string.pref_key_migrating_from_fenix_tip)
FIREFOX_NIGHTLY.productName -> context.getString(R.string.pref_key_migrating_from_firefox_nightly_tip)
FENIX_NIGHTLY.productName -> context.getString(R.string.pref_key_migrating_from_fenix_nightly_tip)
else -> { "" }
}
}
}

View File

@ -24,8 +24,6 @@ object SupportUtils {
const val POCKET_TRENDING_URL = "https://getpocket.com/fenix-top-articles"
const val WIKIPEDIA_URL = "https://www.wikipedia.org/"
const val FENIX_PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=${BuildConfig.APPLICATION_ID}"
const val FIREFOX_BETA_PLAY_STORE_URL = "market://details?id=org.mozilla.firefox_beta"
const val FIREFOX_NIGHTLY_PLAY_STORE_URL = "market://details?id=org.mozilla.fenix"
const val GOOGLE_URL = "https://www.google.com/"
const val BAIDU_URL = "https://m.baidu.com/?from=1000969a"
const val JD_URL = "https://union-click.jd.com/jdc" +
@ -40,7 +38,6 @@ object SupportUtils {
const val GOOGLE_XX_URL = "https://www.google.com/webhp?client=firefox-b-m&channel=ts"
enum class SumoTopic(internal val topicStr: String) {
FENIX_MOVING("sync-delist"),
HELP("faq-android"),
PRIVATE_BROWSING_MYTHS("common-myths-about-private-browsing"),
YOUR_RIGHTS("your-rights"),

View File

@ -214,21 +214,6 @@ class Settings(private val appContext: Context) : PreferencesHolder {
false
)
// If any of the prefs have been modified, quit displaying the fenix moved tip
fun shouldDisplayFenixMovingTip(): Boolean =
preferences.getBoolean(
appContext.getString(R.string.pref_key_migrating_from_fenix_nightly_tip),
true
) &&
preferences.getBoolean(
appContext.getString(R.string.pref_key_migrating_from_firefox_nightly_tip),
true
) &&
preferences.getBoolean(
appContext.getString(R.string.pref_key_migrating_from_fenix_tip),
true
)
var defaultSearchEngineName by stringPreference(
appContext.getPreferenceKey(R.string.pref_key_search_engine),
default = ""

View File

@ -226,9 +226,6 @@
<!-- A value of `true` means the jump back in onboarding popup has not been shown yet -->
<string name="pref_key_should_show_jump_back_in_tabs_popup" translatable="false">pref_key_should_show_jump_back_in_tabs_popup</string>
<string name="pref_key_migrating_from_fenix_nightly_tip" translatable="false">pref_key_migrating_from_fenix_nightly_tip</string>
<string name="pref_key_migrating_from_firefox_nightly_tip" translatable="false">pref_key_migrating_from_firefox_nightly_tip</string>
<string name="pref_key_migrating_from_fenix_tip" translatable="false">pref_key_migrating_from_fenix_tip</string>
<string name="pref_key_master_password_tip" translatable="false">pref_key_master_password_tip</string>
<string name="pref_key_debug_settings" translatable="false">pref_key_debug_settings</string>

View File

@ -1114,31 +1114,31 @@
<!-- Tips -->
<!-- text for firefox preview moving tip header "Firefox Preview" and "Firefox Nightly" are intentionally hardcoded -->
<string name="tip_firefox_preview_moved_header">Firefox Preview is now Firefox Nightly</string>
<string name="tip_firefox_preview_moved_header" moz:RemovedIn="100" tools:ignore="UnusedResources">Firefox Preview is now Firefox Nightly</string>
<!-- text for firefox preview moving tip description -->
<string name="tip_firefox_preview_moved_description">
<string name="tip_firefox_preview_moved_description" moz:RemovedIn="100" tools:ignore="UnusedResources">
Firefox Nightly gets updated every night and has experimental new features.
However, it may be less stable. Download our beta browser for a more stable experience.</string>
<!-- text for firefox preview moving tip button. "Firefox for Android Beta" is intentionally hardcoded -->
<string name="tip_firefox_preview_moved_button_2">Get Firefox for Android Beta</string>
<string name="tip_firefox_preview_moved_button_2" moz:RemovedIn="100" tools:ignore="UnusedResources">Get Firefox for Android Beta</string>
<!-- text for firefox preview moving tip header. "Firefox Nightly" is intentionally hardcoded -->
<string name="tip_firefox_preview_moved_header_preview_installed">Firefox Nightly has moved</string>
<string name="tip_firefox_preview_moved_header_preview_installed" moz:RemovedIn="100" tools:ignore="UnusedResources">Firefox Nightly has moved</string>
<!-- text for firefox preview moving tip description -->
<string name="tip_firefox_preview_moved_description_preview_installed">
<string name="tip_firefox_preview_moved_description_preview_installed" moz:RemovedIn="100" tools:ignore="UnusedResources">
This app will no longer receive security updates. Stop using this app and switch to the new Nightly.
\n\nTo transfer your bookmarks, logins, and history to another app, create a Firefox account.</string>
<!-- text for firefox preview moving tip button -->
<string name="tip_firefox_preview_moved_button_preview_installed">Switch to the new Nightly</string>
<string name="tip_firefox_preview_moved_button_preview_installed" moz:RemovedIn="100" tools:ignore="UnusedResources">Switch to the new Nightly</string>
<!-- text for firefox preview moving tip header. "Firefox Nightly" is intentionally hardcoded -->
<string name="tip_firefox_preview_moved_header_preview_not_installed">Firefox Nightly has moved</string>
<string name="tip_firefox_preview_moved_header_preview_not_installed" moz:RemovedIn="100" tools:ignore="UnusedResources">Firefox Nightly has moved</string>
<!-- text for firefox preview moving tip description -->
<string name="tip_firefox_preview_moved_description_preview_not_installed">
<string name="tip_firefox_preview_moved_description_preview_not_installed" moz:RemovedIn="100" tools:ignore="UnusedResources">
This app will no longer receive security updates. Get the new Nightly and stop using this app.
\n\nTo transfer your bookmarks, logins, and history to another app, create a Firefox account.</string>
<!-- text for firefox preview moving tip button -->
<string name="tip_firefox_preview_moved_button_preview_not_installed">Get the new Nightly</string>
<string name="tip_firefox_preview_moved_button_preview_not_installed" moz:RemovedIn="100" tools:ignore="UnusedResources">Get the new Nightly</string>
<!-- Onboarding -->
<!-- Text for onboarding welcome message

View File

@ -1,208 +0,0 @@
/* 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.components.tips.providers
import android.content.Context
import android.content.Intent
import android.content.Intent.ACTION_VIEW
import androidx.core.net.toUri
import io.mockk.Runs
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.mockkStatic
import io.mockk.spyk
import io.mockk.unmockkObject
import io.mockk.unmockkStatic
import io.mockk.verify
import mozilla.components.support.test.robolectric.testContext
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.MozillaProductDetector
import org.mozilla.fenix.components.metrics.MozillaProductDetector.MozillaProducts
import org.mozilla.fenix.components.tips.TipType
import org.mozilla.fenix.ext.intentFilterEq
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.utils.Settings
@RunWith(FenixRobolectricTestRunner::class)
class MigrationTipProviderTest {
private lateinit var context: Context
private lateinit var settings: Settings
@Before
fun setup() {
mockkStatic("org.mozilla.fenix.ext.ContextKt")
mockkObject(MozillaProductDetector)
context = spyk(testContext)
settings = mockk()
every { context.settings() } returns settings
every { context.startActivity(any()) } just Runs
every { settings.shouldDisplayFenixMovingTip() } returns true
}
@After
fun after() {
unmockkStatic("org.mozilla.fenix.ext.ContextKt")
unmockkObject(MozillaProductDetector)
}
@Test
fun `test FENIX tip`() {
every { context.packageName } returns MozillaProducts.FENIX.productName
val provider = MigrationTipProvider(context)
val tip = provider.tip!!
val button = tip.type as TipType.Button
assertEquals(
context.getString(R.string.tip_firefox_preview_moved_button_2),
button.text
)
assertEquals(
context.getString(R.string.pref_key_migrating_from_fenix_tip),
tip.identifier
)
assertEquals(
context.getString(R.string.tip_firefox_preview_moved_header),
tip.title
)
button.action()
verify { context.startActivity(intentFilterEq(Intent(ACTION_VIEW, SupportUtils.FIREFOX_BETA_PLAY_STORE_URL.toUri()))) }
}
@Test
fun `test FIREFOX_NIGHTLY fenix installed tip`() {
val launchIntent = mockk<Intent>()
every { context.packageName } returns MozillaProducts.FIREFOX_NIGHTLY.productName
every { context.packageManager.getLaunchIntentForPackage(MozillaProducts.FENIX.productName) } returns launchIntent
every { MozillaProductDetector.packageIsInstalled(context, MozillaProducts.FENIX.productName) } returns true
val provider = MigrationTipProvider(context)
val tip = provider.tip!!
val button = tip.type as TipType.Button
assertEquals(
context.getString(R.string.tip_firefox_preview_moved_button_preview_installed),
button.text
)
assertEquals(
context.getString(R.string.pref_key_migrating_from_firefox_nightly_tip),
tip.identifier
)
assertEquals(
context.getString(R.string.tip_firefox_preview_moved_header_preview_installed),
tip.title
)
button.action()
verify { context.startActivity(launchIntent) }
}
@Test
fun `test FIREFOX_NIGHTLY fenix not installed tip`() {
every { context.packageName } returns MozillaProducts.FIREFOX_NIGHTLY.productName
every { MozillaProductDetector.packageIsInstalled(context, MozillaProducts.FENIX.productName) } returns false
val provider = MigrationTipProvider(context)
val tip = provider.tip!!
val button = tip.type as TipType.Button
assertEquals(
context.getString(R.string.tip_firefox_preview_moved_button_preview_not_installed),
button.text
)
assertEquals(
context.getString(R.string.pref_key_migrating_from_firefox_nightly_tip),
tip.identifier
)
assertEquals(
context.getString(R.string.tip_firefox_preview_moved_header_preview_not_installed),
tip.title
)
button.action()
verify { context.startActivity(intentFilterEq(Intent(ACTION_VIEW, SupportUtils.FIREFOX_NIGHTLY_PLAY_STORE_URL.toUri()))) }
}
@Test
fun `test FENIX_NIGHTLY fenix installed tip`() {
val launchIntent = mockk<Intent>()
every { context.packageName } returns MozillaProducts.FENIX_NIGHTLY.productName
every { context.packageManager.getLaunchIntentForPackage(MozillaProducts.FENIX.productName) } returns launchIntent
every { MozillaProductDetector.packageIsInstalled(context, MozillaProducts.FENIX.productName) } returns true
val provider = MigrationTipProvider(context)
val tip = provider.tip!!
val button = tip.type as TipType.Button
assertEquals(
context.getString(R.string.tip_firefox_preview_moved_button_preview_installed),
button.text
)
assertEquals(
context.getString(R.string.pref_key_migrating_from_fenix_nightly_tip),
tip.identifier
)
assertEquals(
context.getString(R.string.tip_firefox_preview_moved_header_preview_installed),
tip.title
)
button.action()
verify { context.startActivity(launchIntent) }
}
@Test
fun `test FENIX_NIGHTLY fenix not installed tip`() {
every { context.packageName } returns MozillaProducts.FENIX_NIGHTLY.productName
every { MozillaProductDetector.packageIsInstalled(context, MozillaProducts.FENIX.productName) } returns false
val provider = MigrationTipProvider(context)
val tip = provider.tip!!
val button = tip.type as TipType.Button
assertEquals(
context.getString(R.string.tip_firefox_preview_moved_button_preview_not_installed),
button.text
)
assertEquals(
context.getString(R.string.pref_key_migrating_from_fenix_nightly_tip),
tip.identifier
)
assertEquals(
context.getString(R.string.tip_firefox_preview_moved_header_preview_not_installed),
tip.title
)
button.action()
verify { context.startActivity(intentFilterEq(Intent(ACTION_VIEW, SupportUtils.FIREFOX_NIGHTLY_PLAY_STORE_URL.toUri()))) }
}
@Test
fun `test other tip`() {
every { context.packageName } returns ""
val provider = MigrationTipProvider(context)
assertNull(provider.tip)
}
@Test
fun `test shouldDisplay`() {
every { settings.shouldDisplayFenixMovingTip() } returns false
assertFalse(MigrationTipProvider(context).shouldDisplay)
every { settings.shouldDisplayFenixMovingTip() } returns true
assertTrue(MigrationTipProvider(context).shouldDisplay)
}
}