test_psl.js (1050B)
1 "use strict"; 2 3 var idna = Cc["@mozilla.org/network/idn-service;1"].getService( 4 Ci.nsIIDNService 5 ); 6 7 function run_test() { 8 var file = do_get_file("data/test_psl.txt"); 9 var uri = Services.io.newFileURI(file); 10 var srvScope = {}; 11 Services.scriptloader.loadSubScript(uri.spec, srvScope); 12 } 13 14 // Exported to the loaded script 15 /* exported checkPublicSuffix */ 16 function checkPublicSuffix(host, expectedSuffix) { 17 var actualSuffix = null; 18 try { 19 actualSuffix = Services.eTLD.getBaseDomainFromHost(host); 20 } catch (e) { 21 if ( 22 e.result != Cr.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS && 23 e.result != Cr.NS_ERROR_ILLEGAL_VALUE 24 ) { 25 throw e; 26 } 27 } 28 // The EffectiveTLDService always gives back punycoded labels. 29 // The test suite wants to get back what it put in. 30 if ( 31 actualSuffix !== null && 32 expectedSuffix !== null && 33 /(^|\.)xn--/.test(actualSuffix) && 34 !/(^|\.)xn--/.test(expectedSuffix) 35 ) { 36 actualSuffix = idna.convertACEtoUTF8(actualSuffix); 37 } 38 Assert.equal(actualSuffix, expectedSuffix); 39 }