| 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..ccd1a264491c21fbe0e291afaab7c878b65f927e
|
| --- /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;
|
| + 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
|
| + // 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;
|
| + 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.setFontScaleFactor(fontsize);
|
| + }
|
| + });
|
| + }
|
| +
|
| + private void setForceEnableZoom(final boolean enabled) {
|
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| + public void run() {
|
| + mFontSizePrefs.setForceEnableZoom(enabled);
|
| + }
|
| + });
|
| + }
|
| +}
|
|
|