netwerk/test/unit/test_bug414122.js

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 const PR_RDONLY = 0x1;
     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);
     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);
    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);
    20   var out = { value: "" };
    21   do
    22   {
    23     var more = lis.readLine(out);
    24     var line = out.value;
    26     line = line.replace(/^\s+/, "");
    27     var firstTwo = line.substring(0, 2); // a misnomer, but whatever
    28     if (firstTwo == "" || firstTwo == "//")
    29       continue;
    31     var space = line.search(/[ \t]/);
    32     line = line.substring(0, space == -1 ? line.length : space);
    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 }
    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 }

mercurial