Bug 1859391 - Update cookie banner settings page to only support private mode.
parent
2cf47b754e
commit
4c9f7f77a6
@ -1,72 +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.ui
|
||||
|
||||
import androidx.core.net.toUri
|
||||
import org.junit.Ignore
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.customannotations.SmokeTest
|
||||
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
|
||||
import org.mozilla.fenix.helpers.TestHelper.exitMenu
|
||||
import org.mozilla.fenix.helpers.TestHelper.restartApp
|
||||
import org.mozilla.fenix.ui.robots.browserScreen
|
||||
import org.mozilla.fenix.ui.robots.homeScreen
|
||||
|
||||
class CookieBannerReductionTest {
|
||||
@get:Rule
|
||||
val activityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides(skipOnboarding = true)
|
||||
|
||||
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1980504
|
||||
// Bug causing flakiness https://bugzilla.mozilla.org/show_bug.cgi?id=1807440
|
||||
@Ignore("Disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1852803")
|
||||
@SmokeTest
|
||||
@Test
|
||||
fun verifyCookieBannerReductionFunctionalityTest() {
|
||||
val webSite = "startsiden.no"
|
||||
|
||||
homeScreen {
|
||||
}.openNavigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(webSite.toUri()) {
|
||||
waitForPageToLoad()
|
||||
verifyCookieBannerExists(exists = true)
|
||||
}.openThreeDotMenu {
|
||||
}.openSettings {
|
||||
verifySettingsOptionSummary("Cookie banner reduction", "Off")
|
||||
}.openCookieBannerReductionSubMenu {
|
||||
verifyCookieBannerView(isCookieBannerReductionChecked = false)
|
||||
clickCookieBannerReductionToggle()
|
||||
verifyCheckedCookieBannerReductionToggle(isCookieBannerReductionChecked = true)
|
||||
}.goBack {
|
||||
verifySettingsOptionSummary("Cookie banner reduction", "On")
|
||||
}
|
||||
|
||||
exitMenu()
|
||||
|
||||
browserScreen {
|
||||
verifyCookieBannerExists(exists = false)
|
||||
}
|
||||
|
||||
restartApp(activityTestRule)
|
||||
|
||||
browserScreen {
|
||||
verifyCookieBannerExists(exists = false)
|
||||
}.openThreeDotMenu {
|
||||
}.openSettings {
|
||||
}.openCookieBannerReductionSubMenu {
|
||||
clickCookieBannerReductionToggle()
|
||||
verifyCheckedCookieBannerReductionToggle(false)
|
||||
}
|
||||
|
||||
exitMenu()
|
||||
|
||||
browserScreen {
|
||||
waitForPageToLoad()
|
||||
}.openThreeDotMenu {
|
||||
}.refreshPage {
|
||||
verifyCookieBannerExists(exists = false)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,47 +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.ui.robots
|
||||
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
|
||||
import org.mozilla.fenix.helpers.MatcherHelper.assertCheckedItemWithResIdExists
|
||||
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
|
||||
import org.mozilla.fenix.helpers.MatcherHelper.checkedItemWithResId
|
||||
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
|
||||
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
|
||||
import org.mozilla.fenix.helpers.TestHelper.mDevice
|
||||
import org.mozilla.fenix.helpers.TestHelper.packageName
|
||||
import org.mozilla.fenix.helpers.click
|
||||
|
||||
/**
|
||||
* Implementation of Robot Pattern for the settings Cookie Banner Reduction sub menu.
|
||||
*/
|
||||
class SettingsSubMenuCookieBannerReductionRobot {
|
||||
fun verifyCookieBannerView(isCookieBannerReductionChecked: Boolean) {
|
||||
assertItemContainingTextExists(cookieBannerOptionTitle, cookieBannerOptionDescription)
|
||||
assertCheckedItemWithResIdExists(checkedCookieBannerOptionToggle(isCookieBannerReductionChecked))
|
||||
}
|
||||
fun clickCookieBannerReductionToggle() = cookieBannerOptionToggle.click()
|
||||
fun verifyCheckedCookieBannerReductionToggle(isCookieBannerReductionChecked: Boolean) =
|
||||
assertCheckedItemWithResIdExists(checkedCookieBannerOptionToggle(isCookieBannerReductionChecked))
|
||||
|
||||
class Transition {
|
||||
fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition {
|
||||
mDevice.pressBack()
|
||||
|
||||
SettingsRobot().interact()
|
||||
return SettingsRobot.Transition()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val cookieBannerOptionTitle =
|
||||
itemContainingText(getStringResource(R.string.reduce_cookie_banner_option))
|
||||
private val cookieBannerOptionDescription =
|
||||
itemContainingText(getStringResource(R.string.reduce_cookie_banner_summary_1))
|
||||
private val cookieBannerOptionToggle =
|
||||
itemWithResId("$packageName:id/learn_more_switch")
|
||||
private fun checkedCookieBannerOptionToggle(isChecked: Boolean = false) =
|
||||
checkedItemWithResId("$packageName:id/learn_more_switch", isChecked)
|
@ -1,62 +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.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.SwitchPreferenceCompat
|
||||
import mozilla.components.concept.engine.Settings
|
||||
import org.mozilla.fenix.GleanMetrics.CookieBanners
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.settings
|
||||
import org.mozilla.fenix.ext.showToolbar
|
||||
|
||||
/**
|
||||
* Lets the user set up the cookie banners handling preferences.
|
||||
*/
|
||||
class CookieBannersFragment : PreferenceFragmentCompat() {
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.cookie_banner_preferences, rootKey)
|
||||
setupPreferences()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
showToolbar(getString(R.string.preferences_cookie_banner_reduction))
|
||||
}
|
||||
|
||||
private fun getEngineSettings(): Settings {
|
||||
return requireContext().components.core.engine.settings
|
||||
}
|
||||
|
||||
private fun setupPreferences() {
|
||||
requirePreference<SwitchPreferenceCompat>(R.string.pref_key_cookie_banner_v1).apply {
|
||||
summary =
|
||||
getString(R.string.reduce_cookie_banner_summary_1, getString(R.string.app_name))
|
||||
onPreferenceChangeListener = object : SharedPreferenceUpdater() {
|
||||
override fun onPreferenceChange(
|
||||
preference: Preference,
|
||||
newValue: Any?,
|
||||
): Boolean {
|
||||
val metricTag = if (newValue == true) {
|
||||
"reject_all"
|
||||
} else {
|
||||
"disabled"
|
||||
}
|
||||
requireContext().settings().shouldUseCookieBanner = newValue as Boolean
|
||||
val mode = requireContext().settings().getCookieBannerHandling()
|
||||
getEngineSettings().cookieBannerHandlingModePrivateBrowsing = mode
|
||||
getEngineSettings().cookieBannerHandlingMode = mode
|
||||
CookieBanners.settingChanged.record(CookieBanners.SettingChangedExtra(metricTag))
|
||||
requireContext().components.useCases.sessionUseCases.reload()
|
||||
return super.onPreferenceChange(preference, newValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +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.settings
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import org.mozilla.fenix.ext.settings
|
||||
|
||||
/**
|
||||
* Cookie banners switch preference with a learn more link.
|
||||
*/
|
||||
class CookieBannersSwitchPreference(context: Context, attrs: AttributeSet?) :
|
||||
LearnMoreSwitchPreference(context, attrs) {
|
||||
|
||||
override fun getLearnMoreUrl(): String {
|
||||
return SupportUtils.getGenericSumoURLForTopic(
|
||||
SupportUtils.SumoTopic.COOKIE_BANNER,
|
||||
)
|
||||
}
|
||||
|
||||
override fun getSwitchValue(): Boolean {
|
||||
return context.settings().shouldUseCookieBanner
|
||||
}
|
||||
}
|
@ -1,83 +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.settings
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.widget.SwitchCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import androidx.preference.SwitchPreferenceCompat
|
||||
import org.mozilla.fenix.BrowserDirection
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.asActivity
|
||||
|
||||
/**
|
||||
* A [SwitchPreferenceCompat] that include a learn more link.
|
||||
*/
|
||||
abstract class LearnMoreSwitchPreference(context: Context, attrs: AttributeSet?) :
|
||||
SwitchPreferenceCompat(context, attrs) {
|
||||
|
||||
init {
|
||||
layoutResource = R.layout.preference_switch_learn_more
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
holder.itemView.isClickable = false
|
||||
val switch = holder.findViewById(R.id.learn_more_switch) as SwitchCompat
|
||||
|
||||
switch.run {
|
||||
isChecked = getSwitchValue()
|
||||
setOnCheckedChangeListener { _, isChecked ->
|
||||
onPreferenceChangeListener?.onPreferenceChange(
|
||||
this@LearnMoreSwitchPreference,
|
||||
isChecked,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
getDescription()?.let {
|
||||
val summaryView = holder.findViewById(android.R.id.summary) as TextView
|
||||
summaryView.text = it
|
||||
summaryView.isVisible = true
|
||||
}
|
||||
|
||||
val learnMoreLink = holder.findViewById(R.id.link) as TextView
|
||||
learnMoreLink.paint?.isUnderlineText = true
|
||||
learnMoreLink.setOnClickListener {
|
||||
it.context.asActivity()?.let { activity ->
|
||||
(activity as HomeActivity).openToBrowserAndLoad(
|
||||
searchTermOrURL = getLearnMoreUrl(),
|
||||
newTab = true,
|
||||
from = BrowserDirection.FromCookieBanner,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val backgroundDrawableArray =
|
||||
context.obtainStyledAttributes(intArrayOf(R.attr.selectableItemBackground))
|
||||
val backgroundDrawable = backgroundDrawableArray.getDrawable(0)
|
||||
backgroundDrawableArray.recycle()
|
||||
learnMoreLink.background = backgroundDrawable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description to be used the UI.
|
||||
*/
|
||||
open fun getDescription(): String? = null
|
||||
|
||||
/**
|
||||
* Returns the URL that should be used when the learn more link is clicked.
|
||||
*/
|
||||
abstract fun getLearnMoreUrl(): String
|
||||
|
||||
/**
|
||||
* Indicates the value which the switch widget should show.
|
||||
*/
|
||||
abstract fun getSwitchValue(): Boolean
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:baselineAligned="false"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Send usage data" />
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="10"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
app:layout_constraintStart_toStartOf="@android:id/title"
|
||||
app:layout_constraintTop_toBottomOf="@android:id/title"
|
||||
tools:text="Mozilla strives to collect only what we need to provide and improve %1$s for everyone." />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/link"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:lineSpacingExtra="1sp"
|
||||
android:paddingBottom="4dp"
|
||||
android:text="@string/studies_learn_more"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
app:layout_constraintStart_toStartOf="@android:id/title"
|
||||
app:layout_constraintTop_toBottomOf="@android:id/summary" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/learn_more_switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:minWidth="58dp"
|
||||
android:minHeight="48dp"
|
||||
android:textColor="@color/state_list_text_color"
|
||||
android:textOff="@string/studies_off"
|
||||
android:textOn="@string/studies_on" />
|
||||
|
||||
</LinearLayout>
|
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!-- 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/. -->
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<org.mozilla.fenix.settings.CookieBannersSwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/pref_key_cookie_banner_v1"
|
||||
android:title="@string/reduce_cookie_banner_option" />
|
||||
</androidx.preference.PreferenceScreen>
|
Loading…
Reference in New Issue