test_idnservice.js (1120B)
1 // Tests nsIIDNService 2 3 "use strict"; 4 5 const idnService = Cc["@mozilla.org/network/idn-service;1"].getService( 6 Ci.nsIIDNService 7 ); 8 9 add_task(async function test_simple() { 10 function isACE(domain) { 11 return domain.startsWith("xn--") || domain.indexOf(".xn--") > -1; 12 } 13 14 let reference = [ 15 // The 3rd element indicates whether the second element 16 // is ACE-encoded 17 ["asciihost", "asciihost", false], 18 ["b\u00FCcher", "xn--bcher-kva", true], 19 ]; 20 21 for (var i = 0; i < reference.length; ++i) { 22 dump("Testing " + reference[i] + "\n"); 23 // We test the following: 24 // - Converting UTF-8 to ACE and back gives us the expected answer 25 // - Converting the ASCII string UTF-8 -> ACE leaves the string unchanged 26 // - isACE returns true when we expect it to (third array elem true) 27 Assert.equal(idnService.convertUTF8toACE(reference[i][0]), reference[i][1]); 28 Assert.equal(idnService.convertUTF8toACE(reference[i][1]), reference[i][1]); 29 Assert.equal(idnService.convertACEtoUTF8(reference[i][1]), reference[i][0]); 30 Assert.equal(isACE(reference[i][1]), reference[i][2]); 31 } 32 });