Bug 1328868 - Part 10 - Add a test to check that flipping the Android pref enables/disables font inflation. r?esawin,sebastian draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Wed, 08 Feb 2017 19:37:58 +0100
changeset 485524 fbf5833ada07ba913c796fd441c4278ea3181532
parent 485523 0251a21d8078f5b486333fcf9fe8f06f60e00647
child 485525 00c5f6fea44ffdd5a4e8644a63715f353ae8bc1a
push id45754
push usermozilla@buttercookie.de
push dateThu, 16 Feb 2017 20:38:49 +0000
reviewersesawin, sebastian
bugs1328868
milestone54.0a1
Bug 1328868 - Part 10 - Add a test to check that flipping the Android pref enables/disables font inflation. r?esawin,sebastian A basic check that the listener is indeed operational. MozReview-Commit-ID: 6KijcsRaScI
mobile/android/tests/browser/chrome/chrome.ini
mobile/android/tests/browser/chrome/test_settings_fontinflation.html
--- a/mobile/android/tests/browser/chrome/chrome.ini
+++ b/mobile/android/tests/browser/chrome/chrome.ini
@@ -39,12 +39,13 @@ skip-if = true # Bug 1241478
 [test_resource_substitutions.html]
 [test_restricted_profiles.html]
 [test_select_disabled.html]
 [test_selectoraddtab.html]
 [test_session_form_data.html]
 [test_session_parentid.html]
 [test_session_scroll_position.html]
 [test_session_zombification.html]
+[test_settings_fontinflation.html]
 [test_shared_preferences.html]
 [test_simple_discovery.html]
 [test_video_discovery.html]
 [test_web_channel.html]
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/chrome/test_settings_fontinflation.html
@@ -0,0 +1,92 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1328868
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1328868</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="head.js"></script>
+  <script type="application/javascript;version=1.7">
+
+  /** Test for Bug 1328868 **/
+
+  "use strict";
+
+  const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+
+  Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+  Cu.import("resource://gre/modules/Services.jsm");
+  Cu.import("resource://gre/modules/Messaging.jsm");
+  Cu.import("resource://gre/modules/Promise.jsm");
+  Cu.import("resource://gre/modules/Task.jsm");
+  Cu.import("resource://gre/modules/SharedPreferences.jsm");
+
+  const GECKO_PREF_FONT_INFLATION = "font.size.inflation.minTwips";
+  const ANDROID_PREF = "android.not_a_preference.font.size.use_system_font_size";
+
+  let sharedPrefs = SharedPreferences.forApp();
+  let _observerId = 0;
+
+  function resetPrefs() {
+    sharedPrefs.setBoolPref(ANDROID_PREF, false);
+    Services.prefs.setIntPref(GECKO_PREF_FONT_INFLATION, 0);
+  }
+
+  SimpleTest.registerCleanupFunction(function() {
+    // If anything goes wrong, we want to be sure to leave everything as we came
+    resetPrefs();
+  });
+
+  add_task(function* test_androidPrefControlsFontInflation() {
+    // Check that we're starting out with the default values
+    is(sharedPrefs.getBoolPref(ANDROID_PREF), false, "System font size scaling is disabled");
+    is(Services.prefs.getIntPref(GECKO_PREF_FONT_INFLATION), 0, "Gecko-side font inflation is disabled");
+
+    // Flipping the Android pref "on" should enable font inflation
+    let observer = makeObserver(_observerId++);
+    Services.prefs.addObserver(GECKO_PREF_FONT_INFLATION, observer, false);
+
+    try {
+      sharedPrefs.setBoolPref(ANDROID_PREF, true);
+      let result = yield observer.promise;
+
+      is(observer.count, 1, "Gecko pref should have changed only once");
+      is(result.data, GECKO_PREF_FONT_INFLATION, "the correct pref has changed");
+      is(Services.prefs.getIntPref(GECKO_PREF_FONT_INFLATION), 120, "Gecko-side font inflation is enabled");
+    } finally {
+      Services.prefs.removeObserver(GECKO_PREF_FONT_INFLATION, observer);
+    }
+
+    // ... and turning it back off should disable it again.
+    observer = makeObserver(_observerId++);
+    Services.prefs.addObserver(GECKO_PREF_FONT_INFLATION, observer, false);
+
+    try {
+      sharedPrefs.setBoolPref(ANDROID_PREF, false);
+      let result = yield observer.promise;
+
+      is(observer.count, 1, "Gecko pref should have changed only once");
+      is(result.data, GECKO_PREF_FONT_INFLATION, "the correct pref has changed");
+      is(Services.prefs.getIntPref(GECKO_PREF_FONT_INFLATION), 0, "Gecko-side font inflation is disabled");
+    } finally {
+      Services.prefs.removeObserver(GECKO_PREF_FONT_INFLATION, observer);
+    }
+  });
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1328868">Mozilla Bug 1328868</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>