Bug 1328868 - Part 11 - Check that zooming via "font.size.systemFontScale" actually has any effect. r?sebastian draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 10 Feb 2017 19:21:32 +0100
changeset 485525 00c5f6fea44ffdd5a4e8644a63715f353ae8bc1a
parent 485524 fbf5833ada07ba913c796fd441c4278ea3181532
child 485526 e01cff0037b706d3ab380659a0048e12da9e6e18
push id45754
push usermozilla@buttercookie.de
push dateThu, 16 Feb 2017 20:38:49 +0000
reviewerssebastian
bugs1328868
milestone54.0a1
Bug 1328868 - Part 11 - Check that zooming via "font.size.systemFontScale" actually has any effect. r?sebastian MozReview-Commit-ID: F2YtTER17xQ
mobile/android/tests/browser/chrome/basic_article_mobile_2x.html
mobile/android/tests/browser/chrome/chrome.ini
mobile/android/tests/browser/chrome/test_settings_fontinflation.html
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/chrome/basic_article_mobile_2x.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Article title</title>
+<meta name="description" content="This is the article description." />
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+</head>
+<style>
+body { font-size: 200% !important; }
+</style>
+<body>
+<header>Site header</header>
+<div>
+<h1>Article title</h1>
+<h2 class="author">by Jane Doe</h2>
+<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.</p>
+<p>Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper ultricies. Curabitur ornare, ligula semper consectetur sagittis, nisi diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, odio nec pretium volutpat, arcu ante placerat erat, non tristique elit urna et turpis. Quisque mi metus, ornare sit amet fermentum et, tincidunt et orci. Fusce eget orci a orci congue vestibulum. Ut dolor diam, elementum et vestibulum eu, porttitor vel elit. Curabitur venenatis pulvinar tellus gravida ornare. Sed et erat faucibus nunc euismod ultricies ut id justo. Nullam cursus suscipit nisi, et ultrices justo sodales nec. Fusce venenatis facilisis lectus ac semper. Aliquam at massa ipsum. Quisque bibendum purus convallis nulla ultrices ultricies. Nullam aliquam, mi eu aliquam tincidunt, purus velit laoreet tortor, viverra pretium nisi quam vitae mi. Fusce vel volutpat elit. Nam sagittis nisi dui.</p>
+<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.</p>
+<p>Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper ultricies. Curabitur ornare, ligula semper consectetur sagittis, nisi diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, odio nec pretium volutpat, arcu ante placerat erat, non tristique elit urna et turpis. Quisque mi metus, ornare sit amet fermentum et, tincidunt et orci. Fusce eget orci a orci congue vestibulum. Ut dolor diam, elementum et vestibulum eu, porttitor vel elit. Curabitur venenatis pulvinar tellus gravida ornare. Sed et erat faucibus nunc euismod ultricies ut id justo. Nullam cursus suscipit nisi, et ultrices justo sodales nec. Fusce venenatis facilisis lectus ac semper. Aliquam at massa ipsum. Quisque bibendum purus convallis nulla ultrices ultricies. Nullam aliquam, mi eu aliquam tincidunt, purus velit laoreet tortor, viverra pretium nisi quam vitae mi. Fusce vel volutpat elit. Nam sagittis nisi dui.</p>
+</div>
+</body>
+</html>
--- a/mobile/android/tests/browser/chrome/chrome.ini
+++ b/mobile/android/tests/browser/chrome/chrome.ini
@@ -1,13 +1,14 @@
 [DEFAULT]
 skip-if = os != 'android'
 support-files =
   basic_article.html
   basic_article_mobile.html
+  basic_article_mobile_2x.html
   desktopmode_user_agent.sjs
   devicesearch.xml
   head.js
   head_search.js
   session_formdata_sample.html
   simpleservice.xml
   video_controls.html
   video_discovery.html
--- a/mobile/android/tests/browser/chrome/test_settings_fontinflation.html
+++ b/mobile/android/tests/browser/chrome/test_settings_fontinflation.html
@@ -5,16 +5,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 -->
 <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="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
   <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;
@@ -22,47 +23,184 @@ https://bugzilla.mozilla.org/show_bug.cg
   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 FONT_INFLATION_DEFAULT_VALUE = 120;
+  const GECKO_PREF_FONT_SCALE = "font.size.systemFontScale";
   const ANDROID_PREF = "android.not_a_preference.font.size.use_system_font_size";
 
+  // The chrome window
+  let chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+  let BrowserApp = chromeWin.BrowserApp;
+
+  // Track the tabs where the tests are happening
+  let tab;
+
+  // This page will be eligible for font inflation...
+  const URL_desktop = "http://example.org/chrome/mobile/android/tests/browser/chrome/basic_article.html";
+  // ... and this one won't.
+  const URL_mobile = "http://example.org/chrome/mobile/android/tests/browser/chrome/basic_article_mobile.html";
+  const URL_mobile_2x = "http://example.org/chrome/mobile/android/tests/browser/chrome/basic_article_mobile_2x.html";
+
   let sharedPrefs = SharedPreferences.forApp();
   let _observerId = 0;
 
+  function cleanupTabs() {
+    if (tab) {
+      BrowserApp.closeTab(tab);
+      tab = null;
+    }
+  }
+
+  function setSystemFontScale(scale) {
+    Services.prefs.setIntPref(GECKO_PREF_FONT_SCALE, Math.round(scale * 100));
+  }
+
+  function getSystemFontScale() {
+    return Services.prefs.getIntPref(GECKO_PREF_FONT_SCALE) / 100;
+  }
+
   function resetPrefs() {
     sharedPrefs.setBoolPref(ANDROID_PREF, false);
     Services.prefs.setIntPref(GECKO_PREF_FONT_INFLATION, 0);
+    setSystemFontScale(1.0);
   }
 
   SimpleTest.registerCleanupFunction(function() {
     // If anything goes wrong, we want to be sure to leave everything as we came
     resetPrefs();
+    cleanupTabs();
+  });
+
+  add_task(function* test_globalZoomScalesMobilePages() {
+    // 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");
+
+    // Check the system font scale factor and then enable it for testing
+    is(getSystemFontScale(), 1.0, "global zooming is disabled");
+    tab = BrowserApp.addTab(URL_mobile , { selected: true, parentId: BrowserApp.selectedTab.id });
+    yield promiseBrowserEvent(tab.browser, "load");
+    is(tab.browser.textZoom, 1.0, "text zoom is default value");
+
+    setSystemFontScale(2.0);
+    tab.reloadWithMode(tab.desktopMode);
+    yield promiseBrowserEvent(tab.browser, "load");
+
+    is(getSystemFontScale(), 2.0, "global zooming is enabled");
+    is(tab.browser.textZoom, 2.0, "text zoom set through global zooming");
+    let globalZoomOn = snapshotWindow(tab.browser.contentWindow);
+
+    // Disable global zooming again
+    setSystemFontScale(1.0);
+    is(getSystemFontScale(), 1.0, "global zooming is disabled");
+
+    tab.reloadWithMode(tab.desktopMode);
+    yield promiseBrowserEvent(tab.browser, "load");
+
+    is(tab.browser.textZoom, 1.0, "text zoom is back to default value");
+    let globalZoomOff = snapshotWindow(tab.browser.contentWindow);
+    assertSnapshots(globalZoomOn, globalZoomOff, false, null, "globalZoomOn", "globalZoomOff");
+
+    // Now compare with a document that's been zoomed through CSS
+    tab.browser.loadURI(URL_mobile_2x);
+    yield promiseBrowserEvent(tab.browser, "load");
+
+    let cssZoom = snapshotWindow(tab.browser.contentWindow);
+    assertSnapshots(globalZoomOn, cssZoom, true, null, "globalZoomOn", "cssZoom");
+
+    // Load the original document and test normal text zooming
+    tab.browser.loadURI(URL_mobile);
+    yield promiseBrowserEvent(tab.browser, "load");
+
+    tab.browser.textZoom = 2.0;
+    is(tab.browser.textZoom, 2.0, "text zoom is enabled");
+
+    let textZoom = snapshotWindow(tab.browser.contentWindow);
+    assertSnapshots(globalZoomOn, textZoom, true, null, "globalZoomOn", "textZoom");
+
+    cleanupTabs();
   });
 
+  add_task(function* test_fontInflationPrecedence() {
+    // 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");
+
+    // Check the system font scale factor and then take a screenshot of this base state
+    is(getSystemFontScale(), 1.0, "global zooming is disabled");
+    tab = BrowserApp.addTab(URL_desktop , { selected: true, parentId: BrowserApp.selectedTab.id });
+    yield promiseBrowserEvent(tab.browser, "load");
+    is(tab.browser.textZoom, 1.0, "text zoom is default value");
+
+    let noZoom = snapshotWindow(tab.browser.contentWindow);
+
+    // Enable font inflation and check that this has some effect
+    Services.prefs.setIntPref(GECKO_PREF_FONT_INFLATION, FONT_INFLATION_DEFAULT_VALUE);
+
+    tab.reloadWithMode(tab.desktopMode);
+    yield promiseBrowserEvent(tab.browser, "load");
+
+    let fontInflationOn = snapshotWindow(tab.browser.contentWindow);
+    assertSnapshots(noZoom, fontInflationOn, false, null, "noZoom", "fontInflationOn");
+
+    // Now enable global zooming and make sure that this doesn't result in any visual change
+    setSystemFontScale(2.0);
+    tab.reloadWithMode(tab.desktopMode);
+    yield promiseBrowserEvent(tab.browser, "load");
+
+    is(getSystemFontScale(), 2.0, "global zooming is enabled");
+    is(tab.browser.textZoom, 1.0, "text zoom remains at default value");
+    let globalZoomWithFontInflation = snapshotWindow(tab.browser.contentWindow);
+    assertSnapshots(fontInflationOn, globalZoomWithFontInflation, true, null, "fontInflationOn", "globalZoomWithFontInflation");
+
+    // Disable font inflation and check that global zooming becomes active
+    Services.prefs.setIntPref(GECKO_PREF_FONT_INFLATION, 0);
+    tab.reloadWithMode(tab.desktopMode);
+    yield promiseBrowserEvent(tab.browser, "load");
+
+    is(tab.browser.textZoom, 2.0, "text zoom set through global zooming");
+    let globalZoomNoFontInflation = snapshotWindow(tab.browser.contentWindow);
+    assertSnapshots(noZoom, globalZoomNoFontInflation, false, null, "noZoom", "gobalZoomNoFontInflation");
+
+    // Reset global zooming back to default
+    setSystemFontScale(1.0);
+
+    cleanupTabs();
+  });
+
+  // There is a slight delay between flipping the Android shared pref and the
+  // Java side listener native call actually getting through to the font scale in
+  // nsLayoutUtils, therefore this test MUST run last, otherwise the font scale
+  // could be unexpectedly reset in the middle of a following test.
+  // However as as long the test environment uses the default Android system font scale,
+  // this won't impact other unrelated tests since we set "font.size.systemFontScale"
+  // to zero in that case, which already is the default value.
   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");
+    is(getSystemFontScale(), 1.0, "global zooming 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");
+      is(Services.prefs.getIntPref(GECKO_PREF_FONT_INFLATION), FONT_INFLATION_DEFAULT_VALUE, "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);