netwerk/test/unit/test_bug414122.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial