Commit acc596c0 authored by Natalie Chouinard's avatar Natalie Chouinard Committed by Commit Bot

Move and rename Accessibility settings

Move Accessibility settings and tests to subpackage, and rename
according to go/clank-preferences-refactor naming conventions.

Bug: 876376, 1030446
Change-Id: Ib0cdb031cf43fb2b93de8447e2c45af4ab18936b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1949534Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarEnder <ender@google.com>
Commit-Queue: Natalie Chouinard <chouinard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721819}
parent 40c81750
...@@ -1325,7 +1325,6 @@ chrome_java_sources = [ ...@@ -1325,7 +1325,6 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/services/gcm/GcmUma.java", "java/src/org/chromium/chrome/browser/services/gcm/GcmUma.java",
"java/src/org/chromium/chrome/browser/services/gcm/InvalidationGcmUpstreamSender.java", "java/src/org/chromium/chrome/browser/services/gcm/InvalidationGcmUpstreamSender.java",
"java/src/org/chromium/chrome/browser/sessions/SessionTabHelper.java", "java/src/org/chromium/chrome/browser/sessions/SessionTabHelper.java",
"java/src/org/chromium/chrome/browser/settings/AccessibilityPreferences.java",
"java/src/org/chromium/chrome/browser/settings/ButtonPreference.java", "java/src/org/chromium/chrome/browser/settings/ButtonPreference.java",
"java/src/org/chromium/chrome/browser/settings/ChromeBaseCheckBoxPreference.java", "java/src/org/chromium/chrome/browser/settings/ChromeBaseCheckBoxPreference.java",
"java/src/org/chromium/chrome/browser/settings/ChromeBasePreference.java", "java/src/org/chromium/chrome/browser/settings/ChromeBasePreference.java",
...@@ -1357,11 +1356,12 @@ chrome_java_sources = [ ...@@ -1357,11 +1356,12 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/settings/sync/SyncPreferenceUtils.java", "java/src/org/chromium/chrome/browser/settings/sync/SyncPreferenceUtils.java",
"java/src/org/chromium/chrome/browser/settings/TextAndButtonPreference.java", "java/src/org/chromium/chrome/browser/settings/TextAndButtonPreference.java",
"java/src/org/chromium/chrome/browser/settings/TextMessagePreference.java", "java/src/org/chromium/chrome/browser/settings/TextMessagePreference.java",
"java/src/org/chromium/chrome/browser/settings/TextScalePreference.java",
"java/src/org/chromium/chrome/browser/settings/about/AboutChromePreferenceOSVersion.java", "java/src/org/chromium/chrome/browser/settings/about/AboutChromePreferenceOSVersion.java",
"java/src/org/chromium/chrome/browser/settings/about/AboutChromeSettings.java", "java/src/org/chromium/chrome/browser/settings/about/AboutChromeSettings.java",
"java/src/org/chromium/chrome/browser/settings/about/AboutSettingsBridge.java", "java/src/org/chromium/chrome/browser/settings/about/AboutSettingsBridge.java",
"java/src/org/chromium/chrome/browser/settings/about/LegalInformationSettings.java", "java/src/org/chromium/chrome/browser/settings/about/LegalInformationSettings.java",
"java/src/org/chromium/chrome/browser/settings/accessibility/AccessibilitySettings.java",
"java/src/org/chromium/chrome/browser/settings/accessibility/TextScalePreference.java",
"java/src/org/chromium/chrome/browser/settings/autofill/AndroidPaymentAppPreference.java", "java/src/org/chromium/chrome/browser/settings/autofill/AndroidPaymentAppPreference.java",
"java/src/org/chromium/chrome/browser/settings/autofill/AndroidPaymentAppsFragment.java", "java/src/org/chromium/chrome/browser/settings/autofill/AndroidPaymentAppsFragment.java",
"java/src/org/chromium/chrome/browser/settings/autofill/AutofillCreditCardEditor.java", "java/src/org/chromium/chrome/browser/settings/autofill/AutofillCreditCardEditor.java",
......
...@@ -410,6 +410,7 @@ chrome_test_java_sources = [ ...@@ -410,6 +410,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/settings/NotificationsPreferencesTest.java", "javatests/src/org/chromium/chrome/browser/settings/NotificationsPreferencesTest.java",
"javatests/src/org/chromium/chrome/browser/settings/PasswordViewingTypeTest.java", "javatests/src/org/chromium/chrome/browser/settings/PasswordViewingTypeTest.java",
"javatests/src/org/chromium/chrome/browser/settings/SettingsActivityTest.java", "javatests/src/org/chromium/chrome/browser/settings/SettingsActivityTest.java",
"javatests/src/org/chromium/chrome/browser/settings/accessibility/AccessibilitySettingsTest.java",
"javatests/src/org/chromium/chrome/browser/settings/autofill/AutofillProfilesFragmentTest.java", "javatests/src/org/chromium/chrome/browser/settings/autofill/AutofillProfilesFragmentTest.java",
"javatests/src/org/chromium/chrome/browser/settings/autofill/AutofillTestRule.java", "javatests/src/org/chromium/chrome/browser/settings/autofill/AutofillTestRule.java",
"javatests/src/org/chromium/chrome/browser/settings/autofill_assistant/AutofillAssistantPreferencesTest.java", "javatests/src/org/chromium/chrome/browser/settings/autofill_assistant/AutofillAssistantPreferencesTest.java",
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<org.chromium.chrome.browser.settings.TextScalePreference <org.chromium.chrome.browser.settings.accessibility.TextScalePreference
android:key="text_scale" android:key="text_scale"
android:title="@string/font_size" android:title="@string/font_size"
android:selectable="false" /> android:selectable="false" />
......
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
android:order="13" android:order="13"
android:title="@string/prefs_privacy"/> android:title="@string/prefs_privacy"/>
<Preference <Preference
android:fragment="org.chromium.chrome.browser.settings.AccessibilityPreferences" android:fragment="org.chromium.chrome.browser.settings.accessibility.AccessibilitySettings"
android:key="accessibility" android:key="accessibility"
android:order="14" android:order="14"
android:title="@string/prefs_accessibility"/> android:title="@string/prefs_accessibility"/>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
package org.chromium.chrome.browser.settings; package org.chromium.chrome.browser.settings.accessibility;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
...@@ -18,6 +18,8 @@ import org.chromium.chrome.browser.preferences.ChromePreferenceKeys; ...@@ -18,6 +18,8 @@ import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.Pref; import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge; import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager; import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.settings.ChromeBaseCheckBoxPreference;
import org.chromium.chrome.browser.settings.SettingsUtils;
import org.chromium.chrome.browser.util.AccessibilityUtil; import org.chromium.chrome.browser.util.AccessibilityUtil;
import java.text.NumberFormat; import java.text.NumberFormat;
...@@ -25,7 +27,7 @@ import java.text.NumberFormat; ...@@ -25,7 +27,7 @@ import java.text.NumberFormat;
/** /**
* Fragment to keep track of all the accessibility related preferences. * Fragment to keep track of all the accessibility related preferences.
*/ */
public class AccessibilityPreferences public class AccessibilitySettings
extends PreferenceFragmentCompat implements Preference.OnPreferenceChangeListener { extends PreferenceFragmentCompat implements Preference.OnPreferenceChangeListener {
static final String PREF_TEXT_SCALE = "text_scale"; static final String PREF_TEXT_SCALE = "text_scale";
static final String PREF_FORCE_ENABLE_ZOOM = "force_enable_zoom"; static final String PREF_FORCE_ENABLE_ZOOM = "force_enable_zoom";
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
package org.chromium.chrome.browser.settings; package org.chromium.chrome.browser.settings.accessibility;
import android.content.Context; import android.content.Context;
import android.support.v7.preference.PreferenceViewHolder; import android.support.v7.preference.PreferenceViewHolder;
...@@ -13,6 +13,7 @@ import android.widget.TextView; ...@@ -13,6 +13,7 @@ import android.widget.TextView;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.accessibility.FontSizePrefs; import org.chromium.chrome.browser.accessibility.FontSizePrefs;
import org.chromium.chrome.browser.accessibility.FontSizePrefs.FontSizePrefsObserver; import org.chromium.chrome.browser.accessibility.FontSizePrefs.FontSizePrefsObserver;
import org.chromium.chrome.browser.settings.SeekBarPreference;
/** /**
* Preference that allows the user to change the scaling factor that's applied to web page text. * Preference that allows the user to change the scaling factor that's applied to web page text.
...@@ -80,5 +81,4 @@ public class TextScalePreference extends SeekBarPreference { ...@@ -80,5 +81,4 @@ public class TextScalePreference extends SeekBarPreference {
smallestStandardWebPageFontSize * mFontSizePrefs.getFontScaleFactor()); smallestStandardWebPageFontSize * mFontSizePrefs.getFontScaleFactor());
} }
} }
} }
...@@ -14,10 +14,9 @@ import android.app.Activity; ...@@ -14,10 +14,9 @@ import android.app.Activity;
import android.app.Instrumentation; import android.app.Instrumentation;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat; import android.support.v7.preference.PreferenceFragmentCompat;
import org.junit.Assert; import org.junit.Assert;
...@@ -25,7 +24,6 @@ import org.junit.Rule; ...@@ -25,7 +24,6 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.task.PostTask;
import org.chromium.base.test.util.CallbackHelper; import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.DisableIf; import org.chromium.base.test.util.DisableIf;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
...@@ -33,7 +31,6 @@ import org.chromium.base.test.util.FlakyTest; ...@@ -33,7 +31,6 @@ import org.chromium.base.test.util.FlakyTest;
import org.chromium.base.test.util.RetryOnFailure; import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList; import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.accessibility.FontSizePrefs;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer; import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
import org.chromium.chrome.browser.preferences.Pref; import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge; import org.chromium.chrome.browser.preferences.PrefServiceBridge;
...@@ -48,14 +45,11 @@ import org.chromium.chrome.test.util.browser.Features.EnableFeatures; ...@@ -48,14 +45,11 @@ import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.components.search_engines.TemplateUrl; import org.chromium.components.search_engines.TemplateUrl;
import org.chromium.components.search_engines.TemplateUrlService; import org.chromium.components.search_engines.TemplateUrlService;
import org.chromium.components.search_engines.TemplateUrlService.LoadListener; import org.chromium.components.search_engines.TemplateUrlService.LoadListener;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.content_public.browser.test.util.Criteria; import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.browser.test.util.UiUtils;
import org.chromium.policy.test.annotations.Policies; import org.chromium.policy.test.annotations.Policies;
import java.text.NumberFormat;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
...@@ -181,7 +175,7 @@ public class SettingsActivityTest { ...@@ -181,7 +175,7 @@ public class SettingsActivityTest {
final MainPreferences mainPreferences = final MainPreferences mainPreferences =
ActivityUtils.waitForFragmentToAttach(settingsActivity, MainPreferences.class); ActivityUtils.waitForFragmentToAttach(settingsActivity, MainPreferences.class);
final android.support.v7.preference.Preference searchEnginePref = final Preference searchEnginePref =
waitForPreference(mainPreferences, MainPreferences.PREF_SEARCH_ENGINE); waitForPreference(mainPreferences, MainPreferences.PREF_SEARCH_ENGINE);
CriteriaHelper.pollUiThread(Criteria.equals(null, new Callable<Object>() { CriteriaHelper.pollUiThread(Criteria.equals(null, new Callable<Object>() {
...@@ -285,84 +279,6 @@ public class SettingsActivityTest { ...@@ -285,84 +279,6 @@ public class SettingsActivityTest {
return locationPermission; return locationPermission;
} }
/**
* Tests setting FontScaleFactor and ForceEnableZoom in AccessibilityPreferences and ensures
* that ForceEnableZoom changes corresponding to FontScaleFactor.
*/
@Test
@SmallTest
@Feature({"Accessibility"})
public void testAccessibilityPreferences() throws Exception {
String accessibilityPrefClassname = AccessibilityPreferences.class.getName();
AccessibilityPreferences accessibilityPref =
(AccessibilityPreferences) startSettingsActivity(
InstrumentationRegistry.getInstrumentation(), accessibilityPrefClassname)
.getMainFragment();
SeekBarPreference textScalePref = (SeekBarPreference) accessibilityPref.findPreference(
AccessibilityPreferences.PREF_TEXT_SCALE);
ChromeBaseCheckBoxPreference forceEnableZoomPref =
(ChromeBaseCheckBoxPreference) accessibilityPref.findPreference(
AccessibilityPreferences.PREF_FORCE_ENABLE_ZOOM);
NumberFormat percentFormat = NumberFormat.getPercentInstance();
// Arbitrary value 0.4f to be larger and smaller than threshold.
float fontSmallerThanThreshold =
FontSizePrefs.FORCE_ENABLE_ZOOM_THRESHOLD_MULTIPLIER - 0.4f;
float fontBiggerThanThreshold = FontSizePrefs.FORCE_ENABLE_ZOOM_THRESHOLD_MULTIPLIER + 0.4f;
// Set the textScaleFactor above the threshold.
userSetTextScale(accessibilityPref, textScalePref, fontBiggerThanThreshold);
UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation());
// Since above the threshold, this will check the force enable zoom button.
Assert.assertEquals(
percentFormat.format(fontBiggerThanThreshold), textScalePref.getSummary());
Assert.assertTrue(forceEnableZoomPref.isChecked());
assertFontSizePrefs(true, fontBiggerThanThreshold);
// Set the textScaleFactor below the threshold.
userSetTextScale(accessibilityPref, textScalePref, fontSmallerThanThreshold);
UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation());
// Since below the threshold and userSetForceEnableZoom is false, this will uncheck
// the force enable zoom button.
Assert.assertEquals(
percentFormat.format(fontSmallerThanThreshold), textScalePref.getSummary());
Assert.assertFalse(forceEnableZoomPref.isChecked());
assertFontSizePrefs(false, fontSmallerThanThreshold);
userSetTextScale(accessibilityPref, textScalePref, fontBiggerThanThreshold);
// Sets onUserSetForceEnableZoom to be true.
userSetForceEnableZoom(accessibilityPref, forceEnableZoomPref, true);
UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation());
// Since userSetForceEnableZoom is true, when the text scale is moved below the threshold
// ForceEnableZoom should remain checked.
userSetTextScale(accessibilityPref, textScalePref, fontSmallerThanThreshold);
Assert.assertTrue(forceEnableZoomPref.isChecked());
assertFontSizePrefs(true, fontSmallerThanThreshold);
}
@Test
@SmallTest
@Feature({"Accessibility"})
public void testCaptionPreferences() {
String accessibilityPrefClassname = AccessibilityPreferences.class.getName();
AccessibilityPreferences accessibilityPref =
(AccessibilityPreferences) startSettingsActivity(
InstrumentationRegistry.getInstrumentation(), accessibilityPrefClassname)
.getMainFragment();
android.support.v7.preference.Preference captionsPref =
accessibilityPref.findPreference(AccessibilityPreferences.PREF_CAPTIONS);
Assert.assertNotNull(captionsPref);
Assert.assertNotNull(captionsPref.getOnPreferenceClickListener());
Instrumentation.ActivityMonitor monitor =
InstrumentationRegistry.getInstrumentation().addMonitor(
new IntentFilter(Settings.ACTION_CAPTIONING_SETTINGS), null, false);
onView(withText(R.string.accessibility_captions_title)).perform(click());
monitor.waitForActivityWithTimeout(CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL);
Assert.assertEquals("Monitor for has not been called", 1, monitor.getHits());
InstrumentationRegistry.getInstrumentation().removeMonitor(monitor);
}
@Test @Test
@SmallTest @SmallTest
@Policies.Add({ @Policies.Item(key = "PasswordManagerEnabled", string = "false") }) @Policies.Add({ @Policies.Item(key = "PasswordManagerEnabled", string = "false") })
...@@ -385,31 +301,8 @@ public class SettingsActivityTest { ...@@ -385,31 +301,8 @@ public class SettingsActivityTest {
onView(withText(R.string.prefs_saved_passwords)).check(matches(isDisplayed())); onView(withText(R.string.prefs_saved_passwords)).check(matches(isDisplayed()));
} }
private void assertFontSizePrefs( private static Preference waitForPreference(final PreferenceFragmentCompat prefFragment,
final boolean expectedForceEnableZoom, final float expectedFontScale) { final String preferenceKey) throws ExecutionException {
final Context targetContext = InstrumentationRegistry.getTargetContext();
TestThreadUtils.runOnUiThreadBlocking(() -> {
FontSizePrefs fontSizePrefs = FontSizePrefs.getInstance();
Assert.assertEquals(expectedForceEnableZoom, fontSizePrefs.getForceEnableZoom());
Assert.assertEquals(expectedFontScale, fontSizePrefs.getFontScaleFactor(), 0.001f);
});
}
private static void userSetTextScale(final AccessibilityPreferences accessibilityPref,
final SeekBarPreference textScalePref, final float textScale) {
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT,
() -> { accessibilityPref.onPreferenceChange(textScalePref, textScale); });
}
private static void userSetForceEnableZoom(final AccessibilityPreferences accessibilityPref,
final ChromeBaseCheckBoxPreference forceEnableZoomPref, final boolean enabled) {
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT,
() -> { accessibilityPref.onPreferenceChange(forceEnableZoomPref, enabled); });
}
private static android.support.v7.preference.Preference waitForPreference(
final PreferenceFragmentCompat prefFragment, final String preferenceKey)
throws ExecutionException {
CriteriaHelper.pollUiThread(new Criteria() { CriteriaHelper.pollUiThread(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
...@@ -418,11 +311,6 @@ public class SettingsActivityTest { ...@@ -418,11 +311,6 @@ public class SettingsActivityTest {
}); });
return TestThreadUtils.runOnUiThreadBlocking( return TestThreadUtils.runOnUiThreadBlocking(
new Callable<android.support.v7.preference.Preference>() { () -> prefFragment.findPreference(preferenceKey));
@Override
public android.support.v7.preference.Preference call() {
return prefFragment.findPreference(preferenceKey);
}
});
} }
} }
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.settings.accessibility;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import android.app.Instrumentation;
import android.content.IntentFilter;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.v7.preference.Preference;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.task.PostTask;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.accessibility.FontSizePrefs;
import org.chromium.chrome.browser.settings.ChromeBaseCheckBoxPreference;
import org.chromium.chrome.browser.settings.SeekBarPreference;
import org.chromium.chrome.browser.settings.SettingsActivityTest;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.browser.test.util.UiUtils;
import java.text.NumberFormat;
/**
* Tests for the Accessibility Settings menu.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
public class AccessibilitySettingsTest {
/**
* Tests setting FontScaleFactor and ForceEnableZoom in AccessibilitySettings and ensures
* that ForceEnableZoom changes corresponding to FontScaleFactor.
*/
@Test
@SmallTest
@Feature({"Accessibility"})
public void testAccessibilitySettings() throws Exception {
String accessibilitySettingsClassname = AccessibilitySettings.class.getName();
AccessibilitySettings accessibilitySettings =
(AccessibilitySettings) SettingsActivityTest
.startSettingsActivity(InstrumentationRegistry.getInstrumentation(),
accessibilitySettingsClassname)
.getMainFragment();
SeekBarPreference textScalePref = (SeekBarPreference) accessibilitySettings.findPreference(
AccessibilitySettings.PREF_TEXT_SCALE);
ChromeBaseCheckBoxPreference forceEnableZoomPref =
(ChromeBaseCheckBoxPreference) accessibilitySettings.findPreference(
AccessibilitySettings.PREF_FORCE_ENABLE_ZOOM);
NumberFormat percentFormat = NumberFormat.getPercentInstance();
// Arbitrary value 0.4f to be larger and smaller than threshold.
float fontSmallerThanThreshold =
FontSizePrefs.FORCE_ENABLE_ZOOM_THRESHOLD_MULTIPLIER - 0.4f;
float fontBiggerThanThreshold = FontSizePrefs.FORCE_ENABLE_ZOOM_THRESHOLD_MULTIPLIER + 0.4f;
// Set the textScaleFactor above the threshold.
userSetTextScale(accessibilitySettings, textScalePref, fontBiggerThanThreshold);
UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation());
// Since above the threshold, this will check the force enable zoom button.
Assert.assertEquals(
percentFormat.format(fontBiggerThanThreshold), textScalePref.getSummary());
Assert.assertTrue(forceEnableZoomPref.isChecked());
assertFontSizePrefs(true, fontBiggerThanThreshold);
// Set the textScaleFactor below the threshold.
userSetTextScale(accessibilitySettings, textScalePref, fontSmallerThanThreshold);
UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation());
// Since below the threshold and userSetForceEnableZoom is false, this will uncheck
// the force enable zoom button.
Assert.assertEquals(
percentFormat.format(fontSmallerThanThreshold), textScalePref.getSummary());
Assert.assertFalse(forceEnableZoomPref.isChecked());
assertFontSizePrefs(false, fontSmallerThanThreshold);
userSetTextScale(accessibilitySettings, textScalePref, fontBiggerThanThreshold);
// Sets onUserSetForceEnableZoom to be true.
userSetForceEnableZoom(accessibilitySettings, forceEnableZoomPref, true);
UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation());
// Since userSetForceEnableZoom is true, when the text scale is moved below the threshold
// ForceEnableZoom should remain checked.
userSetTextScale(accessibilitySettings, textScalePref, fontSmallerThanThreshold);
Assert.assertTrue(forceEnableZoomPref.isChecked());
assertFontSizePrefs(true, fontSmallerThanThreshold);
}
@Test
@SmallTest
@Feature({"Accessibility"})
public void testCaptionPreferences() {
String accessibilitySettingsClassname = AccessibilitySettings.class.getName();
AccessibilitySettings accessibilitySettings =
(AccessibilitySettings) SettingsActivityTest
.startSettingsActivity(InstrumentationRegistry.getInstrumentation(),
accessibilitySettingsClassname)
.getMainFragment();
Preference captionsPref =
accessibilitySettings.findPreference(AccessibilitySettings.PREF_CAPTIONS);
Assert.assertNotNull(captionsPref);
Assert.assertNotNull(captionsPref.getOnPreferenceClickListener());
Instrumentation.ActivityMonitor monitor =
InstrumentationRegistry.getInstrumentation().addMonitor(
new IntentFilter(Settings.ACTION_CAPTIONING_SETTINGS), null, false);
onView(withText(org.chromium.chrome.R.string.accessibility_captions_title))
.perform(click());
monitor.waitForActivityWithTimeout(CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL);
Assert.assertEquals("Monitor for has not been called", 1, monitor.getHits());
InstrumentationRegistry.getInstrumentation().removeMonitor(monitor);
}
private void assertFontSizePrefs(
final boolean expectedForceEnableZoom, final float expectedFontScale) {
TestThreadUtils.runOnUiThreadBlocking(() -> {
FontSizePrefs fontSizePrefs = FontSizePrefs.getInstance();
Assert.assertEquals(expectedForceEnableZoom, fontSizePrefs.getForceEnableZoom());
Assert.assertEquals(expectedFontScale, fontSizePrefs.getFontScaleFactor(), 0.001f);
});
}
private static void userSetTextScale(final AccessibilitySettings accessibilitySettings,
final SeekBarPreference textScalePref, final float textScale) {
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT,
() -> accessibilitySettings.onPreferenceChange(textScalePref, textScale));
}
private static void userSetForceEnableZoom(final AccessibilitySettings accessibilitySettings,
final ChromeBaseCheckBoxPreference forceEnableZoomPref, final boolean enabled) {
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT,
() -> accessibilitySettings.onPreferenceChange(forceEnableZoomPref, enabled));
}
}
\ No newline at end of file
Markdown is supported
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