1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/chrome/test/unit/test_bug848297.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,48 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + */ 1.8 + 1.9 +var MANIFESTS = [ 1.10 + do_get_file("data/test_bug848297.manifest") 1.11 +]; 1.12 + 1.13 +// Stub in the locale service so we can control what gets returned as the OS locale setting 1.14 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); 1.15 + 1.16 +registerManifests(MANIFESTS); 1.17 + 1.18 +var chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"] 1.19 + .getService(Ci.nsIXULChromeRegistry) 1.20 + .QueryInterface(Ci.nsIToolkitChromeRegistry); 1.21 +chromeReg.checkForNewChrome(); 1.22 + 1.23 +var prefService = Cc["@mozilla.org/preferences-service;1"] 1.24 + .getService(Ci.nsIPrefService) 1.25 + .QueryInterface(Ci.nsIPrefBranch); 1.26 + 1.27 +function enum_to_array(strings) { 1.28 + let rv = []; 1.29 + while (strings.hasMore()) { 1.30 + rv.push(strings.getNext()); 1.31 + } 1.32 + rv.sort(); 1.33 + return rv; 1.34 +} 1.35 + 1.36 +function run_test() { 1.37 + 1.38 + // without override 1.39 + prefService.setCharPref("general.useragent.locale", "de"); 1.40 + do_check_eq(chromeReg.getSelectedLocale("basepack"), "en-US"); 1.41 + do_check_eq(chromeReg.getSelectedLocale("overpack"), "de"); 1.42 + do_check_matches(enum_to_array(chromeReg.getLocalesForPackage("basepack")), 1.43 + ['en-US', 'fr']); 1.44 + 1.45 + // with override 1.46 + prefService.setCharPref("chrome.override_package.basepack", "overpack"); 1.47 + do_check_eq(chromeReg.getSelectedLocale("basepack"), "de"); 1.48 + do_check_matches(enum_to_array(chromeReg.getLocalesForPackage("basepack")), 1.49 + ['de', 'en-US']); 1.50 + 1.51 +}