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