Bug 1254978 - Set blank if the current font is not installed and the font backend does not support language-specific enumeration. r=Gijs

This commit is contained in:
Masatoshi Kimura 2016-03-14 22:01:05 +09:00
Родитель f923e76fc7
Коммит 419788582a
2 изменённых файлов: 58 добавлений и 1 удалений

Просмотреть файл

@ -20,5 +20,57 @@ add_task(function() {
let fontSizeField = doc.getElementById("defaultFontSize");
is(fontSizeField.value, defaultFontSize, "Font size should be set correctly.");
doc.getElementById("advancedFonts").click();
let win = yield promiseLoadSubDialog("chrome://browser/content/preferences/fonts.xul");
doc = win.document;
// Simulate a dumb font backend.
win.FontBuilder._enumerator = {
_list: ["MockedFont1", "MockedFont2", "MockedFont3"],
EnumerateFonts: function(lang, type, list) {
return this._list;
},
EnumerateAllFonts: function() {
return this._list;
},
getDefaultFont: function() { return null; },
getStandardFamilyName: function(name) { return name; },
};
win.FontBuilder._allFonts = null;
win.FontBuilder._langGroupSupported = false;
let langGroupElement = doc.getElementById("font.language.group");
let selectLangsField = doc.getElementById("selectLangs");
let serifField = doc.getElementById("serif");
let armenian = "x-armn";
let western = "x-western";
langGroupElement.value = armenian;
selectLangsField.value = armenian;
is(serifField.value, "", "Font family should not be set.");
langGroupElement.value = western;
selectLangsField.value = western;
// Simulate a font backend supporting language-specific enumeration.
// NB: FontBuilder has cached the return value from EnumerateAllFonts(),
// so _allFonts will always have 3 elements regardless of subsequent
// _list changes.
win.FontBuilder._enumerator._list = ["MockedFont2"];
langGroupElement.value = armenian;
selectLangsField.value = armenian;
is(serifField.value, "MockedFont2", "Font family should be set.");
langGroupElement.value = western;
selectLangsField.value = western;
// Simulate a system that has no fonts for the specified language.
win.FontBuilder._enumerator._list = [];
langGroupElement.value = armenian;
selectLangsField.value = armenian;
is(serifField.value, "", "Font family should not be set.");
gBrowser.removeCurrentTab();
});

Просмотреть файл

@ -16,6 +16,7 @@ var FontBuilder = {
},
_allFonts: null,
_langGroupSupported: false,
buildFontList: function (aLanguage, aFontType, aMenuList)
{
// Reset the list
@ -62,6 +63,7 @@ var FontBuilder = {
// Build the UI for the remaining fonts.
if (this._allFonts.length > fonts.length) {
this._langGroupSupported = true;
// Both lists are sorted, and the Fonts-By-Type list is a subset of the
// All-Fonts list, so walk both lists side-by-side, skipping values we've
// already created menu items for.
@ -102,7 +104,10 @@ var FontBuilder = {
return undefined;
}
let defaultValue = aElement.firstChild.firstChild.getAttribute("value");
// The first item will be a reasonable choice only if the font backend
// supports language-specific enumaration.
let defaultValue = this._langGroupSupported ?
aElement.firstChild.firstChild.getAttribute("value") : "";
let fontNameList = preference.name.replace(".name.", ".name-list.");
let prefFontNameList = document.getElementById(fontNameList);
if (!prefFontNameList || !prefFontNameList.value)