michael@0: var etld = Cc["@mozilla.org/network/effective-tld-service;1"] michael@0: .getService(Ci.nsIEffectiveTLDService); michael@0: michael@0: var idna = Cc["@mozilla.org/network/idn-service;1"] michael@0: .getService(Ci.nsIIDNService); michael@0: michael@0: var Cr = Components.results; michael@0: michael@0: function run_test() michael@0: { michael@0: var file = do_get_file("data/test_psl.txt"); michael@0: var ios = Cc["@mozilla.org/network/io-service;1"] michael@0: .getService(Ci.nsIIOService); michael@0: var uri = ios.newFileURI(file); michael@0: var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"] michael@0: .getService(Ci.mozIJSSubScriptLoader); michael@0: var srvScope = {}; michael@0: scriptLoader.loadSubScript(uri.spec, srvScope, "utf-8"); michael@0: } michael@0: michael@0: function checkPublicSuffix(host, expectedSuffix) michael@0: { michael@0: var actualSuffix = null; michael@0: try { michael@0: actualSuffix = etld.getBaseDomainFromHost(host); michael@0: } catch (e if e.result == Cr.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS || michael@0: e.result == Cr.NS_ERROR_ILLEGAL_VALUE) { michael@0: } michael@0: // The EffectiveTLDService always gives back punycoded labels. michael@0: // The test suite wants to get back what it put in. michael@0: if (actualSuffix !== null && expectedSuffix !== null && michael@0: /(^|\.)xn--/.test(actualSuffix) && !/(^|\.)xn--/.test(expectedSuffix)) { michael@0: actualSuffix = idna.convertACEtoUTF8(actualSuffix); michael@0: } michael@0: do_check_eq(actualSuffix, expectedSuffix); michael@0: }