1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
"use strict";
var testpath = "/bug1054739";
function run_test() {
let intlPrefs = Services.prefs.getBranch("intl.");
let oldAcceptLangPref = intlPrefs.getCharPref("accept_languages");
let testData = [
["en", "en"],
["ast", "ast"],
["fr-ca", "fr-CA"],
["zh-yue", "zh-yue"],
["az-latn", "az-Latn"],
["sl-nedis", "sl-nedis"],
["zh-hant-hk", "zh-Hant-HK"],
["ZH-HANT-HK", "zh-Hant-HK"],
["en-us-x-priv", "en-US-x-priv"],
["en-us-x-twain", "en-US-x-twain"],
["de, en-US, en", "de,en-US;q=0.7,en;q=0.3"],
["de,en-us,en", "de,en-US;q=0.7,en;q=0.3"],
["en-US, en", "en-US,en;q=0.5"],
["EN-US;q=0.2, EN", "en-US,en;q=0.5"],
["en ;q=0.8, de ", "en,de;q=0.5"],
[",en,", "en"],
];
for (let i = 0; i < testData.length; i++) {
let acceptLangPref = testData[i][0];
let expectedHeader = testData[i][1];
intlPrefs.setCharPref("accept_languages", acceptLangPref);
let acceptLangHeader =
setupChannel(testpath).getRequestHeader("Accept-Language");
equal(acceptLangHeader, expectedHeader);
}
intlPrefs.setCharPref("accept_languages", oldAcceptLangPref);
}
function setupChannel(path) {
let uri = NetUtil.newURI("http://localhost:4444" + path);
let chan = NetUtil.newChannel({
uri,
loadUsingSystemPrincipal: true,
});
chan.QueryInterface(Ci.nsIHttpChannel);
return chan;
}
|