summaryrefslogtreecommitdiffstats
path: root/toolkit/components/webextensions/test/xpcshell/test_locale_data.js
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2018-02-10 02:51:36 -0500
committerMatt A. Tobin <email@mattatobin.com>2018-02-10 02:51:36 -0500
commit37d5300335d81cecbecc99812747a657588c63eb (patch)
tree765efa3b6a56bb715d9813a8697473e120436278 /toolkit/components/webextensions/test/xpcshell/test_locale_data.js
parentb2bdac20c02b12f2057b9ef70b0a946113a00e00 (diff)
parent4fb11cd5966461bccc3ed1599b808237be6b0de9 (diff)
downloadUXP-37d5300335d81cecbecc99812747a657588c63eb.tar
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.gz
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.lz
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.xz
UXP-37d5300335d81cecbecc99812747a657588c63eb.zip
Merge branch 'ext-work'
Diffstat (limited to 'toolkit/components/webextensions/test/xpcshell/test_locale_data.js')
-rw-r--r--toolkit/components/webextensions/test/xpcshell/test_locale_data.js130
1 files changed, 130 insertions, 0 deletions
diff --git a/toolkit/components/webextensions/test/xpcshell/test_locale_data.js b/toolkit/components/webextensions/test/xpcshell/test_locale_data.js
new file mode 100644
index 000000000..c3cd44e57
--- /dev/null
+++ b/toolkit/components/webextensions/test/xpcshell/test_locale_data.js
@@ -0,0 +1,130 @@
+"use strict";
+
+Cu.import("resource://gre/modules/Extension.jsm");
+
+/* globals ExtensionData */
+
+const uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
+
+function* generateAddon(data) {
+ let id = uuidGenerator.generateUUID().number;
+
+ data = Object.assign({embedded: true}, data);
+ data.manifest = Object.assign({applications: {gecko: {id}}}, data.manifest);
+
+ let xpi = Extension.generateXPI(data);
+ do_register_cleanup(() => {
+ Services.obs.notifyObservers(xpi, "flush-cache-entry", null);
+ xpi.remove(false);
+ });
+
+ let fileURI = Services.io.newFileURI(xpi);
+ let jarURI = NetUtil.newURI(`jar:${fileURI.spec}!/webextension/`);
+
+ let extension = new ExtensionData(jarURI);
+ yield extension.readManifest();
+
+ return extension;
+}
+
+add_task(function* testMissingDefaultLocale() {
+ let extension = yield generateAddon({
+ "files": {
+ "_locales/en_US/messages.json": {},
+ },
+ });
+
+ equal(extension.errors.length, 0, "No errors reported");
+
+ yield extension.initAllLocales();
+
+ equal(extension.errors.length, 1, "One error reported");
+
+ do_print(`Got error: ${extension.errors[0]}`);
+
+ ok(extension.errors[0].includes('"default_locale" property is required'),
+ "Got missing default_locale error");
+});
+
+
+add_task(function* testInvalidDefaultLocale() {
+ let extension = yield generateAddon({
+ "manifest": {
+ "default_locale": "en",
+ },
+
+ "files": {
+ "_locales/en_US/messages.json": {},
+ },
+ });
+
+ equal(extension.errors.length, 1, "One error reported");
+
+ do_print(`Got error: ${extension.errors[0]}`);
+
+ ok(extension.errors[0].includes("Loading locale file _locales/en/messages.json"),
+ "Got invalid default_locale error");
+
+ yield extension.initAllLocales();
+
+ equal(extension.errors.length, 2, "Two errors reported");
+
+ do_print(`Got error: ${extension.errors[1]}`);
+
+ ok(extension.errors[1].includes('"default_locale" property must correspond'),
+ "Got invalid default_locale error");
+});
+
+
+add_task(function* testUnexpectedDefaultLocale() {
+ let extension = yield generateAddon({
+ "manifest": {
+ "default_locale": "en_US",
+ },
+ });
+
+ equal(extension.errors.length, 1, "One error reported");
+
+ do_print(`Got error: ${extension.errors[0]}`);
+
+ ok(extension.errors[0].includes("Loading locale file _locales/en-US/messages.json"),
+ "Got invalid default_locale error");
+
+ yield extension.initAllLocales();
+
+ equal(extension.errors.length, 2, "One error reported");
+
+ do_print(`Got error: ${extension.errors[1]}`);
+
+ ok(extension.errors[1].includes('"default_locale" property must correspond'),
+ "Got unexpected default_locale error");
+});
+
+
+add_task(function* testInvalidSyntax() {
+ let extension = yield generateAddon({
+ "manifest": {
+ "default_locale": "en_US",
+ },
+
+ "files": {
+ "_locales/en_US/messages.json": '{foo: {message: "bar", description: "baz"}}',
+ },
+ });
+
+ equal(extension.errors.length, 1, "No errors reported");
+
+ do_print(`Got error: ${extension.errors[0]}`);
+
+ ok(extension.errors[0].includes("Loading locale file _locales\/en_US\/messages\.json: SyntaxError"),
+ "Got syntax error");
+
+ yield extension.initAllLocales();
+
+ equal(extension.errors.length, 2, "One error reported");
+
+ do_print(`Got error: ${extension.errors[1]}`);
+
+ ok(extension.errors[1].includes("Loading locale file _locales\/en_US\/messages\.json: SyntaxError"),
+ "Got syntax error");
+});