diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /chrome/test/unit/test_bug519468.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'chrome/test/unit/test_bug519468.js')
-rw-r--r-- | chrome/test/unit/test_bug519468.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/chrome/test/unit/test_bug519468.js b/chrome/test/unit/test_bug519468.js new file mode 100644 index 000000000..69c5c8622 --- /dev/null +++ b/chrome/test/unit/test_bug519468.js @@ -0,0 +1,94 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +var MANIFESTS = [ + do_get_file("data/test_bug519468.manifest") +]; + +Components.utils.import("resource://testing-common/MockRegistrar.jsm"); +// Stub in the locale service so we can control what gets returned as the OS locale setting +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); + +var stubOSLocale = null; + +StubLocaleService = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsILocaleService, Ci.nsISupports]), + + getLocaleComponentForUserAgent: function SLS_getLocaleComponentForUserAgent() + { + return stubOSLocale; + } +} + +MockRegistrar.register("@mozilla.org/intl/nslocaleservice;1", StubLocaleService); + +// Now fire up the test +do_test_pending() +registerManifests(MANIFESTS); + +var chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"] + .getService(Ci.nsIXULChromeRegistry) + .QueryInterface(Ci.nsIToolkitChromeRegistry); +chromeReg.checkForNewChrome(); + +var prefService = Cc["@mozilla.org/preferences-service;1"] + .getService(Ci.nsIPrefService) + .QueryInterface(Ci.nsIPrefBranch); +var os = Cc["@mozilla.org/observer-service;1"] + .getService(Ci.nsIObserverService); + +var testsLocale = [ + // These tests cover when the OS local is included in our manifest + {matchOS: false, selected: "en-US", osLocale: "xx-AA", locale: "en-US"}, + {matchOS: true, selected: "en-US", osLocale: "xx-AA", locale: "xx-AA"}, + {matchOS: false, selected: "fr-FR", osLocale: "xx-AA", locale: "fr-FR"}, + {matchOS: true, selected: "fr-FR", osLocale: "xx-AA", locale: "xx-AA"}, + {matchOS: false, selected: "de-DE", osLocale: "xx-AA", locale: "de-DE"}, + {matchOS: true, selected: "de-DE", osLocale: "xx-AA", locale: "xx-AA"}, + // these tests cover the case where the OS locale is not available in our manifest, but the + // base language is (ie, substitute xx-AA which we have for xx-BB which we don't) + {matchOS: false, selected: "en-US", osLocale: "xx-BB", locale: "en-US"}, + {matchOS: true, selected: "en-US", osLocale: "xx-BB", locale: "xx-AA"}, + {matchOS: false, selected: "fr-FR", osLocale: "xx-BB", locale: "fr-FR"}, + {matchOS: true, selected: "fr-FR", osLocale: "xx-BB", locale: "xx-AA"}, + // These tests cover where the language is not available + {matchOS: false, selected: "en-US", osLocale: "xy-BB", locale: "en-US"}, + {matchOS: true, selected: "en-US", osLocale: "xy-BB", locale: "en-US"}, + {matchOS: false, selected: "fr-FR", osLocale: "xy-BB", locale: "fr-FR"}, + {matchOS: true, selected: "fr-FR", osLocale: "xy-BB", locale: "en-US"}, +]; + +var observedLocale = null; + +function test_locale(aTest) { + observedLocale = null; + + stubOSLocale = aTest.osLocale; + prefService.setBoolPref("intl.locale.matchOS", aTest.matchOS); + prefService.setCharPref("general.useragent.locale", aTest.selected); + + chromeReg.reloadChrome(); + + do_check_eq(observedLocale, aTest.locale); +} + +// Callback function for observing locale change. May be called more than once +// per test iteration. +function checkValidity() { + observedLocale = chromeReg.getSelectedLocale("testmatchos"); + dump("checkValidity called back with locale = " + observedLocale + "\n"); +} + +function run_test() { + os.addObserver(checkValidity, "selected-locale-has-changed", false); + + for (let count = 0 ; count < testsLocale.length ; count++) { + dump("count = " + count + " " + testsLocale[count].toSource() + "\n"); + test_locale(testsLocale[count]); + } + + os.removeObserver(checkValidity, "selected-locale-has-changed"); + do_test_finished(); +} |