Bug 779845 - Import PSL test from http://publicsuffix.org/list/test.txt. r=gerv.
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Fri, 24 Aug 2012 14:57:51 +0100
changeset 105338 3e1fa8a59f8db1cc34e2942b556c4ef32d320776
parent 105337 1ec081fd2580188b9f48c53ded10615d708ac1ac
child 105339 600cc083dda03b846250bdd76c1bd0a3e8c6a159
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersgerv
bugs779845
milestone17.0a1
Bug 779845 - Import PSL test from http://publicsuffix.org/list/test.txt. r=gerv.
netwerk/test/unit/data/test_psl.txt
netwerk/test/unit/test_psl.js
netwerk/test/unit/xpcshell.ini
--- a/netwerk/test/unit/data/test_psl.txt
+++ b/netwerk/test/unit/data/test_psl.txt
@@ -1,78 +1,78 @@
-# Any copyright is dedicated to the Public Domain.
-# http://creativecommons.org/publicdomain/zero/1.0/
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/publicdomain/zero/1.0/
 
-# NULL input.
-checkPublicSuffix(NULL, NULL);
-# Mixed case.
-checkPublicSuffix('COM', NULL);
+// null input.
+checkPublicSuffix(null, null);
+// Mixed case.
+checkPublicSuffix('COM', null);
 checkPublicSuffix('example.COM', 'example.com');
 checkPublicSuffix('WwW.example.COM', 'example.com');
-# Leading dot.
-checkPublicSuffix('.com', NULL);
-checkPublicSuffix('.example', NULL);
-checkPublicSuffix('.example.com', NULL);
-checkPublicSuffix('.example.example', NULL);
-# Unlisted TLD.
-checkPublicSuffix('example', NULL);
+// Leading dot.
+checkPublicSuffix('.com', null);
+checkPublicSuffix('.example', null);
+checkPublicSuffix('.example.com', null);
+checkPublicSuffix('.example.example', null);
+// Unlisted TLD.
+checkPublicSuffix('example', null);
 checkPublicSuffix('example.example', 'example.example');
 checkPublicSuffix('b.example.example', 'example.example');
 checkPublicSuffix('a.b.example.example', 'example.example');
-# Listed, but non-Internet, TLD.
-#checkPublicSuffix('local', NULL);
-#checkPublicSuffix('example.local', NULL);
-#checkPublicSuffix('b.example.local', NULL);
-#checkPublicSuffix('a.b.example.local', NULL);
-# TLD with only 1 rule.
-checkPublicSuffix('biz', NULL);
+// Listed, but non-Internet, TLD.
+//checkPublicSuffix('local', null);
+//checkPublicSuffix('example.local', null);
+//checkPublicSuffix('b.example.local', null);
+//checkPublicSuffix('a.b.example.local', null);
+// TLD with only 1 rule.
+checkPublicSuffix('biz', null);
 checkPublicSuffix('domain.biz', 'domain.biz');
 checkPublicSuffix('b.domain.biz', 'domain.biz');
 checkPublicSuffix('a.b.domain.biz', 'domain.biz');
-# TLD with some 2-level rules.
-checkPublicSuffix('com', NULL);
+// TLD with some 2-level rules.
+checkPublicSuffix('com', null);
 checkPublicSuffix('example.com', 'example.com');
 checkPublicSuffix('b.example.com', 'example.com');
 checkPublicSuffix('a.b.example.com', 'example.com');
-checkPublicSuffix('uk.com', NULL);
+checkPublicSuffix('uk.com', null);
 checkPublicSuffix('example.uk.com', 'example.uk.com');
 checkPublicSuffix('b.example.uk.com', 'example.uk.com');
 checkPublicSuffix('a.b.example.uk.com', 'example.uk.com');
 checkPublicSuffix('test.ac', 'test.ac');
-# TLD with only 1 (wildcard) rule.
-checkPublicSuffix('cy', NULL);
-checkPublicSuffix('c.cy', NULL);
+// TLD with only 1 (wildcard) rule.
+checkPublicSuffix('cy', null);
+checkPublicSuffix('c.cy', null);
 checkPublicSuffix('b.c.cy', 'b.c.cy');
 checkPublicSuffix('a.b.c.cy', 'b.c.cy');
-# More complex TLD.
-checkPublicSuffix('jp', NULL);
+// More complex TLD.
+checkPublicSuffix('jp', null);
 checkPublicSuffix('test.jp', 'test.jp');
 checkPublicSuffix('www.test.jp', 'test.jp');
-checkPublicSuffix('ac.jp', NULL);
+checkPublicSuffix('ac.jp', null);
 checkPublicSuffix('test.ac.jp', 'test.ac.jp');
 checkPublicSuffix('www.test.ac.jp', 'test.ac.jp');
-checkPublicSuffix('kyoto.jp', NULL);
+checkPublicSuffix('kyoto.jp', null);
 checkPublicSuffix('test.kyoto.jp', 'test.kyoto.jp');
-checkPublicSuffix('ide.kyoto.jp', NULL);
+checkPublicSuffix('ide.kyoto.jp', null);
 checkPublicSuffix('b.ide.kyoto.jp', 'b.ide.kyoto.jp');
 checkPublicSuffix('a.b.ide.kyoto.jp', 'b.ide.kyoto.jp');
-checkPublicSuffix('c.kobe.jp', NULL);
+checkPublicSuffix('c.kobe.jp', null);
 checkPublicSuffix('b.c.kobe.jp', 'b.c.kobe.jp');
 checkPublicSuffix('a.b.c.kobe.jp', 'b.c.kobe.jp');
 checkPublicSuffix('city.kobe.jp', 'city.kobe.jp');
 checkPublicSuffix('www.city.kobe.jp', 'city.kobe.jp');
-# TLD with a wildcard rule and exceptions.
-checkPublicSuffix('om', NULL);
-checkPublicSuffix('test.om', NULL);
+// TLD with a wildcard rule and exceptions.
+checkPublicSuffix('om', null);
+checkPublicSuffix('test.om', null);
 checkPublicSuffix('b.test.om', 'b.test.om');
 checkPublicSuffix('a.b.test.om', 'b.test.om');
 checkPublicSuffix('songfest.om', 'songfest.om');
 checkPublicSuffix('www.songfest.om', 'songfest.om');
-# US K12.
-checkPublicSuffix('us', NULL);
+// US K12.
+checkPublicSuffix('us', null);
 checkPublicSuffix('test.us', 'test.us');
 checkPublicSuffix('www.test.us', 'test.us');
-checkPublicSuffix('ak.us', NULL);
+checkPublicSuffix('ak.us', null);
 checkPublicSuffix('test.ak.us', 'test.ak.us');
 checkPublicSuffix('www.test.ak.us', 'test.ak.us');
-checkPublicSuffix('k12.ak.us', NULL);
+checkPublicSuffix('k12.ak.us', null);
 checkPublicSuffix('test.k12.ak.us', 'test.k12.ak.us');
 checkPublicSuffix('www.test.k12.ak.us', 'test.k12.ak.us');
new file mode 100644
--- /dev/null
+++ b/netwerk/test/unit/test_psl.js
@@ -0,0 +1,28 @@
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+var etld = Cc["@mozilla.org/network/effective-tld-service;1"]
+             .getService(Ci.nsIEffectiveTLDService);
+
+function run_test()
+{
+  var file = do_get_file("data/test_psl.txt");
+  var ios = Cc["@mozilla.org/network/io-service;1"]
+              .getService(Ci.nsIIOService);
+  var uri = ios.newFileURI(file);
+  var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
+                       .getService(Ci.mozIJSSubScriptLoader);
+  var srvScope = {};
+  scriptLoader.loadSubScript(uri.spec, srvScope);
+}
+
+function checkPublicSuffix(host, expectedSuffix)
+{
+  var actualSuffix = null;
+  try {
+    actualSuffix = etld.getBaseDomainFromHost(host);
+  } catch (e if e.name == "NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS" ||
+                e.name == "NS_ERROR_ILLEGAL_VALUE") {
+  }
+  do_check_eq(actualSuffix, expectedSuffix);
+}
--- a/netwerk/test/unit/xpcshell.ini
+++ b/netwerk/test/unit/xpcshell.ini
@@ -155,16 +155,17 @@ skip-if = os == "win"
 [test_plaintext_sniff.js]
 [test_post.js]
 [test_progress.js]
 [test_protocolproxyservice.js]
 [test_proxy-failover_canceled.js]
 [test_proxy-failover_passing.js]
 [test_proxy-replace_canceled.js]
 [test_proxy-replace_passing.js]
+[test_psl.js]
 [test_range_requests.js]
 [test_readline.js]
 [test_redirect-caching_canceled.js]
 [test_redirect-caching_failure.js]
 [test_redirect-caching_passing.js]
 [test_redirect_canceled.js]
 [test_redirect_failure.js]
 [test_redirect_passing.js]