mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-10 21:28:04 +02:00
***
Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8
This changes the behavior of ChromeUtils.import() to return an exports object,
rather than a module global, in all cases except when `null` is passed as a
second argument, and changes the default behavior not to pollute the global
scope with the module's exports. Thus, the following code written for the old
model:
ChromeUtils.import("resource://gre/modules/Services.jsm");
is approximately the same as the following, in the new model:
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
Since the two behaviors are mutually incompatible, this patch will land with a
scripted rewrite to update all existing callers to use the new model rather
than the old.
***
Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs
This was done using the followng script:
https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm
***
Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D16747
***
Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16748
***
Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16749
***
Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs
***
Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16750
--HG--
extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895
extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
113 lines
3.8 KiB
JavaScript
113 lines
3.8 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
const { L10nRegistry, FileSource } = ChromeUtils.import("resource://gre/modules/L10nRegistry.jsm");
|
|
|
|
const fs = {
|
|
"toolkit/intl/languageNames.ftl": `
|
|
language-name-en = English
|
|
`,
|
|
"toolkit/intl/regionNames.ftl": `
|
|
region-name-us = United States
|
|
region-name-ru = Russia
|
|
`,
|
|
};
|
|
|
|
L10nRegistry.loadSync = function(url) {
|
|
if (!fs.hasOwnProperty(url)) {
|
|
return false;
|
|
}
|
|
return fs[url];
|
|
};
|
|
|
|
let locales = Services.locale.packagedLocales;
|
|
const mockSource = new FileSource("mock", locales, "");
|
|
L10nRegistry.registerSource(mockSource);
|
|
|
|
const gLangDN = Services.intl.getLanguageDisplayNames.bind(Services.intl, undefined);
|
|
const gAvLocDN = Services.intl.getAvailableLocaleDisplayNames.bind(Services.intl);
|
|
const gRegDN = Services.intl.getRegionDisplayNames.bind(Services.intl, undefined);
|
|
const gLocDN = Services.intl.getLocaleDisplayNames.bind(Services.intl, undefined);
|
|
|
|
add_test(function test_valid_language_tag() {
|
|
deepEqual(gLocDN([]), []);
|
|
deepEqual(gLocDN(["en"]), ["English"]);
|
|
deepEqual(gLocDN(["und"]), ["und"]);
|
|
run_next_test();
|
|
});
|
|
|
|
add_test(function test_valid_region_tag() {
|
|
deepEqual(gLocDN(["en-US"]), ["English (United States)"]);
|
|
deepEqual(gLocDN(["en-XY"]), ["English (XY)"]);
|
|
run_next_test();
|
|
});
|
|
|
|
add_test(function test_valid_script_tag() {
|
|
deepEqual(gLocDN(["en-Cyrl"]), ["English (Cyrl)"]);
|
|
deepEqual(gLocDN(["en-Cyrl-RU"]), ["English (Cyrl, Russia)"]);
|
|
run_next_test();
|
|
});
|
|
|
|
add_test(function test_valid_variants_tag() {
|
|
deepEqual(gLocDN(["en-Cyrl-macos"]), ["English (Cyrl, macos)"]);
|
|
deepEqual(gLocDN(["en-Cyrl-RU-macos"]), ["English (Cyrl, Russia, macos)"]);
|
|
deepEqual(gLocDN(["en-Cyrl-RU-macos-modern"]), ["English (Cyrl, Russia, macos, modern)"]);
|
|
run_next_test();
|
|
});
|
|
|
|
add_test(function test_other_subtags_ignored() {
|
|
deepEqual(gLocDN(["en-x-ignore"]), ["English"]);
|
|
deepEqual(gLocDN(["en-t-en-latn"]), ["English"]);
|
|
deepEqual(gLocDN(["en-u-hc-h24"]), ["English"]);
|
|
run_next_test();
|
|
});
|
|
|
|
add_test(function test_invalid_locales() {
|
|
deepEqual(gLocDN(["2"]), ["2"]);
|
|
deepEqual(gLocDN([""]), [""]);
|
|
Assert.throws(() => gLocDN([2]), /All locale codes must be strings/);
|
|
Assert.throws(() => gLocDN([{}]), /All locale codes must be strings/);
|
|
Assert.throws(() => gLocDN([true]), /All locale codes must be strings/);
|
|
run_next_test();
|
|
});
|
|
|
|
add_test(function test_language_only() {
|
|
deepEqual(gLangDN([]), []);
|
|
deepEqual(gLangDN(["en"]), ["English"]);
|
|
deepEqual(gLangDN(["und"]), ["und"]);
|
|
run_next_test();
|
|
});
|
|
|
|
add_test(function test_invalid_languages() {
|
|
deepEqual(gLangDN(["2"]), ["2"]);
|
|
deepEqual(gLangDN([""]), [""]);
|
|
Assert.throws(() => gLangDN([2]), /All language codes must be strings/);
|
|
Assert.throws(() => gLangDN([{}]), /All language codes must be strings/);
|
|
Assert.throws(() => gLangDN([true]), /All language codes must be strings/);
|
|
run_next_test();
|
|
});
|
|
|
|
add_test(function test_region_only() {
|
|
deepEqual(gRegDN([]), []);
|
|
deepEqual(gRegDN(["US"]), ["United States"]);
|
|
deepEqual(gRegDN(["und"]), ["UND"]);
|
|
run_next_test();
|
|
});
|
|
|
|
add_test(function test_invalid_regions() {
|
|
deepEqual(gRegDN(["2"]), ["2"]);
|
|
deepEqual(gRegDN([""]), [""]);
|
|
Assert.throws(() => gRegDN([2]), /All region codes must be strings/);
|
|
Assert.throws(() => gRegDN([{}]), /All region codes must be strings/);
|
|
Assert.throws(() => gRegDN([true]), /All region codes must be strings/);
|
|
run_next_test();
|
|
});
|
|
|
|
add_test(function test_availableLocaleDisplayNames() {
|
|
let langCodes = gAvLocDN("language");
|
|
equal(langCodes.length > 0, true, "There should be some language codes available");
|
|
let regCodes = gAvLocDN("region");
|
|
equal(regCodes.length > 0, true, "There should be some region codes available");
|
|
run_next_test();
|
|
});
|