Unverified Commit d5cb9c59 authored by ekager's avatar ekager Committed by GitHub
Browse files

For #15910 - Adds back automatic toggle, disables slider when enabled (#16070)

parent dbe6dbb1
......@@ -10,9 +10,9 @@ import androidx.test.uiautomator.UiDevice
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.Ignore
import org.mozilla.fenix.FenixApplication
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
......@@ -85,7 +85,7 @@ class SettingsBasicsTest {
verifyThemes()
}.goBack {
}.openAccessibilitySubMenu {
verifyMenuItems()
verifyAutomaticFontSizingMenuItems()
}.goBack {
// drill down to submenu
}
......@@ -181,7 +181,7 @@ class SettingsBasicsTest {
}
@Test
fun changeAccessibilitySettings() {
fun changeAccessibiltySettings() {
// Goes through the settings and changes the default text on a webpage, then verifies if the text has changed.
val fenixApp = activityIntentTestRule.activity.applicationContext as FenixApplication
val webpage = getLoremIpsumAsset(mockWebServer).url
......@@ -193,7 +193,8 @@ class SettingsBasicsTest {
}.openThreeDotMenu {
}.openSettings {
}.openAccessibilitySubMenu {
verifyMenuItems()
clickFontSizingSwitch()
verifyEnabledMenuItems()
changeTextSizeSlider(textSizePercentage)
verifyTextSizePercentage(textSizePercentage)
}.goBack {
......@@ -201,6 +202,14 @@ class SettingsBasicsTest {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(webpage) {
checkTextSizeOnWebsite(textSizePercentage, fenixApp.components)
}.openTabDrawer {
}.openNewTab {
}.dismiss {
}.openThreeDotMenu {
}.openSettings {
}.openAccessibilitySubMenu {
clickFontSizingSwitch()
verifyMenuItemsAreDisabled()
}
}
......
......@@ -6,30 +6,32 @@
package org.mozilla.fenix.ui.robots
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import android.view.KeyEvent
import android.view.KeyEvent.KEYCODE_DPAD_RIGHT
import android.view.KeyEvent.KEYCODE_DPAD_LEFT
import android.view.KeyEvent.ACTION_DOWN
import android.view.KeyEvent.KEYCODE_DPAD_LEFT
import android.view.KeyEvent.KEYCODE_DPAD_RIGHT
import android.view.View
import android.widget.SeekBar
import android.widget.TextView
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
import androidx.test.espresso.ViewAssertion
import org.hamcrest.CoreMatchers.allOf
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.Matcher
import org.mozilla.fenix.components.Components
import org.mozilla.fenix.helpers.assertIsEnabled
import org.mozilla.fenix.helpers.isEnabled
import org.mozilla.fenix.ui.robots.SettingsSubMenuAccessibilityRobot.Companion.DECIMAL_CONVERSION
import org.mozilla.fenix.ui.robots.SettingsSubMenuAccessibilityRobot.Companion.MIN_VALUE
import org.mozilla.fenix.ui.robots.SettingsSubMenuAccessibilityRobot.Companion.STEP_SIZE
......@@ -48,7 +50,13 @@ class SettingsSubMenuAccessibilityRobot {
const val TEXT_SIZE = 16f
}
fun verifyMenuItems() = assertMenuItems()
fun verifyAutomaticFontSizingMenuItems() = assertAutomaticFontSizingMenuItems()
fun clickFontSizingSwitch() = toggleFontSizingSwitch()
fun verifyEnabledMenuItems() = assertEnabledMenuItems()
fun verifyMenuItemsAreDisabled() = assertMenuItemsAreDisabled()
fun changeTextSizeSlider(seekBarPercentage: Int) = adjustTextSizeSlider(seekBarPercentage)
......@@ -69,7 +77,22 @@ class SettingsSubMenuAccessibilityRobot {
val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
private fun assertMenuItems() {
private fun assertAutomaticFontSizingMenuItems() {
onView(withText("Automatic font sizing"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
val strFont = "Font size will match your Android settings. Disable to manage font size here."
onView(withText(strFont))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}
private fun toggleFontSizingSwitch() {
// Toggle font size to off
onView(withText("Automatic font sizing"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.perform(click())
}
private fun assertEnabledMenuItems() {
assertFontSize()
assertSliderBar()
}
......@@ -77,9 +100,11 @@ private fun assertMenuItems() {
private fun assertFontSize() {
val view = onView(withText("Font Size"))
view.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.check(matches(isEnabled(true)))
val strFont = "Make text on websites larger or smaller"
onView(withText(strFont))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.check(matches(isEnabled(true)))
}
private fun assertSliderBar() {
......@@ -103,6 +128,20 @@ private fun assertTextSizePercentage(textSize: Int) {
.check(textSizePercentageEquals(textSize))
}
private fun assertMenuItemsAreDisabled() {
onView(withText("Font Size")).assertIsEnabled(false)
val strFont = "Make text on websites larger or smaller"
onView(withText(strFont)).assertIsEnabled(false)
onView(withId(org.mozilla.fenix.R.id.sampleText)).assertIsEnabled(false)
onView(withId(org.mozilla.fenix.R.id.seekbar_value)).assertIsEnabled(false)
onView(withId(org.mozilla.fenix.R.id.seekbar)).assertIsEnabled(false)
}
private fun goBackButton() =
onView(allOf(withContentDescription("Navigate up")))
......
......@@ -47,7 +47,7 @@ object GeckoProvider {
.build()
val settings = context.components.settings
if (!settings.shouldUseAutoSize()) {
if (!settings.shouldUseAutoSize) {
runtimeSettings.automaticFontSizeAdjustment = false
val fontSize = settings.fontSizeFactor
runtimeSettings.fontSizeFactor = fontSize
......
......@@ -47,7 +47,7 @@ object GeckoProvider {
.build()
val settings = context.components.settings
if (!settings.shouldUseAutoSize()) {
if (!settings.shouldUseAutoSize) {
runtimeSettings.automaticFontSizeAdjustment = false
val fontSize = settings.fontSizeFactor
runtimeSettings.fontSizeFactor = fontSize
......
......@@ -57,7 +57,7 @@ object GeckoProvider {
.build()
val settings = context.components.settings
if (!settings.shouldUseAutoSize()) {
if (!settings.shouldUseAutoSize) {
runtimeSettings.automaticFontSizeAdjustment = false
val fontSize = settings.fontSizeFactor
runtimeSettings.fontSizeFactor = fontSize
......
......@@ -97,8 +97,8 @@ class Core(
trackingProtectionPolicy = trackingProtectionPolicyFactory.createTrackingProtectionPolicy(),
historyTrackingDelegate = HistoryDelegate(lazyHistoryStorage),
preferredColorScheme = getPreferredColorScheme(),
automaticFontSizeAdjustment = context.settings().shouldUseAutoSize(),
fontInflationEnabled = context.settings().shouldUseAutoSize(),
automaticFontSizeAdjustment = context.settings().shouldUseAutoSize,
fontInflationEnabled = context.settings().shouldUseAutoSize,
suspendMediaWhenInactive = false,
forceUserScalableContent = context.settings().forceEnableZoom,
loginAutofillEnabled = context.settings().shouldAutofillLogins
......
......@@ -48,18 +48,35 @@ class AccessibilityFragment : PreferenceFragmentCompat() {
val newTextScale =
((newTextSize * STEP_SIZE) + MIN_SCALE_VALUE).toFloat() / PERCENT_TO_DECIMAL
// Save new text scale value. We assume auto sizing is off if this change listener was called.
settings.fontSizeFactor = newTextScale
components.core.engine.settings.fontSizeFactor = newTextScale
// If scale is 100%, use the automatic font size adjustment
val useAutoSize = newTextScale == 1F
// Reload the current session to reflect the new text scale
components.useCases.sessionUseCases.reload()
true
}
textSizePreference.isEnabled = !requireContext().settings().shouldUseAutoSize
val useAutoSizePreference =
requirePreference<SwitchPreference>(R.string.pref_key_accessibility_auto_size)
useAutoSizePreference.setOnPreferenceChangeListener<Boolean> { preference, useAutoSize ->
val settings = preference.context.settings()
val components = preference.context.components
// Save the new setting value
settings.shouldUseAutoSize = useAutoSize
components.core.engine.settings.automaticFontSizeAdjustment = useAutoSize
components.core.engine.settings.fontInflationEnabled = useAutoSize
// If using manual sizing, update the engine settings with the new scale
// If using manual sizing, update the engine settings with the local saved setting
if (!useAutoSize) {
components.core.engine.settings.fontSizeFactor = newTextScale
components.core.engine.settings.fontSizeFactor = settings.fontSizeFactor
}
// Enable the manual sizing controls if automatic sizing is turned off.
textSizePreference.isEnabled = !useAutoSize
// Reload the current session to reflect the new text scale
components.useCases.sessionUseCases.reload()
true
......
......@@ -67,30 +67,37 @@ class TextPercentageSeekBarPreference @JvmOverloads constructor(
) : Preference(context, attrs, defStyleAttr, defStyleRes) {
/* synthetic access */
internal var mSeekBarValue: Int = 0
/* synthetic access */
internal var mMin: Int = 0
private var mMax: Int = 0
private var mSeekBarIncrement: Int = 0
/* synthetic access */
internal var mTrackingTouch: Boolean = false
/* synthetic access */
internal var mSeekBar: SeekBar? = null
private var mSeekBarValueTextView: TextView? = null
private var mExampleTextTextView: TextView? = null
/**
* Whether the SeekBar should respond to the left/right keys
*/
/* synthetic access */
var isAdjustable: Boolean = false
/**
* Whether to show the SeekBar value TextView next to the bar
*/
private var mShowSeekBarValue: Boolean = false
/**
* Whether the SeekBarPreference should continuously save the Seekbar value while it is being dragged.
*/
/* synthetic access */
var updatesContinuously: Boolean = false
/**
* Listener reacting to the [SeekBar] changing value by the user
*/
......@@ -273,6 +280,8 @@ class TextPercentageSeekBarPreference @JvmOverloads constructor(
updateExampleTextValue(mSeekBarValue)
updateLabelValue(mSeekBarValue)
mSeekBar?.isEnabled = isEnabled
mSeekBarValueTextView?.alpha = if (isEnabled) 1F else HALF_ALPHA
mExampleTextTextView?.alpha = if (isEnabled) 1F else HALF_ALPHA
mSeekBar?.let {
it.thumbOffset = it.thumb.intrinsicWidth.div(2 * PI).roundToInt()
}
......@@ -461,6 +470,7 @@ class TextPercentageSeekBarPreference @JvmOverloads constructor(
companion object {
private const val TAG = "SeekBarPreference"
private const val STEP_SIZE = 5
private const val HALF_ALPHA = 0.5F
private const val MIN_VALUE = 50
private const val DECIMAL_CONVERSION = 100f
private const val TEXT_SIZE = 16f
......
......@@ -315,13 +315,16 @@ class Settings(private val appContext: Context) : PreferencesHolder {
val shouldShowSecurityPinWarning: Boolean
get() = loginsSecureWarningCount.underMaxCount()
fun shouldUseAutoSize() = fontSizeFactor == 1F
var shouldUseLightTheme by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_light_theme),
default = false
)
var shouldUseAutoSize by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_accessibility_auto_size),
default = true
)
var fontSizeFactor by floatPreference(
appContext.getPreferenceKey(R.string.pref_key_accessibility_font_scale),
default = 1f
......
......@@ -11,6 +11,7 @@
<string name="pref_key_site_permissions" translatable="false">pref_key_site_permissions</string>
<string name="pref_key_add_private_browsing_shortcut" translatable="false">pref_key_add_private_browsing_shortcut</string>
<string name="pref_key_accessibility" translatable="false">pref_key_accessibility</string>
<string name="pref_key_accessibility_auto_size" translatable="false">pref_key_accessibility_auto_size</string>
<string name="pref_key_accessibility_font_scale" translatable="false">pref_key_accessibility_font_scale</string>
<string name="pref_key_accessibility_force_enable_zoom" translatable="false">pref_key_accessibility_force_enable_zoom</string>
<string name="pref_key_advanced" translatable="false">pref_key_advanced</string>
......
......@@ -4,6 +4,11 @@
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<SwitchPreference
android:defaultValue="true"
android:key="@string/pref_key_accessibility_auto_size"
android:summary="@string/preference_accessibility_auto_size_summary"
android:title="@string/preference_accessibility_auto_size_2" />
<!-- Custom Preference that scales from 50-200% by steps of 5 represented by 0-30 in steps of 1-->
<org.mozilla.fenix.settings.TextPercentageSeekBarPreference
android:defaultValue="10"
......@@ -13,6 +18,7 @@
android:summary="@string/preference_accessibility_text_size_summary"
android:title="@string/preference_accessibility_font_size_title"
app:adjustable="true"
app:enabled="false"
app:iconSpaceReserved="false"
app:min="0"
app:seekBarIncrement="1"
......
......@@ -43,6 +43,9 @@ class ExtensionsTest {
every {
fragment.getString(R.string.pref_key_accessibility_force_enable_zoom)
} returns "pref_key_accessibility_force_enable_zoom"
every {
fragment.getString(R.string.pref_key_accessibility_auto_size)
} returns "pref_key_accessibility_auto_size"
}
@Test
......@@ -75,6 +78,11 @@ class ExtensionsTest {
every {
fragment.findPreference<SwitchPreference>("pref_key_accessibility_auto_size")
} returns switchPreference
assertEquals(
switchPreference,
fragment.requirePreference<SwitchPreference>(R.string.pref_key_accessibility_auto_size)
)
}
@Test
......
......@@ -258,6 +258,19 @@ class SettingsTest {
assertEquals(settings.getTabTimeout(), Settings.ONE_MONTH_MS)
}
@Test
fun shouldUseAutoSize() {
// When just created
// Then
assertTrue(settings.shouldUseAutoSize)
// When
settings.shouldUseAutoSize = false
// Then
assertFalse(settings.shouldUseAutoSize)
}
@Test
fun shouldAutofill() {
// When just created
......
Supports Markdown
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