|
1 const PR_RDONLY = 0x1; |
|
2 |
|
3 var etld = Cc["@mozilla.org/network/effective-tld-service;1"] |
|
4 .getService(Ci.nsIEffectiveTLDService); |
|
5 var idn = Cc["@mozilla.org/network/idn-service;1"] |
|
6 .getService(Ci.nsIIDNService); |
|
7 |
|
8 function run_test() |
|
9 { |
|
10 var fis = Cc["@mozilla.org/network/file-input-stream;1"] |
|
11 .createInstance(Ci.nsIFileInputStream); |
|
12 fis.init(do_get_file("effective_tld_names.dat"), |
|
13 PR_RDONLY, 0444, Ci.nsIFileInputStream.CLOSE_ON_EOF); |
|
14 |
|
15 var lis = Cc["@mozilla.org/intl/converter-input-stream;1"] |
|
16 .createInstance(Ci.nsIConverterInputStream); |
|
17 lis.init(fis, "UTF-8", 1024, 0); |
|
18 lis.QueryInterface(Ci.nsIUnicharLineInputStream); |
|
19 |
|
20 var out = { value: "" }; |
|
21 do |
|
22 { |
|
23 var more = lis.readLine(out); |
|
24 var line = out.value; |
|
25 |
|
26 line = line.replace(/^\s+/, ""); |
|
27 var firstTwo = line.substring(0, 2); // a misnomer, but whatever |
|
28 if (firstTwo == "" || firstTwo == "//") |
|
29 continue; |
|
30 |
|
31 var space = line.search(/[ \t]/); |
|
32 line = line.substring(0, space == -1 ? line.length : space); |
|
33 |
|
34 if ("*." == firstTwo) |
|
35 { |
|
36 let (rest = line.substring(2)) |
|
37 { |
|
38 checkPublicSuffix("foo.SUPER-SPECIAL-AWESOME-PREFIX." + rest, |
|
39 "SUPER-SPECIAL-AWESOME-PREFIX." + rest); |
|
40 } |
|
41 } |
|
42 else if ("!" == line.charAt(0)) |
|
43 { |
|
44 checkPublicSuffix(line.substring(1), |
|
45 line.substring(line.indexOf(".") + 1)); |
|
46 } |
|
47 else |
|
48 { |
|
49 checkPublicSuffix("SUPER-SPECIAL-AWESOME-PREFIX." + line, line); |
|
50 } |
|
51 } |
|
52 while (more); |
|
53 } |
|
54 |
|
55 function checkPublicSuffix(host, expectedSuffix) |
|
56 { |
|
57 expectedSuffix = idn.convertUTF8toACE(expectedSuffix).toLowerCase(); |
|
58 var actualSuffix = etld.getPublicSuffixFromHost(host); |
|
59 do_check_eq(actualSuffix, expectedSuffix); |
|
60 } |