1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is mozilla.org code.
16 * The Initial Developer of the Original Code is
17 * Vivien Nicolas <21@vingtetun.org>.
19 * Portions created by the Initial Developer are Copyright (C) 2007
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK *****
39 function write_locale(stream, locale, package) {
40 var s = "locale " + package + " " + locale + " jar:" + locale + ".jar!";
41 s += "/locale/" + locale + "/" + package +"/\n";
42 stream.write(s, s.length);
45 var localeService = Cc["@mozilla.org/intl/nslocaleservice;1"]
46 .getService(Ci.nsILocaleService);
48 var systemLocale = localeService.getLocaleComponentForUserAgent();
52 if (systemLocale == "en-US")
53 locales = [ "en-US", "fr-FR", "de-DE" ];
54 else if (systemLocale == "fr-FR")
55 locales = [ "en-US", systemLocale, "de-DE" ];
57 locales = [ "en-US", systemLocale, "fr-FR" ];
60 var workingDir = Cc["@mozilla.org/file/directory_service;1"].
61 getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
62 var manifest = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
63 manifest.initWithFile(workingDir);
64 manifest.append("test_bug519468.manifest");
65 manifest.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
66 var stream = Cc["@mozilla.org/network/file-output-stream;1"].
67 createInstance(Ci.nsIFileOutputStream);
68 stream.init(manifest, 0x04 | 0x08 | 0x20, 0600, 0); // write, create, truncate
69 locales.slice(0,2).forEach(function(l) write_locale(stream, l, "testmatchos"));
70 write_locale(stream, locales[2], "testnomatchos");
77 registerManifests(MANIFESTS);
79 var chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]
80 .getService(Ci.nsIXULChromeRegistry)
81 .QueryInterface(Ci.nsIToolkitChromeRegistry);
82 chromeReg.checkForNewChrome();
84 var prefService = Cc["@mozilla.org/preferences-service;1"]
85 .getService(Ci.nsIPrefService)
86 .QueryInterface(Ci.nsIPrefBranch);
88 function test_locale(aTest) {
89 prefService.setBoolPref("intl.locale.matchOS", aTest.matchOS);
91 prefService.setCharPref("general.useragent.locale", aTest.selected);
94 prefService.clearUserPref("general.useragent.locale");
97 var selectedLocale = chromeReg.getSelectedLocale(aTest.package);
98 do_check_eq(selectedLocale, aTest.locale);
104 {matchOS: true, selected: null, locale: systemLocale},
105 {matchOS: true, selected: locales[0], locale: locales[0]},
106 {matchOS: true, selected: locales[1], locale: locales[1]},
107 {matchOS: true, selected: locales[2], locale: locales[0]},
108 {matchOS: true, selected: null, locale: locales[2], package: "testnomatchos"},
109 {matchOS: false, selected: null, locale: locales[0]},
110 {matchOS: false, selected: locales[0], locale: locales[0]},
111 {matchOS: false, selected: locales[1], locale: locales[1]},
112 {matchOS: false, selected: locales[2], locale: locales[0]},
115 for (var i = 0; i < tests.length; ++ i) {
118 test.package = "testmatchos";