Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1077)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/accessibility/FontSizePrefsTest.java

Issue 415343002: Upstream accessibility font size preferences. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Made callback methods private, test expect statements changed, styling Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/accessibility/FontSizePrefsTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/accessibility/FontSizePrefsTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/accessibility/FontSizePrefsTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..e6758032d8d1100a53d5fc2a6cb60ac15e9c1b3c
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/accessibility/FontSizePrefsTest.java
@@ -0,0 +1,161 @@
+// Copyright 2014 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.accessibility;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.chromium.base.test.util.Feature;
+import org.chromium.base.ThreadUtils;
+import org.chromium.chrome.browser.profiles.Profile;
+import org.chromium.chrome.shell.ChromeShellTestBase;
+import org.chromium.content.browser.test.util.UiUtils;
+
+/**
+ * Test class for {@link FontSizePrefs}.
+ */
+public class FontSizePrefsTest extends ChromeShellTestBase {
+
+ private FontSizePrefs mFontSizePrefs;
+
+ private static final float FONT_SMALLER_THAN_THRESHOLD =
+ FontSizePrefs.FORCE_ENABLE_ZOOM_THRESHOLD_MULTIPLIER - 0.4f;
robliao 2014/07/25 23:49:34 0.4f arbitrary?
sunangel 2014/07/28 21:17:20 Yes, but now that the threshold has been moved to
+ private static final float FONT_LARGER_THAN_THRESHOLD =
+ FontSizePrefs.FORCE_ENABLE_ZOOM_THRESHOLD_MULTIPLIER + 0.4f;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ startChromeBrowserProcessSync(getInstrumentation().getTargetContext());
+ mFontSizePrefs = FontSizePrefs.getForProfile(Profile.getLastUsedProfile(),
+ launchChromeShellWithBlankPage().getApplicationContext());
+ }
+
+ @SmallTest
+ @Feature({"Accessibility"})
+ public void testGetAndSetFontAndForceEnableZoom() throws InterruptedException {
+ // Check default font.
+ assertEquals(1f, mFontSizePrefs.getFontScaleFactor());
+
+ // Check the default value of force enable zoom.
+ assertEquals(false, mFontSizePrefs.getForceEnableZoom());
+ setForceEnableZoom(true);
+ assertEquals(true, mFontSizePrefs.getForceEnableZoom());
+
+ // Set force enable zoom false again to ensure that when font is now changed but remains
+ // below the threshold, force enable zoom remains false.
+ setForceEnableZoom(false);
+ // Check that font size can be correctly set and force enable zoom does
+ // not change when font size is not increased above the threshold.
+ setFontScale(FONT_SMALLER_THAN_THRESHOLD);
+ UiUtils.settleDownUI(getInstrumentation());
+ assertEquals(FONT_SMALLER_THAN_THRESHOLD, mFontSizePrefs.getFontScaleFactor());
+ assertEquals(false, mFontSizePrefs.getForceEnableZoom());
+
+ // Check that force enable zoom does change when font increased above
+ // threshold, since user has not checked the set enable zoom.
+ setFontScale(FONT_LARGER_THAN_THRESHOLD);
+ UiUtils.settleDownUI(getInstrumentation());
+ assertEquals(FONT_LARGER_THAN_THRESHOLD, mFontSizePrefs.getFontScaleFactor());
+ assertEquals(true, mFontSizePrefs.getForceEnableZoom());
+ }
+
+ @SmallTest
+ @Feature({"Accessibility"})
+ public void testObserversForceEnableZoom() throws InterruptedException {
+ TestingObserver test1 = new TestingObserver();
+ TestingObserver test2 = new TestingObserver();
+ mFontSizePrefs.addObserver(test1);
+ mFontSizePrefs.addObserver(test2);
+
+ // Checks that force enable zoom for both observers is correctly changed.
+ setForceEnableZoom(true);
+ UiUtils.settleDownUI(getInstrumentation());
+ assertEquals(true, test1.getForceEnableZoom());
+ assertEquals(true, test2.getForceEnableZoom());
+
+ //Checks that removing observer and setting force enable zoom works.
+ mFontSizePrefs.removeObserver(test1);
+ setForceEnableZoom(false);
+ UiUtils.settleDownUI(getInstrumentation());
+ assertEquals(true, test1.getForceEnableZoom());
+ assertEquals(false, test2.getForceEnableZoom());
+ mFontSizePrefs.removeObserver(test2);
+ }
+
+
+ @SmallTest
+ @Feature({"Accessibility"})
+ public void testObserversFontScale() throws InterruptedException {
+ TestingObserver test1 = new TestingObserver();
+ TestingObserver test2 = new TestingObserver();
+ mFontSizePrefs.addObserver(test1);
+ mFontSizePrefs.addObserver(test2);
+
+ // Checks that font scale for both observers is correctly changed.
+ setFontScale(FONT_SMALLER_THAN_THRESHOLD);
+ UiUtils.settleDownUI(getInstrumentation());
+ assertEquals(FONT_SMALLER_THAN_THRESHOLD, test1.getFontScaleFactor());
+ assertEquals(FONT_SMALLER_THAN_THRESHOLD, test2.getFontScaleFactor());
+
+ //Checks that font scale for both observers is correctly changed and when the font scale is
robliao 2014/07/25 23:49:34 Space after //
sunangel 2014/07/28 21:17:20 Done.
+ // increased above the threshold, force enable zoom also changes correspondingly.
+ setFontScale(FONT_LARGER_THAN_THRESHOLD);
+ UiUtils.settleDownUI(getInstrumentation());
+ assertEquals(FONT_LARGER_THAN_THRESHOLD, test1.getFontScaleFactor());
+ assertEquals(FONT_LARGER_THAN_THRESHOLD, test2.getFontScaleFactor());
+ assertEquals(true, test1.getForceEnableZoom());
+ assertEquals(true, test2.getForceEnableZoom());
+
+ //Checks that removing observer and setting font works.
+ mFontSizePrefs.removeObserver(test1);
+ setFontScale(FONT_SMALLER_THAN_THRESHOLD);
+ UiUtils.settleDownUI(getInstrumentation());
+ assertEquals(FONT_LARGER_THAN_THRESHOLD, test1.getFontScaleFactor());
+ assertEquals(FONT_SMALLER_THAN_THRESHOLD, test2.getFontScaleFactor());
+ mFontSizePrefs.removeObserver(test2);
+ }
+
+ private static class TestingObserver implements FontSizePrefs.Observer {
+ private float mFontSize;
robliao 2014/07/25 23:49:34 Tabs = 4 Spaces and below.
sunangel 2014/07/28 21:17:20 Done.
+ private boolean mForceEnableZoom;
+
+ public TestingObserver() {
+ mFontSize = 1;
+ mForceEnableZoom = false;
+ }
+
+ public float getFontScaleFactor() {
+ return mFontSize;
+ }
+
+ public void onChangeFontSize(float font) {
+ mFontSize = font;
+ }
+
+ public boolean getForceEnableZoom() {
+ return mForceEnableZoom;
+ }
+
+ public void onChangeForceEnableZoom(boolean enabled) {
+ mForceEnableZoom = enabled;
+ }
+ }
+
+ private void setFontScale(final float fontsize) {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ public void run() {
+ mFontSizePrefs.setAndProcessFontScaleFactor(fontsize);
+ }
+ });
+ }
+
+ private void setForceEnableZoom(final boolean enabled) {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ public void run() {
+ mFontSizePrefs.setForceEnableZoom(enabled);
+ }
+ });
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698