4 var tld = Services.eTLD;
5 Assert.equal(tld.getPublicSuffixFromHost("localhost"), "localhost");
6 Assert.equal(tld.getPublicSuffixFromHost("localhost."), "localhost.");
7 Assert.equal(tld.getPublicSuffixFromHost("domain.com"), "com");
8 Assert.equal(tld.getPublicSuffixFromHost("domain.com."), "com.");
9 Assert.equal(tld.getPublicSuffixFromHost("domain.co.uk"), "co.uk");
10 Assert.equal(tld.getPublicSuffixFromHost("domain.co.uk."), "co.uk.");
11 Assert.equal(tld.getPublicSuffixFromHost("co.uk"), "co.uk");
12 Assert.equal(tld.getBaseDomainFromHost("domain.co.uk"), "domain.co.uk");
13 Assert.equal(tld.getBaseDomainFromHost("domain.co.uk."), "domain.co.uk.");
16 tld.getPublicSuffixFromHost("");
17 do_throw("this should fail");
19 Assert.equal(e.result, Cr.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS);
23 tld.getBaseDomainFromHost("domain.co.uk", 1);
24 do_throw("this should fail");
26 Assert.equal(e.result, Cr.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS);
30 tld.getBaseDomainFromHost("co.uk");
31 do_throw("this should fail");
33 Assert.equal(e.result, Cr.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS);
37 tld.getBaseDomainFromHost("");
38 do_throw("this should fail");
40 Assert.equal(e.result, Cr.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS);
44 tld.getPublicSuffixFromHost("1.2.3.4");
45 do_throw("this should fail");
47 Assert.equal(e.result, Cr.NS_ERROR_HOST_IS_IP_ADDRESS);
51 tld.getPublicSuffixFromHost("2010:836B:4179::836B:4179");
52 do_throw("this should fail");
54 Assert.equal(e.result, Cr.NS_ERROR_HOST_IS_IP_ADDRESS);
58 tld.getPublicSuffixFromHost("3232235878");
59 do_throw("this should fail");
61 Assert.equal(e.result, Cr.NS_ERROR_HOST_IS_IP_ADDRESS);
65 tld.getPublicSuffixFromHost("::ffff:192.9.5.5");
66 do_throw("this should fail");
68 Assert.equal(e.result, Cr.NS_ERROR_HOST_IS_IP_ADDRESS);
72 tld.getPublicSuffixFromHost("::1");
73 do_throw("this should fail");
75 Assert.equal(e.result, Cr.NS_ERROR_HOST_IS_IP_ADDRESS);
78 // Check IP addresses with trailing dot as well, Necko sometimes accepts
79 // those (depending on operating system, see bug 380543)
81 tld.getPublicSuffixFromHost("127.0.0.1.");
82 do_throw("this should fail");
84 Assert.equal(e.result, Cr.NS_ERROR_HOST_IS_IP_ADDRESS);
88 tld.getPublicSuffixFromHost("::ffff:127.0.0.1.");
89 do_throw("this should fail");
91 Assert.equal(e.result, Cr.NS_ERROR_HOST_IS_IP_ADDRESS);
94 // check normalization: output should be consistent with
95 // nsIURI::GetAsciiHost(), i.e. lowercased and ASCII/ACE encoded
96 var uri = Services.io.newURI("http://b\u00FCcher.co.uk");
97 Assert.equal(tld.getBaseDomain(uri), "xn--bcher-kva.co.uk");
99 tld.getBaseDomainFromHost("b\u00FCcher.co.uk"),
100 "xn--bcher-kva.co.uk"
102 Assert.equal(tld.getPublicSuffix(uri), "co.uk");
103 Assert.equal(tld.getPublicSuffixFromHost("b\u00FCcher.co.uk"), "co.uk");
105 // check that malformed hosts are rejected as invalid args
107 tld.getBaseDomainFromHost("domain.co.uk..");
108 do_throw("this should fail");
110 Assert.equal(e.result, Cr.NS_ERROR_ILLEGAL_VALUE);
114 tld.getBaseDomainFromHost("domain.co..uk");
115 do_throw("this should fail");
117 Assert.equal(e.result, Cr.NS_ERROR_ILLEGAL_VALUE);
121 tld.getBaseDomainFromHost(".domain.co.uk");
122 do_throw("this should fail");
124 Assert.equal(e.result, Cr.NS_ERROR_ILLEGAL_VALUE);
128 tld.getBaseDomainFromHost(".domain.co.uk");
129 do_throw("this should fail");
131 Assert.equal(e.result, Cr.NS_ERROR_ILLEGAL_VALUE);
135 tld.getBaseDomainFromHost(".");
136 do_throw("this should fail");
138 Assert.equal(e.result, Cr.NS_ERROR_ILLEGAL_VALUE);
142 tld.getBaseDomainFromHost("..");
143 do_throw("this should fail");
145 Assert.equal(e.result, Cr.NS_ERROR_ILLEGAL_VALUE);