netwerk/test/unit/test_bug414122.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/test/unit/test_bug414122.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,60 @@
     1.4 +const PR_RDONLY = 0x1;
     1.5 +
     1.6 +var etld = Cc["@mozilla.org/network/effective-tld-service;1"]
     1.7 +             .getService(Ci.nsIEffectiveTLDService);
     1.8 +var idn = Cc["@mozilla.org/network/idn-service;1"]
     1.9 +             .getService(Ci.nsIIDNService);
    1.10 +
    1.11 +function run_test()
    1.12 +{
    1.13 +  var fis = Cc["@mozilla.org/network/file-input-stream;1"]
    1.14 +              .createInstance(Ci.nsIFileInputStream);
    1.15 +  fis.init(do_get_file("effective_tld_names.dat"),
    1.16 +           PR_RDONLY, 0444, Ci.nsIFileInputStream.CLOSE_ON_EOF);
    1.17 +
    1.18 +  var lis = Cc["@mozilla.org/intl/converter-input-stream;1"]
    1.19 +              .createInstance(Ci.nsIConverterInputStream);
    1.20 +  lis.init(fis, "UTF-8", 1024, 0);
    1.21 +  lis.QueryInterface(Ci.nsIUnicharLineInputStream);
    1.22 +
    1.23 +  var out = { value: "" };
    1.24 +  do
    1.25 +  {
    1.26 +    var more = lis.readLine(out);
    1.27 +    var line = out.value;
    1.28 +
    1.29 +    line = line.replace(/^\s+/, "");
    1.30 +    var firstTwo = line.substring(0, 2); // a misnomer, but whatever
    1.31 +    if (firstTwo == "" || firstTwo == "//")
    1.32 +      continue;
    1.33 +
    1.34 +    var space = line.search(/[ \t]/);
    1.35 +    line = line.substring(0, space == -1 ? line.length : space);
    1.36 +
    1.37 +    if ("*." == firstTwo)
    1.38 +    {
    1.39 +      let (rest = line.substring(2))
    1.40 +      {
    1.41 +        checkPublicSuffix("foo.SUPER-SPECIAL-AWESOME-PREFIX." + rest,
    1.42 +                          "SUPER-SPECIAL-AWESOME-PREFIX." + rest);
    1.43 +      }
    1.44 +    }
    1.45 +    else if ("!" == line.charAt(0))
    1.46 +    {
    1.47 +      checkPublicSuffix(line.substring(1),
    1.48 +                        line.substring(line.indexOf(".") + 1));
    1.49 +    }
    1.50 +    else
    1.51 +    {
    1.52 +      checkPublicSuffix("SUPER-SPECIAL-AWESOME-PREFIX." + line, line);
    1.53 +    }
    1.54 +  }
    1.55 +  while (more);
    1.56 +}
    1.57 +
    1.58 +function checkPublicSuffix(host, expectedSuffix)
    1.59 +{
    1.60 +  expectedSuffix = idn.convertUTF8toACE(expectedSuffix).toLowerCase();
    1.61 +  var actualSuffix = etld.getPublicSuffixFromHost(host);
    1.62 +  do_check_eq(actualSuffix, expectedSuffix);
    1.63 +}

mercurial