зеркало из https://github.com/mozilla/pjs.git
Bug 689702 - Update getLocales pref dynamically. r=mfinkle
This commit is contained in:
Родитель
141f3da856
Коммит
7b1072fa0f
|
@ -97,6 +97,8 @@ _BROWSER_FILES = \
|
||||||
browser_thumbnails.js \
|
browser_thumbnails.js \
|
||||||
browser_install.xml \
|
browser_install.xml \
|
||||||
browser_upgrade.rdf\
|
browser_upgrade.rdf\
|
||||||
|
browser_localerepository.js \
|
||||||
|
locales_list.sjs \
|
||||||
mock_autocomplete.json\
|
mock_autocomplete.json\
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
var localeList = serverRoot + "locales_list.sjs";
|
||||||
|
var PREF_LOCALE_LIST = "extensions.getLocales.get.url";
|
||||||
|
|
||||||
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||||
|
Components.utils.import("resource://gre/modules/LocaleRepository.jsm");
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
waitForExplicitFinish();
|
||||||
|
runNextTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
function end_test() {
|
||||||
|
Services.prefs.clearUserPref(PREF_LOCALE_LIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
registerCleanupFunction(end_test);
|
||||||
|
|
||||||
|
gTests.push({
|
||||||
|
desc: "Test getting a list of compatable locales",
|
||||||
|
run: function() {
|
||||||
|
Services.prefs.setCharPref(PREF_LOCALE_LIST, localeList);
|
||||||
|
LocaleRepository.getLocales(this.listLoaded);
|
||||||
|
},
|
||||||
|
|
||||||
|
listLoaded: function(aLocales) {
|
||||||
|
is(aLocales.length, 1, "Correct number of locales were found");
|
||||||
|
isnot(aLocales[0].addon, null, "Locale has an addon");
|
||||||
|
is(aLocales[0].xpiURL, "http://www.example.com/mylocale.xpi", "Locale has correct xpi url");
|
||||||
|
is(aLocales[0].xpiHash, null, "Locale has correct hash");
|
||||||
|
|
||||||
|
is(aLocales[0].addon.id, "langpack-test-1@firefox-mobile.mozilla.org", "Locale has correct id");
|
||||||
|
is(aLocales[0].addon.name, "Test Locale", "Locale has correct name");
|
||||||
|
is(aLocales[0].addon.type, "language", "Locale has correct type");
|
||||||
|
|
||||||
|
is(aLocales[0].addon.targetLocale, "test", "Locale has correct target locale");
|
||||||
|
is(aLocales[0].addon.version, "1.0", "Locale has correct version");
|
||||||
|
runNextTest();
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,109 @@
|
||||||
|
let fennecID = "{a23983c0-fd0e-11dc-95ff-0800200c9a66}";
|
||||||
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||||
|
|
||||||
|
function getLocale(aLocaleParams, aAppParams) {
|
||||||
|
let l = {
|
||||||
|
TARGETLOCALE: "test",
|
||||||
|
NAME: "Test Locale",
|
||||||
|
VERSION: "1.0",
|
||||||
|
INSTALL: "http://www.example.com/mylocale.xpi",
|
||||||
|
TYPENUMBER: 5,
|
||||||
|
TYPENAME: "Language Pack (Application)",
|
||||||
|
IDNUMBER: "",
|
||||||
|
};
|
||||||
|
let a = {
|
||||||
|
APPNAME: "Fennec",
|
||||||
|
MINVERSION: "4.0", MAXVERSION: "*",
|
||||||
|
APPID: fennecID
|
||||||
|
};
|
||||||
|
|
||||||
|
if (aLocaleParams) {
|
||||||
|
for (var entry in aLocaleParams) {
|
||||||
|
l[entry] = aLocaleParams[entry];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aAppParams) {
|
||||||
|
for (var entry in aAppParams) {
|
||||||
|
a[entry] = aAppParams[entry];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
l.app = a;
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
let gLocales = [
|
||||||
|
getLocale({IDNUMBER: 1}),
|
||||||
|
|
||||||
|
/* These locales should fail in the LocaleRepository */
|
||||||
|
getLocale({IDNUMBER: 1}), // no duplicate ids
|
||||||
|
getLocale({IDNUMBER: 2, INSTALL: "INVALID_URL"}),
|
||||||
|
getLocale({IDNUMBER: 3}, {APPID: "INVALID_ID"}),
|
||||||
|
getLocale({IDNUMBER: 3}, {MAXVERSION: "0"}),
|
||||||
|
getLocale({IDNUMBER: 4, TARGETLOCALE: ""}),
|
||||||
|
getLocale({IDNUMBER: 5, NAME: ""}),
|
||||||
|
getLocale({IDNUMBER: 6, VERSION: ""}),
|
||||||
|
getLocale({IDNUMBER: 7, TYPENUMBER: ""})
|
||||||
|
];
|
||||||
|
|
||||||
|
let appTemplate = "<application>" +
|
||||||
|
"<name>{APPNAME}</name>" +
|
||||||
|
"<min_version>{MINVERSION}</min_version>" +
|
||||||
|
"<max_version>{MAXVERSION}</max_version>" +
|
||||||
|
"<appID>{APPID}</appID>" +
|
||||||
|
"</application>";
|
||||||
|
|
||||||
|
let template = "<addon>"+
|
||||||
|
"<target_locale>{TARGETLOCALE}</target_locale>" +
|
||||||
|
"<name>{NAME}</name>"+
|
||||||
|
"<type id=\"{TYPENUMBER}\">{TYPENAME}</type>"+
|
||||||
|
"<guid>langpack-{TARGETLOCALE}-{IDNUMBER}@firefox-mobile.mozilla.org</guid>"+
|
||||||
|
"<version>{VERSION}</version>"+
|
||||||
|
"<status id=\"4\">Public</status>"+
|
||||||
|
"<compatible_applications>{APPS}</compatible_applications>"+
|
||||||
|
"<all_compatible_os><os>ALL</os></all_compatible_os>"+
|
||||||
|
"<install os=\"ALL\">{INSTALL}</install><strings>\n" +
|
||||||
|
"title=TITLE\n" +
|
||||||
|
"continueIn=CONTINUEIN\n" +
|
||||||
|
"name=NAME\n" +
|
||||||
|
"choose=CHOOSE\n" +
|
||||||
|
"chooseLanguage=CHOOSELANGUAGE\n" +
|
||||||
|
"cancel=CANCEL\n" +
|
||||||
|
"continue=CONTINUE\n" +
|
||||||
|
"installing=INSTALLING\n" +
|
||||||
|
"installerror=INSTALLERROR\n" +
|
||||||
|
"loading=LOADING" +
|
||||||
|
"</strings>"+
|
||||||
|
"</addon>";
|
||||||
|
|
||||||
|
function handleRequest(request, response) {
|
||||||
|
|
||||||
|
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||||
|
response.setHeader("Content-Type", "text/xml", false);
|
||||||
|
|
||||||
|
response.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||||
|
response.write("<addons>");
|
||||||
|
|
||||||
|
for(var i = 0; i < gLocales.length; i++) {
|
||||||
|
let t = template;
|
||||||
|
t = t.replace(/{TARGETLOCALE}/g, gLocales[i].TARGETLOCALE);
|
||||||
|
t = t.replace(/{NAME}/, gLocales[i].NAME);
|
||||||
|
t = t.replace(/{VERSION}/, gLocales[i].VERSION);
|
||||||
|
t = t.replace(/{INSTALL}/, gLocales[i].INSTALL);
|
||||||
|
t = t.replace(/{TYPENUMBER}/, gLocales[i].TYPENUMBER);
|
||||||
|
t = t.replace(/{TYPENAME}/, gLocales[i].TYPENAME);
|
||||||
|
t = t.replace(/{IDNUMBER}/, gLocales[i].IDNUMBER)
|
||||||
|
|
||||||
|
let a = appTemplate;
|
||||||
|
a = a.replace(/{APPNAME}/, gLocales[i].app.APPNAME);
|
||||||
|
a = a.replace(/{MINVERSION}/, gLocales[i].app.MINVERSION);
|
||||||
|
a = a.replace(/{MAXVERSION}/, gLocales[i].app.MAXVERSION);
|
||||||
|
a = a.replace(/{APPID}/, gLocales[i].app.APPID);
|
||||||
|
|
||||||
|
t = t.replace(/{APPS}/, a);
|
||||||
|
response.write(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.write("</addons>");
|
||||||
|
}
|
|
@ -45,8 +45,6 @@ Cu.import("resource://gre/modules/Services.jsm");
|
||||||
Cu.import("resource://gre/modules/AddonManager.jsm");
|
Cu.import("resource://gre/modules/AddonManager.jsm");
|
||||||
Cu.import("resource://gre/modules/NetUtil.jsm");
|
Cu.import("resource://gre/modules/NetUtil.jsm");
|
||||||
|
|
||||||
var gServiceURL = Services.prefs.getCharPref("extensions.getLocales.get.url");
|
|
||||||
|
|
||||||
// A map between XML keys to LocaleSearchResult keys for string values
|
// A map between XML keys to LocaleSearchResult keys for string values
|
||||||
// that require no extra parsing from XML
|
// that require no extra parsing from XML
|
||||||
const STRING_KEY_MAP = {
|
const STRING_KEY_MAP = {
|
||||||
|
@ -83,7 +81,7 @@ var LocaleRepository = {
|
||||||
},
|
},
|
||||||
|
|
||||||
getLocales: function getLocales(aCallback, aFilters) {
|
getLocales: function getLocales(aCallback, aFilters) {
|
||||||
let url = gServiceURL;
|
let url = Services.prefs.getCharPref("extensions.getLocales.get.url");
|
||||||
|
|
||||||
if (!url) {
|
if (!url) {
|
||||||
aCallback([]);
|
aCallback([]);
|
||||||
|
@ -166,7 +164,7 @@ var LocaleRepository = {
|
||||||
addon.type = "language";
|
addon.type = "language";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
WARN("Unknown type id when parsing addon: " + id);
|
this.log("Unknown type id when parsing addon: " + id);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "authors":
|
case "authors":
|
||||||
|
@ -219,7 +217,12 @@ var LocaleRepository = {
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
result.xpiURL = xpiURL;
|
result.xpiURL = xpiURL;
|
||||||
|
try {
|
||||||
addon.sourceURI = NetUtil.newURI(xpiURL);
|
addon.sourceURI = NetUtil.newURI(xpiURL);
|
||||||
|
} catch(ex) {
|
||||||
|
this.log("Addon has invalid uri: " + addon.sourceURI);
|
||||||
|
addon.sourceURI = null;
|
||||||
|
}
|
||||||
|
|
||||||
let size = parseInt(node.getAttribute("size"));
|
let size = parseInt(node.getAttribute("size"));
|
||||||
addon.size = (size >= 0) ? size : null;
|
addon.size = (size >= 0) ? size : null;
|
||||||
|
@ -270,7 +273,7 @@ var LocaleRepository = {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Ignore add-on missing a required attribute
|
// Ignore add-on missing a required attribute
|
||||||
let requiredAttributes = ["id", "name", "version", "type", "targetLocale"];
|
let requiredAttributes = ["id", "name", "version", "type", "targetLocale", "sourceURI"];
|
||||||
if (requiredAttributes.some(function(aAttribute) !result.addon[aAttribute]))
|
if (requiredAttributes.some(function(aAttribute) !result.addon[aAttribute]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче